move horizontal scrollbar always visible setting to window model

This commit is contained in:
Fabian Jakobs 2011-07-27 15:27:53 +02:00
commit 069293b3ff
5 changed files with 31 additions and 22 deletions

View file

@ -339,7 +339,7 @@ define(function(require, exports, module) {
showGutterEl.checked = editor.getShowGutter(); showGutterEl.checked = editor.getShowGutter();
showPrintMarginEl.checked = editor.getShowPrintMargin(); showPrintMarginEl.checked = editor.getShowPrintMargin();
highlightSelectedWordE.checked = editor.getHighlightSelectedWord(); highlightSelectedWordE.checked = editor.getHighlightSelectedWord();
showHScrollEl.checked = editor.renderer.getHScrollBarAlwaysVisible(); showHScrollEl.checked = editor.getHScrollBarAlwaysVisible();
softTabEl.checked = session.getUseSoftTabs(); softTabEl.checked = session.getUseSoftTabs();
behavioursEl.checked = editor.getBehavioursEnabled() behavioursEl.checked = editor.getBehavioursEnabled()
} }
@ -418,7 +418,7 @@ define(function(require, exports, module) {
}); });
bindCheckbox("show_hscroll", function(checked) { bindCheckbox("show_hscroll", function(checked) {
env.editor.renderer.setHScrollBarAlwaysVisible(checked); env.editor.setHScrollBarAlwaysVisible(checked);
}); });
bindCheckbox("soft_tab", function(checked) { bindCheckbox("soft_tab", function(checked) {

View file

@ -650,6 +650,14 @@ var Editor = function(windowView, buffer) {
this.getShowGutter = function() { this.getShowGutter = function() {
return this.windowModel.getShowGutter(); return this.windowModel.getShowGutter();
}; };
this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
this.windowModel.setHScrollBarAlwaysVisible(alwaysVisible);
};
this.getHScrollBarAlwaysVisible = function() {
return this.windowModel.getHScrollBarAlwaysVisible();
};
this.$readOnly = false; this.$readOnly = false;
this.setReadOnly = function(readOnly) { this.setReadOnly = function(readOnly) {

View file

@ -76,6 +76,7 @@ var Window = exports.Window = function() {
this.printMarginColumn = 80; this.printMarginColumn = 80;
this.showGutter = true; this.showGutter = true;
this.padding = 4; this.padding = 4;
this.horizScrollAlwaysVisible = false;
}; };
(function() { (function() {
@ -150,8 +151,20 @@ var Window = exports.Window = function() {
this.getPadding = function() { this.getPadding = function() {
return this.padding; return this.padding;
} };
this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
if (this.horizScrollAlwaysVisible == alwaysVisible)
return;
this.horizScrollAlwaysVisible = alwaysVisible;
this._emit("changeHorizScroll");
};
this.getHScrollBarAlwaysVisible = function() {
return this.horizScrollAlwaysVisible;
};
}).call(Window.prototype); }).call(Window.prototype);
}); });

View file

@ -89,20 +89,13 @@ var WindowView = function(windowModel, container, theme) {
this.$cursorLayer = new CursorLayer(windowModel, this.content); this.$cursorLayer = new CursorLayer(windowModel, this.content);
this.$cursorPadding = 8; this.$cursorPadding = 8;
// Indicates whether the horizontal scrollbar is visible
this.$horizScroll = true; this.$horizScroll = true;
this.$horizScrollAlwaysVisible = true;
this.scrollBar = new ScrollBar(container); this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this)); this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
this.scrollTop = 0; this.scrollTop = 0;
this.cursorPos = {
row : 0,
column : 0
};
var _self = this; var _self = this;
this.$textLayer.addEventListener("changeCharaterSize", function() { this.$textLayer.addEventListener("changeCharaterSize", function() {
_self.characterWidth = textLayer.getCharacterWidth(); _self.characterWidth = textLayer.getCharacterWidth();
@ -120,6 +113,7 @@ var WindowView = function(windowModel, container, theme) {
this.updatePadding(); this.updatePadding();
this.updatePrintMargin(); this.updatePrintMargin();
this.updateHorizScroll();
}; };
(function() { (function() {
@ -323,17 +317,10 @@ var WindowView = function(windowModel, container, theme) {
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
this.updatePrintMargin(); this.updatePrintMargin();
}; };
this.getHScrollBarAlwaysVisible = function() { this.updateHorizScroll = function() {
return this.$horizScrollAlwaysVisible; if (!this.model.horizScrollAlwaysVisible || !this.$horizScroll)
}; this.$loop.schedule(this.CHANGE_SCROLL);
this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
if (this.$horizScrollAlwaysVisible != alwaysVisible) {
this.$horizScrollAlwaysVisible = alwaysVisible;
if (!this.$horizScrollAlwaysVisible || !this.$horizScroll)
this.$loop.schedule(this.CHANGE_SCROLL);
}
}; };
this.onScroll = function(e) { this.onScroll = function(e) {
@ -425,7 +412,7 @@ var WindowView = function(windowModel, container, theme) {
var longestLine = this.$getLongestLine(); var longestLine = this.$getLongestLine();
var widthChanged = this.model.layerConfig.width != longestLine; var widthChanged = this.model.layerConfig.width != longestLine;
var horizScroll = this.$horizScrollAlwaysVisible || this.model.size.scrollerWidth - longestLine < 0; var horizScroll = this.model.horizScrollAlwaysVisible || this.model.size.scrollerWidth - longestLine < 0;
var horizScrollChanged = this.$horizScroll !== horizScroll; var horizScrollChanged = this.$horizScroll !== horizScroll;
this.$horizScroll = horizScroll; this.$horizScroll = horizScroll;
if (horizScrollChanged) if (horizScrollChanged)

View file

@ -45,6 +45,7 @@ var WindowController = exports.WindowController = function(model, view) {
model.on("changePrintMargin", view.updatePrintMargin.bind(view)); model.on("changePrintMargin", view.updatePrintMargin.bind(view));
model.on("changeShowGutter", view.updateShowGutter.bind(view)); model.on("changeShowGutter", view.updateShowGutter.bind(view));
model.on("changePadding", view.updatePadding.bind(view)); model.on("changePadding", view.updatePadding.bind(view));
model.on("changeHorizScroll", view.updateHorizScroll.bind(view));
}; };
(function() { (function() {