DEFAULT_FILE_NAME and getDateString()
Prepare save and open drawing features.
This commit is contained in:
parent
f0ac2a21b0
commit
7878af7157
13
draw.js
13
draw.js
|
|
@ -47,6 +47,7 @@ const Prefs = Extension.imports.prefs;
|
||||||
const _ = imports.gettext.domain(Extension.metadata["gettext-domain"]).gettext;
|
const _ = imports.gettext.domain(Extension.metadata["gettext-domain"]).gettext;
|
||||||
|
|
||||||
const GS_VERSION = Config.PACKAGE_VERSION;
|
const GS_VERSION = Config.PACKAGE_VERSION;
|
||||||
|
const DEFAULT_FILE_NAME = 'DrawOnYourScreen';
|
||||||
|
|
||||||
const FILL_ICON_PATH = Extension.dir.get_child('icons').get_child('fill-symbolic.svg').get_path();
|
const FILL_ICON_PATH = Extension.dir.get_child('icons').get_child('fill-symbolic.svg').get_path();
|
||||||
const STROKE_ICON_PATH = Extension.dir.get_child('icons').get_child('stroke-symbolic.svg').get_path();
|
const STROKE_ICON_PATH = Extension.dir.get_child('icons').get_child('stroke-symbolic.svg').get_path();
|
||||||
|
|
@ -64,6 +65,11 @@ var FontWeightNames = { 0: 'Normal', 1: 'Bold' };
|
||||||
var FontStyleNames = { 0: 'Normal', 1: 'Italic', 2: 'Oblique' };
|
var FontStyleNames = { 0: 'Normal', 1: 'Italic', 2: 'Oblique' };
|
||||||
var FontFamilyNames = { 0: 'Default', 1: 'Sans-Serif', 2: 'Serif', 3: 'Monospace', 4: 'Cursive', 5: 'Fantasy' };
|
var FontFamilyNames = { 0: 'Default', 1: 'Sans-Serif', 2: 'Serif', 3: 'Monospace', 4: 'Cursive', 5: 'Fantasy' };
|
||||||
|
|
||||||
|
function getDateString() {
|
||||||
|
let date = GLib.DateTime.new_now_local();
|
||||||
|
return `${date.format("%F")} ${date.format("%X")}`;
|
||||||
|
}
|
||||||
|
|
||||||
// DrawingArea is the widget in which we draw, thanks to Cairo.
|
// DrawingArea is the widget in which we draw, thanks to Cairo.
|
||||||
// It creates and manages a DrawingElement for each "brushstroke".
|
// It creates and manages a DrawingElement for each "brushstroke".
|
||||||
// It handles pointer/mouse/(touch?) events and some keyboard events.
|
// It handles pointer/mouse/(touch?) events and some keyboard events.
|
||||||
|
|
@ -606,8 +612,7 @@ var DrawingArea = new Lang.Class({
|
||||||
}
|
}
|
||||||
content += "\n</svg>";
|
content += "\n</svg>";
|
||||||
|
|
||||||
let date = GLib.DateTime.new_now_local();
|
let filename = `${DEFAULT_FILE_NAME} ${getDateString()}.svg`;
|
||||||
let filename = `DrawOnYourScreen ${date.format("%F")} ${date.format("%X")}.svg`;
|
|
||||||
let dir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES);
|
let dir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES);
|
||||||
let path = GLib.build_filenamev([dir, filename]);
|
let path = GLib.build_filenamev([dir, filename]);
|
||||||
if (GLib.file_test(path, GLib.FileTest.EXISTS))
|
if (GLib.file_test(path, GLib.FileTest.EXISTS))
|
||||||
|
|
@ -628,7 +633,7 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
saveAsJson: function() {
|
saveAsJson: function() {
|
||||||
let filename = `DrawOnYourScreen.json`;
|
let filename = `${DEFAULT_FILE_NAME}.json`;
|
||||||
let dir = GLib.get_user_data_dir();
|
let dir = GLib.get_user_data_dir();
|
||||||
let path = GLib.build_filenamev([dir, filename]);
|
let path = GLib.build_filenamev([dir, filename]);
|
||||||
|
|
||||||
|
|
@ -652,7 +657,7 @@ var DrawingArea = new Lang.Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
_loadJson: function() {
|
_loadJson: function() {
|
||||||
let filename = `DrawOnYourScreen.json`;
|
let filename = `${DEFAULT_FILE_NAME}.json`;
|
||||||
let dir = GLib.get_user_data_dir();
|
let dir = GLib.get_user_data_dir();
|
||||||
let path = GLib.build_filenamev([dir, filename]);
|
let path = GLib.build_filenamev([dir, filename]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue