From 57c9c6268e7070917075e88ba5e39d47523c232a Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Sun, 18 Apr 2021 17:32:39 +0300 Subject: [PATCH] [common] extended theme's object --- apps/common/main/lib/controller/Themes.js | 85 ++++++++++--------- apps/common/main/lib/view/Header.js | 1 - .../main/app/view/FileMenuPanels.js | 19 +++-- apps/documenteditor/main/locale/en.json | 9 +- .../main/app/view/FileMenuPanels.js | 16 ++-- apps/presentationeditor/main/locale/en.json | 9 +- .../main/resources/less/app.less | 1 + .../main/app/view/FileMenuPanels.js | 16 ++-- apps/spreadsheeteditor/main/locale/en.json | 9 +- .../main/resources/less/app.less | 1 + 10 files changed, 93 insertions(+), 73 deletions(-) diff --git a/apps/common/main/lib/controller/Themes.js b/apps/common/main/lib/controller/Themes.js index 7a70c233e..d7e8cfdf6 100644 --- a/apps/common/main/lib/controller/Themes.js +++ b/apps/common/main/lib/controller/Themes.js @@ -7,24 +7,22 @@ define([ ], function () { 'use strict'; - Common.UI.Themes = new (function() { - var sdk_themes_alias = { - 'theme-light': 'flat', - 'theme-dark': 'flatDark' - }; - + Common.UI.Themes = new (function(locale) { + !locale && (locale = {}); + var id_default_theme = 'theme-classic-light'; var themes_map = { - 'theme-light': 'light', - 'theme-classic-light': 'light', - 'theme-dark': 'dark' - } - - sdk_themes_alias.contains = function (name) { - return !!this[name]; - } - - themes_map.contains = function (name) { - return !!this[name]; + 'theme-light': { + text: locale.txtThemeLight || 'Light', + type: 'light' + }, + 'theme-classic-light': { + text: locale.txtThemeClassicLight || 'Classic Light', + type: 'light' + }, + 'theme-dark': { + text: locale.txtThemeDark || 'Dark', + type: 'dark' + }, } var name_colors = [ @@ -128,10 +126,6 @@ define([ } return { - THEME_LIGHT_ID: 'theme-light', - THEME_CLASSIC_LIGHT_ID: 'theme-classic-light', - THEME_DARK_ID: 'theme-dark', - init: function (api) { var me = this; @@ -142,7 +136,7 @@ define([ }) this.api = api; - var theme_name = Common.localStorage.getItem('ui-theme', 'theme-light'); + var theme_name = Common.localStorage.getItem('ui-theme', id_default_theme); if ( !$('body').hasClass(theme_name) ) { $('body').addClass(theme_name); @@ -152,50 +146,57 @@ define([ obj.type = themes_map[theme_name]; obj.name = theme_name; api.asc_setSkin(obj); - - // app.eventbus.addListeners({ - // 'FileMenu': { - // 'settings:apply': function (menu) { - // } - // } - // }, {id: 'Themes'}); - - // getComputedStyle(document.documentElement).getPropertyValue('--background-normal'); }, available: function () { return !Common.Utils.isIE; }, - current: function () { - return Common.localStorage.getItem('ui-theme') || 'theme-light'; + map: function () { + return themes_map + }, + + get: function (id) { + return themes_map[id] + }, + + currentThemeId: function () { + return Common.localStorage.getItem('ui-theme') || id_default_theme; + }, + + defaultThemeId: function () { + return id_default_theme; + }, + + defaultTheme: function () { + return themes_map[id_default_theme] }, isDarkTheme: function () { return themes_map[this.current()] == 'dark'; }, - setTheme: function (name) { - if ( themes_map.contains(name) ) { + setTheme: function (id) { + if ( !!themes_map[id] ) { var classname = document.documentElement.className.replace(/theme-\w+\s?/, ''); document.body.className = classname; - $('body').addClass(name); + $('body').addClass(id); var obj = get_current_theme_colors(name_colors); - obj.type = themes_map[name]; - obj.name = name; + obj.type = themes_map[id].type; + obj.name = id; this.api.asc_setSkin(obj); - Common.localStorage.setItem('ui-theme', name); - Common.NotificationCenter.trigger('uitheme:changed', name); + Common.localStorage.setItem('ui-theme', id); + Common.NotificationCenter.trigger('uitheme:changed', id); } }, toggleTheme: function () { - this.setTheme(this.current() == 'theme-dark' ? 'theme-light' : 'theme-dark'); + this.setTheme(this.current() == 'theme-dark' ? id_default_theme : 'theme-dark'); } } - })(); + })(Common.UI.Themes); }); diff --git a/apps/common/main/lib/view/Header.js b/apps/common/main/lib/view/Header.js index cf2ef9395..60802aaae 100644 --- a/apps/common/main/lib/view/Header.js +++ b/apps/common/main/lib/view/Header.js @@ -782,7 +782,6 @@ define([ textAdvSettings: 'Advanced Settings', tipViewSettings: 'View Settings', textRemoveFavorite: 'Remove from Favorites', - textDarkTheme: 'Dark theme', textAddFavorite: 'Mark as favorite' } }(), Common.Views.Header || {})) diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 2ac8862ba..f097325a7 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -464,11 +464,6 @@ define([ style : 'width: 160px;', editable : false, cls : 'input-group-nr', - data : [ - { value: Common.UI.Themes.THEME_LIGHT_ID, displayValue: this.txtThemeLight }, - { value: Common.UI.Themes.THEME_CLASSIC_LIGHT_ID, displayValue: "Classic light" }, - { value: Common.UI.Themes.THEME_DARK_ID, displayValue: this.txtThemeDark } - ] }); $markup.find('.btn.primary').each(function(index, el){ @@ -601,8 +596,16 @@ define([ this.chPaste.setValue(Common.Utils.InternalSettings.get("de-settings-paste-button")); - item = this.cmbTheme.store.findWhere({value: Common.UI.Themes.current()}); - this.cmbTheme.setValue(item ? item.get('value') : Common.UI.Themes.THEME_LIGHT_ID); + var data = []; + for (var t in Common.UI.Themes.map()) { + data.push({value: t, displayValue: Common.UI.Themes.get(t).text}); + } + + if ( data.length ) { + this.cmbTheme.setData(data); + item = this.cmbTheme.store.findWhere({value: Common.UI.Themes.currentThemeId()}); + this.cmbTheme.setValue(item ? item.get('value') : Common.UI.Themes.defaultThemeId()); + } }, applySettings: function() { @@ -731,8 +734,6 @@ define([ strPasteButton: 'Show Paste Options button when content is pasted', txtProofing: 'Proofing', strTheme: 'Theme', - txtThemeLight: 'Light', - txtThemeDark: 'Dark', txtAutoCorrect: 'AutoCorrect options...' }, DE.Views.FileMenuPanels.Settings || {})); diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index d8a7e29a6..aa582576e 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -192,6 +192,9 @@ "Common.UI.Window.textInformation": "Information", "Common.UI.Window.textWarning": "Warning", "Common.UI.Window.yesButtonText": "Yes", + "Common.UI.Themes.txtThemeDark": "Dark", + "Common.UI.Themes.txtThemeLight": "Light", + "Common.UI.Themes.txtThemeClassicLight": "Classic Light", "Common.Utils.Metric.txtCm": "cm", "Common.Utils.Metric.txtPt": "pt", "Common.Views.About.txtAddress": "address: ", @@ -260,7 +263,7 @@ "Common.Views.Header.textAdvSettings": "Advanced settings", "Common.Views.Header.textBack": "Open file location", "Common.Views.Header.textCompactView": "Hide Toolbar", - "Common.Views.Header.textDarkTheme": "Dark theme", + "del_Common.Views.Header.textDarkTheme": "Dark theme", "Common.Views.Header.textHideLines": "Hide Rulers", "Common.Views.Header.textHideStatusBar": "Hide Status Bar", "Common.Views.Header.textRemoveFavorite": "Remove from Favorites", @@ -1716,8 +1719,8 @@ "DE.Views.FileMenuPanels.Settings.txtSpellCheck": "Spell Checking", "DE.Views.FileMenuPanels.Settings.txtStopMacros": "Disable All", "DE.Views.FileMenuPanels.Settings.txtStopMacrosDesc": "Disable all macros without a notification", - "DE.Views.FileMenuPanels.Settings.txtThemeDark": "Dark", - "DE.Views.FileMenuPanels.Settings.txtThemeLight": "Light", + "del_DE.Views.FileMenuPanels.Settings.txtThemeDark": "Dark", + "del_DE.Views.FileMenuPanels.Settings.txtThemeLight": "Light", "DE.Views.FileMenuPanels.Settings.txtWarnMacros": "Show Notification", "DE.Views.FileMenuPanels.Settings.txtWarnMacrosDesc": "Disable all macros with a notification", "DE.Views.FileMenuPanels.Settings.txtWin": "as Windows", diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index 05fc32092..c775fee34 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -403,10 +403,6 @@ define([ style : 'width: 160px;', editable : false, cls : 'input-group-nr', - data : [ - { value: Common.UI.Themes.THEME_LIGHT_ID, displayValue: this.txtThemeLight }, - { value: Common.UI.Themes.THEME_DARK_ID, displayValue: this.txtThemeDark } - ] }); $markup.find('.btn.primary').each(function(index, el){ @@ -529,8 +525,16 @@ define([ this.chPaste.setValue(Common.Utils.InternalSettings.get("pe-settings-paste-button")); - item = this.cmbTheme.store.findWhere({value: Common.UI.Themes.current()}); - this.cmbTheme.setValue(item ? item.get('value') : Common.UI.Themes.THEME_LIGHT_ID); + var data = []; + for (var t in Common.UI.Themes.map()) { + data.push({value: t, displayValue: Common.UI.Themes.get(t).text}); + } + + if ( data.length ) { + this.cmbTheme.setData(data); + item = this.cmbTheme.store.findWhere({value: Common.UI.Themes.currentThemeId()}); + this.cmbTheme.setValue(item ? item.get('value') : Common.UI.Themes.defaultThemeId()); + } }, applySettings: function() { diff --git a/apps/presentationeditor/main/locale/en.json b/apps/presentationeditor/main/locale/en.json index f25eeddf0..d5e1ce708 100644 --- a/apps/presentationeditor/main/locale/en.json +++ b/apps/presentationeditor/main/locale/en.json @@ -83,6 +83,9 @@ "Common.UI.Window.textInformation": "Information", "Common.UI.Window.textWarning": "Warning", "Common.UI.Window.yesButtonText": "Yes", + "Common.UI.Themes.txtThemeDark": "Dark", + "Common.UI.Themes.txtThemeLight": "Light", + "Common.UI.Themes.txtThemeClassicLight": "Classic Light", "Common.Utils.Metric.txtCm": "cm", "Common.Utils.Metric.txtPt": "pt", "Common.Views.About.txtAddress": "address: ", @@ -148,7 +151,7 @@ "Common.Views.Header.textAdvSettings": "Advanced settings", "Common.Views.Header.textBack": "Open file location", "Common.Views.Header.textCompactView": "Hide Toolbar", - "Common.Views.Header.textDarkTheme": "Dark theme", + "del_Common.Views.Header.textDarkTheme": "Dark theme", "Common.Views.Header.textHideLines": "Hide Rulers", "Common.Views.Header.textHideStatusBar": "Hide Status Bar", "Common.Views.Header.textRemoveFavorite": "Remove from Favorites", @@ -1352,8 +1355,8 @@ "PE.Views.FileMenuPanels.Settings.txtSpellCheck": "Spell Checking", "PE.Views.FileMenuPanels.Settings.txtStopMacros": "Disable All", "PE.Views.FileMenuPanels.Settings.txtStopMacrosDesc": "Disable all macros without a notification", - "PE.Views.FileMenuPanels.Settings.txtThemeDark": "Dark", - "PE.Views.FileMenuPanels.Settings.txtThemeLight": "Light", + "del_PE.Views.FileMenuPanels.Settings.txtThemeDark": "Dark", + "del_PE.Views.FileMenuPanels.Settings.txtThemeLight": "Light", "PE.Views.FileMenuPanels.Settings.txtWarnMacros": "Show Notification", "PE.Views.FileMenuPanels.Settings.txtWarnMacrosDesc": "Disable all macros with a notification", "PE.Views.FileMenuPanels.Settings.txtWin": "as Windows", diff --git a/apps/presentationeditor/main/resources/less/app.less b/apps/presentationeditor/main/resources/less/app.less index 5f1c42b0c..cb08bdcb4 100644 --- a/apps/presentationeditor/main/resources/less/app.less +++ b/apps/presentationeditor/main/resources/less/app.less @@ -10,6 +10,7 @@ // Bootstrap overwrite @import "../../../../common/main/resources/less/variables.less"; @import "../../../../common/main/resources/less/colors-table.less"; +@import "../../../../common/main/resources/less/colors-table-classic.less"; @import "../../../../common/main/resources/less/colors-table-dark.less"; // diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index a78bb458c..ded4333a6 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -1009,10 +1009,6 @@ define([ style : 'width: 160px;', editable : false, cls : 'input-group-nr', - data : [ - { value: Common.UI.Themes.THEME_LIGHT_ID, displayValue: this.txtThemeLight }, - { value: Common.UI.Themes.THEME_DARK_ID, displayValue: this.txtThemeDark } - ] }); $markup.find('.btn.primary').each(function(index, el){ @@ -1175,8 +1171,16 @@ define([ this.chPaste.setValue(Common.Utils.InternalSettings.get("sse-settings-paste-button")); - item = this.cmbTheme.store.findWhere({value: Common.UI.Themes.current()}); - this.cmbTheme.setValue(item ? item.get('value') : Common.UI.Themes.THEME_LIGHT_ID); + var data = []; + for (var t in Common.UI.Themes.map()) { + data.push({value: t, displayValue: Common.UI.Themes.get(t).text}); + } + + if ( data.length ) { + this.cmbTheme.setData(data); + item = this.cmbTheme.store.findWhere({value: Common.UI.Themes.currentThemeId()}); + this.cmbTheme.setValue(item ? item.get('value') : Common.UI.Themes.defaultThemeId()); + } }, applySettings: function() { diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index c8483be4b..32c9f8fdf 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -84,6 +84,9 @@ "Common.UI.Window.textInformation": "Information", "Common.UI.Window.textWarning": "Warning", "Common.UI.Window.yesButtonText": "Yes", + "Common.UI.Themes.txtThemeDark": "Dark", + "Common.UI.Themes.txtThemeLight": "Light", + "Common.UI.Themes.txtThemeClassicLight": "Classic Light", "Common.Utils.Metric.txtCm": "cm", "Common.Utils.Metric.txtPt": "pt", "Common.Views.About.txtAddress": "address: ", @@ -144,7 +147,7 @@ "Common.Views.Header.textAdvSettings": "Advanced settings", "Common.Views.Header.textBack": "Open file location", "Common.Views.Header.textCompactView": "Hide Toolbar", - "Common.Views.Header.textDarkTheme": "Dark theme", + "del_Common.Views.Header.textDarkTheme": "Dark theme", "Common.Views.Header.textHideLines": "Hide Rulers", "Common.Views.Header.textHideStatusBar": "Hide Status Bar", "Common.Views.Header.textRemoveFavorite": "Remove from Favorites", @@ -1938,8 +1941,8 @@ "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtRunMacrosDesc": "Enable all macros without a notification", "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtStopMacros": "Disable All", "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtStopMacrosDesc": "Disable all macros without a notification", - "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtThemeDark": "Dark", - "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtThemeLight": "Light", + "del_SSE.Views.FileMenuPanels.MainSettingsGeneral.txtThemeDark": "Dark", + "del_SSE.Views.FileMenuPanels.MainSettingsGeneral.txtThemeLight": "Light", "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtWarnMacros": "Show Notification", "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtWarnMacrosDesc": "Disable all macros with a notification", "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtWin": "as Windows", diff --git a/apps/spreadsheeteditor/main/resources/less/app.less b/apps/spreadsheeteditor/main/resources/less/app.less index fed2e5b4c..d0cd39be2 100644 --- a/apps/spreadsheeteditor/main/resources/less/app.less +++ b/apps/spreadsheeteditor/main/resources/less/app.less @@ -10,6 +10,7 @@ // Bootstrap overwrite @import "../../../../common/main/resources/less/variables.less"; @import "../../../../common/main/resources/less/colors-table.less"; +@import "../../../../common/main/resources/less/colors-table-classic.less"; @import "../../../../common/main/resources/less/colors-table-dark.less"; //