1
0
Fork 0

Further development of tree-view:

+ Commands implemented.
  + Changes to the interface and documentation.
  + Don’t look in TEXMACS_PIXMAP_PATH if DecorationRole is set.
This commit is contained in:
Miguel de Benito 2014-01-01 23:15:10 +00:00
parent 812ee2a023
commit 06ee7775f0
1 changed files with 71 additions and 21 deletions

View File

@ -1,4 +1,4 @@
<TeXmacs|1.0.7.21> <TeXmacs|1.99.1>
<style|tmdoc> <style|tmdoc>
@ -110,7 +110,7 @@
<paragraph|Displaying trees with <scm|tree-widget>> <paragraph|Displaying trees with <scm|tree-widget>>
<\explain> <\explain>
<scm|(tree-widget <scm-arg|data> <scm-arg|data-roles>)><explain-synopsis|a <scm|(tree-widget cmd <scm-arg|data> <scm-arg|data-roles>)><explain-synopsis|a
tree view> tree view>
<|explain> <|explain>
The <scm|tree-widget> provides a graphical representation of a <TeXmacs> The <scm|tree-widget> provides a graphical representation of a <TeXmacs>
@ -137,7 +137,7 @@
<\scm-code> <\scm-code>
(root (root
\ \ (library "My bibliography" "icon.xpm" 12345 \ \ (library "Library" "icon.png" 12345
\ \ \ \ (collection "Cool stuff" 001) \ \ \ \ (collection "Cool stuff" 001)
@ -168,28 +168,69 @@
StatusTipRole \ \ \ \ \ ; for the status bar (if present and StatusTipRole \ \ \ \ \ ; for the status bar (if present and
supported) supported)
DecorationRole \ \ \ \ ; file name of an icon to use (in DecorationRole \ \ \ \ ; file name of an icon to use
$TEXMACS_PIXMAP_PATH)
CommandRole \ \ \ \ \ \ \ ; command to be executed when the user CommandRole \ \ \ \ \ \ \ ; sent to the command executed after
(double?) clicks (double?) clicks
UserRole:\<less\>number\<gtr\> \ ; left to user definition UserRole:\<less\>number\<gtr\> \ ; left to user definition (will be
returned as strings)
</code> </code>
</verbatim-code> </verbatim-code>
It is possible to omit the data role specification. By default the widget <paragraph|Default data roles>It is possible to omit some or all of the
will use the tree label's string representation as <scm|DisplayRole>, data role specification. By default the widget will use the tree label's
<scm|EditRole>, <scm|ToolTipRole> and <scm|StatusTipRole>. For the string representation for <scm|DisplayRole>, <scm|EditRole>,
<scm|DecorationRole> it will try to load pixmaps named <scm|ToolTipRole> and <scm|StatusTipRole>. For the <scm|DecorationRole>
<shell|treelabel.xpm> in <shell|$TEXMACS_PIXMAP_PATH>. it will try to load pixmaps named <shell|treelabel-\<less\>label\<gtr\>.xpm>
in <shell|$TEXMACS_PIXMAP_PATH>. This search
<with|font-series|bold|won't> happen if the <scm|DecorationRole> is
specified (i.e. a full path with or without environment variables and
wildcards must be given). The default <scm|CommandRole> is the subtree
itself (see below).
For an example see <scm|widget10> in <hlink|menu-test.scm|$TEXMACS_PATH/progs/kernel/gui/menu-test.scm>. <paragraph|Using commands>The first argument of <scm|tree-widget>,
<scm-arg|cmd>, \ is a <scheme> lambda that will be called when items are
clicked. The procedure must have the following signature:
<\scm-code>
(lambda (Event CommandRole . UserRoles) (...))
</scm-code>
where:
<\itemize-dot>
<item><scm|Event> is an integer: either 1, 2 or 4 for a single, right
or middle click respectively. In the future, other events could be
supported (like double clicks, drag&drop, unfold, etc.)
<item><scm|CommandRole> is either the value of that role if given for
the data item, or the subtree itself otherwise.
<item><scm|UserRoles> is a (possibly empty) list with the data for
those roles given in the data role specification.
</itemize-dot>
If multiple selections are enabled and one is made, <scm|CommandRole> and
<scm|UserRole> will both be lists (not implemented yet). Keep in mind
that the data is a <TeXmacs> tree and thus not a copy but always a
pointer to the actual data (unless you copy or transform it into another
format with e.g. <scm|tree-\<gtr\>stree>)
<paragraph|Examples>See <scm|widget10> in
<hlink|menu-test.scm|$TEXMACS_PATH/progs/kernel/gui/menu-test.scm> and
``<hlink|Displaying lists and trees|$TEXMACS_PATH/doc/devel/scheme/gui/scheme-gui-lists-trees.scm>''.
</explain> </explain>
<subparagraph|An example using data roles> <paragraph|An example using data roles>
We build on the previous example: We build on the previous example, but now we add a command. Notice how the
way one adds commands to <scm|tree-view> departs from that of other
widgets, where instead of a procedure one must provide a list with code
expecting one or two arguments with fixed names (usually <scm|answer> and
<scm|filter>). <with|font-shape|italic|Note to self>: this is easily
changed in <scm|$tree-view>, but it seems easier to manage empty arguments
this way.
<\session|scheme|default> <\session|scheme|default>
<\input|Scheme] > <\input|Scheme] >
@ -199,7 +240,7 @@
\ \ \ '(root \ \ \ '(root
\ \ \ \ \ (library "My bibliography" "icon.xpm" 12345 \ \ \ \ \ (library "Library" "$TEXMACS_PIXMAP_PATH/tm_german.xpm" 01
\ \ \ \ \ \ \ \ \ \ \ \ \ \ (collection "Cool stuff" 001) \ \ \ \ \ \ \ \ \ \ \ \ \ \ (collection "Cool stuff" 001)
@ -224,7 +265,15 @@
\ \ \ \ \ \ \ \ \ \ (collection DisplayRole UserRole:1)))) \ \ \ \ \ \ \ \ \ \ (collection DisplayRole UserRole:1))))
</input> </input>
<\unfolded-io|Scheme] > <\input|Scheme] >
(define (action clicked cmd-role . user-roles)
\ \ (display* "clicked= " clicked ", cmd-role= " cmd-role
\ \ \ \ \ \ \ \ \ \ \ \ ", user-roles= " user-roles "\\n")))
</input>
<\input|Scheme] >
(tm-widget (widget-library) (tm-widget (widget-library)
\ \ (resize ("150px" "400px" "9000px") ("300px" "600px" "9000px") \ \ (resize ("150px" "400px" "9000px") ("300px" "600px" "9000px")
@ -235,16 +284,17 @@
\ \ \ \ \ \ === \ \ \ \ \ \ ===
\ \ \ \ \ \ (tree-view t dd)))) \ \ \ \ \ \ (tree-view action t dd))))
<|unfolded-io> </input>
\;
</unfolded-io>
<\input|Scheme] > <\input|Scheme] >
(top-window widget-library "Tree View") (top-window widget-library "Tree View")
</input> </input>
</session> </session>
Notice how we must add <shell|$TEXMACS_PIXMAP_PATH> to the name of the
pixmap because we are not using the default <scm|DecorationRole>.\
<subparagraph|An example using the buffer tree> <subparagraph|An example using the buffer tree>
We can even use the <scm|buffer-tree> as argument to <scm|tree-widget>. We can even use the <scm|buffer-tree> as argument to <scm|tree-widget>.