Automatically refresh filebrowser on window focus, and preserve path after scanning

This commit is contained in:
Antoine Pilote
2024-09-05 19:44:27 -04:00
parent 9e05e6883a
commit 422331dec2
11 changed files with 110 additions and 2 deletions

View File

@@ -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>());
}

View File

@@ -75,4 +75,9 @@ void EditorLayer::OnUpdate()
void EditorLayer::OnDetach()
{
delete m_EditorInterface;
}
void EditorLayer::OnWindowFocused()
{
m_EditorInterface->OnWindowFocused();
}

View File

@@ -22,6 +22,8 @@ public:
virtual void OnUpdate() override;
virtual void OnDetach() override;
virtual void OnWindowFocused() override;
private:
CommandBuffer mCommandBuffer;
Nuake::EditorInterface* m_EditorInterface;

View File

@@ -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));

View File

@@ -102,5 +102,8 @@ namespace Nuake
public:
std::string GetEntityTypeName(const Entity& entity) const;
static void PushCommand(ICommand&& command);
public:
void OnWindowFocused();
};
}

View File

@@ -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;

View File

@@ -32,5 +32,7 @@ namespace Nuake {
bool DeletePopup();
void DrawContextMenu();
void RefreshFileBrowser();
void Scan();
};
}