Merge lp:~julien-spautz/switchboard-plug-keyboard/custom-shortcuts into lp:~elementary-pantheon/switchboard-plug-keyboard/trunk
- custom-shortcuts
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 325 | ||||
Proposed branch: | lp:~julien-spautz/switchboard-plug-keyboard/custom-shortcuts | ||||
Merge into: | lp:~elementary-pantheon/switchboard-plug-keyboard/trunk | ||||
Diff against target: |
971 lines (+550/-233) 12 files modified
src/CMakeLists.txt (+4/-0) src/Pages/Shortcuts/conflict_dialog.vala (+19/-0) src/Pages/Shortcuts/custom_shortcut_settings.vala (+146/-0) src/Pages/Shortcuts/custom_tree.vala (+178/-0) src/Pages/Shortcuts/display.vala (+23/-11) src/Pages/Shortcuts/display_tree.vala (+5/-0) src/Pages/Shortcuts/list.vala (+1/-26) src/Pages/Shortcuts/section_switcher.vala (+6/-3) src/Pages/Shortcuts/settings.vala (+1/-1) src/Pages/Shortcuts/shortcut.vala (+2/-2) src/Pages/Shortcuts/tree.vala (+144/-181) src/Pages/shortcuts.vala (+21/-9) |
||||
To merge this branch: | bzr merge lp:~julien-spautz/switchboard-plug-keyboard/custom-shortcuts | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raphael Isemann (community) | code style, functionality | Needs Fixing | |
Artem Anufrij (community) | code style | Needs Fixing | |
Danielle Foré | Needs Fixing | ||
David Gomes (community) | Needs Fixing | ||
Review via email: mp+212343@code.launchpad.net |
Commit message
Description of the change
Now open for review.
Implemented custom shortcuts into the keyboard plug. I'm using dconf/gsettings instead of gconf (unlike elementary tweaks) since the gconf version doesn't seem to work on isis, also it's deprecated.
Custom shortcuts can be added/removed/
If the schema for custom shortcuts doesn't exist, the section will not be shown at all.
Conflicting shortcuts are handled like before, asking the user whether he wants to reassign the shortcut.
NOTE that changes to custom shortcuts will, for some reason, not be applied immediately but you'll have to log out and in again, reboot or restart gnome-settings-
- 136. By Julien Spautz
-
small refactor: using DisplayTree instead of GtkTree to avoid casting
- 137. By Julien Spautz
-
remove some unused code
- 138. By Julien Spautz
-
fixed failing assertions on clearing shortcuts
- 139. By Julien Spautz
-
fix inconsistent whitespace
Julien Spautz (julien-spautz) wrote : | # |
Completely forgot about the whitespace... Following files should now follow elementary's coding guidelines, all other files should still be internally consistent:
src/Pages/
src/Pages/
src/Pages/
src/Pages/
src/Pages/
(The four first files are new, the last one isn't, but I had to change a lot of code in that one so I converted it to elementary code)
- 140. By Julien Spautz
-
fixed small inconsistency in whitespace
David Gomes (davidgomes) wrote : | # |
I can't seem to build this. First I got:
`
/usr/bin/msgfmt: error while opening "/home/
`
So I ran it with root privileges and got: http://
Julien Spautz (julien-spautz) wrote : | # |
built it on freya beta 1 and it works for me, can someone test it again?
Danielle Foré (danrabbit) wrote : | # |
Shortcuts don't seem to apply until I log out and log back in. Is there any way to make these apply immediately? (restart/update whatever service is responsible for watching for shortcuts?)
If not, we should at least show an infobar stating that you'll need to log out or restart for the changes to take effect.
Danielle Foré (danrabbit) wrote : | # |
The "-" button shouldn't be sensitive if there is no line selected
Artem Anufrij (artem-anufrij) wrote : | # |
see line comments
Raphael Isemann (teemperor) wrote : | # |
As Daniel said, you shouln't need to relog/reboot for the keybindings to take effect, so just set "org.gnome.
Interestingly on my system if i do this noise seems to loose the binding to the next/previous keys on my keyboard until i restart noise. But i think that's rather a bug in noise itself?
Otherwise:
* Commented-out code in line 780-781.
* Line 417: tbar = new Gtk.Toolbar(); <- needs a blank before the bracket
Preview Diff
1 | === modified file 'src/CMakeLists.txt' | |||
2 | --- src/CMakeLists.txt 2014-01-10 08:17:09 +0000 | |||
3 | +++ src/CMakeLists.txt 2014-03-30 21:21:15 +0000 | |||
4 | @@ -29,6 +29,10 @@ | |||
5 | 29 | Pages/Shortcuts/shortcut.vala | 29 | Pages/Shortcuts/shortcut.vala |
6 | 30 | Pages/Shortcuts/list.vala | 30 | Pages/Shortcuts/list.vala |
7 | 31 | Pages/Shortcuts/section_switcher.vala | 31 | Pages/Shortcuts/section_switcher.vala |
8 | 32 | Pages/Shortcuts/custom_tree.vala | ||
9 | 33 | Pages/Shortcuts/custom_shortcut_settings.vala | ||
10 | 34 | Pages/Shortcuts/conflict_dialog.vala | ||
11 | 35 | Pages/Shortcuts/display_tree.vala | ||
12 | 32 | 36 | ||
13 | 33 | Pages/layout.vala | 37 | Pages/layout.vala |
14 | 34 | Pages/Layout/display.vala | 38 | Pages/Layout/display.vala |
15 | 35 | 39 | ||
16 | === added file 'src/Pages/Shortcuts/conflict_dialog.vala' | |||
17 | --- src/Pages/Shortcuts/conflict_dialog.vala 1970-01-01 00:00:00 +0000 | |||
18 | +++ src/Pages/Shortcuts/conflict_dialog.vala 2014-03-30 21:21:15 +0000 | |||
19 | @@ -0,0 +1,19 @@ | |||
20 | 1 | class ConflictDialog : Gtk.MessageDialog { | ||
21 | 2 | |||
22 | 3 | public signal void reassign (); | ||
23 | 4 | |||
24 | 5 | public ConflictDialog (string shortcut, string conflict_action, string this_action) { | ||
25 | 6 | modal = true; | ||
26 | 7 | message_type = Gtk.MessageType.WARNING; | ||
27 | 8 | text = @"\"$shortcut\" is already used for \"$conflict_action\"!"; | ||
28 | 9 | secondary_text = _(@"If you reassign the shortcut to \"$this_action\", \"$conflict_action\" will be disabled"); | ||
29 | 10 | add_button (_("Cancel"), 0); | ||
30 | 11 | add_button (_("Reassign"), 1); | ||
31 | 12 | |||
32 | 13 | response.connect ((response_id) => { | ||
33 | 14 | if (response_id == 1) | ||
34 | 15 | reassign (); | ||
35 | 16 | destroy(); | ||
36 | 17 | }); | ||
37 | 18 | } | ||
38 | 19 | } | ||
39 | 0 | \ No newline at end of file | 20 | \ No newline at end of file |
40 | 1 | 21 | ||
41 | === added file 'src/Pages/Shortcuts/custom_shortcut_settings.vala' | |||
42 | --- src/Pages/Shortcuts/custom_shortcut_settings.vala 1970-01-01 00:00:00 +0000 | |||
43 | +++ src/Pages/Shortcuts/custom_shortcut_settings.vala 2014-03-30 21:21:15 +0000 | |||
44 | @@ -0,0 +1,146 @@ | |||
45 | 1 | class Pantheon.Keyboard.Shortcuts.CustomShortcutSettings : Object { | ||
46 | 2 | |||
47 | 3 | const string SCHEMA = "org.gnome.settings-daemon.plugins.media-keys"; | ||
48 | 4 | const string KEY = "custom-keybinding"; | ||
49 | 5 | |||
50 | 6 | const string RELOCATABLE_SCHEMA_PATH_TEMLPATE = "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom%d/"; | ||
51 | 7 | |||
52 | 8 | const int MAX_SHORTCUTS = 100; | ||
53 | 9 | |||
54 | 10 | static GLib.Settings settings; | ||
55 | 11 | |||
56 | 12 | public static bool available = false; | ||
57 | 13 | |||
58 | 14 | public struct CustomShortcut { | ||
59 | 15 | string shortcut; | ||
60 | 16 | string command; | ||
61 | 17 | string relocatable_schema; | ||
62 | 18 | } | ||
63 | 19 | |||
64 | 20 | public static void init () { | ||
65 | 21 | var schema_source = GLib.SettingsSchemaSource.get_default (); | ||
66 | 22 | |||
67 | 23 | var schema = schema_source.lookup (SCHEMA, true); | ||
68 | 24 | |||
69 | 25 | if (schema == null) { | ||
70 | 26 | warning ("Schema \"%s\" is not installed on your system.", SCHEMA); | ||
71 | 27 | return; | ||
72 | 28 | } | ||
73 | 29 | |||
74 | 30 | settings = new GLib.Settings.full (schema, null, null); | ||
75 | 31 | available = true; | ||
76 | 32 | } | ||
77 | 33 | |||
78 | 34 | static string[] get_relocatable_schemas () { | ||
79 | 35 | return settings.get_strv (KEY + "s"); | ||
80 | 36 | } | ||
81 | 37 | |||
82 | 38 | static string get_relocatable_schema_path (int i) { | ||
83 | 39 | return RELOCATABLE_SCHEMA_PATH_TEMLPATE.printf (i); | ||
84 | 40 | } | ||
85 | 41 | |||
86 | 42 | static GLib.Settings? get_relocatable_schema_settings (string relocatable_schema) { | ||
87 | 43 | return new GLib.Settings.with_path (SCHEMA + "." + KEY, relocatable_schema); | ||
88 | 44 | } | ||
89 | 45 | |||
90 | 46 | public static string? create_shortcut () requires (available) { | ||
91 | 47 | for (int i = 0; i < MAX_SHORTCUTS; i++) { | ||
92 | 48 | var new_relocatable_schema = get_relocatable_schema_path (i); | ||
93 | 49 | |||
94 | 50 | if (relocatable_schema_is_used (new_relocatable_schema) == false) { | ||
95 | 51 | add_relocatable_schema (new_relocatable_schema); | ||
96 | 52 | reset_relocatable_schema (new_relocatable_schema); | ||
97 | 53 | return new_relocatable_schema; | ||
98 | 54 | } | ||
99 | 55 | } | ||
100 | 56 | |||
101 | 57 | return (string) null; | ||
102 | 58 | } | ||
103 | 59 | |||
104 | 60 | static bool relocatable_schema_is_used (string new_relocatable_schema) { | ||
105 | 61 | var relocatable_schemas = get_relocatable_schemas (); | ||
106 | 62 | |||
107 | 63 | foreach (var relocatable_schema in relocatable_schemas) | ||
108 | 64 | if (relocatable_schema == new_relocatable_schema) | ||
109 | 65 | return true; | ||
110 | 66 | |||
111 | 67 | return false; | ||
112 | 68 | } | ||
113 | 69 | |||
114 | 70 | static void add_relocatable_schema (string new_relocatable_schema) { | ||
115 | 71 | var relocatable_schemas = get_relocatable_schemas (); | ||
116 | 72 | relocatable_schemas += new_relocatable_schema; | ||
117 | 73 | settings.set_strv (KEY + "s", relocatable_schemas); | ||
118 | 74 | } | ||
119 | 75 | |||
120 | 76 | static void reset_relocatable_schema (string relocatable_schema) { | ||
121 | 77 | var relocatable_settings = get_relocatable_schema_settings (relocatable_schema); | ||
122 | 78 | relocatable_settings.reset ("name"); | ||
123 | 79 | relocatable_settings.reset ("command"); | ||
124 | 80 | relocatable_settings.reset ("binding"); | ||
125 | 81 | } | ||
126 | 82 | |||
127 | 83 | public static void remove_shortcut (string relocatable_schema) | ||
128 | 84 | requires (available) { | ||
129 | 85 | |||
130 | 86 | string []relocatable_schemas = {}; | ||
131 | 87 | |||
132 | 88 | foreach (var schema in get_relocatable_schemas ()) | ||
133 | 89 | if (schema != relocatable_schema) | ||
134 | 90 | relocatable_schemas += schema; | ||
135 | 91 | |||
136 | 92 | reset_relocatable_schema (relocatable_schema); | ||
137 | 93 | settings.set_strv (KEY + "s", relocatable_schemas); | ||
138 | 94 | } | ||
139 | 95 | |||
140 | 96 | public static bool edit_shortcut (string relocatable_schema, string shortcut) | ||
141 | 97 | requires (available) { | ||
142 | 98 | |||
143 | 99 | var relocatable_settings = get_relocatable_schema_settings (relocatable_schema); | ||
144 | 100 | relocatable_settings.set_string ("binding", shortcut); | ||
145 | 101 | return true; | ||
146 | 102 | } | ||
147 | 103 | |||
148 | 104 | public static bool edit_command (string relocatable_schema, string command) | ||
149 | 105 | requires (available) { | ||
150 | 106 | |||
151 | 107 | var relocatable_settings = get_relocatable_schema_settings (relocatable_schema); | ||
152 | 108 | relocatable_settings.set_string ("command", command); | ||
153 | 109 | return true; | ||
154 | 110 | } | ||
155 | 111 | |||
156 | 112 | public static GLib.List <CustomShortcut?> list_custom_shortcuts () | ||
157 | 113 | requires (available) { | ||
158 | 114 | |||
159 | 115 | var list = new GLib.List <CustomShortcut?> (); | ||
160 | 116 | foreach (var relocatable_schema in get_relocatable_schemas ()) | ||
161 | 117 | list.append (create_custom_shortcut_object (relocatable_schema)); | ||
162 | 118 | return list; | ||
163 | 119 | } | ||
164 | 120 | |||
165 | 121 | static CustomShortcut? create_custom_shortcut_object (string relocatable_schema) { | ||
166 | 122 | var relocatable_settings = get_relocatable_schema_settings (relocatable_schema); | ||
167 | 123 | |||
168 | 124 | return { | ||
169 | 125 | relocatable_settings.get_string ("binding"), | ||
170 | 126 | relocatable_settings.get_string ("command"), | ||
171 | 127 | relocatable_schema | ||
172 | 128 | }; | ||
173 | 129 | } | ||
174 | 130 | |||
175 | 131 | public static bool shortcut_conflicts (Shortcut new_shortcut, out string command, | ||
176 | 132 | out string relocatable_schema) { | ||
177 | 133 | var custom_shortcuts = list_custom_shortcuts (); | ||
178 | 134 | |||
179 | 135 | foreach (var custom_shortcut in custom_shortcuts) { | ||
180 | 136 | var shortcut = new Shortcut.parse (custom_shortcut.shortcut); | ||
181 | 137 | if (shortcut.is_equal (new_shortcut)) { | ||
182 | 138 | command = custom_shortcut.command; | ||
183 | 139 | relocatable_schema = custom_shortcut.relocatable_schema; | ||
184 | 140 | return true; | ||
185 | 141 | } | ||
186 | 142 | } | ||
187 | 143 | |||
188 | 144 | return false; | ||
189 | 145 | } | ||
190 | 146 | } | ||
191 | 0 | \ No newline at end of file | 147 | \ No newline at end of file |
192 | 1 | 148 | ||
193 | === added file 'src/Pages/Shortcuts/custom_tree.vala' | |||
194 | --- src/Pages/Shortcuts/custom_tree.vala 1970-01-01 00:00:00 +0000 | |||
195 | +++ src/Pages/Shortcuts/custom_tree.vala 2014-03-30 21:21:15 +0000 | |||
196 | @@ -0,0 +1,178 @@ | |||
197 | 1 | private class Pantheon.Keyboard.Shortcuts.CustomTree : Gtk.TreeView, DisplayTree { | ||
198 | 2 | |||
199 | 3 | Gtk.CellRendererText cell_desc; | ||
200 | 4 | Gtk.CellRendererAccel cell_edit; | ||
201 | 5 | |||
202 | 6 | enum Column { | ||
203 | 7 | COMMAND, | ||
204 | 8 | SHORTCUT, | ||
205 | 9 | SCHEMA, | ||
206 | 10 | COUNT | ||
207 | 11 | } | ||
208 | 12 | |||
209 | 13 | public CustomTree () { | ||
210 | 14 | setup_gui (); | ||
211 | 15 | load_and_display_custom_shortcuts (); | ||
212 | 16 | connect_signals (); | ||
213 | 17 | } | ||
214 | 18 | |||
215 | 19 | Gtk.ListStore list_store { | ||
216 | 20 | get { return model as Gtk.ListStore; } | ||
217 | 21 | } | ||
218 | 22 | |||
219 | 23 | void setup_gui () { | ||
220 | 24 | var store = new Gtk.ListStore (Column.COUNT , typeof (string), | ||
221 | 25 | typeof (string), | ||
222 | 26 | typeof (string)); | ||
223 | 27 | |||
224 | 28 | cell_desc = new Gtk.CellRendererText (); | ||
225 | 29 | cell_edit = new Gtk.CellRendererAccel (); | ||
226 | 30 | |||
227 | 31 | cell_desc.editable = true; | ||
228 | 32 | cell_edit.editable = true; | ||
229 | 33 | cell_edit.accel_mode = Gtk.CellRendererAccelMode.OTHER; | ||
230 | 34 | |||
231 | 35 | this.set_model (store); | ||
232 | 36 | |||
233 | 37 | this.insert_column_with_attributes (-1, _("Command"), cell_desc, "markup", Column.COMMAND); | ||
234 | 38 | this.insert_column_with_attributes (-1, _("Shortcut"), cell_edit, "text", Column.SHORTCUT); | ||
235 | 39 | |||
236 | 40 | this.expand = true; | ||
237 | 41 | this.get_column (0).expand = true; | ||
238 | 42 | } | ||
239 | 43 | |||
240 | 44 | public void load_and_display_custom_shortcuts () { | ||
241 | 45 | Gtk.TreeIter iter; | ||
242 | 46 | var store = new Gtk.ListStore (Column.COUNT , typeof (string), | ||
243 | 47 | typeof (string), | ||
244 | 48 | typeof (string)); | ||
245 | 49 | |||
246 | 50 | foreach (var custom_shortcut in CustomShortcutSettings.list_custom_shortcuts ()) { | ||
247 | 51 | var shortcut = new Shortcut.parse (custom_shortcut.shortcut); | ||
248 | 52 | |||
249 | 53 | store.append (out iter); | ||
250 | 54 | store.set (iter, | ||
251 | 55 | Column.COMMAND, command_to_display (custom_shortcut.command), | ||
252 | 56 | Column.SHORTCUT, shortcut.to_readable (), | ||
253 | 57 | Column.SCHEMA, custom_shortcut.relocatable_schema | ||
254 | 58 | ); | ||
255 | 59 | } | ||
256 | 60 | |||
257 | 61 | model = store; | ||
258 | 62 | } | ||
259 | 63 | |||
260 | 64 | void connect_signals () { | ||
261 | 65 | this.button_press_event.connect ((event) => { | ||
262 | 66 | if (event.window != this.get_bin_window ()) | ||
263 | 67 | return false; | ||
264 | 68 | |||
265 | 69 | Gtk.TreePath path; | ||
266 | 70 | Gtk.TreeViewColumn col; | ||
267 | 71 | |||
268 | 72 | if (this.get_path_at_pos ((int) event.x, (int) event.y, | ||
269 | 73 | out path, out col, null, null)) { | ||
270 | 74 | this.grab_focus (); | ||
271 | 75 | this.set_cursor (path, col, true); | ||
272 | 76 | } | ||
273 | 77 | |||
274 | 78 | return true; | ||
275 | 79 | }); | ||
276 | 80 | |||
277 | 81 | cell_edit.accel_edited.connect ((path, key, mods) => { | ||
278 | 82 | var shortcut = new Shortcut (key, mods); | ||
279 | 83 | change_shortcut (path, shortcut); | ||
280 | 84 | }); | ||
281 | 85 | |||
282 | 86 | cell_edit.accel_cleared.connect ((path) => { | ||
283 | 87 | change_shortcut (path, (Shortcut) null); | ||
284 | 88 | }); | ||
285 | 89 | |||
286 | 90 | cell_desc.edited.connect (change_command); | ||
287 | 91 | } | ||
288 | 92 | |||
289 | 93 | string command_to_display (string? command) { | ||
290 | 94 | if (command == null || command.strip () == "") | ||
291 | 95 | return "<i>" +_("Enter Command") + "</i>"; | ||
292 | 96 | return GLib.Markup.escape_text (command); | ||
293 | 97 | } | ||
294 | 98 | |||
295 | 99 | public void on_add_clicked () { | ||
296 | 100 | var store = model as Gtk.ListStore; | ||
297 | 101 | Gtk.TreeIter iter; | ||
298 | 102 | |||
299 | 103 | var relocatable_schema = CustomShortcutSettings.create_shortcut (); | ||
300 | 104 | |||
301 | 105 | store.append (out iter); | ||
302 | 106 | store.set (iter, Column.COMMAND, command_to_display (null)); | ||
303 | 107 | store.set (iter, Column.SHORTCUT, (new Shortcut.parse ("")).to_readable ()); | ||
304 | 108 | store.set (iter, Column.SCHEMA, relocatable_schema); | ||
305 | 109 | } | ||
306 | 110 | |||
307 | 111 | public void on_remove_clicked () { | ||
308 | 112 | Gtk.TreeIter iter; | ||
309 | 113 | Gtk.TreePath path; | ||
310 | 114 | GLib.Value relocatable_schema; | ||
311 | 115 | |||
312 | 116 | get_cursor (out path, null); | ||
313 | 117 | model.get_iter (out iter, path); | ||
314 | 118 | model.get_value (iter, Column.SCHEMA, out relocatable_schema); | ||
315 | 119 | |||
316 | 120 | CustomShortcutSettings.remove_shortcut ((string) relocatable_schema); | ||
317 | 121 | list_store.remove (iter); | ||
318 | 122 | } | ||
319 | 123 | |||
320 | 124 | void change_command (string path, string new_text) { | ||
321 | 125 | Gtk.TreeIter iter; | ||
322 | 126 | GLib.Value relocatable_schema; | ||
323 | 127 | |||
324 | 128 | model.get_iter (out iter, new Gtk.TreePath.from_string (path)); | ||
325 | 129 | model.get_value (iter, Column.SCHEMA, out relocatable_schema); | ||
326 | 130 | |||
327 | 131 | CustomShortcutSettings.edit_command ((string) relocatable_schema, new_text); | ||
328 | 132 | load_and_display_custom_shortcuts (); | ||
329 | 133 | } | ||
330 | 134 | |||
331 | 135 | public bool shortcut_conflicts (Shortcut shortcut, out string name) { | ||
332 | 136 | return CustomShortcutSettings.shortcut_conflicts (shortcut, out name, null); | ||
333 | 137 | } | ||
334 | 138 | |||
335 | 139 | public void reset_shortcut (Shortcut shortcut) { | ||
336 | 140 | string relocatable_schema; | ||
337 | 141 | CustomShortcutSettings.shortcut_conflicts (shortcut, null, out relocatable_schema); | ||
338 | 142 | CustomShortcutSettings.edit_shortcut (relocatable_schema, ""); | ||
339 | 143 | load_and_display_custom_shortcuts (); | ||
340 | 144 | } | ||
341 | 145 | |||
342 | 146 | bool change_shortcut (string path, Shortcut? shortcut) { | ||
343 | 147 | Gtk.TreeIter iter; | ||
344 | 148 | GLib.Value command, relocatable_schema; | ||
345 | 149 | |||
346 | 150 | model.get_iter (out iter, new Gtk.TreePath.from_string (path)); | ||
347 | 151 | model.get_value (iter, Column.SCHEMA, out relocatable_schema); | ||
348 | 152 | model.get_value (iter, Column.COMMAND, out command); | ||
349 | 153 | |||
350 | 154 | var not_null_shortcut = shortcut ?? new Shortcut (); | ||
351 | 155 | |||
352 | 156 | string conflict_name; | ||
353 | 157 | |||
354 | 158 | if (shortcut != null) { | ||
355 | 159 | foreach (var tree in trees) { | ||
356 | 160 | if (tree.shortcut_conflicts (shortcut, out conflict_name) == false) | ||
357 | 161 | continue; | ||
358 | 162 | |||
359 | 163 | var dialog = new ConflictDialog (shortcut.to_readable (), conflict_name, (string) command); | ||
360 | 164 | dialog.reassign.connect (() => { | ||
361 | 165 | tree.reset_shortcut (shortcut); | ||
362 | 166 | CustomShortcutSettings.edit_shortcut ((string) relocatable_schema, not_null_shortcut.to_gsettings ()); | ||
363 | 167 | load_and_display_custom_shortcuts (); | ||
364 | 168 | }); | ||
365 | 169 | dialog.show (); | ||
366 | 170 | return false; | ||
367 | 171 | } | ||
368 | 172 | } | ||
369 | 173 | |||
370 | 174 | CustomShortcutSettings.edit_shortcut ((string) relocatable_schema, not_null_shortcut.to_gsettings ()); | ||
371 | 175 | load_and_display_custom_shortcuts (); | ||
372 | 176 | return true; | ||
373 | 177 | } | ||
374 | 178 | } | ||
375 | 0 | \ No newline at end of file | 179 | \ No newline at end of file |
376 | 1 | 180 | ||
377 | === modified file 'src/Pages/Shortcuts/display.vala' | |||
378 | --- src/Pages/Shortcuts/display.vala 2014-01-06 17:12:27 +0000 | |||
379 | +++ src/Pages/Shortcuts/display.vala 2014-03-30 21:21:15 +0000 | |||
380 | @@ -1,3 +1,4 @@ | |||
381 | 1 | // TODO use new Gtk.Stack widget here | ||
382 | 1 | namespace Pantheon.Keyboard.Shortcuts | 2 | namespace Pantheon.Keyboard.Shortcuts |
383 | 2 | { | 3 | { |
384 | 3 | // creates a grid containing a tree view and an inline toolbar | 4 | // creates a grid containing a tree view and an inline toolbar |
385 | @@ -6,16 +7,17 @@ | |||
386 | 6 | int selected; | 7 | int selected; |
387 | 7 | 8 | ||
388 | 8 | Gtk.ScrolledWindow scroll; | 9 | Gtk.ScrolledWindow scroll; |
392 | 9 | Tree[] trees; | 10 | DisplayTree[] trees; |
393 | 10 | 11 | ||
394 | 11 | public ShortcutDisplay (Tree[] t) | 12 | Gtk.Toolbar tbar; |
395 | 13 | |||
396 | 14 | public ShortcutDisplay (DisplayTree[] t) | ||
397 | 12 | { | 15 | { |
398 | 13 | selected = 0; | 16 | selected = 0; |
399 | 14 | 17 | ||
403 | 15 | trees = t; | 18 | foreach (var tree in t) { |
401 | 16 | |||
402 | 17 | foreach (var tree in trees) { | ||
404 | 18 | tree.set_rules_hint (true); | 19 | tree.set_rules_hint (true); |
405 | 20 | trees += tree; | ||
406 | 19 | } | 21 | } |
407 | 20 | 22 | ||
408 | 21 | scroll = new Gtk.ScrolledWindow(null, null); | 23 | scroll = new Gtk.ScrolledWindow(null, null); |
409 | @@ -23,14 +25,15 @@ | |||
410 | 23 | scroll.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC; | 25 | scroll.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC; |
411 | 24 | scroll.shadow_type = Gtk.ShadowType.IN; | 26 | scroll.shadow_type = Gtk.ShadowType.IN; |
412 | 25 | scroll.expand = true; | 27 | scroll.expand = true; |
414 | 26 | scroll.add (trees[selected]); | 28 | scroll.add (t[selected]); |
415 | 27 | 29 | ||
417 | 28 | var tbar = new Gtk.Toolbar(); | 30 | tbar = new Gtk.Toolbar(); |
418 | 29 | tbar.set_style(Gtk.ToolbarStyle.ICONS); | 31 | tbar.set_style(Gtk.ToolbarStyle.ICONS); |
419 | 30 | tbar.set_icon_size(Gtk.IconSize.SMALL_TOOLBAR); | 32 | tbar.set_icon_size(Gtk.IconSize.SMALL_TOOLBAR); |
420 | 31 | tbar.set_show_arrow(false); | 33 | tbar.set_show_arrow(false); |
421 | 32 | tbar.hexpand = true; | 34 | tbar.hexpand = true; |
423 | 33 | 35 | tbar.no_show_all = true; | |
424 | 36 | |||
425 | 34 | scroll.get_style_context().set_junction_sides(Gtk.JunctionSides.BOTTOM); | 37 | scroll.get_style_context().set_junction_sides(Gtk.JunctionSides.BOTTOM); |
426 | 35 | tbar.get_style_context().add_class(Gtk.STYLE_CLASS_INLINE_TOOLBAR); | 38 | tbar.get_style_context().add_class(Gtk.STYLE_CLASS_INLINE_TOOLBAR); |
427 | 36 | tbar.get_style_context().set_junction_sides(Gtk.JunctionSides.TOP); | 39 | tbar.get_style_context().set_junction_sides(Gtk.JunctionSides.TOP); |
428 | @@ -48,7 +51,12 @@ | |||
429 | 48 | tbar.insert (remove_button, -1); | 51 | tbar.insert (remove_button, -1); |
430 | 49 | 52 | ||
431 | 50 | this.attach (scroll, 0, 0, 1, 1); | 53 | this.attach (scroll, 0, 0, 1, 1); |
433 | 51 | //this.attach (tbar, 0, 1, 1, 1); | 54 | this.attach (tbar, 0, 1, 1, 1); |
434 | 55 | |||
435 | 56 | add_button.clicked.connect (() => | ||
436 | 57 | (trees[selected] as CustomTree).on_add_clicked ()); | ||
437 | 58 | remove_button.clicked.connect (() => | ||
438 | 59 | (trees[selected] as CustomTree).on_remove_clicked ()); | ||
439 | 52 | } | 60 | } |
440 | 53 | 61 | ||
441 | 54 | // replace old tree view with new one | 62 | // replace old tree view with new one |
442 | @@ -58,7 +66,11 @@ | |||
443 | 58 | scroll.add (trees[new_selection]); | 66 | scroll.add (trees[new_selection]); |
444 | 59 | 67 | ||
445 | 60 | selected = new_selection; | 68 | selected = new_selection; |
447 | 61 | scroll.show_all (); | 69 | |
448 | 70 | tbar.no_show_all = new_selection != SectionID.CUSTOM; | ||
449 | 71 | tbar.visible = new_selection == SectionID.CUSTOM; | ||
450 | 72 | |||
451 | 73 | show_all (); | ||
452 | 62 | 74 | ||
453 | 63 | return true; | 75 | return true; |
454 | 64 | } | 76 | } |
455 | 65 | 77 | ||
456 | === added file 'src/Pages/Shortcuts/display_tree.vala' | |||
457 | --- src/Pages/Shortcuts/display_tree.vala 1970-01-01 00:00:00 +0000 | |||
458 | +++ src/Pages/Shortcuts/display_tree.vala 2014-03-30 21:21:15 +0000 | |||
459 | @@ -0,0 +1,5 @@ | |||
460 | 1 | interface Pantheon.Keyboard.Shortcuts.DisplayTree : Gtk.TreeView { | ||
461 | 2 | |||
462 | 3 | public abstract bool shortcut_conflicts (Shortcut shortcut, out string name); | ||
463 | 4 | public abstract void reset_shortcut (Shortcut shortcut); | ||
464 | 5 | } | ||
465 | 0 | \ No newline at end of file | 6 | \ No newline at end of file |
466 | 1 | 7 | ||
467 | === modified file 'src/Pages/Shortcuts/list.vala' | |||
468 | --- src/Pages/Shortcuts/list.vala 2014-03-12 08:11:41 +0000 | |||
469 | +++ src/Pages/Shortcuts/list.vala 2014-03-30 21:21:15 +0000 | |||
470 | @@ -21,31 +21,6 @@ | |||
471 | 21 | return; | 21 | return; |
472 | 22 | } | 22 | } |
473 | 23 | 23 | ||
474 | 24 | public bool conflicts (Shortcut s, out string key, out int group, out int path) | ||
475 | 25 | { | ||
476 | 26 | key = (string) null; | ||
477 | 27 | group = (SectionID) 0; | ||
478 | 28 | path = -1; | ||
479 | 29 | |||
480 | 30 | if (s.accel_key == Gdk.Key.BackSpace) | ||
481 | 31 | return false; | ||
482 | 32 | |||
483 | 33 | for (int g = 0; g < groups.length; g++) | ||
484 | 34 | { | ||
485 | 35 | for (int i = 0; i < groups[g].actions.length; i++) | ||
486 | 36 | { | ||
487 | 37 | if (s.is_equal (settings.get_val(groups[g].schemas[i], groups[g].keys[i]))) | ||
488 | 38 | { | ||
489 | 39 | key = groups[g].keys[i]; | ||
490 | 40 | group = g; | ||
491 | 41 | path = i; | ||
492 | 42 | return true; | ||
493 | 43 | } | ||
494 | 44 | } | ||
495 | 45 | } | ||
496 | 46 | return false; | ||
497 | 47 | } | ||
498 | 48 | |||
499 | 49 | public List () | 24 | public List () |
500 | 50 | { | 25 | { |
501 | 51 | groups = | 26 | groups = |
502 | @@ -70,7 +45,7 @@ | |||
503 | 70 | _("Expose Windows"), | 45 | _("Expose Windows"), |
504 | 71 | _("Expose all Windows") | 46 | _("Expose all Windows") |
505 | 72 | }, | 47 | }, |
507 | 73 | schemas = { | 48 | schemas = { |
508 | 74 | Schema.WM, | 49 | Schema.WM, |
509 | 75 | Schema.WM, | 50 | Schema.WM, |
510 | 76 | Schema.WM, | 51 | Schema.WM, |
511 | 77 | 52 | ||
512 | === modified file 'src/Pages/Shortcuts/section_switcher.vala' | |||
513 | --- src/Pages/Shortcuts/section_switcher.vala 2014-01-06 17:12:27 +0000 | |||
514 | +++ src/Pages/Shortcuts/section_switcher.vala 2014-03-30 21:21:15 +0000 | |||
515 | @@ -12,8 +12,11 @@ | |||
516 | 12 | 12 | ||
517 | 13 | Gtk.TreeIter iter; | 13 | Gtk.TreeIter iter; |
518 | 14 | 14 | ||
521 | 15 | // add the sections | 15 | var max_section_id = CustomShortcutSettings.available |
522 | 16 | for (int id = 0; id < SectionID.COUNT; id++) { | 16 | ? SectionID.COUNT |
523 | 17 | : SectionID.CUSTOM; | ||
524 | 18 | |||
525 | 19 | for (int id = 0; id < max_section_id; id++) { | ||
526 | 17 | store.append (out iter); | 20 | store.append (out iter); |
527 | 18 | store.set (iter, 0, section_names[id]); | 21 | store.set (iter, 0, section_names[id]); |
528 | 19 | } | 22 | } |
529 | @@ -39,6 +42,6 @@ | |||
530 | 39 | }); | 42 | }); |
531 | 40 | } | 43 | } |
532 | 41 | 44 | ||
534 | 42 | public signal void changed (int i); | 45 | public signal bool changed (int i); |
535 | 43 | } | 46 | } |
536 | 44 | } | 47 | } |
537 | 45 | \ No newline at end of file | 48 | \ No newline at end of file |
538 | 46 | 49 | ||
539 | === modified file 'src/Pages/Shortcuts/settings.vala' | |||
540 | --- src/Pages/Shortcuts/settings.vala 2014-01-06 17:12:27 +0000 | |||
541 | +++ src/Pages/Shortcuts/settings.vala 2014-03-30 21:21:15 +0000 | |||
542 | @@ -26,7 +26,7 @@ | |||
543 | 26 | var schema = schema_source.lookup (name, true); | 26 | var schema = schema_source.lookup (name, true); |
544 | 27 | 27 | ||
545 | 28 | if (schema == null) { | 28 | if (schema == null) { |
547 | 29 | warning ("Schema \"%s\" is not installed on you system.", name); | 29 | warning ("Schema \"%s\" is not installed on your system.", name); |
548 | 30 | schemas += (GLib.Settings) null; | 30 | schemas += (GLib.Settings) null; |
549 | 31 | } else { | 31 | } else { |
550 | 32 | schemas += new GLib.Settings.full (schema, null, null); | 32 | schemas += new GLib.Settings.full (schema, null, null); |
551 | 33 | 33 | ||
552 | === modified file 'src/Pages/Shortcuts/shortcut.vala' | |||
553 | --- src/Pages/Shortcuts/shortcut.vala 2014-01-06 17:12:27 +0000 | |||
554 | +++ src/Pages/Shortcuts/shortcut.vala 2014-03-30 21:21:15 +0000 | |||
555 | @@ -10,7 +10,7 @@ | |||
556 | 10 | string SEPARATOR = " · "; | 10 | string SEPARATOR = " · "; |
557 | 11 | 11 | ||
558 | 12 | // constructors | 12 | // constructors |
560 | 13 | public Shortcut ( uint key, Gdk.ModifierType mod ) | 13 | public Shortcut (uint key = 0, Gdk.ModifierType mod = (Gdk.ModifierType) 0) |
561 | 14 | { | 14 | { |
562 | 15 | accel_key = key; | 15 | accel_key = key; |
563 | 16 | modifiers = mod; | 16 | modifiers = mod; |
564 | @@ -107,4 +107,4 @@ | |||
565 | 107 | } | 107 | } |
566 | 108 | 108 | ||
567 | 109 | } | 109 | } |
568 | 110 | } | ||
569 | 111 | \ No newline at end of file | 110 | \ No newline at end of file |
570 | 111 | } | ||
571 | 112 | 112 | ||
572 | === modified file 'src/Pages/Shortcuts/tree.vala' | |||
573 | --- src/Pages/Shortcuts/tree.vala 2014-01-06 17:12:27 +0000 | |||
574 | +++ src/Pages/Shortcuts/tree.vala 2014-03-30 21:21:15 +0000 | |||
575 | @@ -1,182 +1,145 @@ | |||
757 | 1 | namespace Pantheon.Keyboard.Shortcuts | 1 | namespace Pantheon.Keyboard.Shortcuts { |
758 | 2 | { | 2 | |
759 | 3 | // contains the shortcuts and handels all changes in gsettings | 3 | private class Tree : Gtk.TreeView, DisplayTree { |
760 | 4 | private class Tree : Gtk.TreeView | 4 | |
761 | 5 | { | 5 | public SectionID group { private get; construct; } |
762 | 6 | private string[] actions; | 6 | |
763 | 7 | private Schema[] schemas; | 7 | private string[] actions; |
764 | 8 | private string[] keys; | 8 | private Schema[] schemas; |
765 | 9 | 9 | private string[] keys; | |
766 | 10 | // quick access to one item in the tree view | 10 | |
767 | 11 | public bool get_item (uint i, out string action, out Schema schema, out string key) | 11 | public Tree (SectionID group) { |
768 | 12 | { | 12 | Object (group: group); |
769 | 13 | action = null; | 13 | |
770 | 14 | schema = (Schema) null; | 14 | load_and_display_shortcuts (); |
771 | 15 | key = null; | 15 | |
772 | 16 | 16 | var cell_desc = new Gtk.CellRendererText (); | |
773 | 17 | if (i < actions.length) | 17 | var cell_edit = new Gtk.CellRendererAccel (); |
774 | 18 | { | 18 | |
775 | 19 | action = actions[i]; | 19 | cell_edit.editable = true; |
776 | 20 | schema = schemas[i]; | 20 | cell_edit.accel_mode = Gtk.CellRendererAccelMode.OTHER; |
777 | 21 | key = keys[i]; | 21 | |
778 | 22 | return true; | 22 | this.insert_column_with_attributes (-1, null, cell_desc, "text", 0); |
779 | 23 | } | 23 | this.insert_column_with_attributes (-1, null, cell_edit, "text", 1); |
780 | 24 | return false; | 24 | //this.insert_column_with_attributes (-1, null, cell_desc, "text", 2); |
781 | 25 | } | 25 | //this.insert_column_with_attributes (-1, null, cell_edit, "text", 3); |
782 | 26 | 26 | ||
783 | 27 | public Tree (SectionID group) | 27 | this.headers_visible = false; |
784 | 28 | { | 28 | this.expand = true; |
785 | 29 | list.get_group (group, out actions, out schemas, out keys); | 29 | |
786 | 30 | 30 | this.get_column (0).expand = true; | |
787 | 31 | // create list store | 31 | |
788 | 32 | var store = new Gtk.ListStore (4, typeof (string), | 32 | this.button_press_event.connect ((event) => { |
789 | 33 | typeof (string), | 33 | if (event.window != this.get_bin_window ()) |
790 | 34 | typeof (Schema), | 34 | return false; |
791 | 35 | typeof (string)); | 35 | |
792 | 36 | 36 | Gtk.TreePath path; | |
793 | 37 | Gtk.TreeIter iter; | 37 | |
794 | 38 | 38 | if (this.get_path_at_pos ((int) event.x, (int) event.y, | |
795 | 39 | for (int i = 0; i < actions.length; i++) | 39 | out path, null, null, null)) { |
796 | 40 | { | 40 | Gtk.TreeViewColumn col = this.get_column (1); |
797 | 41 | var shortcut = settings.get_val(schemas[i], keys[i]); | 41 | this.grab_focus (); |
798 | 42 | 42 | this.set_cursor (path, col, true); | |
799 | 43 | // simply ignore missing keys/schemas | 43 | } |
800 | 44 | if (shortcut == null) | 44 | |
801 | 45 | continue; | 45 | return true; |
802 | 46 | 46 | }); | |
803 | 47 | store.append (out iter); | 47 | |
804 | 48 | store.set (iter, 0, actions[i], | 48 | cell_edit.accel_edited.connect ((path, key, mods) => { |
805 | 49 | 1, shortcut.to_readable(), | 49 | var shortcut = new Shortcut (key, mods); |
806 | 50 | 2, schemas[i], // hidden | 50 | change_shortcut (path, shortcut); |
807 | 51 | 3, keys[i], -1); // hidden | 51 | }); |
808 | 52 | } | 52 | |
809 | 53 | 53 | cell_edit.accel_cleared.connect ((path) => { | |
810 | 54 | // create tree view | 54 | change_shortcut (path, (Shortcut) null); |
811 | 55 | var cell_desc = new Gtk.CellRendererText (); | 55 | }); |
812 | 56 | var cell_edit = new Gtk.CellRendererAccel (); | 56 | } |
813 | 57 | 57 | ||
814 | 58 | cell_edit.editable = true; | 58 | void load_and_display_shortcuts () { |
815 | 59 | cell_edit.accel_mode = Gtk.CellRendererAccelMode.OTHER; | 59 | list.get_group (group, out actions, out schemas, out keys); |
816 | 60 | 60 | ||
817 | 61 | this.set_model (store); | 61 | var store = new Gtk.ListStore (4, typeof (string), typeof (string), |
818 | 62 | 62 | typeof (Schema), typeof (string)); | |
819 | 63 | this.insert_column_with_attributes (-1, null, cell_desc, "text", 0); | 63 | |
820 | 64 | this.insert_column_with_attributes (-1, null, cell_edit, "text", 1); | 64 | Gtk.TreeIter iter; |
821 | 65 | // debug | 65 | |
822 | 66 | //this.insert_column_with_attributes (-1, null, cell_desc, "text", 2); | 66 | for (int i = 0; i < actions.length; i++) { |
823 | 67 | //this.insert_column_with_attributes (-1, null, cell_edit, "text", 3); | 67 | var shortcut = settings.get_val(schemas[i], keys[i]); |
824 | 68 | 68 | ||
825 | 69 | this.headers_visible = false; | 69 | if (shortcut == null) |
826 | 70 | this.expand = true; | 70 | continue; |
827 | 71 | 71 | ||
828 | 72 | this.get_column (0).expand = true; | 72 | store.append (out iter); |
829 | 73 | 73 | store.set (iter, 0, actions[i], | |
830 | 74 | this.button_press_event.connect ((event) => | 74 | 1, shortcut.to_readable(), |
831 | 75 | { | 75 | 2, schemas[i], // hidden |
832 | 76 | if (event.window != this.get_bin_window ()) | 76 | 3, keys[i], -1); // hidden |
833 | 77 | return false; | 77 | } |
834 | 78 | 78 | ||
835 | 79 | Gtk.TreePath path; | 79 | model = store; |
836 | 80 | 80 | } | |
837 | 81 | if (this.get_path_at_pos ((int) event.x, | 81 | |
838 | 82 | (int) event.y, | 82 | public bool shortcut_conflicts (Shortcut shortcut, out string name) { |
839 | 83 | out path, null, | 83 | string[] actions, keys; |
840 | 84 | null, null)) | 84 | Schema[] schemas; |
841 | 85 | { | 85 | |
842 | 86 | Gtk.TreeViewColumn col = this.get_column (1); | 86 | list.get_group (group, out actions, out schemas, out keys); |
843 | 87 | this.grab_focus (); | 87 | |
844 | 88 | this.set_cursor (path, col, true); | 88 | for (int i = 0; i < actions.length; i++) { |
845 | 89 | } | 89 | if (shortcut.is_equal (settings.get_val (schemas[i], keys[i]))) { |
846 | 90 | 90 | name = actions[i]; | |
847 | 91 | return true; | 91 | return true; |
848 | 92 | } ); | 92 | } |
849 | 93 | 93 | } | |
850 | 94 | // signals | 94 | |
851 | 95 | cell_edit.accel_edited.connect ((path, key, mods) => | 95 | return false; |
852 | 96 | { | 96 | } |
853 | 97 | var shortcut = new Shortcut (key, mods); | 97 | |
854 | 98 | change_shortcut (path, shortcut); | 98 | public void reset_shortcut (Shortcut shortcut) { |
855 | 99 | } ); | 99 | string[] actions, keys; |
856 | 100 | 100 | Schema[] schemas; | |
857 | 101 | cell_edit.accel_cleared.connect ((path) => | 101 | var empty_shortcut = new Shortcut (); |
858 | 102 | { | 102 | |
859 | 103 | change_shortcut (path, (Shortcut) null); | 103 | list.get_group (group, out actions, out schemas, out keys); |
860 | 104 | } ); | 104 | |
861 | 105 | } | 105 | for (int i = 0; i < actions.length; i++) |
862 | 106 | 106 | if (shortcut.is_equal (settings.get_val (schemas[i], keys[i]))) | |
863 | 107 | // change a shortcut in the list store and gsettings | 107 | settings.set_val (schemas[i], keys[i], empty_shortcut); |
864 | 108 | private bool change_shortcut (string path, Shortcut? shortcut) | 108 | |
865 | 109 | { | 109 | load_and_display_shortcuts (); |
866 | 110 | Gtk.TreeIter iter; | 110 | } |
867 | 111 | GLib.Value key, schema, name; | 111 | |
868 | 112 | 112 | public bool change_shortcut (string path, Shortcut? shortcut) { | |
869 | 113 | model.get_iter (out iter, new Gtk.TreePath.from_string (path)); | 113 | Gtk.TreeIter iter; |
870 | 114 | 114 | GLib.Value key, schema, name; | |
871 | 115 | model.get_value (iter, 0, out name); | 115 | |
872 | 116 | model.get_value (iter, 2, out schema); | 116 | model.get_iter (out iter, new Gtk.TreePath.from_string (path)); |
873 | 117 | model.get_value (iter, 3, out key); | 117 | |
874 | 118 | 118 | model.get_value (iter, 0, out name); | |
875 | 119 | 119 | model.get_value (iter, 2, out schema); | |
876 | 120 | if (shortcut != null) | 120 | model.get_value (iter, 3, out key); |
877 | 121 | { | 121 | |
878 | 122 | // new shortcut is old shortcut? | 122 | string conflict_name; |
879 | 123 | if (shortcut.is_equal (settings.get_val ((Schema)schema, (string)key))) | 123 | |
880 | 124 | return true; | 124 | if (shortcut != null) { |
881 | 125 | 125 | foreach (var tree in trees) { | |
882 | 126 | string conflict_accel; | 126 | if (tree.shortcut_conflicts (shortcut, out conflict_name) == false) |
883 | 127 | int conflict_group; | 127 | continue; |
884 | 128 | int conflict_path; | 128 | |
885 | 129 | 129 | var dialog = new ConflictDialog (shortcut.to_readable (), conflict_name, (string) name); | |
886 | 130 | // check if shortcut is already used | 130 | dialog.reassign.connect (() => { |
887 | 131 | if (list.conflicts (shortcut, out conflict_accel, out conflict_group, out conflict_path)) | 131 | tree.reset_shortcut (shortcut); |
888 | 132 | { | 132 | settings.set_val ((Schema) schema, (string) key, shortcut); |
889 | 133 | string conflict_action; | 133 | load_and_display_shortcuts (); |
890 | 134 | Schema conflict_schema; | 134 | }); |
891 | 135 | string conflict_key; | 135 | dialog.show (); |
892 | 136 | 136 | return false; | |
893 | 137 | // get some info about the conflicting item | 137 | } |
894 | 138 | trees[conflict_group].get_item (conflict_path, out conflict_action, out conflict_schema, out conflict_key); | 138 | } |
895 | 139 | 139 | ||
896 | 140 | // ask user what to do | 140 | settings.set_val ((Schema) schema, (string) key, shortcut ?? new Shortcut ()); |
897 | 141 | var msg = new Gtk.MessageDialog (null, Gtk.DialogFlags.MODAL, | 141 | load_and_display_shortcuts (); |
898 | 142 | Gtk.MessageType.WARNING, | 142 | return true; |
899 | 143 | Gtk.ButtonsType.NONE, | 143 | } |
900 | 144 | "\"%s\" is already used for \"%s\"!", shortcut.to_readable (), conflict_action); | 144 | } |
720 | 145 | |||
721 | 146 | msg.secondary_text = _("If you reassign the shortcut to \"%s\", \"%s\" will be disabled").printf ((string)name, conflict_action); | ||
722 | 147 | msg.add_button (_("Cancel"), 0); | ||
723 | 148 | msg.add_button (_("Reassign"), 1); | ||
724 | 149 | |||
725 | 150 | msg.response.connect ((response_id) => | ||
726 | 151 | { | ||
727 | 152 | if (response_id == 1) | ||
728 | 153 | { | ||
729 | 154 | trees[conflict_group].change_shortcut (conflict_path.to_string (), (Shortcut) null); | ||
730 | 155 | change_shortcut (path, shortcut); | ||
731 | 156 | } | ||
732 | 157 | |||
733 | 158 | msg.destroy(); | ||
734 | 159 | }); | ||
735 | 160 | msg.show (); | ||
736 | 161 | |||
737 | 162 | return false; | ||
738 | 163 | } | ||
739 | 164 | |||
740 | 165 | if (!shortcut.valid ()) | ||
741 | 166 | return false; | ||
742 | 167 | } | ||
743 | 168 | |||
744 | 169 | // unset/disable shortcut | ||
745 | 170 | if (shortcut == null) | ||
746 | 171 | { | ||
747 | 172 | (model as Gtk.ListStore).set (iter, 1, _("Disabled")); | ||
748 | 173 | settings.set_val((Schema)schema, (string)key, new Shortcut(0, (Gdk.ModifierType)0)); | ||
749 | 174 | return true; | ||
750 | 175 | } | ||
751 | 176 | |||
752 | 177 | (model as Gtk.ListStore).set (iter, 1, shortcut.to_readable ()); | ||
753 | 178 | settings.set_val((Schema)schema, (string)key, shortcut); | ||
754 | 179 | return true; | ||
755 | 180 | } | ||
756 | 181 | } | ||
901 | 182 | } | 145 | } |
902 | 183 | \ No newline at end of file | 146 | \ No newline at end of file |
903 | 184 | 147 | ||
904 | === modified file 'src/Pages/shortcuts.vala' | |||
905 | --- src/Pages/shortcuts.vala 2014-01-06 17:12:27 +0000 | |||
906 | +++ src/Pages/shortcuts.vala 2014-03-30 21:21:15 +0000 | |||
907 | @@ -5,9 +5,18 @@ | |||
908 | 5 | // class to interact with gsettings | 5 | // class to interact with gsettings |
909 | 6 | private Shortcuts.Settings settings; | 6 | private Shortcuts.Settings settings; |
910 | 7 | // array of tree views, one for each section | 7 | // array of tree views, one for each section |
912 | 8 | private Tree[] trees; | 8 | private DisplayTree[] trees; |
913 | 9 | 9 | ||
915 | 10 | private enum SectionID { WINDOWS, WORKSPACES, SCREENSHOTS, APPS, MEDIA, A11Y, COUNT } | 10 | private enum SectionID { |
916 | 11 | WINDOWS, | ||
917 | 12 | WORKSPACES, | ||
918 | 13 | SCREENSHOTS, | ||
919 | 14 | APPS, | ||
920 | 15 | MEDIA, | ||
921 | 16 | A11Y, | ||
922 | 17 | CUSTOM, | ||
923 | 18 | COUNT | ||
924 | 19 | } | ||
925 | 11 | 20 | ||
926 | 12 | private string[] section_names; | 21 | private string[] section_names; |
927 | 13 | 22 | ||
928 | @@ -27,6 +36,8 @@ | |||
929 | 27 | 36 | ||
930 | 28 | public Page () | 37 | public Page () |
931 | 29 | { | 38 | { |
932 | 39 | CustomShortcutSettings.init (); | ||
933 | 40 | |||
934 | 30 | // init public elements | 41 | // init public elements |
935 | 31 | section_names = { | 42 | section_names = { |
936 | 32 | _("Windows"), | 43 | _("Windows"), |
937 | @@ -34,15 +45,18 @@ | |||
938 | 34 | _("Screenshots"), | 45 | _("Screenshots"), |
939 | 35 | _("Applications"), | 46 | _("Applications"), |
940 | 36 | _("Media"), | 47 | _("Media"), |
942 | 37 | _("Universal Access") | 48 | _("Universal Access"), |
943 | 49 | _("Custom") | ||
944 | 38 | }; | 50 | }; |
945 | 39 | 51 | ||
946 | 40 | list = new List (); | 52 | list = new List (); |
947 | 41 | settings = new Shortcuts.Settings (); | 53 | settings = new Shortcuts.Settings (); |
948 | 42 | 54 | ||
950 | 43 | for (int id = 0; id < SectionID.COUNT; id++) { | 55 | for (int id = 0; id < SectionID.CUSTOM; id++) |
951 | 44 | trees += new Tree ((SectionID) id); | 56 | trees += new Tree ((SectionID) id); |
953 | 45 | } | 57 | |
954 | 58 | if (CustomShortcutSettings.available) | ||
955 | 59 | trees += new CustomTree (); | ||
956 | 46 | 60 | ||
957 | 47 | // private elements | 61 | // private elements |
958 | 48 | var shortcut_display = new ShortcutDisplay (trees); | 62 | var shortcut_display = new ShortcutDisplay (trees); |
959 | @@ -51,9 +65,7 @@ | |||
960 | 51 | this.attach (section_switcher, 0, 0, 1, 1); | 65 | this.attach (section_switcher, 0, 0, 1, 1); |
961 | 52 | this.attach (shortcut_display, 1, 0, 2, 1); | 66 | this.attach (shortcut_display, 1, 0, 2, 1); |
962 | 53 | 67 | ||
966 | 54 | section_switcher.changed.connect ((i) => { | 68 | section_switcher.changed.connect (shortcut_display.change_selection); |
964 | 55 | shortcut_display.change_selection (i); | ||
965 | 56 | }); | ||
967 | 57 | } | 69 | } |
968 | 58 | } | 70 | } |
969 | 59 | } | ||
970 | 60 | \ No newline at end of file | 71 | \ No newline at end of file |
971 | 72 | } |
Code style wise this can't really pass for now. You added a new file that is tab-indented (conflict_ dialog. vala). (and I realize you did it to keep consistency with existing files in the project, but new code should *usually* be good code).
Also diff lines 727-735 you mixed tabs and spaces.
I can't yet review the code itself, give me a couple of days. I'll test it in the meanwhile too.