From be2e5d6febcea3ec98801f2ba34e50b516b2c73c Mon Sep 17 00:00:00 2001 From: tromey Date: Thu, 4 Oct 2001 15:01:33 +0000 Subject: [PATCH] * 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. --- gdb/gdbtk/ChangeLog | 17 +++++++++++++++ gdb/gdbtk/generic/gdbtk.c | 24 ++++++++++---------- gdb/gdbtk/library/editor.tcl | 47 ++++++++++++++++++++++++++++++++++++++++ gdb/gdbtk/library/prefs.tcl | 3 +++ gdb/gdbtk/library/srcpref.itb | 10 +++++++++ gdb/gdbtk/library/srctextwin.itb | 6 ++--- gdb/gdbtk/library/srcwin.itb | 16 +++++--------- gdb/gdbtk/library/tclIndex | 1 + 8 files changed, 96 insertions(+), 28 deletions(-) create mode 100644 gdb/gdbtk/library/editor.tcl diff --git a/gdb/gdbtk/ChangeLog b/gdb/gdbtk/ChangeLog index 5fedca710a..21d36647d7 100644 --- a/gdb/gdbtk/ChangeLog +++ b/gdb/gdbtk/ChangeLog @@ -1,3 +1,20 @@ +2001-10-02 Tom Tromey + + * 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 * library/console.itb (Console::_operate_and_get_next): New method. diff --git a/gdb/gdbtk/generic/gdbtk.c b/gdb/gdbtk/generic/gdbtk.c index 6c9bc6f455..40d440eb2a 100644 --- a/gdb/gdbtk/generic/gdbtk.c +++ b/gdb/gdbtk/generic/gdbtk.c @@ -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 or --external-editor 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 index 0000000000..b569a31a43 --- /dev/null +++ b/gdb/gdbtk/library/editor.tcl @@ -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 + } + } +} diff --git a/gdb/gdbtk/library/prefs.tcl b/gdb/gdbtk/library/prefs.tcl index bad51466dd..f8809b6391 100644 --- a/gdb/gdbtk/library/prefs.tcl +++ b/gdb/gdbtk/library/prefs.tcl @@ -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 diff --git a/gdb/gdbtk/library/srcpref.itb b/gdb/gdbtk/library/srcpref.itb index 152022c1d2..441358fd4e 100644 --- a/gdb/gdbtk/library/srcpref.itb +++ b/gdb/gdbtk/library/srcpref.itb @@ -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] diff --git a/gdb/gdbtk/library/srctextwin.itb b/gdb/gdbtk/library/srctextwin.itb index a17c9027fb..36bcf03921 100644 --- a/gdb/gdbtk/library/srctextwin.itb +++ b/gdb/gdbtk/library/srctextwin.itb @@ -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 } diff --git a/gdb/gdbtk/library/srcwin.itb b/gdb/gdbtk/library/srcwin.itb index f54c5a47b3..5d9029669f 100644 --- a/gdb/gdbtk/library/srcwin.itb +++ b/gdb/gdbtk/library/srcwin.itb @@ -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 } # ------------------------------------------------------------------ diff --git a/gdb/gdbtk/library/tclIndex b/gdb/gdbtk/library/tclIndex index 2af5c7b4cf..df7a350b6f 100644 --- a/gdb/gdbtk/library/tclIndex +++ b/gdb/gdbtk/library/tclIndex @@ -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]] -- 2.11.0