Do

Merge lp:~cszikszoy/do/kb-service into lp:do

Proposed by Chris S.
Status: Superseded
Proposed branch: lp:~cszikszoy/do/kb-service
Merge into: lp:do
Diff against target: None lines
To merge this branch: bzr merge lp:~cszikszoy/do/kb-service
Reviewer Review Type Date Requested Status
Do Core Team Pending
Review via email: mp+9183@code.launchpad.net

This proposal has been superseded by a proposal from 2009-07-27.

To post a comment you must log in.
Revision history for this message
Chris S. (cszikszoy) wrote :

This adds a Keybinding service to Do.Platform.

This service is what all other assemblies will interact with to register keys (both internal and with the host OS) to perform specific actions. Keys can now be bound from any other assmebly that references Do.Platform. Also, multiple key combinations can now be registered with the host OS. For example, I've added a new global hotkey, "<Super>period", this will summon do directly in text mode. Using the keybinding service, this can all be done in one line.

The keybinding service consists of an interface in Do.Platform, IKeyBindingService. Next, in Do.Platform.Common an AbstractKeyBindingService is defined. This class implements all of the platform independant code relating to mapping and keeping track of hotkeys. For example, all internal events (anything other than the summon key, basically) get handled by this class. This class defines two abstract methods, RegisterOSKey, and UnRegisterOSKey. These methods should be defined in the platform specific implementation of the Keybinding service which gets placed in Do.Platform.*

Along with creating the keybinging service, I've also edited libdo to return gbooleans when it tries to register or unregister keys. This feedback helpful in determining if we were successful in attempting to register a particular keystring with the host OS. Should the binding of a keystring, the KeybindingService will attempt to use the DefaultKeystring, instead of what's in the preferences.

Finally, I've removed unnecessary files (XKeyBinder.cs & CoreKeyBindings.cs, both in Do) and fixed the KeyBindingTreeview in the preferences widget. Thanks to a tip I saw on a bug report, setting the CellRendererAccelMode to "Other" allows many more keys to be grabbed.

I originally wrote this service as a part of the Windows port, and I've already written the windows specific implementation of KeyBindingService there.

lp:~cszikszoy/do/kb-service updated
1285. By Chris S.

remove debug msg

Revision history for this message
Chris S. (cszikszoy) wrote :

Also, please ignore the Console.WriteLine () on line 1038 of the diff. I removed that in rev 1285, but LP currently doesn't update the merge diff when I add revisions after I proposed the merge.

(Here's to hoping they fix that! https://bugs.launchpad.net/launchpad-code/+bug/392343)

Revision history for this message
David Siegel (djsiegel-deactivatedaccount) wrote :

Awesome.

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

Please remove the <Super>period global keybinding, and then we'll be merge
ready!

--
--Alex Launi

Revision history for this message
Chris S. (cszikszoy) wrote :

I can do that, but I thought it was pretty neat and useful for plugins that primarily use text mode, like Microblogging or Translate. It was also something that I put in there to highlight the capabilities of the new keybinding service, but if you think it should go, I can take it out.

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

On Sat, Jul 25, 2009 at 12:28 AM, Chris S. <email address hidden> wrote:

> I can do that, but I thought it was pretty neat and useful for plugins that
> primarily use text mode, like Microblogging or Translate. It was also
> something that I put in there to highlight the capabilities of the new
> keybinding service, but if you think it should go, I can take it out.
> --
> https://code.edge.launchpad.net/~cszikszoy/do/kb-service/+merge/9183<https://code.edge.launchpad.net/%7Ecszikszoy/do/kb-service/+merge/9183>
> Your team GNOME Do Core Team is subscribed to branch lp:do.
>

I can see why it'd be neat but I don't think it's useful enough to warrant a
second keybinding to summon Do, and has the potential to be more confusing
than useful. I wouldn't be opposed to leaving it in the keybindings UI but
unbound by default, so that power users can bind it if they want. How do you
feel about that?

--
--Alex Launi

lp:~cszikszoy/do/kb-service updated
1286. By Chris S.

change dict to list, leave summon in text mode unbound by default

1287. By Chris S.

merge trunk

1288. By Chris S.

fixes as per Roberts review

1289. By Chris S.

it helps when I save the file _before_ pushing...

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'Do.Platform.Linux/Do.Platform.Linux.dll.config.in'
--- Do.Platform.Linux/Do.Platform.Linux.dll.config.in 1970-01-01 00:00:00 +0000
+++ Do.Platform.Linux/Do.Platform.Linux.dll.config.in 2009-07-23 07:17:00 +0000
@@ -0,0 +1,3 @@
1<configuration>
2 <dllmap dll="libdo" target="@expanded_libdir@/@PACKAGE@/libdo.so"/>
3</configuration>
04
=== modified file 'Do.Platform.Linux/Do.Platform.Linux.mdp'
--- Do.Platform.Linux/Do.Platform.Linux.mdp 2009-06-26 11:01:40 +0000
+++ Do.Platform.Linux/Do.Platform.Linux.mdp 2009-07-22 01:12:59 +0000
@@ -52,6 +52,7 @@
52 <File name="src/Do.Platform/Do.Platform.Linux/NetworkService.cs" subtype="Code" buildaction="Compile" />52 <File name="src/Do.Platform/Do.Platform.Linux/NetworkService.cs" subtype="Code" buildaction="Compile" />
53 <File name="src/Do.Widgets/PluginAvailableDialog.cs" subtype="Code" buildaction="Compile" />53 <File name="src/Do.Widgets/PluginAvailableDialog.cs" subtype="Code" buildaction="Compile" />
54 <File name="gtk-gui/Do.Platform.Linux.PluginAvailableDialog.cs" subtype="Code" buildaction="Compile" />54 <File name="gtk-gui/Do.Platform.Linux.PluginAvailableDialog.cs" subtype="Code" buildaction="Compile" />
55 <File name="src/Do.Platform/Do.Platform.Linux/KeyBindingService.cs" subtype="Code" buildaction="Compile" />
55 </Contents>56 </Contents>
56 <References>57 <References>
57 <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />58 <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
@@ -71,7 +72,7 @@
71 <ProjectReference type="Project" localcopy="True" refto="Do.Interface.Linux" />72 <ProjectReference type="Project" localcopy="True" refto="Do.Interface.Linux" />
72 <ProjectReference type="Gac" localcopy="True" refto="gnome-vfs-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />73 <ProjectReference type="Gac" localcopy="True" refto="gnome-vfs-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
73 <ProjectReference type="Gac" localcopy="True" refto="gnome-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />74 <ProjectReference type="Gac" localcopy="True" refto="gnome-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
75 <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
74 <ProjectReference type="Gac" localcopy="True" refto="nunit.framework, Version=2.2.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />76 <ProjectReference type="Gac" localcopy="True" refto="nunit.framework, Version=2.2.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
75 <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
76 </References>77 </References>
77</Project>78</Project>
78\ No newline at end of file79\ No newline at end of file
7980
=== modified file 'Do.Platform.Linux/Makefile.am'
--- Do.Platform.Linux/Makefile.am 2009-06-26 11:01:40 +0000
+++ Do.Platform.Linux/Makefile.am 2009-07-23 07:17:00 +0000
@@ -7,7 +7,7 @@
7FILES = \7FILES = \
8 gtk-gui/Do.Platform.Linux.AbstractLoginWidget.cs \8 gtk-gui/Do.Platform.Linux.AbstractLoginWidget.cs \
9 gtk-gui/Do.Platform.Linux.PluginAvailableDialog.cs \9 gtk-gui/Do.Platform.Linux.PluginAvailableDialog.cs \
10 gtk-gui/generated.cs \10 gtk-gui/generated.cs \
11 src/AssemblyInfo.cs \11 src/AssemblyInfo.cs \
12 src/Do.Platform/ConsoleCrayon.cs \12 src/Do.Platform/ConsoleCrayon.cs \
13 src/Do.Platform/Do.Platform.Linux/Do.Platform.Linux.DBus/IController.cs \13 src/Do.Platform/Do.Platform.Linux/Do.Platform.Linux.DBus/IController.cs \
@@ -23,6 +23,7 @@
23 src/Do.Platform/Do.Platform.Linux/TrayIconService.cs \23 src/Do.Platform/Do.Platform.Linux/TrayIconService.cs \
24 src/Do.Platform/Do.Platform.Linux/UniverseFactoryService.cs \24 src/Do.Platform/Do.Platform.Linux/UniverseFactoryService.cs \
25 src/Do.Platform/Do.Platform.Linux/NetworkService.cs \25 src/Do.Platform/Do.Platform.Linux/NetworkService.cs \
26 src/Do.Platform/Do.Platform.Linux/KeyBindingService.cs \
26 src/Do.Universe/ApplicationItem.cs \27 src/Do.Universe/ApplicationItem.cs \
27 src/Do.Universe/CategoryItem.cs \28 src/Do.Universe/CategoryItem.cs \
28 src/Do.Universe/NullApplicationItem.cs \29 src/Do.Universe/NullApplicationItem.cs \
@@ -63,3 +64,8 @@
63 Do.Universe \64 Do.Universe \
64 Do.Platform \65 Do.Platform \
65 Do.Interface.Linux66 Do.Interface.Linux
67
68CLEANFILES += Do.Platform.Linux.dll.config
69EXTRA_DIST += Do.Platform.Linux.dll.config.in
70
71module_DATA += Do.Platform.Linux.dll.config
6672
=== modified file 'Do.Platform.Linux/Resources/Do.Platform.Linux.addin.xml'
--- Do.Platform.Linux/Resources/Do.Platform.Linux.addin.xml 2009-06-26 09:44:33 +0000
+++ Do.Platform.Linux/Resources/Do.Platform.Linux.addin.xml 2009-07-22 01:12:59 +0000
@@ -22,6 +22,7 @@
22 <Service type="Do.Platform.Linux.NetworkService" />22 <Service type="Do.Platform.Linux.NetworkService" />
23 <Service type="Do.Platform.Linux.TrayIconService" />23 <Service type="Do.Platform.Linux.TrayIconService" />
24 <Service type="Do.Platform.Linux.ConsoleLogService" />24 <Service type="Do.Platform.Linux.ConsoleLogService" />
25 <Service type="Do.Platform.Linux.KeyBindingService" />
25 <Service type="Do.Platform.Linux.EnvironmentService" />26 <Service type="Do.Platform.Linux.EnvironmentService" />
26 <Service type="Do.Platform.Linux.UniverseFactoryService" />27 <Service type="Do.Platform.Linux.UniverseFactoryService" />
27 <Service type="Do.Platform.Linux.GConfPreferencesService" />28 <Service type="Do.Platform.Linux.GConfPreferencesService" />
2829
=== added file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/KeyBindingService.cs'
--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/KeyBindingService.cs 1970-01-01 00:00:00 +0000
+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/KeyBindingService.cs 2009-07-23 07:17:00 +0000
@@ -0,0 +1,57 @@
1using System;
2using System.Linq;
3using System.Collections.Generic;
4using System.Runtime.InteropServices;
5
6using Mono.Unix;
7using Gdk;
8using Do.Platform.Common;
9
10namespace Do.Platform.Linux
11{
12 class KeyBindingService : AbstractKeyBindingService
13 {
14
15 [DllImport("libdo")]
16 static extern void gnomedo_keybinder_init ();
17
18 [DllImport("libdo")]
19 static extern bool gnomedo_keybinder_bind (string keystring, BindkeyHandler handler);
20
21 [DllImport("libdo")]
22 static extern bool gnomedo_keybinder_unbind (string keystring, BindkeyHandler handler);
23
24 public delegate void BindkeyHandler (string key, IntPtr user_data);
25
26 BindkeyHandler key_handler;
27
28 public KeyBindingService () : base ()
29 {
30 key_handler = new BindkeyHandler (KeybindingPressed);
31
32 try {
33 gnomedo_keybinder_init ();
34 } catch (DllNotFoundException) {
35 Log.Error ("libdo not found - keybindings will not work.");
36 }
37 }
38
39 void KeybindingPressed (string keystring, IntPtr user_data) {
40 if (Bindings.ContainsKey (keystring)) {
41 Bindings [keystring].Callback (null);
42 }
43 }
44
45 public override bool RegisterOSKey (string keyString, EventCallback cb) {
46 return gnomedo_keybinder_bind (keyString, key_handler);
47 }
48
49 public override bool UnRegisterOSKey (string keyString) {
50
51 if (Bindings.ContainsKey (keyString)) {
52 return gnomedo_keybinder_unbind (keyString, key_handler);
53 }
54 return false;
55 }
56 }
57}
0\ No newline at end of file58\ No newline at end of file
159
=== modified file 'Do.Platform/Do.Platform.mdp'
--- Do.Platform/Do.Platform.mdp 2009-06-26 11:01:40 +0000
+++ Do.Platform/Do.Platform.mdp 2009-07-23 07:17:00 +0000
@@ -86,6 +86,10 @@
86 <File name="src/Do.Platform/Do.Platform.Default/PluginManagerService.cs" subtype="Code" buildaction="Compile" />86 <File name="src/Do.Platform/Do.Platform.Default/PluginManagerService.cs" subtype="Code" buildaction="Compile" />
87 <File name="src/Do.Platform/Do.Platform.ServiceStack/IStrictService.cs" subtype="Code" buildaction="Compile" />87 <File name="src/Do.Platform/Do.Platform.ServiceStack/IStrictService.cs" subtype="Code" buildaction="Compile" />
88 <File name="src/Do.Universe/Do.Universe.Common/CopyToClipboardAction.cs" subtype="Code" buildaction="Compile" />88 <File name="src/Do.Universe/Do.Universe.Common/CopyToClipboardAction.cs" subtype="Code" buildaction="Compile" />
89 <File name="src/Do.Platform/Do.Platform.Common/AbstractKeyBindingService.cs" subtype="Code" buildaction="Compile" />
90 <File name="src/Do.Platform/IKeyBindingService.cs" subtype="Code" buildaction="Compile" />
91 <File name="src/Do.Platform/KeyBinding.cs" subtype="Code" buildaction="Compile" />
92 <File name="src/Do.Platform/Do.Platform.Default/KeyBindingService.cs" subtype="Code" buildaction="Compile" />
89 </Contents>93 </Contents>
90 <References>94 <References>
91 <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />95 <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
@@ -95,7 +99,7 @@
95 <ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />99 <ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
96 <ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />100 <ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
97 <ProjectReference type="Gac" localcopy="True" refto="gnome-vfs-sharp, Version=2.24.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />101 <ProjectReference type="Gac" localcopy="True" refto="gnome-vfs-sharp, Version=2.24.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
102 <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
98 <ProjectReference type="Gac" localcopy="True" refto="nunit.framework, Version=2.2.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />103 <ProjectReference type="Gac" localcopy="True" refto="nunit.framework, Version=2.2.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
99 <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
100 </References>104 </References>
101</Project>105</Project>
102\ No newline at end of file106\ No newline at end of file
103107
=== modified file 'Do.Platform/Makefile.am'
--- Do.Platform/Makefile.am 2009-06-26 11:01:40 +0000
+++ Do.Platform/Makefile.am 2009-07-23 07:17:00 +0000
@@ -14,6 +14,7 @@
14 src/Do.Platform/Do.Platform.Common/DictionaryPreferencesService.cs \14 src/Do.Platform/Do.Platform.Common/DictionaryPreferencesService.cs \
15 src/Do.Platform/Do.Platform.Common/EventsOnlyNotificationsService.cs \15 src/Do.Platform/Do.Platform.Common/EventsOnlyNotificationsService.cs \
16 src/Do.Platform/Do.Platform.Common/FileLogService.cs \16 src/Do.Platform/Do.Platform.Common/FileLogService.cs \
17 src/Do.Platform/Do.Platform.Common/AbstractKeyBindingService.cs \
17 src/Do.Platform/Do.Platform.Default/CoreService.cs \18 src/Do.Platform/Do.Platform.Default/CoreService.cs \
18 src/Do.Platform/Do.Platform.Default/DefaultApplicationService.cs \19 src/Do.Platform/Do.Platform.Default/DefaultApplicationService.cs \
19 src/Do.Platform/Do.Platform.Default/DefaultSystemService.cs \20 src/Do.Platform/Do.Platform.Default/DefaultSystemService.cs \
@@ -28,6 +29,7 @@
28 src/Do.Platform/Do.Platform.Default/UniverseFactoryService.cs \29 src/Do.Platform/Do.Platform.Default/UniverseFactoryService.cs \
29 src/Do.Platform/Do.Platform.Default/WindowingService.cs \30 src/Do.Platform/Do.Platform.Default/WindowingService.cs \
30 src/Do.Platform/Do.Platform.Default/NetworkService.cs \31 src/Do.Platform/Do.Platform.Default/NetworkService.cs \
32 src/Do.Platform/Do.Platform.Default/KeyBindingService.cs \
31 src/Do.Platform/Do.Platform.Preferences/PreferencesFactory.cs \33 src/Do.Platform/Do.Platform.Preferences/PreferencesFactory.cs \
32 src/Do.Platform/Do.Platform.Preferences/PreferencesImplementation.cs \34 src/Do.Platform/Do.Platform.Preferences/PreferencesImplementation.cs \
33 src/Do.Platform/Do.Platform.ServiceStack/IInitializedService.cs \35 src/Do.Platform/Do.Platform.ServiceStack/IInitializedService.cs \
@@ -57,6 +59,8 @@
57 src/Do.Platform/Services.cs \59 src/Do.Platform/Services.cs \
58 src/Do.Platform/INetworkService.cs \60 src/Do.Platform/INetworkService.cs \
59 src/Do.Platform/NetworkStateChangedEventArgs.cs \61 src/Do.Platform/NetworkStateChangedEventArgs.cs \
62 src/Do.Platform/IKeyBindingService.cs \
63 src/Do.Platform/KeyBinding.cs \
60 src/Do.Universe/Do.Universe.Common/EmailAction.cs \64 src/Do.Universe/Do.Universe.Common/EmailAction.cs \
61 src/Do.Universe/Do.Universe.Common/OpenAction.cs \65 src/Do.Universe/Do.Universe.Common/OpenAction.cs \
62 src/Do.Universe/Do.Universe.Common/OpenUrlAction.cs \66 src/Do.Universe/Do.Universe.Common/OpenUrlAction.cs \
@@ -89,5 +93,6 @@
89 System \93 System \
90 System.Core \94 System.Core \
91 Mono.Posix \95 Mono.Posix \
96 $(GTK_SHARP_20_LIBS) \
92 $(MONO_ADDINS_LIBS) \97 $(MONO_ADDINS_LIBS) \
93 $(NUNIT_LIBS)98 $(NUNIT_LIBS)
9499
=== added file 'Do.Platform/src/Do.Platform/Do.Platform.Common/AbstractKeyBindingService.cs'
--- Do.Platform/src/Do.Platform/Do.Platform.Common/AbstractKeyBindingService.cs 1970-01-01 00:00:00 +0000
+++ Do.Platform/src/Do.Platform/Do.Platform.Common/AbstractKeyBindingService.cs 2009-07-23 07:17:00 +0000
@@ -0,0 +1,102 @@
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6using Do.Platform.Common;
7
8namespace Do.Platform.Common
9{
10 public abstract class AbstractKeyBindingService : IKeyBindingService
11 {
12
13 public abstract bool RegisterOSKey (string keyString, EventCallback cb);
14 public abstract bool UnRegisterOSKey (string keyString);
15
16 IPreferences prefs;
17
18 #region IInitializedService
19
20 public void Initialize () {
21 Bindings = new Dictionary<string, KeyBinding> ();
22
23 prefs = Services.Preferences.Get<AbstractKeyBindingService> ();
24 }
25
26 #endregion
27
28 #region IKeyBindingService
29
30 // keyString -> KeyEvent
31 public Dictionary<string, KeyBinding> Bindings { get; private set; }
32
33 public bool RegisterKeyBinding (KeyBinding binding) {
34 bool success = true;
35
36 //first check if this event is already mapped
37 if (Bindings.ContainsKey (binding.KeyString)) {
38 Log<AbstractKeyBindingService>.Error ("'{0}' is already mapped", binding.KeyString);
39 return false;
40 }
41
42 //try to get the keystring from the prefs. We default to the KeyBinding.KeyString, so we can later check
43 //if the prefs value matches that, we're using the default, otherwise we're using a user specified value
44 string prefsKeyString = prefs.Get (binding.Description.Replace (' ', '_'), binding.KeyString);
45 //if these values don't match then the user has specified a new keystring
46 //update the KeyEvent then continue
47 if (prefsKeyString != binding.KeyString)
48 binding.KeyString = prefsKeyString;
49
50 //if we are registering a key with the OS, do something special
51 if (binding.IsOSKey) {
52 //try to register the key from the prefs with the OS
53 success = RegisterOSKey (binding.KeyString, binding.Callback);
54 //if we fail to register the summon key, try again with the default binding
55 if (!success && RegisterOSKey (binding.DefaultKeyString, binding.Callback)) {
56 //if we succeeded now, change the event's keystring
57 binding.KeyString = binding.DefaultKeyString;
58 success = true;
59 }
60 }
61
62 if (success) {
63 //add the event to our mapped events dict
64 Bindings.Add (binding.KeyString, binding);
65 //set the bound keystring in the prefs
66 SetKeyString (binding, binding.KeyString);
67 }
68
69 return success;
70 }
71
72 public bool SetKeyString (KeyBinding binding, string newKeyString) {
73 bool success = true;
74
75 //if this key should be registered with the OS
76 if (binding.IsOSKey) {
77 //remove the old keystring from the OS
78 UnRegisterOSKey (binding.KeyString);
79 //register again with the new keystring
80 success = RegisterOSKey (newKeyString, binding.Callback);
81 }
82
83 if (success) {
84 //first remove the old binding
85 Bindings.Remove (binding.KeyString);
86 //next set the new keystring
87 binding.KeyString = newKeyString;
88 //now add it back to the dict of bindings
89 Bindings.Add (binding.KeyString, binding);
90
91 //save the new value in the prefs
92 prefs.Set (binding.Description.Replace (' ', '_'), binding.KeyString);
93
94 Log<AbstractKeyBindingService>.Debug ("Event '{0}' now mapped to: {1}", binding.Description, binding.KeyString);
95 }
96
97 return success;
98 }
99
100 #endregion
101 }
102}
0\ No newline at end of file103\ No newline at end of file
1104
=== added file 'Do.Platform/src/Do.Platform/Do.Platform.Default/KeyBindingService.cs'
--- Do.Platform/src/Do.Platform/Do.Platform.Default/KeyBindingService.cs 1970-01-01 00:00:00 +0000
+++ Do.Platform/src/Do.Platform/Do.Platform.Default/KeyBindingService.cs 2009-07-23 07:17:00 +0000
@@ -0,0 +1,23 @@
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6using Do.Platform.Common;
7
8namespace Do.Platform.Default
9{
10 class KeyBindingService : IKeyBindingService
11 {
12 public bool RegisterKeyBinding (KeyBinding evnt) {
13 Log.Error ("Default keybinding service cannot register key events. {0}", evnt.KeyString);
14 return false;
15 }
16 public bool SetKeyString (KeyBinding binding, string keyString) {
17 return false;
18 }
19 public Dictionary<string, KeyBinding> Bindings { get { return null; } }
20 public void Initialize () {
21 }
22 }
23}
024
=== added file 'Do.Platform/src/Do.Platform/IKeyBindingService.cs'
--- Do.Platform/src/Do.Platform/IKeyBindingService.cs 1970-01-01 00:00:00 +0000
+++ Do.Platform/src/Do.Platform/IKeyBindingService.cs 2009-07-23 07:17:00 +0000
@@ -0,0 +1,19 @@
1using System;
2using System.Collections.Generic;
3
4using Do.Platform.Common;
5using Do.Platform.ServiceStack;
6
7using Gdk;
8
9namespace Do.Platform
10{
11 public delegate void EventCallback (EventKey evtky);
12
13 public interface IKeyBindingService : IInitializedService
14 {
15 bool RegisterKeyBinding (KeyBinding evnt);
16 bool SetKeyString (KeyBinding binding, string keyString);
17 Dictionary<string, KeyBinding> Bindings { get; }
18 }
19}
020
=== added file 'Do.Platform/src/Do.Platform/KeyBinding.cs'
--- Do.Platform/src/Do.Platform/KeyBinding.cs 1970-01-01 00:00:00 +0000
+++ Do.Platform/src/Do.Platform/KeyBinding.cs 2009-07-23 07:17:00 +0000
@@ -0,0 +1,33 @@
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6using Do.Platform.Common;
7
8using Gdk;
9
10namespace Do.Platform
11{
12 public class KeyBinding
13 {
14 public string Description { get; private set; }
15 public EventCallback Callback { get; private set; }
16 public string KeyString { get; set; }
17 public string DefaultKeyString { get; private set; }
18 public bool IsOSKey { get; private set; }
19
20 public KeyBinding (string description, string keyString, EventCallback eventFunc) : this (description, keyString, eventFunc, false)
21 {
22 }
23
24 public KeyBinding (string description, string keyString, EventCallback eventFunc, bool isoskey)
25 {
26 this.Description = description;
27 this.KeyString = keyString;
28 this.DefaultKeyString = keyString;
29 this.Callback = eventFunc;
30 this.IsOSKey = isoskey;
31 }
32 }
33}
0\ No newline at end of file34\ No newline at end of file
135
=== modified file 'Do.Platform/src/Do.Platform/Services.cs'
--- Do.Platform/src/Do.Platform/Services.cs 2009-06-26 11:01:40 +0000
+++ Do.Platform/src/Do.Platform/Services.cs 2009-07-22 01:12:59 +0000
@@ -38,6 +38,7 @@
38 static INetworkService network;38 static INetworkService network;
39 static IWindowingService windowing;39 static IWindowingService windowing;
40 static AbstractSystemService system;40 static AbstractSystemService system;
41 static IKeyBindingService keybinder;
41 static IEnumerable<ILogService> logs;42 static IEnumerable<ILogService> logs;
42 static PreferencesFactory preferences;43 static PreferencesFactory preferences;
43 static IEnvironmentService environment;44 static IEnvironmentService environment;
@@ -198,6 +199,7 @@
198 return package_manager;199 return package_manager;
199 }200 }
200 }201 }
202
201 public static IPluginManagerService PluginManager {203 public static IPluginManagerService PluginManager {
202 get {204 get {
203 if (plugin_manager == null)205 if (plugin_manager == null)
@@ -205,6 +207,14 @@
205 return plugin_manager;207 return plugin_manager;
206 }208 }
207 }209 }
210
211 public static IKeyBindingService Keybinder {
212 get {
213 if (keybinder == null)
214 keybinder = LocateService<IKeyBindingService, Default.KeyBindingService> ();
215 return keybinder;
216 }
217 }
208218
209 public static PreferencesFactory Preferences {219 public static PreferencesFactory Preferences {
210220
211221
=== removed file 'Do/Do.exe.config.in'
--- Do/Do.exe.config.in 2008-04-27 01:12:26 +0000
+++ Do/Do.exe.config.in 1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
1<configuration>
2 <dllmap dll="libc" target="libc.so.6"/>
3 <dllmap dll="libdo" target="@expanded_libdir@/@PACKAGE@/libdo.so"/>
4</configuration>
50
=== modified file 'Do/Makefile.am'
--- Do/Makefile.am 2009-06-26 11:01:40 +0000
+++ Do/Makefile.am 2009-07-23 09:29:41 +0000
@@ -16,7 +16,6 @@
16 gtk-gui/generated.cs \16 gtk-gui/generated.cs \
17 src/AssemblyInfo.cs \17 src/AssemblyInfo.cs \
18 src/CorePreferences.cs \18 src/CorePreferences.cs \
19 src/CoreKeybindings.cs \
20 src/Do.Core/Do.Core.Addins/AddinClassifier.cs \19 src/Do.Core/Do.Core.Addins/AddinClassifier.cs \
21 src/Do.Core/Do.Core.Addins/CommunityAddinClassifier.cs \20 src/Do.Core/Do.Core.Addins/CommunityAddinClassifier.cs \
22 src/Do.Core/Do.Core.Addins/GreedyAddinClassifier.cs \21 src/Do.Core/Do.Core.Addins/GreedyAddinClassifier.cs \
@@ -73,8 +72,7 @@
73 src/Mono.Addins/AddinExtensions.cs \72 src/Mono.Addins/AddinExtensions.cs \
74 src/Mono.Addins/Mono.Addins.Setup/AddinRepositoryEntryExtensions.cs \73 src/Mono.Addins/Mono.Addins.Setup/AddinRepositoryEntryExtensions.cs \
75 src/PathExtensions.cs \74 src/PathExtensions.cs \
76 src/Util.cs \75 src/Util.cs
77 src/XKeybinder.cs
7876
79RESOURCES = \77RESOURCES = \
80 gtk-gui/gui.stetic \78 gtk-gui/gui.stetic \
@@ -103,10 +101,10 @@
103# Extra rules for our binary, not worth factoring out101# Extra rules for our binary, not worth factoring out
104#102#
105103
106CLEANFILES += Do.exe.config gnome-do104CLEANFILES += gnome-do
107EXTRA_DIST += Do.exe.config.in gnome-do.in Do.addins105EXTRA_DIST += gnome-do.in Do.addins
108106
109module_DATA += Do.exe.config Do.addins107module_DATA += Do.addins
110bin_SCRIPTS = gnome-do108bin_SCRIPTS = gnome-do
111109
112MCS_FLAGS += -unsafe110MCS_FLAGS += -unsafe
113111
=== modified file 'Do/gtk-gui/gui.stetic'
--- Do/gtk-gui/gui.stetic 2009-06-26 11:01:40 +0000
+++ Do/gtk-gui/gui.stetic 2009-07-23 07:17:00 +0000
@@ -5,9 +5,6 @@
5 <target-gtk-version>2.12</target-gtk-version>5 <target-gtk-version>2.12</target-gtk-version>
6 </configuration>6 </configuration>
7 <import>7 <import>
8 <widget-library name="../../Do.Platform.Linux/bin/Debug/Do.Platform.Linux.dll" />
9 <widget-library name="../../Do.Interface.Linux/bin/Debug/Do.Interface.Linux.dll" />
10 <widget-library name="../../Do.Interface.Linux.AnimationBase/bin/Debug/Do.Interface.Linux.AnimationBase.dll" />
11 <widget-library name="Mono.Addins.Gui, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />8 <widget-library name="Mono.Addins.Gui, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
12 <widget-library name="../bin/Debug/Do.exe" internal="true" />9 <widget-library name="../bin/Debug/Do.exe" internal="true" />
13 </import>10 </import>
@@ -136,6 +133,7 @@
136 <property name="Position">0</property>133 <property name="Position">0</property>
137 <property name="AutoSize">False</property>134 <property name="AutoSize">False</property>
138 <property name="Expand">False</property>135 <property name="Expand">False</property>
136 <property name="Fill">False</property>
139 </packing>137 </packing>
140 </child>138 </child>
141 <child>139 <child>
@@ -143,7 +141,8 @@
143 <property name="MemberName" />141 <property name="MemberName" />
144 <property name="Ypad">1</property>142 <property name="Ypad">1</property>
145 <property name="Xalign">0</property>143 <property name="Xalign">0</property>
146 <property name="LabelProp" translatable="yes">To edit a shortcut, double-click it and type a new one.</property>144 <property name="LabelProp" translatable="yes">To edit a shortcut, double-click it and type a new one.
145To restore a shortcut to the default, double click and press Backspace.</property>
147 <property name="Wrap">True</property>146 <property name="Wrap">True</property>
148 </widget>147 </widget>
149 <packing>148 <packing>
150149
=== removed file 'Do/src/CoreKeybindings.cs'
--- Do/src/CoreKeybindings.cs 2009-03-28 23:09:02 +0000
+++ Do/src/CoreKeybindings.cs 1970-01-01 00:00:00 +0000
@@ -1,230 +0,0 @@
1
2/* Keybindings.cs
3 *
4 * GNOME Do is the legal property of its developers. Please refer to the
5 * COPYRIGHT file distributed with this
6 * source distribution.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22using System;
23using System.Linq;
24using System.Collections;
25using System.Collections.Generic;
26using Env = System.Environment;
27
28using Do.Platform;
29
30namespace Do
31{
32
33 class CoreKeybindings
34 {
35 Dictionary<string, string> KeycodeMap ; // keybinding -> shortcut name
36 Dictionary<string, Shortcut> ShortcutMap ; // shortcut name -> shortcut
37 Dictionary<string, string> DefaultShortcutMap ; // default keybinding -> shortcut name
38
39 IPreferences Preferences { get; set; }
40
41 public ArrayList Shortcuts ;
42 public Dictionary<string, List<KeyChangedCb>> PreferencesCbs;
43 public delegate void KeyChangedCb (object sender, PreferencesChangedEventArgs e);
44
45 public CoreKeybindings ()
46 {
47
48 Preferences = Services.Preferences.Get<CoreKeybindings> ();
49 Preferences.PreferencesChanged += PreferencesChanged;
50
51 Shortcuts = new ArrayList ();
52 KeycodeMap = new Dictionary<string, string> (); // keybinding -> shortcut name
53 ShortcutMap = new Dictionary<string, Shortcut> (); // shortcut name -> shortcut
54 DefaultShortcutMap = new Dictionary<string, string> (); // default keybinding -> shortcut name
55 PreferencesCbs = new Dictionary<string, List<KeyChangedCb>> ();
56
57 Initialize ();
58 }
59
60 public void Initialize ()
61 {
62 // Read all values out of preferences and populate the KeybindingMap
63 ReadShortcuts ();
64 }
65
66 public bool RegisterShortcut (Shortcut sc, string defaultBinding)
67 {
68 if (!RegisterShortcut (sc))
69 return false;
70 if (!BindDefault (sc, defaultBinding))
71 return false;
72 return true;
73 }
74
75 public bool RegisterShortcut (Shortcut sc)
76 {
77 if (Shortcuts.Contains (sc) || ShortcutMap.ContainsKey (sc.ShortcutName))
78 return false;
79
80 Shortcuts.Add (sc);
81 ShortcutMap [sc.ShortcutName] = sc;
82 PreferencesCbs [sc.ShortcutName] = new List<KeyChangedCb> ();
83 SaveShortcuts ();
84 return true;
85 }
86
87 public Shortcut GetShortcutByKeycode (string keycode)
88 {
89 if (!KeycodeMap.ContainsKey (keycode))
90 return null;
91
92 string scname = KeycodeMap [keycode];
93
94 if (!ShortcutMap.ContainsKey (scname))
95 return null;
96
97 return ShortcutMap [scname];
98
99 }
100
101 public string GetKeybinding (Shortcut sc)
102 {
103 return GetKeybinding (sc.ShortcutName);
104 }
105
106 public string GetKeybinding (string sc)
107 {
108
109 foreach (KeyValuePair<string, string> entry in KeycodeMap) {
110 if (entry.Value == sc)
111 return entry.Key;
112 }
113 return null;
114 }
115
116 public string GetDefaultKeybinding (Shortcut sc)
117 {
118 return GetDefaultKeybinding (sc.ShortcutName);
119 }
120
121 public string GetDefaultKeybinding (string sc)
122 {
123 foreach (KeyValuePair<string, string> entry in DefaultShortcutMap) {
124 if (entry.Value == sc)
125 return entry.Key;
126 }
127 return null;
128 }
129
130
131 public bool BindShortcut (Shortcut sc, string keycode)
132 {
133 // Add this function to our keybinding map
134 return BindShortcut (sc.ShortcutName, keycode);
135
136 }
137
138 public bool BindShortcut (string sc, string keycode)
139 {
140 string oldcode = GetKeybinding (sc);
141 if (oldcode != null)
142 KeycodeMap.Remove (oldcode); // remove the old keybinding from the map
143
144 KeycodeMap [keycode] = sc;
145 Preferences.Set (sc, keycode);
146
147 return true;
148 }
149
150 // Add Default Keycode mapping - used for resetting to default or not overwriting read values
151 public bool BindDefault (Shortcut sc, string keycode)
152 {
153 return BindDefault (sc.ShortcutName, keycode);
154
155 }
156
157 public bool BindDefault (string sc, string keycode)
158 {
159
160 string assigned_keycode = GetKeybinding (sc);
161 if (assigned_keycode == null) {
162 // Put this shortcut in the mapping
163 BindShortcut (sc, keycode);
164 }
165
166 DefaultShortcutMap [keycode] = sc;
167 return true;
168
169 }
170
171 public bool UnregisterShortcut (Shortcut sc)
172 {
173 if (!Shortcuts.Contains (sc))
174 return false;
175
176 Shortcuts.Remove (sc);
177 ShortcutMap.Remove (sc.ShortcutName);
178 SaveShortcuts ();
179 return true;
180 }
181
182 public bool RegisterNotification (Shortcut sc, KeyChangedCb cb)
183 {
184 return RegisterNotification (sc.ShortcutName, cb);
185 }
186
187 public bool RegisterNotification (string scname, KeyChangedCb cb)
188 {
189 PreferencesCbs [scname].Add (cb);
190 return true;
191 }
192
193 void SaveShortcuts ()
194 {
195 string scstring = "";
196 foreach (Shortcut sc in Shortcuts) {
197 scstring += sc.ShortcutName.Trim () + ",";
198 }
199 Preferences.Set ("RegisteredShortcuts", scstring);
200 }
201
202 void ReadShortcuts ()
203 {
204 string scstring = Preferences.Get ("RegisteredShortcuts", "").Trim ();
205 if (scstring == "")
206 return;
207
208 foreach (string sc in scstring.Split (',')) {
209 if (sc.Trim () == "")
210 continue;
211
212 string keycode = Preferences.Get (sc, "");
213 if (keycode != "")
214 BindShortcut (sc, keycode);
215 }
216 }
217
218 void PreferencesChanged (object sender, PreferencesChangedEventArgs e)
219 {
220
221 if (PreferencesCbs.ContainsKey (e.Key)) {
222 foreach (KeyChangedCb cb in PreferencesCbs [e.Key]) {
223 cb (this, e);
224 }
225 }
226 }
227
228 }
229
230}
2310
=== modified file 'Do/src/Do.Core/Controller.cs'
--- Do/src/Do.Core/Controller.cs 2009-06-24 01:42:21 +0000
+++ Do/src/Do.Core/Controller.cs 2009-07-23 09:14:01 +0000
@@ -30,6 +30,7 @@
30using Do.UI;30using Do.UI;
31using Do.Universe;31using Do.Universe;
32using Do.Platform;32using Do.Platform;
33using Do.Platform.Common;
33using Do.Interface;34using Do.Interface;
3435
35namespace Do.Core36namespace Do.Core
@@ -108,96 +109,37 @@
108 Screen.Default.CompositedChanged += OnCompositingChanged;109 Screen.Default.CompositedChanged += OnCompositingChanged;
109 110
110 // Register Shortcuts111 // Register Shortcuts
111 // TODO: Localize the text here.112 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Enter Text Mode"), "period",
112 // Previous shortcuts113 OnTextModePressEvent));
113 Do.Keybindings.RegisterShortcut (114 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Copy to Clipboard"), "<Control>c",
114 new Shortcut ("SummonKey", 115 OnCopyEvent));
115 Catalog.GetString ("Summon GNOME Do"), 116 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Paste Current Text"), "<Control>v",
116 OnSummonKeyPressEvent),117 OnPasteEvent));
117 "<Super>space");118 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Previous Pane"), "<Shift>Tab",
118 Do.Keybindings.RegisterShortcut (119 OnPreviousPanePressEvent));
119 new Shortcut ("TextModeKey",120 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Next Pane"), "Tab",
120 Catalog.GetString ("Enter text mode"),121 OnNextPanePressEvent));
121 OnTextModePressEvent),122 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Previous Item"), "Up",
122 "period");123 OnUpKeyPressEvent));
123 // New shortcuts124 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Next Item"), "Down",
124 Do.Keybindings.RegisterShortcut (125 OnDownKeyPressEvent));
125 new Shortcut ("CopyKey",126 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("First Item"), "Home",
126 Catalog.GetString ("Copy Text"),127 OnHomeKeyPressEvent));
127 OnCopyEvent),128 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Last Item"), "End",
128 "<Control>c");129 OnEndKeyPressEvent));
129 Do.Keybindings.RegisterShortcut (130 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Previous 5 Results"), "Page_Up",
130 new Shortcut ("PasteKey",131 OnPageUpKeyPressEvent));
131 Catalog.GetString ("Paste Text"),132 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Next 5 Results"), "Page_Down",
132 OnPasteEvent),133 OnPageDownKeyPressEvent));
133 "<Control>v");134 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Step Out of Item"), "Left",
134 Do.Keybindings.RegisterShortcut (135 OnLeftKeyPressEvent));
135 new Shortcut ("AlternateEscapeKey",136 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Browse Into Item"), "Right",
136 Catalog.GetString ("Alternate Escape"),137 OnRightKeyPressEvent));
137 OnEscapeKeyPressEvent));138 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Select Multiple Items"), "comma",
138 Do.Keybindings.RegisterShortcut (139 OnSelectionKeyPressEvent));
139 new Shortcut ("AlternateActivateKey",140 //summon in text mode
140 Catalog.GetString ("Alternate Activate"),141 Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Summon in Text Mode"), "<Super>period",
141 OnActivateKeyPressEvent));142 delegate { this.Summon (); SearchController.TextMode = true; UpdatePane (CurrentPane); } , true));
142 Do.Keybindings.RegisterShortcut (
143 new Shortcut ("AlternateDeleteKey",
144 Catalog.GetString ("Alternate Delete"),
145 OnDeleteKeyPressEvent));
146 Do.Keybindings.RegisterShortcut (
147 new Shortcut ("ShiftTabKey",
148 Catalog.GetString ("Previous Pane"),
149 OnShiftTabKeyPressEvent),
150 "ISO_Left_Tab");
151 Do.Keybindings.RegisterShortcut (
152 new Shortcut ("TabKey",
153 Catalog.GetString ("Next Pane"),
154 OnTabKeyPressEvent),
155 "Tab");
156 Do.Keybindings.RegisterShortcut (
157 new Shortcut ("UpKey",
158 Catalog.GetString ("Previous Result"),
159 OnUpKeyPressEvent),
160 "Up");
161 Do.Keybindings.RegisterShortcut (
162 new Shortcut ("DownKey",
163 Catalog.GetString ("Next Result"),
164 OnDownKeyPressEvent),
165 "Down");
166 Do.Keybindings.RegisterShortcut (
167 new Shortcut ("HomeKey",
168 Catalog.GetString ("First Result"),
169 OnHomeKeyPressEvent),
170 "Home");
171 Do.Keybindings.RegisterShortcut (
172 new Shortcut ("EndKey",
173 Catalog.GetString ("Last Result"),
174 OnEndKeyPressEvent),
175 "End");
176 Do.Keybindings.RegisterShortcut (
177 new Shortcut ("PageUpKey",
178 Catalog.GetString ("Previous 5 Results"),
179 OnPageUpKeyPressEvent),
180 "Page_Up");
181 Do.Keybindings.RegisterShortcut (
182 new Shortcut ("PageDownKey",
183 Catalog.GetString ("Next 5 Results"),
184 OnPageDownKeyPressEvent),
185 "Page_Down");
186 Do.Keybindings.RegisterShortcut (
187 new Shortcut ("LeftKey",
188 Catalog.GetString ("Step out of Item"),
189 OnLeftKeyPressEvent),
190 "Left");
191 Do.Keybindings.RegisterShortcut (
192 new Shortcut ("RightKey",
193 Catalog.GetString ("Browse Into Item"),
194 OnRightKeyPressEvent),
195 "Right");
196 Do.Keybindings.RegisterShortcut (
197 new Shortcut ("CommaKey",
198 Catalog.GetString ("Multiple selection"),
199 OnSelectionKeyPressEvent),
200 "comma");
201 }143 }
202144
203 void OnSummoned ()145 void OnSummoned ()
@@ -507,13 +449,10 @@
507 } else if (key == Key.Delete ||449 } else if (key == Key.Delete ||
508 key == Key.BackSpace) {450 key == Key.BackSpace) {
509 OnDeleteKeyPressEvent (evnt);451 OnDeleteKeyPressEvent (evnt);
510 } else {452 } else if (Services.Keybinder.Bindings.ContainsKey (KeyEventToString (evnt))) {
511 // User set keybindings453 // User set keybindings
512 Shortcut sc = Do.Keybindings.GetShortcutByKeycode (KeyEventToString (evnt));454 Services.Keybinder.Bindings [KeyEventToString (evnt)].Callback (evnt);
513 if (sc != null) {455 } else {
514 sc.Callback (evnt);
515 return;
516 }
517 OnInputKeyPressEvent (evnt);456 OnInputKeyPressEvent (evnt);
518 }457 }
519 }458 }
@@ -648,7 +587,7 @@
648 if (SearchController.ItemChildSearch ()) GrowResults ();587 if (SearchController.ItemChildSearch ()) GrowResults ();
649 }588 }
650589
651 void OnTabKeyPressEvent (EventKey evnt)590 void OnNextPanePressEvent (EventKey evnt)
652 {591 {
653 im_context.Reset ();592 im_context.Reset ();
654 ShrinkResults ();593 ShrinkResults ();
@@ -661,7 +600,7 @@
661 UpdatePane (CurrentPane);600 UpdatePane (CurrentPane);
662 }601 }
663602
664 void OnShiftTabKeyPressEvent (EventKey evnt)603 void OnPreviousPanePressEvent (EventKey evnt)
665 {604 {
666 im_context.Reset ();605 im_context.Reset ();
667 ShrinkResults ();606 ShrinkResults ();
@@ -760,7 +699,14 @@
760 if ((evnt.State & ModifierType.Mod1Mask) != 0) {699 if ((evnt.State & ModifierType.Mod1Mask) != 0) {
761 modifier += "<Alt>";700 modifier += "<Alt>";
762 }701 }
763 return modifier + evnt.Key.ToString ();702 if ((evnt.State & ModifierType.ShiftMask) != 0) {
703 modifier += "<Shift>";
704 //if we're pressing shift, and the key is ISO_Left_Tab,
705 //just make it Tab
706 if (evnt.Key == Key.ISO_Left_Tab)
707 return string.Format ("{0}{1}", modifier, Key.Tab);
708 }
709 return string.Format ("{0}{1}", modifier, evnt.Key.ToString ());
764 }710 }
765#endregion711#endregion
766 712
767713
=== modified file 'Do/src/Do.UI/KeybindingTreeView.cs'
--- Do/src/Do.UI/KeybindingTreeView.cs 2009-06-20 04:30:05 +0000
+++ Do/src/Do.UI/KeybindingTreeView.cs 2009-07-23 09:14:01 +0000
@@ -20,40 +20,41 @@
2020
2121
22using System;22using System;
23using System.Linq;
24
23using Gtk;25using Gtk;
24using Mono.Unix;26using Mono.Unix;
2527
28using Do.Platform;
29using Do.Platform.Common;
30
26namespace Do.UI31namespace Do.UI
27{32{
28 public class KeybindingTreeView : TreeView33 public class KeybindingTreeView : TreeView
29 {34 {
30 enum Column {35 enum Column {
31 Action = 0,36 Action = 0,
37 BoundKeyString,
38 DefaultKeybinding,
32 Binding,39 Binding,
33 DefaultKeybinding,
34 ShortcutName,
35 NumColumns40 NumColumns
36 }41 }
37 42
38 public KeybindingTreeView ()43 public KeybindingTreeView ()
39 { 44 {
40 Model = new ListStore (typeof (string), typeof (string), typeof (string), typeof (string));45 Model = new ListStore (typeof (string), typeof (string), typeof (string), typeof (KeyBinding));
41 46
42 CellRendererText actionCell = new CellRendererText ();47 CellRendererText actionCell = new CellRendererText ();
43 actionCell.Width = 150;48 actionCell.Width = 150;
44 InsertColumn (-1, Catalog.GetString ("Action"), actionCell, "text", (int)Column.Action);49 InsertColumn (-1, Catalog.GetString ("Action"), actionCell, "text", (int)Column.Action);
45 50
46 CellRendererAccel bindingCell = new CellRendererAccel ();51 CellRendererAccel bindingCell = new CellRendererAccel ();
47 bindingCell.AccelMode = CellRendererAccelMode.Gtk;52 bindingCell.AccelMode = CellRendererAccelMode.Other;
48 bindingCell.Editable = true;53 bindingCell.Editable = true;
49 bindingCell.AccelEdited += new AccelEditedHandler (OnAccelEdited);54 bindingCell.AccelEdited += new AccelEditedHandler (OnAccelEdited);
50 bindingCell.AccelCleared += new AccelClearedHandler (OnAccelCleared);55 bindingCell.AccelCleared += new AccelClearedHandler (OnAccelCleared);
51 InsertColumn (-1, Catalog.GetString ("Shortcut"), bindingCell, "text", (int)Column.Binding);56 InsertColumn (-1, Catalog.GetString ("Shortcut"), bindingCell, "text", (int)Column.BoundKeyString);
52 57
53 CellRendererText defaultbindingCell = new CellRendererText ();
54 actionCell.Width = 150;
55// InsertColumn (-1, Catalog.GetString ("Default Shortcut"), defaultbindingCell, "text", (int)Column.DefaultKeybinding);
56
57 RowActivated += new RowActivatedHandler (OnRowActivated);58 RowActivated += new RowActivatedHandler (OnRowActivated);
58 ButtonPressEvent += new ButtonPressEventHandler (OnButtonPress);59 ButtonPressEvent += new ButtonPressEventHandler (OnButtonPress);
59 60
@@ -66,9 +67,8 @@
66 ListStore store = Model as ListStore;67 ListStore store = Model as ListStore;
67 store.Clear ();68 store.Clear ();
6869
69 foreach (Shortcut sc in Do.Keybindings.Shortcuts) {70 foreach (KeyBinding binding in Services.Keybinder.Bindings.Values.OrderBy (k => k.Description)) {
70 store.AppendValues (sc.FriendlyName, Do.Keybindings.GetKeybinding (sc), 71 store.AppendValues (binding.Description, binding.KeyString, binding.DefaultKeyString, binding);
71 Do.Keybindings.GetDefaultKeybinding (sc), sc.ShortcutName);
72 }72 }
73 }73 }
74 74
@@ -81,21 +81,21 @@
81 81
82 if (GetPathAtPos ((int) args.Event.X, (int) args.Event.Y,out path)) {82 if (GetPathAtPos ((int) args.Event.X, (int) args.Event.Y,out path)) {
83 GrabFocus ();83 GrabFocus ();
84 SetCursor (path, GetColumn ((int) Column.Binding), true);84 SetCursor (path, GetColumn ((int) Column.BoundKeyString), true);
85 } 85 }
86 }86 }
87 87
88 private void OnRowActivated (object o, RowActivatedArgs args)88 private void OnRowActivated (object o, RowActivatedArgs args)
89 {89 {
90 GrabFocus ();90 GrabFocus ();
91 SetCursor (args.Path, GetColumn ((int) Column.Binding), true);91 SetCursor (args.Path, GetColumn ((int) Column.BoundKeyString), true);
92 }92 }
9393
94 private bool ClearPreviousBinding (TreeModel model, TreePath path, TreeIter treeiter, string keyBinding) 94 private bool ClearPreviousBinding (TreeModel model, TreePath path, TreeIter treeiter, string keyBinding)
95 {95 {
96 string binding = model.GetValue (treeiter, (int) Column.Binding) as string;96 string binding = model.GetValue (treeiter, (int) Column.BoundKeyString) as string;
97 if (binding == keyBinding) {97 if (binding == keyBinding) {
98 model.SetValue (treeiter, (int) Column.Binding, "");98 model.SetValue (treeiter, (int) Column.BoundKeyString, "");
99 }99 }
100 return false;100 return false;
101 }101 }
@@ -110,10 +110,18 @@
110 110
111 string realKey = Gtk.Accelerator.Name (args.AccelKey, args.AccelMods);111 string realKey = Gtk.Accelerator.Name (args.AccelKey, args.AccelMods);
112 112
113 if (args.AccelKey == (uint) Gdk.Key.Super_L) {
114 //setting CellRenderAccelMode to "Other" ignores the Super key as a modifier
115 //this prevents us from grabbing _only_ the Super key.
116 return;
117 }
118
119 Console.WriteLine ("key: {0}, mods: {1}", args.AccelKey, args.AccelMods);
120
113 // Look for any other rows that have the same binding and then zero that binding out121 // Look for any other rows that have the same binding and then zero that binding out
114 Model.Foreach ((model, path, treeiter) => ClearPreviousBinding (model, path, treeiter, realKey));122 Model.Foreach ((model, path, treeiter) => ClearPreviousBinding (model, path, treeiter, realKey));
115123
116 store.SetValue (iter, (int) Column.Binding, realKey);124 store.SetValue (iter, (int) Column.BoundKeyString, realKey);
117125
118 SaveBindings ();126 SaveBindings ();
119 }127 }
@@ -127,9 +135,9 @@
127 store.GetIter (out iter, new TreePath (args.PathString));135 store.GetIter (out iter, new TreePath (args.PathString));
128 try {136 try {
129 string defaultVal = store.GetValue (iter, (int) Column.DefaultKeybinding).ToString ();137 string defaultVal = store.GetValue (iter, (int) Column.DefaultKeybinding).ToString ();
130 store.SetValue (iter, (int) Column.Binding, defaultVal);138 store.SetValue (iter, (int) Column.BoundKeyString, defaultVal);
131 } catch (Exception e) {139 } catch (Exception e) {
132 store.SetValue (iter, (int) Column.Binding, "");140 store.SetValue (iter, (int) Column.BoundKeyString, "");
133 }141 }
134142
135 SaveBindings ();143 SaveBindings ();
@@ -142,12 +150,17 @@
142 150
143 private bool SaveBindingsForeachFunc (TreeModel model, TreePath path, TreeIter iter)151 private bool SaveBindingsForeachFunc (TreeModel model, TreePath path, TreeIter iter)
144 {152 {
145 string binding, shortcutname;153 string newKeyString = model.GetValue (iter, (int) Column.BoundKeyString) as string;
146 binding = model.GetValue (iter, (int) Column.Binding) as string;154 KeyBinding binding = model.GetValue (iter, (int) Column.Binding) as KeyBinding;
147 shortcutname = model.GetValue (iter, (int) Column.ShortcutName) as string;155
148 156 if (newKeyString != null) {
149 if (binding != null && binding != "DISABLED" && binding != Do.Keybindings.GetKeybinding (shortcutname))157 //try to save
150 Do.Keybindings.BindShortcut (shortcutname, binding);158 if (!Services.Keybinder.SetKeyString (binding, newKeyString)) {
159 //if we fail reset to the default value
160 model.SetValue (iter, (int) Column.BoundKeyString, binding.DefaultKeyString);
161 Services.Keybinder.SetKeyString (binding, binding.DefaultKeyString);
162 }
163 }
151 return false;164 return false;
152 }165 }
153 166
154167
=== modified file 'Do/src/Do.cs'
--- Do/src/Do.cs 2009-06-21 02:20:30 +0000
+++ Do/src/Do.cs 2009-07-23 09:29:41 +0000
@@ -27,18 +27,17 @@
27using Do.UI;27using Do.UI;
28using Do.Core;28using Do.Core;
29using Do.Platform;29using Do.Platform;
30using Do.Platform.Common;
3031
31namespace Do {32namespace Do {
3233
33 static class Do {34 static class Do {
34 35
35 static XKeybinder keybinder;
36 static Controller controller;36 static Controller controller;
37 static UniverseManager universe_manager;37 static UniverseManager universe_manager;
3838
39 public static CorePreferences Preferences { get; private set; } 39 public static CorePreferences Preferences { get; private set; }
40 public static CoreKeybindings Keybindings { get; private set; } 40
41
42 internal static void Main (string [] args)41 internal static void Main (string [] args)
43 {42 {
44 Catalog.Init ("gnome-do", AssemblyInfo.LocaleDirectory);43 Catalog.Init ("gnome-do", AssemblyInfo.LocaleDirectory);
@@ -55,8 +54,6 @@
5554
56 Preferences = new CorePreferences ();55 Preferences = new CorePreferences ();
5756
58 Keybindings = new CoreKeybindings ();
59
60 // Now we can set the preferred log level.57 // Now we can set the preferred log level.
61 if (Preferences.QuietStart)58 if (Preferences.QuietStart)
62 Log.DisplayLevel = LogLevel.Error;59 Log.DisplayLevel = LogLevel.Error;
@@ -73,12 +70,11 @@
73 Controller.Initialize ();70 Controller.Initialize ();
74 UniverseManager.Initialize ();71 UniverseManager.Initialize ();
75 72
76 keybinder = new XKeybinder ();
77 SetupKeybindings ();73 SetupKeybindings ();
7874
79 if (!Preferences.QuietStart)75 if (!Preferences.QuietStart)
80 Controller.Summon ();76 Controller.Summon ();
81 77
82 Gtk.Application.Run ();78 Gtk.Application.Run ();
83 79
84 RelevanceProvider.Serialize (RelevanceProvider.DefaultProvider);80 RelevanceProvider.Serialize (RelevanceProvider.DefaultProvider);
@@ -100,37 +96,17 @@
100 return universe_manager;96 return universe_manager;
101 }97 }
102 }98 }
103
104 static void SummonKeyCb (object sender, PreferencesChangedEventArgs e)
105 {
106 try {
107 if (e.OldValue != null)
108 keybinder.Unbind (e.OldValue as string);
109 keybinder.Bind (Keybindings.GetKeybinding ("SummonKey"), OnActivate);
110 } catch (Exception ex) {
111 Log.Error ("Could not bind summon key: {0}", ex.Message);
112 Log.Debug (ex.StackTrace);
113 }
114
115 }
116 99
117 static void SetupKeybindings ()100 static void SetupKeybindings ()
118 {101 {
119 try {102 try {
120 keybinder.Bind (Keybindings.GetKeybinding ("SummonKey"), OnActivate);103 if (!Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Summon Do"),
104 "<Super>space", delegate { controller.Summon (); }, true)))
105 throw new Exception ();
121 } catch (Exception e) {106 } catch (Exception e) {
122 Log.Error ("Could not bind summon key: {0}", e.Message);107 Log.Fatal ("Could not bind summon key!");
123 Log.Debug (e.StackTrace);108 Log.Debug (e.StackTrace);
124 }109 }
125
126 // Watch preferences for changes to the keybinding so we
127 // can change the binding when the user reassigns it.
128 Keybindings.RegisterNotification ("SummonKey", SummonKeyCb);
129 }
130
131 static void OnActivate (object sender, EventArgs e)
132 {
133 controller.Summon ();
134 }110 }
135 }111 }
136}112}
137113
=== removed file 'Do/src/XKeybinder.cs'
--- Do/src/XKeybinder.cs 2008-12-18 18:39:06 +0000
+++ Do/src/XKeybinder.cs 1970-01-01 00:00:00 +0000
@@ -1,103 +0,0 @@
1/*****************************************************************************/
2/* XKeybinder.cs - Keybinding code taken from Tomboy */
3/* Copyright (C) 2004-2007 Alex Graveley <alex@beatniksoftware.com> */
4/* */
5/* This library is free software; you can redistribute it and/or */
6/* modify it under the terms of the GNU Lesser General Public */
7/* License as published by the Free Software Foundation; either */
8/* version 2.1 of the License, or (at your option) any later version. */
9/* */
10/* This library is distributed in the hope that it will be useful, */
11/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
13/* Lesser General Public License for more details. */
14/* */
15/* You should have received a copy of the GNU Lesser General Public */
16/* License along with this library; if not, write to the Free Software */
17/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18/*****************************************************************************/
19
20using System;
21using System.Collections;
22using System.Runtime.InteropServices;
23using Mono.Unix;
24
25using Do.Platform;
26
27namespace Do
28{
29 public class XKeybinder
30 {
31 [DllImport("libdo")]
32 static extern void gnomedo_keybinder_init ();
33
34 [DllImport("libdo")]
35 static extern void gnomedo_keybinder_bind (string keystring, BindkeyHandler handler);
36
37 [DllImport("libdo")]
38 static extern void gnomedo_keybinder_unbind (string keystring, BindkeyHandler handler);
39
40 public delegate void BindkeyHandler (string key, IntPtr user_data);
41
42 ArrayList bindings;
43 BindkeyHandler key_handler;
44
45 struct Binding {
46 internal string keystring;
47 internal EventHandler handler;
48 }
49
50 public XKeybinder ()
51 : base ()
52 {
53 bindings = new ArrayList ();
54 key_handler = new BindkeyHandler (KeybindingPressed);
55
56 try {
57 gnomedo_keybinder_init ();
58 } catch (DllNotFoundException) {
59 Log.Error ("libdo not found - keybindings will not work.");
60 }
61 }
62
63 void KeybindingPressed (string keystring, IntPtr user_data)
64 {
65 foreach (Binding bind in bindings) {
66 if (bind.keystring == keystring) {
67 bind.handler (this, new EventArgs ());
68 }
69 }
70 }
71
72 public void Bind (string keystring, EventHandler handler)
73 {
74 Binding bind = new Binding ();
75 bind.keystring = keystring;
76 bind.handler = handler;
77 bindings.Add (bind);
78
79 gnomedo_keybinder_bind (bind.keystring, key_handler);
80 }
81
82 public void Unbind (string keystring)
83 {
84 foreach (Binding bind in bindings) {
85 if (bind.keystring == keystring) {
86 gnomedo_keybinder_unbind (bind.keystring, key_handler);
87
88 bindings.Remove (bind);
89 break;
90 }
91 }
92 }
93
94 public virtual void UnbindAll ()
95 {
96 foreach (Binding bind in bindings) {
97 gnomedo_keybinder_unbind (bind.keystring, key_handler);
98 }
99
100 bindings.Clear ();
101 }
102 }
103}
1040
=== modified file 'configure.ac'
--- configure.ac 2009-07-08 09:33:18 +0000
+++ configure.ac 2009-07-23 09:14:01 +0000
@@ -134,7 +134,6 @@
134134
135AC_CONFIG_FILES([135AC_CONFIG_FILES([
136BundledLibraries/Makefile136BundledLibraries/Makefile
137Do/Do.exe.config
138Do/Makefile137Do/Makefile
139Do/gnome-do138Do/gnome-do
140Do/src/AssemblyInfo.cs139Do/src/AssemblyInfo.cs
@@ -152,6 +151,7 @@
152Do.Platform/Makefile151Do.Platform/Makefile
153Do.Platform/src/AssemblyInfo.cs152Do.Platform/src/AssemblyInfo.cs
154Do.Platform.Linux/Makefile153Do.Platform.Linux/Makefile
154Do.Platform.Linux/Do.Platform.Linux.dll.config
155Do.Platform.Linux/src/AssemblyInfo.cs155Do.Platform.Linux/src/AssemblyInfo.cs
156Do.Platform.Linux.JoliCloud/Makefile156Do.Platform.Linux.JoliCloud/Makefile
157Do.Platform.Linux.JoliCloud/src/AssemblyInfo.cs157Do.Platform.Linux.JoliCloud/src/AssemblyInfo.cs
@@ -201,4 +201,4 @@
201 Release Build: ${enable_release}201 Release Build: ${enable_release}
202 NUnit: ${have_nunit}202 NUnit: ${have_nunit}
203203
204EOF
205\ No newline at end of file204\ No newline at end of file
205EOF
206206
=== modified file 'libdo/keybinder.c'
--- libdo/keybinder.c 2008-02-18 14:40:44 +0000
+++ libdo/keybinder.c 2009-07-23 07:17:00 +0000
@@ -257,7 +257,7 @@
257 NULL);257 NULL);
258}258}
259259
260void 260gboolean
261gnomedo_keybinder_bind (const char *keystring,261gnomedo_keybinder_bind (const char *keystring,
262 GnomeDoBindkeyHandler handler,262 GnomeDoBindkeyHandler handler,
263 gpointer user_data)263 gpointer user_data)
@@ -279,9 +279,11 @@
279 g_free (binding->keystring);279 g_free (binding->keystring);
280 g_free (binding);280 g_free (binding);
281 }281 }
282
283 return success;
282}284}
283285
284void286gboolean
285gnomedo_keybinder_unbind (const char *keystring, 287gnomedo_keybinder_unbind (const char *keystring,
286 GnomeDoBindkeyHandler handler)288 GnomeDoBindkeyHandler handler)
287{289{
@@ -302,6 +304,8 @@
302 g_free (binding);304 g_free (binding);
303 break;305 break;
304 }306 }
307
308 return TRUE;
305}309}
306310
307/* 311/*
308312
=== modified file 'libdo/keybinder.h'
--- libdo/keybinder.h 2008-02-18 14:40:44 +0000
+++ libdo/keybinder.h 2009-07-23 07:17:00 +0000
@@ -32,11 +32,11 @@
3232
33void gnomedo_keybinder_init (void);33void gnomedo_keybinder_init (void);
3434
35void gnomedo_keybinder_bind (const char *keystring,35gboolean gnomedo_keybinder_bind (const char *keystring,
36 GnomeDoBindkeyHandler handler,36 GnomeDoBindkeyHandler handler,
37 gpointer user_data);37 gpointer user_data);
3838
39void gnomedo_keybinder_unbind (const char *keystring,39gboolean gnomedo_keybinder_unbind (const char *keystring,
40 GnomeDoBindkeyHandler handler);40 GnomeDoBindkeyHandler handler);
4141
42gboolean gnomedo_keybinder_is_modifier (guint keycode);42gboolean gnomedo_keybinder_is_modifier (guint keycode);