Skip to content

Commit

Permalink
Merge pull request #68 from swsnr/swsnr/issue67
Browse files Browse the repository at this point in the history
Define additional shortcuts
  • Loading branch information
swsnr authored Dec 30, 2024
2 parents 98c333b + 24a02bf commit 499b787
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 71 deletions.
1 change: 1 addition & 0 deletions resources/de.swsnr.turnon.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<release version="next" date="9999-01-01">
<description>
<p>Save and restore main window state.</p>
<p>Define additional shortcuts.</p>
<p>Update translations.</p>
</description>
<issues>
Expand Down
55 changes: 53 additions & 2 deletions resources/gtk/help-overlay.blp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,64 @@ Gtk.ShortcutsWindow help_overlay {
section-name: "shortcuts";

Gtk.ShortcutsGroup {
title: C_("shortcuts group", "General");
title: C_("shortcuts group", "Devices");

Gtk.ShortcutsShortcut {
title: C_("shortcut description", "Add a new device");
action-name: "win.add-device";
accelerator: "<Ctrl>N";
}

Gtk.ShortcutsShortcut {
title: C_("shortcut description", "Toggle network scanning");
accelerator: "F5";
}
}

Gtk.ShortcutsGroup {
title: C_("shortcuts group", "Single device");

Gtk.ShortcutsShortcut {
title: C_("shortcut description", "Turn on device");
accelerator: "Return";
}

Gtk.ShortcutsShortcut {
title: C_("shortcut description", "Edit device");
accelerator: "<Alt>Return";
}

Gtk.ShortcutsShortcut {
title: C_("shortcut description", "Ask to delete device");
accelerator: "Delete";
}

Gtk.ShortcutsShortcut {
title: C_("shortcut description", "Immediately delete device without confirmation");
accelerator: "<Ctrl>Delete";
}
}

Gtk.ShortcutsGroup {
title: C_("shortcuts group", "Discovered device");

Gtk.ShortcutsShortcut {
title: C_("shortcut description", "Add as a new device");
accelerator: "<Ctrl>N";
}
}

Gtk.ShortcutsGroup {
title: C_("shortcuts group", "Edit device");

Gtk.ShortcutsShortcut {
title: C_("shortcut description", "Save device");
accelerator: "<Ctrl>S";
}
}

Gtk.ShortcutsGroup {
title: C_("shortcuts group", "General");

Gtk.ShortcutsShortcut {
title: C_("shortcut description", "Show shortcuts");
action-name: "win.show-help-overlay";
Expand Down
66 changes: 64 additions & 2 deletions resources/gtk/help-overlay.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,75 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<property name="section-name">shortcuts</property>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcuts group">General</property>
<property name="title" translatable="yes" context="shortcuts group">Devices</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut description">Add a new device</property>
<property name="action-name">win.add-device</property>
<property name="accelerator">&lt;Ctrl&gt;N</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut description">Toggle network scanning</property>
<property name="accelerator">F5</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcuts group">Single device</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut description">Turn on device</property>
<property name="accelerator">Return</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut description">Edit device</property>
<property name="accelerator">&lt;Alt&gt;Return</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut description">Ask to delete device</property>
<property name="accelerator">Delete</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut description">Immediately delete device without confirmation</property>
<property name="accelerator">&lt;Ctrl&gt;Delete</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcuts group">Discovered device</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut description">Add as a new device</property>
<property name="accelerator">&lt;Ctrl&gt;N</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcuts group">Edit device</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut description">Save device</property>
<property name="accelerator">&lt;Ctrl&gt;S</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes" context="shortcuts group">General</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut description">Show shortcuts</property>
Expand Down
14 changes: 7 additions & 7 deletions resources/ui/device-row.blp
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,37 @@ template $DeviceRow: Adw.ActionRow {
child: Gtk.Box {
orientation: horizontal;

Gtk.Button {
Gtk.Button add {
icon-name: "list-add-symbolic";
tooltip-text: C_("device-row.action.row.add.tooltip", "Add this device");
action-name: "row.add";
valign: center;
visible: bind template.can-add;
visible: bind add.sensitive;

styles [
"flat"
]
}

Gtk.Button {
Gtk.Button edit {
icon-name: "document-edit-symbolic";
tooltip-text: C_("device-row.action.row.edit.tooltip", "Edit this device");
action-name: "row.edit";
valign: center;
visible: bind template.can-edit;
visible: bind edit.sensitive;

styles [
"flat"
]
}

Gtk.Button {
Gtk.Button delete {
icon-name: "user-trash-symbolic";
tooltip-text: C_("device-row.action.row.ask-delete.tooltip", "Delete this device?");
action-name: "row.ask_delete";
action-name: "row.ask-delete";
margin-start: 6;
valign: center;
visible: bind template.can-delete;
visible: bind delete.sensitive;

styles [
"flat"
Expand Down
14 changes: 7 additions & 7 deletions resources/ui/device-row.ui
Original file line number Diff line number Diff line change
Expand Up @@ -90,37 +90,37 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<object class="GtkBox">
<property name="orientation">0</property>
<child>
<object class="GtkButton">
<object class="GtkButton" id="add">
<property name="icon-name">list-add-symbolic</property>
<property name="tooltip-text" translatable="yes" context="device-row.action.row.add.tooltip">Add this device</property>
<property name="action-name">row.add</property>
<property name="valign">3</property>
<property name="visible" bind-source="DeviceRow" bind-property="can-add" bind-flags="sync-create"/>
<property name="visible" bind-source="add" bind-property="sensitive" bind-flags="sync-create"/>
<style>
<class name="flat"/>
</style>
</object>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="edit">
<property name="icon-name">document-edit-symbolic</property>
<property name="tooltip-text" translatable="yes" context="device-row.action.row.edit.tooltip">Edit this device</property>
<property name="action-name">row.edit</property>
<property name="valign">3</property>
<property name="visible" bind-source="DeviceRow" bind-property="can-edit" bind-flags="sync-create"/>
<property name="visible" bind-source="edit" bind-property="sensitive" bind-flags="sync-create"/>
<style>
<class name="flat"/>
</style>
</object>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="delete">
<property name="icon-name">user-trash-symbolic</property>
<property name="tooltip-text" translatable="yes" context="device-row.action.row.ask-delete.tooltip">Delete this device?</property>
<property name="action-name">row.ask_delete</property>
<property name="action-name">row.ask-delete</property>
<property name="margin-start">6</property>
<property name="valign">3</property>
<property name="visible" bind-source="DeviceRow" bind-property="can-delete" bind-flags="sync-create"/>
<property name="visible" bind-source="delete" bind-property="sensitive" bind-flags="sync-create"/>
<style>
<class name="flat"/>
</style>
Expand Down
12 changes: 10 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ impl TurnOnApplication {
];
self.add_action_entries(actions);

self.set_accels_for_action("win.add-device", &["<Control>n"]);
self.set_accels_for_action("window.close", &["<Control>w"]);
self.set_accels_for_action("app.quit", &["<Control>q"]);
}
Expand Down Expand Up @@ -339,7 +338,7 @@ mod imp {
fn activate(&self) {
glib::debug!("Activating application");
self.parent_activate();
let app: &super::TurnOnApplication = &self.obj();
let app = &*self.obj();
match app.active_window() {
Some(window) => {
glib::debug!("Representing existing application window");
Expand All @@ -352,6 +351,15 @@ mod imp {
window.add_css_class("devel");
}
window.bind_model(&self.devices);
window.connect_scan_network_notify(glib::clone!(
#[strong]
app,
move |window| {
app.devices()
.discovered_devices()
.set_discovery_enabled(window.scan_network());
}
));
window.present();
}
}
Expand Down
Loading

0 comments on commit 499b787

Please sign in to comment.