diff --git a/apps/presentationeditor/main/app/controller/LeftMenu.js b/apps/presentationeditor/main/app/controller/LeftMenu.js index 5f941717c..8d95869a1 100644 --- a/apps/presentationeditor/main/app/controller/LeftMenu.js +++ b/apps/presentationeditor/main/app/controller/LeftMenu.js @@ -79,7 +79,8 @@ define([ 'LeftMenu': { 'panel:show': _.bind(this.menuExpand, this), 'comments:show': _.bind(this.commentsShowHide, this, 'show'), - 'comments:hide': _.bind(this.commentsShowHide, this, 'hide') + 'comments:hide': _.bind(this.commentsShowHide, this, 'hide'), + 'search:aftershow': _.bind(this.onShowAfterSearch, this) }, 'FileMenu': { 'menu:hide': _.bind(this.menuFilesShowHide, this, 'hide'), @@ -648,10 +649,31 @@ define([ if ((!previewPanel || !previewPanel.isVisible()) && !this._state.no_slides) { Common.UI.Menu.Manager.hideAll(); var full_menu_pressed = this.leftMenu.btnAbout.pressed; - this.showSearchDlg(true,s); - this.leftMenu.btnSearch.toggle(true,true); this.leftMenu.btnAbout.toggle(false); full_menu_pressed && this.menuExpand(this.leftMenu.btnAbout, 'files', false); + + var selectedText = this.api.asc_GetSelectedText(); + if (this.isSearchPanelVisible()) { + selectedText && this.leftMenu.panelSearch.setFindText(selectedText); + this.leftMenu.panelSearch.focus(s); + return false; + } else if (this.getApplication().getController('Viewport').isSearchBarVisible()) { + if (s === 'replace') { + this.getApplication().getController('Viewport').header.btnSearch.toggle(false); + this.onShowHideSearch(true, this.getApplication().getController('Viewport').searchBar.inputSearch.val()); + } else { + selectedText && this.getApplication().getController('Viewport').searchBar.setText(selectedText); + this.getApplication().getController('Viewport').searchBar.focus(); + return false; + } + } else if (s === 'search') { + Common.NotificationCenter.trigger('search:show'); + return false; + } else { + this.onShowHideSearch(true, selectedText); + } + this.leftMenu.btnSearchBar.toggle(true,true); + this.leftMenu.panelSearch.focus(s); } return false; case 'save': @@ -682,6 +704,10 @@ define([ return false; case 'escape': // if (!this.leftMenu.isOpened()) return true; + var btnSearch = this.getApplication().getController('Viewport').header.btnSearch; + btnSearch.pressed && btnSearch.toggle(false); + this.leftMenu._state.isSearchOpen && (this.leftMenu._state.isSearchOpen = false); + // TODO: if ( this.leftMenu.menuFile.isVisible() ) { if (Common.UI.HintManager.needCloseFileMenu()) @@ -774,24 +800,37 @@ define([ } }, - onShowHideSearch: function (state, findText, action) { + onShowHideSearch: function (state, findText) { if (state) { Common.UI.Menu.Manager.hideAll(); - var mode = this.mode.isEdit && !this.viewmode ? (action || undefined) : 'no-replace'; - findText && this.leftMenu.panelSearch.setFindText(findText); - this.leftMenu.panelSearch.setSearchMode(mode); this.leftMenu.showMenu('advancedsearch'); + this.onShowAfterSearch(findText); } else { this.leftMenu.btnSearchBar.toggle(false, true); this.leftMenu.onBtnMenuClick(this.leftMenu.btnSearchBar); } }, + onShowAfterSearch: function (findText) { + var text = findText || this.api.asc_GetSelectedText(); + if (text) { + this.leftMenu.panelSearch.setFindText(text); + } else if (text !== undefined) { + this.leftMenu.panelSearch.setFindText(''); + } + this.leftMenu.panelSearch.focus(); + }, + onMenuSearchBar: function(obj, show) { if (show) { var mode = this.mode.isEdit && !this.viewmode ? undefined : 'no-replace'; this.leftMenu.panelSearch.setSearchMode(mode); } + this.leftMenu._state.isSearchOpen = show; + }, + + isSearchPanelVisible: function () { + return this.leftMenu._state.isSearchOpen; }, showHistory: function() { diff --git a/apps/presentationeditor/main/app/controller/Viewport.js b/apps/presentationeditor/main/app/controller/Viewport.js index 7eb4a417a..12ae69ce9 100644 --- a/apps/presentationeditor/main/app/controller/Viewport.js +++ b/apps/presentationeditor/main/app/controller/Viewport.js @@ -174,6 +174,7 @@ define([ Common.NotificationCenter.on('app:face', this.onAppShowed.bind(this)); Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this)); + Common.NotificationCenter.on('search:show', _.bind(this.onSearchShow, this)); }, onAppShowed: function (config) { @@ -343,7 +344,7 @@ define([ me.header.btnOptions.menu.on('item:click', me.onOptionsItemClick.bind(this)); } - me.header.btnSearch.on('click', me.onSearchClick.bind(this)); + me.header.btnSearch.on('toggle', me.onSearchToggle.bind(this)); }, onLayoutChanged: function(area) { @@ -514,22 +515,32 @@ define([ Common.localStorage.setBool('pe-hidden-notes', !bIsShow); }, - onSearchClick: function () { + onSearchShow: function () { + this.header.btnSearch && this.header.btnSearch.toggle(true); + }, + + onSearchToggle: function () { + var leftMenu = this.getApplication().getController('LeftMenu'); + if (leftMenu.isSearchPanelVisible()) { + this.header.btnSearch.toggle(false, true); + leftMenu.getView('LeftMenu').panelSearch.focus(); + return; + } if (!this.searchBar) { this.searchBar = new Common.UI.SearchBar({}); + this.searchBar.on('hide', _.bind(function () { + this.header.btnSearch.toggle(false, true); + }, this)); } if (this.header.btnSearch.pressed) { - if (this.searchBar.isVisible()) { - this.searchBar.focus(); - } else { - this.searchBar.show(); - } + this.searchBar.show(this.api.asc_GetSelectedText()); } else { this.searchBar.hide(); } - this.searchBar.on('hide', _.bind(function () { - this.header.btnSearch.toggle(false); - }, this)); + }, + + isSearchBarVisible: function () { + return this.searchBar && this.searchBar.isVisible(); }, textFitPage: 'Fit to Page', diff --git a/apps/presentationeditor/main/app/view/LeftMenu.js b/apps/presentationeditor/main/app/view/LeftMenu.js index 00c3a90b0..f3b8f98aa 100644 --- a/apps/presentationeditor/main/app/view/LeftMenu.js +++ b/apps/presentationeditor/main/app/view/LeftMenu.js @@ -255,6 +255,7 @@ define([ if (this.panelSearch) { if (this.btnSearchBar.pressed) { this.panelSearch.show(); + this.fireEvent('search:aftershow', this); } else { this.panelSearch.hide(); }