var name = tree.columns.getPrimaryColumn();
var path = new Array();
while (row >= 0) {
- path.splice(0, 0, tree.view.getCellText(row, name));
+ path.splice(0, 0, split_checkbox_value(tree.view.getCellText(row, name))[1]);
row = tree.view.getParentIndex(row);
}
return path;
return tag.join('/') in o;
}
+function join_checkbox_value(name, value) {
+ var v = ' ';
+ if (value == true)
+ v = '+';
+ return '('+v+') ' + name;
+}
+
+function split_checkbox_value(text) {
+ if (text.length > 3 && text[0] == '(' && text[2] == ')') {
+ return [text[1] == '+', text.slice(4)];
+ }
+ return [false, text]; // No checkbox set yet.
+}
+
+function get_checkbox_value(tree, row) {
+ var name = tree.columns.getPrimaryColumn();
+ var text = tree.view.getCellText(row, name);
+ return split_checkbox_value(text)[0];
+}
+
+function set_checkbox_value(tree, row, value) {
+ var name = tree.columns.getPrimaryColumn();
+ var text = tree.view.getCellText(row, name);
+ text = split_checkbox_value(text)[1];
+ tree.view.setCellText(row, name, join_checkbox_value(text, value));
+}
+
function setup_checkboxes(tags) {
+ //alert(tags);
var tree = document.getElementById('checkbox-tree');
- var ctags = tree.columns.getLastColumn();
for (var row=0; row<tree.view.rowCount; row++) {
p = tree_path(tree, row);
- tree.view.origSetCellValue(row, ctags, tag_in_tags(p, tags));
+ set_checkbox_value(tree, row, tag_in_tags(p, tags));
}
- tree.treeBoxObject.invalidateColumn(ctags);
+ tree.treeBoxObject.invalidate();
}
/* Functions driving the CherryPy backend */
alert("Error loading page\n\n"+e.responseText);
return;
}
- document.getElementById('raw-tree').builder.refresh();
- document.getElementById('tag-tree').builder.refresh();
- document.getElementById('checkbox-tree').builder.refresh();
-
- var id = document.getElementById('element').tree_id;
- var path_tags = tree_selection(id);
- setup_checkboxes(path_tags[1]);
+ document.getElementById('raw-tree').builder.refresh("blocking");
+ document.getElementById('tag-tree').builder.refresh("blocking");
+ document.getElementById('checkbox-tree').builder.refresh("blocking");
+
+ /* The refreshed data sources will overwrite some of the
+ checkbox text. Wait until the data is refreshed, and
+ reload the checkboxes.
+ */
+ window.setTimeout(function () {
+ var id = document.getElementById('element').tree_id;
+ var path_tags = tree_selection(id);
+ setup_checkboxes(path_tags[1]);
+ alert('reset');
+ }, 3000);
}
}
var title = caption.label.split(':', 1)[0];
caption.label = title+': '+path.join('/');
+ //alert('setup checkboxes for set_selecte_elt');
setup_checkboxes(tags);
var element = document.getElementById('element');
set_selected_element(path_tags[0], path_tags[1], 'tag-tree');
}
-function checkbox_activity(tree, row, col, value) {
+
+function checkbox_select(e) {
+ /* https://developer.mozilla.org/en/XUL_Tutorial/Tree_Selection
+ https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsITreeSelection
+ */
+ var tree = document.getElementById('checkbox-tree');
+ var s = tree.view.selection.isSelected(tree.currentIndex);
+ var row = tree.currentIndex;
+ if (tree.view.selection.isSelected(row) == false)
+ return; // clearing the selection raises another onselect event
+ tree.view.selection.clearSelection();
+ tree.blur()
var path = document.getElementById('element').file_path;
- var name = tree.columns.getPrimaryColumn();
- id = tree_path(tree, row);
if (path == 'UNDEFINED') {
return;
- } else if (value == true || value == 'true') {
- add_tag(path, id);
+ }
+ alert(e.target.id);
+ var tag = tree_path(tree, row);
+ var value = !get_checkbox_value(tree, row);
+ //alert('set checkbox by hand');
+ set_checkbox_value(tree, row, value);
+ if (value == true || value == 'true') {
+ add_tag(path, tag);
} else {
- remove_tag(path, id);
+ remove_tag(path, tag);
}
}
<caption id="selected-caption" label="&selected.caption;"/>
<groupbox id="tags" flex="1">
<caption label="&tags.caption;"/>
- <tree id="checkbox-tree" rows="2" seltype="single" selstype="primary"
- editable="true"
- datasources="tag.rdf raw.rdf"
- ref="http://dirtag.com/tag/files"
- flex="1">
- <!-- checkbox callback attached in dirtag.js's initialize() -->
+ <tree id="checkbox-tree" rows="1" seltype="single" selstype="primary"
+ editable="true" flex="1"
+ datasources="tag.rdf raw.rdf" ref="http://dirtag.com/tag/files"
+ onselect="checkbox_select(event);">
<treecols>
- <treecol id="checkbox-tree-check-column" label="CK" type="checkbox"
- editable="true"/>
<treecol id="checkbox-tree-path-column" label="&path_column.label;"
editable="true" primary="true"
sort="rdf:http://dirtag.com/rdf#name" flex="1"/>
<treechildren>
<treeitem uri="rdf:*" open="true">
<treerow>
- <treecell editable="true"/>
<treecell label="rdf:http://dirtag.com/rdf#name"/>
</treerow>
</treeitem>