From d7dfdd35a404deaf68317fccf67f56a43840271f Mon Sep 17 00:00:00 2001 From: Alexey Koshelev Date: Wed, 12 Mar 2025 16:52:29 +0300 Subject: [PATCH] [DE] Set current printer for printers combobox --- apps/common/main/lib/controller/Desktop.js | 8 ++- .../main/app/controller/Print.js | 23 ++++-- .../main/app/view/FileMenuPanels.js | 72 +++++++++++-------- 3 files changed, 63 insertions(+), 40 deletions(-) diff --git a/apps/common/main/lib/controller/Desktop.js b/apps/common/main/lib/controller/Desktop.js index 5a8f5de24c..9c14be39c8 100644 --- a/apps/common/main/lib/controller/Desktop.js +++ b/apps/common/main/lib/controller/Desktop.js @@ -199,6 +199,7 @@ define([ webapp.getController('Main').onPrint(); } else if (/printer:config/.test(cmd)) { + var currentPrinter = null; var printers = []; var paramParse; try { @@ -207,10 +208,11 @@ define([ console.warn('printers info is broken'); } - if(paramParse && paramParse.printers){ - printers = paramParse.printers; + if(paramParse){ + paramParse.printers && (printers = paramParse.printers); + paramParse.current_printer && (currentPrinter = paramParse.current_printer); } - webapp.getController('Print').setPrinters(printers); + webapp.getController('Print').setPrinterInfo(currentPrinter, printers); } else if (/file:saveas/.test(cmd)) { webapp.getController('Main').api.asc_DownloadAs(); diff --git a/apps/documenteditor/main/app/controller/Print.js b/apps/documenteditor/main/app/controller/Print.js index 0ab83f3231..7f17ca2346 100644 --- a/apps/documenteditor/main/app/controller/Print.js +++ b/apps/documenteditor/main/app/controller/Print.js @@ -43,7 +43,10 @@ define([ this.adjPrintParams = new Asc.asc_CAdjustPrint(); this._state = { lock_doc: false, - firstPrintPage: 0 + firstPrintPage: 0, + isPrinterInfoLoad: false, + currentPrinter: null, + printersList: [] }; this._navigationPreview = { @@ -54,8 +57,6 @@ define([ this._isPreviewVisible = false; - this._printersList = []; - this.addListeners({ 'PrintWithPreview': { 'show': _.bind(this.onShowMainSettingsPrint, this), @@ -131,7 +132,9 @@ define([ return me.txtPrintRangeInvalid; }; - this._printersList.length > 0 && (this.printSettings.setCmbPrinterOptions(this._printersList)); + if(this._state.isPrinterInfoLoad) { + this.printSettings.updateCmbPrinter(this._state.currentPrinter, this._state.printersList); + } Common.NotificationCenter.on('window:resize', _.bind(function () { if (this._isPreviewVisible) { @@ -402,9 +405,13 @@ define([ Common.NotificationCenter.trigger('edit:complete'); }, - setPrinters: function(list) { - this._printersList = list; - this.printSettings.setCmbPrinterOptions(this._printersList); + setPrinterInfo: function(currentPrinter, list) { + this._state.isPrinterInfoLoad = true; + this._state.currentPrinter = currentPrinter; + this._state.printersList = list; + if(this.printSettings) { + this.printSettings.updateCmbPrinter(this._state.currentPrinter, this._state.printersList); + } }, checkPageSize: function(width, height, left, right, top, bottom) { @@ -534,7 +541,9 @@ define([ this._state.firstPrintPage = this._navigationPreview.currentPage; var size = this.api.asc_getPageSize(this._state.firstPrintPage); + var printerOption = this.printSettings.cmbPrinter.getSelectedRecord(); this.adjPrintParams.asc_setNativeOptions({ + printer: printerOption ? printerOption.value : null, pages: this.printSettings.cmbRange.getValue()===-1 ? this.printSettings.inputPages.getValue() : this.printSettings.cmbRange.getValue(), paperSize: { w: size ? size['W'] : undefined, diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index eaa8b9a7da..598611efa0 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -2735,6 +2735,26 @@ define([], function () { Common.UI.BaseView.prototype.initialize.call(this,arguments); this.menu = options.menu; + + this._defaultPaperSizeList = [ + { value: 0, displayValue: ['US Letter', '21,59', '27,94', 'cm'], caption: 'US Letter', size: [215.9, 279.4]}, + { value: 1, displayValue: ['US Legal', '21,59', '35,56', 'cm'], caption: 'US Legal', size: [215.9, 355.6]}, + { value: 2, displayValue: ['A4', '21', '29,7', 'cm'], caption: 'A4', size: [210, 297]}, + { value: 3, displayValue: ['A5', '14,8', '21', 'cm'], caption: 'A5', size: [148, 210]}, + { value: 4, displayValue: ['B5', '17,6', '25', 'cm'], caption: 'B5', size: [176, 250]}, + { value: 5, displayValue: ['Envelope #10', '10,48', '24,13', 'cm'], caption: 'Envelope #10', size: [104.8, 241.3]}, + { value: 6, displayValue: ['Envelope DL', '11', '22', 'cm'], caption: 'Envelope DL', size: [110, 220]}, + { value: 7, displayValue: ['Tabloid', '27,94', '43,18', 'cm'], caption: 'Tabloid', size: [279.4, 431.8]}, + { value: 8, displayValue: ['A3', '29,7', '42', 'cm'], caption: 'A3', size: [297, 420]}, + { value: 9, displayValue: ['Tabloid Oversize', '29,69', '45,72', 'cm'], caption: 'Tabloid Oversize', size: [296.9, 457.2]}, + { value: 10, displayValue: ['ROC 16K', '19,68', '27,3', 'cm'], caption: 'ROC 16K', size: [196.8, 273]}, + { value: 11, displayValue: ['Envelope Choukei 3', '12', '23,5', 'cm'], caption: 'Envelope Choukei 3', size: [120, 235]}, + { value: 12, displayValue: ['Super B/A3', '30,5', '48,7', 'cm'], caption: 'Super B/A3', size: [305, 487]}, + { value: 13, displayValue: ['A4', '84,1', '118,9', 'cm'], caption: 'A0', size: [841, 1189]}, + { value: 14, displayValue: ['A4', '59,4', '84,1', 'cm'], caption: 'A1', size: [594, 841]}, + { value: 16, displayValue: ['A4', '42', '59,4', 'cm'], caption: 'A2', size: [420, 594]}, + { value: 17, displayValue: ['A4', '10,5', '14,8', 'cm'], caption: 'A6', size: [105, 148]} + ]; this._initSettings = true; }, @@ -3036,23 +3056,34 @@ define([], function () { updateSettings: function() { this.setCmbSidesOptions(true); this.setCmbPaperSizeOptions(); - this.cmbPrinter.setValue(null); }, - setCmbPrinterOptions: function(printers) { + updateCmbPrinter: function(currentPrinter, printers) { var cmbPrinterOptions = []; - if(printers) { - cmbPrinterOptions = printers.map(function(printer) { - return { - value: printer.name, - displayValue: printer.name, - paperSupported: printer.paper_supported, - isDuplexSupported: printer.duplex_supported - } + + printers = printers || []; + + //If the current printer is not in the list of printers, add it + if(currentPrinter && !_.some(printers, function(printer) { return printer.name == currentPrinter })) { + printers.push({ + name: currentPrinter, + duplex_supported: true, + paperSupported: this._defaultPaperSizeList }); } + cmbPrinterOptions = printers.map(function(printer) { + return { + value: printer.name, + displayValue: printer.name, + paperSupported: printer.paper_supported, + isDuplexSupported: printer.duplex_supported + } + }); + this.cmbPrinter.setData(cmbPrinterOptions); + this.cmbPrinter.setValue(currentPrinter); + this.cmbPrinter.trigger('selected', this, this.cmbPrinter.getSelectedRecord()); }, setCmbSidesOptions: function(isDuplexSupported) { @@ -3071,25 +3102,6 @@ define([], function () { }, setCmbPaperSizeOptions(paperSizeList) { - var defaultList = [ - { value: 0, displayValue: ['US Letter', '21,59', '27,94', 'cm'], caption: 'US Letter', size: [215.9, 279.4]}, - { value: 1, displayValue: ['US Legal', '21,59', '35,56', 'cm'], caption: 'US Legal', size: [215.9, 355.6]}, - { value: 2, displayValue: ['A4', '21', '29,7', 'cm'], caption: 'A4', size: [210, 297]}, - { value: 3, displayValue: ['A5', '14,8', '21', 'cm'], caption: 'A5', size: [148, 210]}, - { value: 4, displayValue: ['B5', '17,6', '25', 'cm'], caption: 'B5', size: [176, 250]}, - { value: 5, displayValue: ['Envelope #10', '10,48', '24,13', 'cm'], caption: 'Envelope #10', size: [104.8, 241.3]}, - { value: 6, displayValue: ['Envelope DL', '11', '22', 'cm'], caption: 'Envelope DL', size: [110, 220]}, - { value: 7, displayValue: ['Tabloid', '27,94', '43,18', 'cm'], caption: 'Tabloid', size: [279.4, 431.8]}, - { value: 8, displayValue: ['A3', '29,7', '42', 'cm'], caption: 'A3', size: [297, 420]}, - { value: 9, displayValue: ['Tabloid Oversize', '29,69', '45,72', 'cm'], caption: 'Tabloid Oversize', size: [296.9, 457.2]}, - { value: 10, displayValue: ['ROC 16K', '19,68', '27,3', 'cm'], caption: 'ROC 16K', size: [196.8, 273]}, - { value: 11, displayValue: ['Envelope Choukei 3', '12', '23,5', 'cm'], caption: 'Envelope Choukei 3', size: [120, 235]}, - { value: 12, displayValue: ['Super B/A3', '30,5', '48,7', 'cm'], caption: 'Super B/A3', size: [305, 487]}, - { value: 13, displayValue: ['A4', '84,1', '118,9', 'cm'], caption: 'A0', size: [841, 1189]}, - { value: 14, displayValue: ['A4', '59,4', '84,1', 'cm'], caption: 'A1', size: [594, 841]}, - { value: 16, displayValue: ['A4', '42', '59,4', 'cm'], caption: 'A2', size: [420, 594]}, - { value: 17, displayValue: ['A4', '10,5', '14,8', 'cm'], caption: 'A6', size: [105, 148]} - ]; var resultList = []; if(paperSizeList && paperSizeList.length > 0) { @@ -3102,7 +3114,7 @@ define([], function () { } }); } else { - resultList = defaultList; + resultList = this._defaultPaperSizeList; } resultList.push({ value: -1, displayValue: this.txtCustom, caption: this.txtCustom, size: []});