public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Improved menu handling with sessions
@ 2001-08-03 11:46 Keith Seitz
  2001-08-03 14:06 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Keith Seitz @ 2001-08-03 11:46 UTC (permalink / raw)
  To: Insight Maling List

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
   }

   # ------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Improved menu handling with sessions
  2001-08-03 11:46 [PATCH] Improved menu handling with sessions Keith Seitz
@ 2001-08-03 14:06 ` Tom Tromey
  2001-08-03 14:14   ` Keith Seitz
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2001-08-03 14:06 UTC (permalink / raw)
  To: Keith Seitz; +Cc: Insight Maling List

>>>>> "Keith" == Keith Seitz <keiths@cygnus.com> writes:

Keith> Sorry to waste time on this, but this has really been bugging
Keith> me. Ever notice that sessions never appear in the menu until
Keith> you restart insight?

Nice.  Thanks.
I don't think it is a waste of time... but then I wouldn't.

Keith> 	(gdbtk_tcl_exec_file_display): Save the new session, too.
Keith> 	(set_exe_name): Don't bother saving the session here.
Keith> 	(_close_file): Save the session here, too.

I don't understand this part of the change.
Why do this?

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Improved menu handling with sessions
  2001-08-03 14:06 ` Tom Tromey
@ 2001-08-03 14:14   ` Keith Seitz
  0 siblings, 0 replies; 3+ messages in thread
From: Keith Seitz @ 2001-08-03 14:14 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Insight Maling List

On 3 Aug 2001, Tom Tromey wrote:

> Keith> 	(gdbtk_tcl_exec_file_display): Save the new session, too.
> Keith> 	(set_exe_name): Don't bother saving the session here.
> Keith> 	(_close_file): Save the session here, too.
>
> I don't understand this part of the change.
> Why do this?

It's actually pretty simple... We were doing stuff like:

  if {$::gdb_exe_name != ""} { save_sessions }

Side affect: the CURRENT executable is not saved until you EXIT Insight.
The first change (gdbtk_tcl_exec_file, called from the bowels of gdb) adds
the new session to the session list. It shows up in the file menu
immediately. (Maybe this is not correct/ideal?)

The set_exe_name change is now redundant, since gdbtk_tcl_exec_file is
called for all exec file changes.

Finally, we want to save any changes made to the session when we "close"
the session/executable. So any changes we've made get saved.

Got it? (I'm not entirely sure I do.. It took me much longer to figure out
where we need to save the session for this reason or that.0

Keith


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-08-03 14:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-03 11:46 [PATCH] Improved menu handling with sessions Keith Seitz
2001-08-03 14:06 ` Tom Tromey
2001-08-03 14:14   ` Keith Seitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).