3 using System
.Collections
;
4 using System
.Runtime
.InteropServices
;
8 public class XKeybinder
10 [DllImport("libbeagleuiglue")]
11 static extern void tomboy_keybinder_init ();
13 [DllImport("libbeagleuiglue")]
14 static extern void tomboy_keybinder_bind (string keystring
,
15 BindkeyHandler handler
);
17 [DllImport("libbeagleuiglue")]
18 static extern void tomboy_keybinder_unbind (string keystring
,
19 BindkeyHandler handler
);
21 public delegate void BindkeyHandler (string key
, IntPtr user_data
);
24 BindkeyHandler key_handler
;
27 internal string keystring
;
28 internal EventHandler handler
;
34 bindings
= new ArrayList ();
35 key_handler
= new BindkeyHandler (KeybindingPressed
);
37 tomboy_keybinder_init ();
40 void KeybindingPressed (string keystring
, IntPtr user_data
)
42 foreach (Binding bind
in bindings
) {
43 if (bind
.keystring
== keystring
) {
44 bind
.handler (this, new EventArgs ());
49 public void Bind (string keystring
,
52 Binding bind
= new Binding ();
53 bind
.keystring
= keystring
;
54 bind
.handler
= handler
;
57 tomboy_keybinder_bind (bind
.keystring
, key_handler
);
60 public void Unbind (string keystring
)
62 foreach (Binding bind
in bindings
) {
63 if (bind
.keystring
== keystring
) {
64 tomboy_keybinder_unbind (bind
.keystring
,
67 bindings
.Remove (bind
);
73 public virtual void UnbindAll ()
75 foreach (Binding bind
in bindings
) {
76 tomboy_keybinder_unbind (bind
.keystring
, key_handler
);
83 public class GConfXKeybinder
: XKeybinder
88 public GConfXKeybinder ()
90 client
= new GConf
.Client ();
91 bindings
= new ArrayList ();
94 public void Bind (string gconf_path
,
95 string default_binding
,
99 Binding binding
= new Binding (gconf_path
,
103 bindings
.Add (binding
);
104 } catch (Exception e
) {
105 Logger
.Log
.Error (e
, "Error Adding global keybinding:");
109 public override void UnbindAll ()
114 } catch (Exception e
) {
115 Logger
.Log
.Error (e
, "Error Removing global keybinding:");
121 public string gconf_path
;
122 public string key_sequence
;
123 EventHandler handler
;
124 GConfXKeybinder parent
;
126 public Binding (string gconf_path
,
127 string default_binding
,
128 EventHandler handler
,
129 GConfXKeybinder parent
)
131 this.gconf_path
= gconf_path
;
132 this.key_sequence
= default_binding
;
133 this.handler
= handler
;
134 this.parent
= parent
;
137 key_sequence
= (string) parent
.client
.Get (gconf_path
);
138 } catch (Exception e
) {
139 Logger
.Log
.Warn ("GConf key '{0}' does not exist, using default.",
145 parent
.client
.AddNotify (
147 new GConf
.NotifyEventHandler (BindingChanged
));
150 void BindingChanged (object sender
, GConf
.NotifyEventArgs args
)
152 if (args
.Key
== gconf_path
) {
153 Logger
.Log
.Debug ("Binding for '{0}' changed to '{1}'!",
159 key_sequence
= (string) args
.Value
;
164 public void SetBinding ()
166 if (key_sequence
== null ||
167 key_sequence
== String
.Empty
||
168 key_sequence
== "disabled")
171 Logger
.Log
.Debug ("Binding key '{0}' for '{1}'",
175 parent
.Bind (key_sequence
, handler
);
178 public void UnsetBinding ()
180 if (key_sequence
== null)
183 Logger
.Log
.Debug ("Unbinding key '{0}' for '{1}'",
187 parent
.Unbind (key_sequence
);