[Tkabber-dev] r488 - trunk/plugins/notes

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed May 4 02:52:19 MSD 2011


Author: Totktonada
Date: 2011-05-04 02:52:19 +0400 (Wed, 04 May 2011)
New Revision: 488

Modified:
   trunk/plugins/notes/notes.tcl
Log:
If title empty, notes in listbox displayed by his texts.
Add "Delete note" button.
Fix formatting (replace tab by 8 spaces).


Modified: trunk/plugins/notes/notes.tcl
===================================================================
--- trunk/plugins/notes/notes.tcl	2011-05-02 00:31:31 UTC (rev 487)
+++ trunk/plugins/notes/notes.tcl	2011-05-03 22:52:19 UTC (rev 488)
@@ -7,13 +7,13 @@
     ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
     if {![::plugins::is_registered notes]} {
-	::plugins::register notes \
-			    -namespace [namespace current] \
-			    -source [info script] \
-			    -description [::msgcat::mc "Whether the Notes plugin is loaded."] \
-			    -loadcommand [namespace code load] \
-			    -unloadcommand [namespace code unload]
-	return
+        ::plugins::register notes \
+            -namespace [namespace current] \
+            -source [info script] \
+            -description [::msgcat::mc "Whether the Notes plugin is loaded."] \
+            -loadcommand [namespace code load] \
+            -unloadcommand [namespace code unload]
+        return
     }
 }
 
@@ -67,20 +67,20 @@
 
 proc notes::setup_menu {} {
     catch {
-	set m [.mainframe getmenu plugins]
-	set ind [$m index end]
+        set m [.mainframe getmenu plugins]
+        set ind [$m index end]
 
-	$m insert $ind command -label [::msgcat::mc "Notes"] \
-	    -command [list [namespace current]::open_window]
+        $m insert $ind command -label [::msgcat::mc "Notes"] \
+            -command [list [namespace current]::open_window]
     }
 }
 
 proc notes::desetup_menu {} {
     catch {
-	set m [.mainframe getmenu plugins]
-	set ind [$m index [::msgcat::mc "Notes"]]
+        set m [.mainframe getmenu plugins]
+        set ind [$m index [::msgcat::mc "Notes"]]
 
-	$m delete $ind
+        $m delete $ind
     }
 }
 
@@ -141,7 +141,7 @@
     set notes($xlib) $noteslist
 
     if {[expr [winfo exists .notes] && [cequal $current_xlib $xlib]]} {
-        update_lbox $xlib
+        update_lbox
     }
     return
 }
@@ -176,6 +176,9 @@
     set new_button [button $tools.new_button -text [::msgcat::mc "New note"] \
         -command [list [namespace current]::edit_note -1]]
     pack $new_button -anchor w -side left
+    set delete_button [button $tools.delete_button -text [::msgcat::mc "Delete note"] \
+        -command [list [namespace current]::delete_focused_note]]
+    pack $delete_button -anchor w -side left
 
 # TODO: from menubutton to OptionMenu?
 #    set conn_menu [OptionMenu $tools.conn_menu [connections]]
@@ -208,7 +211,7 @@
 
     set lbox [listbox $lbox_frame.lbox -takefocus 1 -exportselection 0]
     $lbox selection clear 0 end
-    update_lbox $current_xlib
+    update_lbox
     $lbox selection set 0
     focus $lbox
 
@@ -231,6 +234,18 @@
     grid rowconfigure $lbox_frame 0 -weight 1
 }
 
+proc notes::delete_focused_note {} {
+#TODO: ask "Are you sure..?".
+    variable notes
+    variable current_xlib
+
+    set lbox .notes.lbox_frame.lbox
+    set idx [$lbox index active]
+    set notes($current_xlib) [lreplace $notes($current_xlib) $idx $idx]
+    store_notes $current_xlib
+    $lbox delete $idx $idx
+}
+
 proc notes::edit_note {idx args} {
     variable notes
     variable current_xlib
@@ -325,26 +340,54 @@
     $lbox insert end [get_short_string $new_note]
 }
 
-proc notes::update_lbox {xlib} {
+proc notes::update_lbox {} {
     variable notes
+    variable current_xlib
 
     set lbox .notes.lbox_frame.lbox
     $lbox delete 0 end
 
-    foreach note $notes($xlib) {
-	$lbox insert end [get_short_string $note]
+    foreach note $notes($current_xlib) {
+        $lbox insert end [get_short_string $note]
     }
 #    $lbox selection clear 0 end
 #    $lbox selection set 0
 }
 
 proc notes::get_short_string {note} {
+    set title ""
+    set tags_str ""
+    set text ""
+
     foreach {key value} $note {
         switch -- $key {
-            title {
-                return $value
-	    }
-	}
+            title -
+            text {
+                set $key $value
+            }
+            tags {
+                set tags_str [join $value " "]
+            }
+        }
     }
-    return "Empty title?"
+
+    set short_string $title
+
+    if {[string length $short_string] == 0} {
+        set short_string $text
+    }
+
+    if {[string length $short_string] == 0} {
+        set short_string {[Title and text is empty]}
+    }
+
+# TODO: Need?
+if {0} {
+    set max_length 30
+    if {[string length $short_string] > $max_length} {
+        set short_string "[string range $short_string 0 [expr $max_length - 4]]..."
+    }
 }
+
+    return $short_string
+}



More information about the Tkabber-dev mailing list