00001 #windowlist.tcl: provides routines for managing windows from menu, i.e. minimize, raise, bring all to front; standard menu item on Mac OS X.
00002
00003 #(c) 2010 WordTech Communications LLC. License: standard Tcl license, http://www.tcl.tk/software/tcltk/license.html
00004
00005 #includes code from http://wiki.tcl.tk/1461
00006
00007 ##"cycle through windows" code courtesy of Tom Hennigan, tomhennigan@gmail.com, (c) 2009
00008
00009 package provide windowlist 1.3
00010
00011 namespace eval windowlist {
00012
00013 #make the window menu
00014 proc windowMenu {mainmenu} {
00015
00016 menu $mainmenu.windowlist
00017
00018 $mainmenu.windowlist add command -label "Minimize" -command [namespace current]::minimizeFrontWindow -accelerator Cmd-M
00019 $mainmenu.windowlist add separator
00020 $mainmenu.windowlist add command -label "Bring All to Front" -command [namespace current]::raiseAllWindows
00021 $mainmenu.windowlist add separator
00022 $mainmenu.windowlist add command -label "Cycle Through Windows" \
00023 -command {raise [lindex [wm stackorder .] 0]} \
00024 -accelerator "Cmd-`"
00025 bind all <Command-quoteleft> {raise [lindex [wm stackorder .] 0]}
00026 $mainmenu.windowlist add separator
00027 $mainmenu.windowlist add command -label "Main Window" -command ::tk::mac::ReopenApplication
00028 $mainmenu.windowlist add separator
00029 $mainmenu.windowlist add command -label [wm title .] -command ::tk::mac::ReopenApplication
00030
00031 $mainmenu add cascade -label "Window" -menu $mainmenu.windowlist
00032
00033 #bind the window menu to update whenever a new window is added, on menu selection
00034 bind all <<MenuSelect>> +[list [namespace current]::updateWindowMenu $mainmenu.windowlist]
00035 bind all <Command-M> [namespace current]::minimizeFrontWindow
00036 bind all <Command-m> [namespace current]::minimizeFrontWindow
00037 bind . <Command-w> {wm state . withdrawn}
00038 bind . <Command-W> {wm state . withdrawn}
00039 wm protocol . WM_DELETE_WINDOW {wm state . withdrawn}
00040
00041 }
00042
00043
00044 #update the window menu with windows
00045 proc updateWindowMenu {windowmenu} {
00046
00047 set windowlist [wm stackorder .]
00048
00049 #search for drawer window first
00050 if {[lsearch $windowlist ".drawer"] >= 0 } {
00051 set windowlist [lreplace $windowlist [lsearch $windowlist ".drawer"] [lsearch $windowlist ".drawer"]]
00052 update
00053 }
00054
00055 if {$windowlist == {}} {
00056 return
00057 }
00058
00059 $windowmenu delete 8 end
00060 foreach item $windowlist {
00061 $windowmenu add command -label "[wm title $item]" -command [list raise $item]
00062
00063 }
00064 }
00065
00066
00067
00068 #make all windows visible
00069 proc raiseAllWindows {} {
00070
00071 #get list of mapped windows
00072 set windowlist [wm stackorder .]
00073
00074 #do nothing if all windows are minimized
00075 if {$windowlist == {}} {
00076 return
00077 }
00078
00079 #use [winfo children .] here to get windows that are minimized
00080 foreach item [winfo children .] {
00081
00082 #get all toplevel windows, exclude menubar windows
00083 if { [string equal [winfo toplevel $item] $item] && [catch {$item cget -tearoff}]} {
00084 wm deiconify $item
00085 }
00086 }
00087 #be sure to deiconify ., since the above command only gets the child toplevels
00088 wm deiconify .
00089 }
00090
00091 #minimize the selected window
00092 proc minimizeFrontWindow {} {
00093
00094 #get list of mapped windows
00095 set windowlist [wm stackorder .]
00096
00097 #do nothing if all windows are minimized
00098 if {$windowlist == {}} {
00099 return
00100 } else {
00101
00102 #minimize topmost window
00103 set topwindow [lindex $windowlist end]
00104 wm iconify $topwindow
00105
00106 }
00107 }
00108
00109 namespace export *
00110 }
00111
00112 #raise window if closed--dock click
00113 proc ::tk::mac::ReopenApplication {} {
00114
00115 if { [wm state .] == "withdrawn"} {
00116 wm state . normal
00117 raise .
00118 } else {
00119 wm deiconify .
00120 raise .
00121 }
00122
00123 }
00124
00125
00126
00127
00128
00129