fix menu item name and sensitivity stynchronization

This commit is contained in:
abakkk 2020-08-05 02:49:52 +02:00
parent 408929848d
commit 80e2955f8c
2 changed files with 13 additions and 5 deletions

View File

@ -1074,7 +1074,7 @@ var DrawingArea = new Lang.Class({
} }
}, },
_saveAsJson: function(name, notify) { _saveAsJson: function(name, notify, callback) {
// stop drawing or writing // stop drawing or writing
if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.isWriting) { if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.isWriting) {
this._stopWriting(); this._stopWriting();
@ -1107,11 +1107,13 @@ var DrawingArea = new Lang.Class({
this.jsonName = name; this.jsonName = name;
this.lastJsonContents = contents; this.lastJsonContents = contents;
} }
if (callback)
callback();
}); });
}, },
saveAsJsonWithName: function(name) { saveAsJsonWithName: function(name, callback) {
this._saveAsJson(name); this._saveAsJson(name, false, callback);
}, },
saveAsJson: function() { saveAsJson: function() {

10
menu.js
View File

@ -420,6 +420,7 @@ var DrawingMenu = new Lang.Class({
_addOpenDrawingSubMenuItem: function(menu) { _addOpenDrawingSubMenuItem: function(menu) {
let item = new PopupMenu.PopupSubMenuMenuItem(_("Open drawing"), true); let item = new PopupMenu.PopupSubMenuMenuItem(_("Open drawing"), true);
this.openDrawingSubMenuItem = item; this.openDrawingSubMenuItem = item;
this.openDrawingSubMenuItem.setSensitive(Boolean(Files.getJsons().length));
this.openDrawingSubMenu = item.menu; this.openDrawingSubMenu = item.menu;
item.icon.set_icon_name('document-open-symbolic'); item.icon.set_icon_name('document-open-symbolic');
@ -463,6 +464,7 @@ var DrawingMenu = new Lang.Class({
deleteButton.connect('clicked', () => { deleteButton.connect('clicked', () => {
json.delete(); json.delete();
item.destroy(); item.destroy();
this.openDrawingSubMenuItem.setSensitive(!this.openDrawingSubMenu.isEmpty());
}); });
}); });
@ -493,13 +495,17 @@ var DrawingMenu = new Lang.Class({
this.saveDrawingSubMenuItem.setSensitive(this.area.elements.length > 0); this.saveDrawingSubMenuItem.setSensitive(this.area.elements.length > 0);
}, },
_onDrawingSaved() {
this._updateDrawingNameMenuItem();
this.openDrawingSubMenuItem.setSensitive(true);
},
_populateSaveDrawingSubMenu: function() { _populateSaveDrawingSubMenu: function() {
this.saveDrawingSubMenu.removeAll(); this.saveDrawingSubMenu.removeAll();
let saveEntry = new DrawingMenuEntry({ initialTextGetter: Files.getDateString, let saveEntry = new DrawingMenuEntry({ initialTextGetter: Files.getDateString,
entryActivateCallback: (text) => { entryActivateCallback: (text) => {
this.area.saveAsJsonWithName(text); this.area.saveAsJsonWithName(text, this._onDrawingSaved.bind(this));
this.saveDrawingSubMenu.toggle(); this.saveDrawingSubMenu.toggle();
this._updateDrawingNameMenuItem();
}, },
invalidStrings: [Me.metadata['persistent-file-name'], '/'], invalidStrings: [Me.metadata['persistent-file-name'], '/'],
primaryIconName: 'insert-text' }); primaryIconName: 'insert-text' });