mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-04 19:47:31 +00:00
Click [X] with mouse and close the panel, plus a bunch of refactoring (#14602)
This commit is contained in:
parent
24d3a9cb5d
commit
a4908fa0a1
@ -297,6 +297,7 @@ static void __freeAllPanels(RPanels *panels);
|
||||
/* get */
|
||||
static RPanel *__getPanel(RPanels *panels, int i);
|
||||
static RPanel *__getCurPanel(RPanels *panels);
|
||||
static int __get_panel_idx_in_pos(RCore *core, int x, int y);
|
||||
static RPanels *__get_panels(RPanelsRoot *panels_root, int i);
|
||||
static RPanels *__get_cur_panels(RPanelsRoot *panels_root);
|
||||
static char *get_word_from_canvas(RCore *core, RPanels *panels, int x, int y);
|
||||
@ -419,6 +420,7 @@ static void __setMode(RCore *core, RPanelsMode mode);
|
||||
static bool __handleZoomMode(RCore *core, const int key);
|
||||
static bool __handleWindowMode(RCore *core, const int key);
|
||||
static bool __handleCursorMode(RCore *core, const int key);
|
||||
static bool __handle_mouse(RCore *core, RPanel *panel, int *key);
|
||||
static void __toggleZoomMode(RCore *core);
|
||||
static void __toggleWindowMode(RCore *core);
|
||||
|
||||
@ -785,6 +787,20 @@ RPanel *__getCurPanel(RPanels *panels) {
|
||||
return __getPanel (panels, panels->curnode);
|
||||
}
|
||||
|
||||
int __get_panel_idx_in_pos(RCore *core, int x, int y) {
|
||||
RPanels *panels = core->panels;
|
||||
int i = -1;
|
||||
for (i = 0; i < panels->n_panels; i++) {
|
||||
RPanel *p = __getPanel (panels, i);
|
||||
if (x >= p->view->pos.x && x < p->view->pos.x + p->view->pos.w) {
|
||||
if (y >= p->view->pos.y && y < p->view->pos.y + p->view->pos.h) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void __handlePrompt(RCore *core, RPanels *panels) {
|
||||
r_core_visual_prompt_input (core);
|
||||
int i;
|
||||
@ -895,10 +911,10 @@ void __defaultPanelPrint(RCore *core, RConsCanvas *can, RPanel *panel, int w, in
|
||||
} else {
|
||||
if (!strcmp (panel->model->title, cmd_title)) {
|
||||
snprintf (title, sizeof (title) - 1,
|
||||
" %s ", panel->model->title);
|
||||
"[X] %s ", panel->model->title);
|
||||
} else {
|
||||
snprintf (title, sizeof (title) - 1,
|
||||
" %s (%s) ", panel->model->title, cmd_title);
|
||||
"[X] %s (%s) ", panel->model->title, cmd_title);
|
||||
}
|
||||
snprintf (cache_title, sizeof (cache_title) - 1,
|
||||
"[Cache] %s", readOnly ? "N/A" : panel->model->cache ? "On" : "Off");
|
||||
@ -1568,6 +1584,101 @@ bool __handleCursorMode(RCore *core, const int key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool __handle_mouse(RCore *core, RPanel *panel, int *key) {
|
||||
const int MENU_Y = 1;
|
||||
RPanels *panels = core->panels;
|
||||
int i;
|
||||
if (*key == 0) {
|
||||
int x, y;
|
||||
if (r_cons_get_click (&x, &y)) {
|
||||
char *word = get_word_from_canvas (core, panels, x, y);
|
||||
if (y == MENU_Y) {
|
||||
for (i = 0; i < COUNT (menus); i++) {
|
||||
if (!strcmp (word, menus[i])) {
|
||||
__setMode (core, PANEL_MODE_MENU);
|
||||
__clearPanelsMenu (core);
|
||||
RPanelsMenu *menu = panels->panelsMenu;
|
||||
RPanelsMenuItem *parent = menu->history[menu->depth - 1];
|
||||
parent->selectedIndex = i;
|
||||
RPanelsMenuItem *child = parent->sub[parent->selectedIndex];
|
||||
(void)(child->cb (core));
|
||||
__setRefreshAll (core, false, false);
|
||||
free (word);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!strcmp (word, "Tab")) {
|
||||
__handle_tab_new (core);
|
||||
free (word);
|
||||
return true;
|
||||
}
|
||||
if (word[0] == '[' && word[1] && word[2] == ']') {
|
||||
return true;
|
||||
}
|
||||
if (atoi (word)) {
|
||||
__handle_tab_nth (core, word[0]);
|
||||
return true;
|
||||
}
|
||||
} else if (panels->mode == PANEL_MODE_MENU) {
|
||||
char *word = get_word_from_canvas_for_menu (core, panels, x, y);
|
||||
RPanelsMenu *menu = panels->panelsMenu;
|
||||
RPanelsMenuItem *parent = menu->history[menu->depth - 1];
|
||||
for (i = 0; i < parent->n_sub; i++) {
|
||||
if (!strcmp (word, parent->sub[i]->get_name_cb (core, parent->sub[i]->base_name))) {
|
||||
parent->selectedIndex = i;
|
||||
(void)(parent->sub[parent->selectedIndex]->cb (core));
|
||||
__moveMenuCursor (core, menu, parent);
|
||||
free (word);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
__clearPanelsMenu (core);
|
||||
__setMode (core, PANEL_MODE_DEFAULT);
|
||||
__getCurPanel (panels)->view->refresh = true;
|
||||
return true;
|
||||
} else {
|
||||
// TODO: select nth panel here
|
||||
const int idx = __get_panel_idx_in_pos (core, x, y);
|
||||
if (idx == -1) {
|
||||
return false;
|
||||
}
|
||||
RPanel *ppos = __getPanel(panels, idx);
|
||||
const int TITLE_Y = ppos->view->pos.y + 2;
|
||||
if (y == TITLE_Y && strcmp (word, " X ")) {
|
||||
__dismantleDelPanel (core, ppos, idx);
|
||||
__setRefreshAll (core, false, false);
|
||||
free (word);
|
||||
return true;
|
||||
}
|
||||
if (word) {
|
||||
if (__check_panel_type (panel, PANEL_CMD_FUNCTION , strlen (PANEL_CMD_FUNCTION)) &&
|
||||
__check_if_addr(word, strlen (word))) {
|
||||
const ut64 addr = r_num_math (core->num, word);
|
||||
r_core_seek (core, addr, 1);
|
||||
__setAddrByType (core, PANEL_CMD_DISASSEMBLY, addr);
|
||||
}
|
||||
r_config_set (core->config, "scr.highlight", word);
|
||||
free (word);
|
||||
}
|
||||
if (x >= ppos->view->pos.x && x < ppos->view->pos.x + 4) {
|
||||
*key = 'c';
|
||||
return false;
|
||||
}
|
||||
__set_curnode(core, idx);
|
||||
__setRefreshAll (core, true, true);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (*key == INT8_MAX) {
|
||||
*key = '"';
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void __jmp_to_cursor_addr(RCore *core, RPanel *panel) {
|
||||
ut64 addr = __parse_string_on_cursor (core, panel, panel->view->curpos);
|
||||
if (addr == UT64_MAX) {
|
||||
@ -5861,101 +5972,15 @@ repeat:
|
||||
} else {
|
||||
okey = r_cons_readchar ();
|
||||
}
|
||||
|
||||
key = r_cons_arrow_to_hjkl (okey);
|
||||
if (key == 0) {
|
||||
int x, y;
|
||||
if (r_cons_get_click (&x, &y)) {
|
||||
char *word = get_word_from_canvas (core, panels, x, y);
|
||||
if (y == 1) { // click on first line (The menu
|
||||
for (i = 0; i < COUNT (menus); i++) {
|
||||
if (!strcmp (word, menus[i])) {
|
||||
__setMode (core, PANEL_MODE_MENU);
|
||||
__clearPanelsMenu (core);
|
||||
RPanelsMenu *menu = panels->panelsMenu;
|
||||
RPanelsMenuItem *parent = menu->history[menu->depth - 1];
|
||||
parent->selectedIndex = i;
|
||||
RPanelsMenuItem *child = parent->sub[parent->selectedIndex];
|
||||
(void)(child->cb (core));
|
||||
__setRefreshAll (core, false, false);
|
||||
free (word);
|
||||
goto repeat;
|
||||
}
|
||||
}
|
||||
if (!strcmp (word, "Tab")) {
|
||||
__handle_tab_new (core);
|
||||
free (word);
|
||||
goto repeat;
|
||||
}
|
||||
if (word[0] == '[' && word[1] && word[2] == ']') {
|
||||
goto repeat;
|
||||
}
|
||||
if (atoi (word)) {
|
||||
__handle_tab_nth (core, word[0]);
|
||||
if (panels_root->root_state != DEFAULT) {
|
||||
goto exit;
|
||||
}
|
||||
goto repeat;
|
||||
}
|
||||
} else if (panels->mode == PANEL_MODE_MENU) {
|
||||
char *word = get_word_from_canvas_for_menu (core, panels, x, y);
|
||||
RPanelsMenu *menu = panels->panelsMenu;
|
||||
RPanelsMenuItem *parent = menu->history[menu->depth - 1];
|
||||
for (i = 0; i < parent->n_sub; i++) {
|
||||
if (!strcmp (word, parent->sub[i]->get_name_cb (core, parent->sub[i]->base_name))) {
|
||||
parent->selectedIndex = i;
|
||||
(void)(parent->sub[parent->selectedIndex]->cb (core));
|
||||
__moveMenuCursor (core, menu, parent);
|
||||
free (word);
|
||||
goto repeat;
|
||||
}
|
||||
}
|
||||
__clearPanelsMenu (core);
|
||||
__setMode (core, PANEL_MODE_DEFAULT);
|
||||
__getCurPanel (panels)->view->refresh = true;
|
||||
goto repeat;
|
||||
} else {
|
||||
// TODO: select nth panel here
|
||||
if (r_str_endswith (word, "X]")) {
|
||||
key = 'X';
|
||||
free (word);
|
||||
goto skip;
|
||||
}
|
||||
if (word) {
|
||||
if (__check_panel_type (cur, PANEL_CMD_FUNCTION , strlen (PANEL_CMD_FUNCTION)) &&
|
||||
__check_if_addr(word, strlen (word))) {
|
||||
const ut64 addr = r_num_math (core->num, word);
|
||||
r_core_seek (core, addr, 1);
|
||||
__setAddrByType (core, PANEL_CMD_DISASSEMBLY, addr);
|
||||
}
|
||||
r_config_set (core->config, "scr.highlight", word);
|
||||
free (word);
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < panels->n_panels; i++) {
|
||||
RPanel *p = __getPanel (panels, i);
|
||||
if (x >= p->view->pos.x && x < p->view->pos.x + p->view->pos.w) {
|
||||
if (y >= p->view->pos.y && y < p->view->pos.y + p->view->pos.h) {
|
||||
if (x >= p->view->pos.x && x < p->view->pos.x + 4) {
|
||||
key = 'c';
|
||||
goto skip;
|
||||
}
|
||||
panels->curnode = i;
|
||||
__set_curnode(core, i);
|
||||
__setRefreshAll (core, true, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
goto repeat;
|
||||
}
|
||||
} else {
|
||||
goto repeat;
|
||||
if (__handle_mouse (core, cur, &key)) {
|
||||
if (panels_root->root_state != DEFAULT) {
|
||||
goto exit;
|
||||
}
|
||||
goto repeat;
|
||||
}
|
||||
if (key == INT8_MAX) {
|
||||
key = '"';
|
||||
}
|
||||
skip:
|
||||
|
||||
r_cons_switchbuf (true);
|
||||
|
||||
if (panels->mode == PANEL_MODE_MENU) {
|
||||
|
Loading…
Reference in New Issue
Block a user