Skip to content

Commit

Permalink
Improved right click menu and started working on support for editing …
Browse files Browse the repository at this point in the history
…a code zone #308
  • Loading branch information
rzaharia committed Jun 19, 2024
1 parent 02129fd commit 05cabcb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
29 changes: 15 additions & 14 deletions GViewCore/src/View/DissasmViewer/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ constexpr int32 RIGHT_CLICK_CLEAR_SELECTION = 7;
constexpr int32 RIGHT_CLICK_DISSASM_COLLAPSE_ZONE = 8;
constexpr int32 RIGHT_CLICK_DISSASM_EXPAND_ZONE = 9;

constexpr int32 RIGHT_CLICK_CODE_ZONE_EDIT = 10;

struct RightClickCommand {
int commandID;
std::string_view text;
// Input::Key shortcutKey = Input::Key::None;
AppCUI::Controls::ItemHandle handle = AppCUI::Controls::InvalidItemHandle;
// AppCUI::Controls::ItemHandle handle = AppCUI::Controls::InvalidItemHandle;
};

inline RightClickCommand RIGHT_CLICK_MENU_COMMANDS[] = {
Expand All @@ -45,21 +47,20 @@ inline RightClickCommand RIGHT_CLICK_MENU_COMMANDS[] = {
struct RightClickSubMenus {
const char* name;
std::vector<RightClickCommand> commands;
AppCUI::Controls::ItemHandle handle;
// AppCUI::Controls::ItemHandle handle;
};

inline RightClickSubMenus RIGHT_CLICK_SUB_MENUS_COMMANDS[] = { { "CollapsibleZone",
{
{ RIGHT_CLICK_MENU_CMD_NEW_COLLAPSE_ZONE, "Add collapse zone" },
{ RIGHT_CLICK_DISSASM_REMOVE_COLLAPSE_ZONE, "Remove collapse zone" },
{ RIGHT_CLICK_DISSASM_COLLAPSE_ZONE, "Collapse zone" },
{ RIGHT_CLICK_DISSASM_EXPAND_ZONE, "Expand zone" },
} },
{ "Comment",
{
{ RIGHT_CLICK_ADD_COMMENT, "Add comment" },
{ RIGHT_CLICK_REMOVE_COMMENT, "Remove comment" },
} } };
const RightClickSubMenus RIGHT_CLICK_SUB_MENUS_COMMANDS[] = {
{ "CollapsibleZone",
{
{ RIGHT_CLICK_MENU_CMD_NEW_COLLAPSE_ZONE, "Add collapse zone" },
{ RIGHT_CLICK_DISSASM_REMOVE_COLLAPSE_ZONE, "Remove collapse zone" },
{ RIGHT_CLICK_DISSASM_COLLAPSE_ZONE, "Collapse zone" },
{ RIGHT_CLICK_DISSASM_EXPAND_ZONE, "Expand zone" }
} },
{ "Comment", { { RIGHT_CLICK_ADD_COMMENT, "Add comment" }, { RIGHT_CLICK_REMOVE_COMMENT, "Remove comment" } } },
{ "CodeZone", { { RIGHT_CLICK_CODE_ZONE_EDIT, "Edit zone" } } }
};

namespace GView
{
Expand Down
3 changes: 3 additions & 0 deletions GViewCore/src/View/DissasmViewer/DissasmKeyEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ bool Instance::OnEvent(Reference<Control>, Event eventType, int ID)
case RIGHT_CLICK_ADD_COMMENT:
AddComment();
return true;
case RIGHT_CLICK_CODE_ZONE_EDIT:
EditDissasmCodeZoneCommand();
return true;
case RIGHT_CLICK_REMOVE_COMMENT:
RemoveComment();
return true;
Expand Down
2 changes: 2 additions & 0 deletions GViewCore/src/View/DissasmViewer/DissasmViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ namespace View
void CommandExecuteCollapsibleZoneOperation(CollapsibleZoneOperation operation);
void DissasmZoneProcessSpaceKey(DissasmCodeZone* zone, uint32 line, uint64* offsetToReach = nullptr);

void EditDissasmCodeZoneCommand();

public:
Instance(Reference<GView::Object> obj, Settings* settings);
virtual ~Instance() override;
Expand Down
14 changes: 8 additions & 6 deletions GViewCore/src/View/DissasmViewer/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,18 @@ Instance::Instance(Reference<GView::Object> obj, Settings* _settings)

this->codePage = CodePageID::DOS_437;

for (auto& submenu : RIGHT_CLICK_SUB_MENUS_COMMANDS) {
submenu.handle = rightClickMenu.AddSubMenu(submenu.name);
auto subMenu = rightClickMenu.GetSubMenu(submenu.handle);
for (auto& command : submenu.commands) {
command.handle = subMenu->AddCommandItem(command.text, command.commandID);
for (const auto& submenu : RIGHT_CLICK_SUB_MENUS_COMMANDS) {
assert(submenu.name);
const auto handle = rightClickMenu.AddSubMenu(submenu.name);
auto subMenu = rightClickMenu.GetSubMenu(handle);
for (const auto& command : submenu.commands) {
assert(!command.text.empty());
subMenu->AddCommandItem(command.text, command.commandID);
}
}

for (auto& menu_command : RIGHT_CLICK_MENU_COMMANDS) {
menu_command.handle = rightClickMenu.AddCommandItem(menu_command.text, menu_command.commandID);
rightClickMenu.AddCommandItem(menu_command.text, menu_command.commandID);
}
// rightClickOffset = 0;

Expand Down
5 changes: 5 additions & 0 deletions GViewCore/src/View/DissasmViewer/x86_x64/DissasmX86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,11 @@ void Instance::DissasmZoneProcessSpaceKey(DissasmCodeZone* zone, uint32 line, ui
Cursor.hasMovedView = true;
}

void Instance::EditDissasmCodeZoneCommand()
{
AppCUI::Dialogs::MessageBox::ShowError("Error", "Not implemented yet !");
}

void Instance::CommandExecuteCollapsibleZoneOperation(CollapsibleZoneOperation operation)
{
if (operation == CollapsibleZoneOperation::Add && !selection.HasSelection(0)) {
Expand Down

0 comments on commit 05cabcb

Please sign in to comment.