-
Notifications
You must be signed in to change notification settings - Fork 272
Editor Layouts Management #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
562c8fa
006b4ce
4e96974
0dbdddd
7934b0b
db8ecd8
d7ad241
f7f334e
46e1496
2a2ea98
6a5a3bc
4367683
a202fe1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,8 @@ | |||||||||
* @licence: MIT | ||||||||||
*/ | ||||||||||
|
||||||||||
#include <filesystem> | ||||||||||
|
||||||||||
#include <OvTools/Utils/SystemCalls.h> | ||||||||||
|
||||||||||
#include <OvCore/ECS/Components/CCamera.h> | ||||||||||
|
@@ -30,6 +32,7 @@ | |||||||||
#include "OvEditor/Core/EditorActions.h" | ||||||||||
#include "OvEditor/Settings/EditorSettings.h" | ||||||||||
#include "OvEditor/Utils/ActorCreationMenu.h" | ||||||||||
#include "OvUI/Plugins/ContextualMenu.h" | ||||||||||
|
||||||||||
using namespace OvUI::Panels; | ||||||||||
using namespace OvUI::Widgets; | ||||||||||
|
@@ -197,8 +200,80 @@ void OvEditor::Panels::MenuBar::CreateSettingsMenu() | |||||||||
|
||||||||||
void OvEditor::Panels::MenuBar::CreateLayoutMenu() | ||||||||||
{ | ||||||||||
auto& layoutMenu = CreateWidget<MenuList>("Layout"); | ||||||||||
layoutMenu.CreateWidget<MenuItem>("Reset").ClickedEvent += EDITOR_BIND(ResetLayout); | ||||||||||
auto& layoutMenuList = CreateWidget<MenuList>("Layout"); | ||||||||||
|
||||||||||
auto& uiManager = *EDITOR_CONTEXT(uiManager); | ||||||||||
const std::filesystem::path& layoutsPath = uiManager.GetLayoutsPath(); | ||||||||||
|
||||||||||
auto& saveMenuItem = layoutMenuList.CreateWidget<MenuItem>("Save"); | ||||||||||
saveMenuItem.ClickedEvent += EDITOR_BIND(SaveCurrentLayout); | ||||||||||
|
||||||||||
auto& saveNewMenuList = layoutMenuList.CreateWidget<MenuList>("Save New"); | ||||||||||
auto& layoutInputText = saveNewMenuList.CreateWidget<InputFields::InputText>("Layout Name"); | ||||||||||
layoutInputText.selectAllOnClick = true; | ||||||||||
layoutInputText.EnterPressedEvent += [&layoutsPath](std::string p_input) | ||||||||||
{ | ||||||||||
if (p_input.empty()) | ||||||||||
return; | ||||||||||
|
||||||||||
auto& uiManager = *EDITOR_CONTEXT(uiManager); | ||||||||||
EDITOR_EXEC(DelayAction(std::bind(&OvUI::Core::UIManager::SaveLayout, &uiManager, layoutsPath / (p_input + ".ini")), 1)); | ||||||||||
}; | ||||||||||
|
||||||||||
auto& loadMenuList = layoutMenuList.CreateWidget<MenuList>("Load"); | ||||||||||
|
||||||||||
loadMenuList.ClickedEvent += [&] | ||||||||||
{ | ||||||||||
loadMenuList.RemoveAllWidgets(); | ||||||||||
|
||||||||||
for (const auto& entry : std::filesystem::directory_iterator(layoutsPath)) | ||||||||||
{ | ||||||||||
if (entry.is_regular_file() && entry.path().extension() == ".ini") | ||||||||||
{ | ||||||||||
auto& layoutMenuItem = loadMenuList.CreateWidget<MenuItem>(entry.path().stem().string()); | ||||||||||
layoutMenuItem.name = entry.path().stem().string(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could display which layout is currently selected with a checkmark
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, since with this change we can show the currently selected layout, maybe we should always have a "Default" option in the "Load" list (instead of "Reset" outside of the list), and the "Default" option would have no contextual menu (so it cannot be deleted/renamed) |
||||||||||
|
||||||||||
layoutMenuItem.ClickedEvent += [entry] | ||||||||||
{ | ||||||||||
auto& uiManager = *EDITOR_CONTEXT(uiManager); | ||||||||||
EDITOR_EXEC(DelayAction(std::bind(&OvUI::Core::UIManager::SetLayout, &uiManager, entry.path()), 1)); | ||||||||||
|
||||||||||
Settings::EditorSettings::LatestLayout = entry.path().string(); | ||||||||||
maxbrundev marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
}; | ||||||||||
|
||||||||||
auto& contextualMenu = layoutMenuItem.AddPlugin<OvUI::Plugins::ContextualMenu>(); | ||||||||||
auto& deleteMenuItem = contextualMenu.CreateWidget<MenuItem>("Delete"); | ||||||||||
|
||||||||||
deleteMenuItem.ClickedEvent += [entry, &layoutMenuItem] | ||||||||||
{ | ||||||||||
auto& uiManager = *EDITOR_CONTEXT(uiManager); | ||||||||||
EDITOR_EXEC(DelayAction(std::bind(&OvUI::Core::UIManager::DeleteLayout, &uiManager, entry.path()), 1)); | ||||||||||
layoutMenuItem.enabled = false; | ||||||||||
|
||||||||||
}; | ||||||||||
auto& renameToMenuList = contextualMenu.CreateWidget<MenuList>("Rename to..."); | ||||||||||
|
||||||||||
auto& renameInputText = renameToMenuList.CreateWidget<InputFields::InputText>(""); | ||||||||||
renameInputText.content = entry.path().stem().string(); | ||||||||||
renameInputText.selectAllOnClick = true; | ||||||||||
|
||||||||||
renameInputText.EnterPressedEvent += [entry, &layoutMenuItem, &layoutsPath, &contextualMenu](std::string p_newName) | ||||||||||
{ | ||||||||||
if (p_newName.empty()) | ||||||||||
return; | ||||||||||
|
||||||||||
layoutMenuItem.name = p_newName; | ||||||||||
|
||||||||||
auto& uiManager = *EDITOR_CONTEXT(uiManager); | ||||||||||
EDITOR_EXEC(DelayAction(std::bind(&OvUI::Core::UIManager::RenameLayout, &uiManager, entry.path(), layoutsPath / (p_newName + ".ini")), 1)); | ||||||||||
|
||||||||||
contextualMenu.Close(); | ||||||||||
}; | ||||||||||
} | ||||||||||
} | ||||||||||
}; | ||||||||||
|
||||||||||
layoutMenuList.CreateWidget<MenuItem>("Reset").ClickedEvent += EDITOR_BIND(ResetLayout); | ||||||||||
} | ||||||||||
|
||||||||||
void OvEditor::Panels::MenuBar::CreateHelpMenu() | ||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this call, we should also update
Settings::EditorSettings::LatestLayout
, otherwise creating a new layout and exiting, result in theLatestLayout
still being the previous one.