[Tkabber-dev] r1963 - in trunk/tkabber-plugins: . unixkeys

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Nov 17 03:39:38 MSK 2010


Author: kostix
Date: 2010-11-17 03:39:38 +0300 (Wed, 17 Nov 2010)
New Revision: 1963

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/unixkeys/unixkeys.tcl
Log:
Make unixkeys plugin dynamically loadable

Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2010-11-16 01:42:04 UTC (rev 1962)
+++ trunk/tkabber-plugins/ChangeLog	2010-11-17 00:39:38 UTC (rev 1963)
@@ -1,3 +1,7 @@
+2010-11-17  Konstantin Khomoutov <flatworm at users.sourceforge.net>
+
+	* unixkeys/unixkeys.tcl: Make unixkeys plugin dynamically loadable.
+
 2010-11-16  Konstantin Khomoutov <flatworm at users.sourceforge.net>
 
 	* stripes/stripes.tcl: Make stripes plugin dynamically loadable,

Modified: trunk/tkabber-plugins/unixkeys/unixkeys.tcl
===================================================================
--- trunk/tkabber-plugins/unixkeys/unixkeys.tcl	2010-11-16 01:42:04 UTC (rev 1962)
+++ trunk/tkabber-plugins/unixkeys/unixkeys.tcl	2010-11-17 00:39:38 UTC (rev 1963)
@@ -8,52 +8,102 @@
 # See README for usage guidelines.
 # See license.terms for details on usage and distribution.
 
+package require msgcat
+
 namespace eval unixkeys {
-    proc BindEntry {event script} {
-	bind Entry   $event $script
-	bind BwEntry $event $script
+    ::msgcat::mcload [file join [file dirname [info script]] msgs]
+
+    if {![::plugins::is_registered unixkeys]} {
+        ::plugins::register unixkeys \
+            -namespace [namespace current] \
+            -source [info script] \
+            -description [::msgcat::mc \
+		"Whether the Unixkeys plugin is loaded."]\n[::msgcat::mc \
+		"This plugin makes the widgets providing textual input\
+		    support certain combinations of keystrokes\
+		    familiar to the users of Readline and Emacs."] \
+            -loadcommand [namespace code load] \
+            -unloadcommand [namespace code unload]
+        return
     }
+}
 
+proc unixkeys::load {} {
     foreach mod {Alt Meta} {
-	bind Text <$mod-Key-a> [bind Text <Control-Key-Home>]
-	bind Text <$mod-Key-e> [bind Text <Control-Key-End>]
+	Bind Text <$mod-Key-a> [bind Text <Control-Key-Home>]
+	Bind Text <$mod-Key-e> [bind Text <Control-Key-End>]
 	BindEntry <$mod-Key-a> [bind Entry <Key-Home>]
 	BindEntry <$mod-Key-e> [bind Entry <Key-End>]
     }
 
     foreach mod {Alt Meta} {
-	bind Text <$mod-Key-b> [bind Text <Control-Key-Left>]
-	bind Text <$mod-Key-f> [bind Text <Control-Key-Right>]
+	Bind Text <$mod-Key-b> [bind Text <Control-Key-Left>]
+	Bind Text <$mod-Key-f> [bind Text <Control-Key-Right>]
     }
     BindEntry <Alt-Key-b> [bind Entry <Meta-Key-b>]
     BindEntry <Alt-Key-f> [bind Entry <Meta-Key-f>]
 
-    bind Text  <Control-Key-u> { %W delete {insert linestart} insert}
+    Bind Text  <Control-Key-u> { %W delete {insert linestart} insert}
     BindEntry <Control-Key-u>  { %W delete 0 insert }
 
     foreach {mod key} {Alt BackSpace Control w} {
-	bind Text  <$mod-Key-$key> { %W delete [tk::TextPrevPos %W insert tcl_startOfPreviousWord] insert }
+	Bind Text  <$mod-Key-$key> { %W delete [tk::TextPrevPos %W insert tcl_startOfPreviousWord] insert }
 	BindEntry <$mod-Key-$key>  { %W delete [tk::EntryPreviousWord %W insert] insert }
     }
 
     foreach key {d Delete} {
 	foreach mod {Alt Meta} {
-	    bind Text  <$mod-Key-$key> { %W delete insert [::tk::TextNextPos %W insert tcl_endOfWord] }
+	    Bind Text  <$mod-Key-$key> { %W delete insert [::tk::TextNextPos %W insert tcl_endOfWord] }
 	    BindEntry <$mod-Key-$key>  { %W delete insert [::tk::EntryNextWord %W insert] }
 	}
     }
 
     if {[string equal $::tcl_platform(os) windows]} {
-	event add <<Undo>> <Control-Key-underscore>
+	AddEvent <<Undo>> <Control-Key-underscore>
     }
-    event add <<Undo>> <Control-Key-x><Control-Key-u>
+    AddEvent <<Undo>> <Control-Key-x><Control-Key-u>
 
-    bind Text <Control-slash>     { %W tag add sel 1.0 end }
-    bind Text <Control-backslash> { %W tag remove sel 1.0 end }
-    bind Text <Control-Key-x><h>  { %W tag add sel 1.0 end }
+    Bind Text <Control-slash>     { %W tag add sel 1.0 end }
+    Bind Text <Control-backslash> { %W tag remove sel 1.0 end }
+    Bind Text <Control-Key-x><h>  { %W tag add sel 1.0 end }
     BindEntry <Control-Key-x><h>  [bind Entry <Control-slash>]
 }
 
-namespace delete unixkeys
+proc unixkeys::Bind {target event script} {
+    set existing [bind $target $event]
+    bind $target $event $script
 
+    variable bindtable
+    lappend bindtable $target $event $script $existing
+}
+
+proc unixkeys::BindEntry {event script} {
+    Bind Entry   $event $script
+    Bind BwEntry $event $script
+}
+
+proc unixkeys::AddEvent {name event} {
+    event add $name $event
+
+    variable evtable
+    lappend evtable $name $event
+}
+
+proc unixkeys::unload {} {
+    variable bindtable
+    foreach {target event installed original} $bindtable {
+	set existing [bind $target $event]
+	if {[string equal $existing $installed]} {
+	    bind $target $event $original
+	}
+    }
+    unset bindtable
+
+    variable evtable
+    foreach {name event} $evtable {
+	event delete $name $event
+    }
+    unset evtable
+}
+
 # vim:ts=8:sw=4:sts=4:noet



More information about the Tkabber-dev mailing list