Merge pull request #20 from antopilo/feature/NK-96-delete-file-from-context-menu

Delete Hovered File from Context Menu
This commit is contained in:
émeryc
2023-07-09 23:50:55 -04:00
committed by GitHub
4 changed files with 45 additions and 6 deletions

View File

@@ -40,7 +40,9 @@ class MyEntityScript is ScriptableEntity {
#include <src/Rendering/Textures/Material.h>
namespace Nuake {
namespace Nuake
{
// TODO: add filetree in same panel
void FileSystemUI::Draw()
{
@@ -114,7 +116,7 @@ namespace Nuake {
return true;
}
void FileSystemUI::DrawFile(Ref<File> file)
void FileSystemUI::DrawFile(Ref<File> file, uint32_t drawId)
{
ImGui::PushFont(EditorInterface::bigIconFont);
std::string fileExtension = file->GetExtension();
@@ -163,6 +165,26 @@ namespace Nuake {
}
}
const std::string hoverMenuId = std::string("item_hover_menu") + std::to_string(drawId);
if (ImGui::IsItemHovered() && ImGui::IsMouseReleased(1))
{
ImGui::OpenPopup(hoverMenuId.c_str());
m_hasClickedOnFile = true;
}
if (ImGui::BeginPopup(hoverMenuId.c_str()))
{
if (ImGui::MenuItem("Delete"))
{
if(FileSystem::RemoveFile(file->GetAbsolutePath()) != 0)
{
Logger::Log("Failed to remove file: " + file->GetAbsolutePath(), CRITICAL);
}
}
ImGui::EndPopup();
RefreshFileBrowser();
}
ImGui::Text(file->GetName().c_str());
ImGui::PopFont();
}
@@ -181,7 +203,12 @@ namespace Nuake {
void FileSystemUI::DrawContextMenu()
{
if (ImGui::BeginPopupContextWindow())
if (!m_hasClickedOnFile && ImGui::IsMouseReleased(1) && ImGui::IsWindowHovered())
{
ImGui::OpenPopup("window_hover_menu");
}
if (ImGui::BeginPopup("window_hover_menu"))
{
if (ImGui::MenuItem("New folder"))
{
@@ -372,12 +399,14 @@ namespace Nuake {
else
ImGui::TableNextRow();
DrawFile(f);
DrawFile(f, i);
i++;
}
}
DrawContextMenu();
m_hasClickedOnFile = false;
ImGui::EndTable();
}

View File

@@ -11,9 +11,12 @@ namespace Nuake {
public:
Ref<Directory> m_CurrentDirectory;
bool m_hasClickedOnFile;
FileSystemUI(EditorInterface* editor) {
FileSystemUI(EditorInterface* editor)
{
m_CurrentDirectory = FileSystem::RootDirectory;
m_hasClickedOnFile = false;
Editor = editor;
}
@@ -23,8 +26,9 @@ namespace Nuake {
void EditorInterfaceDrawFiletree(Ref<Directory> dir);
void DrawDirectory(Ref<Directory> directory);
bool EntityContainsItself(Entity source, Entity target);
void DrawFile(Ref<File> file);
void DrawFile(Ref<File> file, uint32_t drawId);
void DrawDirectoryExplorer();
bool DeletePopup();
void DrawContextMenu();
void RefreshFileBrowser();
};

View File

@@ -166,6 +166,11 @@ namespace Nuake
fileWriter.close();
}
int FileSystem::RemoveFile(const std::string& path)
{
return std::remove(path.c_str());
}
Ref<Directory> FileSystem::GetFileTree()
{
return RootDirectory;

View File

@@ -43,6 +43,7 @@ namespace Nuake
static bool BeginWriteFile(const std::string path);
static bool WriteLine(const std::string line);
static void EndWriteFile();
static int RemoveFile(const std::string& path);
};
class File