[desktop] send 'save' button changed icon

This commit is contained in:
Maxim Kadushkin 2019-11-05 15:28:33 +03:00
parent a0616e8f17
commit a72d14d421
4 changed files with 40 additions and 9 deletions

View file

@ -648,6 +648,24 @@ define([
btnIconEl.addClass(cls || '');
},
changeIcon: function(opts) {
var me = this;
if ( opts && (opts.prev || opts.next)) {
!!opts.prev && (me.$icon.removeClass(opts.prev));
!!opts.next && !me.$icon.hasClass(opts.next) && (me.$icon.addClass(opts.next));
if ( !!me.options.signals ) {
if ( !(me.options.signals.indexOf('icon:changed') < 0) ) {
me.trigger('icon:changed', me, opts);
}
}
}
},
hasIcon: function(iconcls) {
return this.$icon.hasClass(iconcls);
},
setVisible: function(visible) {
if (this.cmpEl) this.cmpEl.toggleClass('hidden', !visible);
this.visible = visible;

View file

@ -46,6 +46,11 @@ define([
var app = window.AscDesktopEditor,
webapp = window.DE || window.PE || window.SSE;
var titlebuttons;
var btnsave_icons = {
'btn-save': 'save',
'btn-save-coauth': 'coauth',
'btn-synch': 'synch' };
if ( !!app ) {
window.on_native_message = function (cmd, param) {
@ -116,8 +121,7 @@ define([
var _serializeHeaderButton = function(action, config) {
return {
action: action,
width: config.btn.$el.width(),
height: config.btn.$el.height(),
icon: config.icon || undefined,
hint: config.btn.options.hint,
disabled: config.disabled
};
@ -130,6 +134,10 @@ define([
app.execCommand('title:button', JSON.stringify({disabled: _buttons}));
};
var _onSaveIconChanged = function (e, opts) {
app.execCommand('title:button', JSON.stringify({'icon:changed': {'save': btnsave_icons[opts.next]}}));
};
var _onModalDialog = function (status) {
if ( status == 'open' ) {
app.execCommand('title:button', JSON.stringify({disabled: {'all':true}}));
@ -176,6 +184,12 @@ define([
titlebuttons[i].btn.options.signals = ['disabled'];
titlebuttons[i].btn.on('disabled', _onTitleButtonDisabled.bind(this, i));
}
header.btnSave.options.signals.push('icon:changed');
header.btnSave.on('icon:changed', _onSaveIconChanged.bind(this));
var iconname = /\s?([^\s]+)$/.exec(titlebuttons.save.btn.$icon.attr('class'));
!!iconname && iconname.length && (titlebuttons.save.icon = btnsave_icons[iconname]);
});
Common.NotificationCenter.on({

View file

@ -527,7 +527,7 @@ define([
me.btnRedo = createTitleButton('svg-btn-redo', $html.findById('#slot-btn-dt-redo'), true);
if ( me.btnSave.$icon.is('svg') ) {
me.btnSave.$icon.addClass('icon-save');
me.btnSave.$icon.addClass('icon-save btn-save');
var _create_use = function (extid, intid) {
var _use = document.createElementNS('http://www.w3.org/2000/svg', 'use');
_use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', extid);

View file

@ -2025,7 +2025,7 @@ define([
}
this._state.hasCollaborativeChanges = true;
this.btnCollabChanges.$icon.removeClass(this.btnSaveCls).addClass('btn-synch');
this.btnCollabChanges.changeIcon({prev:this.btnSaveCls, next:'btn-synch'});
if (this.showSynchTip) {
this.btnCollabChanges.updateHint('');
if (this.synchTooltip === undefined)
@ -2061,8 +2061,8 @@ define([
if ( !this._state.previewmode && this.btnCollabChanges.rendered ) {
var me = this;
if ( me.btnCollabChanges.$icon.hasClass('btn-synch') ) {
me.btnCollabChanges.$icon.removeClass('btn-synch').addClass(me.btnSaveCls);
if ( me.btnCollabChanges.isIcon('btn-synch') ) {
me.btnCollabChanges.changeIcon({prev:'btn-synch', next:me.btnSaveCls});
if (this.synchTooltip)
this.synchTooltip.hide();
this.btnCollabChanges.updateHint(this.btnSaveTip);
@ -2086,10 +2086,9 @@ define([
if ( cls !== me.btnSaveCls && me.btnCollabChanges.rendered ) {
me.btnSaveTip = ((length > 1) ? me.tipSaveCoauth : me.tipSave ) + Common.Utils.String.platformKey('Ctrl+S');
if ( !me.btnCollabChanges.$icon.hasClass('btn-synch') ) {
me.btnCollabChanges.$icon.removeClass(me.btnSaveCls).addClass(cls);
if ( !me.btnCollabChanges.isIcon('btn-synch') ) {
me.btnCollabChanges.changeIcon({prev:me.btnSaveCls, next:cls});
me.btnCollabChanges.updateHint(me.btnSaveTip);
}
me.btnSaveCls = cls;
}