+ and add_regvalue_items path =
+ let item = factory#add_item "Copy value to clipboard" in
+ ignore (item#connect#activate
+ ~callback:(fun () -> op_copy_regvalue#call path));
+
+ in
+
+ let has_menu =
+ match paths with
+ | [] -> false
+
+ (* single selection *)
+ | [path, { content=Top (OS os)} ] -> (* top level operating system *)
+ add_top_os_items os path; true
+
+ | [path, { content=Top (Volume dev) }] -> (* top level volume *)
+ add_top_volume_items path; true
+
+ | [path, { content=Directory _ }] -> (* directory *)
+ add_directory_items path; true
+
+ | [path, { content=File _ }] -> (* file *)
+ add_file_items path; true
+
+ | [path, { content=TopWinReg _ }] -> (* top level registry node *)
+ add_topwinreg_items path; true
+
+ | [path, { content=RegKey _ }] -> (* registry node *)
+ add_regkey_items path; true
+
+ | [path, { content=RegValue _ }] -> (* registry key/value pair *)
+ add_regvalue_items path; true
+
+ | [_, { content=(Loading|ErrorMessage _|Info _) }] -> false
+
+ | _::_::_ ->
+ (* At the moment multiple selection is disabled. When/if we
+ * enable it we should do something intelligent here. XXX
+ *)
+ false in
+ if has_menu then Some menu else None
+
+ (* Store hdata into a row. *)
+ method private store_hdata row hdata =
+ let index = unique () in
+ Hashtbl.add hash index hdata;
+ model#set ~row ~column:index_col index
+
+ (* Retrieve previously stored hdata from a row. *)
+ method private get_hdata row =
+ let index = model#get ~row ~column:index_col in
+ try Hashtbl.find hash index
+ with Not_found -> assert false
+
+ (* [find_child_node_by_content row content] searches the direct
+ children of [row] looking for one which exactly matches
+ [hdata.content] and returns that child. If no child found,
+ raises [Not_found]. *)
+ method private find_child_node_by_content row c =
+ let rec loop row =
+ if (self#get_hdata row).content = c then
+ row
+ else if model#iter_next row then
+ loop row
+ else
+ raise Not_found
+ in
+
+ if not (model#iter_has_child row) then
+ raise Not_found;
+
+ let first_child = model#iter_children (Some row) in
+ loop first_child
+
+ (* Search up to the top of the tree so we know if this directory
+ * comes from an OS or a volume, and the full path to here.
+ *
+ * The path up the tree will always look something like:
+ * Top
+ * \_ Directory
+ * \_ Directory
+ * \_ Loading <--- you are here
+ *
+ * Note this function cannot be called on registry keys. See
+ * {!get_registry_path} for that.
+ *)
+ method get_pathname row =
+ let hdata = self#get_hdata row in
+ let parent = model#iter_parent row in
+
+ match hdata, parent with
+ | { state=IsLeaf; content=(Loading|ErrorMessage _|Info _) }, Some parent ->
+ self#get_pathname parent
+ | { state=IsLeaf; content=(Loading|ErrorMessage _|Info _) }, None ->
+ assert false
+ | { content=Directory { dent_name = name }}, Some parent
+ | { content=File { dent_name = name }}, Some parent ->
+ let src, parent_name = self#get_pathname parent in
+ let path =
+ if parent_name = "/" then "/" ^ name
+ else parent_name ^ "/" ^ name in
+ src, path
+ | { content=Top src }, _ -> src, "/"
+ | { content=Directory _ }, None -> assert false
+ | { content=File _ }, None -> assert false
+ | { content=Loading }, _ -> assert false
+ | { content=ErrorMessage _ }, _ -> assert false
+ | { content=Info _ }, _ -> assert false
+ | { content=TopWinReg _ }, _ -> assert false
+ | { content=RegKey _ }, _ -> assert false
+ | { content=RegValue _ }, _ -> assert false
+
+ method get_direntry row =
+ let hdata = self#get_hdata row in
+ match hdata with
+ | { content=Directory direntry}
+ | { content=File direntry} -> direntry
+ | _ -> assert false
+
+ (* Search up to the top of the tree from a registry key.
+ *
+ * The path up the tree will always look something like:
+ * TopWinReg
+ * \_ RegKey
+ * \_ RegKey <--- you are here
+ * \_ Loading <--- or here
+ *
+ * Note this function cannot be called on ordinary paths. Use
+ * {!get_pathname} for that.