From 80e2955f8ce7922b18ca1f93b65ef392fedd04fb Mon Sep 17 00:00:00 2001 From: abakkk Date: Wed, 5 Aug 2020 02:49:52 +0200 Subject: [PATCH] fix menu item name and sensitivity stynchronization --- area.js | 8 +++++--- menu.js | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/area.js b/area.js index 0b3ad26..e8e220b 100644 --- a/area.js +++ b/area.js @@ -1074,7 +1074,7 @@ var DrawingArea = new Lang.Class({ } }, - _saveAsJson: function(name, notify) { + _saveAsJson: function(name, notify, callback) { // stop drawing or writing if (this.currentElement && this.currentElement.shape == Shapes.TEXT && this.isWriting) { this._stopWriting(); @@ -1107,11 +1107,13 @@ var DrawingArea = new Lang.Class({ this.jsonName = name; this.lastJsonContents = contents; } + if (callback) + callback(); }); }, - saveAsJsonWithName: function(name) { - this._saveAsJson(name); + saveAsJsonWithName: function(name, callback) { + this._saveAsJson(name, false, callback); }, saveAsJson: function() { diff --git a/menu.js b/menu.js index 0a09f03..1c64232 100644 --- a/menu.js +++ b/menu.js @@ -420,6 +420,7 @@ var DrawingMenu = new Lang.Class({ _addOpenDrawingSubMenuItem: function(menu) { let item = new PopupMenu.PopupSubMenuMenuItem(_("Open drawing"), true); this.openDrawingSubMenuItem = item; + this.openDrawingSubMenuItem.setSensitive(Boolean(Files.getJsons().length)); this.openDrawingSubMenu = item.menu; item.icon.set_icon_name('document-open-symbolic'); @@ -463,6 +464,7 @@ var DrawingMenu = new Lang.Class({ deleteButton.connect('clicked', () => { json.delete(); 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); }, + _onDrawingSaved() { + this._updateDrawingNameMenuItem(); + this.openDrawingSubMenuItem.setSensitive(true); + }, + _populateSaveDrawingSubMenu: function() { this.saveDrawingSubMenu.removeAll(); let saveEntry = new DrawingMenuEntry({ initialTextGetter: Files.getDateString, entryActivateCallback: (text) => { - this.area.saveAsJsonWithName(text); + this.area.saveAsJsonWithName(text, this._onDrawingSaved.bind(this)); this.saveDrawingSubMenu.toggle(); - this._updateDrawingNameMenuItem(); }, invalidStrings: [Me.metadata['persistent-file-name'], '/'], primaryIconName: 'insert-text' });