⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 greppane.tcl

📁 This Source-Navigator, an IDE for C/C++/Fortran/Java/Tcl/PHP/Python and a host of other languages.
💻 TCL
📖 第 1 页 / 共 3 页
字号:
                return 0            }            set lineranges ""            foreach pos ${foundranges} {                set col [expr {[lindex [split ${pos} .] end] - ${foundidx}}]                lappend lineranges "${foundline}.${col}"            }            ${ed} tag remove sel 0.0 end            ${ed} tag remove grep 0.0 end            foreach {from to} ${lineranges} {                ${ed} tag add sel ${from} ${to}                if {! $sn_options(def,grep-mark-all)} {                    break                }            }            #move to the first selection position in the editor.            ${ed} mark set lastpos insert            ${ed} mark set insert [lindex ${lineranges} 0]            ${ed} see insert            return 1        }        return 0    }    # These methods handle our custom interaction with the    # text widget. We use a text widget like it is a listbox    # so we have to do our own special bindings.    private method text_b1_down { w x y } {        # Don't allow selection action while grep is running        if {${Proceed} != 0} {            sn_log "ignoring click selection, grep is active"            bell            return        }        # Get the line number at the given x y position        set line [lindex [split [$w index @$x,$y] .] 0]        text_select_line $line        bind $w <B1-Motion> [itcl::code $this text_b1_motion %W %x %y]        bind $w <ButtonRelease-1> [itcl::code $this text_b1_up %W %x %y]    }    private method text_b1_motion { w x y } {        # Get the line number at the given x y position        set line [lindex [split [$w index @$x,$y] .] 0]        text_select_line $line    }    private method text_b1_up { w x y } {        set text_b1_really_up_after [after 500 [itcl::code $this handle_single_click]]        bind $w <B1-Motion> {}        bind $w <ButtonRelease-1> {}    }    # Double clicking on a line will open the given file    # in the editor or in another window if reuse is    # deselected. It does not set regular the export line.    private method text_b1_double { w x y } {        # Don't allow selection action while grep is running        if {${Proceed} != 0} {            sn_log "ignoring double click selection, grep is active"            bell            return        }        after cancel $text_b1_really_up_after        bind $w <B1-Motion> {}        bind $w <ButtonRelease-1> {}        sn_log "greppane Text -> Button double $text_b1_current_line_num"        tixBusy $itk_component(results) on        update idletasks        sn_grep_edit_file $text_current_line        tixBusy $itk_component(results) off    }    # Highlight the given line in the grep results    private method text_select_line { linenum } {        sn_log "text_select_line $linenum"        if {$linenum == $text_b1_current_line_num} {            return        }        set w $itk_component(results)        $w tag remove sel 0.0 end        $w tag add sel $linenum.0 [list $linenum.0 lineend]        $w see $linenum.0        set text_b1_current_line_num $linenum        set text_current_line [$w get $linenum.0 [list $linenum.0 lineend]]        sn_log "new selected line_num is $text_b1_current_line_num, line is \"$text_current_line\""    }    # Move the selected line up or down by one element    private method incr_selected_line { amount } {        if {$amount != "+1" && $amount != "-1"} {            error "incr amount must be +1 or -1, you gave \"$amount\""                    }        # Ignore newlines to find last line of text.        for {set i 1} {1} {incr i} {            set index [$itk_component(results) index [list end - $i char]]            if {[$itk_component(results) get $index] != "\n" ||                    $index == "1.0"} {                break            }        }        set lastline [expr {int($index)}]        set nextline [expr {$text_b1_current_line_num + $amount}]        if {$nextline == 0} {            # Text widget treats line 0 as line 1            text_select_line $lastline        } elseif {$nextline > $lastline} {            # If they are on the last line, shoot them back to line 1            text_select_line 1        } else {            text_select_line $nextline        }    }    method print {} {        if {$itk_option(-next) != ""} {            $itk_option(-next) print        } else {            Editor&::print_dialog $itk_component(results)        }    }    method filter {{all 0}} {    }    #this function is called, when the symbols combobox    #is called    method postcommand {m} {        set ed [MultiWindow&::list_find $itk_option(-next) edit]        if {$itk_option(-symbols) == "" || ${ed} == ""} {            return        }        ${ed} postcommand ${m}    }    method activate {} {        if {$itk_option(-symbols) != ""} {            if {[MultiWindow&::list_find $itk_option(-next) edit] == ""} {                $itk_option(-symbols) configure -state disabled            }        }        if {$itk_option(-menu) != ""} {        }        if {$itk_option(-toolbar) != ""} {            pack $itk_component(greptoolbar) -side left        }    }    method deactivate {} {        if {$itk_option(-symbols) != ""} {            $itk_option(-symbols) configure -state normal        }        if {$itk_option(-menu) != ""} {        }        if {$itk_option(-toolbar) != ""} {            pack forget $itk_component(greptoolbar)        }    }    method Selection {} {        global tcl_platform        # No selection has been made        if {$text_b1_current_line_num == -1} {            return [list "" "" "" "" "" "" "" ""]        }        set sel [$this Split_Line]        sn_log "Split_Line returned \"$sel\""        if {${sel} != ""} {            set file [file nativename [lindex ${sel} 0]]# What the heck is this regsub for? Why convert to nativename and then back again?            if {$tcl_platform(platform) == "windows"} {                regsub -all {\\} ${file} {/} file            }            set foundline [lindex ${sel} 1]# What is this doing?            if {$tcl_platform(platform) != "windows"} {                set last [string last "/" ${file}]                set len [string length ${file}]                #sometimes we get strang results from\                  'sn_goto_comp_error_or_grep'                if {${last} != -1 && [expr ${last} + 1] == ${len} ||\                  [string first "**" ${file}] == 0} {                    set file ""                    set foundline ""                }            }        } else {            set file ""            set foundline ""            set foundranges ""        }        return [list "" "" "" ${file} ${foundline} "" "" ""]    }    method gotosymbol {{scope ""} {sym ""} {cls ""} {file ""} {from ""} \            {type ""} {prm ""} {to ""} {always 1}} {        set pattern ${sym}        ${this} FormatPattern        return 1    }# FIXME: I think this is broken!    method clearselection {} {        $itk_component(results) clear    }    # This method is called externally when things like editor prefs change!    public method Update_Layout {} {        global sn_options        $itk_component(results) tag configure grep -font $sn_options(def,grep-found-font)\          -foreground $sn_options(def,grep-found-fg)        $itk_component(results) config -font $sn_options(def,grep-font)\          -selectforeground $sn_options(def,select-fg)\          -selectbackground $sn_options(def,select-bg)    }    method Focus {} {        focus [$itk_component(pattern) component entry]    }    #make a title for the Dump position, this is usefull    #for the views stack (prev/next)    method DumpTitle {{dump ""}} {        if {${dump} == ""} {            set dump [Dump]        }        set grepstr [lindex ${dump} 0]        set grepfpat [lindex ${dump} 1]        return "Grep [string trim ${grepstr}(${grepfpat})]"    }# FIXME: Will this be needed once we move to multichild?    method AddHistoryFromDump {dump title} {    }    #return the important data to restore this widget    #in later time again (used by saving the project)    method Dump {} {        set cnts [$itk_component(results) get 0.0 end]        return [list ${pattern} ${filepattern} ${GrepPatFilter}\          ${GrepNocase} ${maxmatches}]    }# FIXME: where are these dump and restore methods ever used ???    #gets the result from the function "Dump" to    #restore the older state (used by restoring the project)    method Restore {str} {        set pattern [lindex ${str} 0]        set filepattern [lindex ${str} 1]        set GrepPatFilter [lindex ${str} 2]        set GrepNocase [lindex ${str} 3]        set maxmatches [lindex ${str} 4]        #restore result and it's highlights        GrepResetFromHistory ${pattern} ${filepattern} ${GrepNocase}    }    method Close {{mode 0}} {        return 1    }    method whoami {} {        return grep    }    #if an editor is added to the grep, call the    #goto function of the editor.    method goto {combo txt} {        set ed [MultiWindow&::list_find $itk_option(-next) edit]        if {$itk_option(-symbols) != "" && ${ed} != ""} {            #dump the current view into the history stack            $itk_option(-parent) history_stack_add_point ${ed}            ${ed} goto ${combo} ${txt}        }    }    #    # VARIABLES    ## FIXME: These should be itk rename and keep options not variables !!!#itk_option define -value value Value "" { ... }    # interface to query and set the string we will grep for    public variable pattern ""    public variable filepattern * {        if {$filepattern == ""} {            set filepattern *        }    }    # Pattern selected in the "Format" combo box    private variable GrepPatFilter ""    # If true, then ignore case during the grep command    private variable GrepNocase 0    # Max number of matches before stopping grep    public variable maxmatches 100 {        if {$maxmatches <= 0} {            # Reject new setting            break        }    }    private variable MaxFound    private common PatternFormats    private common PatternFormatsCombo    # Boolean to determine if user selected on of the    # lines in the grep output    # This will be set to the last line in the grep    # results that the user clicked on.    private variable selectedLine -1    private variable counter 0    # Variables used in implementing custom listbox like    # bindings on the text widet    private variable text_b1_really_up_after ""    private variable text_b1_current_line_num -1    # The text from the currently selected line    # in the text widget.    private variable text_current_line    # The text from the last "selected" line    # in the text widget. This can be different    # from the text_current_line in the case    # of a double click. A double click will    # change the text_current_line but it    # does not modify the exported_current_line    private variable exported_current_line ""    #protected variable progressbar ""    protected variable foundidx 0    protected variable foundline 0    protected variable foundranges ""    protected variable lineranges ""    protected variable textualline ""    protected variable filter "*"    protected variable file_list ""    protected variable Configure_binding ""    protected variable Proceed 0    # Don't close window after selecting an entry    public variable hold 1    public variable width 80    public variable height 10    public variable cancelcommand ""    # Either an ExecGrepDriver or a TclGrepDriver object    private variable driver}# FIXME: need to convert over to class decl and method bodies!

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -