From 730ea07cc6e153b4239d6b45b9f3e4e10b8a1973 Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Fri, 3 Jun 2022 22:03:29 +0300 Subject: [PATCH] [themes] fix for View tab --- .../main/app/controller/ViewTab.js | 32 ++++++++++++------- .../main/app/controller/ViewTab.js | 31 +++++++++++------- .../main/app/view/ViewTab.js | 31 +++++++++++------- 3 files changed, 59 insertions(+), 35 deletions(-) diff --git a/apps/documenteditor/main/app/controller/ViewTab.js b/apps/documenteditor/main/app/controller/ViewTab.js index 07567b2a50..0a3ca29687 100644 --- a/apps/documenteditor/main/app/controller/ViewTab.js +++ b/apps/documenteditor/main/app/controller/ViewTab.js @@ -157,20 +157,28 @@ define([ }); if (Common.UI.Themes.available()) { - var menuItems = [], - currentTheme = Common.UI.Themes.currentThemeId() || Common.UI.Themes.defaultThemeId(); - for (var t in Common.UI.Themes.map()) { - menuItems.push({ - value: t, - caption: Common.UI.Themes.get(t).text, - checked: t === currentTheme, - checkable: true, - toggleGroup: 'interface-theme' - }); + function _fill_themes() { + var btn = this.view.btnInterfaceTheme; + if ( typeof(btn.menu) == 'object' ) btn.menu.removeAll(); + else btn.setMenu(new Common.UI.Menu()); + + var currentTheme = Common.UI.Themes.currentThemeId() || Common.UI.Themes.defaultThemeId(); + for (var t in Common.UI.Themes.map()) { + btn.menu.addItem({ + value: t, + caption: Common.UI.Themes.get(t).text, + checked: t === currentTheme, + checkable: true, + toggleGroup: 'interface-theme' + }); + } } - if (menuItems.length) { - me.view.btnInterfaceTheme.setMenu(new Common.UI.Menu({items: menuItems})); + Common.NotificationCenter.on('uitheme:countchanged', _fill_themes.bind(me)); + _fill_themes.call(me); + + if (me.view.btnInterfaceTheme.menu.items.length) { + // me.view.btnInterfaceTheme.setMenu(new Common.UI.Menu({items: menuItems})); me.view.btnInterfaceTheme.menu.on('item:click', _.bind(function (menu, item) { var value = item.value; Common.UI.Themes.setTheme(value); diff --git a/apps/presentationeditor/main/app/controller/ViewTab.js b/apps/presentationeditor/main/app/controller/ViewTab.js index 4e2249cf4a..f8cecce5d4 100644 --- a/apps/presentationeditor/main/app/controller/ViewTab.js +++ b/apps/presentationeditor/main/app/controller/ViewTab.js @@ -177,20 +177,27 @@ define([ }); if (Common.UI.Themes.available()) { - var menuItems = [], - currentTheme = Common.UI.Themes.currentThemeId() || Common.UI.Themes.defaultThemeId(); - for (var t in Common.UI.Themes.map()) { - menuItems.push({ - value: t, - caption: Common.UI.Themes.get(t).text, - checked: t === currentTheme, - checkable: true, - toggleGroup: 'interface-theme' - }); + function _fill_themes() { + var btn = this.view.btnInterfaceTheme; + if ( typeof(btn.menu) == 'object' ) btn.menu.removeAll(); + else btn.setMenu(new Common.UI.Menu()); + + var currentTheme = Common.UI.Themes.currentThemeId() || Common.UI.Themes.defaultThemeId(); + for (var t in Common.UI.Themes.map()) { + btn.menu.addItem({ + value: t, + caption: Common.UI.Themes.get(t).text, + checked: t === currentTheme, + checkable: true, + toggleGroup: 'interface-theme' + }); + } } - if (menuItems.length) { - this.view.btnInterfaceTheme.setMenu(new Common.UI.Menu({items: menuItems})); + Common.NotificationCenter.on('uitheme:countchanged', _fill_themes.bind(me)); + _fill_themes.call(me); + + if (me.view.btnInterfaceTheme.menu.items.length) { this.view.btnInterfaceTheme.menu.on('item:click', _.bind(function (menu, item) { var value = item.value; Common.UI.Themes.setTheme(value); diff --git a/apps/spreadsheeteditor/main/app/view/ViewTab.js b/apps/spreadsheeteditor/main/app/view/ViewTab.js index b095bf02c9..70df8db8f0 100644 --- a/apps/spreadsheeteditor/main/app/view/ViewTab.js +++ b/apps/spreadsheeteditor/main/app/view/ViewTab.js @@ -401,18 +401,27 @@ define([ } } if (Common.UI.Themes.available()) { - var menuItems = [], - currentTheme = Common.UI.Themes.currentThemeId() || Common.UI.Themes.defaultThemeId(); - for (var t in Common.UI.Themes.map()) { - menuItems.push({ - value: t, - caption: Common.UI.Themes.get(t).text, - checked: t === currentTheme, - checkable: true, - toggleGroup: 'interface-theme' - }); + function _fill_themes() { + var btn = this.btnInterfaceTheme; + if ( typeof(btn.menu) == 'object' ) btn.menu.removeAll(); + else btn.setMenu(new Common.UI.Menu()); + + var currentTheme = Common.UI.Themes.currentThemeId() || Common.UI.Themes.defaultThemeId(); + for (var t in Common.UI.Themes.map()) { + btn.menu.addItem({ + value: t, + caption: Common.UI.Themes.get(t).text, + checked: t === currentTheme, + checkable: true, + toggleGroup: 'interface-theme' + }); + } } - if (menuItems.length) { + + Common.NotificationCenter.on('uitheme:countchanged', _fill_themes.bind(me)); + _fill_themes.call(me); + + if (me.view.btnInterfaceTheme.menu.items.length) { me.btnInterfaceTheme.setMenu(new Common.UI.Menu({items: menuItems})); me.btnInterfaceTheme.menu.on('item:click', _.bind(function (menu, item) { var value = item.value;