From 46565ba4cce440a96dbe4844c2b01502b468d7f6 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 16 Jul 2010 16:48:59 -0400 Subject: [PATCH] Use checkbox tree rather than a simple array for element tags in dirtag.xul --- static/dirtag.css | 18 ++++++++++++++++++ static/dirtag.js | 32 ++++++++++++++++++++++++++------ static/dirtag.xul | 32 +++++++++++++++++++++++++++----- 3 files changed, 71 insertions(+), 11 deletions(-) diff --git a/static/dirtag.css b/static/dirtag.css index e57c498..9fcf43d 100644 --- a/static/dirtag.css +++ b/static/dirtag.css @@ -4,3 +4,21 @@ https://developer.mozilla.org/en/XUL/groupbox */ /* groupbox {border-style:solid; border-color:black; border:1px;} */ + +/* Checkbox images following + https://developer.mozilla.org/en/XUL/Attribute/treecol.type + http://code.google.com/p/weaponry/wiki/ExtensionWrittingTipsAndTricks + */ +treechildren::-moz-tree-checkbox +{ + /* unchecked checkbox treecells. This style MUST come before treechildren::-moz-tree-checkbox(checked) otherwise it won't take effect. */ + list-style-image: none; +} +treechildren::-moz-tree-checkbox(checked) +{ + list-style-image: url(chrome://global/skin/checkbox/cbox-check.gif); +} +treechildren::-moz-tree-checkbox(disabled) +{ + list-style-image: url(chrome://global/skin/checkbox/cbox-check-dis.gif); +} diff --git a/static/dirtag.js b/static/dirtag.js index d04acaa..e406112 100644 --- a/static/dirtag.js +++ b/static/dirtag.js @@ -12,6 +12,20 @@ function tree_selection(id) { return path; } +function tree_selection_and_check(id) { + var tree = document.getElementById(id); + var name = tree.columns.getPrimaryColumn(); + var check = tree.columns.getFirstColumn(); + var i = tree.currentIndex; + var checked = tree.view.getCellValue(i, check); + var path = new Array(); + while (i >= 0) { + path.splice(0, 0, tree.view.getCellText(i, name)); + i = tree.view.getParentIndex(i); + } + return [path, checked]; +} + /* Functions driving the CherryPy backend */ function new_tag(path) { @@ -20,11 +34,11 @@ function new_tag(path) { } function add_tag(path, tag) { - alert('Add tag '+path.toString()+' to '+tag); + alert('Add tag '+tag+' to '+path.toString()); } function remove_tag(path, tag) { - alert('Remove tag '+path.toString()+' from '+tag); + alert('Remove tag '+tag+' from '+path.toString()); } /* The bindings themselves */ @@ -41,7 +55,7 @@ function new_tag_button() { function set_selected_element(path) { element = document.getElementById('element'); element.file_path = path; - alert(path.toString()); + alert('Set selected element: '+path.toString()); } function raw_tree_select() { @@ -54,9 +68,15 @@ function tag_tree_select() { function tag_check(event) { var path = document.getElementById('element').file_path; - if (event.target.checked) { - add_tag(path, event.target.id); + var a = tree_selection_and_check('checkbox-tree'); + id = a[0]; + checked = a[1]; + alert('path: '+path.toString()); + alert('id: '+id); + alert('check: '+checked); + if (checked) { + add_tag(path, id); } else { - remove_tag(path, event.target.id); + remove_tag(path, id); } } diff --git a/static/dirtag.xul b/static/dirtag.xul index 7ee1f30..9481f34 100644 --- a/static/dirtag.xul +++ b/static/dirtag.xul @@ -106,13 +106,35 @@ - + - + - - - + + + + + + + +