From mboxrd@z Thu Jan 1 00:00:00 1970 From: Keith Seitz To: "Martin M. Hunt" Cc: Insight Maling List Subject: Re: [RFA] globalpref fixes Date: Sun, 04 Nov 2001 10:52:00 -0000 Message-id: References: <200111022341.PAA13481@cygnus.com> X-SW-Source: 2001-q4/msg00264.html On Fri, 2 Nov 2001, Martin M. Hunt wrote: > Haven't seen approval for this yet. Thanks for the reminder. Please check this in. Thanks! Keith > ---------- Forwarded Message ---------- > > Subject: [RFA] globalpref fixes > Date: Thu, 18 Oct 2001 12:46:07 -0700 > From: "Martin M. Hunt" > To: Insight Mailing List > > More preferences cleanup. > > - OK, APPLY, CANCEL work same as for srcprefs. > > - The font code that gets the initial list of fonts has been changed. On my > system it took 35 seconds and now takes less than 3. Most of the problem was > due to font metric queries taking up to several seconds on some troublesome > fonts. Selecting some of those fonts (like "song ti" on RH7.1) causes > Insight to hang anyway. So I now have those fonts removed from the list. I > also sort the list. > > - All private variables and methods renamed to start with an underscore. > > -- > Martin Hunt > GDB Engineer > Red Hat, Inc. > > 2001-10-18 Martin M. Hunt > > * library/globalpref.itb (GlobalPref::_init_var): > New method to initialize _saved and _new arrays. > (GlobalPref::constructor): Call _init_var. > (GlobalPref::_buildwin): Use _new array for prefs > variables. Font optimizations. Remove troublesome > fonts and sort the list. > (GlobalPref::toggle_tracing_mode): Removed. Some > functionality moved to _apply and _cancel. > (GlobalPref::_apply): Set prefs with values from the > _new array. > (SrcPref::_cancel): Reset prefs with values from _saved. > > * library/globalpref.ith: Changed private variables > and methods to start with underscore. > (tracing_cb): Removed. > (_init): Changed from proc to method. > > Index: globalpref.ith > =================================================================== > RCS file: /cvs/src/src/gdb/gdbtk/library/globalpref.ith,v > retrieving revision 1.2 > diff -u -p -r1.2 globalpref.ith > --- globalpref.ith 2001/08/16 18:55:50 1.2 > +++ globalpref.ith 2001/10/18 19:37:57 > @@ -16,31 +16,32 @@ class GlobalPref { > inherit ManagedWin ModalDialog > > private { > - variable icondirlist "" > - variable Original ;# Original settings > + variable _new > + variable _saved > + variable _icondirlist "" > + variable _original ;# Original font settings > variable _size ;# Array tracking spinint values > - variable Fonts ;# List of all available fonts for editing > + variable _fonts ;# List of all available fonts for editing > common tracing_labels > common inited 0 > - variable tracing_cb > > - proc _init {} > - method build_win {} > - method make_font_item {f name label font_list} > - method resize_font_item_height {} > - method change_icons {w args} > + method _init {} > + method _init_var {} > + method _build_win {} > + method _make_font_item {f name label font_list} > + method _resize_font_item_height {} > + method _change_icons {w args} > method _change_font {font stupid implementation} > method _change_size {direction font} > - method toggle_tracing_mode {} > - method ok {} > - method apply {{deleteMe 0}} > + method _ok {} > + method _apply {{deleteMe 0}} > + method _cancel {} > method cancel {} > - method toggle_tracing {win} > + method _toggle_tracing {win} > } > > public { > method constructor {args} > method destructor {} > } > - > } > Index: globalpref.itb > =================================================================== > RCS file: /cvs/src/src/gdb/gdbtk/library/globalpref.itb,v > retrieving revision 1.5 > diff -u -p -r1.5 globalpref.itb > --- globalpref.itb 2001/08/16 18:55:50 1.5 > +++ globalpref.itb 2001/10/18 19:37:57 > @@ -18,7 +18,7 @@ > # ---------------------------------------------------------------------- > > # ------------------------------------------------------------------ > -# PROC: _init - set up the tracing labels info > +# METHOD: _init - set up the tracing labels info > # ------------------------------------------------------------------ > body GlobalPref::_init {} { > if {$inited} { > @@ -41,12 +41,26 @@ body GlobalPref::_init {} { > } > > # ------------------------------------------------------------------ > +# METHOD: init_var - initialize preference variables > +# ------------------------------------------------------------------ > +body GlobalPref::_init_var {} { > + set vlist {gdb/ImageDir gdb/console/wrap gdb/mode > + gdb/help/browser gdb/use_icons} > + > + foreach var $vlist { > + set _saved($var) [pref get $var] > + set _new($var) $_saved($var) > + } > +} > + > +# ------------------------------------------------------------------ > # METHOD: constructor - create the Global Preferences object > # ------------------------------------------------------------------ > body GlobalPref::constructor {args} { > window_name "Global Preferences" > _init > - build_win > + _init_var > + _build_win > eval itk_initialize $args > } > > @@ -54,15 +68,15 @@ body GlobalPref::constructor {args} { > # METHOD: destructor - destroy the Global Preferences object > # ------------------------------------------------------------------ > body GlobalPref::destructor {} { > - foreach thunk $Fonts { > + foreach thunk $_fonts { > font delete test-$thunk-font > } > } > > # ------------------------------------------------------------------ > -# METHOD: build_win - build the dialog > +# METHOD: _build_win - build the dialog > # ------------------------------------------------------------------ > -body GlobalPref::build_win {} { > +body GlobalPref::_build_win {} { > global tcl_platform GDBTK_LIBRARY > debug > frame $itk_interior.f > @@ -73,23 +87,22 @@ body GlobalPref::build_win {} { > frame $frame.icons > label $frame.icons.lab -text "Icons " > combobox::combobox $frame.icons.cb -editable 0 -maxheight 10\ > - -command [code $this change_icons] > + -command [code $this _change_icons] > > # get list of icon directories > set curdir [pwd] > - set icondirlist "" > + set _icondirlist "" > cd $GDBTK_LIBRARY > foreach foo [glob -- *] { > if {[file isdirectory $foo] && [file exists [file join $foo > "icons.txt"]]} { > - lappend icondirlist $foo > + lappend _icondirlist $foo > } > } > > set width 14 > # load combobox > - set imagedir [pref get gdb/ImageDir] > - foreach dir $icondirlist { > - if {![string compare $dir $imagedir]} { > + foreach dir $_icondirlist { > + if {![string compare $dir $_saved(gdb/ImageDir)]} { > set cdir 1 > } else { > set cdir 0 > @@ -121,6 +134,22 @@ body GlobalPref::build_win {} { > # to rescan the font list, without deleting the entry from the > # init file. > set font_cache [pref get gdb/font_cache] > + > + # get list of fonts, removing some that typically > + # are not useful or cause tk problems > + set fam [lremove [font families] "open look glyph"] > + set fam [lremove $fam "open look cursor"] > + set fam [lremove $fam "song ti"] > + set fam [lremove $fam "clearlyu"] > + set fam [lremove $fam "clearlyu alternate glyphs"] > + set fam [lremove $fam "clearlyu arabic extra"] > + set fam [lremove $fam "clearlyu ligature"] > + set fam [lremove $fam "clearlyu pua"] > + set fam [lremove $fam "fangsong ti"] > + set fam [lremove $fam "newspaper"] > + set fam [lremove $fam "palatino linotype"] > + set fam [lsort $fam] > + > if {$font_cache == ""} { > if {$tcl_platform(platform) == "unix"} { > toplevel .c > @@ -135,40 +164,40 @@ body GlobalPref::build_win {} { > > ::raise .c > ::update > > } > - set fam [font families] > + > foreach fn $fam { > if {[font metrics [list $fn] -fixed] == 1} { > lappend font_cache $fn > } > } > pref set gdb/font_cache $font_cache > - if {$tcl_platform(platform) == "unix"} { destroy .c } > + if {[winfo exists .c]} { destroy .c } > } > > Labelledframe $frame.d -text "Fonts" > set f [$frame.d get_frame] > > - make_font_item $f fixed "Fixed Font:" $font_cache > + _make_font_item $f fixed "Fixed Font:" $font_cache > > if {$tcl_platform(platform) != "windows"} { > # Cannot change the windows menu font ourselves > - make_font_item $f menu "Menu Font:" [font families] > + _make_font_item $f menu "Menu Font:" $fam > } > > - make_font_item $f default "Default Font:" [font families] > - make_font_item $f status "Status Bar Font:" [font families] > + _make_font_item $f default "Default Font:" $fam > + _make_font_item $f status "Status Bar Font:" $fam > > # This is the tracing preference > set tracing_cb [pref get gdb/mode] > if { ![info exists tracing_labels($tracing_cb)]} { > - debug "Got unknown mode value: $tracing_cb" > + dbug E "Got unknown mode value: $tracing_cb" > set tracing_labels($tracing_cb) "Unknown gdb mode..." > } > > frame $frame.tracing > - checkbutton $frame.tracing.cb -variable [scope tracing_cb] \ > + checkbutton $frame.tracing.cb -variable [scope _new(gdb/mode)] \ > -text $tracing_labels($tracing_cb) \ > - -command [code $this toggle_tracing $frame.tracing.cb] \ > + -command [code $this _toggle_tracing $frame.tracing.cb] \ > -width $tracing_labels(max_len) -anchor w > pack $frame.tracing.cb -pady 10 -side left -fill none > > @@ -180,21 +209,21 @@ body GlobalPref::build_win {} { > } > frame $frame.browser > checkbutton $frame.browser.cb \ > - -text $help_text -variable [pref varname gdb/help/browser] > + -text $help_text -variable [scope _new(gdb/help/browser)] > pack $frame.browser.cb -pady 10 -side left -fill none > > # use_icons > if {$tcl_platform(platform) == "unix"} { > frame $frame.use_icons > checkbutton $frame.use_icons.cb \ > - -text "Use builtin image as icon." -variable [pref varname > gdb/use_icons] > + -text "Use builtin image as icon." -variable [scope > _new(gdb/use_icons)] > pack $frame.use_icons.cb -pady 10 -side left -fill none > } > > # console wrap > frame $frame.consolewrap > checkbutton $frame.consolewrap.cw -text "wrap text in console window" \ > - -variable [pref varname gdb/console/wrap] > + -variable [scope _new(gdb/console/wrap)] > pack $frame.consolewrap.cw -pady 10 -side left -fill none > > pack $frame.icons.lab $frame.icons.cb -side left > @@ -208,9 +237,9 @@ body GlobalPref::build_win {} { > pack $frame.d -side top -fill both -expand yes > > # make buttons > - button $itk_interior.x.ok -text OK -underline 0 -width 7 -command [code > $this ok] > - button $itk_interior.x.apply -text Apply -width 7 -underline 0 -command > [code $this apply] > - button $itk_interior.x.cancel -text Cancel -width 7 -underline 0 -command > [code $this cancel] > + button $itk_interior.x.ok -text OK -underline 0 -width 7 -command [code > $this _ok] > + button $itk_interior.x.apply -text Apply -width 7 -underline 0 -command > [code $this _apply] > + button $itk_interior.x.cancel -text Cancel -width 7 -underline 0 -command > [code $this _cancel] > pack $itk_interior.x.ok $itk_interior.x.apply $itk_interior.x.cancel -side > left > standard_button_box $itk_interior.x > pack $itk_interior.x -fill x -padx 5 -pady 5 -side bottom > @@ -226,25 +255,25 @@ body GlobalPref::build_win {} { > > ::update idletasks > > - resize_font_item_height > + _resize_font_item_height > pack propagate $itk_interior.f 0 > > } > # ------------------------------------------------------------------ > -# PRIVATE METHOD: make_font_item > +# PRIVATE METHOD: _make_font_item > # ------------------------------------------------------------------ > -body GlobalPref::make_font_item {f name label font_list} { > +body GlobalPref::_make_font_item {f name label font_list} { > > # create ComboBox with font name > - lappend Fonts $name > + lappend _fonts $name > > - set Original($name,family) [font actual global/$name -family] > - set Original($name,size) [font actual global/$name -size] > - font create test-$name-font -family $Original($name,family) \ > - -size $Original($name,size) > + set _original($name,family) [font actual global/$name -family] > + set _original($name,size) [font actual global/$name -size] > + font create test-$name-font -family $_original($name,family) \ > + -size $_original($name,size) > label $f.${name}x -text $label > > - combobox::combobox $f.${name}n -editable 0 -value $Original($name,family) > \ + combobox::combobox $f.${name}n -editable 0 -value > $_original($name,family) \ > -command [code $this _change_font $name] > > foreach a $font_list { > @@ -258,17 +287,17 @@ body GlobalPref::make_font_item {f name > -decrement [code $this _change_size down $name] > } {} > label $f.${name}l -text ABCDEFabcdef0123456789 -font test-$name-font > - set _size($name) $Original($name,size) > + set _size($name) $_original($name,size) > > grid $f.${name}x $f.${name}n $f.${name}s $f.${name}l -sticky we -padx 5 > -pady 5 > grid columnconfigure $f 3 -weight 1 > } > > # ------------------------------------------------------------------ > -# PRIVATE METHOD: resize_font_item_height > +# PRIVATE METHOD: _resize_font_item_height > # ------------------------------------------------------------------ > -body GlobalPref::resize_font_item_height {} { > - foreach font $Fonts { > +body GlobalPref::_resize_font_item_height {} { > + foreach font $_fonts { > set master [$itk_interior.f.d get_frame] > set row [gridCGet $master.${font}l -row] > grid rowconfigure $master $row -minsize [lindex [grid bbox $master 0 > $row 3 $row ] 3] > @@ -276,16 +305,13 @@ body GlobalPref::resize_font_item_height > } > > # ------------------------------------------------------------------ > -# PRIVATE METHOD: change_icons > +# PRIVATE METHOD: _change_icons > # ------------------------------------------------------------------ > -body GlobalPref::change_icons {w args} { > - global gdb_ImageDir GDBTK_LIBRARY > +body GlobalPref::_change_icons {w args} { > + debug > set index [$w list curselection] > if {$index != ""} { > - set dir [lindex $icondirlist $index] > - pref set gdb/ImageDir $dir > - set gdb_ImageDir [file join $GDBTK_LIBRARY $dir] > - ManagedWin::restart > + set _new(gdb/ImageDir) [lindex $_icondirlist $index] > } > } > > @@ -328,34 +354,25 @@ body GlobalPref::_change_size {direction > font configure test-$font-font -size $_size($font) > } > > -# ------------------------------------------------------------------ > -# METHOD: toggle_tracing_mode - toggles the tracing mode on and off > -# ------------------------------------------------------------------ > -body GlobalPref::toggle_tracing_mode {} { > - pref set gdb/mode $tracing_cb > - # Reset the button-1 behavior if you are going out of trace mode. > - if {!$tracing_cb} { > - pref set gdb/B1_behavior 1 > - } > -} > > -body GlobalPref::toggle_tracing {win} { > - debug foo > - $win configure -text $tracing_labels($tracing_cb) > +body GlobalPref::_toggle_tracing {win} { > + debug > + $win configure -text $tracing_labels($_new(gdb/mode)) > } > > # ------------------------------------------------------------------ > -# METHOD: ok - called to accept settings and close dialog > +# METHOD: _ok - called to accept settings and close dialog > # ------------------------------------------------------------------ > -body GlobalPref::ok {} { > - apply 1 > +body GlobalPref::_ok {} { > + _apply 1 > } > > # ------------------------------------------------------------------ > -# METHOD: apply - apply current settings to the screen > +# METHOD: _apply - apply current settings to the screen > # ------------------------------------------------------------------ > -body GlobalPref::apply {{deleteMe 0}} { > - set commands {} > +body GlobalPref::_apply {{deleteMe 0}} { > + debug > + set changed_something 0 > > # If you are not destroying the window, then make sure to > # propagate the geometry info from the font frame, so that changing > @@ -366,61 +383,90 @@ body GlobalPref::apply {{deleteMe 0}} { > pack propagate $itk_interior.f 1 > } > > - foreach thunk $Fonts { > + foreach thunk $_fonts { > set font [font configure test-$thunk-font] > if {[pref get global/font/$thunk] != $font} { > - lappend commands [list pref set global/font/$thunk $font] > + pref set global/font/$thunk $font > + set changed_something 1 > } > } > > - if {[pref get gdb/mode] != $tracing_cb} { > - lappend commands toggle_tracing_mode > + foreach var [array names _new] { > + if {$_new($var) != [pref get $var]} { > + debug "$var = $_new($var)" > + > + if {$var == "gdb/mode"} { > + if {!$_new(gdb/mode)} { pref set gdb/B1_behavior 1 } > + } elseif {$var == "gdb/ImageDir"} { > + set ::gdb_ImageDir [file join $::GDBTK_LIBRARY $_new($var)] > + } > + pref set $var $_new($var) > + set changed_something 1 > + } > } > > - if {[llength $commands] > 0} { > - foreach command $commands { > - eval $command > - } > - if {$deleteMe} { > - unpost > - } > + if {$changed_something} { > + if {$deleteMe} { unpost } > ManagedWin::restart > return > } > - if {$deleteMe} { > - unpost > + if {$deleteMe} { > + unpost > } else { > after idle " > update idletasks > - [code $this resize_font_item_height] > + [code $this _resize_font_item_height] > pack propagate $itk_interior.f 0 > " > } > } > > # ------------------------------------------------------------------ > -# METHOD: cancel - forget current settings -- reset to original > +# METHOD: _cancel - forget current settings -- reset to original > # state and close preferences > # ------------------------------------------------------------------ > -body GlobalPref::cancel {} { > +body GlobalPref::_cancel {} { > + debug > + set changed_something 0 > + > # Reset fonts if different > - set commands {} > - foreach thunk $Fonts { > + foreach thunk $_fonts { > set family [font configure global/$thunk -family] > set size [font configure global/$thunk -size] > - if {$Original($thunk,family) != $family || $Original($thunk,size) != > $size} { > - lappend commands [list pref set global/font/$thunk \ > - [list -family $Original($thunk,family) -size $Original($thunk,size)]] > + if {$_original($thunk,family) != $family || $_original($thunk,size) != > $size} { > + pref set global/font/$thunk \ > + [list -family $_original($thunk,family) -size $_original($thunk,size)] > + set changed_something 1 > } > } > > - if {[llength $commands] > 0} { > - foreach command $commands { > - eval $command > + foreach var [array names _saved] { > + if {$_saved($var) != [pref get $var]} { > + debug "$var = $_saved($var)" > + > + if {$var == "gdb/mode"} { > + if {!$_saved(gdb/mode)} { pref set gdb/B1_behavior 1 } > + } elseif {$var == "gdb/ImageDir"} { > + set ::gdb_ImageDir [file join $::GDBTK_LIBRARY $_saved($var)] > + } > + pref set $var $_saved($var) > + set changed_something 1 > } > } > - if {[llength $commands] > 0} { > + > + if {$changed_something} { > ManagedWin::restart > } > unpost > +} > + > +# ------------------------------------------------------------------ > +# METHOD: cancel - override modal dialog cancel method. > +# The cancel method is actually called when > +# the window is closed. Name needs fixed. > +# ------------------------------------------------------------------ > +body GlobalPref::cancel {} { > + # when the window is closed, we want the preferences selected to > + # be applied. > + _apply 1 > } > > ------------------------------------------------------- > > -- > Martin Hunt > GDB Engineer > Red Hat, Inc. >