add a lot of icons

* Complete Files.Icons.
* Add a lot of icons in the menu and the osd notifications.
This commit is contained in:
abakkk 2020-09-12 01:25:37 +02:00
parent 771bad2d59
commit 24682db69c
12 changed files with 204 additions and 74 deletions

47
area.js
View File

@ -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,7 +402,7 @@ 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 <i>%s</i> to get\na fourth control point")
this.emit('show-osd', Files.Icons.ARC, _("Press <i>%s</i> to get\na fourth control point")
.format(Gtk.accelerator_get_label(Clutter.KEY_Return, 0)), "", -1, true);
this.currentElement.addPoint();
this.updatePointerCursor(true);
@ -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 <i>%s</i> to mark vertices")
this.emit('show-osd', icon, _("Press <i>%s</i> 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,7 +699,7 @@ 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 <i>%s</i>")
this.emit('show-osd', Files.Icons.TOOL_TEXT, _("Type your text and press <i>%s</i>")
.format(Gtk.accelerator_get_label(Clutter.KEY_Escape, 0)), "", -1, true);
this._updateTextCursorTimeout();
this.textHasCursor = true;
@ -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, `<span font_weight="${this.currentFontWeight}">` +
this.emit('show-osd', Files.Icons.FONT_WEIGHT, `<span font_weight="${this.currentFontWeight}">` +
`${DisplayStrings.FontWeight[this.currentFontWeight]}</span>`, "", -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, `<span font_style="${DisplayStrings.FontStyleMarkup[this.currentFontStyle]}">` +
this.emit('show-osd', Files.Icons.FONT_STYLE, `<span font_style="${DisplayStrings.FontStyleMarkup[this.currentFontStyle]}">` +
`${DisplayStrings.FontStyle[this.currentFontStyle]}</span>`, "", -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, `<span font_family="${this.currentFontFamily}">${DisplayStrings.getFontFamily(this.currentFontFamily)}</span>`, "", -1, false);
this.emit('show-osd', Files.Icons.FONT_FAMILY, `<span font_family="${this.currentFontFamily}">${DisplayStrings.getFontFamily(this.currentFontFamily)}</span>`, "", -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) {

View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" version="1.1">
<metadata>
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
</metadata>
<path style="fill:#555" d="M 14,1 C 13,1 13,2 13,2 13,2 12.941,4.04 12.701,4.6152 12.204,5.8094 11.214,7 8,7 4.2143,7 2.2036,8.8094 1.4512,10.615 1,11.698 1,14 1,14 1,14 1,15 2,15 3,15 3,14 3,14 3,14 2.9373,12.253 3.2988,11.385 3.7964,10.191 4.7857,9 8,9 11.786,9 13.796,7.1906 14.549,5.3848 15.045,4.1955 15,2 15,2 15,2 15,1 14,1 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 607 B

View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" version="1.1">
<metadata>
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
</metadata>
<path style="fill:#555" d="M 8,1 A 7,7 0 0 0 1,8 7,7 0 0 0 8,15 7,7 0 0 0 15,8 7,7 0 0 0 8,1 Z M 8,3 A 5,5 0 0 1 13,8 5,5 0 0 1 8,13 5,5 0 0 1 3,8 5,5 0 0 1 8,3 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 445 B

View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" version="1.1">
<metadata>
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
</metadata>
<path style="fill:#555" d="M 12.778,13.778 C 12.778,13.778 13.278,14.278 13.778,13.778 14.278,13.278 13.778,12.778 13.778,12.778 L 3.2237,2.2237 C 3.2237,2.2237 2.7237,1.7237 2.2237,2.2237 1.7237,2.7237 2.2237,3.2237 2.2237,3.2237 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 508 B

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">
<metadata>
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
</metadata>
<path d="M8 15.5L5 12h2v-2h2v2h2zM.5 8L4 5v2h2v2H4v2z" fill="#555"/>
<a transform="scale(.99497) rotate(-4.342 5.603 3.916)">
<path fill="#555" d="M8.672.954l-3.654 3.2c.634.717 1.341 1.557 1.92 2.193l1.28 1.46.166-2.484.022-.02c.769-.196 1.74.097 2.457.915 1.102 1.259.67 2.758-.634 3.9l.57.674c.346.407 1.058.4 1.396-.012 1.65-1.444 1.556-4.028.037-5.763-.986-1.124-2.398-1.707-3.725-1.579z"/>
</a>
</svg>

After

Width:  |  Height:  |  Size: 911 B

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" height="920.729" width="920.729">
<metadata>
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
</metadata>
<g fill="#555">
<path d="M440.186 181.818L105.352 648.939l5.721 8.528 33.597 49.602 41.293 13.82a50.861 50.861 0 0124.356 17.459l26.35 34.666 57.764 15.887 9.915 2.679 334.834-467.121zM748.693 132.147L587.243 16.42c-5.212-3.736-11.417-4.963-17.26-3.999-5.843.964-11.324 4.119-15.06 9.33l-98.575 137.52L655.45 301.987l98.575-137.52c7.471-10.423 5.092-24.848-5.331-32.32zM85.656 701.799l-1.38 16.076-12.96 154.533c-1.304 15.408 12.444 27.113 26.686 24.764 1.826-.301 3.698-.891 5.54-1.664l142.184-61.904 14.781-6.471 14.782-6.471 11.63-5.107-30.349-8.311-28.966-7.882c-4.91-1.347-9.241-4.29-12.338-8.281l-22.267-29.244-5.13-6.657a22.981 22.981 0 00-11.062-7.928l-7.951-2.721-34.847-11.695c-4.865-1.637-8.952-4.807-11.805-9.026l-16.768-24.9-17.617-26.072-1.101 12.656z"/>
<path d="M833.815 836.441a28.252 28.252 0 00-4.099.32l-245.553 32.915c-12.592 1.659-21.454-12.102-14.704-22.933 3.674-5.717 7.248-11.533 10.82-17.35 9.43-15.442-3.362-35.884-20.963-35.804-1.2.005-2.398.112-3.698.317L233.84 843.768l-38.473 5.975L90.44 866.021c-11.892 1.854-19.846 11.99-18.791 24.086.424 5.397 2.648 10.488 6.165 14.272 4.12 4.481 9.831 6.956 16.031 6.927 1.2-.005 2.4-.112 3.699-.316l383.534-59.444c13.092-2.06 22.159 12.7 14.507 23.534-2.485 3.411-4.969 6.923-7.453 10.334-6.857 9.431-5.186 25.125 2.85 33.187 4.12 4.182 9.33 6.358 14.83 6.333.6-.003 1.3-.006 1.898-.11h.101l.1-.001 331.105-43.705h.101l.1-.002c5.696-.925 10.68-4.248 13.958-9.364 3.575-5.616 4.843-12.522 3.215-18.714-2.646-10.089-11.476-16.649-22.576-16.598z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" version="1.1">
<metadata>
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
</metadata>
<path style="fill:#555" d="M 12.98,2.5 1.9551,3.502 1.5,4 V 14 L 2.3203,14.385 8.0684,9.5938 13.777,12.447 14.496,11.945 13.496,2.9453 Z M 12.557,3.543 13.402,11.143 8.2227,8.5527 7.6797,8.6152 2.5,12.932 V 4.457 Z"/>
<path style="fill:#555" d="M 10,9 A 2,2 0 0 1 8,11 2,2 0 0 1 6,9 2,2 0 0 1 8,7 2,2 0 0 1 10,9 Z M 4,4 A 2,2 0 0 1 2,6 2,2 0 0 1 0,4 2,2 0 0 1 2,2 2,2 0 0 1 4,4 Z M 4,14 A 2,2 0 0 1 2,16 2,2 0 0 1 0,14 2,2 0 0 1 2,12 2,2 0 0 1 4,14 Z M 16,12 A 2,2 0 0 1 14,14 2,2 0 0 1 12,12 2,2 0 0 1 14,10 2,2 0 0 1 16,12 Z M 15,3 A 2,2 0 0 1 13,5 2,2 0 0 1 11,3 2,2 0 0 1 13,1 2,2 0 0 1 15,3 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 877 B

View File

@ -0,0 +1,9 @@
<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
<rect fill="#555" x="98" y="204" width="226" height="40" transform="translate(116,253) rotate(-66) translate(-211,-226)"/>
<rect fill="#555" x="145" y="339" width="270" height="40" transform="translate(236,262) rotate(58) translate(-280,-362)"/>
<rect fill="#555" x="141" y="429" width="211" height="40" transform="translate(374,300) rotate(-47) translate(-246,-451)"/>
<circle fill="#555" cx="166" cy="172" r="55"/>
<circle fill="#555" cx="166" cy="172" r="55" transform="translate(143,190)"/>
<circle fill="#555" cx="166" cy="172" r="55" transform="translate(-87,168)"/>
<circle fill="#555" cx="166" cy="172" r="55" transform="translate(273,56)"/>
</svg>

After

Width:  |  Height:  |  Size: 734 B

View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" version="1.1">
<metadata>
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
</metadata>
<path style="fill:#555" d="M 1,1 V 15 H 15 V 1 Z M 3,3 H 13 V 13 H 3 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 351 B

View File

@ -0,0 +1,17 @@
<svg width="16" height="16">
<metadata>
https://github.com/maoschanz/drawing/blob/master/src/tools/icons/tool-scale-symbolic.svg
</metadata>
<g fill="#555">
<path
d="M1.984 8.986A1 1 0 0 0 1 10v4a1 1 0 0 0 1 1h4a1 1 0 1 0 0-2H3v-3a1 1 0 0 0-1.016-1.014z" />
<path
d="M6.48 8.49a1 1 0 0 0-.687.303l-4.5 4.5a1 1 0 1 0 1.414 1.414l4.5-4.5A1 1 0 0 0 6.48 8.49z" />
<path d="M1 14h1v1H1z" />
<path d="M10 1a1 1 0 1 0 0 2h3v3a1 1 0 1 0 2 0V2a1 1 0 0 0-1-1z" />
<path d="M14 1h1v1h-1z" />
<path
d="M13.984.99a1 1 0 0 0-.69.301l-4.5 4.469a1 1 0 1 0 1.411 1.418l4.5-4.469a1 1 0 0 0-.72-1.719z" />
<path d="M1 9h1v1H1zM6 14h1v1H6zM14 6h1v1h-1zM9 1h1v1H9z" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 711 B

View File

@ -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',

105
menu.js
View File

@ -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 = `<span font_weight="${key}">${obj[key]}</span>`;
else if (targetProperty == 'currentFontStyle')
text = `<span font_style="${DisplayStrings.FontStyleMarkup[key]}">${obj[key]}</span>`;
else
text = String(obj[key]);
let text = targetProperty == 'currentFontWeight' ? `<span font_weight="${key}">${obj[key]}</span>` :
targetProperty == 'currentFontStyle' ? `<span font_style="${DisplayStrings.FontStyleMarkup[key]}">${obj[key]}</span>` :
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;