From 9140de31efef2856c89ca9345fc419b7ca0d5bdf Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Sun, 27 Sep 2020 23:44:54 +0300 Subject: [PATCH] [DE] Refactoring line numbers --- .../main/app/controller/Toolbar.js | 36 ++++++++++- .../main/app/view/LineNumbersDialog.js | 64 +++++++++++++------ .../app/view/ParagraphSettingsAdvanced.js | 7 ++ apps/documenteditor/main/app/view/Toolbar.js | 10 ++- 4 files changed, 90 insertions(+), 27 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index fa5398ffd..7e06507a9 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -387,6 +387,7 @@ define([ this.api.asc_registerCallback('asc_onMathTypes', _.bind(this.onApiMathTypes, this)); this.api.asc_registerCallback('asc_onColumnsProps', _.bind(this.onColumnsProps, this)); this.api.asc_registerCallback('asc_onSectionProps', _.bind(this.onSectionProps, this)); + this.api.asc_registerCallback('asc_onLineNumbersProps', _.bind(this.onLineNumbersProps, this)); this.api.asc_registerCallback('asc_onContextMenu', _.bind(this.onContextMenu, this)); this.api.asc_registerCallback('asc_onShowParaMarks', _.bind(this.onShowParaMarks, this)); this.api.asc_registerCallback('asc_onChangeSdtGlobalSettings', _.bind(this.onChangeSdtGlobalSettings, this)); @@ -1677,16 +1678,21 @@ define([ }, onLineNumbersSelect: function(menu, item) { + if (_.isUndefined(item.value)) + return; + switch (item.value) { case 0: - break; case 1: - break; case 2: - break; case 3: + this._state.linenum = undefined; + if (this.api && item.checked) { + + } break; case 4: + this.api && this.api.put_ParagraphSuppressLineNumbers(item.checked); break; case 5: var win, @@ -1694,15 +1700,39 @@ define([ win = new DE.Views.LineNumbersDialog({ handler: function(dlg, result) { if (result == 'ok') { + // var props = dlg.getSettings(); + // me.api.asc_SetLineNumbersProps(props); Common.NotificationCenter.trigger('edit:complete', me.toolbar); } } }); win.show(); + // win.setSettings(me.api.asc_GetLineNumbersProps()); break; } }, + onLineNumbersProps: function(props) { + if (props) { + // var type = props.asc_getType(); + var index = -1; + // switch (type) { + // case Asc.None: index = 0; break; + // case Asc.Continuous: index = 1; break; + // case Asc.Page: index = 2; break; + // case Asc.Section: index = 3; break; + // } + if (this._state.linenum === index) + return; + if (index < 0) + this.toolbar.btnLineNumbers.menu.clearAll(); + else + this.toolbar.btnLineNumbers.menu.items[index].setChecked(true); + + this._state.linenum = index; + } + }, + onColorSchemaClick: function(menu, item) { if (this.api) { this.api.asc_ChangeColorSchemeByIdx(item.value); diff --git a/apps/documenteditor/main/app/view/LineNumbersDialog.js b/apps/documenteditor/main/app/view/LineNumbersDialog.js index 68a483c48..ba57aa7fe 100644 --- a/apps/documenteditor/main/app/view/LineNumbersDialog.js +++ b/apps/documenteditor/main/app/view/LineNumbersDialog.js @@ -47,9 +47,11 @@ define([ DE.Views.LineNumbersDialog = Common.UI.Window.extend(_.extend({ options: { width: 290, + height: 273, header: true, style: 'min-width: 290px;', - cls: 'modal-dlg' + cls: 'modal-dlg', + buttons: ['ok', 'cancel'] }, initialize : function(options) { @@ -69,10 +71,6 @@ define([ '
', '
', '
', - '', - '' ].join(''); @@ -107,7 +105,8 @@ define([ defaultUnit : '', value: 1, maxValue: 32767, - minValue: 1 + minValue: 1, + disabled: true }); this.spnFromText = new Common.UI.MetricSpinner({ @@ -118,7 +117,8 @@ define([ value: 'Auto', maxValue: 55.87, minValue: 0.1, - allowAuto: true + allowAuto: true, + disabled: true }); this.spinners.push(this.spnFromText); @@ -129,25 +129,30 @@ define([ defaultUnit : '', value: 1, maxValue: 100, - minValue: 1 + minValue: 1, + disabled: true }); this.rbRestartEachPage = new Common.UI.RadioBox({ el: $('#line-numbers-restart-each-page'), labelText: this.textRestartEachPage, - name: 'asc-radio-line-numbers' + name: 'asc-radio-line-numbers', + disabled: true, + checked: true }); this.rbRestartEachSection = new Common.UI.RadioBox({ el: $('#line-numbers-restart-each-section'), labelText: this.textRestartEachSection, - name: 'asc-radio-line-numbers' + name: 'asc-radio-line-numbers', + disabled: true }); this.rbContinuous = new Common.UI.RadioBox({ el: $('#line-numbers-continuous'), labelText: this.textContinuous, - name: 'asc-radio-line-numbers' + name: 'asc-radio-line-numbers', + disabled: true }); @@ -157,11 +162,21 @@ define([ }, afterRender: function() { - this._setDefaults(); }, - _setDefaults: function() { - + setSettings: function (props) { + if (props) { + // var type = props.asc_getType(); + // this.chAddLineNumbering.setValue(type !== case Asc.None); + // switch (type) { + // case Asc.Continuous: this.rbContinuous.setValue(true, true); break; + // case Asc.Page: this.rbRestartEachPage.setValue(true, true); break; + // case Asc.Section: this.rbRestartEachSection.setValue(true, true); break; + // } + // this.spnStartAt.setValue(props.get_StartAt()!==null ? props.get_StartAt() : '', true); + // this.spnFromText.setValue(props.get_FromText()!==null ? (props.get_FromText()<0 ? -1 : Common.Utils.Metric.fnRecalcFromMM(props.get_FromText())) : '', true); + // this.spnCountBy.setValue(props.get_Count()!==null ? props.get_Count() : '', true); + } }, _handleInput: function(state) { @@ -182,7 +197,22 @@ define([ }, getSettings: function() { - return this; + // var props = new Asc.CDocumentLineNumberProps(); + // if (this.chAddLineNumbering.getValue()!=='checked') { + // props.put_Type(Asc.None); + // } else { + // if (this.rbContinuous.getValue()) + // props.put_Type(Asc.Continuous); + // else if (this.rbRestartEachPage.getValue()) + // props.put_Type(Asc.Page); + // else if (this.rbRestartEachSection.getValue()) + // props.put_Type(Asc.Section); + // props.put_StartAt(this.spnStartAt.getNumberValue()); + // var value = this.spnFromText.getNumberValue(); + // props.put_FromText(value<0 ? -1 : Common.Utils.Metric.fnRecalcToMM()); + // props.put_Count(this.spnCountBy.getNumberValue()); + // } + // return props; }, updateMetricUnit: function() { @@ -196,9 +226,7 @@ define([ }, - textTitle: 'Line Numbers Settings', - cancelButtonText: 'Cancel', - okButtonText: 'Ok', + textTitle: 'Line Numbers', textAddLineNumbering: 'Add line numbering', textStartAt: 'Start at', textFromText: 'From text', diff --git a/apps/documenteditor/main/app/view/ParagraphSettingsAdvanced.js b/apps/documenteditor/main/app/view/ParagraphSettingsAdvanced.js index 558a2a49d..b79f5a641 100644 --- a/apps/documenteditor/main/app/view/ParagraphSettingsAdvanced.js +++ b/apps/documenteditor/main/app/view/ParagraphSettingsAdvanced.js @@ -350,6 +350,11 @@ define([ 'text!documenteditor/main/app/template/ParagraphSettingsAdvanced.tem el: $('#paragraphadv-checkbox-suppress-line-numbers'), labelText: this.strSuppressLineNumbers }); + this.chLineNumbers.on('change', _.bind(function(field, newValue, oldValue, eOpts){ + if (this._changedProps) { + // this._changedProps.put_SuppressLineNumbers(field.getValue()=='checked'); + } + }, this)); // Borders @@ -779,6 +784,8 @@ define([ 'text!documenteditor/main/app/template/ParagraphSettingsAdvanced.tem this.chKeepNext.setValue((props.get_KeepNext() !== null && props.get_KeepNext() !== undefined) ? props.get_KeepNext() : 'indeterminate', true); this.chOrphan.setValue((props.get_WidowControl() !== null && props.get_WidowControl() !== undefined) ? props.get_WidowControl() : 'indeterminate', true); + // this.chLineNumbers.setValue((props.get_SuppressLineNumbers() !== null && props.get_SuppressLineNumbers() !== undefined) ? props.get_SuppressLineNumbers() : 'indeterminate', true); + this.Borders = new Asc.asc_CParagraphBorders(props.get_Borders()); // Margins diff --git a/apps/documenteditor/main/app/view/Toolbar.js b/apps/documenteditor/main/app/view/Toolbar.js index 7ae282680..4d01f9555 100644 --- a/apps/documenteditor/main/app/view/Toolbar.js +++ b/apps/documenteditor/main/app/view/Toolbar.js @@ -1009,15 +1009,13 @@ define([ { caption: this.textSuppressForCurrentParagraph, checkable: true, - toggleGroup: 'menuLineNumbers', + allowDepress: true, value: 4 }, {caption: '--'}, { caption: this.textCustomLineNumbers, - value: 5, - checkable: true, - toggleGroup: 'menuLineNumbers' + value: 5 } ] }) @@ -2420,8 +2418,8 @@ define([ textRestartEachPage: 'Restart Each Page', textRestartEachSection: 'Restart Each Section', textSuppressForCurrentParagraph: 'Suppress for Current Paragraph', - textCustomLineNumbers: 'Custom Line Numbers', - tipLineNumbers: 'Line Numbers' + textCustomLineNumbers: 'Line Numbering Options', + tipLineNumbers: 'Show line numbers' } })(), DE.Views.Toolbar || {})); });