void add_folder(nana::treebox& treebox, nana::treebox::item_proxy proxy, std::filesystem::path path)
{
    treebox.auto_draw(false);
    for (std::filesystem::directory_iterator dir_iter{ path }; dir_iter != std::filesystem::directory_iterator{}; ++dir_iter) {
        treebox.insert(proxy, dir_iter->path().u8string(), dir_iter->path().filename().u8string());
    }
    treebox.auto_draw(true);
}

int main() {
    nana::form main_window{ nana::API::make_center(640, 480) };
    nana::treebox music_list{ main_window, nana::rectangle{0,0,200,470} };
    nana::treebox::item_proxy proxy{ music_list.insert("C:/Users/RachelPF99/Music/BMS", "BMS") };
    add_folder(music_list, proxy, "C:/Users/RachelPF99/Music/BMS/");
    main_window.show();
    nana::exec();
    return 0;
}

5db6854b0d1ee.png

Hello everyone, I hope you are doing well.
I am having problems understanding the arguments of the treebox::insert() function.
There are:

  • item_proxy insert(item_proxy pos, const std::string& path_key, std::string title);
  • item_proxy insert(const std::string& path_key, std::string title);

I thought that path_key meant the path of the node. But it seems path_key created a node with four childs, instead of just one with the direction of path_key. Trying to explain better:

I thought that when you call insert(), you insert a node with path_key being an internal path that is stored with the node, so if the user clicks the node you can retrieve the path of the real element in the computer that the node represents, but it seems this is not the case.

The "title" argument is what I thought (the name of the node that will be displayed in the nana::treebox) so there is no problem in there...?

How do I correctly use the treebox?

```` void add_folder(nana::treebox& treebox, nana::treebox::item_proxy proxy, std::filesystem::path path) { treebox.auto_draw(false); for (std::filesystem::directory_iterator dir_iter{ path }; dir_iter != std::filesystem::directory_iterator{}; ++dir_iter) { treebox.insert(proxy, dir_iter->path().u8string(), dir_iter->path().filename().u8string()); } treebox.auto_draw(true); } int main() { nana::form main_window{ nana::API::make_center(640, 480) }; nana::treebox music_list{ main_window, nana::rectangle{0,0,200,470} }; nana::treebox::item_proxy proxy{ music_list.insert("C:/Users/RachelPF99/Music/BMS", "BMS") }; add_folder(music_list, proxy, "C:/Users/RachelPF99/Music/BMS/"); main_window.show(); nana::exec(); return 0; } ```` ![5db6854b0d1ee.png](serve/attachment&path=5db6854b0d1ee.png) Hello everyone, I hope you are doing well. I am having problems understanding the arguments of the treebox::insert() function. There are: - item_proxy insert(item_proxy pos, const std::string& path_key, std::string title); - item_proxy insert(const std::string& path_key, std::string title); I thought that path_key meant the path of the node. But it seems path_key created a node with four childs, instead of just one with the direction of path_key. Trying to explain better: I thought that when you call insert(), you insert a node with path_key being an internal path that is stored with the node, so if the user clicks the node you can retrieve the path of the real element in the computer that the node represents, but it seems this is not the case. The "title" argument is what I thought (the name of the node that will be displayed in the nana::treebox) so there is no problem in there...? How do I correctly use the treebox?

The treebox widget can represent not only filesystem path data, but other data too. In general you need to add both a key and a title. The title is shown in the GUI and the key is used to construct the path to node. When you insert a node using a key with "separators" this is interpreted as a path to the node in the tree (not necessary a filesystem path). The function will try to find that path to modify the pointed node with the new title, but if it is not found it will create a new node. Unfortunately, if no title was given to some of the (internal) nodes created to make the new path they will be shown with no title at all.
Now, if you want to "reconstruct" the path to the node you may use tree.make_key_path.
In your case the treebox path don't coincide with the filesystem path. For you, a simpler alternative maybe to use the overload of item_proxy.append() which add an "internal value" of an arbitrary type to the created node to hold the filesystem path.

