feat: adding active window selection and refactoring keybindings
This commit is contained in:
+95
-125
@@ -2,7 +2,7 @@ import Adw from 'gi://Adw';
|
||||
import Gio from 'gi://Gio';
|
||||
import Gtk from 'gi://Gtk';
|
||||
import Gdk from 'gi://Gdk';
|
||||
import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
|
||||
import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
|
||||
import {Logger} from "../utils/logger.js";
|
||||
import {EntryRow} from "./keybindings.js";
|
||||
|
||||
@@ -11,160 +11,115 @@ export default class AerospikeExtensions extends ExtensionPreferences {
|
||||
// Create settings object
|
||||
const settings = this.getSettings('org.gnome.shell.extensions.aerospike');
|
||||
|
||||
// Create a preferences page
|
||||
const page = new Adw.PreferencesPage({
|
||||
title: _('Settings'),
|
||||
icon_name: 'preferences-system-symbolic',
|
||||
// Create keybindings page (top-level)
|
||||
const keybindingsPage = new Adw.PreferencesPage({
|
||||
title: _('Keybindings'),
|
||||
icon_name: 'input-keyboard-symbolic',
|
||||
});
|
||||
window.add(page);
|
||||
window.add(keybindingsPage);
|
||||
|
||||
const keybindingMap = this.createKeybindingMap();
|
||||
|
||||
// Create options group
|
||||
const optionsGroup = new Adw.PreferencesGroup({
|
||||
title: _('Options'),
|
||||
});
|
||||
page.add(optionsGroup);
|
||||
|
||||
// Add dropdown
|
||||
const dropdownRow = new Adw.ComboRow({
|
||||
title: _('Select an option'),
|
||||
});
|
||||
optionsGroup.add(dropdownRow);
|
||||
|
||||
// Create dropdown model
|
||||
const dropdownModel = new Gtk.StringList();
|
||||
dropdownModel.append(_('Option 1'));
|
||||
dropdownModel.append(_('Option 2'));
|
||||
dropdownModel.append(_('Option 3'));
|
||||
dropdownModel.append(_('Option 4'));
|
||||
|
||||
dropdownRow.set_model(dropdownModel);
|
||||
|
||||
// Set the active option based on settings
|
||||
const currentOption = settings.get_string('dropdown-option');
|
||||
switch (currentOption) {
|
||||
case 'option1':
|
||||
dropdownRow.set_selected(0);
|
||||
break;
|
||||
case 'option2':
|
||||
dropdownRow.set_selected(1);
|
||||
break;
|
||||
case 'option3':
|
||||
dropdownRow.set_selected(2);
|
||||
break;
|
||||
case 'option4':
|
||||
dropdownRow.set_selected(3);
|
||||
break;
|
||||
default:
|
||||
dropdownRow.set_selected(0);
|
||||
}
|
||||
|
||||
// Connect dropdown change signal
|
||||
dropdownRow.connect('notify::selected', () => {
|
||||
const selected = dropdownRow.get_selected();
|
||||
let optionValue: string;
|
||||
|
||||
switch (selected) {
|
||||
case 0:
|
||||
optionValue = 'option1';
|
||||
break;
|
||||
case 1:
|
||||
optionValue = 'option2';
|
||||
break;
|
||||
case 2:
|
||||
optionValue = 'option3';
|
||||
break;
|
||||
case 3:
|
||||
optionValue = 'option4';
|
||||
break;
|
||||
default:
|
||||
optionValue = 'option1';
|
||||
}
|
||||
|
||||
settings.set_string('dropdown-option', optionValue);
|
||||
});
|
||||
|
||||
// Add color button
|
||||
const colorRow = new Adw.ActionRow({
|
||||
title: _('Choose a color'),
|
||||
});
|
||||
optionsGroup.add(colorRow);
|
||||
|
||||
const colorButton = new Gtk.ColorButton();
|
||||
colorRow.add_suffix(colorButton);
|
||||
colorRow.set_activatable_widget(colorButton);
|
||||
|
||||
// Set current color from settings
|
||||
const colorStr = settings.get_string('color-selection');
|
||||
const rgba = new Gdk.RGBA();
|
||||
rgba.parse(colorStr);
|
||||
colorButton.set_rgba(rgba);
|
||||
|
||||
// Connect color button signal
|
||||
colorButton.connect('color-set', () => {
|
||||
const color = colorButton.get_rgba().to_string();
|
||||
settings.set_string('color-selection', color);
|
||||
});
|
||||
|
||||
// Create keybindings group
|
||||
const keybindingsGroup = new Adw.PreferencesGroup({
|
||||
title: _('Keyboard Shortcuts'),
|
||||
// Top-level Keybindings header group with syntax help
|
||||
const keybindingsHeader = new Adw.PreferencesGroup({
|
||||
title: _('Keybindings'),
|
||||
description: `${_("Syntax")}: <Super>h, <Shift>g, <Super><Shift>h
|
||||
${_("Legend")}: <Super> - ${_("Windows key")}, <Primary> - ${_("Control key")}
|
||||
${_("Delete text to unset. Press Return key to accept.")}`,
|
||||
});
|
||||
page.add(keybindingsGroup);
|
||||
keybindingsPage.add(keybindingsHeader);
|
||||
|
||||
// Add keybinding rows as EntryRows with proper mapping
|
||||
// Use the helper function to create the map object
|
||||
const keybindingMap = this.createKeybindingMap();
|
||||
|
||||
keybindingsGroup.add(
|
||||
// --- Focus group ---
|
||||
const focusGroup = new Adw.PreferencesGroup({
|
||||
title: _('Focus'),
|
||||
});
|
||||
keybindingsPage.add(focusGroup);
|
||||
|
||||
focusGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Action 1'),
|
||||
title: _('Focus Left'),
|
||||
settings: settings,
|
||||
bind: 'focus-left',
|
||||
map: keybindingMap
|
||||
})
|
||||
);
|
||||
|
||||
focusGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Focus Right'),
|
||||
settings: settings,
|
||||
bind: 'focus-right',
|
||||
map: keybindingMap
|
||||
})
|
||||
);
|
||||
|
||||
focusGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Focus Up'),
|
||||
settings: settings,
|
||||
bind: 'focus-up',
|
||||
map: keybindingMap
|
||||
})
|
||||
);
|
||||
|
||||
focusGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Focus Down'),
|
||||
settings: settings,
|
||||
bind: 'focus-down',
|
||||
map: keybindingMap
|
||||
})
|
||||
);
|
||||
|
||||
// --- Move group ---
|
||||
const moveGroup = new Adw.PreferencesGroup({
|
||||
title: _('Move'),
|
||||
});
|
||||
keybindingsPage.add(moveGroup);
|
||||
|
||||
moveGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Move Left'),
|
||||
settings: settings,
|
||||
bind: 'move-left',
|
||||
map: keybindingMap
|
||||
})
|
||||
);
|
||||
|
||||
keybindingsGroup.add(
|
||||
|
||||
moveGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Action 2'),
|
||||
title: _('Move Right'),
|
||||
settings: settings,
|
||||
bind: 'move-right',
|
||||
map: keybindingMap
|
||||
})
|
||||
);
|
||||
|
||||
keybindingsGroup.add(
|
||||
|
||||
moveGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Action 3'),
|
||||
title: _('Move Up'),
|
||||
settings: settings,
|
||||
bind: 'join-with-left',
|
||||
map: keybindingMap
|
||||
})
|
||||
);
|
||||
|
||||
keybindingsGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Action 4'),
|
||||
settings: settings,
|
||||
bind: 'join-with-right',
|
||||
bind: 'move-up',
|
||||
map: keybindingMap
|
||||
})
|
||||
);
|
||||
|
||||
keybindingsGroup.add(
|
||||
moveGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Print Tree Structure'),
|
||||
title: _('Move Down'),
|
||||
settings: settings,
|
||||
bind: 'print-tree',
|
||||
bind: 'move-down',
|
||||
map: keybindingMap
|
||||
})
|
||||
);
|
||||
|
||||
keybindingsGroup.add(
|
||||
// --- Container Interactions group ---
|
||||
const containerGroup = new Adw.PreferencesGroup({
|
||||
title: _('Container Interactions'),
|
||||
});
|
||||
keybindingsPage.add(containerGroup);
|
||||
|
||||
containerGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Toggle Orientation'),
|
||||
settings: settings,
|
||||
@@ -173,7 +128,7 @@ export default class AerospikeExtensions extends ExtensionPreferences {
|
||||
})
|
||||
);
|
||||
|
||||
keybindingsGroup.add(
|
||||
containerGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Reset Container Ratios to Equal'),
|
||||
settings: settings,
|
||||
@@ -182,7 +137,7 @@ export default class AerospikeExtensions extends ExtensionPreferences {
|
||||
})
|
||||
);
|
||||
|
||||
keybindingsGroup.add(
|
||||
containerGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Toggle Tabbed Mode'),
|
||||
settings: settings,
|
||||
@@ -191,6 +146,21 @@ export default class AerospikeExtensions extends ExtensionPreferences {
|
||||
})
|
||||
);
|
||||
|
||||
// --- Debugging group ---
|
||||
const debuggingGroup = new Adw.PreferencesGroup({
|
||||
title: _('Debugging'),
|
||||
});
|
||||
keybindingsPage.add(debuggingGroup);
|
||||
|
||||
debuggingGroup.add(
|
||||
new EntryRow({
|
||||
title: _('Print Tree Structure'),
|
||||
settings: settings,
|
||||
bind: 'print-tree',
|
||||
map: keybindingMap
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// Helper function to create a keybinding mapping object
|
||||
|
||||
Reference in New Issue
Block a user