[common] lock/unlock header buttons on file menu events

This commit is contained in:
Maxim Kadushkin 2018-02-23 00:19:40 +03:00
parent 482a7d11bf
commit 39f29c5ef8
5 changed files with 104 additions and 11 deletions

View file

@ -630,6 +630,35 @@ define([
return this.btnSave;
},
lockHeaderBtns: function (alias, lock) {
var me = this;
if ( alias == 'users' ) {
if ( lock )
$btnUsers.addClass('disabled').attr('disabled', 'disabled'); else
$btnUsers.removeClass('disabled').attr('disabled', '');
} else {
function _lockButton(btn) {
if ( btn ) {
if ( lock ) {
btn.keepState = {
disabled: btn.isDisabled()
};
} else {
btn.setDisabled( btn.keepState.disabled );
delete me.btnUndo.keepState;
}
}
}
if ( alias == 'undo' ) {
_lockButton(me.btnUndo);
} else
if ( alias == 'redo' ) {
_lockButton(me.btnRedo);
}
}
},
textBack: 'Go to Documents',
txtRename: 'Rename',
textSaveBegin: 'Saving...',

View file

@ -168,6 +168,11 @@
cursor: pointer;
font-size: 14px;
}
&.disabled {
opacity: 0.65;
pointer-events: none;
}
}
.cousers-menu {
@ -180,6 +185,12 @@
width: 285px;
font-size: 12px;
z-index: 1042;
.top-title & {
top: @height-title + @height-tabs - 8px;
}
> label {
white-space: normal;
}

View file

@ -68,6 +68,10 @@ define([
var me = this;
this.addListeners({
'FileMenu': {
'menu:hide': me.onFileMenu.bind(me, 'hide'),
'menu:show': me.onFileMenu.bind(me, 'show')
},
'Toolbar': {
'render:before' : function (toolbar) {
var config = DE.getController('Main').appOptions;
@ -79,12 +83,17 @@ define([
Common.Utils.InternalSettings.get('toolbar-height-compact') : Common.Utils.InternalSettings.get('toolbar-height-normal');
},
'undo:disabled' : function (state) {
if ( me.header.btnUndo )
me.header.btnUndo.setDisabled(state);
if ( me.header.btnUndo ) {
if ( me.header.btnUndo.keepState )
me.header.btnUndo.keepState.disabled = state;
else me.header.btnUndo.setDisabled(state);
}
},
'redo:disabled' : function (state) {
if ( me.header.btnRedo )
me.header.btnRedo.setDisabled(state);
if ( me.header.btnRedo.keepState )
me.header.btnRedo.keepState.disabled = state;
else me.header.btnRedo.setDisabled(state);
},
'save:disabled' : function (state) {
if ( me.header.btnSave )
@ -197,6 +206,14 @@ define([
onWindowResize: function(e) {
this.onLayoutChanged('window');
Common.NotificationCenter.trigger('window:resize');
},
onFileMenu: function (opts) {
var me = this;
var _need_disable = opts == 'show';
me.header.lockHeaderBtns( 'undo', _need_disable );
me.header.lockHeaderBtns( 'redo', _need_disable );
}
});
});

View file

@ -69,6 +69,10 @@ define([
// This most important part when we will tell our controller what events should be handled
this.addListeners({
'FileMenu': {
'menu:hide': me.onFileMenu.bind(me, 'hide'),
'menu:show': me.onFileMenu.bind(me, 'show')
},
'Toolbar': {
'render:before' : function (toolbar) {
var config = PE.getController('Main').appOptions;
@ -80,12 +84,18 @@ define([
Common.Utils.InternalSettings.get('toolbar-height-compact') : Common.Utils.InternalSettings.get('toolbar-height-normal');
},
'undo:disabled' : function (state) {
if ( me.header.btnUndo )
me.header.btnUndo.setDisabled(state);
if ( me.header.btnUndo ) {
if ( me.header.btnUndo.keepState )
me.header.btnUndo.keepState.disabled = state;
else me.header.btnUndo.setDisabled(state);
}
},
'redo:disabled' : function (state) {
if ( me.header.btnRedo )
me.header.btnRedo.setDisabled(state);
if ( me.header.btnRedo ) {
if ( me.header.btnRedo.keepState )
me.header.btnRedo.keepState.disabled = state;
else me.header.btnRedo.setDisabled(state);
}
},
'save:disabled' : function (state) {
if ( me.header.btnSave )
@ -236,6 +246,14 @@ define([
element.msRequestFullscreen();
}
}
},
onFileMenu: function (opts) {
var me = this;
var _need_disable = opts == 'show';
me.header.lockHeaderBtns( 'undo', _need_disable );
me.header.lockHeaderBtns( 'redo', _need_disable );
}
});
});

View file

@ -67,6 +67,10 @@ define([
// This most important part when we will tell our controller what events should be handled
this.addListeners({
'FileMenu': {
'menu:hide': me.onFileMenu.bind(me, 'hide'),
'menu:show': me.onFileMenu.bind(me, 'show')
},
'Toolbar': {
'render:before' : function (toolbar) {
var config = SSE.getController('Main').appOptions;
@ -78,12 +82,18 @@ define([
Common.Utils.InternalSettings.get('toolbar-height-compact') : Common.Utils.InternalSettings.get('toolbar-height-normal');
},
'undo:disabled' : function (state) {
if ( me.header.btnUndo )
me.header.btnUndo.setDisabled(state);
if ( me.header.btnUndo ) {
if ( me.header.btnUndo.keepState )
me.header.btnUndo.keepState.disabled = state;
else me.header.btnUndo.setDisabled(state);
}
},
'redo:disabled' : function (state) {
if ( me.header.btnRedo )
me.header.btnRedo.setDisabled(state);
if ( me.header.btnRedo ) {
if ( me.header.btnRedo.keepState )
me.header.btnRedo.keepState.disabled = state;
else me.header.btnRedo.setDisabled(state);
}
},
'save:disabled' : function (state) {
if ( me.header.btnSave )
@ -205,6 +215,14 @@ define([
onWindowResize: function(e) {
this.onLayoutChanged('window');
Common.NotificationCenter.trigger('window:resize');
},
onFileMenu: function (opts) {
var me = this;
var _need_disable = opts == 'show';
me.header.lockHeaderBtns( 'undo', _need_disable );
me.header.lockHeaderBtns( 'redo', _need_disable );
}
});
});