Open Folder in File Explorer

This commit is contained in:
émeryc
2023-07-12 21:41:09 -04:00
parent e90776e6bb
commit 12e7cb0625
10 changed files with 46 additions and 14 deletions

View File

@@ -92,7 +92,7 @@ int main(int argc, char* argv[])
editor.BuildFonts();
Ref<Nuake::Project> project = Nuake::Project::New();
FileSystem::SetRootDirectory(projectPath + "/../");
FileSystem::SetRootDirectory(FileSystem::RemoveFileFromPath(projectPath));
project->FullPath = projectPath;
project->Deserialize(FileSystem::ReadFile(projectPath, true));
@@ -143,7 +143,7 @@ int main(int argc, char* argv[])
if (shouldLoadProject)
{
FileSystem::SetRootDirectory(projectPath + "/../");
FileSystem::SetRootDirectory(FileSystem::RemoveFileFromPath(projectPath));
auto project = Project::New();
auto projectFileData = FileSystem::ReadFile(projectPath, true);

View File

@@ -41,8 +41,7 @@ namespace Nuake
{
// Parse the project and load it.
std::string projectPath = FileDialog::OpenFile(".project");
FileSystem::SetRootDirectory(projectPath + "/../");
FileSystem::SetRootDirectory(FileSystem::RemoveFileFromPath(projectPath));
Ref<Project> project = Project::New();
if (!project->Deserialize(FileSystem::ReadFile(projectPath, true)))
{

View File

@@ -1291,7 +1291,7 @@ namespace Nuake {
if (projectPath == "") // Hit cancel.
return;
FileSystem::SetRootDirectory(projectPath + "/../");
FileSystem::SetRootDirectory(FileSystem::RemoveFileFromPath(projectPath));
Ref<Project> project = Project::New();
if (!project->Deserialize(FileSystem::ReadFile(projectPath, true)))
{

View File

@@ -176,15 +176,23 @@ namespace Nuake
if (ImGui::BeginPopup(hoverMenuId.c_str()))
{
if (ImGui::MenuItem("Show in File Explorer"))
{
OS::OpenInFileExplorer(file->GetAbsolutePath());
}
ImGui::Separator();
if (ImGui::MenuItem("Delete"))
{
if(FileSystem::RemoveFile(file->GetAbsolutePath()) != 0)
{
Logger::Log("Failed to remove file: " + file->GetAbsolutePath(), CRITICAL);
Logger::Log("Failed to remove file: " + file->GetRelativePath(), CRITICAL);
}
RefreshFileBrowser();
}
ImGui::EndPopup();
RefreshFileBrowser();
}
ImGui::Text(file->GetName().c_str());

View File

@@ -254,7 +254,7 @@ namespace Nuake
SaveRecentFile();
std::string projectPath = _Projects[SelectedProject].Path;
FileSystem::SetRootDirectory(projectPath + "/../");
FileSystem::SetRootDirectory(FileSystem::RemoveFileFromPath(projectPath));
auto project = Project::New();
auto projectFileData = FileSystem::ReadFile(projectPath, true);

View File

@@ -163,7 +163,7 @@ namespace Nuake
return false;
}
FileSystem::SetRootDirectory(project->FullPath + "/../");
FileSystem::SetRootDirectory(FileSystem::RemoveFileFromPath(project->FullPath));
return true;
}

View File

@@ -124,6 +124,12 @@ namespace Nuake
return fs::relative(absolutePath, rootPath).generic_string();
}
std::string FileSystem::RemoveFileFromPath(const std::string& fullPath)
{
std::filesystem::path pathObj(fullPath);
return pathObj.parent_path().string();
}
std::string FileSystem::ReadFile(const std::string& path, bool absolute)
{
std::string finalPath = path;

View File

@@ -30,6 +30,7 @@ namespace Nuake
static void Scan();
static std::string AbsoluteToRelative(const std::string& path);
static std::string RemoveFileFromPath(const std::string& fullPath);
static Ref<Directory> GetFileTree();
static Ref<File> GetFile(const std::string& path);
static std::string GetFileNameFromPath(const std::string& path);

17
Nuake/src/Core/OS.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include "OS.h"
#include <chrono>
#include "String.h"
#include <Windows.h>
using namespace Nuake;
int OS::GetTime()
{
return static_cast<int>(std::chrono::system_clock::now().time_since_epoch().count());
}
void OS::OpenInFileExplorer(const std::string& filePath)
{
ShellExecuteA(nullptr, "open", "explorer.exe", ("/select," + std::string(filePath)).c_str(), nullptr, SW_SHOWDEFAULT);
}

View File

@@ -1,13 +1,14 @@
#pragma once
#pragma once
#include <string>
namespace Nuake
{
class OS
{
public:
static int GetTime()
{
return static_cast<int>(std::chrono::system_clock::now().time_since_epoch().count());
}
static int GetTime();
static void OpenInFileExplorer(const std::string& filePath);
};
}