Add categories to Windows to filter actions to display
This commit is contained in:
parent
9b9b93a183
commit
52ed1e7749
|
|
@ -8,7 +8,7 @@ namespace Nz
|
|||
: public EditorWindow
|
||||
{
|
||||
public:
|
||||
EditorMainWindow(EditorBaseApplication* app, const std::string& name = "");
|
||||
EditorMainWindow(EditorBaseApplication* app, const std::string& name = "", const std::vector<std::string>& categories = {});
|
||||
virtual ~EditorMainWindow() = default;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace Nz
|
|||
: private Nz::ImguiHandler
|
||||
{
|
||||
public:
|
||||
EditorWindow(EditorBaseApplication* app, const std::string& name = "");
|
||||
EditorWindow(EditorBaseApplication* app, const std::string& name = "", const std::vector<std::string>& categories = {});
|
||||
virtual ~EditorWindow();
|
||||
|
||||
EditorWindow(const EditorWindow&) = delete;
|
||||
|
|
@ -28,6 +28,8 @@ namespace Nz
|
|||
EditorBaseApplication* GetApplication() { return m_application; }
|
||||
const EditorBaseApplication* GetApplication() const { return m_application; }
|
||||
|
||||
bool HasMenuCategory(const std::string& category) const;
|
||||
|
||||
protected:
|
||||
void DrawMenus();
|
||||
|
||||
|
|
@ -39,6 +41,7 @@ namespace Nz
|
|||
|
||||
EditorBaseApplication* m_application;
|
||||
std::string m_windowName;
|
||||
std::vector<std::string> m_categories;
|
||||
|
||||
struct MenuAction
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
EditorMainWindow::EditorMainWindow(EditorBaseApplication* app, const std::string& name)
|
||||
: EditorWindow(app, name)
|
||||
EditorMainWindow::EditorMainWindow(EditorBaseApplication* app, const std::string& name, const std::vector<std::string>& categories)
|
||||
: EditorWindow(app, name, categories)
|
||||
{ }
|
||||
|
||||
void EditorMainWindow::OnRenderImgui()
|
||||
|
|
|
|||
|
|
@ -4,12 +4,18 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
EditorWindow::EditorWindow(EditorBaseApplication* app, const std::string& name)
|
||||
EditorWindow::EditorWindow(EditorBaseApplication* app, const std::string& name, const std::vector<std::string>& categories)
|
||||
: m_application(app)
|
||||
, m_windowName(name)
|
||||
, m_categories(categories)
|
||||
{
|
||||
Nz::Imgui::Instance()->AddHandler(this);
|
||||
|
||||
// Automatically add actions to menus
|
||||
app->OnActionRegistered.Connect([this](auto&& prop) {
|
||||
if (!HasMenuCategory(prop.category))
|
||||
return;
|
||||
|
||||
auto name = prop.className;
|
||||
AddMenuAction(prop.path, prop.shortcut.ToString(), [name]() { Nz::ActionStack::Instance()->ExecuteAction(name); }, prop.icon);
|
||||
});
|
||||
|
|
@ -60,6 +66,12 @@ namespace Nz
|
|||
parent.entries.push_back(MenuSeparator{});
|
||||
}
|
||||
|
||||
bool EditorWindow::HasMenuCategory(const std::string& category) const
|
||||
{
|
||||
return std::find_if(m_categories.begin(), m_categories.end(), [&category](auto&& cat) { return cat == category; })
|
||||
!= m_categories.end();
|
||||
}
|
||||
|
||||
void EditorWindow::DrawMenus()
|
||||
{
|
||||
if (m_root.entries.empty())
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace NzEditor
|
||||
{
|
||||
AssetsWindow::AssetsWindow(Nz::EditorBaseApplication* app)
|
||||
: Nz::EditorWindow(app, "Assets Browser")
|
||||
: Nz::EditorWindow(app, "Assets Browser", { "Assets" })
|
||||
{
|
||||
BuildMenuBar();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,21 +3,8 @@
|
|||
namespace NzEditor
|
||||
{
|
||||
MainWindow::MainWindow(Nz::EditorBaseApplication* app)
|
||||
: Nz::EditorMainWindow(app, "MainWindow")
|
||||
: Nz::EditorMainWindow(app, "MainWindow", { "General", "Plugins" })
|
||||
{
|
||||
BuildMenuBar();
|
||||
}
|
||||
|
||||
void MainWindow::BuildMenuBar()
|
||||
{
|
||||
AddMenuAction("File|Project|New", "Ctrl+Shift+N", [this]() { NewProject(); });
|
||||
AddMenuAction("File|Project|Open", "Ctrl+Shift+O", [this]() { OpenProject(); });
|
||||
AddMenuAction("File|Project|Save", "Ctrl+Shift+S", [this]() { SaveProject(); });
|
||||
AddMenuAction("File|Level|New", "Ctrl+N", [this]() { NewLevel(); });
|
||||
AddMenuAction("File|Level|Open", "Ctrl+O", [this]() { OpenLevel(); });
|
||||
AddMenuAction("File|Level|Save", "Ctrl+S", [this]() { SaveLevel(); });
|
||||
AddMenuSeparator("File");
|
||||
AddMenuAction("File|Quit", "Ctrl+W", [this]() { Quit(); });
|
||||
}
|
||||
|
||||
bool MainWindow::Quit()
|
||||
|
|
|
|||
Loading…
Reference in New Issue