From 0a4e0383a03e22bcfaf66b6e8051852b8e961192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Mon, 29 Apr 2024 08:40:48 +0200 Subject: [PATCH] editor: content browser recently used folder listing --- Editor/ContentBrowserWindow.cpp | 43 ++++++++++++++++++- Editor/ContentBrowserWindow.h | 3 ++ Editor/Editor.cpp | 73 +++++++++++++++++++++++++-------- Editor/Editor.h | 2 + 4 files changed, 102 insertions(+), 19 deletions(-) diff --git a/Editor/ContentBrowserWindow.cpp b/Editor/ContentBrowserWindow.cpp index cecb277d3..6043f9593 100644 --- a/Editor/ContentBrowserWindow.cpp +++ b/Editor/ContentBrowserWindow.cpp @@ -130,6 +130,7 @@ void ContentBrowserWindow::ResizeLayout() openFolderButton.SetSize(XMFLOAT2(separator - padding * 2, openFolderButton.GetSize().y)); openFolderButton.AttachTo(this); + size_t seli = 0; for (auto& x : folderButtons) { x.Detach(); @@ -137,6 +138,9 @@ void ContentBrowserWindow::ResizeLayout() x.SetSize(XMFLOAT2(separator - padding * 2, x.GetSize().y)); y += x.GetSize().y + padding; x.AttachTo(this); + seli++; + if (seli == SELECTION_RECENTFOLDER_BEGIN) + y += x.GetSize().y + padding; } y = padding + 10; @@ -181,6 +185,7 @@ void ContentBrowserWindow::RefreshContent() { wi::gui::Button& button = folderButtons[SELECTION_RECENT]; button.Create("Recently Used"); + button.SetTooltip("List all recently used files, not grouped by folders."); button.SetLocalizationEnabled(false); button.SetSize(XMFLOAT2(wid, hei)); button.OnClick([this](wi::gui::EventArgs args) { @@ -196,6 +201,7 @@ void ContentBrowserWindow::RefreshContent() { wi::gui::Button& button = folderButtons[SELECTION_SCRIPTS]; button.Create("Scripts"); + button.SetTooltip(content_folder + "scripts"); button.SetLocalizationEnabled(false); button.SetSize(XMFLOAT2(wid, hei)); button.OnClick([this](wi::gui::EventArgs args) { @@ -211,6 +217,7 @@ void ContentBrowserWindow::RefreshContent() { wi::gui::Button& button = folderButtons[SELECTION_MODELS]; button.Create("Models"); + button.SetTooltip(content_folder + "models"); button.SetLocalizationEnabled(false); button.SetSize(XMFLOAT2(wid, hei)); button.OnClick([this](wi::gui::EventArgs args) { @@ -223,6 +230,26 @@ void ContentBrowserWindow::RefreshContent() } } + for (size_t i = 0; i < editor->recentFolders.size(); ++i) + { + wi::gui::Button& button = folderButtons[SELECTION_RECENTFOLDER_BEGIN + i]; + std::string folder = editor->recentFolders[i]; + folder = folder.substr(0, folder.find_last_of("/\\")); + folder = folder.substr(folder.find_last_of("/\\")); + button.Create(folder); + button.SetTooltip(editor->recentFolders[i]); // full folder name! + button.SetLocalizationEnabled(false); + button.SetSize(XMFLOAT2(wid, hei)); + button.OnClick([this, i](wi::gui::EventArgs args) { + SetSelection((SELECTION)(SELECTION_RECENTFOLDER_BEGIN + i)); + }); + AddWidget(&button, wi::gui::Window::AttachmentOptions::NONE); + if (current_selection == SELECTION_COUNT) + { + current_selection = (SELECTION)(SELECTION_RECENTFOLDER_BEGIN + i); + } + } + if (current_selection != SELECTION_COUNT) { SetSelection(current_selection); @@ -244,7 +271,6 @@ void ContentBrowserWindow::SetSelection(SELECTION selection) switch (selection) { - default: case SELECTION_SCRIPTS: AddItems(content_folder + "scripts/", "lua", ICON_SCRIPT); openFolderButton.OnClick([this](wi::gui::EventArgs args) { @@ -289,6 +315,21 @@ void ContentBrowserWindow::SetSelection(SELECTION selection) } } break; + default: + { + size_t i = selection - SELECTION_RECENTFOLDER_BEGIN; + i = std::min(i, editor->recentFolders.size() - 1); + const std::string& folder = editor->recentFolders[i]; + AddItems(folder + "/", "wiscene", ICON_OBJECT); + AddItems(folder + "/", "gltf", ICON_OBJECT); + AddItems(folder + "/", "glb", ICON_OBJECT); + AddItems(folder + "/", "obj", ICON_OBJECT); + openFolderButton.OnClick([this, folder](wi::gui::EventArgs args) { + wi::helper::OpenUrl(folder); + }); + AddWidget(&openFolderButton, wi::gui::Window::AttachmentOptions::NONE); + } + break; } for (auto& x : itemButtons) diff --git a/Editor/ContentBrowserWindow.h b/Editor/ContentBrowserWindow.h index be9438b79..889048d24 100644 --- a/Editor/ContentBrowserWindow.h +++ b/Editor/ContentBrowserWindow.h @@ -15,6 +15,9 @@ public: SELECTION_SCRIPTS, SELECTION_MODELS, + SELECTION_RECENTFOLDER_BEGIN, + SELECTION_RECENTFOLDER_END = SELECTION_RECENTFOLDER_BEGIN + 10, + SELECTION_COUNT }; SELECTION current_selection = SELECTION_COUNT; diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 2981db7e4..91ff2478e 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -717,12 +717,23 @@ void EditorComponent::Load() }; wi::helper::GetFileNamesInDirectory("fonts/", load_font, "TTF"); - size_t current_recent = 0; - auto& recent = main->config.GetSection("recent"); - while (recent.Has(std::to_string(current_recent).c_str())) { - recentFilenames.push_back(recent.GetText(std::to_string(current_recent).c_str())); - current_recent++; + size_t current_recent = 0; + auto& recent = main->config.GetSection("recent"); + while (recent.Has(std::to_string(current_recent).c_str())) + { + recentFilenames.push_back(recent.GetText(std::to_string(current_recent).c_str())); + current_recent++; + } + } + { + size_t current_recent = 0; + auto& recent = main->config.GetSection("recent_folders"); + while (recent.Has(std::to_string(current_recent).c_str())) + { + recentFolders.push_back(recent.GetText(std::to_string(current_recent).c_str())); + current_recent++; + } } RenderPath2D::Load(); @@ -3642,26 +3653,52 @@ void EditorComponent::ConsumeHistoryOperation(bool undo) void EditorComponent::RegisterRecentlyUsed(const std::string& filename) { - for (size_t i = 0; i < recentFilenames.size();) { - if (recentFilenames[i].compare(filename) == 0) + for (size_t i = 0; i < recentFilenames.size();) { - recentFilenames.erase(recentFilenames.begin() + i); + if (recentFilenames[i].compare(filename) == 0) + { + recentFilenames.erase(recentFilenames.begin() + i); + } + else + { + i++; + } } - else + while (recentFilenames.size() >= maxRecentFilenames) { - i++; + recentFilenames.erase(recentFilenames.begin()); + } + recentFilenames.push_back(filename); + auto& recent = main->config.GetSection("recent"); + for (size_t i = 0; i < recentFilenames.size(); ++i) + { + recent.Set(std::to_string(i).c_str(), recentFilenames[i]); } } - while (recentFilenames.size() >= maxRecentFilenames) { - recentFilenames.erase(recentFilenames.begin()); - } - recentFilenames.push_back(filename); - auto& recent = main->config.GetSection("recent"); - for (size_t i = 0; i < recentFilenames.size(); ++i) - { - recent.Set(std::to_string(i).c_str(), recentFilenames[i]); + std::string folder = wi::helper::GetDirectoryFromPath(filename); + for (size_t i = 0; i < recentFolders.size();) + { + if (recentFolders[i].compare(folder) == 0) + { + recentFolders.erase(recentFolders.begin() + i); + } + else + { + i++; + } + } + while (recentFolders.size() >= maxRecentFolders) + { + recentFolders.erase(recentFolders.begin()); + } + recentFolders.push_back(folder); + auto& recent = main->config.GetSection("recent_folders"); + for (size_t i = 0; i < recentFolders.size(); ++i) + { + recent.Set(std::to_string(i).c_str(), recentFolders[i]); + } } main->config.Commit(); contentBrowserWnd.RefreshContent(); diff --git a/Editor/Editor.h b/Editor/Editor.h index 4e6e79d8e..7768cf533 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -141,6 +141,8 @@ public: wi::vector recentFilenames; size_t maxRecentFilenames = 10; + wi::vector recentFolders; + size_t maxRecentFolders = 5; void RegisterRecentlyUsed(const std::string& filename); void Open(const std::string& filename);