feat: Added context menu with right-clicking on file provider (#1084)

Co-authored-by: Nik <werwolv98@gmail.com>
This commit is contained in:
iTrooz
2023-05-21 13:21:53 +02:00
committed by GitHub
parent 047c39e2c7
commit 5666a5c5fb
8 changed files with 107 additions and 0 deletions

View File

@@ -42,6 +42,8 @@ namespace hex::plugin::builtin {
[[nodiscard]] bool hasFilePicker() const override { return true; }
[[nodiscard]] bool handleFilePicker() override;
std::vector<std::pair<std::string, std::function<void()>>> getMenuEntries() override;
void setPath(const std::fs::path &path);
[[nodiscard]] bool open() override;

View File

@@ -352,6 +352,8 @@
"hex.builtin.provider.file.modification",
"hex.builtin.provider.file.path",
"hex.builtin.provider.file.size",
"hex.builtin.provider.file.menu.open_file",
"hex.builtin.provider.file.menu.open_folder",
"hex.builtin.provider.gdb",
"hex.builtin.provider.gdb.ip",
"hex.builtin.provider.gdb.name",

View File

@@ -403,6 +403,8 @@
"hex.builtin.provider.file.modification": "Last modification time",
"hex.builtin.provider.file.path": "File path",
"hex.builtin.provider.file.size": "Size",
"hex.builtin.provider.file.menu.open_file": "Open file externally",
"hex.builtin.provider.file.menu.open_folder": "Open containing folder",
"hex.builtin.provider.gdb": "GDB Server Provider",
"hex.builtin.provider.gdb.ip": "IP Address",
"hex.builtin.provider.gdb.name": "GDB Server <{0}:{1}>",

View File

@@ -185,6 +185,19 @@ namespace hex::plugin::builtin {
});
}
std::vector<std::pair<std::string, std::function<void()>>> FileProvider::getMenuEntries(){
return {
{"hex.builtin.provider.file.menu.open_folder"_lang, [path = this->m_path] {
fs::openFolderWithSelectionExternal(path);
}},
{"hex.builtin.provider.file.menu.open_file"_lang, [path = this->m_path] {
fs::openFileExternal(path);
}},
};
}
void FileProvider::setPath(const std::fs::path &path) {
this->m_path = path;
}

View File

@@ -224,6 +224,20 @@ namespace hex::plugin::builtin {
ImHexApi::Provider::remove(providers[i]);
break;
}
std::string popupID = std::string("ProviderMenu.") + std::to_string(tabProvider->getID());
if (ImGui::IsMouseReleased(1) && ImGui::IsItemHovered()) {
ImGui::OpenPopup(popupID.c_str());
}
if (ImGui::BeginPopup(popupID.c_str())) {
for (auto p : tabProvider->getMenuEntries()) {
if (ImGui::MenuItem(p.first.c_str())) {
p.second();
}
}
ImGui::EndPopup();
}
}
ImGui::EndTabBar();
}