mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-27 23:37:05 -05:00
feat: Allow any custom content to be displayed in the command palette
This commit is contained in:
@@ -21,12 +21,14 @@ EXPORT_MODULE namespace hex {
|
||||
|
||||
namespace impl {
|
||||
|
||||
using QueryResultCallback = std::function<void(std::string)>;
|
||||
|
||||
struct QueryResult {
|
||||
std::string name;
|
||||
std::function<void(std::string)> callback;
|
||||
QueryResultCallback callback;
|
||||
};
|
||||
|
||||
using ContentDisplayCallback = std::function<void(std::string)>;
|
||||
using ContentDisplayCallback = std::function<void()>;
|
||||
using DisplayCallback = std::function<std::string(std::string)>;
|
||||
using ExecuteCallback = std::function<std::optional<std::string>(std::string)>;
|
||||
using QueryCallback = std::function<std::vector<QueryResult>(std::string)>;
|
||||
@@ -46,10 +48,15 @@ EXPORT_MODULE namespace hex {
|
||||
DisplayCallback displayCallback;
|
||||
};
|
||||
|
||||
struct ContentDisplay {
|
||||
bool showSearchBox;
|
||||
ContentDisplayCallback callback;
|
||||
};
|
||||
|
||||
const std::vector<Entry>& getEntries();
|
||||
const std::vector<Handler>& getHandlers();
|
||||
|
||||
std::optional<ContentDisplayCallback>& getDisplayedContent();
|
||||
std::optional<ContentDisplay>& getDisplayedContent();
|
||||
|
||||
}
|
||||
|
||||
@@ -86,6 +93,12 @@ EXPORT_MODULE namespace hex {
|
||||
* @param displayCallback Display callback that will be called to display the content
|
||||
*/
|
||||
void setDisplayedContent(const impl::ContentDisplayCallback &displayCallback);
|
||||
|
||||
/**
|
||||
* @brief Opens the command palette window, displaying a user defined interface
|
||||
* @param displayCallback Display callback that will be called to display the content
|
||||
*/
|
||||
void openWithContent(const impl::ContentDisplayCallback &displayCallback);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,34 +71,8 @@ namespace hex {
|
||||
/**
|
||||
* @brief Requests the Pattern editor to run the current code
|
||||
*
|
||||
* This is only ever used in the introduction tutorial.
|
||||
*
|
||||
* FIXME: the name is misleading, as for now this activates the pattern's auto-evaluation rather than a
|
||||
* one-off execution
|
||||
*/
|
||||
EVENT_DEF(RequestRunPatternCode);
|
||||
|
||||
/**
|
||||
* @brief Request to load a pattern language file
|
||||
*
|
||||
* FIXME: this request is unused, as now another component is responsible for pattern file loading.
|
||||
* This request should be scrapped.
|
||||
*
|
||||
* @param path the pattern file's path
|
||||
* @param bool track changes to the file on disk
|
||||
*
|
||||
*/
|
||||
EVENT_DEF(RequestLoadPatternLanguageFile, std::fs::path, bool);
|
||||
|
||||
/**
|
||||
* @brief Request to save a pattern language file
|
||||
*
|
||||
* FIXME: this request is unused, as now another component is responsible for pattern file saving.
|
||||
* This request should be scrapped.
|
||||
*
|
||||
* @param path the pattern file's path
|
||||
*/
|
||||
EVENT_DEF(RequestSavePatternLanguageFile, std::fs::path);
|
||||
EVENT_DEF(RequestTriggerPatternEvaluation);
|
||||
|
||||
/**
|
||||
* @brief Requests ImHex to open and process a file
|
||||
@@ -116,4 +90,9 @@ namespace hex {
|
||||
*/
|
||||
EVENT_DEF(RequestAddVirtualFile, std::fs::path, std::vector<u8>, Region);
|
||||
|
||||
/**
|
||||
* @brief Requests the command palette to be opened
|
||||
*/
|
||||
EVENT_DEF(RequestOpenCommandPalette);
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <jthread.hpp>
|
||||
#include <hex/api/events/requests_interaction.hpp>
|
||||
|
||||
#if defined(OS_WEB)
|
||||
#include <emscripten.h>
|
||||
@@ -613,8 +614,8 @@ namespace hex {
|
||||
return *s_handlers;
|
||||
}
|
||||
|
||||
static AutoReset<std::optional<ContentDisplayCallback>> s_displayedContent;
|
||||
std::optional<ContentDisplayCallback>& getDisplayedContent() {
|
||||
static AutoReset<std::optional<ContentDisplay>> s_displayedContent;
|
||||
std::optional<ContentDisplay>& getDisplayedContent() {
|
||||
return *s_displayedContent;
|
||||
}
|
||||
|
||||
@@ -633,7 +634,12 @@ namespace hex {
|
||||
}
|
||||
|
||||
void setDisplayedContent(const impl::ContentDisplayCallback &displayCallback) {
|
||||
impl::s_displayedContent = displayCallback;
|
||||
impl::s_displayedContent = impl::ContentDisplay { true, displayCallback };
|
||||
}
|
||||
|
||||
void openWithContent(const impl::ContentDisplayCallback &displayCallback) {
|
||||
RequestOpenCommandPalette::post();
|
||||
impl::s_displayedContent = impl::ContentDisplay { false, displayCallback };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user