new DisplayStrings object
Group the most strings to display in a new DisplayStrings object. It is used by both menu and osd notifications.
This commit is contained in:
parent
f9769c11f2
commit
2dd900bddf
41
area.js
41
area.js
|
|
@ -1,5 +1,5 @@
|
||||||
/* jslint esversion: 6 */
|
/* jslint esversion: 6 */
|
||||||
/* exported Tools, ToolNames, FontGenericFamilies, DrawingArea */
|
/* exported Tools, DrawingArea */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Abakkk
|
* Copyright 2019 Abakkk
|
||||||
|
|
@ -49,13 +49,12 @@ const TEXT_CURSOR_TIME = 600; // ms
|
||||||
const ELEMENT_GRABBER_TIME = 80; // ms, default is about 16 ms
|
const ELEMENT_GRABBER_TIME = 80; // ms, default is about 16 ms
|
||||||
const GRID_TILES_HORIZONTAL_NUMBER = 30;
|
const GRID_TILES_HORIZONTAL_NUMBER = 30;
|
||||||
|
|
||||||
const { Shapes, ShapeNames, Transformations, LineCapNames, LineJoinNames, FillRuleNames, FontWeightNames, FontStyleNames } = Elements;
|
const { Shapes, Transformations } = Elements;
|
||||||
const Manipulations = { MOVE: 100, RESIZE: 101, MIRROR: 102 };
|
const { DisplayStrings } = Menu;
|
||||||
const ManipulationNames = { 100: "Move", 101: "Resize", 102: "Mirror" };
|
|
||||||
var Tools = Object.assign({}, Shapes, Manipulations);
|
|
||||||
var ToolNames = Object.assign({}, ShapeNames, ManipulationNames);
|
|
||||||
|
|
||||||
var FontGenericFamilies = ['Sans-Serif', 'Serif', 'Monospace', 'Cursive', 'Fantasy'];
|
const FontGenericFamilies = ['Sans-Serif', 'Serif', 'Monospace', 'Cursive', 'Fantasy'];
|
||||||
|
const Manipulations = { MOVE: 100, RESIZE: 101, MIRROR: 102 };
|
||||||
|
var Tools = Object.assign({}, Shapes, Manipulations);
|
||||||
|
|
||||||
const getClutterColorFromString = function(string, fallback) {
|
const getClutterColorFromString = function(string, fallback) {
|
||||||
let [success, color] = Clutter.Color.from_string(string);
|
let [success, color] = Clutter.Color.from_string(string);
|
||||||
|
|
@ -115,7 +114,7 @@ var DrawingArea = new Lang.Class({
|
||||||
|
|
||||||
get menu() {
|
get menu() {
|
||||||
if (!this._menu)
|
if (!this._menu)
|
||||||
this._menu = new Menu.DrawingMenu(this, this.monitor);
|
this._menu = new Menu.DrawingMenu(this, this.monitor, Tools);
|
||||||
return this._menu;
|
return this._menu;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -898,18 +897,18 @@ var DrawingArea = new Lang.Class({
|
||||||
|
|
||||||
selectTool: function(tool) {
|
selectTool: function(tool) {
|
||||||
this.currentTool = tool;
|
this.currentTool = tool;
|
||||||
this.emit('show-osd', null, _(ToolNames[tool]), "", -1, false);
|
this.emit('show-osd', null, DisplayStrings.Tool[tool], "", -1, false);
|
||||||
this.updatePointerCursor();
|
this.updatePointerCursor();
|
||||||
},
|
},
|
||||||
|
|
||||||
switchFill: function() {
|
switchFill: function() {
|
||||||
this.fill = !this.fill;
|
this.fill = !this.fill;
|
||||||
this.emit('show-osd', null, this.fill ? _("Fill") : _("Outline"), "", -1, false);
|
this.emit('show-osd', null, DisplayStrings.getFill(this.fill), "", -1, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
switchFillRule: function() {
|
switchFillRule: function() {
|
||||||
this.currentFillRule = this.currentFillRule == 1 ? 0 : this.currentFillRule + 1;
|
this.currentFillRule = this.currentFillRule == 1 ? 0 : this.currentFillRule + 1;
|
||||||
this.emit('show-osd', null, _(FillRuleNames[this.currentFillRule]), "", -1, false);
|
this.emit('show-osd', null, DisplayStrings.FillRule[this.currentFillRule], "", -1, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
switchColorPalette: function(reverse) {
|
switchColorPalette: function(reverse) {
|
||||||
|
|
@ -923,26 +922,26 @@ var DrawingArea = new Lang.Class({
|
||||||
|
|
||||||
switchDash: function() {
|
switchDash: function() {
|
||||||
this.dashedLine = !this.dashedLine;
|
this.dashedLine = !this.dashedLine;
|
||||||
this.emit('show-osd', null, this.dashedLine ? _("Dashed line") : _("Full line"), "", -1, false);
|
this.emit('show-osd', null, DisplayStrings.getDashedLine(this.dashedLine), "", -1, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
incrementLineWidth: function(increment) {
|
incrementLineWidth: function(increment) {
|
||||||
this.currentLineWidth = Math.max(this.currentLineWidth + increment, 0);
|
this.currentLineWidth = Math.max(this.currentLineWidth + increment, 0);
|
||||||
this.emit('show-osd', null, _("%d px").format(this.currentLineWidth), "", 2 * this.currentLineWidth, false);
|
this.emit('show-osd', null, DisplayStrings.getPixels(this.currentLineWidth), "", 2 * this.currentLineWidth, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
switchLineJoin: function() {
|
switchLineJoin: function() {
|
||||||
this.currentLineJoin = this.currentLineJoin == 2 ? 0 : this.currentLineJoin + 1;
|
this.currentLineJoin = this.currentLineJoin == 2 ? 0 : this.currentLineJoin + 1;
|
||||||
this.emit('show-osd', null, _(LineJoinNames[this.currentLineJoin]), "", -1, false);
|
this.emit('show-osd', null, DisplayStrings.LineJoin[this.currentLineJoin], "", -1, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
switchLineCap: function() {
|
switchLineCap: function() {
|
||||||
this.currentLineCap = this.currentLineCap == 2 ? 0 : this.currentLineCap + 1;
|
this.currentLineCap = this.currentLineCap == 2 ? 0 : this.currentLineCap + 1;
|
||||||
this.emit('show-osd', null, _(LineCapNames[this.currentLineCap]), "", -1, false);
|
this.emit('show-osd', null, DisplayStrings.LineCap[this.currentLineCap], "", -1, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
switchFontWeight: function() {
|
switchFontWeight: function() {
|
||||||
let fontWeights = Object.keys(FontWeightNames).map(key => Number(key));
|
let fontWeights = Object.keys(DisplayStrings.FontWeight).map(key => Number(key));
|
||||||
let index = fontWeights.indexOf(this.currentFontWeight);
|
let index = fontWeights.indexOf(this.currentFontWeight);
|
||||||
this.currentFontWeight = index == fontWeights.length - 1 ? fontWeights[0] : fontWeights[index + 1];
|
this.currentFontWeight = index == fontWeights.length - 1 ? fontWeights[0] : fontWeights[index + 1];
|
||||||
if (this.currentElement && this.currentElement.font) {
|
if (this.currentElement && this.currentElement.font) {
|
||||||
|
|
@ -950,7 +949,7 @@ var DrawingArea = new Lang.Class({
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
}
|
}
|
||||||
this.emit('show-osd', null, `<span font_weight="${this.currentFontWeight}">` +
|
this.emit('show-osd', null, `<span font_weight="${this.currentFontWeight}">` +
|
||||||
`${_(FontWeightNames[this.currentFontWeight])}</span>`, "", -1, false);
|
`${DisplayStrings.FontWeight[this.currentFontWeight]}</span>`, "", -1, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
switchFontStyle: function() {
|
switchFontStyle: function() {
|
||||||
|
|
@ -959,8 +958,8 @@ var DrawingArea = new Lang.Class({
|
||||||
this.currentElement.font.set_style(this.currentFontStyle);
|
this.currentElement.font.set_style(this.currentFontStyle);
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
}
|
}
|
||||||
this.emit('show-osd', null, `<span font_style="${FontStyleNames[this.currentFontStyle].toLowerCase()}">` +
|
this.emit('show-osd', null, `<span font_style="${DisplayStrings.FontStyleMarkup[this.currentFontStyle]}">` +
|
||||||
`${_(FontStyleNames[this.currentFontStyle])}</span>`, "", -1, false);
|
`${DisplayStrings.FontStyle[this.currentFontStyle]}</span>`, "", -1, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
switchFontFamily: function(reverse) {
|
switchFontFamily: function(reverse) {
|
||||||
|
|
@ -973,7 +972,7 @@ var DrawingArea = new Lang.Class({
|
||||||
this.currentElement.font.set_family(this.currentFontFamily);
|
this.currentElement.font.set_family(this.currentFontFamily);
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
}
|
}
|
||||||
this.emit('show-osd', null, `<span font_family="${this.currentFontFamily}">${_(this.currentFontFamily)}</span>`, "", -1, false);
|
this.emit('show-osd', null, `<span font_family="${this.currentFontFamily}">${DisplayStrings.getFontFamily(this.currentFontFamily)}</span>`, "", -1, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
switchTextAlignment: function() {
|
switchTextAlignment: function() {
|
||||||
|
|
@ -982,7 +981,7 @@ var DrawingArea = new Lang.Class({
|
||||||
this.currentElement.textRightAligned = this.currentTextRightAligned;
|
this.currentElement.textRightAligned = this.currentTextRightAligned;
|
||||||
this._redisplay();
|
this._redisplay();
|
||||||
}
|
}
|
||||||
this.emit('show-osd', null, this.currentTextRightAligned ? _("Right aligned") : _("Left aligned"), "", -1, false);
|
this.emit('show-osd', null, DisplayStrings.getTextAlignment(this.currentTextRightAligned), "", -1, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
switchImageFile: function() {
|
switchImageFile: function() {
|
||||||
|
|
|
||||||
39
elements.js
39
elements.js
|
|
@ -19,7 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jslint esversion: 6 */
|
/* jslint esversion: 6 */
|
||||||
/* exported Shapes, ShapeNames, Transformations, LineCapNames, LineJoinNames, FillRuleNames, FontWeightNames, FontStyleNames, getPangoFontFamilies, DrawingElement */
|
/* exported Shapes, Transformations, getPangoFontFamilies, DrawingElement */
|
||||||
|
|
||||||
const Cairo = imports.cairo;
|
const Cairo = imports.cairo;
|
||||||
const Clutter = imports.gi.Clutter;
|
const Clutter = imports.gi.Clutter;
|
||||||
|
|
@ -27,28 +27,29 @@ const Lang = imports.lang;
|
||||||
const Pango = imports.gi.Pango;
|
const Pango = imports.gi.Pango;
|
||||||
const PangoCairo = imports.gi.PangoCairo;
|
const PangoCairo = imports.gi.PangoCairo;
|
||||||
|
|
||||||
const reverseEnumeration = function(obj) {
|
|
||||||
let reversed = {};
|
|
||||||
Object.keys(obj).forEach(key => {
|
|
||||||
reversed[obj[key]] = key.slice(0,1) + key.slice(1).toLowerCase().replace('_', '-');
|
|
||||||
});
|
|
||||||
return reversed;
|
|
||||||
};
|
|
||||||
|
|
||||||
var Shapes = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6, IMAGE: 7 };
|
var Shapes = { NONE: 0, LINE: 1, ELLIPSE: 2, RECTANGLE: 3, TEXT: 4, POLYGON: 5, POLYLINE: 6, IMAGE: 7 };
|
||||||
var ShapeNames = { 0: "Free drawing", 1: "Line", 2: "Ellipse", 3: "Rectangle", 4: "Text", 5: "Polygon", 6: "Polyline", 7: "Image" };
|
|
||||||
var Transformations = { TRANSLATION: 0, ROTATION: 1, SCALE_PRESERVE: 2, STRETCH: 3, REFLECTION: 4, INVERSION: 5 };
|
var Transformations = { TRANSLATION: 0, ROTATION: 1, SCALE_PRESERVE: 2, STRETCH: 3, REFLECTION: 4, INVERSION: 5 };
|
||||||
var LineCapNames = Object.assign(reverseEnumeration(Cairo.LineCap), { 2: 'Square' });
|
|
||||||
var LineJoinNames = reverseEnumeration(Cairo.LineJoin);
|
|
||||||
var FillRuleNames = { 0: 'Nonzero', 1: 'Evenodd' };
|
|
||||||
var FontWeightNames = Object.assign(reverseEnumeration(Pango.Weight), { 200: "Ultra-light", 350: "Semi-light", 600: "Semi-bold", 800: "Ultra-bold" });
|
|
||||||
delete FontWeightNames[Pango.Weight.ULTRAHEAVY];
|
|
||||||
var FontStyleNames = reverseEnumeration(Pango.Style);
|
|
||||||
|
|
||||||
var getPangoFontFamilies = function() {
|
var getPangoFontFamilies = function() {
|
||||||
return PangoCairo.font_map_get_default().list_families().map(fontFamily => fontFamily.get_name()).sort((a,b) => a.localeCompare(b));
|
return PangoCairo.font_map_get_default().list_families().map(fontFamily => fontFamily.get_name()).sort((a,b) => a.localeCompare(b));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getFillRuleSvgName = function(fillRule) {
|
||||||
|
return fillRule == Pango.FillRule.EVEN_ODD ? 'evenodd' : 'nonzero';
|
||||||
|
};
|
||||||
|
|
||||||
|
const getLineCapSvgName = function(lineCap) {
|
||||||
|
return lineCap == Pango.LineCap.BUTT ? 'butt' :
|
||||||
|
lineCap == Pango.LineCap.SQUASH ? 'square' :
|
||||||
|
'round';
|
||||||
|
};
|
||||||
|
|
||||||
|
const getLineJoinSvgName = function(lineJoin) {
|
||||||
|
return lineJoin == Pango.LineJoin.MITER ? 'miter' :
|
||||||
|
lineJoin == Pango.LineJoin.BEVEL ? 'bevel' :
|
||||||
|
'round';
|
||||||
|
};
|
||||||
|
|
||||||
const SVG_DEBUG_SUPERPOSES_CAIRO = false;
|
const SVG_DEBUG_SUPERPOSES_CAIRO = false;
|
||||||
const RADIAN = 180 / Math.PI; // degree
|
const RADIAN = 180 / Math.PI; // degree
|
||||||
const INVERSION_CIRCLE_RADIUS = 12; // px
|
const INVERSION_CIRCLE_RADIUS = 12; // px
|
||||||
|
|
@ -295,7 +296,7 @@ const _DrawingElement = new Lang.Class({
|
||||||
if (fill) {
|
if (fill) {
|
||||||
attributes = `fill="${color}"`;
|
attributes = `fill="${color}"`;
|
||||||
if (this.fillRule)
|
if (this.fillRule)
|
||||||
attributes += ` fill-rule="${FillRuleNames[this.fillRule].toLowerCase()}"`;
|
attributes += ` fill-rule="${getFillRuleSvgName(this.fillRule)}"`;
|
||||||
} else {
|
} else {
|
||||||
attributes = `fill="none"`;
|
attributes = `fill="none"`;
|
||||||
}
|
}
|
||||||
|
|
@ -304,9 +305,9 @@ const _DrawingElement = new Lang.Class({
|
||||||
attributes += ` stroke="${color}"` +
|
attributes += ` stroke="${color}"` +
|
||||||
` stroke-width="${this.line.lineWidth}"`;
|
` stroke-width="${this.line.lineWidth}"`;
|
||||||
if (this.line.lineCap)
|
if (this.line.lineCap)
|
||||||
attributes += ` stroke-linecap="${LineCapNames[this.line.lineCap].toLowerCase()}"`;
|
attributes += ` stroke-linecap="${getLineCapSvgName(this.line.lineCap)}"`;
|
||||||
if (this.line.lineJoin && !this.isStraightLine)
|
if (this.line.lineJoin && !this.isStraightLine)
|
||||||
attributes += ` stroke-linejoin="${LineJoinNames[this.line.lineJoin].toLowerCase()}"`;
|
attributes += ` stroke-linejoin="${getLineJoinSvgName(this.line.lineJoin)}"`;
|
||||||
if (this.dash && this.dash.active && this.dash.array && this.dash.array[0] && this.dash.array[1])
|
if (this.dash && this.dash.active && this.dash.array && this.dash.array[0] && this.dash.array[1])
|
||||||
attributes += ` stroke-dasharray="${this.dash.array[0]} ${this.dash.array[1]}" stroke-dashoffset="${this.dash.offset}"`;
|
attributes += ` stroke-dasharray="${this.dash.array[0]} ${this.dash.array[1]}" stroke-dashoffset="${this.dash.offset}"`;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
2
files.js
2
files.js
|
|
@ -1,5 +1,5 @@
|
||||||
/* jslint esversion: 6 */
|
/* jslint esversion: 6 */
|
||||||
/* exported Image, getImages, getJsons, getDateString */
|
/* exported Image, getImages, Json, getJsons, getDateString */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Abakkk
|
* Copyright 2019 Abakkk
|
||||||
|
|
|
||||||
|
|
@ -500,9 +500,6 @@ msgstr ""
|
||||||
msgid "Square"
|
msgid "Square"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
msgid "Dashed"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
# generic font-family SVG attribute
|
# generic font-family SVG attribute
|
||||||
msgid "Sans-Serif"
|
msgid "Sans-Serif"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
||||||
126
menu.js
126
menu.js
|
|
@ -1,5 +1,5 @@
|
||||||
/* jslint esversion: 6 */
|
/* jslint esversion: 6 */
|
||||||
/* exported DrawingMenu */
|
/* exported DisplayStrings, DrawingMenu */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Abakkk
|
* Copyright 2019 Abakkk
|
||||||
|
|
@ -37,8 +37,6 @@ const Slider = imports.ui.slider;
|
||||||
|
|
||||||
const ExtensionUtils = imports.misc.extensionUtils;
|
const ExtensionUtils = imports.misc.extensionUtils;
|
||||||
const Me = ExtensionUtils.getCurrentExtension();
|
const Me = ExtensionUtils.getCurrentExtension();
|
||||||
const Area = Me.imports.area;
|
|
||||||
const Elements = Me.imports.elements;
|
|
||||||
const Files = Me.imports.files;
|
const Files = Me.imports.files;
|
||||||
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
||||||
|
|
||||||
|
|
@ -70,11 +68,81 @@ const getSummary = function(settingKey) {
|
||||||
return Me.internalShortcutSettings.settings_schema.get_key(settingKey).get_summary();
|
return Me.internalShortcutSettings.settings_schema.get_key(settingKey).get_summary();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Used by both menu and osd notifications.
|
||||||
|
var DisplayStrings = {
|
||||||
|
getDashedLine: function(dashed) {
|
||||||
|
return dashed ? _("Dashed line") : _("Full line");
|
||||||
|
},
|
||||||
|
|
||||||
|
getFill: function(fill) {
|
||||||
|
return fill ? _("Fill") : _("Outline");
|
||||||
|
},
|
||||||
|
|
||||||
|
get FillRule() {
|
||||||
|
if (!this._fillRules)
|
||||||
|
this._fillRules = { 0: _("Nonzero"), 1: _("Evenodd") };
|
||||||
|
return this._fillRules;
|
||||||
|
},
|
||||||
|
|
||||||
|
getFontFamily: function(family) {
|
||||||
|
if (!this._fontGenericFamilies)
|
||||||
|
this._fontGenericFamilies = { 'Sans-Serif': _("Sans-Serif"), 'Serif': _("Serif"), 'Monospace': _("Monospace"),
|
||||||
|
'Cursive': _("Cursive"), 'Fantasy': _("Fantasy") };
|
||||||
|
return this._fontGenericFamilies[family] || family;
|
||||||
|
},
|
||||||
|
|
||||||
|
get FontStyle() {
|
||||||
|
if (!this._fontStyles)
|
||||||
|
this._fontStyles = { 0: _("Normal"), 1: _("Oblique"), 2: _("Italic") };
|
||||||
|
return this._fontStyles;
|
||||||
|
},
|
||||||
|
|
||||||
|
FontStyleMarkup: { 0: 'normal', 1: 'oblique', 2: 'italic' },
|
||||||
|
|
||||||
|
get FontWeight() {
|
||||||
|
if (!this._fontWeights)
|
||||||
|
this._fontWeights = { 100: _("Thin"), 200: _("Ultra Light"), 300: _("Light"), 350: _("Semi Light"),
|
||||||
|
380: _("Book"), 400: _("Normal"), 500: _("Medium"), 600: _("Semi Bold"),
|
||||||
|
700: _("Bold"), 800: _("Ultra Bold"), 900: _("Heavy"), 1000:_("Ultra Heavy") };
|
||||||
|
return this._fontWeights;
|
||||||
|
},
|
||||||
|
|
||||||
|
get LineCap() {
|
||||||
|
if (!this._lineCaps)
|
||||||
|
this._lineCaps = { 0: _("Butt"), 1: _("Round"), 2: _("Square") };
|
||||||
|
return this._lineCaps;
|
||||||
|
},
|
||||||
|
|
||||||
|
get LineJoin() {
|
||||||
|
if (!this._lineJoins)
|
||||||
|
this._lineJoins = { 0: _("Miter"), 1: _("Round"), 2: _("Bevel") };
|
||||||
|
return this._lineJoins;
|
||||||
|
},
|
||||||
|
|
||||||
|
getPixels(value) {
|
||||||
|
return _("%d px").format(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
getTextAlignment: function(rightAligned) {
|
||||||
|
return rightAligned ? _("Right aligned") : _("Left aligned");
|
||||||
|
},
|
||||||
|
|
||||||
|
get Tool() {
|
||||||
|
if (!this._tools)
|
||||||
|
this._tools = { 0: _("Free drawing"), 1: _("Line"), 2: _("Ellipse"), 3: _("Rectangle"),
|
||||||
|
4: _("Text"), 5: _("Polygon"), 6: _("Polyline"), 7: _("Image"),
|
||||||
|
100: _("Move"), 101: _("Resize"), 102: _("Mirror") };
|
||||||
|
return this._tools;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var DrawingMenu = new Lang.Class({
|
var DrawingMenu = new Lang.Class({
|
||||||
Name: 'DrawOnYourScreenDrawingMenu',
|
Name: 'DrawOnYourScreenDrawingMenu',
|
||||||
|
|
||||||
_init: function(area, monitor) {
|
_init: function(area, monitor, drawingTools) {
|
||||||
this.area = area;
|
this.area = area;
|
||||||
|
this.drawingTools = drawingTools;
|
||||||
|
|
||||||
let side = Clutter.get_default_text_direction() == Clutter.TextDirection.RTL ? St.Side.RIGHT : St.Side.LEFT;
|
let side = Clutter.get_default_text_direction() == Clutter.TextDirection.RTL ? St.Side.RIGHT : St.Side.LEFT;
|
||||||
this.menu = new PopupMenu.PopupMenu(Main.layoutManager.dummyCursor, 0.25, side);
|
this.menu = new PopupMenu.PopupMenu(Main.layoutManager.dummyCursor, 0.25, side);
|
||||||
this.menuManager = new PopupMenu.PopupMenuManager(GS_VERSION < '3.33.0' ? { actor: this.area } : this.area);
|
this.menuManager = new PopupMenu.PopupMenuManager(GS_VERSION < '3.33.0' ? { actor: this.area } : this.area);
|
||||||
|
|
@ -116,6 +184,8 @@ var DrawingMenu = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
disable: function() {
|
disable: function() {
|
||||||
|
delete this.area;
|
||||||
|
delete this.drawingTools;
|
||||||
this.menuManager.removeMenu(this.menu);
|
this.menuManager.removeMenu(this.menu);
|
||||||
Main.layoutManager.uiGroup.remove_actor(this.menu.actor);
|
Main.layoutManager.uiGroup.remove_actor(this.menu.actor);
|
||||||
this.menu.destroy();
|
this.menu.destroy();
|
||||||
|
|
@ -171,21 +241,21 @@ var DrawingMenu = new Lang.Class({
|
||||||
this.menu.addMenuItem(groupItem);
|
this.menu.addMenuItem(groupItem);
|
||||||
this._addSeparator(this.menu, true);
|
this._addSeparator(this.menu, true);
|
||||||
|
|
||||||
this._addSubMenuItem(this.menu, 'document-edit-symbolic', Area.ToolNames, this.area, 'currentTool', this._updateSectionVisibility.bind(this));
|
this._addSubMenuItem(this.menu, 'document-edit-symbolic', DisplayStrings.Tool, this.area, 'currentTool', this._updateSectionVisibility.bind(this));
|
||||||
this.paletteItem = this._addPaletteSubMenuItem(this.menu);
|
this.paletteItem = this._addPaletteSubMenuItem(this.menu);
|
||||||
this.colorItem = this._addColorSubMenuItem(this.menu);
|
this.colorItem = this._addColorSubMenuItem(this.menu);
|
||||||
this.fillItem = this._addSwitchItem(this.menu, _("Fill"), this.strokeIcon, this.fillIcon, this.area, 'fill', this._updateSectionVisibility.bind(this));
|
this.fillItem = this._addSwitchItem(this.menu, DisplayStrings.getFill(true), this.strokeIcon, this.fillIcon, this.area, 'fill', this._updateSectionVisibility.bind(this));
|
||||||
this.fillSection = new PopupMenu.PopupMenuSection();
|
this.fillSection = new PopupMenu.PopupMenuSection();
|
||||||
this.fillSection.itemActivated = () => {};
|
this.fillSection.itemActivated = () => {};
|
||||||
this.fillRuleItem = this._addSwitchItem(this.fillSection, _("Evenodd"), this.fillRuleNonzeroIcon, this.fillRuleEvenoddIcon, this.area, 'currentEvenodd');
|
this.fillRuleItem = this._addSwitchItem(this.fillSection, DisplayStrings.FillRule[1], this.fillRuleNonzeroIcon, this.fillRuleEvenoddIcon, this.area, 'currentEvenodd');
|
||||||
this.menu.addMenuItem(this.fillSection);
|
this.menu.addMenuItem(this.fillSection);
|
||||||
this._addSeparator(this.menu);
|
this._addSeparator(this.menu);
|
||||||
|
|
||||||
let lineSection = new PopupMenu.PopupMenuSection();
|
let lineSection = new PopupMenu.PopupMenuSection();
|
||||||
this._addSliderItem(lineSection, this.area, 'currentLineWidth');
|
this._addSliderItem(lineSection, this.area, 'currentLineWidth');
|
||||||
this._addSubMenuItem(lineSection, this.linejoinIcon, Elements.LineJoinNames, this.area, 'currentLineJoin');
|
this._addSubMenuItem(lineSection, this.linejoinIcon, DisplayStrings.LineJoin, this.area, 'currentLineJoin');
|
||||||
this._addSubMenuItem(lineSection, this.linecapIcon, Elements.LineCapNames, this.area, 'currentLineCap');
|
this._addSubMenuItem(lineSection, this.linecapIcon, DisplayStrings.LineCap, this.area, 'currentLineCap');
|
||||||
this._addSwitchItem(lineSection, _("Dashed"), this.fullLineIcon, this.dashedLineIcon, this.area, 'dashedLine');
|
this._addSwitchItem(lineSection, DisplayStrings.getDashedLine(true), this.fullLineIcon, this.dashedLineIcon, this.area, 'dashedLine');
|
||||||
this._addSeparator(lineSection);
|
this._addSeparator(lineSection);
|
||||||
this.menu.addMenuItem(lineSection);
|
this.menu.addMenuItem(lineSection);
|
||||||
lineSection.itemActivated = () => {};
|
lineSection.itemActivated = () => {};
|
||||||
|
|
@ -193,9 +263,9 @@ var DrawingMenu = new Lang.Class({
|
||||||
|
|
||||||
let fontSection = new PopupMenu.PopupMenuSection();
|
let fontSection = new PopupMenu.PopupMenuSection();
|
||||||
this._addFontFamilySubMenuItem(fontSection, 'font-x-generic-symbolic');
|
this._addFontFamilySubMenuItem(fontSection, 'font-x-generic-symbolic');
|
||||||
this._addSubMenuItem(fontSection, 'format-text-bold-symbolic', Elements.FontWeightNames, this.area, 'currentFontWeight');
|
this._addSubMenuItem(fontSection, 'format-text-bold-symbolic', DisplayStrings.FontWeight, this.area, 'currentFontWeight');
|
||||||
this._addSubMenuItem(fontSection, 'format-text-italic-symbolic', Elements.FontStyleNames, this.area, 'currentFontStyle');
|
this._addSubMenuItem(fontSection, 'format-text-italic-symbolic', DisplayStrings.FontStyle, this.area, 'currentFontStyle');
|
||||||
this._addSwitchItem(fontSection, _("Right aligned"), 'format-justify-left-symbolic', 'format-justify-right-symbolic', this.area, 'currentTextRightAligned');
|
this._addSwitchItem(fontSection, DisplayStrings.getTextAlignment(true), 'format-justify-left-symbolic', 'format-justify-right-symbolic', this.area, 'currentTextRightAligned');
|
||||||
this._addSeparator(fontSection);
|
this._addSeparator(fontSection);
|
||||||
this.menu.addMenuItem(fontSection);
|
this.menu.addMenuItem(fontSection);
|
||||||
fontSection.itemActivated = () => {};
|
fontSection.itemActivated = () => {};
|
||||||
|
|
@ -254,11 +324,11 @@ var DrawingMenu = new Lang.Class({
|
||||||
undoButton.reactive = this.area.elements.length > 0;
|
undoButton.reactive = this.area.elements.length > 0;
|
||||||
redoButton.reactive = this.area.undoneElements.length > 0;
|
redoButton.reactive = this.area.undoneElements.length > 0;
|
||||||
eraseButton.reactive = this.area.elements.length > 0;
|
eraseButton.reactive = this.area.elements.length > 0;
|
||||||
smoothButton.reactive = this.area.elements.length > 0 && this.area.elements[this.area.elements.length - 1].shape == Area.Tools.NONE;
|
smoothButton.reactive = this.area.elements.length > 0 && this.area.elements[this.area.elements.length - 1].shape == this.drawingTools.NONE;
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateSectionVisibility: function() {
|
_updateSectionVisibility: function() {
|
||||||
let [isText, isImage] = [this.area.currentTool == Area.Tools.TEXT, this.area.currentTool == Area.Tools.IMAGE];
|
let [isText, isImage] = [this.area.currentTool == this.drawingTools.TEXT, this.area.currentTool == this.drawingTools.IMAGE];
|
||||||
this.lineSection.actor.visible = !isText && !isImage;
|
this.lineSection.actor.visible = !isText && !isImage;
|
||||||
this.fontSection.actor.visible = isText;
|
this.fontSection.actor.visible = isText;
|
||||||
this.imageSection.actor.visible = isImage;
|
this.imageSection.actor.visible = isImage;
|
||||||
|
|
@ -306,13 +376,13 @@ var DrawingMenu = new Lang.Class({
|
||||||
|
|
||||||
_addSliderItem: function(menu, target, targetProperty) {
|
_addSliderItem: function(menu, target, targetProperty) {
|
||||||
let item = new PopupMenu.PopupBaseMenuItem({ activate: false });
|
let item = new PopupMenu.PopupBaseMenuItem({ activate: false });
|
||||||
let label = new St.Label({ text: _("%d px").format(target[targetProperty]), style_class: 'draw-on-your-screen-menu-slider-label' });
|
let label = new St.Label({ text: DisplayStrings.getPixels(target[targetProperty]), style_class: 'draw-on-your-screen-menu-slider-label' });
|
||||||
let slider = new Slider.Slider(target[targetProperty] / 50);
|
let slider = new Slider.Slider(target[targetProperty] / 50);
|
||||||
|
|
||||||
if (GS_VERSION < '3.33.0') {
|
if (GS_VERSION < '3.33.0') {
|
||||||
slider.connect('value-changed', (slider, value, property) => {
|
slider.connect('value-changed', (slider, value, property) => {
|
||||||
target[targetProperty] = Math.max(Math.round(value * 50), 0);
|
target[targetProperty] = Math.max(Math.round(value * 50), 0);
|
||||||
label.set_text(_("%d px").format(target[targetProperty]));
|
label.set_text(DisplayStrings.getPixels(target[targetProperty]));
|
||||||
if (target[targetProperty] === 0)
|
if (target[targetProperty] === 0)
|
||||||
label.add_style_class_name(WARNING_COLOR_STYLE_CLASS_NAME);
|
label.add_style_class_name(WARNING_COLOR_STYLE_CLASS_NAME);
|
||||||
else
|
else
|
||||||
|
|
@ -321,7 +391,7 @@ var DrawingMenu = new Lang.Class({
|
||||||
} else {
|
} else {
|
||||||
slider.connect('notify::value', () => {
|
slider.connect('notify::value', () => {
|
||||||
target[targetProperty] = Math.max(Math.round(slider.value * 50), 0);
|
target[targetProperty] = Math.max(Math.round(slider.value * 50), 0);
|
||||||
label.set_text(_("%d px").format(target[targetProperty]));
|
label.set_text(DisplayStrings.getPixels(target[targetProperty]));
|
||||||
if (target[targetProperty] === 0)
|
if (target[targetProperty] === 0)
|
||||||
label.add_style_class_name(WARNING_COLOR_STYLE_CLASS_NAME);
|
label.add_style_class_name(WARNING_COLOR_STYLE_CLASS_NAME);
|
||||||
else
|
else
|
||||||
|
|
@ -340,7 +410,7 @@ var DrawingMenu = new Lang.Class({
|
||||||
_addSubMenuItem: function(menu, icon, obj, target, targetProperty, callback) {
|
_addSubMenuItem: function(menu, icon, obj, target, targetProperty, callback) {
|
||||||
if (targetProperty == 'currentImage')
|
if (targetProperty == 'currentImage')
|
||||||
icon = obj[target[targetProperty]].gicon;
|
icon = obj[target[targetProperty]].gicon;
|
||||||
let item = new PopupMenu.PopupSubMenuMenuItem(_(String(obj[target[targetProperty]])), icon ? true : false);
|
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))
|
if (icon && icon instanceof GObject.Object && GObject.type_is_a(icon, Gio.Icon))
|
||||||
item.icon.set_gicon(icon);
|
item.icon.set_gicon(icon);
|
||||||
else if (icon)
|
else if (icon)
|
||||||
|
|
@ -354,15 +424,15 @@ var DrawingMenu = new Lang.Class({
|
||||||
for (let i in obj) {
|
for (let i in obj) {
|
||||||
let text;
|
let text;
|
||||||
if (targetProperty == 'currentFontWeight')
|
if (targetProperty == 'currentFontWeight')
|
||||||
text = `<span font_weight="${i}">${_(obj[i])}</span>`;
|
text = `<span font_weight="${i}">${obj[i]}</span>`;
|
||||||
else if (targetProperty == 'currentFontStyle')
|
else if (targetProperty == 'currentFontStyle')
|
||||||
text = `<span font_style="${obj[i].toLowerCase()}">${_(obj[i])}</span>`;
|
text = `<span font_style="${DisplayStrings.FontStyleMarkup[i]}">${obj[i]}</span>`;
|
||||||
else
|
else
|
||||||
text = _(String(obj[i]));
|
text = String(obj[i]);
|
||||||
|
|
||||||
let iCaptured = Number(i);
|
let iCaptured = Number(i);
|
||||||
let subItem = item.menu.addAction(text, () => {
|
let subItem = item.menu.addAction(text, () => {
|
||||||
item.label.set_text(_(String(obj[iCaptured])));
|
item.label.set_text(String(obj[iCaptured]));
|
||||||
target[targetProperty] = iCaptured;
|
target[targetProperty] = iCaptured;
|
||||||
if (targetProperty == 'currentImage')
|
if (targetProperty == 'currentImage')
|
||||||
item.icon.set_gicon(obj[iCaptured].gicon);
|
item.icon.set_gicon(obj[iCaptured].gicon);
|
||||||
|
|
@ -374,9 +444,9 @@ var DrawingMenu = new Lang.Class({
|
||||||
getActor(subItem).connect('key-focus-in', updateSubMenuAdjustment);
|
getActor(subItem).connect('key-focus-in', updateSubMenuAdjustment);
|
||||||
|
|
||||||
// change the display order of tools
|
// change the display order of tools
|
||||||
if (obj == Area.ToolNames && i == Area.Tools.POLYGON)
|
if (obj == DisplayStrings.Tool && i == this.drawingTools.POLYGON)
|
||||||
item.menu.moveMenuItem(subItem, 4);
|
item.menu.moveMenuItem(subItem, 4);
|
||||||
else if (obj == Area.ToolNames && i == Area.Tools.POLYLINE)
|
else if (obj == DisplayStrings.Tool && i == this.drawingTools.POLYLINE)
|
||||||
item.menu.moveMenuItem(subItem, 5);
|
item.menu.moveMenuItem(subItem, 5);
|
||||||
}
|
}
|
||||||
return GLib.SOURCE_REMOVE;
|
return GLib.SOURCE_REMOVE;
|
||||||
|
|
@ -445,7 +515,7 @@ var DrawingMenu = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
_addFontFamilySubMenuItem: function(menu, icon) {
|
_addFontFamilySubMenuItem: function(menu, icon) {
|
||||||
let item = new PopupMenu.PopupSubMenuMenuItem(this.area.currentFontFamily, true);
|
let item = new PopupMenu.PopupSubMenuMenuItem(DisplayStrings.getFontFamily(this.area.currentFontFamily), true);
|
||||||
item.icon.set_icon_name(icon);
|
item.icon.set_icon_name(icon);
|
||||||
|
|
||||||
item.menu.itemActivated = () => {
|
item.menu.itemActivated = () => {
|
||||||
|
|
@ -456,8 +526,8 @@ var DrawingMenu = new Lang.Class({
|
||||||
item.menu.open = (animate) => {
|
item.menu.open = (animate) => {
|
||||||
if (!item.menu.isOpen && item.menu.isEmpty()) {
|
if (!item.menu.isOpen && item.menu.isEmpty()) {
|
||||||
this.area.fontFamilies.forEach(family => {
|
this.area.fontFamilies.forEach(family => {
|
||||||
let subItem = item.menu.addAction(_(family), () => {
|
let subItem = item.menu.addAction(DisplayStrings.getFontFamily(family), () => {
|
||||||
item.label.set_text(_(family));
|
item.label.set_text(DisplayStrings.getFontFamily(family));
|
||||||
this.area.currentFontFamily = family;
|
this.area.currentFontFamily = family;
|
||||||
});
|
});
|
||||||
if (FONT_FAMILY_STYLE)
|
if (FONT_FAMILY_STYLE)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue