From 24682db69c4efb9e7131e8c3b253cc9d69c93183 Mon Sep 17 00:00:00 2001 From: abakkk Date: Sat, 12 Sep 2020 01:25:37 +0200 Subject: [PATCH] add a lot of icons * Complete Files.Icons. * Add a lot of icons in the menu and the osd notifications. --- area.js | 51 +++++++----- data/icons/arc-symbolic.svg | 7 ++ data/icons/tool-ellipse-symbolic.svg | 7 ++ data/icons/tool-line-symbolic.svg | 7 ++ data/icons/tool-move-symbolic.svg | 14 ++++ data/icons/tool-none-symbolic.svg | 14 ++++ data/icons/tool-polygon-symbolic.svg | 8 ++ data/icons/tool-polyline-symbolic.svg | 9 +++ data/icons/tool-rectangle-symbolic.svg | 7 ++ data/icons/tool-resize-symbolic.svg | 17 ++++ files.js | 32 +++++--- menu.js | 105 ++++++++++++++----------- 12 files changed, 204 insertions(+), 74 deletions(-) create mode 100644 data/icons/arc-symbolic.svg create mode 100644 data/icons/tool-ellipse-symbolic.svg create mode 100644 data/icons/tool-line-symbolic.svg create mode 100644 data/icons/tool-move-symbolic.svg create mode 100644 data/icons/tool-none-symbolic.svg create mode 100644 data/icons/tool-polygon-symbolic.svg create mode 100644 data/icons/tool-polyline-symbolic.svg create mode 100644 data/icons/tool-rectangle-symbolic.svg create mode 100644 data/icons/tool-resize-symbolic.svg diff --git a/area.js b/area.js index 1978efb..85fa316 100644 --- a/area.js +++ b/area.js @@ -55,7 +55,12 @@ const { DisplayStrings } = Menu; const FontGenericFamilies = ['Sans-Serif', 'Serif', 'Monospace', 'Cursive', 'Fantasy']; const Manipulations = { MOVE: 100, RESIZE: 101, MIRROR: 102 }; -var Tools = Object.assign({}, Shapes, Manipulations); +var Tools = Object.assign({ + getNameOf: function(value) { + return Object.keys(this).find(key => this[key] == value); + } +}, Shapes, Manipulations); +Object.defineProperty(Tools, 'getNameOf', { enumerable: false }); const getClutterColorFromString = function(string, fallback) { let [success, color] = Clutter.Color.from_string(string); @@ -397,8 +402,8 @@ var DrawingArea = new Lang.Class({ event.get_key_symbol() == Clutter.KEY_Control_L) { if (this.currentElement.points.length == 2) // Translators: %s is a key label - this.emit('show-osd', null, _("Press %s to get\na fourth control point") - .format(Gtk.accelerator_get_label(Clutter.KEY_Return, 0)), "", -1, true); + this.emit('show-osd', Files.Icons.ARC, _("Press %s to get\na fourth control point") + .format(Gtk.accelerator_get_label(Clutter.KEY_Return, 0)), "", -1, true); this.currentElement.addPoint(); this.updatePointerCursor(true); this._redisplay(); @@ -495,7 +500,7 @@ var DrawingArea = new Lang.Class({ if (this.grabbedElementLocked) { this.updatePointerCursor(); let label = controlPressed ? _("Mark a point of symmetry") : _("Draw a line of symmetry"); - this.emit('show-osd', null, label, "", -1, true); + this.emit('show-osd', Files.Icons.TOOL_MIRROR, label, "", -1, true); return; } } @@ -628,10 +633,12 @@ var DrawingArea = new Lang.Class({ this.currentElement.startDrawing(startX, startY); - if (this.currentTool == Shapes.POLYGON || this.currentTool == Shapes.POLYLINE) + if (this.currentTool == Shapes.POLYGON || this.currentTool == Shapes.POLYLINE) { + let icon = Files.Icons[this.currentTool == Shapes.POLYGON ? 'TOOL_POLYGON' : 'TOOL_POLYLINE']; // Translators: %s is a key label - this.emit('show-osd', null, _("Press %s to mark vertices") + this.emit('show-osd', icon, _("Press %s to mark vertices") .format(Gtk.accelerator_get_label(Clutter.KEY_Return, 0)), "", -1, true); + } this.motionHandler = this.connect('motion-event', (actor, event) => { if (this.spaceKeyPressed) @@ -692,8 +699,8 @@ var DrawingArea = new Lang.Class({ this.currentElement.text = ''; this.currentElement.cursorPosition = 0; // Translators: %s is a key label - this.emit('show-osd', null, _("Type your text and press %s") - .format(Gtk.accelerator_get_label(Clutter.KEY_Escape, 0)), "", -1, true); + this.emit('show-osd', Files.Icons.TOOL_TEXT, _("Type your text and press %s") + .format(Gtk.accelerator_get_label(Clutter.KEY_Escape, 0)), "", -1, true); this._updateTextCursorTimeout(); this.textHasCursor = true; this._redisplay(); @@ -897,23 +904,25 @@ var DrawingArea = new Lang.Class({ this._redisplay(); } // Foreground color markup is not displayed since 3.36, use style instead but the transparency is lost. - this.emit('show-osd', null, this.currentColor.string || this.currentColor.to_string(), this.currentColor.to_string().slice(0, 7), -1, false); + this.emit('show-osd', Files.Icons.COLOR, this.currentColor.string || this.currentColor.to_string(), this.currentColor.to_string().slice(0, 7), -1, false); }, selectTool: function(tool) { this.currentTool = tool; - this.emit('show-osd', null, DisplayStrings.Tool[tool], "", -1, false); + this.emit('show-osd', Files.Icons[`TOOL_${Tools.getNameOf(tool)}`] || null, DisplayStrings.Tool[tool], "", -1, false); this.updatePointerCursor(); }, switchFill: function() { this.fill = !this.fill; - this.emit('show-osd', null, DisplayStrings.getFill(this.fill), "", -1, false); + let icon = Files.Icons[this.fill ? 'FILL' : 'STROKE']; + this.emit('show-osd', icon, DisplayStrings.getFill(this.fill), "", -1, false); }, switchFillRule: function() { this.currentFillRule = this.currentFillRule == 1 ? 0 : this.currentFillRule + 1; - this.emit('show-osd', null, DisplayStrings.FillRule[this.currentFillRule], "", -1, false); + let icon = Files.Icons[this.currentEvenodd ? 'FILLRULE_EVENODD' : 'FILLRULE_NONZERO']; + this.emit('show-osd', icon, DisplayStrings.FillRule[this.currentFillRule], "", -1, false); }, switchColorPalette: function(reverse) { @@ -922,12 +931,13 @@ var DrawingArea = new Lang.Class({ this.currentPalette = index <= 0 ? this.palettes[this.palettes.length - 1] : this.palettes[index - 1]; else this.currentPalette = index == this.palettes.length - 1 ? this.palettes[0] : this.palettes[index + 1]; - this.emit('show-osd', null, this.currentPalette[0], "", -1, false); + this.emit('show-osd', Files.Icons.PALETTE, this.currentPalette[0], "", -1, false); }, switchDash: function() { this.dashedLine = !this.dashedLine; - this.emit('show-osd', null, DisplayStrings.getDashedLine(this.dashedLine), "", -1, false); + let icon = Files.Icons[this.dashedLine ? 'DASHED_LINE' : 'FULL_LINE']; + this.emit('show-osd', icon, DisplayStrings.getDashedLine(this.dashedLine), "", -1, false); }, incrementLineWidth: function(increment) { @@ -937,12 +947,12 @@ var DrawingArea = new Lang.Class({ switchLineJoin: function() { this.currentLineJoin = this.currentLineJoin == 2 ? 0 : this.currentLineJoin + 1; - this.emit('show-osd', null, DisplayStrings.LineJoin[this.currentLineJoin], "", -1, false); + this.emit('show-osd', Files.Icons.LINEJOIN, DisplayStrings.LineJoin[this.currentLineJoin], "", -1, false); }, switchLineCap: function() { this.currentLineCap = this.currentLineCap == 2 ? 0 : this.currentLineCap + 1; - this.emit('show-osd', null, DisplayStrings.LineCap[this.currentLineCap], "", -1, false); + this.emit('show-osd', Files.Icons.LINECAP, DisplayStrings.LineCap[this.currentLineCap], "", -1, false); }, switchFontWeight: function() { @@ -953,7 +963,7 @@ var DrawingArea = new Lang.Class({ this.currentElement.font.set_weight(this.currentFontWeight); this._redisplay(); } - this.emit('show-osd', null, `` + + this.emit('show-osd', Files.Icons.FONT_WEIGHT, `` + `${DisplayStrings.FontWeight[this.currentFontWeight]}`, "", -1, false); }, @@ -963,7 +973,7 @@ var DrawingArea = new Lang.Class({ this.currentElement.font.set_style(this.currentFontStyle); this._redisplay(); } - this.emit('show-osd', null, `` + + this.emit('show-osd', Files.Icons.FONT_STYLE, `` + `${DisplayStrings.FontStyle[this.currentFontStyle]}`, "", -1, false); }, @@ -977,7 +987,7 @@ var DrawingArea = new Lang.Class({ this.currentElement.font.set_family(this.currentFontFamily); this._redisplay(); } - this.emit('show-osd', null, `${DisplayStrings.getFontFamily(this.currentFontFamily)}`, "", -1, false); + this.emit('show-osd', Files.Icons.FONT_FAMILY, `${DisplayStrings.getFontFamily(this.currentFontFamily)}`, "", -1, false); }, switchTextAlignment: function() { @@ -986,7 +996,8 @@ var DrawingArea = new Lang.Class({ this.currentElement.textRightAligned = this.currentTextRightAligned; this._redisplay(); } - this.emit('show-osd', null, DisplayStrings.getTextAlignment(this.currentTextRightAligned), "", -1, false); + let icon = Files.Icons[this.currentTextRightAligned ? 'RIGHT_ALIGNED' : 'LEFT_ALIGNED']; + this.emit('show-osd', icon, DisplayStrings.getTextAlignment(this.currentTextRightAligned), "", -1, false); }, switchImageFile: function(reverse) { diff --git a/data/icons/arc-symbolic.svg b/data/icons/arc-symbolic.svg new file mode 100644 index 0000000..4bed5e4 --- /dev/null +++ b/data/icons/arc-symbolic.svg @@ -0,0 +1,7 @@ + + +https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/blob/master/Papirus/symbolic/actions/tool-arc-symbolic.svg +https://www.gnu.org/licenses/gpl-3.0.html + + + diff --git a/data/icons/tool-ellipse-symbolic.svg b/data/icons/tool-ellipse-symbolic.svg new file mode 100644 index 0000000..9eeb5fc --- /dev/null +++ b/data/icons/tool-ellipse-symbolic.svg @@ -0,0 +1,7 @@ + + +https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/blob/master/Papirus/symbolic/actions/tool-circle-move-symbolic.svg +https://www.gnu.org/licenses/gpl-3.0.html + + + diff --git a/data/icons/tool-line-symbolic.svg b/data/icons/tool-line-symbolic.svg new file mode 100644 index 0000000..fc731dd --- /dev/null +++ b/data/icons/tool-line-symbolic.svg @@ -0,0 +1,7 @@ + + +https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/blob/master/Papirus/symbolic/actions/tool-line-symbolic.svg +https://www.gnu.org/licenses/gpl-3.0.html + + + diff --git a/data/icons/tool-move-symbolic.svg b/data/icons/tool-move-symbolic.svg new file mode 100644 index 0000000..0a9f236 --- /dev/null +++ b/data/icons/tool-move-symbolic.svg @@ -0,0 +1,14 @@ + + + +Combination of https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/blob/master/Papirus/symbolic/actions/object-move-symbolic.svg +https://www.gnu.org/licenses/gpl-3.0.html +and https://gitlab.gnome.org/World/design/icon-library/-/blob/master/data/resources/icon-dev-kit/rotate-symbolic.svg +https://www.gnu.org/licenses/gpl-3.0.html +optimized with SVGO + + + + + + diff --git a/data/icons/tool-none-symbolic.svg b/data/icons/tool-none-symbolic.svg new file mode 100644 index 0000000..de6fd8a --- /dev/null +++ b/data/icons/tool-none-symbolic.svg @@ -0,0 +1,14 @@ + + + +Combination of https://www.svgrepo.com/svg/150374/pencil +https://creativecommons.org/publicdomain/zero/1.0/deed.en +and https://www.svgrepo.com/svg/29291/pencil +https://creativecommons.org/publicdomain/zero/1.0/deed.en +Optimized with svgo + + + + + + diff --git a/data/icons/tool-polygon-symbolic.svg b/data/icons/tool-polygon-symbolic.svg new file mode 100644 index 0000000..2ee0447 --- /dev/null +++ b/data/icons/tool-polygon-symbolic.svg @@ -0,0 +1,8 @@ + + +https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/blob/master/Papirus/symbolic/actions/tool-polygon-symbolic.svg +https://www.gnu.org/licenses/gpl-3.0.html + + + + diff --git a/data/icons/tool-polyline-symbolic.svg b/data/icons/tool-polyline-symbolic.svg new file mode 100644 index 0000000..fee381d --- /dev/null +++ b/data/icons/tool-polyline-symbolic.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/data/icons/tool-rectangle-symbolic.svg b/data/icons/tool-rectangle-symbolic.svg new file mode 100644 index 0000000..e513e9f --- /dev/null +++ b/data/icons/tool-rectangle-symbolic.svg @@ -0,0 +1,7 @@ + + +https://github.com/PapirusDevelopmentTeam/papirus-icon-theme/blob/master/Papirus/symbolic/actions/tool-rectangle-symbolic.svg +https://www.gnu.org/licenses/gpl-3.0.html + + + diff --git a/data/icons/tool-resize-symbolic.svg b/data/icons/tool-resize-symbolic.svg new file mode 100644 index 0000000..96010ed --- /dev/null +++ b/data/icons/tool-resize-symbolic.svg @@ -0,0 +1,17 @@ + + +https://github.com/maoschanz/drawing/blob/master/src/tools/icons/tool-scale-symbolic.svg + + + + + + + + + + + diff --git a/files.js b/files.js index 492c506..d78398d 100644 --- a/files.js +++ b/files.js @@ -36,17 +36,21 @@ const DEFAULT_USER_IMAGE_LOCATION = GLib.build_filenamev([GLib.get_user_data_dir const Clipboard = St.Clipboard.get_default(); const CLIPBOARD_TYPE = St.ClipboardType.CLIPBOARD; const ICON_DIR = Me.dir.get_child('data').get_child('icons'); -const ICON_NAMES = ['color', 'dashed-line', 'fillrule-evenodd', 'fillrule-nonzero', 'fill', 'full-line', 'linecap', 'linejoin', 'palette', 'smooth', 'stroke']; - -var Icons = { - get ENTER() { return this._enter || void (this._enter = new Gio.ThemedIcon({ name: 'applications-graphics-symbolic' })) || this._enter; }, - get GRAB() { return this._grab || void (this._grab = new Gio.ThemedIcon({ name: 'input-touchpad-symbolic' })) || this._grab; }, - get LEAVE() { return this._leave || void (this._leave = new Gio.ThemedIcon({ name: 'application-exit-symbolic' })) || this._leave; }, - get OPEN() { return this._open || void (this._open = new Gio.ThemedIcon({ name: 'document-open-symbolic' })) || this._open; }, - get SAVE() { return this._save || void (this._save = new Gio.ThemedIcon({ name: 'document-save-symbolic' })) || this._save; }, - get UNGRAB() { return this._ungrab || void (this._ungrab = new Gio.ThemedIcon({ name: 'touchpad-disabled-symbolic' })) || this._ungrab; } +const ICON_NAMES = [ + 'arc', 'color', 'dashed-line', 'fillrule-evenodd', 'fillrule-nonzero', 'fill', 'full-line', 'linecap', 'linejoin', 'palette', 'smooth', 'stroke', + 'tool-ellipse', 'tool-line', 'tool-move', 'tool-none', 'tool-polygon', 'tool-polyline', 'tool-rectangle', 'tool-resize', +]; +const ThemedIconNames = { + ENTER: 'applications-graphics', LEAVE: 'application-exit', + GRAB: 'input-touchpad', UNGRAB: 'touchpad-disabled', + OPEN: 'document-open', SAVE: 'document-save', + FONT_FAMILY: 'font-x-generic', FONT_STYLE: 'format-text-italic', FONT_WEIGHT:'format-text-bold', + LEFT_ALIGNED: 'format-justify-left', RIGHT_ALIGNED: 'format-justify-right', + TOOL_IMAGE: 'insert-image', TOOL_MIRROR: 'view-mirror', TOOL_TEXT: 'insert-text', }; +var Icons = {}; + ICON_NAMES.forEach(name => { Object.defineProperty(Icons, name.toUpperCase().replace(/-/gi, '_'), { get: function() { @@ -59,6 +63,16 @@ ICON_NAMES.forEach(name => { }); }); +Object.keys(ThemedIconNames).forEach(key => { + Object.defineProperty(Icons, key, { + get: function() { + if (!this[`_${key}`]) + this[`_${key}`] = new Gio.ThemedIcon({ name: `${ThemedIconNames[key]}-symbolic` }); + return this[`_${key}`]; + } + }); +}); + // wrapper around an image file var Image = new Lang.Class({ Name: 'DrawOnYourScreenImage', diff --git a/menu.js b/menu.js index 12e8e5c..8316999 100644 --- a/menu.js +++ b/menu.js @@ -22,7 +22,6 @@ */ const Clutter = imports.gi.Clutter; -const Gio = imports.gi.Gio; const GLib = imports.gi.GLib; const GObject = imports.gi.GObject; const Gtk = imports.gi.Gtk; @@ -231,9 +230,9 @@ var DrawingMenu = new Lang.Class({ this.menu.addMenuItem(groupItem); this._addSeparator(this.menu, true); - this._addSubMenuItem(this.menu, 'document-edit-symbolic', DisplayStrings.Tool, this.area, 'currentTool', this._updateSectionVisibility.bind(this)); - this.paletteItem = this._addPaletteSubMenuItem(this.menu); - this.colorItem = this._addColorSubMenuItem(this.menu); + this._addToolSubMenuItem(this.menu, this._updateSectionVisibility.bind(this)); + this.paletteItem = this._addPaletteSubMenuItem(this.menu, Files.Icons.PALETTE); + this.colorItem = this._addColorSubMenuItem(this.menu, Files.Icons.COLOR); this.fillItem = this._addSwitchItem(this.menu, DisplayStrings.getFill(true), Files.Icons.STROKE, Files.Icons.FILL, this.area, 'fill', this._updateSectionVisibility.bind(this)); this.fillSection = new PopupMenu.PopupMenuSection(); this.fillSection.itemActivated = () => {}; @@ -252,10 +251,10 @@ var DrawingMenu = new Lang.Class({ this.lineSection = lineSection; let fontSection = new PopupMenu.PopupMenuSection(); - this._addFontFamilySubMenuItem(fontSection, 'font-x-generic-symbolic'); - this._addSubMenuItem(fontSection, 'format-text-bold-symbolic', DisplayStrings.FontWeight, this.area, 'currentFontWeight'); - this._addSubMenuItem(fontSection, 'format-text-italic-symbolic', DisplayStrings.FontStyle, this.area, 'currentFontStyle'); - this._addSwitchItem(fontSection, DisplayStrings.getTextAlignment(true), 'format-justify-left-symbolic', 'format-justify-right-symbolic', this.area, 'currentTextRightAligned'); + this._addFontFamilySubMenuItem(fontSection, Files.Icons.FONT_FAMILY); + this._addSubMenuItem(fontSection, Files.Icons.FONT_WEIGHT, DisplayStrings.FontWeight, this.area, 'currentFontWeight'); + this._addSubMenuItem(fontSection, Files.Icons.FONT_STYLE, DisplayStrings.FontStyle, this.area, 'currentFontStyle'); + this._addSwitchItem(fontSection, DisplayStrings.getTextAlignment(true), Files.Icons.LEFT_ALIGNED, Files.Icons.RIGHT_ALIGNED, this.area, 'currentTextRightAligned'); this._addSeparator(fontSection); this.menu.addMenuItem(fontSection); fontSection.itemActivated = () => {}; @@ -276,8 +275,8 @@ var DrawingMenu = new Lang.Class({ this._addSeparator(this.menu); this._addDrawingNameItem(this.menu); - this._addOpenDrawingSubMenuItem(this.menu); - this._addSaveDrawingSubMenuItem(this.menu); + this._addOpenDrawingSubMenuItem(this.menu, Files.Icons.OPEN); + this._addSaveDrawingSubMenuItem(this.menu, Files.Icons.SAVE); this.menu.addAction(getSummary('save-as-svg'), this.area.saveAsSvg.bind(this.area), 'image-x-generic-symbolic'); this.menu.addAction(getSummary('open-preferences'), areaManager.openPreferences.bind(areaManager), 'document-page-setup-symbolic'); @@ -334,18 +333,14 @@ var DrawingMenu = new Lang.Class({ item.icon = new St.Icon({ style_class: 'popup-menu-icon' }); getActor(item).insert_child_at_index(item.icon, 1); let icon = target[targetProperty] ? iconTrue : iconFalse; - if (icon && icon instanceof GObject.Object && GObject.type_is_a(icon, Gio.Icon)) + if (icon) item.icon.set_gicon(icon); - else if (icon) - item.icon.set_icon_name(icon); item.connect('toggled', (item, state) => { target[targetProperty] = state; let icon = target[targetProperty] ? iconTrue : iconFalse; - if (icon && icon instanceof GObject.Object && GObject.type_is_a(icon, Gio.Icon)) + if (icon) item.icon.set_gicon(icon); - else if (icon) - item.icon.set_icon_name(icon); if (onToggled) onToggled(); }); @@ -392,40 +387,25 @@ var DrawingMenu = new Lang.Class({ menu.addMenuItem(item); }, - _addSubMenuItem: function(menu, icon, obj, target, targetProperty, callback) { + _addSubMenuItem: function(menu, icon, obj, target, targetProperty) { let item = new PopupMenu.PopupSubMenuMenuItem(String(obj[target[targetProperty]]), icon ? true : false); - if (icon && icon instanceof GObject.Object && GObject.type_is_a(icon, Gio.Icon)) - item.icon.set_gicon(icon); - else if (icon) - item.icon.set_icon_name(icon); + item.icon.set_gicon(icon); item.menu.itemActivated = item.menu.close; GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => { Object.keys(obj).forEach(key => { - let text; - if (targetProperty == 'currentFontWeight') - text = `${obj[key]}`; - else if (targetProperty == 'currentFontStyle') - text = `${obj[key]}`; - else - text = String(obj[key]); + let text = targetProperty == 'currentFontWeight' ? `${obj[key]}` : + targetProperty == 'currentFontStyle' ? `${obj[key]}` : + String(obj[key]); let subItem = item.menu.addAction(text, () => { item.label.set_text(String(obj[key])); target[targetProperty] = Number(key); - if (callback) - callback(); }); subItem.label.get_clutter_text().set_use_markup(true); getActor(subItem).connect('key-focus-in', updateSubMenuAdjustment); - - // change the display order of tools - if (obj == DisplayStrings.Tool && Number(key) == this.drawingTools.POLYGON) - item.menu.moveMenuItem(subItem, 4); - else if (obj == DisplayStrings.Tool && Number(key) == this.drawingTools.POLYLINE) - item.menu.moveMenuItem(subItem, 5); }); return GLib.SOURCE_REMOVE; }); @@ -433,10 +413,45 @@ var DrawingMenu = new Lang.Class({ menu.addMenuItem(item); }, - _addPaletteSubMenuItem: function(menu) { + _addToolSubMenuItem: function(menu, callback) { + let item = new PopupMenu.PopupSubMenuMenuItem(DisplayStrings.Tool[this.area.currentTool], true); + + let toolName = this.drawingTools.getNameOf(this.area.currentTool); + item.icon.set_gicon(Files.Icons[`TOOL_${toolName}`]); + + item.menu.itemActivated = item.menu.close; + + GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => { + Object.keys(DisplayStrings.Tool).forEach(key => { + let text = DisplayStrings.Tool[key]; + let toolName = this.drawingTools.getNameOf(key); + let subItemIcon = Files.Icons[`TOOL_${toolName}`]; + let subItem = item.menu.addAction(text, () => { + item.label.set_text(text); + item.icon.set_gicon(subItemIcon); + this.area.currentTool = Number(key); + callback(); + }, subItemIcon); + + subItem.label.get_clutter_text().set_use_markup(true); + getActor(subItem).connect('key-focus-in', updateSubMenuAdjustment); + + // change the display order of tools + if (key == this.drawingTools.POLYGON) + item.menu.moveMenuItem(subItem, Number(this.drawingTools.TEXT)); + else if (key == this.drawingTools.POLYLINE) + item.menu.moveMenuItem(subItem, Number(this.drawingTools.TEXT) + 1); + }); + return GLib.SOURCE_REMOVE; + }); + + menu.addMenuItem(item); + }, + + _addPaletteSubMenuItem: function(menu, icon) { let text = _(this.area.currentPalette[0] || "Palette"); let item = new PopupMenu.PopupSubMenuMenuItem(text, true); - item.icon.set_gicon(Files.Icons.PALETTE); + item.icon.set_gicon(icon); item.menu.itemActivated = item.menu.close; @@ -460,10 +475,10 @@ var DrawingMenu = new Lang.Class({ return item; }, - _addColorSubMenuItem: function(menu) { + _addColorSubMenuItem: function(menu, icon) { let item = new PopupMenu.PopupSubMenuMenuItem(_("Color"), true); this.colorSubMenu = item.menu; - item.icon.set_gicon(Files.Icons.COLOR); + item.icon.set_gicon(icon); item.icon.set_style(`color:${this.area.currentColor.to_string().slice(0, 7)};`); item.menu.itemActivated = item.menu.close; @@ -492,7 +507,7 @@ var DrawingMenu = new Lang.Class({ _addFontFamilySubMenuItem: function(menu, icon) { let item = new PopupMenu.PopupSubMenuMenuItem(DisplayStrings.getFontFamily(this.area.currentFontFamily), true); - item.icon.set_icon_name(icon); + item.icon.set_gicon(icon); item.menu.itemActivated = item.menu.close; @@ -555,12 +570,12 @@ var DrawingMenu = new Lang.Class({ } }, - _addOpenDrawingSubMenuItem: function(menu) { + _addOpenDrawingSubMenuItem: function(menu, icon) { let item = new PopupMenu.PopupSubMenuMenuItem(_("Open drawing"), true); this.openDrawingSubMenuItem = item; this.openDrawingSubMenu = item.menu; item.setSensitive(Boolean(Files.getJsons().length)); - item.icon.set_icon_name('document-open-symbolic'); + item.icon.set_gicon(icon); item.menu.itemActivated = item.menu.close; @@ -608,12 +623,12 @@ var DrawingMenu = new Lang.Class({ this.openDrawingSubMenuItem.setSensitive(!this.openDrawingSubMenu.isEmpty()); }, - _addSaveDrawingSubMenuItem: function(menu) { + _addSaveDrawingSubMenuItem: function(menu, icon) { let item = new PopupMenu.PopupSubMenuMenuItem(getSummary('save-as-json'), true); this.saveDrawingSubMenuItem = item; this._updateSaveDrawingSubMenuItemSensitivity(); this.saveDrawingSubMenu = item.menu; - item.icon.set_icon_name('document-save-symbolic'); + item.icon.set_gicon(icon); item.menu.itemActivated = item.menu.close;