mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Automatically refresh filebrowser on window focus, and preserve path after scanning
This commit is contained in:
@@ -45,6 +45,32 @@ void EditorApplication::OnInit()
|
||||
}
|
||||
}
|
||||
|
||||
m_Window->SetOnWindowFocusedCallback([&](Window& window, bool focused)
|
||||
{
|
||||
if (!focused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& layer : m_LayerStack)
|
||||
{
|
||||
layer->OnWindowFocused();
|
||||
}
|
||||
});
|
||||
|
||||
m_Window->SetOnWindowClosedCallback([](Window& window)
|
||||
{
|
||||
if (Engine::GetProject())
|
||||
{
|
||||
Engine::GetProject()->Save();
|
||||
}
|
||||
|
||||
if (Engine::GetCurrentScene())
|
||||
{
|
||||
Engine::GetCurrentScene()->Save();
|
||||
}
|
||||
});
|
||||
|
||||
PushLayer(CreateScope<EditorLayer>());
|
||||
}
|
||||
|
||||
|
||||
@@ -75,4 +75,9 @@ void EditorLayer::OnUpdate()
|
||||
void EditorLayer::OnDetach()
|
||||
{
|
||||
delete m_EditorInterface;
|
||||
}
|
||||
|
||||
void EditorLayer::OnWindowFocused()
|
||||
{
|
||||
m_EditorInterface->OnWindowFocused();
|
||||
}
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
virtual void OnUpdate() override;
|
||||
virtual void OnDetach() override;
|
||||
|
||||
virtual void OnWindowFocused() override;
|
||||
|
||||
private:
|
||||
CommandBuffer mCommandBuffer;
|
||||
Nuake::EditorInterface* m_EditorInterface;
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "../Actions/EditorSelection.h"
|
||||
#include "FileSystemUI.h"
|
||||
|
||||
#include <src/FileSystem/Directory.h>
|
||||
|
||||
#include "../Misc/InterfaceFonts.h"
|
||||
|
||||
#include "WelcomeWindow.h"
|
||||
@@ -3177,6 +3179,12 @@ namespace Nuake {
|
||||
mCommandBuffer->PushCommand(command);
|
||||
}
|
||||
|
||||
void EditorInterface::OnWindowFocused()
|
||||
{
|
||||
filesystem->Scan();
|
||||
|
||||
}
|
||||
|
||||
bool EditorInterface::LoadProject(const std::string& projectPath)
|
||||
{
|
||||
FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath));
|
||||
|
||||
@@ -102,5 +102,8 @@ namespace Nuake
|
||||
public:
|
||||
std::string GetEntityTypeName(const Entity& entity) const;
|
||||
static void PushCommand(ICommand&& command);
|
||||
|
||||
public:
|
||||
void OnWindowFocused();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -694,8 +694,28 @@ namespace Nuake
|
||||
|
||||
void FileSystemUI::RefreshFileBrowser()
|
||||
{
|
||||
Scan();
|
||||
}
|
||||
|
||||
void FileSystemUI::Scan()
|
||||
{
|
||||
if (!m_CurrentDirectory)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::string previousPath = m_CurrentDirectory->FullPath;
|
||||
|
||||
FileSystem::Scan();
|
||||
m_CurrentDirectory = FileSystem::RootDirectory;
|
||||
|
||||
if (FileSystem::DirectoryExists(previousPath, true))
|
||||
{
|
||||
m_CurrentDirectory = FileSystem::GetDirectory(FileSystem::AbsoluteToRelative(previousPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_CurrentDirectory = FileSystem::RootDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
float h = 200;
|
||||
|
||||
@@ -32,5 +32,7 @@ namespace Nuake {
|
||||
bool DeletePopup();
|
||||
void DrawContextMenu();
|
||||
void RefreshFileBrowser();
|
||||
|
||||
void Scan();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Nuake {
|
||||
|
||||
virtual void OnDraw() {};
|
||||
|
||||
virtual void OnWindowFocused() {};
|
||||
// TODO: OnEvent
|
||||
|
||||
inline const std::string& GetName() const { return m_Name; }
|
||||
|
||||
@@ -19,5 +19,8 @@ namespace Nuake
|
||||
|
||||
Directory() = default;
|
||||
~Directory() = default;
|
||||
|
||||
std::string GetName() const;
|
||||
std::string GetFullPath() const;
|
||||
};
|
||||
}
|
||||
@@ -237,6 +237,39 @@ Ref<File> FileSystem::GetFile(const std::string& path)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Ref<Directory> FileSystem::GetDirectory(const std::string& path)
|
||||
{
|
||||
// Note, Might be broken on other platforms.
|
||||
auto splits = String::Split(path, '/');
|
||||
|
||||
int currentDepth = -1;
|
||||
std::string currentDirName = ".";
|
||||
Ref<Directory> currentDirComparator = RootDirectory;
|
||||
while (currentDirName == currentDirComparator->Name)
|
||||
{
|
||||
currentDepth++;
|
||||
|
||||
if (currentDepth >= splits.size())
|
||||
{
|
||||
return currentDirComparator;
|
||||
}
|
||||
|
||||
currentDirName = splits[currentDepth];
|
||||
|
||||
// Find next directory
|
||||
for (auto& d : currentDirComparator->Directories)
|
||||
{
|
||||
if (d->Name == currentDirName)
|
||||
{
|
||||
currentDirComparator = d;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return currentDirComparator;
|
||||
}
|
||||
|
||||
std::string FileSystem::GetFileNameFromPath(const std::string& path)
|
||||
{
|
||||
const auto& split = String::Split(path, '/');
|
||||
@@ -251,3 +284,8 @@ Directory::Directory(const std::string& path)
|
||||
Name = FileSystem::AbsoluteToRelative(path);
|
||||
FullPath = path;
|
||||
}
|
||||
|
||||
std::string Directory::GetName() const
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace Nuake
|
||||
{
|
||||
public:
|
||||
static std::string Root;
|
||||
|
||||
static Ref<Directory> RootDirectory;
|
||||
static Ref<filewatch::FileWatch<std::string>> RootFileWatch;
|
||||
|
||||
@@ -28,6 +27,7 @@ namespace Nuake
|
||||
static std::string GetParentPath(const std::string& fullPath);
|
||||
static Ref<Directory> GetFileTree();
|
||||
static Ref<File> GetFile(const std::string& path);
|
||||
static Ref<Directory> GetDirectory(const std::string& path);
|
||||
static std::string GetFileNameFromPath(const std::string& path);
|
||||
static void ScanDirectory(Ref<Directory> directory);
|
||||
static void GetDirectories();
|
||||
|
||||
Reference in New Issue
Block a user