Skip to content

Commit

Permalink
Merge pull request #65 from themighty1/position_toggle
Browse files Browse the repository at this point in the history
Allow to toggle notes' position with a shortcut
  • Loading branch information
maoschanz authored Nov 20, 2021
2 parents b1578f5 + 8f16b4c commit 5b4fa39
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 23 deletions.
62 changes: 54 additions & 8 deletions notes@maestroschan.fr/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,34 @@ class NotesManager {

// Initialisation of the signals connections
this._bindShortcut();
this._bindLayerShortcut();
this._connectAllSignals();
}

_bindShortcut () {
this.USE_SHORTCUT = Convenience.getSettings().get_boolean('use-shortcut');
if (!this.USE_SHORTCUT) { return; }
if (this.USE_SHORTCUT) {
Main.wm.addKeybinding(
'notes-kb-shortcut',
Convenience.getSettings(),
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.ALL,
this._toggleState.bind(this)
);
}
}

Main.wm.addKeybinding(
'notes-kb-shortcut',
Convenience.getSettings(),
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.ALL,
this._toggleState.bind(this)
);
_bindLayerShortcut () {
this.USE_LAYER_SHORTCUT = Convenience.getSettings().get_boolean('use-layer-shortcut');
if (this.USE_LAYER_SHORTCUT) {
Main.wm.addKeybinding(
'notes-layer-kb-shortcut',
Convenience.getSettings(),
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.ALL,
this._toggleLayer.bind(this)
);
}
}

_loadAllNotes () {
Expand Down Expand Up @@ -167,7 +181,19 @@ class NotesManager {

//--------------------------------------------------------------------------

_toggleLayer () {
switch (SETTINGS.get_string('layout-position')) {
case 'above-all':
SETTINGS.set_string('layout-position', 'on-background');
break;
case 'on-background':
SETTINGS.set_string('layout-position', 'above-all');
break;
}
}

_toggleState () {

if(!this._notesLoaded) {
this._loadAllNotes();
}
Expand Down Expand Up @@ -243,6 +269,14 @@ class NotesManager {
'changed::notes-kb-shortcut',
this._updateShortcut.bind(this)
);
this._settingsSignals['kb-shortcut-3'] = SETTINGS.connect(
'changed::use-layer-shortcut',
this._updateLayerShortcut.bind(this)
);
this._settingsSignals['kb-shortcut-4'] = SETTINGS.connect(
'changed::notes-layer-kb-shortcut',
this._updateLayerShortcut.bind(this)
);
this._settingsSignals['auto-focus'] = SETTINGS.connect(
'changed::auto-focus',
this._updateFocusSetting.bind(this)
Expand All @@ -256,6 +290,13 @@ class NotesManager {
this._bindShortcut();
}

_updateLayerShortcut () {
if(this.USE_LAYER_SHORTCUT) {
Main.wm.removeKeybinding('notes-layer-kb-shortcut');
}
this._bindLayerShortcut();
}

_updateFocusSetting () {
// XXX currently not very user-friendly
Main.notify(
Expand Down Expand Up @@ -304,6 +345,8 @@ class NotesManager {
SETTINGS.disconnect(this._settingsSignals['hide-icon']);
SETTINGS.disconnect(this._settingsSignals['kb-shortcut-1']);
SETTINGS.disconnect(this._settingsSignals['kb-shortcut-2']);
SETTINGS.disconnect(this._settingsSignals['kb-shortcut-3']);
SETTINGS.disconnect(this._settingsSignals['kb-shortcut-4']);
SETTINGS.disconnect(this._settingsSignals['auto-focus']);

this._allNotes.forEach(function (n) {
Expand All @@ -314,6 +357,9 @@ class NotesManager {
if(this.USE_SHORTCUT) {
Main.wm.removeKeybinding('notes-kb-shortcut');
}
if(this.USE_LAYER_SHORTCUT) {
Main.wm.removeKeybinding('notes-layer-kb-shortcut');
}

this.panel_button.destroy();
}
Expand Down
33 changes: 33 additions & 0 deletions notes@maestroschan.fr/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,39 @@ const NotesSettingsWidget = new GObject.Class({
this._hide_switch.sensitive = widget.active;
});


// Context: %s will be replaced with the default keyboard shortcut
let default_kbs_label2 = _("Default value is %s");
default_kbs_label2 = default_kbs_label2.replace('%s', "<Super><Alt>j");

// Text entry
let keybinding_entry2 = builder.get_object('keybinding_entry2');
keybinding_entry2.set_sensitive(SETTINGS.get_boolean('use-layer-shortcut'));
keybinding_entry2.set_tooltip_text(default_kbs_label2);

if (SETTINGS.get_strv('notes-layer-kb-shortcut') != '') {
keybinding_entry2.text = SETTINGS.get_strv('notes-layer-kb-shortcut')[0];
}

// "Apply" button
let keybinding_button2 = builder.get_object('keybinding_button2');
keybinding_button2.set_sensitive(SETTINGS.get_boolean('use-layer-shortcut'));

keybinding_button2.connect('clicked', (widget) => {
SETTINGS.set_strv('notes-layer-kb-shortcut', [keybinding_entry2.text]);
});

// "Enable shortcut" switch
let keybinding_switch2 = builder.get_object('keybinding_switch2');
keybinding_switch2.set_state(SETTINGS.get_boolean('use-layer-shortcut'));

keybinding_switch2.connect('notify::active', (widget) => {
SETTINGS.set_boolean('use-layer-shortcut', widget.active);
keybinding_entry2.sensitive = widget.active;
keybinding_button2.sensitive = widget.active;
this._hide_switch.sensitive = widget.active;
});

//----------------------------------------------------------------------

// The default color of the very first note
Expand Down
119 changes: 104 additions & 15 deletions notes@maestroschan.fr/prefs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">15</property>
<property name="top-attach">14</property>
<property name="width">2</property>
</packing>
</child>
Expand All @@ -138,25 +138,94 @@
<object class="GtkLabel">
<property name="expand">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Use a keyboard shortcut</property>
<property name="tooltip_text" translatable="yes">Use a keyboard shortcut to toggle notes</property>
<property name="label" translatable="yes">Toggle notes layer</property>
<property name="tooltip_text" translatable="yes">Use a keyboard shortcut to toggle notes layer (toggle between "Above everything" and "On the background")</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">17</property>
<property name="top-attach">15</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="keybinding_switch">
<object class="GtkBox">
<property name="expand">False</property>
<property name="halign">end</property>
<child>
<object class="GtkEntry" id="keybinding_entry2" />
</child>
<child>
<object class="GtkMenuButton">
<property name="tooltip-text" translatable="yes">Help</property>
<property name="popover">help-popover-1</property>
<child>
<object class="GtkBox">
<property name="spacing">2</property>
<child>
<object class="GtkImage">
<property name="icon-name">help-faq-symbolic</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="icon-name">pan-down-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
<style><class name="linked"/></style>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">16</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="halign">fill</property>
<child>
<object class="GtkButton" id="keybinding_button2">
<property name="expand">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Apply</property>
</object>
<packing>
<property name="position">1</property>
<property name="pack_type">start</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="keybinding_switch2">
<property name="expand">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
</object>
<packing>
<property name="position">2</property>
<property name="pack_type">end</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">16</property>
</packing>
</child>

<child>
<object class="GtkLabel">
<property name="expand">False</property>
<property name="halign">start</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Toggle notes visibility</property>
<property name="tooltip_text" translatable="yes">Use a keyboard shortcut to toggle notes visibility (toggle between "Show" and "Hide")</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="left-attach">0</property>
<property name="top-attach">17</property>
</packing>
</child>

<child>
<object class="GtkBox">
<property name="expand">False</property>
Expand Down Expand Up @@ -193,17 +262,37 @@
</packing>
</child>
<child>
<object class="GtkButton" id="keybinding_button">
<property name="expand">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Apply</property>
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="halign">fill</property>
<child>
<object class="GtkButton" id="keybinding_button">
<property name="expand">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Apply</property>
</object>
<packing>
<property name="position">1</property>
<property name="pack_type">start</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="keybinding_switch">
<property name="expand">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
</object>
<packing>
<property name="position">2</property>
<property name="pack_type">end</property>
</packing>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">18</property>
<property name="left-attach">1</property>
<property name="top-attach">18</property>
</packing>
</child>

<child>
<object class="GtkLabel">
<property name="halign">end</property>
Expand Down
Binary file modified notes@maestroschan.fr/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@
<description>Should be true only if there is shortcut.</description>
</key>

<key type="b" name="use-layer-shortcut">
<default>false</default>
<summary>Keyboard shortcut</summary>
<description>If the keyboard shortcut should be active</description>
</key>
<key name="notes-layer-kb-shortcut" type="as">
<default><![CDATA[['<Super><Alt>j','']]]></default>
<summary>Keyboard shortcut value</summary>
<description>Keyboard shortcut which toggles layer of notes.</description>
</key>

<!-- -->

<key type="b" name="ugly-hack">
Expand Down

0 comments on commit 5b4fa39

Please sign in to comment.