OSDN Git Service

* library/tclIndex: Updated.
authortromey <tromey>
Thu, 4 Oct 2001 15:01:33 +0000 (15:01 +0000)
committertromey <tromey>
Thu, 4 Oct 2001 15:01:33 +0000 (15:01 +0000)
* library/prefs.tcl (pref_set_defaults): Define gdb/editor
preference.
* library/srcpref.itb (SrcPref::constructor): Save gdb/editor
preference.
(SrcPref::build_win): Added external editor control.
* library/srctextwin.itb (SrcTextWin::do_source_popup): Always
enable external editor.  Use `code' instead of `list'.
* library/srcwin.itb (SrcWin::edit): Use Editor::edit.
* library/editor.tcl: New file.
* generic/gdbtk.c (enable_external_editor): Removed.
(external_editor_command): Default to NULL.
(gdbtk_init): Don't set enable_external_editor.  Free external
editor command when finished with it.

gdb/gdbtk/ChangeLog
gdb/gdbtk/generic/gdbtk.c
gdb/gdbtk/library/editor.tcl [new file with mode: 0644]
gdb/gdbtk/library/prefs.tcl
gdb/gdbtk/library/srcpref.itb
gdb/gdbtk/library/srctextwin.itb
gdb/gdbtk/library/srcwin.itb
gdb/gdbtk/library/tclIndex

index 5fedca7..21d3664 100644 (file)
@@ -1,3 +1,20 @@
+2001-10-02  Tom Tromey  <tromey@redhat.com>
+
+       * library/tclIndex: Updated.
+       * library/prefs.tcl (pref_set_defaults): Define gdb/editor
+       preference.
+       * library/srcpref.itb (SrcPref::constructor): Save gdb/editor
+       preference.
+       (SrcPref::build_win): Added external editor control.
+       * library/srctextwin.itb (SrcTextWin::do_source_popup): Always
+       enable external editor.  Use `code' instead of `list'.
+       * library/srcwin.itb (SrcWin::edit): Use Editor::edit.
+       * library/editor.tcl: New file.
+       * generic/gdbtk.c (enable_external_editor): Removed.
+       (external_editor_command): Default to NULL.
+       (gdbtk_init): Don't set enable_external_editor.  Free external
+       editor command when finished with it.
+
 2001-09-28  Tom Tromey  <tromey@redhat.com>
 
        * library/console.itb (Console::_operate_and_get_next): New method.
index 6c9bc6f..40d440e 100644 (file)
@@ -83,15 +83,10 @@ x_event_wrapper (signo)
 }
 
  /*
-  * These two variables control the interaction with an external editor.
-  * If enable_external_editor is set at startup, BEFORE Gdbtk_Init is run
-  * then the Tcl variable of the same name will be set, and a command will
-  * called external_editor_command will be invoked to call out to the
-  * external editor.  We give a dummy version here to warn if it is not set.
+  * This variable controls the interaction with an external editor.
   */
-int enable_external_editor = 0;
-char *external_editor_command = "tk_dialog .warn-external \\\n\
-\"No command is specified.\nUse --tclcommand <tcl/file> or --external-editor <cmd> to specify a new command\" 0 Ok";
+
+char *external_editor_command = NULL;
 
 extern int Tktable_Init (Tcl_Interp * interp);
 
@@ -585,13 +580,16 @@ gdbtk_init (argv0)
           "Send a command directly into tk.");
 
   /*
-   * Set the variables for external editor:
+   * Set the variable for external editor:
    */
 
-  Tcl_SetVar (gdbtk_interp, "enable_external_editor",
-             enable_external_editor ? "1" : "0", 0);
-  Tcl_SetVar (gdbtk_interp, "external_editor_command",
-             external_editor_command, 0);
+  if (external_editor_command != NULL)
+    {
+      Tcl_SetVar (gdbtk_interp, "external_editor_command",
+                 external_editor_command, 0);
+      xfree (external_editor_command);
+      external_editor_command = NULL;
+    }
 
   /* close old output and send new to GDBTK */
   ui_file_delete (gdb_stdout);
diff --git a/gdb/gdbtk/library/editor.tcl b/gdb/gdbtk/library/editor.tcl
new file mode 100644 (file)
index 0000000..b569a31
--- /dev/null
@@ -0,0 +1,47 @@
+# Editor
+# Copyright 2001 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) as published by
+# the Free Software Foundation; either version 2 of the License, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# ----------------------------------------------------------------------
+# Implements a set of editor commands
+# ----------------------------------------------------------------------
+
+namespace eval Editor {
+  namespace export edit
+
+  proc edit {loc_info} {
+    global external_editor_command
+
+    if {[info exists external_editor_command]} {
+      if {[catch {uplevel \#0 "$external_editor_command edit $loc_info"} \
+            err]} {
+       tk_dialog .warn-sn "Edit" $err error 0 Ok
+      }
+      return
+    }
+
+    lassign $loc_info baseName fnName fileName lineNum addr pc
+
+    set newCmd [pref get gdb/editor]
+    if {! [string compare $newCmd ""]} {
+      tk_dialog .warn "Edit" "No editor command specified" error 0 Ok
+    }
+
+    # Replace %s with file name and %d with line number.
+    regsub -all -- %s $newCmd $fileName newCmd
+    regsub -all -- %d $newCmd $lineNum newCmd
+
+    if {[catch "exec $newCmd &" err]} {
+      tk_dialog .warn "Edit" $err error 0 Ok
+    }
+  }
+}
index bad5146..f8809b6 100644 (file)
@@ -409,6 +409,9 @@ proc pref_set_defaults {} {
   pref define gdb/mem/ascii_char .
   pref define gdb/mem/bytes_per_row 16
   pref define gdb/mem/color green
+
+  # External editor.
+  pref define gdb/editor ""
 }
 
 # This traces the global/fixed font and forces src-font to
index 152022c..441358f 100644 (file)
@@ -34,6 +34,7 @@ body SrcPref::constructor {args} {
   set saved(gdb/src/source2_fg)       [pref get gdb/src/source2_fg]
   set saved(gdb/src/tab_size)         [pref get gdb/src/tab_size]
   set saved(gdb/mode)                 [pref get gdb/mode]
+  set saved(gdb/editor)                      [pref get gdb/editor]
 }
 
 # ------------------------------------------------------------------
@@ -170,6 +171,13 @@ body SrcPref::build_win {} {
     set current_disassembly_flavor ""
   }
 
+  # External editor.
+  frame $f.exted
+  label $f.exted.l -text "External Editor: "
+  entry $f.exted.e -width 40 -textvariable [pref varname gdb/editor]
+  pack $f.exted.l -side left
+  pack $f.exted.e -side left -padx 4
+
   pack $f.colors -fill both -expand 1
   pack $f.rmv  -fill both -expand yes
   pack $f.x -fill x -expand yes
@@ -178,6 +186,8 @@ body SrcPref::build_win {} {
     pack $f.dis -side top -fill x -padx 4
   }
 
+  pack $f.exted -side top -fill x -padx 4 -pady 4
+
   button $itk_interior.f.b.ok -text OK -width 7 -underline 0 -command [code $this _save]
   button $itk_interior.f.b.apply -text Apply -width 7 -underline 0 -command [code $this _apply]
   button $itk_interior.f.b.quit -text Cancel -width 7 -underline 0 -command [code $this _cancel]
index a17c902..36bcf03 100644 (file)
@@ -2138,10 +2138,8 @@ body SrcTextWin::do_source_popup { X Y x y } {
 
   $popups(source) add command -label "Open Another Source Window" \
     -command {ManagedWin::open SrcWin -force}
-  if {[info exists ::enable_external_editor] && $::enable_external_editor} {
-    $popups(source) add command -label "Open Source in external editor" \
-      -command [list $parent edit]
-  }
+  $popups(source) add command -label "Open Source in external editor" \
+    -command [code $parent edit]
 
   tk_popup $popups(source) $X $Y 
 }
index f54c5a4..5d90296 100644 (file)
@@ -684,26 +684,20 @@ body SrcWin::set_execution_status { {line ""} {pc ""}} {
 #  PUBLIC METHOD:  edit - invoke external editor
 # ------------------------------------------------------------------
 body SrcWin::edit {} {
-  global enable_external_editor external_editor_command
+  global external_editor_command
   # If external editor is enabled, pass the file to the specified command
-    
+
   if {$current(filename) == ""} {
     tk_dialog .warn {Edit} {No file is loaded in the source window.} error 0 Ok
     return
   }
-  
+
   if {[catch {$twin report_source_location} loc_info]} {
     tk_dialog .warn "Edit" "No source file selected" error 0 Ok
     return
   }
-  
-  
-  if {[info exists enable_external_editor] && $enable_external_editor} {
-    if {[catch {uplevel \#0 "$external_editor_command edit $loc_info"} ]} {
-      tk_dialog .warn-sn "Edit" $err error 0 Ok
-    }
-    return
-  }  
+
+  Editor::edit $loc_info
 }
 
 # ------------------------------------------------------------------
index 2af5c7b..df7a350 100644 (file)
@@ -602,3 +602,4 @@ set auto_index(::TargetSelection::set_run) [list source [file join $dir targetse
 set auto_index(::TargetSelection::target_trace) [list source [file join $dir targetselection.itb]]
 set auto_index(::TargetSelection::valid_target) [list source [file join $dir targetselection.itb]]
 set auto_index(::TargetSelection::native_debugging) [list source [file join $dir targetselection.itb]]
+set auto_index(::Editor::edit) [list source [file join $dir editor.tcl]]