+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.
}
/*
- * 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);
"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);
--- /dev/null
+# 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
+ }
+ }
+}
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
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]
}
# ------------------------------------------------------------------
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
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]
$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
}
# 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
}
# ------------------------------------------------------------------
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]]