diff options
Diffstat (limited to 'lib/bottompanel/todo.tcl')
-rw-r--r--[-rwxr-xr-x] | lib/bottompanel/todo.tcl | 258 |
1 files changed, 145 insertions, 113 deletions
diff --git a/lib/bottompanel/todo.tcl b/lib/bottompanel/todo.tcl index 6a7d8ff..21f79a5 100755..100644 --- a/lib/bottompanel/todo.tcl +++ b/lib/bottompanel/todo.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,6 +21,11 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _TODO_TCL ] } { +set _TODO_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Provides autonome GUI component intented for writing ToDo list @@ -35,13 +40,15 @@ class Todo { -family ${Editor::fontFamily} \ -size -${Editor::fontSize} \ ] - common normal_font [font create \ - -family {helvetica} \ - -size -12 -weight {normal} \ + common normal_font [font create \ + -family {helvetica} \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight {normal} \ ] - common bold_font [font create \ - -family {helvetica} \ - -size -12 -weight {bold} \ + common bold_font [font create \ + -family {helvetica} \ + -size [expr {int(-12 * $::font_size_factor)}] \ + -weight {bold} \ ] # List of used text tags common textTags { @@ -64,7 +71,7 @@ class Todo { # Definition of the popup menu common TODOMENU { {command {Undo} {Ctrl+Z} 0 "undo" {undo} - "Undo last operaton"} + "Undo last operation"} {command {Redo} {Ctrl+Shift+Z} 2 "redo" {redo} "Take back last undo operation"} {separator} @@ -83,8 +90,8 @@ class Todo { "Use bold font"} {command {Italic text} {$todo:italic} 0 "italic" {text_italic} "Use italic font"} - {command {Striketrought text} {$todo:strike} 0 "strike" {text_strike} - "Use striketrought font"} + {command {Strikethrough text} {$todo:strike} 0 "strike" {text_strike} + "Use strikethrough font"} {command {Underline text} {$todo:under} 1 "under" {text_under} "Use underline font"} {separator} @@ -96,7 +103,7 @@ class Todo { # Variables related to object initialization private variable input_text ;# String: initial content of the text widget - private variable gui_initialized 0 ;# Bool: GUI created + private variable todo_gui_initialized 0 ;# Bool: GUI created # Other variables private variable main_frame ;# ID of main frame (text_widget; scrollbar; button_frame) @@ -106,7 +113,7 @@ class Todo { private variable parent_container ;# ID of parent contaner (some frame) private variable button_bold ;# ID of button "Bold" private variable button_italic ;# ID of button "Italic" - private variable button_strike ;# ID of button "Striketrought" + private variable button_strike ;# ID of button "Strikethrough" private variable button_under ;# ID of button "Underline" private variable active_tags {} ;# Currently active tags private variable menu {} ;# ID of popup menu @@ -135,9 +142,9 @@ class Todo { # Variables related to search bar private variable search_frame ;# Widget: Search bar frame - private variable last_find_index ;# String: Index of last found occurence of the search string - private variable search_string ;# String: Search string - private variable search_string_length ;# Int: Length of the search string + private variable last_find_index {} ;# String: Index of last found occurrence of the search string + private variable search_string {} ;# String: Search string + private variable search_string_length 0 ;# Int: Length of the search string private variable search_entry ;# Widget: Search bar entry box private variable search_find_next ;# Widget: Button "Next" private variable search_find_prev ;# Widget: Button "Prev" @@ -151,7 +158,7 @@ class Todo { -relief flat ttk::style map Todo_Active.TButton \ -relief [list active raised] \ - -background [list disabled {#EEEEEE} active $buttonActiveBg] + -background [list disabled ${::COMMON_BG_COLOR} active $buttonActiveBg] ttk::style configure Todo_SemiAct.TButton \ -background $buttonSemiActBg \ @@ -159,7 +166,7 @@ class Todo { -relief flat ttk::style map Todo_SemiAct.TButton \ -relief [list active raised] \ - -background [list disabled {#EEEEEE} active $buttonSemiActBg] + -background [list disabled ${::COMMON_BG_COLOR} active $buttonSemiActBg] } ## Object destructor @@ -175,25 +182,25 @@ class Todo { public method get_file_notes_config {} { if {$panel_size < $panel_size_last} { set panel_size_max $panel_size_last - } { + } else { set panel_size_max $panel_size } return [list $notes_visible $panel_size_max] } ## Get contents of file specific notepad - # @parm Int = <current> - Index in $LIST_file_notes + # @parm Int idx=<current> - Index in $LIST_file_notes # @return void - public method get_file_notes_data args { + public method get_file_notes_data {{idx {}}} { CreateTodoGUI - if {$args == {}} { + if {$idx == {}} { return [$file_notes get 1.0 {end-1l lineend}] - } { - set w [lindex $LIST_file_notes $args] + } else { + set w [lindex $LIST_file_notes $idx] if {$w == {}} { return {} - } { + } else { return [$w get 1.0 {end-1l lineend}] } } @@ -216,7 +223,7 @@ class Todo { public method PrepareTodo {parentContainer _input_text} { set parent_container $parentContainer set input_text $_input_text - set gui_initialized 0 + set todo_gui_initialized 0 } ## Inform this tab than it has became active @@ -279,7 +286,7 @@ class Todo { ## Redraw panel (move pane sash) acorning to current value of $PanelSize # @return void public method todo_panel_redraw_pane {} { - if {!$gui_initialized} {return} + if {!$todo_gui_initialized} {return} if {$redraw_pane_in_progress} { after 50 "$this todo_panel_redraw_pane" @@ -294,7 +301,7 @@ class Todo { set redraw_pane_in_progress 0 } - ## Set panel width acording to current sash position + ## Set panel width according to current sash position # @return void public method todo_panel_set_size {} { set panel_size [lindex [$paned_win sash coord 0] 0] @@ -316,7 +323,7 @@ class Todo { set panel_size $panel_size_last # Hide - } { + } else { pack forget $file_notes_pagesManager pack $notes_invisible_frm -fill y -anchor nw $paned_win paneconfigure $right_pane -minsize 20 @@ -382,11 +389,15 @@ class Todo { return [$file_notes get 0.0 end] } - ## Initialize todo text + ## Initialize to do text # @return void public method CreateTodoGUI {} { - if {$gui_initialized} {return} - set gui_initialized 1 + if {$todo_gui_initialized} {return} + set todo_gui_initialized 1 + + if {${::DEBUG}} { + puts "CreateTodoGUI \[ENTER\]" + } set paned_win [panedwindow $parent_container.paned_win \ -sashwidth 4 -showhandle 0 -opaqueresize 1 -orient horizontal \ @@ -407,7 +418,7 @@ class Todo { # RIGHT PART # - set file_notes_pagesManager [PagesManager $right_pane.pmgr -background {#eeeeee}] + set file_notes_pagesManager [PagesManager $right_pane.pmgr -background ${::COMMON_BG_COLOR}] $file_notes_pagesManager compute_size set notes_invisible_frm [frame $right_pane.notes_invisible_frm] @@ -460,7 +471,7 @@ class Todo { -style Flat.TButton \ ] DynamicHelp::add $search_frame.find_next_but \ - -text [mc "Find next occurence of search string"] + -text [mc "Find next occurrence of search string"] # Button: "Prev" set search_find_prev [ttk::button $search_frame.find_prev_but \ -image ::ICONS::16::up0 \ @@ -469,7 +480,7 @@ class Todo { -style Flat.TButton \ ] DynamicHelp::add $search_frame.find_prev_but \ - -text [mc "Find previous occurence of search string"] + -text [mc "Find previous occurrence of search string"] # Button: "Close" pack [ttk::button $search_frame.close_but \ -image ::ICONS::16::button_cancel \ @@ -500,6 +511,9 @@ class Todo { # Pack main frame pack $main_frame -fill both -expand 1 + # Show the search bar frame + TodoProc_find_dialog 0 + # Adjust text widget parameters TodoProc_write_text_from_sgml $input_text unset input_text @@ -517,11 +531,12 @@ class Todo { <Key-Down> <Key-Up> <Key-Right> <Key-Left> <Key-Next> <Key-Prior> - } { - bind $text_widget $key " - [bind Text $key] - $this recalc_left_panel insert - break" + } \ + { + bind $text_widget $key " + [bind Text $key] + $this recalc_left_panel insert + break" } bind $text_widget <KeyRelease> "break" bind $text_widget <KeyPress> "$this TodoProc_Key %A; break" @@ -540,7 +555,7 @@ class Todo { ] DynamicHelp::add $button_bold -text [mc "Bold font"] setStatusTip -widget $button_bold \ - -text {Use bold font} + -text [mc "Use bold font"] # Button "Italic" set button_italic [ttk::button $button_frame.todo_text_bI \ -image ::ICONS::16::text_italic \ @@ -550,16 +565,16 @@ class Todo { DynamicHelp::add $button_italic \ -text [mc "Italic text"] setStatusTip -widget $button_italic \ - -text {Use italic font} - # Button "Striketrought" + -text [mc "Use italic font"] + # Button "Strikethrough" set button_strike [ttk::button $button_frame.todo_text_bS \ -image ::ICONS::16::text_strike \ -command "$this TodoProc_strike" \ -style Flat.TButton \ ] DynamicHelp::add $button_strike \ - -text [mc "Striketrought font"] - setStatusTip -widget $button_strike -text {Use striketrought font} + -text [mc "Strikethrough font"] + setStatusTip -widget $button_strike -text [mc "Use strikethrough font"] # Button "Underline" set button_under [ttk::button $button_frame.todo_text_bU \ -image ::ICONS::16::text_under \ @@ -569,11 +584,11 @@ class Todo { DynamicHelp::add $button_under \ -text [mc "Underline font"] setStatusTip -widget $button_under \ - -text {Use underline font} + -text [mc "Use underline font"] # pack these buttons foreach wdg $tagButtons { - pack [subst "\$$wdg"] + pack [subst -nocommands "\$$wdg"] } # Button "Eraser" pack [ttk::button $button_frame.todo_text_bE \ @@ -584,7 +599,7 @@ class Todo { DynamicHelp::add $button_frame.todo_text_bE \ -text [mc "Erase text tags"] setStatusTip -widget $button_frame.todo_text_bE \ - -text {Remove formating tags within selected area} + -text [mc "Remove formatting tags within selected area"] # Button "Bookmark" pack [ttk::button $button_frame.todo_text_bBm \ -image ::ICONS::16::$bookmarkImage \ @@ -609,7 +624,7 @@ class Todo { ## Recreate all text tags and font font for the text widget # @return void public method todo_refresh_font_settings {} { - if {!$gui_initialized} {CreateTodoGUI} + if {!$todo_gui_initialized} {CreateTodoGUI} $text_widget configure -font [font create \ -family ${Editor::fontFamily} \ -size -${Editor::fontSize} \ @@ -620,7 +635,7 @@ class Todo { ## Create bindings for defined key shortcuts # @return void public method TodoProc_shortcuts_reevaluate {} { - if {!$gui_initialized} {CreateTodoGUI} + if {!$todo_gui_initialized} {CreateTodoGUI} # Unset previous configuration foreach key $set_shortcuts { @@ -662,16 +677,16 @@ class Todo { ## Create popup menu # @return void public method TodoProc_makePopupMenu {} { - if {!$gui_initialized} {return} + if {!$todo_gui_initialized} {return} if {[winfo exists $menu]} { destroy $menu } - menuFactory $TODOMENU $menu 0 "$this TodoProc_" 0 {} + menuFactory $TODOMENU $menu 0 "$this TodoProc_" 0 {} [namespace current] $menu entryconfigure [::mc "Find next"] -state disabled $menu entryconfigure [::mc "Find previous"] -state disabled } - ## Create text tags in todo text widget + ## Create text tags in to do text widget # @return void private method todo_create_tags {} { # Tag "Bold" @@ -713,7 +728,7 @@ class Todo { [expr {[winfo rooty $text_widget] + [lindex $bbox 1] + 10}] } - ## Enable/Disable popup menu items acording to state of the text widget + ## Enable/Disable popup menu items according to state of the text widget # Auxiliary procedure for 'TodoProc_popupMenu' and 'TodoProc_Key_Menu' # @return void private method popup_menu_disena {} { @@ -723,7 +738,7 @@ class Todo { $menu entryconfigure [::mc "Cut"] -state normal } $menu entryconfigure [::mc "Copy"] -state normal - } { + } else { $menu entryconfigure [::mc "Cut"] -state disabled $menu entryconfigure [::mc "Copy"] -state disabled } @@ -732,11 +747,11 @@ class Todo { } } - ## Write text to the text widget from SGML formated data + ## Write text to the text widget from SGML formatted data # @parm String inputData - SGML data # @return void public method TodoProc_write_text_from_sgml {inputData} { - if {!$gui_initialized} {CreateTodoGUI} + if {!$todo_gui_initialized} {CreateTodoGUI} # Replace all \r\n shit with LF regsub -all {(\r)|(\r\n)} $inputData "\n" inputData @@ -752,8 +767,6 @@ class Todo { regsub -all {>} $inputData { } inputData ## Parse pair tags - set lastStartIdx 0 - set lastEndIdx 0 foreach xmltag $xmlTags texttag $textTags { # modify input data for later processing @@ -768,7 +781,7 @@ class Todo { # Translate XML tags to Tk's native text tags set StartRow 1 set EndCol 0 - while 1 { + while {1} { set SRow 0 set ERow 0 set tagLength [string length "<$xmltag>"] @@ -778,7 +791,7 @@ class Todo { set LFidx 0 set LastLFidx $LFidx - while 1 { + while {1} { set LFidx [string first "\n" $data $LFidx] if {($LFidx >= $startIdx) || ($LFidx == -1)} { set correction 0 @@ -789,7 +802,7 @@ class Todo { set StartCol [expr {$startIdx - $LastLFidx - 1 + $correction}] set StartRow [expr {$StartRow + $SRow}] break - } { + } else { set LastLFidx $LFidx incr SRow incr LFidx @@ -803,7 +816,7 @@ class Todo { set LFidx 0 set LastLFidx $LFidx - while 1 { + while {1} { set LFidx [string first "\n" $data $LFidx] if {($LFidx >= $endIdx) || ($LFidx == -1)} { set correction 0 @@ -811,7 +824,7 @@ class Todo { set EndCol [expr {$endIdx - $LastLFidx - $ERow + $correction}] set EndRow [expr {$EndRow + $ERow}] break - } { + } else { set LastLFidx $LFidx incr ERow incr LFidx @@ -835,7 +848,7 @@ class Todo { foreach tag $selfCtags { set Row 1 set Col 0 - while 1 { + while {1} { set tagIdx [string first "<$tag" $data] set tagEndIdx [string first "/>" $data] if {($tagEndIdx < $tagIdx) || ($tagIdx == -1)} {break} @@ -845,7 +858,7 @@ class Todo { set LFidx 0 set LastLFidx $LFidx - while 1 { + while {1} { set LFidx [string first "\n" $data $LFidx] if {$LFidx >= $tagIdx} { @@ -854,7 +867,7 @@ class Todo { set Col [expr {$tagIdx - $LastLFidx - 1 + $correction}] set Row [expr {$Row + $rowTmp}] break - } { + } else { set LastLFidx $LFidx incr rowTmp incr LFidx @@ -873,10 +886,10 @@ class Todo { } } - ## Return content of text widget formated as SGML + ## Return content of text widget formatted as SGML # @return String - SGML code public method TodoProc_read_text_as_sgml {} { - if {!$gui_initialized} {return $input_text} + if {!$todo_gui_initialized} {return $input_text} # Determinate end index set textEnd [$text_widget index end] @@ -899,12 +912,12 @@ class Todo { set i 0 set index {} - while 1 { + while {1} { set index [lindex $ranges $i] if {$index == {}} {break} - lappend tagList "$index $xmltag" + lappend tagList [list $index $xmltag] incr i - lappend tagList "[lindex $ranges $i] /$xmltag" + lappend tagList [list [lindex $ranges $i] "/$xmltag"] incr i } } @@ -936,12 +949,12 @@ class Todo { incr col $colCorrection set imageIdx "$row.$col" - } { + } else { set lastRow $row set colCorrection 0 } - lappend tagList "$imageIdx bookmark/" + lappend tagList [list $imageIdx {bookmark/}] } # Special reverse sorting of tag list @@ -963,7 +976,7 @@ class Todo { incr index set char [string index $data $index] set data [string replace $data $index $index "<$tag>$char"] - } { + } else { set char [string index $data $index] set data [string replace $data $index $index "$char<$tag>"] } @@ -991,7 +1004,7 @@ class Todo { if {$reverse} { set A -1 set B 1 - } { + } else { set A 1 set B -1 } @@ -1010,7 +1023,7 @@ class Todo { return $A } elseif {$FC == $EC} { return 0 - } { + } else { return $B } } else { @@ -1021,7 +1034,7 @@ class Todo { ## Get content of text widget as plain text # @return String - result public method read_plain_text {} { - if {!$gui_initialized} {CreateTodoGUI} + if {!$todo_gui_initialized} {CreateTodoGUI} return [$text_widget get 1.0] } @@ -1029,48 +1042,49 @@ class Todo { # @return void public method TodoProc_bold {} { addRemoveTag tag_bold $button_bold + after idle [list focus $text_widget] } ## Switch to italic font # @return void public method TodoProc_italic {} { addRemoveTag tag_italic $button_italic + after idle [list focus $text_widget] } - ## Switch to striketrought font + ## Switch to strikethrough font # @return void public method TodoProc_strike {} { addRemoveTag tag_overstrike $button_strike + after idle [list focus $text_widget] } ## Switch to underline font # @return void public method TodoProc_under {} { addRemoveTag tag_underline $button_under + after idle [list focus $text_widget] } ## Erase tags - # @parm List idxs = {} - Indexes of selected area - # @parm Bool reset = 1 - Reset font settings on left panel + # @parm List idxs={} - Indexes of selected area + # @parm Bool reset=1 - Reset font settings on left panel # @return Bool - result - public method TodoProc_eraser args { - if {$args == {}} { + public method TodoProc_eraser {{idxs {}} {reset 1}} { + if {$idxs == {}} { set idxs [getSelectionIdx] - set reset 1 - set active_tags {} - } { - set idxs [lindex $args 0] - set reset [lindex $args 1] } if {$idxs == {}} { - set active_tags {} reset_left_panel return 0 } foreach tag $textTags { $text_widget tag remove $tag [lindex $idxs 0] [lindex $idxs 1] } - if {$reset} {reset_left_panel} + if {$reset} { + reset_left_panel + set active_tags [list] + } return 1 } @@ -1125,7 +1139,7 @@ class Todo { public method TodoProc_paste {} { if {[catch { set data [clipboard get] - }]} { + }]} then { return } catch {$text_widget delete sel.first sel.last} @@ -1135,7 +1149,7 @@ class Todo { ## Clear all text # @return void public method TodoProc_clear {} { - if {!$gui_initialized} {CreateTodoGUI} + if {!$todo_gui_initialized} {CreateTodoGUI} catch {$text_widget delete 1.0 end} } @@ -1247,7 +1261,7 @@ class Todo { return 1 } - ## Set background color for button related to given text tag acording to given state + ## Set background color for button related to given text tag according to given state # @parm String tag - name of text tag # @parm Int state - state number (0 == passive; 1 == active; 2 == semi-active) # @return void @@ -1305,12 +1319,12 @@ class Todo { foreach button $tagButtons { # Determinate ID of button widget - set buttonWdg [subst "\$$button"] + set buttonWdg [subst -nocommands "\$$button"] # Determinate state number and set Bg if {[lsearch $affected $button] != -1} { setButtonBg $buttonWdg 1 - } { + } else { setButtonBg $buttonWdg 0 } } @@ -1320,11 +1334,11 @@ class Todo { # @return void private method reset_left_panel {} { foreach button $tagButtons { - setButtonBg [subst "\$$button"] 0 + setButtonBg [subst -nocommands "\$$button"] 0 } } - ## Set background color for given button acording to given state + ## Set background color for given button according to given state # @parm Widget button - ID of button to modify # @parm Int state - state number (0 == passive; 1 == active; 2 == semi-active) # @return void @@ -1352,13 +1366,20 @@ class Todo { lappend active_tags $tagName # Tag is active -> remove the tag - } { + } else { setButtonBg $buttonName 0 set active_tags [lreplace $active_tags $tagIdx $tagIdx] } - # Modify selected area + ## Modify the selected area set idxs [getSelectionIdx] + # There is no selected area + if {$idxs == {}} { + set char_before_cursor [$text_widget get insert-1c insert] + if {$char_before_cursor == { } || $char_before_cursor == "\t" || $char_before_cursor == "\xC2"} { + set idxs [list [$text_widget index insert-1c] [$text_widget index insert]] + } + } if {$idxs != {}} { TodoProc_eraser $idxs 0 foreach tag $active_tags { @@ -1369,7 +1390,7 @@ class Todo { ## Set given text tag for area determinated by given indexes # @parm String tagName - name of text tag to set - # @parm List idxs = {} - target area {first_idx last_idx} + # @parm List idxs - target area {first_idx last_idx} # @return Bool - result private method setTagAtSel {tagName idxs} { if {$idxs == {}} {return 0} @@ -1381,14 +1402,16 @@ class Todo { # @return List - text indexes '{first last}' or '{}' private method getSelectionIdx {} { # Try to determinate indexes + set start {} + set end {} catch { - set start [$text_widget index sel.first] - set end [$text_widget index sel.last] + set start [$text_widget index sel.first] + set end [$text_widget index sel.last] } # Return result - if {[info exists start]} { - return "$start $end" - } { + if {$start != {} && $end != {}} { + return [list $start $end] + } else { return {} } } @@ -1402,14 +1425,19 @@ class Todo { } ## Show search bar + # @parm Bool do_focus_entrybox - Automatically focus the search EntryBox # @return void - public method TodoProc_find_dialog {} { + public method TodoProc_find_dialog {{do_focus 1}} { if {![winfo ismapped $search_frame]} { pack $search_frame -before $main_frame -side top -anchor w $search_entry delete 0 end - focus -force $search_entry - } { - focus -force $search_entry + if {$do_focus} { + focus -force $search_entry + } + } else { + if {$do_focus} { + focus -force $search_entry + } } } @@ -1440,12 +1468,12 @@ class Todo { if {$forw__back} { set direction {-forwards} - } { + } else { set direction {-backwards} } if {${::Todo::match_case}} { set last_find_index [$text_widget search $direction -- $search_string $from] - } { + } else { set last_find_index [$text_widget search $direction -nocase -- $search_string $from] } if {$last_find_index == {}} { @@ -1454,7 +1482,7 @@ class Todo { $search_find_prev configure -state disabled $menu entryconfigure [::mc "Find next"] -state disabled $menu entryconfigure [::mc "Find previous"] -state disabled - } { + } else { $search_entry configure -style StringFound.TEntry $search_find_next configure -state normal $search_find_prev configure -state normal @@ -1470,7 +1498,7 @@ class Todo { } } - ## Find next occurence of the search string + ## Find next occurrence of the search string # @return void public method TodoProc_find_next {} { if {![winfo ismapped $search_frame]} { @@ -1482,7 +1510,7 @@ class Todo { TodoProc_perform_search 1 $last_find_index+${search_string_length}c } - ## Find previous occurence of the search string + ## Find previous occurrence of the search string # @return void public method TodoProc_find_prev {} { if {![winfo ismapped $search_frame]} { @@ -1494,3 +1522,7 @@ class Todo { TodoProc_perform_search 0 $last_find_index } } + +# >>> File inclusion guard +} +# <<< File inclusion guard |