[studio] Fix NewMenu to track prev stage correctly when going back two stages

This commit is contained in:
Gary Talent 2025-01-23 21:13:58 -06:00
parent 9511cb5719
commit 82e2ea747f
2 changed files with 11 additions and 13 deletions

View File

@ -21,7 +21,7 @@ void NewMenu::open() noexcept {
m_selectedType = 0; m_selectedType = 0;
m_itemName = ""; m_itemName = "";
m_typeName = ""; m_typeName = "";
m_path = ""; m_useDefaultPath = true;
m_explorer.setModel(buildFileTreeModel( m_explorer.setModel(buildFileTreeModel(
m_explorer, m_explorer,
[](ox::StringViewCR, ox::FileStat const&s) { [](ox::StringViewCR, ox::FileStat const&s) {
@ -29,9 +29,10 @@ void NewMenu::open() noexcept {
}).or_value(ox::UPtr<FileTreeModel>{})); }).or_value(ox::UPtr<FileTreeModel>{}));
} }
void NewMenu::openPath(ox::StringParam path) noexcept { void NewMenu::openPath(ox::StringViewCR path) noexcept {
open(); open();
m_path = std::move(path); m_useDefaultPath = false;
std::ignore = m_explorer.setSelectedPath(path);
} }
void NewMenu::close() noexcept { void NewMenu::close() noexcept {
@ -92,10 +93,9 @@ void NewMenu::drawNewItemType(StudioContext const&sctx) noexcept {
drawFirstPageButtons(im.itemTemplates().size() == 1 ? drawFirstPageButtons(im.itemTemplates().size() == 1 ?
Stage::NewItemPath : Stage::NewItemTemplate); Stage::NewItemPath : Stage::NewItemTemplate);
if (m_stage == Stage::NewItemPath || m_stage == Stage::NewItemTemplate) { if (m_stage == Stage::NewItemPath || m_stage == Stage::NewItemTemplate) {
if (m_path.len() == 0) { if (m_useDefaultPath) {
m_path = im.defaultPath(); std::ignore = m_explorer.setSelectedPath(im.defaultPath());
} }
std::ignore = m_explorer.setSelectedPath(m_path);
} }
}); });
} }
@ -189,11 +189,9 @@ void NewMenu::finish(StudioContext &sctx) noexcept {
oxLogError(ox::Error{1, "New file error: no file name"}); oxLogError(ox::Error{1, "New file error: no file name"});
return; return;
} }
auto const&im = *m_types[m_selectedType]; auto const &im = *m_types[m_selectedType];
if (auto p = m_explorer.selectedPath()) { auto const path = sfmt("{}/{}.{}",
m_path = std::move(*p); m_explorer.selectedPath().or_value(ox::String{}), m_itemName, im.fileExt());
}
auto const path = sfmt("{}/{}.{}", m_path, m_itemName, im.fileExt());
if (sctx.project->exists(path)) { if (sctx.project->exists(path)) {
oxLogError(ox::Error{1, "New file error: file already exists"}); oxLogError(ox::Error{1, "New file error: file already exists"});
return; return;

View File

@ -33,7 +33,7 @@ class NewMenu final: public Popup {
keel::Context &m_kctx; keel::Context &m_kctx;
ox::String m_typeName; ox::String m_typeName;
ox::IString<255> m_itemName; ox::IString<255> m_itemName;
ox::String m_path; bool m_useDefaultPath{};
ox::Vector<ox::UPtr<ItemMaker>> m_types; ox::Vector<ox::UPtr<ItemMaker>> m_types;
FileExplorer m_explorer{m_kctx}; FileExplorer m_explorer{m_kctx};
size_t m_selectedType = 0; size_t m_selectedType = 0;
@ -43,7 +43,7 @@ class NewMenu final: public Popup {
public: public:
NewMenu(keel::Context &kctx) noexcept; NewMenu(keel::Context &kctx) noexcept;
void openPath(ox::StringParam path) noexcept; void openPath(ox::StringViewCR path) noexcept;
void open() noexcept override; void open() noexcept override;