#
# -*- tcl -*-
# <20240427.1533.00>
#
# By putting this in a separate source, if balloon help is off, we will not
# grab the memory it takes.
#
# Since the balloon code (balloonhelp_for) puts these messages in an array
# indexed by the window name, there is no real need to prevent multiple
# calls to this code as long as the first call is not done if the help is
# disabled.
#
# While most balloonhelp_for calls are done here, not all are.

# This is the callback function for fastcheckboxes and middle buttons

proc buttonHelpCB {w args} {
  global buttonHelp
  if {[info exists buttonHelp($w)]} {
    set index [lassign $buttonHelp($w) list]
    if {$list != {}} {
      upvar #0 $list t
      set ret [lindex  $t {*}$index]
      return [list $ret 0]
    } else {
      return [list "No Help for \"[$w cget -text]\"" 0]
    }
  }
  return {""} -1
}

proc setBalloon {} {
  global glob config
  # A bit of paranoia
  if {$config(hoverTime) < 100} {
    set config(hoverTime) 100
  }
  primeBalloonHelp 1 enable 1 delay $config(hoverTime)
  # This takes care of setting up the middle buttons and the fast checkboxes
  # For more general use we could scan ::buttonHelp to build this, but
  # "AT THIS TIME" we only have the following two.
  balloonhelp_for $glob(win,top).menu_frame.fasync_cmds.. "#! buttonHelpCB"
  balloonhelp_for $glob(win,middle).. "#! buttonHelpCB"
  primeBalloonHelp 1 enable 1
  # balloon_help_config enable 1 \
  #     delay $config(hoverTime) \
  #     display $::displays::monitors(monitors)	     
  set wf $glob(win,top).menu_frame
  balloonhelp_for $wf.file_but {[_b "Click it to see..." ]}
  balloonhelp_for $wf.configuration_but {[_b "Click it to see..." ]}
  balloonhelp_for $wf.utils_but {[_b "Click it to see..." ]}
  balloonhelp_for $wf.help_but {[_b "Click it to see..." ]}
  balloonhelp_for $wf.async \
      {[_b "Count of currently running async activities. Color indicates 1 or more."]}
  # balloonhelp_for $wf.clone \
  #     {[_b "Creats a clone of filerunner in the same dirs as this one." ]}
  balloonhelp_for $wf.clock \
      {[_b "Current date & time of day." ]}
  balloonhelp_for $glob(win,top).status \
      {[_b "Status message line.\
          Full info on selected file appears here.\
          Also other progress messages show up here.\
          Spell check 'no errors' shows up here." ]}
  balloonhelp_for $wf.user \
      {[_b "Current user & machine names." ]}
  
  set wscr .fupper.scroll
  foreach ud {up down} {
    balloonhelp_for  $wscr.$ud \
	{[_b "Scroll the center buttons\
          (mouse wheel anywhere on buttons does this too)." ]}
  }
  balloonhelp_for $wscr.fs.mid {[_b "Lock/unlock left/right column order & \
                            8          sizes. If locked, changing one changes both.\n"]}
  foreach {inst ninst} {left right right left} {
    set wft $glob(win,$inst).top
    set wf  $glob(win,$inst).dirmenu_frame
    set w   $glob(win,bottom).fcmdwin$inst
    
    balloonhelp_for $wscr.$inst  "\[_b \"Dup $ninst dir list in $inst.\"]"
    balloonhelp_for $wscr.fs.$inst\
	"\[_b \"Dup $ninst column order and size on $inst.\"]"
    balloonhelp_for $wf.history_but \
	{[_b "Selectable history for both panes."]}
    balloonhelp_for $wf.hotlist_but \
	{[_b "Open a menu of frequently visited locations."]}
    balloonhelp_for $wf.etc_but \
	[_b "Open a menu of %s pane related commands." $inst]
    balloonhelp_for $wf.button_parentdir \
	{[_b "Go to parent directory."]}
    balloonhelp_for $wft.button_back \
	{[_b "Go back thru the push down stack of dir visits." ]}
    balloonhelp_for $wft.button_xterm \
	{[_b "Launch the configuration specified terminal\
          program in a new window." ]}
    balloonhelp_for $wft.button_frterm \
	{[_b "Open/Close a command sub window\
         at the bottom of this one." ]}
    balloonhelp_for $wft.button_update \
	{[_b "Update the directory list." ]}
    balloonhelp_for $wft.stat \
	[_b "\"Number selected\"/\"Total number of files & directories\"\
            = \"Total size of selected\"\"Volume size (if available)\""]
    balloonhelp_for $glob(win,$inst).entry_dir "#! dirLineBalloonHelp"
    
    # balloonhelp_for $glob(win,$inst).frame_listb.top.c "#! dirListBalloonHelp"
    # foreach wx $glob(winlist,color_xx) {
    #   if {[string match *.c.* $wx] && ![string match *.label* $wx]} {
    #     balloonhelp_for $wx "#! dirListBalloonHelp"
    #   }
    # }
    
    balloonhelp_for $glob(win,$inst).frame_listb.top.c..-font "#! dirListBalloonHelp"
    balloonhelp_for $glob(win,$inst).frame_listb.top.c..*label*\
        {[_b "List box entry label." ]}
    
    balloonhelp_for $glob(win,$inst).frame_listb.v.but \
	{[_b "Toggle the selection(s)." ]}

    balloonhelp_for $w.bot.max \
	{[_ "Toggles this command window between maximum and normal size."]}
    balloonhelp_for $w.bot.smaller {[_b "Makes this command window smaller."]}
    balloonhelp_for $w.bot.larger  {[_b "Makes this command window larger."]}
    balloonhelp_for $w.text \
	{[_b "Results of command entered below.
Also used for command completion.
<3>\tBrings up search/save menu."]}
    
    balloonhelp_for $w.bot.entry \
	{[_b "Command entry window. Bindings:
<Return>\tExecute the entered command.
<Tab>\tAttempt command completion.
Second <Tab> or <Cntl d>\tlists\
       possible completions in\
       above window.
<3>\tComplete with browser.
<Cntl c>\tIf empty entry line abort the last\
        command else clear the entry line.
<Up>\tMove back in shell history.
<Down>\tMove forward in shell history.
<Cntl p>\tSearch back in command stack for\
        command using entry as a pattern." ]}
  }
}
proc dirListBalloonHelp {args} {
  global glob
  set en [array get ::config bind*]
  # the command must be in a) glob(buttoncmds) (embedded info 2) or
  #                        b) config(middle_button_list) (possible info in glob(cmds,list) or
  #                        c) a user defined which we will not track down
  # If we find no info...
  set cont {}
  foreach {key ent} $en {
    set tx {}
    if {[set this [lsearch -exact -index 0 -inline $glob(buttoncmds) $ent]] != {}} {
      if {[lindex $this 3] != {}} {continue}
      set tx [lindex $this 2]
    } elseif {[set this [lsearch -exact -index 0 -inline $glob(cmds,list) $ent]] != {}} {
      set tx [subst [lindex $this 4]]
    }
    if {$tx == {}} {set tx $ent}
    append conf "<[regsub -all {bind|\.|,} $key {}]>\t$tx\n"
  }
 
  return  [subst {{[_b "Dir list box. Buttons left <1>, middle <2>, right <3>:
<Shift-1>\tExtend selection from last single selected entry.
<Cntl-1>\tAdd the file under the mouse to the selection.
<drag 1>\tAdd files moved over to the the selection.
<1>\tSelects entry pointed at.
<Control-1>\tAdds or subtracts entry to/from the selection.
<Shift-1>\tExtends the selection.
<Tab>\tMove focus to other window.
<Up>/<Down>\tMove up/down and select.
<Shift-Up>/<Shift-Down>\tExtend the selection.
<PageUp>/<PageDown>\tPage up/down the file list.
<Left>\tOpen parent directory.
<Right>\tDo View command on selected.
<Alt-char>\tDispatched center button command with 'char' underlined.
<Key-Control-char>\tScroll to dirs that start with 'char'. Config(positiondirs)\
true reverses this and <Key-char>.
<Key-char>\tIf config(keyb_support) is on, Dispatch center button command with 'char' underlined, if config(keyb_support) is off, Scroll to files that start with 'char'.
***\t*** Entries below are from the config(bind*) entries ***
$conf
Mouse buttons 1, 2, & 3 combinations are Configurable. See:\
         'Mouse Bindings & menus'." ]} 0 }]
}


proc dirLineBalloonHelp {args} {
  set en [array get ::config bind*]
  set entry [lsearch -exact $en "PopupDir"]
  set result {}
  if {$entry != -1} {
    set result "<[regsub -all {bind|\.|,} [lindex $en $entry-1] {}]>\tDisplay\
               full directory name.\n"
  }
  return [subst {{[_b "Dir line. Follows dir changes. Enter a new dir here if desired.
Also used as input by MkDir and Select buttons.
<1>\tPositions insert cursor just before char under the mouse. Takes focus.
<2>\t(paste) of a file name here will\
open the referenced dir and select the file\
               after following links.
<Double-1>\tMoves to directory under the\
               mouse.
<Key-char>\tInserts 'char' at insertion cursor.
<Home>\tMoves insert cursor to start of entry.
<Control-a>\tSame as <Key-Home>.
<End>\tMoves insert cursor to end of entry.
<Control-e>\tSame as <Key-End>
<BackSpace>\tDeletes the char to the left of the insert cursor.
<Control-h>\tSame as <BackSpace>.
<Delete>\tDeletes char to right of the insert cursor.
<Control-d>\tSame as <Key-Delete>.
<Control-k>\tDeletes all chars to the right of the insert cursor.
<Left>\tMoves the insert cursor to the left.
<Right>\tMoves the insert cursor to the right
***\t*** Entries below are from config(bind*) entries ***
$result
Mouse buttons 1, 2, & 3 combinations are Configurable. See:\
         'Mouse Bindings & menus'."]  } 0 }]
}
            
