draw-to-osd 3
This commit is contained in:
parent
ef51bb8bf9
commit
9269022d0f
153
draw.js
153
draw.js
|
|
@ -32,19 +32,15 @@ const Pango = imports.gi.Pango;
|
|||
const PangoCairo = imports.gi.PangoCairo;
|
||||
const St = imports.gi.St;
|
||||
|
||||
const Config = imports.misc.config;
|
||||
const Screenshot = imports.ui.screenshot;
|
||||
const Tweener = imports.ui.tweener;
|
||||
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
const Me = ExtensionUtils.getCurrentExtension();
|
||||
const Convenience = ExtensionUtils.getSettings ? ExtensionUtils : Me.imports.convenience;
|
||||
const Extension = Me.imports.extension;
|
||||
const Menu = Me.imports.menu;
|
||||
const Prefs = Me.imports.prefs;
|
||||
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
||||
|
||||
const GS_VERSION = Config.PACKAGE_VERSION;
|
||||
const CAIRO_DEBUG_EXTENDS = false;
|
||||
const SVG_DEBUG_EXTENDS = false;
|
||||
const SVG_DEBUG_SUPERPOSES_CAIRO = false;
|
||||
|
|
@ -1903,152 +1899,3 @@ const getAngle = function(xO, yO, xA, yA, xB, yB) {
|
|||
return angle;
|
||||
};
|
||||
|
||||
const HELPER_ANIMATION_TIME = 0.25;
|
||||
const MEDIA_KEYS_SCHEMA = 'org.gnome.settings-daemon.plugins.media-keys';
|
||||
const MEDIA_KEYS_KEYS = {
|
||||
'screenshot': "Screenshot",
|
||||
'screenshot-clip': "Screenshot to clipboard",
|
||||
'area-screenshot': "Area screenshot",
|
||||
'area-screenshot-clip': "Area screenshot to clipboard"
|
||||
};
|
||||
|
||||
// DrawingHelper provides the "help osd" (Ctrl + F1)
|
||||
// It uses the same texts as in prefs
|
||||
var DrawingHelper = new Lang.Class({
|
||||
Name: 'DrawOnYourScreenDrawingHelper',
|
||||
Extends: St.ScrollView,
|
||||
|
||||
_init: function(params, monitor) {
|
||||
params.style_class = 'osd-window draw-on-your-screen-helper';
|
||||
this.parent(params);
|
||||
this.monitor = monitor;
|
||||
this.hide();
|
||||
this.settings = Convenience.getSettings();
|
||||
|
||||
this.settingHandler = this.settings.connect('changed', this._onSettingChanged.bind(this));
|
||||
this.connect('destroy', () => this.settings.disconnect(this.settingHandler));
|
||||
},
|
||||
|
||||
_onSettingChanged: function(settings, key) {
|
||||
if (key == 'toggle-help')
|
||||
this._updateHelpKeyLabel();
|
||||
|
||||
if (this.vbox) {
|
||||
this.vbox.destroy();
|
||||
this.vbox = null;
|
||||
}
|
||||
},
|
||||
|
||||
_updateHelpKeyLabel: function() {
|
||||
let [keyval, mods] = Gtk.accelerator_parse(this.settings.get_strv('toggle-help')[0]);
|
||||
this._helpKeyLabel = Gtk.accelerator_get_label(keyval, mods);
|
||||
},
|
||||
|
||||
get helpKeyLabel() {
|
||||
if (!this._helpKeyLabel)
|
||||
this._updateHelpKeyLabel();
|
||||
|
||||
return this._helpKeyLabel;
|
||||
},
|
||||
|
||||
_populate: function() {
|
||||
this.vbox = new St.BoxLayout({ vertical: true });
|
||||
this.add_actor(this.vbox);
|
||||
this.vbox.add_child(new St.Label({ text: _("Global") }));
|
||||
|
||||
for (let settingKey in Prefs.GLOBAL_KEYBINDINGS) {
|
||||
let hbox = new St.BoxLayout({ vertical: false });
|
||||
if (settingKey.indexOf('-separator-') != -1) {
|
||||
this.vbox.add_child(hbox);
|
||||
continue;
|
||||
}
|
||||
if (!this.settings.get_strv(settingKey)[0])
|
||||
continue;
|
||||
let [keyval, mods] = Gtk.accelerator_parse(this.settings.get_strv(settingKey)[0]);
|
||||
hbox.add_child(new St.Label({ text: _(Prefs.GLOBAL_KEYBINDINGS[settingKey]) }));
|
||||
hbox.add_child(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods), x_expand: true }));
|
||||
this.vbox.add_child(hbox);
|
||||
}
|
||||
|
||||
this.vbox.add_child(new St.Label({ text: _("Internal") }));
|
||||
|
||||
for (let i = 0; i < Prefs.OTHER_SHORTCUTS.length; i++) {
|
||||
if (Prefs.OTHER_SHORTCUTS[i].desc.indexOf('-separator-') != -1) {
|
||||
this.vbox.add_child(new St.BoxLayout({ vertical: false, style_class: 'draw-on-your-screen-helper-separator' }));
|
||||
continue;
|
||||
}
|
||||
let hbox = new St.BoxLayout({ vertical: false });
|
||||
hbox.add_child(new St.Label({ text: _(Prefs.OTHER_SHORTCUTS[i].desc) }));
|
||||
hbox.add_child(new St.Label({ text: Prefs.OTHER_SHORTCUTS[i].shortcut, x_expand: true }));
|
||||
hbox.get_children()[0].get_clutter_text().set_use_markup(true);
|
||||
this.vbox.add_child(hbox);
|
||||
}
|
||||
|
||||
this.vbox.add_child(new St.BoxLayout({ vertical: false, style_class: 'draw-on-your-screen-helper-separator' }));
|
||||
|
||||
for (let settingKey in Prefs.INTERNAL_KEYBINDINGS) {
|
||||
if (settingKey.indexOf('-separator-') != -1) {
|
||||
this.vbox.add_child(new St.BoxLayout({ vertical: false, style_class: 'draw-on-your-screen-helper-separator' }));
|
||||
continue;
|
||||
}
|
||||
let hbox = new St.BoxLayout({ vertical: false });
|
||||
if (!this.settings.get_strv(settingKey)[0])
|
||||
continue;
|
||||
let [keyval, mods] = Gtk.accelerator_parse(this.settings.get_strv(settingKey)[0]);
|
||||
hbox.add_child(new St.Label({ text: _(Prefs.INTERNAL_KEYBINDINGS[settingKey]) }));
|
||||
hbox.add_child(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods), x_expand: true }));
|
||||
this.vbox.add_child(hbox);
|
||||
}
|
||||
|
||||
let mediaKeysSettings;
|
||||
try { mediaKeysSettings = Convenience.getSettings(MEDIA_KEYS_SCHEMA); } catch(e) { return; }
|
||||
this.vbox.add_child(new St.Label({ text: _("System") }));
|
||||
|
||||
for (let settingKey in MEDIA_KEYS_KEYS) {
|
||||
if (!mediaKeysSettings.settings_schema.has_key(settingKey))
|
||||
continue;
|
||||
let shortcut = GS_VERSION < '3.33.0' ? mediaKeysSettings.get_string(settingKey) : mediaKeysSettings.get_strv(settingKey)[0];
|
||||
if (!shortcut)
|
||||
continue;
|
||||
let [keyval, mods] = Gtk.accelerator_parse(shortcut);
|
||||
let hbox = new St.BoxLayout({ vertical: false });
|
||||
hbox.add_child(new St.Label({ text: _(MEDIA_KEYS_KEYS[settingKey]) }));
|
||||
hbox.add_child(new St.Label({ text: Gtk.accelerator_get_label(keyval, mods), x_expand: true }));
|
||||
this.vbox.add_child(hbox);
|
||||
}
|
||||
},
|
||||
|
||||
showHelp: function() {
|
||||
if (!this.vbox)
|
||||
this._populate();
|
||||
|
||||
this.opacity = 0;
|
||||
this.show();
|
||||
|
||||
let maxHeight = this.monitor.height * 3 / 4;
|
||||
this.set_height(Math.min(this.height, maxHeight));
|
||||
this.set_position(Math.floor(this.monitor.width / 2 - this.width / 2),
|
||||
Math.floor(this.monitor.height / 2 - this.height / 2));
|
||||
|
||||
if (this.height == maxHeight)
|
||||
this.vscrollbar_policy = Gtk.PolicyType.ALWAYS;
|
||||
else
|
||||
this.vscrollbar_policy = Gtk.PolicyType.NEVER;
|
||||
|
||||
Tweener.removeTweens(this);
|
||||
Tweener.addTween(this, { opacity: 255,
|
||||
time: HELPER_ANIMATION_TIME,
|
||||
transition: 'easeOutQuad',
|
||||
onComplete: null });
|
||||
},
|
||||
|
||||
hideHelp: function() {
|
||||
Tweener.removeTweens(this);
|
||||
Tweener.addTween(this, { opacity: 0,
|
||||
time: HELPER_ANIMATION_TIME,
|
||||
transition: 'easeOutQuad',
|
||||
onComplete: this.hide.bind(this) });
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue