The bartabs Tcl/Tk package provides a bar widget containing tabs that are
The bartabs defines three TclOO classes:
However, only the Bars class is used to create bars along with tabs. It can be also used to deal with any bars and tabs, providing all necessary interface.
The Bar does not create a real TclOO object, rather it provides syntax sugar for a convenient access to the bar methods.
The Tab does not create a real TclOO object as well. It serves actually for structuring bartabs code as for tab methods. Thus, its methods are accessible through the Bars ("real" TclOO) and Bar ("sugar") objects.
A common work flow with bartabs looks like this:
Firstly, we create a Bars object, e.g.
bartabs::Bars create NS::bars
Then we create a Bar object, e.g.
NS::bars create NS::bar $barOptions
If a tab of the bar should be displayed (with its possible contents), we show the bar and select the current tab:
set TID [NS::bar tabID "tab label"] ;# get the tab's ID by its label
NS::bar $TID show ;# show the bar and select the tab
or just draw the bar without mind-breaking about a tab:
NS::bar draw ;# show the bar without selecting a tab
The rest actions include:
-csel command
option of Bar object)-cdel command
option of Bar object)-cmov command
option of Bar object)cget
and configure
methods to change the bar/tab appearanceThe methods of Tab class are called from Bars or Bar object and are passed: tab ID (TID), method name, arguments. Syntax:
OBJECT TID method arguments
For example: NS::bars $TID close
or NS::bar $TID show false
The methods of Bar class are called from Bar object or (more wordy) from Bars object. Syntax:
BAR_OBJECT method arguments
BARS_OBJECT BID method arguments
For example: NS::bar popList $X $Y
or NS::bars $BID popList $X $Y
The methods of Bars class need no TID nor BID, though not protesting them passed before method name. Syntax:
BARS_OBJECT method arguments
For example:
NS::bars drawAll ;# good boy
NS::bars tab11 drawAll ;# bad boy uses the useless tab11 (TID)
NS::bars bar1 drawAll ;# bad boy's BID is useless as well
There are three "virtual" methods:
NS::bar create NS::tab $label
creates a tab object NS::tab for a tab labeled $label
to access the tab methods, e.g. NS::tab show
NS::tab cget $option
gets an option of tab, e.g. NS::tab cget -text
NS::tab configure $option $value
sets an option of tab, e.g. NS::tab configure -text "new label"
Few words about BID and TID mentioned throughout the bartabs.
These are identifiers of bars and tabs, of form bar<index>
and tab<index>
where <index>
is integer increased from 0 in order of bar/tab creation. The bars and the tabs of all bars have unique IDs.
You can use these literals freely, along with BIDs and TIDs gotten from bartabs methods. For example, if you know that "some tab" was created third, you can show it straightforward:
NS::bar tab2 show ;# show the 3rd tab (TID=tab2)
instead of
NS::bar [NS::bar tabID "some tab"] show ;# find and show the tab by its name
Reference on baltip (package used by bartabs)
Draws all bars. Used at updating themes etc.
proc ::bartabs::drawAll {} { # Draws all bars. Used at updating themes etc. foreach bars $::bartabs::BarsList {$bars drawAll} }
Runs Tk's or apave's ok/yes/no/cancel dialogue.
| ok, yesno or yesnocancel |
| message |
| Not documented. |
| additional arguments of tk_messageBox |
Returns 1 if 'yes' chosen, 2 if 'no', 0 otherwise.
proc ::bartabs::messageBox {type ttl msg args} { # Runs Tk's or apave's ok/yes/no/cancel dialogue. # type - ok, yesno or yesnocancel # ttl - title # ttl - message # args - additional arguments of tk_messageBox # Returns 1 if 'yes' chosen, 2 if 'no', 0 otherwise. # try the apave package's dialogue if {[catch {set res [::apave::obj $type ques $ttl $msg]}]} { # or run the standard tk_messageBox set res [tk_messageBox -title $ttl -message $msg -type $type -icon question {*}$args] set res [expr {$res eq {yes} ? 1 : ($res eq {no} ? 2 : 0)}] } return $res }
_runBound_ | Runs a method bound to an event occuring at a widget. |
bindToEvent | Binds an event on a widget to a command. |
cget | Gets values of options of bars & tabs. |
checkDisabledMenu | Checks whether the popup menu's items are disabled. |
clear | Forgets (hides) the shown tabs. |
| See Tab.close |
closeAll | Closes tabs of bar. |
comparetext | Compares items (by -text attribute) for sort method. |
configure | Sets values of options for bars & tabs. |
draw | Draws the bar tabs at slight changes. |
insertTab | Inserts a new tab into a bar. |
listFlag | Gets a list of TID + flags "visible", "marked", "selected", "disabled". |
listTab | Gets a list of tabs. |
moveTab | Moves a tab to a new position in the bar. |
popList | Shows a menu of tabs. |
remove | Removes a bar. |
scrollLeft | Scrolls tabs to the left. |
scrollRight | Scrolls tabs to the right. |
| See Tab.show |
sort | Sorts a list of tabs by the tab names. |
tabID | Gets TID by tab's label. |
update | Updates the bar in hard way. |
| See Tab.visible |
Runs a method bound to an event occuring at a widget.
| widget |
| event |
| the bound method & its arguments |
method _runBound_ {w ev args} { # Runs a method bound to an event occuring at a widget. # w - widget # ev - event # args - the bound method & its arguments if {[catch {my {*}$args}]} { ;# failed binding => remove it foreach b [split [bind $w $ev] \n] { if {[string first $args $b]==-1} { if {[incr is1]==1} {bind $w $ev $b} {my bindToEvent $w $ev $b} } } } }
Binds an event on a widget to a command.
| the widget's path |
| the event |
| the command |
method bindToEvent {w event args} { # Binds an event on a widget to a command. # w - the widget's path # event - the event # args - the command if {[string first $args [bind $w $event]]<0} { bind $w $event [list + {*}$args] } }
Gets values of options of bars & tabs.
| list of options, e.g. {-tabcurrent -MyOpt} |
Return a list of values or one value if args is one option.
method cget {args} { # Gets values of options of bars & tabs. # args - list of options, e.g. {-tabcurrent -MyOpt} # Return a list of values or one value if args is one option. set BID [my ID] variable btData set res [list] set llen [dict get $btData $BID -LLEN] foreach opt $args { if {$opt eq "-listlen"} { lappend res $llen } elseif {$opt eq "-width"} { lassign [dict get [dict get $btData $BID] -wbar] wbar lappend res [my Aux_WidgetWidth $wbar] } elseif {[dict exists $btData $BID $opt] && ($llen || $opt ne "-tabcurrent")} { lappend res [dict get $btData $BID $opt] } else { lappend res {} } } if {[llength $args]==1} {return [lindex $res 0]} return $res }
Checks whether the popup menu's items are disabled.
| Not documented. |
| Not documented. |
| close function |
func equals to:
1 | for "Close All" |
2 | for "Close All at Left" |
3 | for "Close All at Right" |
Returns "yes" if the menu's item is disabled.
method checkDisabledMenu {BID TID func} { # Checks whether the popup menu's items are disabled. # func - close function # *func* equals to: # 1 - for "Close All" # 2 - for "Close All at Left" # 3 - for "Close All at Right" # Returns "yes" if the menu's item is disabled. lassign [my Mc_MenuItems] list behind close closeall closeleft closeright switch $func { 1 {set item $closeall} 2 {set item $closeleft} 3 {set item $closeright} default {set item $close} } my CheckDsblPopup $BID $TID $item }
Forgets (hides) the shown tabs.
method clear {} { # Forgets (hides) the shown tabs. if {[my Locked [set BID [my ID]]]} return set wlist [] foreach tab [my $BID listTab] { lassign $tab TID text wb wb1 wb2 pf if {[my Tab_Is $wb] && $pf ne {}} { lappend wlist $wb my $TID configure -pf {} } } if {[llength $wlist]} {pack forget {*}$wlist} }
Closes tabs of bar.
| Not documented. |
| Not documented. |
| close function |
| Optional arguments. |
func equals to:
1 | for "Close All" |
2 | for "Close All at Left" |
3 | for "Close All at Right" |
method closeAll {BID TID func args} { # Closes tabs of bar. # func - close function # *func* equals to: # 1 - for "Close All" # 2 - for "Close All at Left" # 3 - for "Close All at Right" switch $func { 1 {my $BID Tab_CloseFew -1 no {*}$args} 2 {my $BID Tab_CloseFew $TID yes} 3 {my $BID Tab_CloseFew $TID no} } }
Compares items (by -text attribute) for sort method.
| 1st item to compare |
| 2nd item to compare |
method comparetext {it1 it2} { # Compares items (by -text attribute) for sort method. # it1 - 1st item to compare # it2 - 2nd item to compare # See also: sort catch {set it1 [dict get $it1 -text]} catch {set it2 [dict get $it2 -text]} string compare -nocase $it1 $it2 }
Sets values of options for bars & tabs.
| list of pairs "option value" |
method configure {args} { # Sets values of options for bars & tabs. # args - list of pairs "option value" set BID [my ID] variable btData foreach {opt val} $args { dict set btData $BID $opt $val if {$opt eq "-TABS"} {dict set btData $BID -LLEN [llength $val]} } if {[dict exists $args -static]} {my $BID Style} }
Draws the bar tabs at slight changes.
| if "yes", run "update" before redrawing; optional, default yes |
method draw {{upd yes}} { # Draws the bar tabs at slight changes. # upd - if "yes", run "update" before redrawing if {[my Locked [set BID [my ID]]]} return if {$upd} update lassign [my Aux_InitDraw $BID] bwidth vislen bd arrlen llen tleft hidearr tabs wframe set tright [expr {$llen-1}] for {set i $tleft} {$i<$llen} {incr i} { lassign [my Tab_DictItem [lindex $tabs $i]] TID text wb wb1 wb2 pf lassign [my Tab_Create $BID $TID $wframe $text] wb wb1 wb2 if {[my Aux_CheckTabVisible $wb $wb1 $wb2 $i $tleft tright vislen $llen $hidearr $arrlen $bd $bwidth tabs $TID $text]} { my Tab_Pack $BID $TID $wb $wb1 $wb2 } } my Aux_EndDraw $BID $tleft $tright $llen my Tab_MarkBar $BID }
Inserts a new tab into a bar.
| tab's label |
| tab's position in tab list; optional, default end |
| tab's image; optional, default "" |
Returns TID of new tab or "".
method insertTab {txt {pos end} {img {}}} { # Inserts a new tab into a bar. # txt - tab's label # pos - tab's position in tab list # img - tab's image # Returns TID of new tab or "". set tabs [my [set BID [my ID]] cget -TABS] set tab [my Tab_Data $BID $txt] if {$tab eq {}} {return {}} if {$pos eq {end}} { lappend tabs $tab } else { set tabs [linsert $tabs $pos $tab] } if {$img ne {}} { set imagetabs [my $BID cget -IMAGETABS] lappend imagetabs [list [lindex $tab 0] $img] my $BID configure -IMAGETABS $imagetabs } my $BID configure -TABS $tabs my $BID Refill $pos [expr {$pos ne "end"}] lindex $tab 0 }
Gets a list of TID + flags "visible", "marked", "selected", "disabled".
| "" for all or "v","m","s","d" for visible, marked, selected, disabled; optional, default "" |
Returns a list "TID, text, visible, marked, selected, disabled" for all or a list of TID for filtered.
method listFlag {{filter {}}} { # Gets a list of TID + flags "visible", "marked", "selected", "disabled". # filter - "" for all or "v","m","s","d" for visible, marked, selected, disabled # Returns a list "TID, text, visible, marked, selected, disabled" for all or a list of TID for filtered. set BID [my ID] lassign [my $BID cget -mark -disable -select -tabcurrent] mark dsbl fewsel tcurr set res [list] foreach tab [my $BID listTab] { lassign $tab TID text wb wb1 wb2 pf set visibl [expr {[my Tab_Is $wb] && $pf ne {}}] set marked [expr {[lsearch $mark $TID]>=0}] set dsbled [expr {[lsearch $dsbl $TID]>=0}] set select [expr {$TID == $tcurr || [lsearch $fewsel $TID]>-1}] if {$filter eq {}} { lappend res [list $TID $text $visibl $marked $select $dsbled] } elseif {$filter eq "v" && $visibl || $filter eq "m" && $marked || $filter eq "d" && $dsbled || $filter eq "s" && $select} { lappend res $TID } } return $res }
Gets a list of tabs.
Returns a list of TID, text, wb, wb1, wb2, pf.
method listTab {} { # Gets a list of tabs. # Returns a list of TID, text, wb, wb1, wb2, pf. set res [list] foreach tab [my [my ID] cget -TABS] {lappend res [my Tab_DictItem $tab]} return $res }
Moves a tab to a new position in the bar.
| Not documented. |
| the new position |
method moveTab {TID pos} { # Moves a tab to a new position in the bar. # pos - the new position set BID [my ID] set tabs [my $BID cget -TABS] if {[set i [lsearch -index 0 $tabs $TID]]>-1} { set tab [lindex $tabs $i] set tabs [lreplace $tabs $i $i] my $BID configure -TABS [linsert $tabs $pos $tab] } }
Shows a menu of tabs.
| x coordinate of mouse pointer; optional, default "" |
| y coordinate of mouse pointer; optional, default "" |
| flag "sorted list" optional, default 0 |
method popList {{X {}} {Y {}} {sortedList 0}} { # Shows a menu of tabs. # X - x coordinate of mouse pointer # Y - y coordinate of mouse pointer # sortedList - flag "sorted list" set BID [my ID] my $BID DestroyMoveWindow lassign [my $BID cget -wbar -title] wbar title set popi $wbar.popupList catch {destroy $popi} menu $popi -tearoff 1 -title $title if {[set plist [my $BID FillMenuList $BID $popi -1 {} $sortedList]] eq "s"} { destroy $popi } else { my Bar_MenuList $BID -1 $popi $plist if {$X eq {}} {lassign [winfo pointerxy .] X Y} tk_popup $popi $X $Y } }
Removes a bar.
Returns "yes" at success.
method remove {} { # Removes a bar. # Returns "yes" at success. set BID [my ID] variable btData if {[dict exists $btData $BID]} { catch {bind [my $BID cget -wbase] <Configure> {}} lassign [my $BID cget -BINDWBASE] wb bnd if {$wb ne {}} {bind $wb <Configure> $bnd} set bar [dict get $btData $BID] foreach tab [dict get $bar -TABS] {my Tab_RemoveLinks $BID [lindex $tab 0]} catch {destroy {*}[dict get $bar -WWID]} catch {destroy [my $BID cget -UNDERWID]} if {[set bc [my $BID cget -BARCOM]] ne {}} {catch {rename $bc {}}} foreach tc [my $BID cget -TABCOM] {catch {rename [lindex $tc 1] {}}} dict unset btData $BID return yes } return no }
Scrolls tabs to the left.
method scrollLeft {} { # Scrolls tabs to the left. set BID [my ID] lassign [my $BID cget -wbar -dotip] w dotip set wlarr $w.larr ;# left arrow if {[my $BID ScrollCurr -1]} { if {$dotip} {catch {::baltip::repaint $wlarr}} return } lassign [my $BID cget -tleft -LLEN -scrollsel] tleft llen sccur if {![string is integer -strict $tleft]} {set tleft 0} if {$tleft && $tleft<$llen} { incr tleft -1 set tID [lindex [my $BID listTab] $tleft 0] my $BID configure -tleft $tleft my $BID Refill $tleft yes if {$sccur} {my $tID Tab_BeCurrent} if {$dotip} {catch {::baltip::repaint $wlarr}} } }
Scrolls tabs to the right.
method scrollRight {} { # Scrolls tabs to the right. set BID [my ID] lassign [my $BID cget -wbar -dotip] w dotip set wrarr $w.rarr ;# left arrow if {[my $BID ScrollCurr 1]} { if {$dotip} {catch {::baltip::repaint $wrarr}} return } lassign [my $BID cget -tright -LLEN -scrollsel] tright llen sccur if {![string is integer -strict $tright]} {set tright [expr {$llen-2}]} if {$tright<($llen-1)} { incr tright set tID [lindex [my $BID listTab] $tright 0] my $BID configure -tright $tright my $BID Refill $tright no if {$sccur} {my $tID Tab_BeCurrent} if {$dotip} {catch {::baltip::repaint $wrarr}} } }
Sorts a list of tabs by the tab names.
| option of sort; optional, default -increasing |
| command to compare two items; optional, default "" |
method sort {{mode -increasing} {cmd {}}} { # Sorts a list of tabs by the tab names. # mode - option of sort # cmd - command to compare two items set BID [my ID] lassign [my $BID cget -tabcurrent -lifo] TID lifo set tabs [my $BID cget -TABS] if {$cmd eq {}} { set tabs [lsort $mode -index 1 -dictionary -command "[self] comparetext" $tabs] } else { set tabs [lsort $mode -dictionary -command $cmd $tabs] } my $BID configure -TABS $tabs -lifo no my $TID show yes my $BID configure -lifo $lifo }
Gets TID by tab's label.
| label |
Returns TID or -1.
method tabID {txt} { # Gets TID by tab's label. # txt - label # Returns TID or -1. set BID [my ID] if {[catch {set ellipse [my $BID cget -ELLIPSE]}]} {return {}} if {[string first $ellipse $txt]>0} { set pattern [string map [list $ellipse "*"] $txt] } else { set pattern {} } foreach tab [my $BID listTab] { lassign $tab tID ttxt if {$txt eq $ttxt} {return $tID} if {$pattern ne {} && [string match $pattern $ttxt]} {return $tID} } return {} }
Updates the bar in hard way.
method update {} { # Updates the bar in hard way. if {[my Locked [set BID [my ID]]]} return update my $BID Refill 0 yes }
constructor | Constructor for the class. |
destructor | Destructor for the class. |
| See Bar._runBound_ |
| See Bar.bindToEvent |
| See Bar.cget |
| See Bar.checkDisabledMenu |
| See Bar.clear |
| See Tab.close |
| See Bar.closeAll |
| See Bar.comparetext |
| See Bar.configure |
create | Creates a bar. |
disableTab | Disables tab(s). |
| See Bar.draw |
drawAll | Redraws all bars. |
enableTab | Enables tab(s). |
| See Bar.insertTab |
isTab | Checks if a tab exists. |
| See Bar.listFlag |
| See Bar.listTab |
markTab | Marks tab(s). |
moveSelTab | Changes a tab's or selected tabs' position in bar. |
| See Bar.moveTab |
onSelectCmd | Runs a command (set by "-csel3") on a list of tabs. |
| See Bar.popList |
| See Bar.remove |
removeAll | Removes all bars. |
| See Bar.scrollLeft |
| See Bar.scrollRight |
selectTab | Selects tab(s). |
| See Tab.show |
| See Bar.sort |
| See Bar.tabID |
unmarkTab | Unmarks tab(s). |
unselectTab | Unselects tab(s). |
| See Bar.update |
updateAll | Updates all bars in hard way. |
| See Tab.visible |
| Optional arguments. |
method constructor {args} { set btData [dict create] if {[llength [self next]]} { next {*}$args } oo::objdefine [self] "method tab-1 {args} {return {-1}}" lappend ::bartabs::BarsList [self] }
method destructor {} { my removeAll unset btData set i [lsearch -exact $::bartabs::BarsList [self]] set ::bartabs::BarsList [lreplace $::bartabs::BarsList $i $i] if {[llength [self next]]} next }
Creates a bar.
| bar command's name or barOpts |
| list of bar's options; optional, default "" |
| tab to show after creating the bar; optional, default "" |
Returns BID.
method create {barCom {barOpts {}} {tab1 {}}} { # Creates a bar. # barCom - bar command's name or barOpts # barOpts - list of bar's options # tab1 - tab to show after creating the bar # Returns BID. if {[set noComm [expr {$barOpts eq {}}]]} {set barOpts $barCom} set w [dict get $barOpts -wbar] ;# parent window set wframe $w.frame ;# frame set wlarr $w.larr ;# left arrow set wrarr $w.rarr ;# right arrow lappend barOpts -WWID [list $wframe $wlarr $wrarr] my My [set BID [my Bar_Data $barOpts]] my $BID InitColors set bgm [my $BID cget -BGMAIN] if {[my TtkTheme]} { ttk::button $wlarr -style ClButton$BID -image bts_ImgLeft -command [list [self] $BID scrollLeft] -takefocus 0 ttk::button $wrarr -style ClButton$BID -image bts_ImgRight -command [list [self] $BID scrollRight] -takefocus 0 } else { button $wlarr -image bts_ImgLeft -borderwidth 0 -highlightthickness 0 -command [list [self] $BID scrollLeft] -takefocus 0 -background $bgm button $wrarr -image bts_ImgRight -borderwidth 0 -highlightthickness 0 -command [list [self] $BID scrollRight] -takefocus 0 -background $bgm } if {$bgm eq {}} {set style {}} {set style "-background $bgm"} frame $wframe -relief flat {*}$style pack $wlarr -side left -padx 0 -pady 0 -anchor e pack $wframe -after $wlarr -side left -padx 0 -pady 0 -fill x -expand 1 pack $wrarr -after $wframe -side right -padx 0 -pady 0 -anchor w if {[my $BID cget -separator]} { if {![winfo exists $w.under]} { ttk::separator $w.under -orient horizontal my $BID configure -UNDERWID $w.under } pack $w.under -before $wlarr -side bottom -fill x -expand 1 -padx 0 -pady 2 } foreach w {wlarr wrarr} { bind [set $w] <Button-3> "[self] $BID popList %X %Y" } set wbase [my $BID cget -wbase] if {$wbase ne {}} { after 1 [list my $BID configure -BINDWBASE [list $wbase [bind $wbase <Configure>]] ; my $BID bindToEvent $wbase <Configure> [self] _runBound_ $wbase <Configure> $BID NeedDraw] } if {!$noComm} { ; proc $barCom {args} "return \[[self] $BID {*}\$args\]" my $BID configure -BARCOM $barCom } if {$tab1 eq {}} { after 50 [list [self] $BID NeedDraw ; [self] $BID draw] } else { set tab1 [my $BID tabID $tab1] if {$tab1 ne {}} {after 100 "[self] $BID clear; [self] $BID $tab1 show yes"} } return $BID }
Disables tab(s).
| list of TID |
method disableTab {args} { # Disables tab(s). # args - list of TID my MarkTab -disable {*}$args }
Redraws all bars.
| if "yes", run "update" before redrawing; optional, default yes |
method drawAll {{upd yes}} { # Redraws all bars. # upd - if "yes", run "update" before redrawing if {$upd} update my Bars_Method draw no }
Enables tab(s).
| list of TID or {} |
method enableTab {args} { # Enables tab(s). # args - list of TID or {} my UnmarkTab -disable {*}$args }
Checks if a tab exists.
| tab ID |
Returns true if the tab exists.
method isTab {TID} { # Checks if a tab exists. # TID - tab ID # Returns true if the tab exists. expr {[my Tab_BID $TID check] ne {}} }
Marks tab(s).
| list of TID |
method markTab {args} { # Marks tab(s). # args - list of TID my MarkTab -mark {*}$args }
Changes a tab's or selected tabs' position in bar.
| TID of the moved tab |
| TID of a tab to move TID1 behind |
TID1 and TID2 must be of the same bar.
method moveSelTab {TID1 TID2} { # Changes a tab's or selected tabs' position in bar. # TID1 - TID of the moved tab # TID2 - TID of a tab to move TID1 behind # TID1 and TID2 must be of the same bar. if {[my $TID1 Tab_Cmd -cmov] ni {"1" "yes" "true"}} return ;# chosen to not move set BID [my Tab_BID $TID1 check] # -lifo option prevents moving, so it has to be temporarily disabled set lifo [my $BID cget -lifo] my $BID configure -lifo no set seltabs [my $BID listFlag "s"] if {[set i [llength $seltabs]]>1} { for {incr i -1} {$i>=0} {incr i -1} { set tid [lindex $seltabs $i] if {$tid ne $TID2} {my MoveTab $tid $TID2} } my $BID Bar_Cmd2 -cmov3 } else { my MoveTab $TID1 $TID2 my $BID Bar_Cmd2 -cmov3 $TID1 ;# command after the action } my $BID configure -lifo $lifo ;# restore -lifo option }
Runs a command (set by "-csel3") on a list of tabs.
| list of TID |
method onSelectCmd {args} { # Runs a command (set by "-csel3") on a list of tabs. # args - list of TID foreach TID $args { if {$TID ni {{} -1}} { set BID [lindex [my Tab_BID $TID] 0] my $BID Bar_Cmd2 -csel3 $TID ;# command after the action } } }
Removes all bars.
method removeAll {} { # Removes all bars. my Bars_Method remove }
Selects tab(s).
| list of TID |
method selectTab {args} { # Selects tab(s). # args - list of TID my MarkTab -select {*}$args my onSelectCmd {*}$args }
Unmarks tab(s).
| list of TID or {} |
method unmarkTab {args} { # Unmarks tab(s). # args - list of TID or {} my UnmarkTab -mark {*}$args }
Unselects tab(s).
| list of TID or {} |
method unselectTab {args} { # Unselects tab(s). # args - list of TID or {} my UnmarkTab -select {*}$args my onSelectCmd {*}$args }
Updates all bars in hard way.
method updateAll {} { # Updates all bars in hard way. my Bars_Method Refill 0 yes }
close | Closes a tab and updates the bar. |
show | Shows a tab in a bar and sets it current. |
visible | Checks if a tab is visible. |
Closes a tab and updates the bar.
| if "yes", update the bar and select the new tab; optional, default yes |
| additional argumens of the -cdel command |
Returns "1" if the deletion was successful, otherwise 0 (no) or -1 (cancel).
method close {{redraw yes} args} { # Closes a tab and updates the bar. # redraw - if "yes", update the bar and select the new tab # args - additional argumens of the -cdel command # Returns "1" if the deletion was successful, otherwise 0 (no) or -1 (cancel). lassign [my Tab_BID [set TID [my ID]]] BID icurr tabcurr if {[my Disabled $TID]} { set ttl [msgcat::mc Closing] set t [my $TID cget -text] set msg [msgcat::mc "Can't close the disabled\n\"%t\"\n\nClose others?"] set msg [string map [list %t $t] $msg] return [expr {[::bartabs::messageBox yesno $ttl $msg -icon question]==1}] } set cdel [my $BID cget -cdel] if {$cdel eq {}} { set res 1 } else { set cdel [my PrepareCmd $TID $BID -cdel {*}$args] if {[catch {set res [{*}$cdel]}]} { set res [my $TID Tab_Cmd -cdel {*}$args] } } if {$res ni {1 yes true}} {return $res} if {$redraw} {my $BID clear} lassign [my $BID cget -TABS -tleft -tright -tabcurrent] tabs tleft tright tcurr my Tab_RemoveLinks $BID $TID destroy [my $TID cget -wb] set tabs [lreplace $tabs $icurr $icurr] oo::objdefine [self] [list deletemethod [lindex $tabcurr 0]] my $BID configure -TABS $tabs if {$redraw} { if {$icurr>=$tleft && $icurr<[llength $tabs]} { my $BID draw my [lindex $tabs $icurr 0] Tab_BeCurrent } else { if {[set TID [lindex $tabs end 0]] ne {}} { my $TID show yes ;# last tab deleted: show the new last if any } } } my $BID Bar_Cmd2 -cdel2 ;# command after the action return 1 }
Shows a tab in a bar and sets it current.
| if "yes", update the bar; optional, default no |
| if "yes", allows moving a tab to 0th position; optional, default yes |
When refill=no and lifo=no, just shows a tab in its current position.
method show {{refill no} {lifo yes}} { # Shows a tab in a bar and sets it current. # refill - if "yes", update the bar # lifo - if "yes", allows moving a tab to 0th position # When refill=no and lifo=no, just shows a tab in its current position. lassign [my IDs [my ID]] TID BID if {$refill} {my $BID clear} set itab 0 foreach tab [my $BID listTab] { lassign $tab tID text wb wb1 wb2 pf if {$TID eq $tID} { set refill [expr {$pf eq {}}] ;# check if visible break } incr itab } if {$refill && $lifo && [my $BID cget -lifo] && (![my $TID visible] || [string is true -strict [my $BID cget -lifoest]])} { my $BID moveTab $TID 0 set itab 0 } if {$refill} {my $BID Refill $itab no yes} my $TID Tab_BeCurrent }
Checks if a tab is visible.
Returns yes if the tab is visible,.
method visible {} { # Checks if a tab is visible. # Returns yes if the tab is visible,. lassign [my IDs [my ID]] TID BID lassign [my $BID cget -tleft -tright] tleft tright set tabs [my $BID listTab] for {set i $tleft} {$i<=$tright} {incr i} { if {$TID eq [lindex $tabs $i 0]} { return yes } } return no }