By the way, using .u8string() maybe problematic because in c++20 it return a std::u8string and not just std::string and will not work with nana 1.7.x. I'm using path.string()

For example you may use in main:

nana::treebox::item_proxy proxy{ music_list.insert("BMS", "BMS") };

and in add_folder:

void add_folder(nana::treebox& treebox, nana::treebox::item_proxy node, const std::filesystem::path &path)
{
    treebox.auto_draw(false);
    for (const auto& new_path: path)  
    {
        std:string name = new_path.filename().string();
        node.append(name, name, new_path);
    }
    treebox.auto_draw(true);
}

and to return the filesystem path from some node my_node use item__proxy.value()

std::filesystem::path my_path=my_node.value<std::filesystem::path>();
The `treebox` widget can represent not only filesystem path data, but other data too. In general you need to add both a key and a title. The title is shown in the GUI and the key is used to construct the path to node. When you insert a node using a key with "separators" this is interpreted as a path to the node in the tree (not necessary a filesystem path). The function will try to find that path to modify the pointed node with the new title, but if it is not found it will create a new node. Unfortunately, if no title was given to some of the (internal) nodes created to make the new path they will be shown with no title at all. Now, if you want to "reconstruct" the path to the node you may use [tree.make_key_path](http://nanapro.org/en-us/documentation/page.php?u=/widgets/treebox#). In your case the treebox path don't coincide with the filesystem path. For you, a simpler alternative maybe to use the overload of [item_proxy.append()](http://nanapro.org/en-us/documentation/page.php?u=/widgets/treebox-item_proxy#) which add an "internal value" of an arbitrary type to the created node to hold the filesystem path. By the way, using `.u8string()` maybe problematic because in c++20 it return a `std::u8string` and not just `std::string` and will not work with nana 1.7.x. I'm using `path.string()` For example you may use in `main`: ```` nana::treebox::item_proxy proxy{ music_list.insert("BMS", "BMS") }; ```` and in `add_folder`: ```` void add_folder(nana::treebox& treebox, nana::treebox::item_proxy node, const std::filesystem::path &path) { treebox.auto_draw(false); for (const auto& new_path: path) { std:string name = new_path.filename().string(); node.append(name, name, new_path); } treebox.auto_draw(true); } ```` and to return the filesystem path from some node `my_node` use [`item__proxy.value()`](http://qpcr4vir.github.io/nana-doxy/html/d5/d96/classnana_1_1drawerbase_1_1treebox_1_1item__proxy.html) ```` std::filesystem::path my_path=my_node.value<std::filesystem::path>(); ````

The reference manual does not explain details very clearly (or at all). The documentation for treebox::insert (at nanapro.org) is incorrect (the overload that you're using takes an argument that is a key, not a key path).

Take a look at this: https://errorflynn.github.io/nana-docs/#widget_treebox::insert

The reference manual does not explain details very clearly (or at all). The documentation for `treebox::insert` (at nanapro.org) is incorrect (the overload that you're using takes an argument that is a key, not a key path). Take a look at this: https://errorflynn.github.io/nana-docs/#widget_treebox::insert

Thank you for answering, I understand better how to use nana::treebox, the information with append() and std::u8string is also very useful. So far, Nana is a very good library, I really like it, but it needs clearer documentation Y_Y . I will help as I continue to familiarize myself with the library.

Thank you for answering, I understand better how to use nana::treebox, the information with append() and std::u8string is also very useful. So far, Nana is a very good library, I really like it, but it needs clearer documentation Y_Y . I will help as I continue to familiarize myself with the library.

Error Flynn, the documentation you sent is very useful and clear! thank you. By coincidence, I also need to use nana::listbox in my program, which you also covered, it seems I am lucky today. Nana needs documentation like this, I will help as I continue to familiarize myself with the library.

Error Flynn, the documentation you sent is very useful and clear! thank you. By coincidence, I also need to use nana::listbox in my program, which you also covered, it seems I am lucky today. Nana needs documentation like this, I will help as I continue to familiarize myself with the library.
25
views
4
replies
3
followers
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft