Tk Library Source Code

View Ticket
Login
Ticket UUID: 2828086
Title: Add <<TreeSelect>> event for keyboard navigation
Type: Patch Version: None
Submitter: wordtech Created on: 2009-07-27 21:48:37
Subsystem: bwidget Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2009-08-04 23:35:34
Resolution: Accepted Closed By: oehhar
    Closed on: 2009-08-04 16:35:34
Description:
The attached patch updates tree.tcl to support the <<TreeSelect>> virtual event for KeyPress-Up and KeyPress-Down. Many users use the keyboard to navigate tree widgets and this brings the BWidget tree in line with current UI best practices.
User Comments: oehhar added on 2009-08-04 23:35:33:
Committed

oehhar added on 2009-08-04 22:55:53:
Koen,
I have overseen the "select set", sorry.

So the patch is o.k., I will apply it.

Harald

danckaert added on 2009-08-04 22:43:15:
Harald,
I don't understand what you mean with "select" methods. Currently, the _keynav procedure contains [selection set] commands. That seems ok to me.
Looking at the source code, I think the current_node stuff does not make any sense. It tests for [info exists selectTree::selectCursor], which is never set. Even the namespace does not exist. (Unless there is some cleverly obfuscated code where it is set -  I've not tested it.)
Koen

oehhar added on 2009-08-04 22:29:57:
Thank you Koen,
what do you think of using "select" methods inside key navigation instead of the current stuff. Does the current node and selected node make any sense ?

Thank you,
Harald

danckaert added on 2009-08-04 22:22:29:
I think the new patch is ok, except that it misses the first part of the "down" case in the switch statement.

Harald, I think the Tree widget does not have single/multiple selection modes like the listbox. I found some references to it in the source code, but it seems to be incomplete and there is no API to use it.

wordtech added on 2009-08-04 05:19:47:
Revised patch file moves <<TreeSelect>> event firing to keyboard navigation proc (_keynav) and adds right-left arrow.

wordtech added on 2009-08-04 05:19:04:

File Added - 337864: tree.patch

wordtech added on 2009-08-04 05:18:27:

File Deleted - 336886:

oehhar added on 2009-08-03 21:24:50:
Dear Kevin,

thank you for the patch. IMHO this is half-baken. I am not at all familiar to the tree widget, please help.

The patch proposes to also bind up and down keys to the virtual event <<TreeSelect>>.

The documentation says: Event <<TreeSelect>> fires if the selection changes. (documentation lacks the trivial fact, that it does not fire if selection changes by the select command).

The selection does not change by the up-down key bindings. Only the current node changes. In consequence, <<TreeSelect>> is not fired - that is ok.

There are IMHO multiple alternatives:

1) Change the way keyboard navigation works:
- if select mode is single, the keybard navigation will change the selection
- if select mode is multiple, the space bar should toggle selection and not expand/collapse the tree. Tree expansion/collapse may be done with the +/- keys.

2) Also fire the event <<TreeSelect>> whenn the current node changes.
A more careful patch must be created to invoke
    event generate $path <<TreeSelect>>
within
    proc Tree::_keynav
each time, the current node changes.

3) Create new event <<CurrentNode>> which is fired each time the current node changes.
(similar to 2))

The effect of the proposed patch may be achieved by two bind commands after widget creation. But key-right and key-left should also be used.

Please comment.

Thank you,
Harald

wordtech added on 2009-07-28 04:54:45:
The patch can be tested with this code:

package require BWidget

Tree .t
pack .t

.t insert end root Foo -text Foo 
.t insert end root Bar -text Bar
.t insert end root Baz -text Bas

bind .t <<TreeSelect>> {puts "foo"}

The keyboard up-down buttons will print "foo" to standard output.

wordtech added on 2009-07-28 04:48:40:

File Added - 336886: tree.patch

Attachments: