From 82dc591fd0afd031d691dac5e4e770cab48952fb Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Fri, 31 Jul 2020 20:34:55 +0300 Subject: [PATCH] [common] debug --- apps/common/Gateway.js | 4 +- apps/common/main/lib/controller/Desktop.js | 46 +++++++++++++++++++++- apps/common/main/lib/util/utils.js | 23 +++++++++-- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index bca4a0bc3..8a1ed817f 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -31,8 +31,8 @@ * */ -if (Common === undefined) { - var Common = {}; +if (window.Common === undefined) { + window.Common = {}; } Common.Gateway = new(function() { diff --git a/apps/common/main/lib/controller/Desktop.js b/apps/common/main/lib/controller/Desktop.js index 76700a078..bd396f0ad 100644 --- a/apps/common/main/lib/controller/Desktop.js +++ b/apps/common/main/lib/controller/Desktop.js @@ -37,7 +37,8 @@ */ define([ - 'core' + 'core', + 'backbone' ], function () { 'use strict'; @@ -56,6 +57,16 @@ define([ 'btn-save': 'save', 'btn-save-coauth': 'coauth', 'btn-synch': 'synch' }; + var _supported = [ + Asc.c_oAscFileType.TXT, + Asc.c_oAscFileType.ODT, + Asc.c_oAscFileType.DOCX, + Asc.c_oAscFileType.HTML, + Asc.c_oAscFileType.PDF, + Asc.c_oAscFileType.PDFA, + Asc.c_oAscFileType.DOTX, + Asc.c_oAscFileType.OTT + ]; if ( !!native ) { @@ -141,6 +152,37 @@ define([ } }; + window.onupdaterecents = function (params) { + var filemenu = webapp.getController('LeftMenu').getView('LeftMenu').getMenu('file'); + if ( !filemenu.panels['recent'] ) { + var store = filemenu.panels['recent'].viewRecentPicker.store; + } + + var _re_name = /([^\\/]+\.[a-zA-Z0-9]{3,})$/; + var _recent = []; + params.forEach(function(file) { + if ( _supported.includes(file.type) && _re_name.test(file.path) && + store && !store.findWhere('id', file.id) ) + { + var name = _re_name.exec(file.path)[1]; + var model = { + url: file.path, + id: file.id, + title: name, + folder: file.path.slice(0, file.path.length - name.length - 1), + fileType: file.type, + }; + + _recent.push(model); + } + }); + + if ( _recent.length ) + if ( !store ) + filemenu.panels['recent'] = (new webapp.Views.FileMenuPanels.RecentFiles({menu:filemenu, recent: _recent})).render(); + else store.add(_recent); + }; + window.on_native_message('editor:config', 'request'); if ( !!window.native_message_cmd ) { for ( var c in window.native_message_cmd ) { @@ -207,6 +249,8 @@ define([ maincontroller.warningDocumentIsLocked(); } } + + native.LocalFileRecents(); }); Common.NotificationCenter.on('action:undocking', function (opts) { diff --git a/apps/common/main/lib/util/utils.js b/apps/common/main/lib/util/utils.js index 948cbb4e3..d74899de3 100644 --- a/apps/common/main/lib/util/utils.js +++ b/apps/common/main/lib/util/utils.js @@ -38,7 +38,18 @@ if (Common.Utils === undefined) { Common.Utils = {}; } -Common.Utils = _.extend(new(function() { +function _extend_object(dest, source) { + if ( typeof _ != "undefined" ) { + return _.extend({}, dest, source); + } else + if ( !!Object ) { + return Object.assign({}, dest, source); + } + + return source; +} + +var utils = new(function() { var userAgent = navigator.userAgent.toLowerCase(), check = function(regex){ return regex.test(userAgent); @@ -221,7 +232,9 @@ Common.Utils = _.extend(new(function() { croppedGeometry: function() {return {left:0, top: Common.Utils.InternalSettings.get('window-inactive-area-top'), width: me.innerWidth, height: me.innerHeight - Common.Utils.InternalSettings.get('window-inactive-area-top')}} } -})(), Common.Utils || {}); +})(); + +Common.Utils = _extend_object(Common.Utils, utils); Common.Utils.ThemeColor = new(function() { return { @@ -306,7 +319,7 @@ Common.Utils.ThemeColor = new(function() { } })(); -Common.Utils.Metric = _.extend( new(function() { +var metrics = new(function() { var me = this; me.c_MetricUnits = { @@ -377,7 +390,9 @@ Common.Utils.Metric = _.extend( new(function() { return value; } } -})(), Common.Utils.Metric || {}); +})(); + +Common.Utils.Metric = _extend_object(Common.Utils.Metric, metrics); Common.Utils.RGBColor = function(colorString) { var r, g, b;