Do

Merge lp:~cszikszoy/do/kb-disabled-keys into lp:do

Proposed by Chris S.
Status: Merged
Approved by: Alex Launi
Approved revision: 1293
Merged at revision: not available
Proposed branch: lp:~cszikszoy/do/kb-disabled-keys
Merge into: lp:do
Diff against target: None lines
To merge this branch: bzr merge lp:~cszikszoy/do/kb-disabled-keys
Reviewer Review Type Date Requested Status
Alex Launi (community) Approve
Review via email: mp+9891@code.launchpad.net

This proposal supersedes a proposal from 2009-08-09.

To post a comment you must log in.
Revision history for this message
Robert Dyer (psybers) wrote : Posted in a previous version of this proposal

Other than the Console.WriteLine on 226, looks good!

review: Approve
Revision history for this message
Chris S. (cszikszoy) wrote : Posted in a previous version of this proposal

> Other than the Console.WriteLine on 226, looks good!
... oh yeah. Thought I got all of those.

Revision history for this message
Chris S. (cszikszoy) wrote : Posted in a previous version of this proposal

Actually, I need to hold off on something. I noticed something strange with the page_down key, need to do some testing. When I register that key in the prefs UI, it binds to "Page_Down". But that console.writeline was testing what actual event keystring gets passed when I press the key. Pressing the Page Down key on my keyboard shows the event keystring "Last"...

Revision history for this message
Alex Launi (alexlauni) wrote :

looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/KeyBindingService.cs'
2--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/KeyBindingService.cs 2009-08-01 22:03:03 +0000
3+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/KeyBindingService.cs 2009-08-08 05:48:10 +0000
4@@ -36,23 +36,24 @@
5 }
6 }
7
8- void KeybindingPressed (string keystring, IntPtr user_data) {
9+ void KeybindingPressed (string keystring, IntPtr user_data)
10+ {
11 if (Bindings.Any (k => k.KeyString == keystring)) {
12 Bindings.First (k => k.KeyString == keystring).Callback (null);
13 }
14 }
15
16- public override bool RegisterOSKey (string keyString, EventCallback cb) {
17+ public override bool RegisterOSKey (string keyString, EventCallback cb)
18+ {
19 if (string.IsNullOrEmpty (keyString) || cb == null)
20 return false;
21 return gnomedo_keybinder_bind (keyString, key_handler);
22 }
23
24- public override bool UnRegisterOSKey (string keyString) {
25-
26- if (Bindings.Any (k => k.KeyString == keyString)) {
27+ public override bool UnRegisterOSKey (string keyString)
28+ {
29+ if (Bindings.Any (k => k.KeyString == keyString))
30 return gnomedo_keybinder_unbind (keyString, key_handler);
31- }
32 return false;
33 }
34 }
35
36=== modified file 'Do.Platform/src/Do.Platform/Do.Platform.Common/AbstractKeyBindingService.cs'
37--- Do.Platform/src/Do.Platform/Do.Platform.Common/AbstractKeyBindingService.cs 2009-08-06 15:52:20 +0000
38+++ Do.Platform/src/Do.Platform/Do.Platform.Common/AbstractKeyBindingService.cs 2009-08-08 05:48:10 +0000
39@@ -33,19 +33,20 @@
40
41 public bool RegisterKeyBinding (KeyBinding binding)
42 {
43- //first check if this keystring is already used
44- if (Bindings.Any (k => k.KeyString == binding.KeyString)) {
45- Log<AbstractKeyBindingService>.Error ("Failed to bind \"{0}\" to \"{1}\"", binding.KeyString);
46- return false;
47- }
48-
49 //try to get the keystring from the prefs. We default to the KeyBinding.KeyString, so we can later check
50 //if the prefs value matches that, we're using the default, otherwise we're using a user specified value
51 string prefsKeyString = prefs.Get (binding.Description.Replace (' ', '_'), binding.KeyString);
52+
53 //if these values don't match then the user has specified a new keystring
54 //update the KeyEvent then continue
55 if (prefsKeyString != binding.KeyString)
56 binding.KeyString = prefsKeyString;
57+
58+ //check if this keystring is already used
59+ if (Bindings.Any (k => k.KeyString == binding.KeyString)) {
60+ Log<AbstractKeyBindingService>.Error ("Key \"{0}\" is already mapped.", binding.KeyString);
61+ binding.KeyString = "";
62+ }
63
64 //if we are registering a key with the OS, do something special
65 if (binding.IsOSKey) {
66@@ -57,7 +58,7 @@
67 } else {
68 Log<AbstractKeyBindingService>.Error ("Failed to bind \"{0}\" to \"{1}\"", binding.Description,
69 binding.KeyString);
70- binding.KeyString = Catalog.GetString ("Disabled");
71+ binding.KeyString = "";
72 }
73 }
74 }
75@@ -73,27 +74,25 @@
76 public bool SetKeyString (KeyBinding binding, string newKeyString)
77 {
78 //first check if this keystring exists
79- if (!Bindings.Any (k => k.KeyString == binding.KeyString)) {
80- Log<AbstractKeyBindingService>.Error ("Failed to bind \"{0}\" to \"{1}\"", binding.KeyString);
81+ if (!Bindings.Any (k => k.KeyString == binding.KeyString))
82 return false;
83- }
84-
85+
86 //if this key should be registered with the OS
87 if (binding.IsOSKey) {
88 //remove the old keystring from the OS
89 UnRegisterOSKey (binding.KeyString);
90- //register again with the new keystring, otherwise bail
91- if (!RegisterOSKey (newKeyString, binding.Callback))
92- return false;
93+ //register again with the new keystring
94+ RegisterOSKey (newKeyString, binding.Callback);
95 }
96
97 //set the new keystring
98- Bindings.First (k => k.KeyString == binding.KeyString).KeyString = newKeyString;
99+ Bindings.First (k => k.Description == binding.Description).KeyString = newKeyString;
100
101 //save the new value in the prefs
102 prefs.Set (binding.Description.Replace (' ', '_'), binding.KeyString);
103
104- Log<AbstractKeyBindingService>.Debug ("\"{0}\" now mapped to \"{1}\"", binding.Description, binding.KeyString);
105+ if (!string.IsNullOrEmpty (binding.KeyString))
106+ Log<AbstractKeyBindingService>.Debug ("\"{0}\" now mapped to \"{1}\"", binding.Description, binding.KeyString);
107
108 return true;
109 }
110
111=== modified file 'Do/src/Do.Core/Controller.cs'
112--- Do/src/Do.Core/Controller.cs 2009-08-06 15:53:55 +0000
113+++ Do/src/Do.Core/Controller.cs 2009-08-09 00:54:16 +0000
114@@ -117,13 +117,16 @@
115 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Summon Do"), "<Super>space",
116 OnSummonKeyPressEvent, true));
117
118- // this keybinding is disabled by default - note the empty binding
119+ // this keybinding is disabled by default - note the empty keybinding
120 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Summon in Text Mode"), "",
121 OnTextModeSummonKeyPressEvent, true));
122
123 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Enter Text Mode"), "period",
124 OnTextModePressEvent));
125
126+ Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Clear"), "Escape",
127+ OnClearKeyPressEvent));
128+
129 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Copy to Clipboard"), "<Control>c",
130 OnCopyEvent));
131 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Paste from Clipboard"), "<Control>v",
132@@ -135,24 +138,24 @@
133 OnNextPanePressEvent));
134
135 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Previous Item"), "Up",
136- OnUpKeyPressEvent));
137+ OnPreviousItemPressEvent));
138 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Next Item"), "Down",
139- OnDownKeyPressEvent));
140+ OnNextItemPressEvent));
141
142 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("First Item"), "Home",
143- OnHomeKeyPressEvent));
144+ OnFirstItemPressEvent));
145 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Last Item"), "End",
146- OnEndKeyPressEvent));
147+ OnLastItemPressEvent));
148
149 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Previous 5 Results"), "Page_Up",
150- OnPageUpKeyPressEvent));
151+ OnNextItemPagePressEvent));
152 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Next 5 Results"), "Page_Down",
153- OnPageDownKeyPressEvent));
154+ OnPreviousItemPagePressEvent));
155
156 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Step Out of Item"), "Left",
157- OnLeftKeyPressEvent));
158+ OnStepOutItemPressEvent));
159 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Step Into Item"), "Right",
160- OnRightKeyPressEvent));
161+ OnStepInItemPressEvent));
162
163 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Select Multiple Items"), "comma",
164 OnSelectionKeyPressEvent));
165@@ -453,12 +456,9 @@
166 private void KeyPressWrap (EventKey evnt)
167 {
168 Key key = (Key) evnt.KeyValue;
169-
170
171- // Currently - only hardcoded are enter keys, escape and delete/backspace
172- if (key == Key.Escape) {
173- OnEscapeKeyPressEvent (evnt);
174- } else if (key == Key.Return ||
175+ // Currently - only hardcoded are enter keys and delete/backspace
176+ if (key == Key.Return ||
177 key == Key.ISO_Enter ||
178 key == Key.KP_Enter) {
179 OnActivateKeyPressEvent (evnt);
180@@ -539,7 +539,7 @@
181 UpdatePane (CurrentPane);
182 }
183
184- void OnEscapeKeyPressEvent (EventKey evnt)
185+ void OnClearKeyPressEvent (EventKey evnt)
186 {
187 im_context.Reset ();
188 if (SearchController.TextType == TextModeType.Explicit) {
189@@ -588,7 +588,7 @@
190 }
191 }
192
193- void OnLeftKeyPressEvent (EventKey evnt)
194+ void OnStepOutItemPressEvent (EventKey evnt)
195 {
196 im_context.Reset ();
197 if (!SearchController.Results.Any ()) return;
198@@ -603,7 +603,7 @@
199 }
200
201 // Hmm.
202- void OnRightKeyPressEvent (EventKey evnt)
203+ void OnStepInItemPressEvent (EventKey evnt)
204 {
205 im_context.Reset ();
206 if (!SearchController.Results.Any ()) return;
207@@ -655,7 +655,7 @@
208 UpdatePane (CurrentPane);
209 }
210
211- void OnUpKeyPressEvent (EventKey evnt)
212+ void OnPreviousItemPressEvent (EventKey evnt)
213 {
214 im_context.Reset ();
215 if (!results_grown) {
216@@ -671,7 +671,7 @@
217 }
218 }
219
220- void OnDownKeyPressEvent (EventKey evnt)
221+ void OnNextItemPressEvent (EventKey evnt)
222 {
223 im_context.Reset ();
224 if (!results_grown) {
225@@ -681,25 +681,25 @@
226 SearchController.Cursor++;
227 }
228
229- void OnHomeKeyPressEvent (EventKey evnt)
230+ void OnFirstItemPressEvent (EventKey evnt)
231 {
232 im_context.Reset ();
233 SearchController.Cursor = 0;
234 }
235
236- void OnEndKeyPressEvent (EventKey evnt)
237+ void OnLastItemPressEvent (EventKey evnt)
238 {
239 im_context.Reset ();
240 SearchController.Cursor = SearchController.Results.Count - 1;
241 }
242
243- void OnPageUpKeyPressEvent (EventKey evnt)
244+ void OnNextItemPagePressEvent (EventKey evnt)
245 {
246 im_context.Reset ();
247 SearchController.Cursor -= 5;
248 }
249
250- void OnPageDownKeyPressEvent (EventKey evnt)
251+ void OnPreviousItemPagePressEvent (EventKey evnt)
252 {
253 im_context.Reset ();
254 SearchController.Cursor += 5;
255@@ -733,7 +733,7 @@
256 if (evnt.Key == Key.ISO_Left_Tab)
257 return string.Format ("{0}{1}", modifier, Key.Tab);
258 }
259- return string.Format ("{0}{1}", modifier, evnt.Key.ToString ());
260+ return string.Format ("{0}{1}", modifier, Gtk.Accelerator.Name (evnt.KeyValue, Gdk.ModifierType.None));
261 }
262 #endregion
263
264
265=== modified file 'Do/src/Do.UI/KeybindingTreeView.cs'
266--- Do/src/Do.UI/KeybindingTreeView.cs 2009-08-03 21:28:26 +0000
267+++ Do/src/Do.UI/KeybindingTreeView.cs 2009-08-08 22:41:51 +0000
268@@ -67,9 +67,11 @@
269 ListStore store = Model as ListStore;
270 store.Clear ();
271
272- foreach (KeyBinding binding in Services.Keybinder.Bindings) { //.OrderBy (k => k.Description)) {
273- Log<KeybindingTreeView>.Debug (binding.Description);
274- store.AppendValues (binding.Description, binding.KeyString, binding.DefaultKeyString, binding);
275+ string ks;
276+
277+ foreach (KeyBinding binding in Services.Keybinder.Bindings) {
278+ ks = (string.IsNullOrEmpty (binding.KeyString)) ? Catalog.GetString ("Disabled") : binding.KeyString;
279+ store.AppendValues (binding.Description, ks, binding.DefaultKeyString, binding);
280 }
281 }
282
283@@ -96,7 +98,7 @@
284 {
285 string binding = model.GetValue (treeiter, (int) Column.BoundKeyString) as string;
286 if (binding == keyBinding) {
287- model.SetValue (treeiter, (int) Column.BoundKeyString, "");
288+ model.SetValue (treeiter, (int) Column.BoundKeyString, Catalog.GetString ("Disabled"));
289 }
290 return false;
291 }
292@@ -132,11 +134,13 @@
293
294 store = Model as ListStore;
295 store.GetIter (out iter, new TreePath (args.PathString));
296+
297 try {
298 string defaultVal = store.GetValue (iter, (int) Column.DefaultKeybinding).ToString ();
299+ defaultVal = (string.IsNullOrEmpty (defaultVal)) ? Catalog.GetString ("Disabled") : defaultVal;
300 store.SetValue (iter, (int) Column.BoundKeyString, defaultVal);
301 } catch (Exception e) {
302- store.SetValue (iter, (int) Column.BoundKeyString, "");
303+ store.SetValue (iter, (int) Column.BoundKeyString, Catalog.GetString ("Disabled"));
304 }
305
306 SaveBindings ();
307@@ -152,6 +156,8 @@
308 string newKeyString = model.GetValue (iter, (int) Column.BoundKeyString) as string;
309 KeyBinding binding = model.GetValue (iter, (int) Column.Binding) as KeyBinding;
310
311+ newKeyString = (newKeyString == Catalog.GetString ("Disabled")) ? "" : newKeyString;
312+
313 //only save if the keystring changed
314 if (newKeyString != null && binding.KeyString != newKeyString) {
315 //try to save