Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ The format is based on [Keep a Changelog], and this project adheres to
by [@ponta0]: [#1915].
- Added "Reset to default value" button for most settings in Preferences dialog:
[#1919].
- Multiple shortcuts can be assigned to the same action through Preferences
dialog: [#932], [#1918].

### Changed

### Removed

### Fixed

[#932]: https://github.com/ddterm/gnome-shell-extension-ddterm/issues/932
[#1915]: https://github.com/ddterm/gnome-shell-extension-ddterm/pull/1915
[#1919]: https://github.com/ddterm/gnome-shell-extension-ddterm/pull/1919
[#1918]: https://github.com/ddterm/gnome-shell-extension-ddterm/pull/1918

[@ponta0]: https://github.com/ponta0

Expand Down
82 changes: 70 additions & 12 deletions ddterm/pref/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ class ShortcutEditDialog extends Gtk.Dialog {
GObject.registerClass(this);
}

static RESPONSE_SET = Gtk.ResponseType.OK;
static RESPONSE_ADD = 1;

#controller;
#label;
#stack;

constructor(params) {
super({
Expand All @@ -184,11 +188,32 @@ class ShortcutEditDialog extends Gtk.Dialog {
margin_end: 16,
};

this.#append(new Gtk.Label({
this.#stack = new Gtk.Stack({
visible: true,
label: this.gettext_domain.gettext('Enter new shortcut'),
interpolate_size: true,
transition_type: this.get_direction() === Gtk.TextDirection.LTR
? Gtk.StackTransitionType.SLIDE_LEFT
: Gtk.StackTransitionType.SLIDE_RIGHT,
...margins,
}));
});

const enter_label = new Gtk.Label({
visible: true,
label: this.gettext_domain.gettext('Enter new shortcut'),
});

const accept_label = new Gtk.Label({
visible: true,
label: this.gettext_domain.gettext(
'Click "Set" to replace existing shortcut(s). ' +
'Click "Add" to add alternative shortcut.'
),
});

this.#stack.add_named(enter_label, 'enter');
this.#stack.add_named(accept_label, 'accept');

this.#append(this.#stack);

this.#label = new Gtk.ShortcutLabel({
visible: true,
Expand All @@ -207,10 +232,25 @@ class ShortcutEditDialog extends Gtk.Dialog {
...margins,
}));

this.add_button(this.gettext_domain.gettext('Cancel'), Gtk.ResponseType.CANCEL);
this.add_button(this.gettext_domain.gettext('Set'), Gtk.ResponseType.OK);
this.set_response_sensitive(Gtk.ResponseType.OK, false);
this.set_default_response(Gtk.ResponseType.OK);
this.add_button(
this.gettext_domain.gettext('Cancel'),
Gtk.ResponseType.CANCEL
);

this.add_button(
this.gettext_domain.gettext('Set'),
ShortcutEditDialog.RESPONSE_SET
);

this.add_button(
this.gettext_domain.gettext('Add'),
ShortcutEditDialog.RESPONSE_ADD
Comment thread
coderabbitai[bot] marked this conversation as resolved.
);

this.set_response_sensitive(ShortcutEditDialog.RESPONSE_SET, false);
this.set_response_sensitive(ShortcutEditDialog.RESPONSE_ADD, false);

this.set_default_response(ShortcutEditDialog.RESPONSE_SET);

this.connect('realize', this.#realize.bind(this));
}
Expand Down Expand Up @@ -247,7 +287,7 @@ class ShortcutEditDialog extends Gtk.Dialog {

if (keyval_lower === Gdk.KEY_BackSpace) {
this.#label.accelerator = null;
this.response(Gtk.ResponseType.OK);
this.response(ShortcutEditDialog.RESPONSE_SET);

return true;
}
Expand All @@ -263,10 +303,13 @@ class ShortcutEditDialog extends Gtk.Dialog {
const valid =
is_valid_accel(keyval_lower, real_mask) && is_valid_binding(keyval_lower, real_mask);

this.set_response_sensitive(Gtk.ResponseType.OK, valid);
this.set_response_sensitive(ShortcutEditDialog.RESPONSE_SET, valid);
this.set_response_sensitive(ShortcutEditDialog.RESPONSE_ADD, valid);

this.#stack.set_visible_child_name(valid ? 'accept' : 'enter');

if (valid)
this.get_widget_for_response(Gtk.ResponseType.OK).grab_focus();
this.get_widget_for_response(ShortcutEditDialog.RESPONSE_SET).grab_focus();

return true;
}
Expand Down Expand Up @@ -363,8 +406,23 @@ class ShortcutRow extends ActionRow {
});

dialog.connect('response', (_, response_id) => {
if (response_id === Gtk.ResponseType.OK) {
this.value = dialog.accelerator ? [dialog.accelerator] : [];
const { accelerator } = dialog;

if (response_id === ShortcutEditDialog.RESPONSE_SET) {
this.value = accelerator ? [accelerator] : [];
this.emit('accelerator-set');
} else if (response_id === ShortcutEditDialog.RESPONSE_ADD) {
const [keyval, modifiers] = accelerator_parse(accelerator);

this.freeze_notify();

try {
this.remove_conflict(keyval, modifiers);
this.value = [...this.value, accelerator];
} finally {
this.thaw_notify();
}

this.emit('accelerator-set');
}

Expand Down
Binary file modified docs/screenshots/shortcut-edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading