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 ("Error Adding global keybinding:");
106 Logger
.Log
.Error (e
);
110 public override void UnbindAll ()
115 } catch (Exception e
) {
116 Logger
.Log
.Error ("Error Removing global keybinding:");
117 Logger
.Log
.Error (e
);
123 public string gconf_path
;
124 public string key_sequence
;
125 EventHandler handler
;
126 GConfXKeybinder parent
;
128 public Binding (string gconf_path
,
129 string default_binding
,
130 EventHandler handler
,
131 GConfXKeybinder parent
)
133 this.gconf_path
= gconf_path
;
134 this.key_sequence
= default_binding
;
135 this.handler
= handler
;
136 this.parent
= parent
;
139 key_sequence
= (string) parent
.client
.Get (gconf_path
);
140 } catch (Exception e
) {
141 Logger
.Log
.Warn ("GConf key '{0}' does not exist, using default.",
147 parent
.client
.AddNotify (
149 new GConf
.NotifyEventHandler (BindingChanged
));
152 void BindingChanged (object sender
, GConf
.NotifyEventArgs args
)
154 if (args
.Key
== gconf_path
) {
155 Logger
.Log
.Debug ("Binding for '{0}' changed to '{1}'!",
161 key_sequence
= (string) args
.Value
;
166 public void SetBinding ()
168 if (key_sequence
== null ||
169 key_sequence
== String
.Empty
||
170 key_sequence
== "disabled")
173 Logger
.Log
.Debug ("Binding key '{0}' for '{1}'",
177 parent
.Bind (key_sequence
, handler
);
180 public void UnsetBinding ()
182 if (key_sequence
== null)
185 Logger
.Log
.Debug ("Unbinding key '{0}' for '{1}'",
189 parent
.Unbind (key_sequence
);