mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
feat: Added command line palette option to open/focus views
This commit is contained in:
@@ -85,15 +85,22 @@ namespace hex {
|
||||
*/
|
||||
[[nodiscard]] virtual View* getMenuItemInheritView() const { return nullptr; }
|
||||
|
||||
[[nodiscard]] virtual bool shouldStoreWindowState() const { return true; }
|
||||
|
||||
[[nodiscard]] const char *getIcon() const { return m_icon; }
|
||||
[[nodiscard]] const UnlocalizedString& getUnlocalizedName() const;
|
||||
[[nodiscard]] std::string getName() const;
|
||||
|
||||
[[nodiscard]] virtual bool shouldStoreWindowState() const { return true; }
|
||||
|
||||
[[nodiscard]] bool &getWindowOpenState();
|
||||
[[nodiscard]] const bool &getWindowOpenState() const;
|
||||
|
||||
[[nodiscard]] const UnlocalizedString &getUnlocalizedName() const;
|
||||
[[nodiscard]] std::string getName() const;
|
||||
[[nodiscard]] bool isFocused() const { return m_focused; }
|
||||
|
||||
[[nodiscard]] static std::string toWindowName(const UnlocalizedString &unlocalizedName);
|
||||
[[nodiscard]] static const View* getLastFocusedView();
|
||||
static void discardNavigationRequests();
|
||||
|
||||
void bringToFront();
|
||||
|
||||
[[nodiscard]] bool didWindowJustOpen();
|
||||
void setWindowJustOpened(bool state);
|
||||
@@ -102,21 +109,8 @@ namespace hex {
|
||||
void setWindowJustClosed(bool state);
|
||||
|
||||
void trackViewState();
|
||||
|
||||
static void discardNavigationRequests();
|
||||
|
||||
[[nodiscard]] static std::string toWindowName(const UnlocalizedString &unlocalizedName);
|
||||
|
||||
[[nodiscard]] bool isFocused() const { return m_focused; }
|
||||
|
||||
/**
|
||||
* @brief Used for focus handling. Don't use this directly
|
||||
* @param focused Whether this view is focused
|
||||
*/
|
||||
void setFocused(bool focused);
|
||||
|
||||
[[nodiscard]] static const View* getLastFocusedView();
|
||||
|
||||
public:
|
||||
class Window;
|
||||
class Special;
|
||||
|
||||
@@ -82,6 +82,12 @@ namespace hex {
|
||||
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;
|
||||
}
|
||||
|
||||
void View::bringToFront() {
|
||||
getWindowOpenState() = true;
|
||||
TaskManager::doLater([this]{ ImGui::SetWindowFocus(toWindowName(getUnlocalizedName()).c_str()); });
|
||||
}
|
||||
|
||||
|
||||
std::string View::toWindowName(const UnlocalizedString &unlocalizedName) {
|
||||
return fmt::format("{}###{}", Lang(unlocalizedName), unlocalizedName.get());
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ namespace hex::plugin::builtin {
|
||||
return result;
|
||||
},
|
||||
[](auto input) {
|
||||
return fmt::format("Provider: {}", input.data());
|
||||
return fmt::format("Data Source: {}", input.data());
|
||||
});
|
||||
|
||||
ContentRegistry::CommandPaletteCommands::add(
|
||||
@@ -414,6 +414,27 @@ namespace hex::plugin::builtin {
|
||||
"hex.builtin.command.convert.desc",
|
||||
handleConversionCommand);
|
||||
|
||||
ContentRegistry::CommandPaletteCommands::addHandler(
|
||||
ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
|
||||
"+",
|
||||
[](const auto &input) {
|
||||
std::vector<ContentRegistry::CommandPaletteCommands::impl::QueryResult> result;
|
||||
|
||||
for (const auto &[unlocalizedName, view] : ContentRegistry::Views::impl::getEntries()) {
|
||||
const auto name = Lang(unlocalizedName);
|
||||
if (!hex::containsIgnoreCase(name, input))
|
||||
continue;
|
||||
result.emplace_back(fmt::format("Focus {} View", name), [&view](const auto &) {
|
||||
view->bringToFront();
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
[](auto input) {
|
||||
return fmt::format("Focus {} View", input.data());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user