Merge pull request #48 from antopilo/NK-141-rename-file&folder
NK-141 - Rename File/Folder
This commit is contained in:
@@ -31,6 +31,9 @@ namespace Nuake
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string renameTempValue = "";
|
||||
|
||||
void FileSystemUI::EditorInterfaceDrawFiletree(Ref<Directory> dir)
|
||||
{
|
||||
ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_FramePadding;
|
||||
@@ -73,6 +76,9 @@ namespace Nuake
|
||||
m_hasClickedOnFile = true;
|
||||
}
|
||||
|
||||
const std::string rename = "Rename" + std::string("##") + hoverMenuId;
|
||||
bool shouldRename = false;
|
||||
|
||||
if (ImGui::BeginPopup(hoverMenuId.c_str()))
|
||||
{
|
||||
if (ImGui::MenuItem("Open"))
|
||||
@@ -106,12 +112,10 @@ namespace Nuake
|
||||
RefreshFileBrowser();
|
||||
}
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 0.2f));
|
||||
if (ImGui::MenuItem("Rename"))
|
||||
{
|
||||
|
||||
shouldRename = true;
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
@@ -123,6 +127,22 @@ namespace Nuake
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (shouldRename)
|
||||
{
|
||||
renameTempValue = directory->name;
|
||||
PopupHelper::OpenPopup(rename);
|
||||
}
|
||||
|
||||
if (PopupHelper::DefineTextDialog(rename, renameTempValue))
|
||||
{
|
||||
if (OS::RenameDirectory(directory, renameTempValue) != 0)
|
||||
{
|
||||
Logger::Log("Cannot rename directory: " + renameTempValue, "editor", CRITICAL);
|
||||
}
|
||||
RefreshFileBrowser();
|
||||
renameTempValue = "";
|
||||
}
|
||||
|
||||
ImGui::Text(directory->name.c_str());
|
||||
ImGui::PopFont();
|
||||
}
|
||||
@@ -206,6 +226,8 @@ namespace Nuake
|
||||
const std::string openScene = "Open Scene" + std::string("##") + hoverMenuId;
|
||||
bool shouldOpenScene = false;
|
||||
|
||||
const std::string rename = "Rename" + std::string("##") + hoverMenuId;
|
||||
bool shouldRename = false;
|
||||
|
||||
if (ImGui::BeginPopup(hoverMenuId.c_str()))
|
||||
{
|
||||
@@ -268,12 +290,10 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 0.2f));
|
||||
if (ImGui::MenuItem("Rename"))
|
||||
{
|
||||
|
||||
shouldRename = true;
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
@@ -290,12 +310,14 @@ namespace Nuake
|
||||
shouldOpenScene = file->GetExtension() == ".scene";
|
||||
}
|
||||
|
||||
// Open Scene Popup
|
||||
|
||||
if (shouldOpenScene)
|
||||
{
|
||||
PopupHelper::Confirmation(openScene);
|
||||
PopupHelper::OpenPopup(openScene);
|
||||
}
|
||||
|
||||
if (PopupHelper::DefineDialog(openScene, " Open the scene? \n Changes will not be saved."))
|
||||
if (PopupHelper::DefineConfirmationDialog(openScene, " Open the scene? \n Changes will not be saved."))
|
||||
{
|
||||
Ref<Scene> scene = Scene::New();
|
||||
const std::string projectPath = file->GetAbsolutePath();
|
||||
@@ -309,6 +331,25 @@ namespace Nuake
|
||||
Engine::LoadScene(scene);
|
||||
}
|
||||
|
||||
// Rename Popup
|
||||
|
||||
if (shouldRename)
|
||||
{
|
||||
renameTempValue = file->GetName();
|
||||
PopupHelper::OpenPopup(rename);
|
||||
}
|
||||
|
||||
if (PopupHelper::DefineTextDialog(rename, renameTempValue))
|
||||
{
|
||||
if(OS::RenameFile(file, renameTempValue) != 0)
|
||||
{
|
||||
Logger::Log("Cannot rename file: " + renameTempValue, "editor", CRITICAL);
|
||||
}
|
||||
RefreshFileBrowser();
|
||||
renameTempValue = "";
|
||||
}
|
||||
|
||||
|
||||
ImGui::Text(file->GetName().c_str());
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user