Merge lp:~djaler1/pantheon-photos/fix-1405890 into lp:~pantheon-photos/pantheon-photos/trunk

Proposed by Kirill Romanov
Status: Merged
Approved by: Danielle Foré
Approved revision: 3102
Merged at revision: 3113
Proposed branch: lp:~djaler1/pantheon-photos/fix-1405890
Merge into: lp:~pantheon-photos/pantheon-photos/trunk
Diff against target: 61 lines (+33/-12)
1 file modified
src/direct/DirectPhotoPage.vala (+33/-12)
To merge this branch: bzr merge lp:~djaler1/pantheon-photos/fix-1405890
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Review via email: mp+314004@code.launchpad.net

Commit message

Make Ctrl + S work in the photo viewer

Description of the change

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

I can confirm that this works as expected :)

review: Approve
Revision history for this message
Corentin Noël (tintou) wrote :

As a side note, instead of doing this (event.state & Gdk.ModifierType.CONTROL_MASK) != 0
The vala language allows you to do `if (Gdk.ModifierType.CONTROL_MASK in event.state)` with flags which is much more graceful and easier to recognize at first sight ;)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/direct/DirectPhotoPage.vala'
2--- src/direct/DirectPhotoPage.vala 2017-01-03 11:02:51 +0000
3+++ src/direct/DirectPhotoPage.vala 2017-01-03 11:58:43 +0000
4@@ -520,24 +520,45 @@
5 save_as_dialog.destroy ();
6 }
7
8+ /** Returns true if the code parameter matches the keycode of the keyval parameter for
9+ * any keyboard group or level (in order to allow for non-QWERTY keyboards) **/
10+ protected bool match_keycode (int keyval, uint code) {
11+ Gdk.KeymapKey [] keys;
12+ Gdk.Keymap keymap = Gdk.Keymap.get_default ();
13+ if (keymap.get_entries_for_keyval (keyval, out keys)) {
14+ foreach (var key in keys) {
15+ if (code == key.keycode)
16+ return true;
17+ }
18+ }
19+ return false;
20+ }
21+
22 protected override bool on_app_key_pressed (Gdk.EventKey event) {
23- bool handled = true;
24-
25- switch (Gdk.keyval_name (event.keyval)) {
26- case "bracketright":
27+ uint keycode = event.hardware_keycode;
28+
29+ if (match_keycode (Gdk.Key.s, keycode)) {
30+ if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0) {
31+ if ((event.state & Gdk.ModifierType.SHIFT_MASK) != 0) {
32+ on_save_as ();
33+ } else {
34+ on_save ();
35+ }
36+ return true;
37+ }
38+ }
39+
40+ if (match_keycode (Gdk.Key.bracketright, keycode)) {
41 activate_action ("RotateClockwise");
42- break;
43+ return true;
44+ }
45
46- case "bracketleft":
47+ if (match_keycode (Gdk.Key.bracketleft, keycode)) {
48 activate_action ("RotateCounterclockwise");
49- break;
50-
51- default:
52- handled = false;
53- break;
54+ return true;
55 }
56
57- return handled ? true : base.on_app_key_pressed (event);
58+ return base.on_app_key_pressed (event);
59 }
60
61 private void on_print () {

Subscribers

People subscribed via source and target branches

to all changes: