[Tkabber-dev] r1463 - in trunk/tkabber-plugins: . cyrillize

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Jun 18 15:29:12 MSD 2008


Author: sergei
Date: 2008-06-18 15:29:09 +0400 (Wed, 18 Jun 2008)
New Revision: 1463

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/cyrillize/cyrillize.tcl
Log:
	* cyrillize/cyrillize.tcl: Added cyrillize bindings to all text and
	  entry widgets.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2008-06-17 20:40:07 UTC (rev 1462)
+++ trunk/tkabber-plugins/ChangeLog	2008-06-18 11:29:09 UTC (rev 1463)
@@ -1,3 +1,8 @@
+2008-06-18  Sergei Golovan <sgolovan at nes.ru>
+
+	* cyrillize/cyrillize.tcl: Added cyrillize bindings to all text and
+	  entry widgets.
+
 2008-06-08  Sergei Golovan <sgolovan at nes.ru>
 
 	* unixkeys/README, unixkeys/TODO, unixkeys/unixkeys.tcl: Added

Modified: trunk/tkabber-plugins/cyrillize/cyrillize.tcl
===================================================================
--- trunk/tkabber-plugins/cyrillize/cyrillize.tcl	2008-06-17 20:40:07 UTC (rev 1462)
+++ trunk/tkabber-plugins/cyrillize/cyrillize.tcl	2008-06-18 11:29:09 UTC (rev 1463)
@@ -40,37 +40,65 @@
 
 #puts [cyrillize::do Ghbdtn]
 
-proc cyrillize::word {iw from to} {
-    set ins [lindex [split [$iw index insert] .] 1]
-    set line [$iw get "insert linestart" "insert lineend"]
-    set wordstart [string wordstart $line [expr $ins - 1]]
-    set wordend [clength [string trimright \
-			      [crange $line 0 [expr $wordstart - 1]]]]
-    set word [crange $line $wordstart [expr $ins - 1]]
+proc cyrillize::wordInText {w from to} {
+    if {[$w cget -state] != "normal"} return
 
+    set ins [lindex [split [$w index insert] .] 1]
+    set line [$w get "insert linestart" "insert lineend"]
+    set wordstart [string wordstart $line [expr {$ins-1}]]
+    set wordend [string length \
+			[string trimright \
+				[string range $line 0 [expr {$wordstart-1}]]]]
+    set word [string range $line $wordstart [expr {$ins-1}]]
+
     set newword [do $word $from $to]
-    $iw delete "insert linestart +$wordstart chars" insert
-    $iw insert insert $newword
+    $w delete "insert linestart +$wordstart chars" insert
+    $w insert insert $newword
 
-    $iw mark set insert "insert linestart +$wordend chars"
+    $w mark set insert "insert linestart +$wordend chars"
 }
 
+proc cyrillize::wordInEntry {w from to} {
+    if {[$w cget -state] != "normal"} return
+
+    set ins [$w index insert]
+    set line [$w get]
+    set wordstart [string wordstart $line [expr {$ins-1}]]
+    set wordend [string length \
+			[string trimright \
+				[string range $line 0 [expr {$wordstart-1}]]]]
+    set word [string range $line $wordstart [expr {$ins-1}]]
+
+    set newword [do $word $from $to]
+    $w delete $wordstart insert
+    $w insert insert $newword
+
+    $w icursor $wordend
+}
+
 event add <<Cyrillize-Eng-Rus>> <Control-quoteright>
 event add <<Cyrillize-Eng-Rus>> <Control-yacute>
 event add <<Cyrillize-Rus-Eng>> <Control-quotedbl>
 event add <<Cyrillize-Rus-Eng>> <Control-Yacute>
 
-proc cyrillize::setup_bindings {chatid type} {
-    variable history
+bind Text <<Cyrillize-Eng-Rus>> \
+     [list [namespace current]::cyrillize::wordInText %W eng rus]
+bind Text <<Cyrillize-Eng-Rus>> +break
+bind Text <<Cyrillize-Rus-Eng>> \
+     [list [namespace current]::cyrillize::wordInText %W rus eng]
+bind Text <<Cyrillize-Rus-Eng>> +break
 
-    set iw [chat::input_win $chatid]
-    bind $iw <<Cyrillize-Eng-Rus>> [list [namespace current]::word $iw eng rus]
-    bind $iw <<Cyrillize-Eng-Rus>> +break
-    bind $iw <<Cyrillize-Rus-Eng>> [list [namespace current]::word $iw rus eng]
-    bind $iw <<Cyrillize-Rus-Eng>> +break
-}
+bind Entry <<Cyrillize-Eng-Rus>> \
+     [list [namespace current]::cyrillize::wordInEntry %W eng rus]
+bind Entry <<Cyrillize-Eng-Rus>> +break
+bind Entry <<Cyrillize-Rus-Eng>> \
+     [list [namespace current]::cyrillize::wordInEntry %W rus eng]
+bind Entry <<Cyrillize-Rus-Eng>> +break
 
-hook::add open_chat_post_hook [namespace current]::cyrillize::setup_bindings
+bind BwEntry <<Cyrillize-Eng-Rus>> \
+     [list [namespace current]::cyrillize::wordInEntry %W eng rus]
+bind BwEntry <<Cyrillize-Eng-Rus>> +break
+bind BwEntry <<Cyrillize-Rus-Eng>> \
+     [list [namespace current]::cyrillize::wordInEntry %W rus eng]
+bind BwEntry <<Cyrillize-Rus-Eng>> +break
 
-
-



More information about the Tkabber-dev mailing list