Files
imhex/plugins/builtin/source/plugin_builtin.cpp
paxcut a9eb7b2d25 fix: fixed auto save projects not being done after the first one. (#2366)
Currently setting the time interval to auto save the project has no
effect other than creating one initial save if the input file is
unsaved. When a file is created and not saved it remains in a dirty
state which prevented setting the state of the autosaved project to
needing to be saved. Fixed by decoupling the state of the provider from
the state of the autosave. When a provider is detected as being dirty it
always makes the autosave as being needed once the time interval has
elapsed.

feat: Implemented the menus on the main menu bar that will be available
when the text editor has focus. It allows you to load and save patterns
using open and save and will tack changes if files on disk are modified
externally. It also only opens the file chooser the first time you save
a pattern file and subsequent changes save to the same file.

If you want to save into another file and have the new file be tracked
you can use Save As. Finally, export doesn't track the file on disk at
all. this feature uses the same changes tracker class used elsewhere in
imHex.

fix: Changed the defaults of various shortcuts that were using Alt + a
key to avoid possible problems with some keyboards. Shouldn't affect end
users as their shortcuts are loaded from internal file but those who
complain about the Alt key misbehaving will be asked to reset the keys
to the new defaults. In addition, all globally accessible shortcuts were
added the Allow while typing flag so that they can be used in any field
that accepts text.

New menu entries were added for debugging to make the pattern editor and
the hex editor menus more like each other.

Finally, the call to RegisterMainMenuEntries() when initializing views
was moved to occur after the call to registerViews() so that menus are
not repeated when set for different views.
2025-08-02 01:29:34 -07:00

151 lines
6.5 KiB
C++

#include <hex/plugin.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/api/task_manager.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/debugging.hpp>
#include <romfs/romfs.hpp>
#include <nlohmann/json.hpp>
#include "content/command_line_interface.hpp"
#include <banners/banner_icon.hpp>
#include <fonts/vscode_icons.hpp>
using namespace hex;
namespace hex::plugin::builtin {
void registerEventHandlers();
void registerDataVisualizers();
void registerMiniMapVisualizers();
void registerDataInspectorEntries();
void registerToolEntries();
void registerPatternLanguageFunctions();
void registerPatternLanguageTypes();
void registerPatternLanguagePragmas();
void registerPatternLanguageVisualizers();
void registerCommandPaletteCommands();
void registerSettings();
void loadSettings();
void registerDataProcessorNodes();
void registerProviders();
void registerDataFormatters();
void registerMainMenuEntries();
void createWelcomeScreen();
void registerViews();
void registerThemeHandlers();
void registerStyleHandlers();
void registerThemes();
void registerBackgroundServices();
void registerNetworkEndpoints();
void registerFileHandlers();
void registerProjectHandlers();
void registerAchievements();
void registerReportGenerators();
void registerTutorials();
void registerDataInformationSections();
void loadWorkspaces();
void addWindowDecoration();
void addFooterItems();
void addTitleBarButtons();
void addToolbarItems();
void addGlobalUIItems();
void addInitTasks();
void handleBorderlessWindowMode();
void setupOutOfBoxExperience();
void extractBundledFiles();
}
IMHEX_PLUGIN_SUBCOMMANDS() {
{ "help", "h", "Print help about this command", hex::plugin::builtin::handleHelpCommand },
{ "version", "", "Print ImHex version", hex::plugin::builtin::handleVersionCommand },
{ "version-short", "", "Print only the version info in plain text", hex::plugin::builtin::handleVersionShortCommand },
{ "plugins", "", "Lists all plugins that have been installed", hex::plugin::builtin::handlePluginsCommand },
{ "language", "", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand },
{ "verbose", "v", "Enables verbose debug logging", hex::plugin::builtin::handleVerboseCommand },
{ "open", "o", "Open files passed as argument. [default]", hex::plugin::builtin::handleOpenCommand },
{ "new", "n", "Create a new empty file", hex::plugin::builtin::handleNewCommand },
{ "select", "", "Select a range of bytes in the Hex Editor", hex::plugin::builtin::handleSelectCommand },
{ "pattern", "", "Sets the loaded pattern", hex::plugin::builtin::handlePatternCommand },
{ "calc", "", "Evaluate a mathematical expression", hex::plugin::builtin::handleCalcCommand },
{ "hash", "", "Calculate the hash of a file", hex::plugin::builtin::handleHashCommand },
{ "encode", "", "Encode a string", hex::plugin::builtin::handleEncodeCommand },
{ "decode", "", "Decode a string", hex::plugin::builtin::handleDecodeCommand },
{ "magic", "", "Identify file types", hex::plugin::builtin::handleMagicCommand },
{ "pl", "", "Interact with the pattern language", hex::plugin::builtin::handlePatternLanguageCommand, SubCommand::Type::SubCommand },
{ "hexdump", "", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand },
{ "demangle", "", "Demangle a mangled symbol", hex::plugin::builtin::handleDemangleCommand },
{ "reset-settings", "", "Resets all settings back to default", hex::plugin::builtin::handleSettingsResetCommand },
{ "debug-mode", "", "Enables debugging features", hex::plugin::builtin::handleDebugModeCommand, },
{ "validate-plugin", "", "Validates that a plugin can be loaded", hex::plugin::builtin::handleValidatePluginCommand }
};
IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
using namespace hex::plugin::builtin;
// Show a warning banner on debug builds
#if defined(DEBUG)
if (!hex::getEnvironmentVariable("NO_DEBUG_BANNER").has_value()) {
ui::BannerIcon::open(ICON_VS_ERROR, "You're running a Debug build of ImHex. Performance will be degraded!", ImColor(153, 58, 58));
}
dbg::setDebugModeEnabled(true);
#else
const auto enabled = ContentRegistry::Settings::read<bool>("hex.builtin.setting.general", "hex.builtin.setting.general.debug_mode_enabled", false);
dbg::setDebugModeEnabled(enabled);
#endif
hex::log::debug("Using romfs: '{}'", romfs::name());
for (auto &path : romfs::list("lang"))
hex::ContentRegistry::Language::addLocalization(nlohmann::json::parse(romfs::get(path).string()));
addInitTasks();
extractBundledFiles();
addFooterItems();
addTitleBarButtons();
addToolbarItems();
addGlobalUIItems();
registerEventHandlers();
registerDataVisualizers();
registerMiniMapVisualizers();
registerDataInspectorEntries();
registerToolEntries();
registerPatternLanguageFunctions();
registerPatternLanguageTypes();
registerPatternLanguagePragmas();
registerPatternLanguageVisualizers();
registerCommandPaletteCommands();
registerThemes();
registerSettings();
loadSettings();
registerDataProcessorNodes();
registerProviders();
registerDataFormatters();
registerViews();
registerMainMenuEntries();
registerThemeHandlers();
registerStyleHandlers();
registerBackgroundServices();
registerNetworkEndpoints();
registerFileHandlers();
registerProjectHandlers();
registerCommandForwarders();
registerAchievements();
registerReportGenerators();
registerTutorials();
registerDataInformationSections();
loadWorkspaces();
addWindowDecoration();
createWelcomeScreen();
setupOutOfBoxExperience();
}