mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-21 20:08:40 +03:00
Delete Selected File from Context Menu
This commit is contained in:
@@ -41,6 +41,7 @@ class MyEntityScript is ScriptableEntity {
|
||||
#include <src/Rendering/Textures/Material.h>
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
// TODO: add filetree in same panel
|
||||
void FileSystemUI::Draw()
|
||||
{
|
||||
@@ -114,7 +115,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 +164,25 @@ 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().c_str()) != 0)
|
||||
{
|
||||
Logger::Log("Failed to remove file: " + file->GetAbsolutePath(), CRITICAL);
|
||||
}
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
RefreshFileBrowser();
|
||||
}
|
||||
|
||||
ImGui::Text(file->GetName().c_str());
|
||||
ImGui::PopFont();
|
||||
}
|
||||
@@ -181,7 +201,9 @@ 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 +394,13 @@ namespace Nuake {
|
||||
else
|
||||
ImGui::TableNextRow();
|
||||
|
||||
DrawFile(f);
|
||||
DrawFile(f, i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
DrawContextMenu();
|
||||
m_hasClickedOnFile = false;
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
@@ -166,6 +166,11 @@ namespace Nuake
|
||||
fileWriter.close();
|
||||
}
|
||||
|
||||
int FileSystem::RemoveFile(char const* path)
|
||||
{
|
||||
return std::remove(path);
|
||||
}
|
||||
|
||||
Ref<Directory> FileSystem::GetFileTree()
|
||||
{
|
||||
return RootDirectory;
|
||||
|
||||
@@ -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(char const* path);
|
||||
};
|
||||
|
||||
class File
|
||||
|
||||
Reference in New Issue
Block a user