#!/afs/ece/usr/tcl/bin/wish -f

foreach pair {{get_widget aux/teach.tcl}} {
  if {[info procs [lindex $pair 0]] == ""} {
    source "[file dirname [info script]]/../[lindex $pair 1]"
}}


# Help text.
set Help "" ; append Help {Menusplith -- Split Long Menus

Ever had a menu so long it fell off the screen? (Yes, Tk tries to prevent this,
but it still happens, expecially with menus that constantly grow over time...)

This tool is useful for breaking up long menus in any application. All you have
to do is click on 'Split', and then click on the remote menu, and it gets
reduced down to a manageable size. (To be precise, all the extra menuentries get
moved into cascade menus, so all your menuentries remain intact; they're just
distributed in a bunch of different submenus.)


Widgets of Menusplith

The Teach Menu

  Split

Click on the Split entry in the Teach menu to break up a menu. After Split is
pressed, click on the menu to split it. Or click on a menubutton, and its menu
will get split.


The Maximum Size Scale

This sets the maximum number of items per menu. It gets set to whatever argument
you pass to menusplith.

} $TH_Help {

Bugs / Limitations

None
(I hope!)
}

proc split_menu {} {
  if {![get_widget]} {th_beep ; return}
  global TH_Dir Max_Menu_Size App Widget Class
  switch $Class {
    Menubutton {
      set menu [lindex [send $App $Widget configure -menu] 4]
    } Menu {set menu $Widget
    } default {th_beep ; return}
  }
  clear_output
  include_files {common.tcl th_gensym} \
	{menusplit.tcl th_split_menu}
  do_cmd "th_split_menu $menu $Max_Menu_Size\n" 0
}


create_form_scale .s "Maximum Menu Size" Max_Menu_Size 10 -from 2 -to 100
.buttons.teach.m add command -label Split -command "split_menu"


