From a5e42b8234ff991ee63e7516ee4ce0750ba4ac62 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 12 Jan 2011 06:06:35 +0000 Subject: made deployable, searchs .txt and .pd, and the whole search patch svn path=/trunk/scripts/guiplugins/search-plugin/; revision=14712 --- search-plugin.tcl | 58 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/search-plugin.tcl b/search-plugin.tcl index 4482c5c..0f09d53 100644 --- a/search-plugin.tcl +++ b/search-plugin.tcl @@ -1,6 +1,7 @@ +# plugin to allow searching all the documentation using a regexp +# check the Help menu for the Search item to use it -package require Tk 8.5 -package require tile +package require Tk 8.4 package require pd_bindings package require pd_menucommands @@ -8,20 +9,20 @@ namespace eval ::dialog_search:: { variable selected_file {} } -# findFiles -# basedir - the directory to start looking in -# pattern - A pattern, as defined by the glob command, that the files must match -proc ::dialog_search::findFiles { basedir pattern } { +# TODO it works funny when libdirs are symlinks +# find_doc_files +# basedir - the directory to start looking in +proc ::dialog_search::find_doc_files { basedir } { # Fix the directory name, this ensures the directory name is in the # native format for the platform and contains a final directory seperator - set basedir [string trimright [file join [file normalize $basedir] { }]] + set basedir [string trimright [file join $basedir { }]] set fileList {} # Look in the current directory for matching files, -type {f r} # means ony readable normal files are looked at, -nocomplain stops # an error being thrown if the returned list is empty - foreach fileName [glob -nocomplain -type {f r} -path $basedir $pattern] { + foreach fileName [glob -nocomplain -type {f r} -path $basedir *.txt *.pd] { lappend fileList $fileName } @@ -29,7 +30,7 @@ proc ::dialog_search::findFiles { basedir pattern } { foreach dirName [glob -nocomplain -type {d r} -path $basedir *] { # Recusively call the routine on the sub directory and append any # new files to the results - set subDirList [findFiles $dirName $pattern] + set subDirList [find_doc_files $dirName] if { [llength $subDirList] > 0 } { foreach subDirFile $subDirList { lappend fileList $subDirFile @@ -39,9 +40,15 @@ proc ::dialog_search::findFiles { basedir pattern } { return $fileList } -proc ::dialog_search::selectline {line} { +proc ::dialog_search::selectline {listingwidget} { variable selected_file - set selected_file [string replace $line [string first ":" $line] end] + set selection [$listingwidget curselection] + if {$selection eq ""} { + set selected_file "" + } else { + set line [$listingwidget get $selection] + set selected_file [string replace $line [string first ":" $line] end] + } } proc ::dialog_search::readfile {file varName} { @@ -54,10 +61,15 @@ proc ::dialog_search::readfile {file varName} { proc ::dialog_search::search {searchtext} { set widget .search.resultslistbox $widget delete 0 end - foreach docfile [findFiles $::sys_libdir "*.pd"] { - readfile $docfile data - searchfile $searchtext $widget \ - [string replace $docfile 0 [string length $::sys_libdir]] + foreach dir [concat [file join $::sys_libdir doc] $::sys_searchpath $::sys_staticpath] { + # Fix the directory name, this ensures the directory name is in the + # native format for the platform and contains a final directory seperator + set dir [file normalize $dir] + foreach docfile [find_doc_files $dir] { + readfile $docfile data + searchfile $searchtext $widget \ + [string replace $docfile 0 [string length $dir]] + } } } @@ -70,8 +82,6 @@ proc ::dialog_search::searchfile {searchtext widget filename} { incr n } } -# $widget insert end "Found $n lines" - $widget see end } proc ::dialog_search::ok {mytoplevel} { @@ -94,17 +104,17 @@ proc ::dialog_search::open_search_dialog {mytoplevel} { proc ::dialog_search::create_dialog {} { variable selected_file toplevel .search - wm title .search [_ "Search Window"] + wm title .search [_ "Search"] entry .search.searchtextentry -bg white -textvar searchtext bind .search.searchtextentry {::dialog_search::search $searchtext} # TODO add history like in the find box bind .search.searchtextentry {set searchtext ""} listbox .search.resultslistbox -yscrollcommand ".search.yscrollbar set" \ - -bg white -height 20 -width 40 - scrollbar .search.yscrollbar -command ".search.resultslistbox yview" + -bg white -highlightcolor blue -height 30 -width 80 + scrollbar .search.yscrollbar -command ".search.resultslistbox yview" \ + -takefocus 0 bind .search.resultslistbox <> \ - {::dialog_search::selectline [.search.resultslistbox get \ - [.search.resultslistbox curselection]]} + "::dialog_search::selectline .search.resultslistbox" bind .search.resultslistbox \ {menu_doc_open $::sys_libdir $::dialog_search::selected_file} bind .search.resultslistbox \ @@ -115,10 +125,12 @@ proc ::dialog_search::create_dialog {} { grid .search.resultslistbox .search.yscrollbar -sticky news grid columnconfig . 0 -weight 1 grid rowconfig . 1 -weight 1 + + focus .search.searchtextentry } set mymenu .menubar.help set inserthere [$mymenu index [_ "Report a bug"]] $mymenu insert $inserthere separator -$mymenu insert $inserthere command -label [_ " Search"] \ +$mymenu insert $inserthere command -label [_ "Search"] \ -command {::dialog_search::open_search_dialog .search} -- cgit v1.2.1