Skip to content

Commit 81657b4

Browse files
committed
feat(shortcuts): Port to libadwaita 1.8
1 parent 24a3e3e commit 81657b4

File tree

9 files changed

+197
-170
lines changed

9 files changed

+197
-170
lines changed

dialect/dialect.gresource.xml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,50 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8" ?>
22
<gresources>
33
<gresource prefix="/app/drey/Dialect">
44
<file compressed="true">style.css</file>
5-
<file compressed="true">style-dark.css</file>
65

76
<file compressed="true" preprocess="xml-stripblanks">preferences.ui</file>
8-
<file compressed="true" preprocess="xml-stripblanks">shortcuts.ui</file>
7+
<file
8+
compressed="true"
9+
preprocess="xml-stripblanks"
10+
>shortcuts-dialog.ui</file>
911
<file compressed="true" preprocess="xml-stripblanks">window.ui</file>
10-
<file compressed="true" preprocess="xml-stripblanks">widgets/lang_row.ui</file>
11-
<file compressed="true" preprocess="xml-stripblanks">widgets/lang_selector.ui</file>
12-
<file compressed="true" preprocess="xml-stripblanks">widgets/provider_preferences.ui</file>
13-
<file compressed="true" preprocess="xml-stripblanks">widgets/speech_button.ui</file>
14-
<file compressed="true" preprocess="xml-stripblanks">widgets/theme_switcher.ui</file>
12+
<file
13+
compressed="true"
14+
preprocess="xml-stripblanks"
15+
>widgets/lang_row.ui</file>
16+
<file
17+
compressed="true"
18+
preprocess="xml-stripblanks"
19+
>widgets/lang_selector.ui</file>
20+
<file
21+
compressed="true"
22+
preprocess="xml-stripblanks"
23+
>widgets/provider_preferences.ui</file>
24+
<file
25+
compressed="true"
26+
preprocess="xml-stripblanks"
27+
>widgets/speech_button.ui</file>
28+
<file
29+
compressed="true"
30+
preprocess="xml-stripblanks"
31+
>widgets/theme_switcher.ui</file>
1532

16-
<file compressed="true" preprocess="xml-stripblanks" alias="appdata.xml">@appstream-path@</file>
33+
<file
34+
compressed="true"
35+
preprocess="xml-stripblanks"
36+
alias="appdata.xml"
37+
>@appstream-path@</file>
1738
</gresource>
1839

1940
<gresource prefix="/app/drey/Dialect/icons/scalable/emblems/">
20-
<file preprocess="xml-stripblanks" alias="dialect-settings-symbolic.svg">icons/settings-symbolic.svg</file>
21-
<file preprocess="xml-stripblanks" alias="dialect-speakers-broken-symbolic.svg">icons/speakers-broken-symbolic.svg</file>
41+
<file
42+
preprocess="xml-stripblanks"
43+
alias="dialect-settings-symbolic.svg"
44+
>icons/settings-symbolic.svg</file>
45+
<file
46+
preprocess="xml-stripblanks"
47+
alias="dialect-speakers-broken-symbolic.svg"
48+
>icons/speakers-broken-symbolic.svg</file>
2249
</gresource>
2350
</gresources>

dialect/main.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
gi.require_version("Spelling", "1")
2222
gi.require_version("GtkSource", "5")
2323

24-
from gi.repository import Adw, Gio, GLib, Gst
24+
from gi.repository import Adw, Gio, GLib, Gst, Gtk
2525
except ImportError or ValueError:
2626
logging.error("Error: GObject dependencies not met.")
2727
exit()
@@ -144,12 +144,17 @@ def setup_actions(self):
144144
about.connect("activate", self._on_about)
145145
self.add_action(about)
146146

147+
shortcuts = Gio.SimpleAction(name="shortcuts")
148+
shortcuts.connect("activate", self._on_shortcuts)
149+
self.add_action(shortcuts)
150+
147151
quit_action = Gio.SimpleAction(name="quit")
148152
quit_action.connect("activate", self._on_quit)
149153
self.add_action(quit_action)
150154

151155
self.set_accels_for_action("app.pronunciation", ["<Primary>P"])
152156
self.set_accels_for_action("app.preferences", ["<Primary>comma"])
157+
self.set_accels_for_action("app.shortcuts", ["<Primary>question"])
153158
self.set_accels_for_action("app.quit", ["<Primary>Q"])
154159

155160
self.set_accels_for_action("win.back", ["<Alt>Left"])
@@ -164,7 +169,6 @@ def setup_actions(self):
164169
self.set_accels_for_action("win.copy", ["<Primary><Shift>C"])
165170
self.set_accels_for_action("win.listen-dest", ["<Primary>L"])
166171
self.set_accels_for_action("win.listen-src", ["<Primary><Shift>L"])
167-
self.set_accels_for_action("win.show-help-overlay", ["<Primary>question"])
168172

169173
def _on_pronunciation(self, action: Gio.SimpleAction, value: GLib.Variant):
170174
"""Update show pronunciation setting"""
@@ -193,6 +197,27 @@ def _on_about(self, _action, _param):
193197

194198
about.present(self.window)
195199

200+
def _on_shortcuts(self, _action, _param):
201+
"""Show shortcuts dialog"""
202+
if not self.window:
203+
return
204+
205+
# Load the shortcuts dialog from resources
206+
builder = Gtk.Builder.new_from_resource(f"{RES_PATH}/shortcuts-dialog.ui")
207+
dialog = builder.get_object("shortcuts_dialog")
208+
translation_section = builder.get_object("translation_section")
209+
210+
if not Settings.get().live_translation:
211+
# Set the accelerator from settings
212+
translate_shortcut = Adw.ShortcutsItem(
213+
title=_("Translate"),
214+
accelerator=Settings.get().translate_accel,
215+
)
216+
translation_section.add(translate_shortcut)
217+
218+
if dialog:
219+
dialog.present(self.window)
220+
196221
def _on_quit(self, _action, _param):
197222
self.quit()
198223

dialect/meson.build

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.proje
55
# Resources
66
blueprints = custom_target('blueprints',
77
input: files(
8-
'shortcuts.blp',
8+
'shortcuts-dialog.blp',
99
'window.blp',
1010
'widgets/lang_selector.blp',
1111
'widgets/lang_row.blp',
@@ -65,7 +65,6 @@ sources = [
6565
'preferences.py',
6666
'session.py',
6767
'settings.py',
68-
'shortcuts.py',
6968
'utils.py',
7069
'window.py',
7170
]
@@ -76,4 +75,4 @@ install_data(sources, install_dir: moduledir)
7675
install_subdir('widgets', install_dir: moduledir)
7776

7877
# Install providers
79-
install_subdir('providers', install_dir: moduledir)
78+
install_subdir('providers', install_dir: moduledir)

dialect/shortcuts-dialog.blp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
Adw.ShortcutsDialog shortcuts_dialog {
5+
Adw.ShortcutsSection translation_section {
6+
title: C_("shortcuts window", "Translator");
7+
8+
Adw.ShortcutsItem switch_shortcut {
9+
title: C_("shortcuts window", "Switch Languages");
10+
action-name: "win.switch";
11+
}
12+
13+
Adw.ShortcutsItem from_shortcut {
14+
title: C_("shortcuts window", "Select source language");
15+
action-name: "win.from";
16+
}
17+
18+
Adw.ShortcutsItem to_shortcut {
19+
title: C_("shortcuts window", "Select destination language");
20+
action-name: "win.to";
21+
}
22+
23+
Adw.ShortcutsItem {
24+
title: C_("shortcuts window", "Clear source text");
25+
action-name: "win.clear";
26+
}
27+
28+
Adw.ShortcutsItem {
29+
title: C_("shortcuts window", "Copy translation");
30+
action-name: "win.copy";
31+
}
32+
33+
Adw.ShortcutsItem {
34+
title: C_("shortcuts window", "Show Pronunciation");
35+
action-name: "app.pronunciation";
36+
}
37+
38+
Adw.ShortcutsItem {
39+
title: C_("shortcuts window", "Increase font size");
40+
action-name: "win.font-size-inc";
41+
}
42+
43+
Adw.ShortcutsItem {
44+
title: C_("shortcuts window", "Decrease font size");
45+
action-name: "win.font-size-dec";
46+
}
47+
}
48+
49+
Adw.ShortcutsSection {
50+
title: C_("shortcuts window", "Text-to-Speech");
51+
52+
Adw.ShortcutsItem {
53+
title: C_("shortcuts window", "Listen to source text");
54+
action-name: "win.listen-src";
55+
}
56+
57+
Adw.ShortcutsItem {
58+
title: C_("shortcuts window", "Listen to translation");
59+
action-name: "win.listen-dest";
60+
}
61+
}
62+
63+
Adw.ShortcutsSection {
64+
title: C_("shortcuts window", "Navigation");
65+
66+
Adw.ShortcutsItem {
67+
title: C_("shortcuts window", "Go back in history");
68+
action-name: "win.back";
69+
}
70+
71+
Adw.ShortcutsItem {
72+
title: C_("shortcuts window", "Go forward in history");
73+
action-name: "win.forward";
74+
}
75+
}
76+
77+
Adw.ShortcutsSection {
78+
title: C_("shortcuts window", "General");
79+
80+
Adw.ShortcutsItem {
81+
title: C_("shortcuts window", "Preferences");
82+
action-name: "app.preferences";
83+
}
84+
85+
Adw.ShortcutsItem {
86+
title: C_("shortcut window", "Shortcuts");
87+
action-name: "app.shortcuts";
88+
}
89+
90+
Adw.ShortcutsItem {
91+
title: C_("shortcuts window", "Quit");
92+
action-name: "app.quit";
93+
}
94+
}
95+
}

dialect/shortcuts.blp

Lines changed: 0 additions & 108 deletions
This file was deleted.

dialect/shortcuts.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

dialect/style-dark.css

Whitespace-only changes.

0 commit comments

Comments
 (0)