This is the mail archive of the
insight@sources.redhat.com
mailing list for the Insight project.
[RFA] srcpref fixes
- To: Insight Maling List <insight at sources dot redhat dot com>
- Subject: [RFA] srcpref fixes
- From: "Martin M. Hunt" <hunt at redhat dot com>
- Date: Thu, 18 Oct 2001 01:12:09 -0700
- Organization: Red Hat Inc
Here are the first of my proposed changes to srcprefs. It does the following:
For all widgets, when changes are made, they are not applied, but instead
recorded in an array "_new".
When the APPLY button is clicked, preferences are updated (from _new) and all
windows rebuilt with the changes.
When the CANCEL button is hit, preferences are reverted to what they were
when the dialog was first created. Windows are rebuilt with these values and
the dialog exits.
When the OK button is hit, chnages are applied, windows are updated, and the
dialog exits.
If the user closes the window by some other means, that is interpreted as an
OK.
The tab size spinint works again.
I have similar changes for globalprefs that I will post later.
--
Martin Hunt
GDB Engineer
Red Hat, Inc.
------------------------------
2001-10-18 Martin M. Hunt <hunt@redhat.com>
* library/srcpref.itb (SrcPref::contructor): Move array
initialization to _init_var.
(SrcPref::_init_var): New method to initialize _saved and
_new arrays.
(SrcPref::buildwin): Rename to _buildwin. Have widgets use
_new instead of [pref varname ...]. Set initial value of
tab size spinint.
(SrcPref::_apply): Set prefs with values from the _new array.
(SrcPref::_cancel): Reset disassembly flavor and don't call
_save because nothing is saved unless OK is selected.
(SrcPref::set_flavor): Rename to _set_flavor.
(SrcPref::_pick): Just set _new, not prefs.
* library/srcpref.ith: Add private variable _new and
private method cancel. Rename others with leading underscore.
Index: srcpref.ith
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/srcpref.ith,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 srcpref.ith
--- srcpref.ith 2000/02/07 00:19:42 1.1.1.1
+++ srcpref.ith 2001/10/18 08:06:02
@@ -16,15 +16,19 @@ class SrcPref {
inherit ManagedWin ModalDialog
private {
- variable _saved ;# These are the saved values...
- variable current_disassembly_flavor ""
+ variable _saved ;# These are the saved values...
+ variable _new ;# These are the changed values
+ variable _saved_disassembly_flavor
+ variable _new_disassembly_flavor ""
- method build_win {}
method _apply {}
+ method _build_win {}
method _cancel {}
- method _save {}
- method set_flavor {w new_mode}
+ method _init_var {}
method _pick {color win tag}
+ method _save {}
+ method _set_flavor {w new_mode}
+ method cancel {}
}
public {
Index: srcpref.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/srcpref.itb,v
retrieving revision 1.3
diff -u -p -r1.3 srcpref.itb
--- srcpref.itb 2001/10/04 15:01:36 1.3
+++ srcpref.itb 2001/10/18 08:06:02
@@ -17,30 +17,32 @@
# ------------------------------------------------------------------
body SrcPref::constructor {args} {
window_name "Source Preferences"
+ _init_var
+ _build_win
+}
- build_win
- set saved(gdb/src/PC_TAG) [pref get gdb/src/PC_TAG]
- set saved(gdb/src/STACK_TAG) [pref get gdb/src/STACK_TAG]
- set saved(gdb/src/BROWSE_TAG) [pref get gdb/src/BROWSE_TAG]
- set saved(gdb/src/run_attach) [pref get gdb/src/run_attach]
- set saved(gdb/src/run_load) [pref get gdb/src/run_load]
- set saved(gdb/src/run_run) [pref get gdb/src/run_run]
- set saved(gdb/src/run_cont) [pref get gdb/src/run_cont]
- set saved(gdb/src/bp_fg) [pref get gdb/src/bp_fg]
- set saved(gdb/src/temp_bp_fg) [pref get gdb/src/temp_bp_fg]
- set saved(gdb/src/trace_fg) [pref get gdb/src/trace_fg]
- set saved(gdb/src/thread_fg) [pref get gdb/src/thread_fg]
- set saved(gdb/src/variableBalloons) [pref get gdb/src/variableBalloons]
- 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]
+# ------------------------------------------------------------------
+# METHOD: init_var - initialize preference variables
+# ------------------------------------------------------------------
+body SrcPref::_init_var {} {
+ set vlist {gdb/src/PC_TAG gdb/src/STACK_TAG gdb/src/BROWSE_TAG
+ gdb/src/run_attach gdb/src/run_load gdb/src/run_run
+ gdb/src/run_cont gdb/src/bp_fg gdb/src/temp_bp_fg
+ gdb/src/trace_fg gdb/src/thread_fg gdb/src/variableBalloons
+ gdb/src/source2_fg gdb/src/tab_size gdb/mode gdb/editor
+ gdb/B1_behavior}
+
+ foreach var $vlist {
+ set _saved($var) [pref get $var]
+ set _new($var) $_saved($var)
+ }
}
+
# ------------------------------------------------------------------
# METHOD: build_win - build the dialog
# ------------------------------------------------------------------
-body SrcPref::build_win {} {
+body SrcPref::_build_win {} {
frame $itk_interior.f
frame $itk_interior.f.a
frame $itk_interior.f.b
@@ -100,7 +102,7 @@ body SrcPref::build_win {} {
# Debug Mode frame
Labelledframe $f.rmv.mode -anchor nw -text "Mouse Button-1 Behavior"
set w [$f.rmv.mode get_frame]
- set var [pref varname gdb/B1_behavior]
+
if {[pref get gdb/mode]} {
set state normal
} else {
@@ -108,19 +110,19 @@ body SrcPref::build_win {} {
set state disabled
}
- radiobutton $w.async -text "Set/Clear Tracepoints" -variable $var \
- -value 0 -state $state
- radiobutton $w.sync -text "Set/Clear Breakpoints" -variable $var \
- -value 1 -state $state
-
+ radiobutton $w.async -text "Set/Clear Tracepoints" \
+ -variable [scope _new(gdb/B1_behavior)] -value 0 -state $state
+ radiobutton $w.sync -text "Set/Clear Breakpoints" \
+ -variable [scope _new(gdb/B1_behavior)] -value 1 -state $state
+
pack $w.async $w.sync -side top
# Variable Balloons
Labelledframe $f.rmv.var -anchor nw -text "Variable Balloons"
set w [$f.rmv.var get_frame]
- set var [pref varname gdb/src/variableBalloons]
- radiobutton $w.var_on -text "On " -variable $var -value 1
- radiobutton $w.var_off -text "Off" -variable $var -value 0
+ set var _new(gdb/src/variableBalloons)
+ radiobutton $w.var_on -text "On " -variable [scope $var] -value 1
+ radiobutton $w.var_off -text "Off" -variable [scope $var] -value 0
pack $w.var_on $w.var_off -side top
grid $f.rmv.mode -sticky nsew -pady 5 -row 0 -col 0
grid $f.rmv.var -sticky nsew -pady 5 -row 0 -col 2
@@ -134,9 +136,11 @@ body SrcPref::build_win {} {
# Tab size
itk_component add size {
iwidgets::spinint $f.x.size -labeltext "Tab Size" -range {1 16} \
- -step 1 -fixed 2 -width 2 -textvariable [pref varname
gdb/src/tab_size] \
+ -step 1 -fixed 2 -width 2 -textvariable [scope _new(gdb/src/tab_size)]
\
-wrap 0
}
+ $f.x.size delete 0 end
+ $f.x.size insert end $_saved(gdb/src/tab_size)
# Linenumbers
# commented out because this option isn't really useful
@@ -155,26 +159,26 @@ body SrcPref::build_win {} {
frame $f.dis
label $f.dis.l -text "Disassembly Flavor: "
combobox::combobox $f.dis.combo -maxheight 15 -width 15 -font src-font
-editable 0 \
- -command [code $this set_flavor]
+ -command [code $this _set_flavor]
foreach elem $vals {
$f.dis.combo list insert end $elem
}
- set current_disassembly_flavor [get_disassembly_flavor]
- $f.dis.combo entryset $current_disassembly_flavor
+ set _saved_disassembly_flavor [get_disassembly_flavor]
+ $f.dis.combo entryset $_saved_disassembly_flavor
pack $f.dis.l -side left
pack $f.dis.combo -side left -padx 4
} else {
- set current_disassembly_flavor ""
+ set _saved_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]
+ entry $f.exted.e -width 40 -textvariable [scope _new(gdb/editor)]
pack $f.exted.l -side left
pack $f.exted.e -side left -padx 4
@@ -199,15 +203,25 @@ body SrcPref::build_win {} {
# METHOD: apply - apply changes
# ------------------------------------------------------------------
body SrcPref::_apply {} {
- if {$current_disassembly_flavor != ""} {
- gdb_cmd "set disassembly-flavor $current_disassembly_flavor"
- pref set gdb/src/disassembly-flavor $current_disassembly_flavor
+ foreach var [array names _new] {
+ if {$_new($var) != [pref get $var]} {
+ #debug "$var = $_new($var)"
+ pref set $var $_new($var)
+ }
+ }
+ if {$_new_disassembly_flavor != ""} {
+ gdb_cmd "set disassembly-flavor $_new_disassembly_flavor"
+ pref set gdb/src/disassembly-flavor $_new_disassembly_flavor
}
ManagedWin::restart
}
+body SrcPref::cancel {} {
+ _save
+}
+
# ------------------------------------------------------------------
-# METHOD: cancel
+# METHOD: _cancel
# ------------------------------------------------------------------
body SrcPref::_cancel {} {
set any_changed 0
@@ -219,12 +233,17 @@ body SrcPref::_cancel {} {
pref set $elem $_saved($elem)
}
}
+
+ if {$_new_disassembly_flavor != ""} {
+ set any_changed 1
+ gdb_cmd "set disassembly-flavor $_saved_disassembly_flavor"
+ pref set gdb/src/disassembly-flavor $_saved_disassembly_flavor
+ }
if {$any_changed} {
- _save
- } else {
- unpost
+ ManagedWin::restart
}
+ unpost
}
# ------------------------------------------------------------------
@@ -236,12 +255,12 @@ body SrcPref::_save {} {
}
# ------------------------------------------------------------------
-# METHOD: set_flavor - sets the disassembly flavor. The set
disassembly-flavor
+# METHOD: _set_flavor - sets the disassembly flavor. The set
disassembly-flavor
# gdb command is already known to exist, so I don't have to
check...
# ------------------------------------------------------------------
-body SrcPref::set_flavor {w new_mode} {
+body SrcPref::_set_flavor {w new_mode} {
$w entryset $new_mode
- set current_disassembly_flavor $new_mode
+ set _new_disassembly_flavor $new_mode
}
@@ -251,7 +270,7 @@ body SrcPref::set_flavor {w new_mode} {
body SrcPref::_pick {color win tag} {
set new_color [tk_chooseColor -initialcolor $color -title "Choose color"]
if {$new_color != $color && $new_color != {}} {
- pref set gdb/src/$tag $new_color
+ set _new(gdb/src/$tag) $new_color
$win configure -activebackground $new_color -bg $new_color
}
}