Author: jsuchome
Date: Wed Feb 23 15:10:43 2011
New Revision: 63463
URL: http://svn.opensuse.org/viewcvs/yast?rev=63463&view=rev
Log:
implement tree handling (checking/unchecking of subtrees) in YCP... :-(
Modified:
branches/tmp/jsuchome/snapper/src/dialogs.ycp
Modified: branches/tmp/jsuchome/snapper/src/dialogs.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/jsuchome/snapper/src/dialogs.ycp?rev=63463&r1=63462&r2=63463&view=diff
==============================================================================
--- branches/tmp/jsuchome/snapper/src/dialogs.ycp (original)
+++ branches/tmp/jsuchome/snapper/src/dialogs.ycp Wed Feb 23 15:10:43 2011
@@ -240,12 +240,16 @@
}
string snapshot_name = tostring (snapshot_num);
+
+ // map of tree (recursive)
map tree_map = $[];
+ // map of all items in tree (just one level)
+ map selected_items = $[];
+
// helper function: update the global map with directory tree structure
map update_tree_map (map current_map, list<string> path_list)
{
- y2internal ("current path list: %1", path_list);
string first = path_list[0]:"";
if (current_map[first]:nil == nil)
@@ -480,22 +484,46 @@
// non-tracked file (so, it should be directory)
if (current_file != "" && files_index[current_file]:$[] == $[])
{
-y2internal ("event: %1", event);
- // FIXME not possible to uncheck an item...
- integer len = size (current_file);
- list<string> sel= [];
- foreach (string key, map m, files_index, {
- // FIXME this could get too slow... build a structure while creating items?
- if (substring (key, 0, len) == current_file)
+ void select_items (map current_map, string prefix) {
+ selected_items[prefix] = ! selected_items[prefix]:false;
+ foreach (string key, map submap, current_map, {
+ string new_path = prefix + "/" + key;
+ if (submap != $[])
+ {
+ select_items ((map) submap, new_path);
+ }
+ else
+ {
+ selected_items[new_path] = ! selected_items[new_path]:false;
+ }
+ });
+ }
+ void update_selection (map current_map, list<string> path_list)
+ {
+ string first = path_list[0]:"";
+ if (size (path_list) == 0)
{
- y2security ("select '%1'", key);
- sel = add (sel, key);
+ select_items (current_map, current_file);
+ }
+ else if (haskey (current_map, first))
+ {
+ update_selection ((map)current_map[first]:$[],
+ (list<string>) remove (path_list, 0)
+ );
}
- });
- if (sel != [])
- {
- UI::ChangeWidget (`tree, `SelectedItems, sel);
}
+ list<string> path_l = splitstring (current_file, "/");
+ if (path_l[0]:"" == "")
+ path_l = remove (path_l, 0);
+
+ update_selection (tree_map, path_l);
+
+ list<string> selection = [];
+ foreach (string key, boolean val, selected_items, {
+ if (val)
+ selection = add (selection, key);
+ });
+ UI::ChangeWidget (`tree, `SelectedItems, selection);
}
}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org