|
1
|
1 #include "foobar2000-sdk-pch.h"
|
|
|
2 #include "contextmenu.h"
|
|
|
3 #include "contextmenu_manager.h"
|
|
|
4 #include "metadb.h"
|
|
|
5
|
|
|
6 bool contextmenu_item::item_get_display_data_root(pfc::string_base & p_out,unsigned & p_displayflags,unsigned p_index,const pfc::list_base_const_t<metadb_handle_ptr> & p_data,const GUID & p_caller)
|
|
|
7 {
|
|
|
8 bool status = false;
|
|
|
9 pfc::ptrholder_t<contextmenu_item_node_root> root ( instantiate_item(p_index,p_data,p_caller) );
|
|
|
10 if (root.is_valid()) status = root->get_display_data(p_out,p_displayflags,p_data,p_caller);
|
|
|
11 return status;
|
|
|
12 }
|
|
|
13
|
|
|
14
|
|
|
15 static contextmenu_item_node * g_find_node(const GUID & p_guid,contextmenu_item_node * p_parent)
|
|
|
16 {
|
|
|
17 if (p_parent->get_guid() == p_guid) return p_parent;
|
|
|
18 else if (p_parent->get_type() == contextmenu_item_node::TYPE_POPUP)
|
|
|
19 {
|
|
|
20 t_size n, m = p_parent->get_children_count();
|
|
|
21 for(n=0;n<m;n++)
|
|
|
22 {
|
|
|
23 contextmenu_item_node * temp = g_find_node(p_guid,p_parent->get_child(n));
|
|
|
24 if (temp) return temp;
|
|
|
25 }
|
|
|
26 return 0;
|
|
|
27 }
|
|
|
28 else return 0;
|
|
|
29 }
|
|
|
30
|
|
|
31 bool contextmenu_item::item_get_display_data(pfc::string_base & p_out,unsigned & p_displayflags,unsigned p_index,const GUID & p_node,const pfc::list_base_const_t<metadb_handle_ptr> & p_data,const GUID & p_caller)
|
|
|
32 {
|
|
|
33 bool status = false;
|
|
|
34 pfc::ptrholder_t<contextmenu_item_node_root> root ( instantiate_item(p_index,p_data,p_caller) );
|
|
|
35 if (root.is_valid())
|
|
|
36 {
|
|
|
37 contextmenu_item_node * node = g_find_node(p_node,root.get_ptr());
|
|
|
38 if (node) status = node->get_display_data(p_out,p_displayflags,p_data,p_caller);
|
|
|
39 }
|
|
|
40 return status;
|
|
|
41 }
|
|
|
42
|
|
|
43
|
|
|
44 GUID contextmenu_item::get_parent_fallback() {
|
|
|
45 unsigned total = get_num_items();
|
|
|
46 if (total < 1) return pfc::guid_null; // hide the item
|
|
|
47 pfc::string_formatter path, base; this->get_item_default_path(0, base);
|
|
|
48 for(unsigned walk = 1; walk < total; ++walk) {
|
|
|
49 this->get_item_default_path(walk, path);
|
|
|
50 if (strcmp(path, base) != 0) return contextmenu_groups::legacy;
|
|
|
51 }
|
|
|
52 return contextmenu_group_manager::get()->path_to_group(base);
|
|
|
53 }
|
|
|
54
|
|
|
55 GUID contextmenu_item::get_parent_() {
|
|
|
56 contextmenu_item_v2::ptr v2;
|
|
|
57 if (service_query_t(v2)) {
|
|
|
58 return v2->get_parent();
|
|
|
59 } else {
|
|
|
60 return get_parent_fallback();
|
|
|
61 }
|
|
|
62 }
|