Merge pull request #42 from antopilo/NK-111-copy-path-file-name-in-context-menu

NK-111 - Copy Menu in Context Menu
This commit is contained in:
émeryc
2023-07-22 02:04:41 -04:00
committed by GitHub
3 changed files with 52 additions and 2 deletions

View File

@@ -162,10 +162,29 @@ namespace Nuake
}
}
if (ImGui::BeginMenu("Copy"))
{
ImGui::Separator();
if (ImGui::MenuItem("Full Path"))
{
OS::CopyToClipboard(file->GetAbsolutePath());
}
if (ImGui::MenuItem("File Name"))
{
OS::CopyToClipboard(file->GetName());
}
ImGui::EndPopup();
}
if(file->GetExtension() != ".project")
{
ImGui::Separator();
// TODO: Add to a 'Edit' menu with File Rename, etc.
if (ImGui::MenuItem("Delete"))
{
if(FileSystem::RemoveFile(file->GetAbsolutePath()) != 0)

View File

@@ -1,11 +1,40 @@
#include "OS.h"
#include "src/Window.h"
#define GLFW_EXPOSE_NATIVE_WIN32
#include "GLFW/glfw3.h"
#include "GLFW/glfw3native.h"
#include <chrono>
#include <Windows.h>
#include <chrono>
using namespace Nuake;
int OS::GetTime()
void OS::CopyToClipboard(const std::string& value)
{
auto glob = GlobalAlloc(GMEM_FIXED, 512);
memcpy(glob, value.data(), value.size());
OpenClipboard(glfwGetWin32Window(Window::Get()->GetHandle()));
EmptyClipboard();
SetClipboardData(CF_TEXT, glob);
CloseClipboard();
}
std::string OS::GetFromClipboard()
{
OpenClipboard(nullptr);
HANDLE hData = GetClipboardData(CF_TEXT);
char* pszText = static_cast<char*>(GlobalLock(hData));
std::string text(pszText);
GlobalUnlock(hData);
CloseClipboard();
return text;
}
int OS::GetTime()
{
return static_cast<int>(std::chrono::system_clock::now().time_since_epoch().count());
}

View File

@@ -7,6 +7,8 @@ namespace Nuake
class OS
{
public:
static void CopyToClipboard(const std::string& value);
static std::string GetFromClipboard();
static int GetTime();
static void OpenIn(const std::string& filePath);
static void ShowInFileExplorer(const std::string& filePath);