[Tkabber-dev] r490 - in trunk/plugins/notes: . xmpp

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Jun 6 01:43:57 MSD 2011


Author: Totktonada
Date: 2011-06-06 01:43:57 +0400 (Mon, 06 Jun 2011)
New Revision: 490

Modified:
   trunk/plugins/notes/notes.tcl
   trunk/plugins/notes/xmpp/xmpp-notes.tcl
Log:
Notes plugin:
1. Fix error with change current connections.
2. Cleanup code.


Modified: trunk/plugins/notes/notes.tcl
===================================================================
--- trunk/plugins/notes/notes.tcl	2011-06-03 19:26:47 UTC (rev 489)
+++ trunk/plugins/notes/notes.tcl	2011-06-05 21:43:57 UTC (rev 490)
@@ -40,7 +40,6 @@
 }
 
 proc notes::open_window {} {
-    variable current_xlib
     set w .notes
 
     if {[winfo exists $w]} {
@@ -195,7 +194,7 @@
             -command [namespace code [format {
                 variable current_xlib
                 set current_xlib %1$s
-                update_lbox %1$s} $conn]]
+                update_lbox} $conn]]
     }
 
     pack $conn_button -anchor w -side left
@@ -250,23 +249,13 @@
     variable notes
     variable current_xlib
 
-    set title ""
-    set tags_str ""
-    set text ""
-
     if {$idx >= 0} {
         set source_note [lindex $notes($current_xlib) $idx]
-        foreach {key value} $source_note {
-            switch -- $key {
-                title -
-                text {
-                    set $key $value
-                }
-                tags {
-                    set tags_str [join $value " "]
-                }
-            }
-        }
+        ::xmpp::private::notes::split $source_note title -> text tags_str
+    } else {
+        set title ""
+        set tags_str ""
+        set text ""
     }
 
     set dialog_w .edit_note
@@ -317,14 +306,10 @@
     set dialog_frame [$dialog_w getframe]
 
     set title [$dialog_frame.title get]
-    set tags  [split [$dialog_frame.tags get] " "]
+    set tags_str [$dialog_frame.tags get]
     set text [$dialog_frame.text get 0.0 "end -1 char"]
 
-    set new_note [list \
-        title $title \
-        tags $tags \
-        text $text \
-    ]
+    set new_note [::xmpp::private::notes::create $title "" $text $tags_str]
 
     if {$idx >= 0} {
         lset notes($xlib) $idx $new_note
@@ -364,22 +349,8 @@
 }
 
 proc notes::get_short_string {note} {
-    set title ""
-    set tags_str ""
-    set text ""
+    ::xmpp::private::notes::split $note title -> text tags_str
 
-    foreach {key value} $note {
-        switch -- $key {
-            title -
-            text {
-                set $key $value
-            }
-            tags {
-                set tags_str [join $value " "]
-            }
-        }
-    }
-
     set short_string $title
 
     if {[string length $short_string] == 0} {

Modified: trunk/plugins/notes/xmpp/xmpp-notes.tcl
===================================================================
--- trunk/plugins/notes/xmpp/xmpp-notes.tcl	2011-06-03 19:26:47 UTC (rev 489)
+++ trunk/plugins/notes/xmpp/xmpp-notes.tcl	2011-06-05 21:43:57 UTC (rev 490)
@@ -3,9 +3,42 @@
 package provide xmpp::private::notes 0.1
 
 namespace eval ::xmpp::private::notes {
-    namespace export store retrieve serialize deserialize
+    namespace export create split store retrieve serialize deserialize
 }
 
+proc ::xmpp::private::notes::create {title tags text {tags_str ""}} {
+    if {![string equal $tags_str ""]} {
+        set tags [::split $tags_str " "]
+    }
+    return [list title $title tags $tags text $text]
+}
+
+proc ::xmpp::private::notes::split {note titleVar tagsVar textVar \
+        {tags_strVar ""}} {
+    upvar 1 $titleVar title $tagsVar tags $textVar text
+
+    set title ""
+    set tags {}
+    set text ""
+
+    foreach {key value} $note {
+        switch -- $key {
+            title -
+            tags -
+            text {
+                set $key $value
+            }
+        }
+    }
+
+    if {![string equal $tags_strVar ""]} {
+        upvar 1 $tags_strVar tags_str
+        set tags_str [join $tags " "]
+    }
+
+    return
+}
+
 proc ::xmpp::private::notes::retrieve {xlib args} {
     set commands {}
     set timeout 0
@@ -54,8 +87,8 @@
         foreach note $subels {
             ::xmpp::xml::split $note n_tag n_xmlns n_attrs n_cdata n_subels
 
-            set tags [split [::xmpp::xml::getAttr $n_attrs "tags"] " "]
             set title ""
+            set tags_str [::xmpp::xml::getAttr $n_attrs "tags"]
             set text ""
 
             foreach n_subel $n_subels {
@@ -68,7 +101,7 @@
                 }
             }
 
-            lappend notes [list tags $tags title $title text $text]
+            lappend notes [::xmpp::private::notes::create $title "" $text $tags_str]
             }
         }
     }
@@ -79,22 +112,8 @@
 proc ::xmpp::private::notes::serialize {notes} {
     set tags {}
     foreach note $notes {
-        set title ""
-        set tags_str ""
-        set text ""
+        ::xmpp::private::notes::split $note title -> text tags_str
 
-        foreach {key value} $note {
-            switch -- $key {
-                title -
-                text {
-                    set $key $value
-                }
-                tags {
-                    set tags_str [join $value " "]
-                }
-            }
-        }
-
         lappend tags [ \
             ::xmpp::xml::create "note" \
                 -attrs [list "tags" $tags_str] \



More information about the Tkabber-dev mailing list