mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
feat: Added context menu with right-clicking on file provider (#1084)
Co-authored-by: Nik <werwolv98@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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}>",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user