git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gitk: Add horizontal scrollbar to the diff view

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 8, 2008, 01:53 UTC
Message-ID
<20080308015357.GU8410@spearce.org>
In-Reply-To
<18383.51154.695501.543720@cargo.ozlabs.ibm.com>
Paul Mackerras <paulus@samba.org> wrote:
Show 14 quoted lines
> Junio C Hamano writes:
> > An obvious solution is to show the scrollbar on-demand (i.e. when the
> > lines are overlong), but I do not talk Tcl/Tk and do not know if you can
> > do that easily.
> 
> I don't know of any extremely easy way to do it; it's certainly
> possible, but I think I would have to calculate the length of each
> line as it is put in, so as to get the maximum, and then have a
> handler for when the pane is resized, and pack and unpack the
> scrollbar as necessary.
> 
> I think it's reasonable to have the scroll bar there always.  I think
> that pane could look better using the grid geometry manager (instead
> of pack), but that can be a separate patch.

git-gui does this scrollbar on-demand thing in its revision list meta-widget, which is lib/choose_rev.tcl. The procedure in question is this, and it gets installed as:

      listbox $w_list \
        -font font_diff \
        -width 50 \
        -height 10 \
        -selectmode browse \
        -exportselection false \
        -xscrollcommand [cb _sb_set $w.list.sbx h] \
        -yscrollcommand [cb _sb_set $w.list.sby v]
method _sb_set {sb orient first last} {
    set old_focus [focus -lastfor $w]
       
    if {$first == 0 && $last == 1} {
        if {[winfo exists $sb]} {
            destroy $sb
            if {$old_focus ne {}} {
                update
                focus $old_focus
            }
        }
        return
    }
       
    if {![winfo exists $sb]} {
        if {$orient eq {h}} {
            scrollbar $sb -orient h -command [list $w_list xview]
            pack $sb -fill x -side bottom -before $w_list
        } else {
            scrollbar $sb -orient v -command [list $w_list yview]
            pack $sb -fill y -side right -before $w_list
        }
        if {$old_focus ne {}} {
            update
            focus $old_focus
        }
    }
       
    catch {$sb set $first $last}
}
-- 
Shawn.
Previous: Pekka KaitaniemiNext: Paul Mackerras
Message 5 of 7 in “gitk: Add horizontal scrollbar to the diff view”
  1. gitk: Add horizontal scrollbar to the diff viewPekka Kaitaniemi, Mar 5, 2008
  2. Junio C HamanoMar 6, 2008
  3. Paul MackerrasMar 6, 2008
  4. Pekka KaitaniemiMar 6, 2008
  5. Shawn O. PearceMar 8, 2008
  6. Paul MackerrasMar 8, 2008
  7. Shawn O. PearceMar 8, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.