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