From 3298e563ad8e9479e0c30b0d99baafcb0550502f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 17 Jul 2010 10:08:34 -0400 Subject: [PATCH] The checkboxes were not settable in the previous implementation. The problem seems to stem from the old flags="dont-build-content" setting, which selects tree vs. content templating. See https://developer.mozilla.org/en/XUL_Tutorial/Trees_and_Templates https://developer.mozilla.org/en/XUL/Attribute/flags for details. Also hooked checkbox handler (checkbox_activity()) on as a method of the tree.view, which makes it easier to only act on checkbox activity, and locate the active row. Other tidbits: * Set type="application/javascript" in dirtag.js import. Might as well to that formally. * selstype="primary" in checkbox-tree. I'd rather disable selection entirely, but this at least keeps it off the checkbox column. --- static/dirtag.js | 41 ++++++++++++++++------------------------- static/dirtag.xul | 12 +++++++----- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/static/dirtag.js b/static/dirtag.js index e406112..554f9ae 100644 --- a/static/dirtag.js +++ b/static/dirtag.js @@ -1,29 +1,18 @@ /* Useful helper functions */ -function tree_selection(id) { - var tree = document.getElementById(id); +function tree_path(tree, row) { var name = tree.columns.getPrimaryColumn(); - var i = tree.currentIndex; var path = new Array(); - while (i >= 0) { - path.splice(0, 0, tree.view.getCellText(i, name)); - i = tree.view.getParentIndex(i); + while (row >= 0) { + path.splice(0, 0, tree.view.getCellText(row, name)); + row = tree.view.getParentIndex(row); } return path; } -function tree_selection_and_check(id) { +function tree_selection(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]; + return tree_path(tree, tree.currentIndex); } /* Functions driving the CherryPy backend */ @@ -45,6 +34,12 @@ function remove_tag(path, tag) { function initialize() { element = document.getElementById('element').file_path = 'UNDEFINED'; + var tree = document.getElementById('checkbox-tree'); + tree.view.origSetCellValue = tree.view.setCellValue; + tree.view.setCellValue = function (row, col, value) { + tree.view.origSetCellValue(row, col, value); + checkbox_activity(tree, row, col, value); + }; } function new_tag_button() { @@ -66,15 +61,11 @@ function tag_tree_select() { set_selected_element(tree_selection('tag-tree')); } -function tag_check(event) { +function checkbox_activity(tree, row, col, value) { var path = document.getElementById('element').file_path; - 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) { + var name = tree.columns.getPrimaryColumn(); + id = tree_path(tree, row); + if (value == true || value == "true") { add_tag(path, id); } else { remove_tag(path, id); diff --git a/static/dirtag.xul b/static/dirtag.xul index 9481f34..cf5ac73 100644 --- a/static/dirtag.xul +++ b/static/dirtag.xul @@ -28,7 +28,7 @@ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" > -