This is the mail archive of the
insight@sources.redhat.com
mailing list for the Insight project.
[PATCH] Improved menu handling with sessions
- To: Insight Maling List <insight at sources dot redhat dot com>
- Subject: [PATCH] Improved menu handling with sessions
- From: Keith Seitz <keiths at cygnus dot com>
- Date: Fri, 3 Aug 2001 11:46:50 -0700 (PDT)
Hi,
Sorry to waste time on this, but this has really been bugging me. Ever
notice that sessions never appear in the menu until you restart insight?
Yich.
Keith
ChangeLog
2001-08-03 Keith Seitz <keiths@redhat.com>
* library/srcbar.itcl (_post): New method.
(_update_file_menu): New method.
(create_file_menu): Move the guts to _update_file_menu.
Add a post command to the menu.
* library/interface.tcl (gdbtk_tcl_file_changed): Catch the
call to run_hooks.
(gdbtk_tcl_exec_file_display): Save the new session, too.
(set_exe_name): Don't bother saving the session here.
(_close_file): Save the session here, too.
(gdbtk_clear_file): Catch the call to run_hooks, too.
* library/gdbmenubar.itcl (menubar_new_menu): Allow caller
to specify optional arguments to be passed to Tk when
creating the menu.
Tk's "menu add" command returns an empty string. Save the
menu's index in the parent instead. This is what all
the menu subcommands want.
Patch
Index: gdbmenubar.itcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/gdbmenubar.itcl,v
retrieving revision 1.7
diff -u -p -r1.7 gdbmenubar.itcl
--- gdbmenubar.itcl 2001/02/01 21:03:43 1.7
+++ gdbmenubar.itcl 2001/08/03 18:42:24
@@ -137,13 +137,16 @@ class GDBMenuBar {
# underline - the index of the underlined character for this menu item.
#
# ------------------------------------------------------------------
- private method menubar_new_menu {name label underline} {
+ private method menubar_new_menu {name label underline args} {
+
set current_menu $Menu.$name
- set menu_list($name) [$Menu add cascade -menu $current_menu \
- -label $label -underline $underline]
- menu $current_menu -tearoff 0
- set menu_list($name,label) $label
+ $Menu add cascade -menu $current_menu -label $label \
+ -underline $underline
+ eval menu $current_menu -tearoff 0 $args
+ # Save the index number of this menu. It is always the last one.
+ set menu_list($name) [$Menu index end]
+ set menu_list($name,label) $label
set item_number -1
}
Index: interface.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/interface.tcl,v
retrieving revision 1.27
diff -u -p -r1.27 interface.tcl
--- interface.tcl 2001/07/21 18:44:03 1.27
+++ interface.tcl 2001/08/03 18:42:24
@@ -712,7 +712,7 @@ proc gdbtk_tcl_file_changed {filename} {
if {$filename == ""} {
gdb_clear_file
- run_hooks gdb_clear_file_hook
+ catch {run_hooks gdb_clear_file_hook}
set ::gdb_exe_name ""
set ::gdb_loaded 0
set ::gdb_running 0
@@ -757,6 +757,9 @@ proc gdbtk_tcl_exec_file_display {filena
set_exe_name $filename
set gdb_exe_changed 0
+ # Add this new session to the session list
+ session_save
+
SrcWin::point_to_main
}
@@ -816,10 +819,6 @@ proc set_exe_name {exe} {
global gdb_exe_name gdb_exe_changed
#debug "exe=$exe gdb_exe_name=$gdb_exe_name"
- if {$gdb_exe_name != ""} then {
- session_save
- }
-
set gdb_exe_name $exe
set gdb_exe_changed 1
}
@@ -934,7 +933,7 @@ proc _open_file {{file ""}} {
gdbtk_idle
return 0
}
-
+
return 1
}
@@ -958,6 +957,7 @@ proc _close_file {} {
}
if {$okay} {
+ session_save
gdb_clear_file
gdbtk_tcl_file_changed ""
@@ -1669,7 +1669,7 @@ proc gdbtk_clear_file {} {
debug
# Give widgets a chance to clean up
- run_hooks gdb_clear_file_hook
+ catch {run_hooks gdb_clear_file_hook}
# Save the target name in case the user has already selected a
# target. No need to force the user to select it again.
Index: srcbar.itcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/srcbar.itcl,v
retrieving revision 1.11
diff -u -p -r1.11 srcbar.itcl
--- srcbar.itcl 2001/07/12 23:10:54 1.11
+++ srcbar.itcl 2001/08/03 18:42:24
@@ -84,6 +84,24 @@ class SrcBar {
#destroy $this
}
+
+ # ------------------------------------------------------------------
+ # NAME: private method SrcBar::_post
+ # DESCRIPTION: Post the given menu
+ #
+ # ARGUMENTS:
+ # what - which menu to post
+ # RETURNS: Nothing
+ # ------------------------------------------------------------------
+ private method _post {what} {
+
+ switch $what {
+ file {
+ _update_file_menu
+ }
+ }
+ }
+
####################################################################
# The next set of functions create the common menu groupings that
@@ -122,13 +140,14 @@ class SrcBar {
}
# ------------------------------------------------------------------
- # METHOD: create_file_menu - Creates the standard file menu.
+ # PRIVATE METHOD: _update_file_menu - update the file menu
+ # Used really only to update the session list.
# ------------------------------------------------------------------
-
- private method create_file_menu {} {
- global enable_external_editor tcl_platform
+ private method _update_file_menu {} {
+ global enable_external_editor tcl_platform gdb_exe_name
- $Menu add menubutton file "File" 0
+ # Clear the File menu
+ $Menu clear file
if {[info exists enable_external_editor] && $enable_external_editor} {
$Menu add command None "Edit Source" \
@@ -138,8 +157,13 @@ class SrcBar {
$Menu add command Other "Open..." \
"_open_file" -underline 0 -accelerator "Ctrl+O"
+ if {$gdb_exe_name == ""} {
+ set state disabled
+ } else {
+ set state normal
+ }
$Menu add command Other "Close" \
- "_close_file" -underline 0 -accelerator "Ctrl+W"
+ "_close_file" -underline 0 -accelerator "Ctrl+W" -state $state
$Menu add command Other "Source..." \
"source_file" -underline 0
@@ -179,6 +203,16 @@ class SrcBar {
$Menu add separator
$Menu add command None "Exit" gdbtk_quit -underline 1
+ }
+
+ # ------------------------------------------------------------------
+ # METHOD: create_file_menu - Creates the standard file menu.
+ # ------------------------------------------------------------------
+
+ private method create_file_menu {} {
+
+ $Menu add menubutton file "File" 0 -postcommand [code $this _post file]
+ _update_file_menu
}
# ------------------------------------------------------------------