aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2011-01-12 06:06:35 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2011-01-12 06:06:35 +0000
commita5e42b8234ff991ee63e7516ee4ce0750ba4ac62 (patch)
tree4c766c65dbd2e89c8bb269ab9c3c057f413e5cb0
parent853149f053f94b029a6b2fe0a0924a90f1ec6156 (diff)
made deployable, searchs .txt and .pd, and the whole search patch
svn path=/trunk/scripts/guiplugins/search-plugin/; revision=14712
-rw-r--r--search-plugin.tcl58
1 files 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 <Return> {::dialog_search::search $searchtext}
# TODO add history like in the find box
bind .search.searchtextentry <Up> {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 <<ListboxSelect>> \
- {::dialog_search::selectline [.search.resultslistbox get \
- [.search.resultslistbox curselection]]}
+ "::dialog_search::selectline .search.resultslistbox"
bind .search.resultslistbox <Key-Return> \
{menu_doc_open $::sys_libdir $::dialog_search::selected_file}
bind .search.resultslistbox <Double-ButtonRelease-1> \
@@ -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}