From f29118dcec7814668e12ddc7b5c2d24e61131101 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 15 Apr 2023 14:05:38 +0300 Subject: [PATCH] WPanel: rename 'selected' to 'current' and related changes. Renames: WPanel::selected -> WPanel::current selection (macro) -> panel_current_entry() panel_selected_at_half() -> panel_current_at_half() move_selection() -> panel_move_current() do_select() -> panel_set_current() try_to_select() -> panel_set_current_by_name() mark_if_marking(): argument and intermal variables file attributes: SELECTED -> CURRENT MARKED_SELECTED -> MARKED_CURRENT Signed-off-by: Andrew Borodin --- src/diffviewer/ydiff.c | 18 +- src/filemanager/achown.c | 2 +- src/filemanager/chattr.c | 2 +- src/filemanager/chmod.c | 2 +- src/filemanager/chown.c | 2 +- src/filemanager/cmd.c | 47 ++- src/filemanager/file.c | 8 +- src/filemanager/filemanager.c | 21 +- src/filemanager/find.c | 5 +- src/filemanager/info.c | 9 +- src/filemanager/layout.c | 4 +- src/filemanager/panel.c | 350 ++++++++++-------- src/filemanager/panel.h | 13 +- src/filemanager/panelize.c | 2 +- src/usermenu.c | 8 +- src/viewer/actions_cmd.c | 4 +- .../exec_get_export_variables_ext.c | 2 +- 17 files changed, 277 insertions(+), 222 deletions(-) diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index ea33841d4..2b6ff0ebd 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -3534,26 +3534,28 @@ dview_diff_cmd (const void *f0, const void *f1) /* run from panels */ const WPanel *panel0 = (const WPanel *) f0; const WPanel *panel1 = (const WPanel *) f1; + const file_entry_t *fe0; + const file_entry_t *fe1; + fe0 = panel_current_entry (panel0); file0 = - vfs_path_append_new (panel0->cwd_vpath, selection (panel0)->fname->str, - (char *) NULL); - is_dir0 = S_ISDIR (selection (panel0)->st.st_mode); + vfs_path_append_new (panel0->cwd_vpath, fe0->fname->str, (char *) NULL); + is_dir0 = S_ISDIR (fe0->st.st_mode); if (is_dir0) { message (D_ERROR, MSG_ERROR, _("\"%s\" is a directory"), - path_trunc (selection (panel0)->fname->str, 30)); + path_trunc (fe0->fname->str, 30)); goto ret; } + fe1 = panel_current_entry (panel1); file1 = - vfs_path_append_new (panel1->cwd_vpath, selection (panel1)->fname->str, - (char *) NULL); - is_dir1 = S_ISDIR (selection (panel1)->st.st_mode); + vfs_path_append_new (panel1->cwd_vpath, fe1->fname->str, (char *) NULL); + is_dir1 = S_ISDIR (fe1->st.st_mode); if (is_dir1) { message (D_ERROR, MSG_ERROR, _("\"%s\" is a directory"), - path_trunc (selection (panel1)->fname->str, 30)); + path_trunc (fe1->fname->str, 30)); goto ret; } break; diff --git a/src/filemanager/achown.c b/src/filemanager/achown.c index ad5234853..00ce5acc8 100644 --- a/src/filemanager/achown.c +++ b/src/filemanager/achown.c @@ -1021,7 +1021,7 @@ advanced_chown_cmd (WPanel * panel) if (panel->marked != 0) fname = next_file (panel); /* next marked file */ else - fname = selection (panel)->fname; /* single file */ + fname = panel_current_entry (panel)->fname; /* single file */ vpath = vfs_path_from_str (fname->str); diff --git a/src/filemanager/chattr.c b/src/filemanager/chattr.c index 566e77a2a..e832a1eb5 100644 --- a/src/filemanager/chattr.c +++ b/src/filemanager/chattr.c @@ -1234,7 +1234,7 @@ chattr_cmd (WPanel * panel) if (panel->marked != 0) fname = next_file (panel); /* next marked file */ else - fname = selection (panel)->fname; /* single file */ + fname = panel_current_entry (panel)->fname; /* single file */ vpath = vfs_path_from_str (fname->str); diff --git a/src/filemanager/chmod.c b/src/filemanager/chmod.c index b1e9da239..911c37cc4 100644 --- a/src/filemanager/chmod.c +++ b/src/filemanager/chmod.c @@ -554,7 +554,7 @@ chmod_cmd (WPanel * panel) if (panel->marked != 0) fname = next_file (panel); /* next marked file */ else - fname = selection (panel)->fname; /* single file */ + fname = panel_current_entry (panel)->fname; /* single file */ vpath = vfs_path_from_str (fname->str); diff --git a/src/filemanager/chown.c b/src/filemanager/chown.c index 2959b4a13..9f7d2e816 100644 --- a/src/filemanager/chown.c +++ b/src/filemanager/chown.c @@ -423,7 +423,7 @@ chown_cmd (WPanel * panel) if (panel->marked != 0) fname = next_file (panel); /* next marked file */ else - fname = selection (panel)->fname; /* single file */ + fname = panel_current_entry (panel)->fname; /* single file */ vpath = vfs_path_from_str (fname->str); diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index dbd10ad22..7df316e7c 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -125,14 +125,18 @@ static const char *machine_str = N_("Enter machine name (F1 for details):"); /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ /** - * Run viewer (internal or external) on the currently selected file. + * Run viewer (internal or external) on the current file. * If @plain_view is TRUE, force internal viewer and raw mode (used for F13). */ static void do_view_cmd (WPanel * panel, gboolean plain_view) { + const file_entry_t *fe; + + fe = panel_current_entry (panel); + /* Directories are viewed by changing to them */ - if (S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel))) + if (S_ISDIR (fe->st.st_mode) || link_isdir (fe)) { vfs_path_t *fname_vpath; @@ -141,18 +145,16 @@ do_view_cmd (WPanel * panel, gboolean plain_view) _("&Yes"), _("&No")) != 0) return; - fname_vpath = vfs_path_from_str (selection (panel)->fname->str); + fname_vpath = vfs_path_from_str (fe->fname->str); if (!panel_cd (panel, fname_vpath, cd_exact)) message (D_ERROR, MSG_ERROR, _("Cannot change directory")); vfs_path_free (fname_vpath, TRUE); } else { - int file_idx; vfs_path_t *filename_vpath; - file_idx = panel->selected; - filename_vpath = vfs_path_from_str (panel->dir.list[file_idx].fname->str); + filename_vpath = vfs_path_from_str (fe->fname->str); view_file (filename_vpath, plain_view, use_internal_view); vfs_path_free (filename_vpath, TRUE); } @@ -589,7 +591,7 @@ view_file (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean inte /* --------------------------------------------------------------------------------------------- */ -/** Run user's preferred viewer on the currently selected file */ +/** Run user's preferred viewer on the current file */ void view_cmd (WPanel * panel) @@ -608,7 +610,7 @@ view_file_cmd (const WPanel * panel) filename = input_expand_dialog (_("View file"), _("Filename:"), - MC_HISTORY_FM_VIEW_FILE, selection (panel)->fname->str, + MC_HISTORY_FM_VIEW_FILE, panel_current_entry (panel)->fname->str, INPUT_COMPLETE_FILENAMES); if (filename == NULL) return; @@ -620,7 +622,7 @@ view_file_cmd (const WPanel * panel) } /* --------------------------------------------------------------------------------------------- */ -/** Run plain internal viewer on the currently selected file */ +/** Run plain internal viewer on the current file */ void view_raw_cmd (WPanel * panel) { @@ -636,7 +638,7 @@ view_filtered_cmd (const WPanel * panel) const char *initial_command; if (input_is_empty (cmdline)) - initial_command = selection (panel)->fname->str; + initial_command = panel_current_entry (panel)->fname->str; else initial_command = input_get_ctext (cmdline); @@ -698,7 +700,7 @@ edit_cmd (const WPanel * panel) { vfs_path_t *fname; - fname = vfs_path_from_str (selection (panel)->fname->str); + fname = vfs_path_from_str (panel_current_entry (panel)->fname->str); if (regex_command (fname, "Edit") == 0) do_edit (fname); vfs_path_free (fname, TRUE); @@ -712,7 +714,7 @@ edit_cmd_force_internal (const WPanel * panel) { vfs_path_t *fname; - fname = vfs_path_from_str (selection (panel)->fname->str); + fname = vfs_path_from_str (panel_current_entry (panel)->fname->str); if (regex_command (fname, "Edit") == 0) edit_file_at_line (fname, TRUE, 1); vfs_path_free (fname, TRUE); @@ -754,12 +756,15 @@ edit_cmd_new (void) void mkdir_cmd (WPanel * panel) { + const file_entry_t *fe; char *dir; const char *name = ""; - /* If 'on' then automatically fills name with current selected item name */ - if (auto_fill_mkdir_name && !DIR_IS_DOTDOT (selection (panel)->fname->str)) - name = selection (panel)->fname->str; + fe = panel_current_entry (panel); + + /* If 'on' then automatically fills name with current item name */ + if (auto_fill_mkdir_name && !DIR_IS_DOTDOT (fe->fname->str)) + name = fe->fname->str; dir = input_expand_dialog (_("Create a new Directory"), @@ -1075,8 +1080,9 @@ swap_cmd (void) void link_cmd (link_type_t link_type) { - const char *filename = selection (current_panel)->fname->str; + const char *filename; + filename = panel_current_entry (current_panel)->fname->str; if (filename != NULL) do_link (link_type, filename); } @@ -1089,7 +1095,7 @@ edit_symlink_cmd (void) const file_entry_t *fe; const char *p; - fe = selection (current_panel); + fe = panel_current_entry (current_panel); p = fe->fname->str; if (!S_ISLNK (fe->st.st_mode)) @@ -1242,8 +1248,9 @@ quick_cd_cmd (WPanel * panel) void smart_dirsize_cmd (WPanel * panel) { - const file_entry_t *entry = &panel->dir.list[panel->selected]; + const file_entry_t *entry; + entry = panel_current_entry (panel); if ((S_ISDIR (entry->st.st_mode) && DIR_IS_DOTDOT (entry->fname->str)) || panel->dirs_marked) dirsizes_cmd (panel); else @@ -1255,7 +1262,9 @@ smart_dirsize_cmd (WPanel * panel) void single_dirsize_cmd (WPanel * panel) { - file_entry_t *entry = &panel->dir.list[panel->selected]; + file_entry_t *entry; + + entry = panel_current_entry (panel); if (S_ISDIR (entry->st.st_mode) && !DIR_IS_DOTDOT (entry->fname->str)) { diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 03bf94055..a8f0a8298 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -1797,7 +1797,7 @@ panel_get_file (const WPanel * panel) return panel->dir.list[i].fname->str; } - return panel->dir.list[panel->selected].fname->str; + return panel_current_entry (panel)->fname->str; } /* --------------------------------------------------------------------------------------------- */ @@ -1809,7 +1809,7 @@ check_single_entry (const WPanel * panel, gboolean force_single, struct stat *sr gboolean ok; if (force_single) - source = selection (panel)->fname->str; + source = panel_current_entry (panel)->fname->str; else source = panel_get_file (panel); @@ -3277,7 +3277,7 @@ compute_dir_size (const vfs_path_t * dirname_vpath, dirsize_status_msg_t * sm, /** * panel_operate: * - * Performs one of the operations on the selection on the source_panel + * Performs one of the operations on the current on the source_panel * (copy, delete, move). * * Returns TRUE if did change the directory @@ -3381,7 +3381,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl { if (operation == OP_DELETE) dialog_type = FILEGUI_DIALOG_DELETE_ITEM; - else if (single_entry && S_ISDIR (selection (panel)->st.st_mode)) + else if (single_entry && S_ISDIR (panel_current_entry (panel)->st.st_mode)) dialog_type = FILEGUI_DIALOG_MULTI_ITEM; else if (single_entry || force_single) dialog_type = FILEGUI_DIALOG_ONE_ITEM; diff --git a/src/filemanager/filemanager.c b/src/filemanager/filemanager.c index 951bd8690..5c916e56c 100644 --- a/src/filemanager/filemanager.c +++ b/src/filemanager/filemanager.c @@ -152,7 +152,7 @@ treebox_cmd (void) { char *sel_dir; - sel_dir = tree_box (selection (current_panel)->fname->str); + sel_dir = tree_box (panel_current_entry (current_panel)->fname->str); if (sel_dir != NULL) { vfs_path_t *sel_vdir; @@ -724,16 +724,20 @@ midnight_put_panel_path (WPanel * panel) static void put_link (WPanel * panel) { + const file_entry_t *fe; + if (!command_prompt) return; - if (S_ISLNK (selection (panel)->st.st_mode)) + + fe = panel_current_entry (panel); + + if (S_ISLNK (fe->st.st_mode)) { char buffer[MC_MAXPATHLEN]; vfs_path_t *vpath; int i; - vpath = - vfs_path_append_new (panel->cwd_vpath, selection (panel)->fname->str, (char *) NULL); + vpath = vfs_path_append_new (panel->cwd_vpath, fe->fname->str, (char *) NULL); i = mc_readlink (vpath, buffer, sizeof (buffer) - 1); vfs_path_free (vpath, TRUE); @@ -783,7 +787,7 @@ put_current_selected (void) tmp = vfs_path_as_str (selected_name); } else - tmp = selection (current_panel)->fname->str; + tmp = panel_current_entry (current_panel)->fname->str; command_insert (cmdline, tmp, TRUE); } @@ -807,9 +811,8 @@ put_tagged (WPanel * panel) } } else - { - command_insert (cmdline, panel->dir.list[panel->selected].fname->str, TRUE); - } + command_insert (cmdline, panel_current_entry (panel)->fname->str, TRUE); + input_enable_update (cmdline); } @@ -1027,7 +1030,7 @@ show_editor_viewer_history (void) d = g_path_get_dirname (s); s_vpath = vfs_path_from_str (d); panel_cd (current_panel, s_vpath, cd_exact); - try_to_select (current_panel, s); + panel_set_current_by_name (current_panel, s); g_free (d); } } diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 9c4d870c5..8b6957927 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -1932,8 +1932,7 @@ find_cmd (WPanel * panel) panel_cd (panel, dirname_vpath, cd_exact); vfs_path_free (dirname_vpath, TRUE); if (filename != NULL) - try_to_select (panel, - filename + (content_pattern != NULL + panel_set_current_by_name (panel, filename + (content_pattern != NULL ? strchr (filename + 4, ':') - filename + 1 : 4)); } else if (filename != NULL) @@ -1956,7 +1955,7 @@ find_cmd (WPanel * panel) if (v == B_PANELIZE) { panel_re_sort (panel); - try_to_select (panel, NULL); + panel_set_current_by_name (panel, NULL); break; } } diff --git a/src/filemanager/info.c b/src/filemanager/info.c index 987a1900c..59477ad51 100644 --- a/src/filemanager/info.c +++ b/src/filemanager/info.c @@ -107,6 +107,7 @@ static void info_show_info (WInfo * info) { const WRect *w = &CONST_WIDGET (info)->rect; + const file_entry_t *fe; static int i18n_adjust = 0; static const char *file_label; GString *buff; @@ -136,7 +137,9 @@ info_show_info (WInfo * info) my_statfs (&myfs_stats, p_rp_cwd); - st = current_panel->dir.list[current_panel->selected].st; + fe = panel_current_entry (current_panel); + + st = fe->st; /* Print only lines which fit */ @@ -263,7 +266,7 @@ info_show_info (WInfo * info) vfs_path_t *vpath; unsigned long attr; - vpath = vfs_path_from_str (current_panel->dir.list[current_panel->selected].fname->str); + vpath = vfs_path_from_str (fe->fname->str); #ifdef ENABLE_EXT2FS_ATTR if (mc_fgetflags (vpath, &attr) == 0) @@ -289,7 +292,7 @@ info_show_info (WInfo * info) const char *fname; widget_gotoyx (w, 3, 2); - fname = current_panel->dir.list[current_panel->selected].fname->str; + fname = fe->fname->str; str_printf (buff, file_label, str_trunc (fname, w->cols - i18n_adjust)); tty_print_string (buff->str); } diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index 03ac48e61..26208462d 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -1200,7 +1200,7 @@ create_panel (int num, panel_view_mode_t type) new_widget = WIDGET (mcview_new (r.y, r.x, r.lines, r.cols, TRUE)); the_other_panel = PANEL (panels[the_other].widget); if (the_other_panel != NULL) - file_name = the_other_panel->dir.list[the_other_panel->selected].fname->str; + file_name = panel_current_entry (the_other_panel)->fname->str; else file_name = ""; @@ -1300,7 +1300,7 @@ swap_panels (void) panelswap (dirs_marked); panelswap (total); panelswap (top_file); - panelswap (selected); + panelswap (current); panelswap (is_panelized); panelswap (panelized_descr); panelswap (dir_stat); diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 544834fe7..682c99e33 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -8,7 +8,7 @@ Miguel de Icaza, 1995 Timur Bakeyev, 1997, 1999 Slava Zanko , 2013 - Andrew Borodin , 2013-2022 + Andrew Borodin , 2013-2023 This file is part of the Midnight Commander. @@ -90,9 +90,9 @@ mc_fhl_t *mc_filehighlight = NULL; /*** file scope macro definitions ****************************************************************/ #define NORMAL 0 -#define SELECTED 1 +#define CURRENT 1 #define MARKED 2 -#define MARKED_SELECTED 3 +#define MARKED_CURRENT 3 #define STATUS 5 /* select/unselect dialog results */ @@ -467,7 +467,7 @@ add_permission_string (const char *dest, int width, file_entry_t * fe, int attr, { if (i >= l && i < r) { - if (attr == SELECTED || attr == MARKED_SELECTED) + if (attr == CURRENT || attr == MARKED_CURRENT) tty_setcolor (MARKED_SELECTED_COLOR); else tty_setcolor (MARKED_COLOR); @@ -791,11 +791,11 @@ file_compute_color (int attr, file_entry_t * fe) { switch (attr) { - case SELECTED: + case CURRENT: return (SELECTED_COLOR); case MARKED: return (MARKED_COLOR); - case MARKED_SELECTED: + case MARKED_CURRENT: return (MARKED_SELECTED_COLOR); case STATUS: return (NORMAL_COLOR); @@ -911,7 +911,7 @@ format_file (WPanel * panel, int file_index, int width, int attr, gboolean issta } else { - if (attr == SELECTED || attr == MARKED_SELECTED) + if (attr == CURRENT || attr == MARKED_CURRENT) tty_setcolor (SELECTED_COLOR); else tty_setcolor (NORMAL_COLOR); @@ -1019,8 +1019,9 @@ static void display_mini_info (WPanel * panel) { Widget *w = WIDGET (panel); + const file_entry_t *fe; - if (!panels_options.show_mini_info || panel->selected < 0) + if (!panels_options.show_mini_info || panel->current < 0) return; widget_gotoyx (w, panel_lines (panel) + 3, 1); @@ -1037,15 +1038,15 @@ display_mini_info (WPanel * panel) /* Status resolves links and show them */ set_colors (panel); - if (S_ISLNK (panel->dir.list[panel->selected].st.st_mode)) + fe = panel_current_entry (panel); + + if (S_ISLNK (fe->st.st_mode)) { char link_target[MC_MAXPATHLEN]; vfs_path_t *lc_link_vpath; int len; - lc_link_vpath = - vfs_path_append_new (panel->cwd_vpath, panel->dir.list[panel->selected].fname->str, - (char *) NULL); + lc_link_vpath = vfs_path_append_new (panel->cwd_vpath, fe->fname->str, (char *) NULL); len = mc_readlink (lc_link_vpath, link_target, MC_MAXPATHLEN - 1); vfs_path_free (lc_link_vpath, TRUE); if (len > 0) @@ -1057,7 +1058,7 @@ display_mini_info (WPanel * panel) else tty_print_string (str_fit_to_term (_(""), w->rect.cols - 2, J_LEFT)); } - else if (DIR_IS_DOTDOT (panel->dir.list[panel->selected].fname->str)) + else if (DIR_IS_DOTDOT (fe->fname->str)) { /* FIXME: * while loading directory (dir_list_load() and dir_list_reload()), @@ -1067,7 +1068,7 @@ display_mini_info (WPanel * panel) } else /* Default behavior */ - repaint_file (panel, panel->selected, STATUS, TRUE); + repaint_file (panel, panel->current, STATUS, TRUE); } /* --------------------------------------------------------------------------------------------- */ @@ -1089,7 +1090,7 @@ paint_dir (WPanel * panel) if (i + panel->top_file < panel->dir.len) { color = 2 * (panel->dir.list[i + panel->top_file].f.marked); - color += (panel->selected == i + panel->top_file && panel->active); + color += (panel->current == i + panel->top_file && panel->active); } repaint_file (panel, i + panel->top_file, color, FALSE); @@ -1345,14 +1346,17 @@ show_dir (const WPanel * panel) { if (panel->marked == 0) { + const file_entry_t *fe; + + fe = panel_current_entry (panel); + /* Show size of curret file in the bottom of panel */ - if (S_ISREG (panel->dir.list[panel->selected].st.st_mode)) + if (S_ISREG (fe->st.st_mode)) { char buffer[BUF_SMALL]; g_snprintf (buffer, sizeof (buffer), " %s ", - size_trunc_sep (panel->dir.list[panel->selected].st.st_size, - panels_options.kilobyte_si)); + size_trunc_sep (fe->st.st_size, panels_options.kilobyte_si)); tty_setcolor (NORMAL_COLOR); widget_gotoyx (w, w->rect.lines - 1, 4); tty_print_string (buffer); @@ -1379,13 +1383,13 @@ adjust_top_file (WPanel * panel) { int items; - /* Update panel->selected to avoid out of range in panel->dir.list[panel->selected] + /* Update panel->current to avoid out of range in panel->dir.list[panel->current] * when panel is redrawing when directory is reloading, for example in path: * dir_list_reload() -> mc_refresh() -> dialog_change_screen_size() -> * midnight_callback (MSG_RESIZE) -> setup_panels() -> panel_callback(MSG_DRAW) -> * display_mini_info() */ - panel->selected = CLAMP (panel->selected, 0, panel->dir.len - 1); + panel->current = CLAMP (panel->current, 0, panel->dir.len - 1); items = panel_items (panel); @@ -1398,8 +1402,8 @@ adjust_top_file (WPanel * panel) { int i; - /* top_file has to be in the range [selected-items+1, selected] so that - the selected file is visible. + /* top_file has to be in the range [current-items+1, current] so that + the current file is visible. top_file should be in the range [0, count-items] so that there's no empty space wasted. Within these ranges, adjust it by as little as possible. */ @@ -1407,7 +1411,7 @@ adjust_top_file (WPanel * panel) if (panel->top_file < 0) panel->top_file = 0; - i = panel->selected - items + 1; + i = panel->current - items + 1; if (panel->top_file < i) panel->top_file = i; @@ -1415,8 +1419,8 @@ adjust_top_file (WPanel * panel) if (panel->top_file > i) panel->top_file = i; - if (panel->top_file > panel->selected) - panel->top_file = panel->selected; + if (panel->top_file > panel->current) + panel->top_file = panel->current; } } @@ -2030,17 +2034,21 @@ maybe_cd (WPanel * panel, gboolean move_up_dir) { if (panels_options.navigate_with_arrows && input_is_empty (cmdline)) { + const file_entry_t *fe; + if (move_up_dir) { cd_up_dir (panel); return MSG_HANDLED; } - if (S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel))) + fe = panel_current_entry (panel); + + if (S_ISDIR (fe->st.st_mode) || link_isdir (fe)) { vfs_path_t *vpath; - vpath = vfs_path_from_str (selection (panel)->fname->str); + vpath = vfs_path_from_str (fe->fname->str); panel_cd (panel, vpath, cd_exact); vfs_path_free (vpath, TRUE); return MSG_HANDLED; @@ -2070,7 +2078,7 @@ force_maybe_cd (WPanel * panel) static inline void unselect_item (WPanel * panel) { - repaint_file (panel, panel->selected, 2 * selection (panel)->f.marked, FALSE); + repaint_file (panel, panel->current, 2 * panel_current_entry (panel)->f.marked, FALSE); } /* --------------------------------------------------------------------------------------------- */ @@ -2079,17 +2087,20 @@ unselect_item (WPanel * panel) static void panel_select_ext_cmd (WPanel * panel) { + const file_entry_t *fe; GString *filename; gboolean do_select; char *reg_exp, *cur_file_ext; mc_search_t *search; int i; - filename = selection (panel)->fname; + fe = panel_current_entry (panel); + + filename = fe->fname; if (filename == NULL) return; - do_select = !selection (panel)->f.marked; + do_select = !fe->f.marked; cur_file_ext = strutils_regex_escape (extension (filename->str)); if (cur_file_ext[0] != '\0') @@ -2105,12 +2116,12 @@ panel_select_ext_cmd (WPanel * panel) for (i = 0; i < panel->dir.len; i++) { - file_entry_t *file_entry = &panel->dir.list[i]; + fe = &panel->dir.list[i]; - if (DIR_IS_DOTDOT (file_entry->fname->str) || S_ISDIR (file_entry->st.st_mode)) + if (DIR_IS_DOTDOT (fe->fname->str) || S_ISDIR (fe->st.st_mode)) continue; - if (!mc_search_run (search, file_entry->fname->str, 0, file_entry->fname->len, NULL)) + if (!mc_search_run (search, fe->fname->str, 0, fe->fname->len, NULL)) continue; do_file_mark (panel, i, do_select ? 1 : 0); @@ -2123,7 +2134,7 @@ panel_select_ext_cmd (WPanel * panel) /* --------------------------------------------------------------------------------------------- */ static int -panel_selected_at_half (const WPanel * panel) +panel_current_at_half (const WPanel * panel) { int lines, top; @@ -2132,9 +2143,9 @@ panel_selected_at_half (const WPanel * panel) /* define top file of column */ top = panel->top_file; if (panel->list_cols > 1) - top += lines * ((panel->selected - top) / lines); + top += lines * ((panel->current - top) / lines); - return (panel->selected - top - lines / 2); + return (panel->current - top - lines / 2); } /* --------------------------------------------------------------------------------------------- */ @@ -2144,15 +2155,15 @@ move_down (WPanel * panel) { int items; - if (panel->selected + 1 == panel->dir.len) + if (panel->current + 1 == panel->dir.len) return; unselect_item (panel); - panel->selected++; + panel->current++; items = panel_items (panel); - if (panels_options.scroll_pages && panel->selected - panel->top_file == items) + if (panels_options.scroll_pages && panel->current - panel->top_file == items) { /* Scroll window half screen */ panel->top_file += items / 2; @@ -2160,7 +2171,7 @@ move_down (WPanel * panel) panel->top_file = panel->dir.len - items; paint_dir (panel); } - else if (panels_options.scroll_center && panel_selected_at_half (panel) > 0) + else if (panels_options.scroll_center && panel_current_at_half (panel) > 0) { /* Scroll window when cursor is halfway down */ panel->top_file++; @@ -2175,13 +2186,13 @@ move_down (WPanel * panel) static void move_up (WPanel * panel) { - if (panel->selected == 0) + if (panel->current == 0) return; unselect_item (panel); - panel->selected--; + panel->current--; - if (panels_options.scroll_pages && panel->selected < panel->top_file) + if (panels_options.scroll_pages && panel->current < panel->top_file) { /* Scroll window half screen */ panel->top_file -= panel_items (panel) / 2; @@ -2189,7 +2200,7 @@ move_up (WPanel * panel) panel->top_file = 0; paint_dir (panel); } - else if (panels_options.scroll_center && panel_selected_at_half (panel) < 0) + else if (panels_options.scroll_center && panel_current_at_half (panel) < 0) { /* Scroll window when cursor is halfway up */ panel->top_file--; @@ -2200,15 +2211,15 @@ move_up (WPanel * panel) } /* --------------------------------------------------------------------------------------------- */ -/** Changes the selection by lines (may be negative) */ +/** Changes the current by lines (may be negative) */ static void -move_selection (WPanel * panel, int lines) +panel_move_current (WPanel * panel, int lines) { int new_pos; gboolean adjust = FALSE; - new_pos = panel->selected + lines; + new_pos = panel->current + lines; if (new_pos >= panel->dir.len) new_pos = panel->dir.len - 1; @@ -2216,15 +2227,15 @@ move_selection (WPanel * panel, int lines) new_pos = 0; unselect_item (panel); - panel->selected = new_pos; + panel->current = new_pos; - if (panel->selected - panel->top_file >= panel_items (panel)) + if (panel->current - panel->top_file >= panel_items (panel)) { panel->top_file += lines; adjust = TRUE; } - if (panel->selected - panel->top_file < 0) + if (panel->current - panel->top_file < 0) { panel->top_file += lines; adjust = TRUE; @@ -2232,8 +2243,8 @@ move_selection (WPanel * panel, int lines) if (adjust) { - if (panel->top_file > panel->selected) - panel->top_file = panel->selected; + if (panel->top_file > panel->current) + panel->top_file = panel->current; if (panel->top_file < 0) panel->top_file = 0; paint_dir (panel); @@ -2248,7 +2259,7 @@ move_left (WPanel * panel) { if (panel->list_cols > 1) { - move_selection (panel, -panel_lines (panel)); + panel_move_current (panel, -panel_lines (panel)); return MSG_HANDLED; } @@ -2262,11 +2273,11 @@ move_right (WPanel * panel) { if (panel->list_cols > 1) { - move_selection (panel, panel_lines (panel)); + panel_move_current (panel, panel_lines (panel)); return MSG_HANDLED; } - return maybe_cd (panel, FALSE); /* cd (selection) */ + return maybe_cd (panel, FALSE); /* cd (current) */ } /* --------------------------------------------------------------------------------------------- */ @@ -2276,7 +2287,7 @@ prev_page (WPanel * panel) { int items; - if (panel->selected == 0 && panel->top_file == 0) + if (panel->current == 0 && panel->top_file == 0) return; unselect_item (panel); @@ -2284,9 +2295,9 @@ prev_page (WPanel * panel) if (panel->top_file < items) items = panel->top_file; if (items == 0) - panel->selected = 0; + panel->current = 0; else - panel->selected -= items; + panel->current -= items; panel->top_file -= items; select_item (panel); @@ -2302,10 +2313,12 @@ goto_parent_dir (WPanel * panel) cd_up_dir (panel); else { - GString *fname = panel->dir.list[panel->selected].fname; + GString *fname; const char *bname; vfs_path_t *dname_vpath; + fname = panel_current_entry (panel)->fname; + if (g_path_is_absolute (fname->str)) fname = mc_g_string_dup (fname); else @@ -2331,7 +2344,7 @@ goto_parent_dir (WPanel * panel) } panel_cd (panel, dname_vpath, cd_exact); - try_to_select (panel, bname); + panel_set_current_by_name (panel, bname); vfs_path_free (dname_vpath, TRUE); g_string_free (fname, TRUE); @@ -2345,7 +2358,7 @@ next_page (WPanel * panel) { int items; - if (panel->selected == panel->dir.len - 1) + if (panel->current == panel->dir.len - 1) return; unselect_item (panel); @@ -2355,9 +2368,9 @@ next_page (WPanel * panel) if (panel->top_file + items < 0) items = -panel->top_file; if (items == 0) - panel->selected = panel->dir.len - 1; + panel->current = panel->dir.len - 1; else - panel->selected += items; + panel->current += items; panel->top_file += items; select_item (panel); @@ -2369,11 +2382,15 @@ next_page (WPanel * panel) static void goto_child_dir (WPanel * panel) { - if ((S_ISDIR (selection (panel)->st.st_mode) || link_isdir (selection (panel)))) + const file_entry_t *fe; + + fe = panel_current_entry (panel); + + if (S_ISDIR (fe->st.st_mode) || link_isdir (fe)) { vfs_path_t *vpath; - vpath = vfs_path_from_str (selection (panel)->fname->str); + vpath = vfs_path_from_str (fe->fname->str); panel_cd (panel, vpath, cd_exact); vfs_path_free (vpath, TRUE); } @@ -2385,7 +2402,7 @@ static void goto_top_file (WPanel * panel) { unselect_item (panel); - panel->selected = panel->top_file; + panel->current = panel->top_file; select_item (panel); } @@ -2395,7 +2412,7 @@ static void goto_middle_file (WPanel * panel) { unselect_item (panel); - panel->selected = panel->top_file + panel_items (panel) / 2; + panel->current = panel->top_file + panel_items (panel) / 2; select_item (panel); } @@ -2405,7 +2422,7 @@ static void goto_bottom_file (WPanel * panel) { unselect_item (panel); - panel->selected = panel->top_file + panel_items (panel) - 1; + panel->current = panel->top_file + panel_items (panel) - 1; select_item (panel); } @@ -2414,7 +2431,7 @@ goto_bottom_file (WPanel * panel) static void move_home (WPanel * panel) { - if (panel->selected == 0) + if (panel->current == 0) return; unselect_item (panel); @@ -2425,12 +2442,12 @@ move_home (WPanel * panel) middle_pos = panel->top_file + panel_items (panel) / 2; - if (panel->selected > middle_pos) + if (panel->current > middle_pos) { goto_middle_file (panel); return; } - if (panel->selected != panel->top_file) + if (panel->current != panel->top_file) { goto_top_file (panel); return; @@ -2438,7 +2455,7 @@ move_home (WPanel * panel) } panel->top_file = 0; - panel->selected = 0; + panel->current = 0; paint_dir (panel); select_item (panel); @@ -2449,7 +2466,7 @@ move_home (WPanel * panel) static void move_end (WPanel * panel) { - if (panel->selected == panel->dir.len - 1) + if (panel->current == panel->dir.len - 1) return; unselect_item (panel); @@ -2461,19 +2478,19 @@ move_end (WPanel * panel) items = panel_items (panel); middle_pos = panel->top_file + items / 2; - if (panel->selected < middle_pos) + if (panel->current < middle_pos) { goto_middle_file (panel); return; } - if (panel->selected != panel->top_file + items - 1) + if (panel->current != panel->top_file + items - 1) { goto_bottom_file (panel); return; } } - panel->selected = panel->dir.len - 1; + panel->current = panel->dir.len - 1; paint_dir (panel); select_item (panel); } @@ -2483,7 +2500,7 @@ move_end (WPanel * panel) static void do_mark_file (WPanel * panel, mark_act_t do_move) { - do_file_mark (panel, panel->selected, selection (panel)->f.marked ? 0 : 1); + do_file_mark (panel, panel->current, panel_current_entry (panel)->f.marked ? 0 : 1); if ((panels_options.mark_moves_down && do_move == MARK_DOWN) || do_move == MARK_FORCE_DOWN) move_down (panel); @@ -2523,16 +2540,16 @@ mark_file_right (WPanel * panel) int lines; if (state_mark < 0) - state_mark = selection (panel)->f.marked ? 0 : 1; + state_mark = panel_current_entry (panel)->f.marked ? 0 : 1; lines = panel_lines (panel); - lines = MIN (lines, panel->dir.len - panel->selected - 1); + lines = MIN (lines, panel->dir.len - panel->current - 1); for (; lines != 0; lines--) { - do_file_mark (panel, panel->selected, state_mark); + do_file_mark (panel, panel->current, state_mark); move_down (panel); } - do_file_mark (panel, panel->selected, state_mark); + do_file_mark (panel, panel->current, state_mark); } /* --------------------------------------------------------------------------------------------- */ @@ -2543,16 +2560,16 @@ mark_file_left (WPanel * panel) int lines; if (state_mark < 0) - state_mark = selection (panel)->f.marked ? 0 : 1; + state_mark = panel_current_entry (panel)->f.marked ? 0 : 1; lines = panel_lines (panel); - lines = MIN (lines, panel->selected + 1); + lines = MIN (lines, panel->current + 1); for (; lines != 0; lines--) { - do_file_mark (panel, panel->selected, state_mark); + do_file_mark (panel, panel->current, state_mark); move_up (panel); } - do_file_mark (panel, panel->selected, state_mark); + do_file_mark (panel, panel->current, state_mark); } /* --------------------------------------------------------------------------------------------- */ @@ -2726,7 +2743,8 @@ panel_do_set_filter (WPanel * panel) static void do_search (WPanel * panel, int c_code) { - int i, sel; + int curr; + int i; gboolean wrapped = FALSE; char *act; mc_search_t *search; @@ -2787,9 +2805,9 @@ do_search (WPanel * panel, int c_code) break; } - sel = panel->selected; + curr = panel->current; - for (i = panel->selected; !wrapped || i != panel->selected; i++) + for (i = panel->current; !wrapped || i != panel->current; i++) { if (i >= panel->dir.len) { @@ -2801,7 +2819,7 @@ do_search (WPanel * panel, int c_code) if (mc_search_run (search, panel->dir.list[i].fname->str, 0, panel->dir.list[i].fname->len, NULL)) { - sel = i; + curr = i; is_found = TRUE; break; } @@ -2809,7 +2827,7 @@ do_search (WPanel * panel, int c_code) if (is_found) { unselect_item (panel); - panel->selected = sel; + panel->current = curr; select_item (panel); widget_draw (WIDGET (panel)); } @@ -2834,8 +2852,8 @@ start_search (WPanel * panel) { if (panel->quick_search.active) { - if (panel->selected == panel->dir.len - 1) - panel->selected = 0; + if (panel->current == panel->dir.len - 1) + panel->current = 0; else move_down (panel); @@ -2953,10 +2971,9 @@ do_enter_on_file_entry (WPanel * panel, file_entry_t * fe) static inline gboolean do_enter (WPanel * panel) { - return do_enter_on_file_entry (panel, selection (panel)); + return do_enter_on_file_entry (panel, panel_current_entry (panel)); } - /* --------------------------------------------------------------------------------------------- */ static void @@ -2973,11 +2990,13 @@ panel_cycle_listing_format (WPanel * panel) static void chdir_other_panel (WPanel * panel) { - const file_entry_t *entry = &panel->dir.list[panel->selected]; + const file_entry_t *entry; vfs_path_t *new_dir_vpath; - char *sel_entry = NULL; + char *curr_entry = NULL; WPanel *p; + entry = panel_current_entry (panel); + if (get_other_type () != view_listing) create_panel (get_other_index (), view_listing); @@ -2986,15 +3005,15 @@ chdir_other_panel (WPanel * panel) else { new_dir_vpath = vfs_path_append_new (panel->cwd_vpath, "..", (char *) NULL); - sel_entry = strrchr (vfs_path_get_last_path_str (panel->cwd_vpath), PATH_SEP); + curr_entry = strrchr (vfs_path_get_last_path_str (panel->cwd_vpath), PATH_SEP); } p = change_panel (); panel_cd (p, new_dir_vpath, cd_exact); vfs_path_free (new_dir_vpath, TRUE); - if (sel_entry) - try_to_select (p, sel_entry); + if (curr_entry != NULL) + panel_set_current_by_name (p, curr_entry); (void) change_panel (); move_down (panel); @@ -3016,9 +3035,9 @@ panel_sync_other (const WPanel * panel) panel_do_cd (other_panel, panel->cwd_vpath, cd_exact); - /* try to select current filename on the other panel */ + /* try to set current filename on the other panel */ if (!panel->is_panelized) - try_to_select (other_panel, selection (panel)->fname->str); + panel_set_current_by_name (other_panel, panel_current_entry (panel)->fname->str); } /* --------------------------------------------------------------------------------------------- */ @@ -3026,6 +3045,7 @@ panel_sync_other (const WPanel * panel) static void chdir_to_readlink (WPanel * panel) { + const file_entry_t *fe; vfs_path_t *new_dir_vpath; char buffer[MC_MAXPATHLEN]; int i; @@ -3037,14 +3057,16 @@ chdir_to_readlink (WPanel * panel) if (get_other_type () != view_listing) return; - if (!S_ISLNK (panel->dir.list[panel->selected].st.st_mode)) + fe = panel_current_entry (panel); + + if (!S_ISLNK (fe->st.st_mode)) return; - i = readlink (selection (panel)->fname->str, buffer, MC_MAXPATHLEN - 1); + i = readlink (fe->fname->str, buffer, MC_MAXPATHLEN - 1); if (i < 0) return; - panel_fname_vpath = vfs_path_from_str (selection (panel)->fname->str); + panel_fname_vpath = vfs_path_from_str (fe->fname->str); ok = (mc_stat (panel_fname_vpath, &st) >= 0); vfs_path_free (panel_fname_vpath, TRUE); if (!ok) @@ -3277,7 +3299,7 @@ panel_set_sort_type_by_id (WPanel * panel, const char *name) /* --------------------------------------------------------------------------------------------- */ /** - * If we moved to the parent directory move the selection pointer to + * If we moved to the parent directory move the 'current' pointer to * the old directory name; If we leave VFS dir, remove FS specificator. * * You do _NOT_ want to add any vfs aware code here. @@ -3383,7 +3405,7 @@ panel_do_cd_int (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum &panel->sort_info, &panel->filter)) message (D_ERROR, MSG_ERROR, _("Cannot read directory contents")); - try_to_select (panel, get_parent_dir_name (panel->cwd_vpath, olddir_vpath)); + panel_set_current_by_name (panel, get_parent_dir_name (panel->cwd_vpath, olddir_vpath)); load_hint (FALSE); panel->dirty = TRUE; @@ -3820,7 +3842,7 @@ static void mouse_toggle_mark (WPanel * panel) { do_mark_file (panel, MARK_DONT_MOVE); - mouse_marking = selection (panel)->f.marked; + mouse_marking = panel_current_entry (panel)->f.marked; mouse_mark_panel = current_panel; } @@ -3831,9 +3853,13 @@ mouse_set_mark (WPanel * panel) { if (mouse_mark_panel == panel) { - if (mouse_marking && !selection (panel)->f.marked) + const file_entry_t *fe; + + fe = panel_current_entry (panel); + + if (mouse_marking && !fe->f.marked) do_mark_file (panel, MARK_DONT_MOVE); - else if (!mouse_marking && selection (panel)->f.marked) + else if (!mouse_marking && fe->f.marked) do_mark_file (panel, MARK_DONT_MOVE); } } @@ -3841,7 +3867,7 @@ mouse_set_mark (WPanel * panel) /* --------------------------------------------------------------------------------------------- */ static void -mark_if_marking (WPanel * panel, const mouse_event_t * event, int previous_selected) +mark_if_marking (WPanel * panel, const mouse_event_t * event, int previous_current) { if ((event->buttons & GPM_B_RIGHT) == 0) return; @@ -3850,19 +3876,19 @@ mark_if_marking (WPanel * panel, const mouse_event_t * event, int previous_selec mouse_toggle_mark (panel); else { - int psel, sel1, sel2; + int pcurr, curr1, curr2; - psel = panel->selected; - sel1 = MIN (previous_selected, panel->selected); - sel2 = MAX (previous_selected, panel->selected); + pcurr = panel->current; + curr1 = MIN (previous_current, panel->current); + curr2 = MAX (previous_current, panel->current); - for (; sel1 <= sel2; sel1++) + for (; curr1 <= curr2; curr1++) { - panel->selected = sel1; + panel->current = curr1; mouse_set_mark (panel); } - panel->selected = psel; + panel->current = pcurr; } } @@ -4001,35 +4027,35 @@ panel_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) case MSG_MOUSE_DRAG: { int my_index; - int previous_selected; + int previous_current; my_index = panel_mouse_is_on_item (panel, event->y - 2, event->x); - previous_selected = panel->selected; + previous_current = panel->current; switch (my_index) { case MOUSE_UPPER_FILE_LIST: move_up (panel); - mark_if_marking (panel, event, previous_selected); + mark_if_marking (panel, event, previous_current); break; case MOUSE_BELOW_FILE_LIST: move_down (panel); - mark_if_marking (panel, event, previous_selected); + mark_if_marking (panel, event, previous_current); break; case MOUSE_AFTER_LAST_FILE: break; /* do nothing */ default: - if (my_index != panel->selected) + if (my_index != panel->current) { unselect_item (panel); - panel->selected = my_index; + panel->current = my_index; select_item (panel); } - mark_if_marking (panel, event, previous_selected); + mark_if_marking (panel, event, previous_current); break; } } @@ -4128,13 +4154,15 @@ update_one_panel_widget (WPanel * panel, panel_update_flags_t flags, const char memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat)); } - /* If current_file == -1 (an invalid pointer) then preserve selection */ + /* If current_file == -1 (an invalid pointer) then preserve current */ free_pointer = current_file == UP_KEEPSEL; if (free_pointer) { - my_current_file = g_strndup (panel->dir.list[panel->selected].fname->str, - panel->dir.list[panel->selected].fname->len); + const GString *fname; + + fname = panel_current_entry (panel)->fname; + my_current_file = g_strndup (fname->str, fname->len); current_file = my_current_file; } @@ -4143,7 +4171,7 @@ update_one_panel_widget (WPanel * panel, panel_update_flags_t flags, const char else panel_reload (panel); - try_to_select (panel, current_file); + panel_set_current_by_name (panel, current_file); panel->dirty = TRUE; if (free_pointer) @@ -4169,13 +4197,13 @@ update_one_panel (int which, panel_update_flags_t flags, const char *current_fil /* --------------------------------------------------------------------------------------------- */ static void -do_select (WPanel * panel, int i) +panel_set_current (WPanel * panel, int i) { - if (i != panel->selected) + if (i != panel->current) { panel->dirty = TRUE; - panel->selected = i; - panel->top_file = panel->selected - (WIDGET (panel)->rect.lines - 2) / 2; + panel->current = i; + panel->top_file = panel->current - (WIDGET (panel)->rect.lines - 2) / 2; if (panel->top_file < 0) panel->top_file = 0; } @@ -4212,7 +4240,7 @@ panel_save_current_file_to_clip_file (const gchar * event_group_name, const gcha if (current_panel->marked == 0) mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_text_to_file", - (gpointer) selection (current_panel)->fname->str); + (gpointer) panel_current_entry (current_panel)->fname->str); else { int i; @@ -4220,12 +4248,14 @@ panel_save_current_file_to_clip_file (const gchar * event_group_name, const gcha char *flist = NULL; for (i = 0; i < current_panel->dir.len; i++) - if (current_panel->dir.list[i].f.marked != 0) + { + const file_entry_t *fe = ¤t_panel->dir.list[i]; + + if (fe->f.marked != 0) { /* Skip the unmarked ones */ if (first) { - flist = g_strndup (current_panel->dir.list[i].fname->str, - current_panel->dir.list[i].fname->len); + flist = g_strndup (fe->fname->str, fe->fname->len); first = FALSE; } else @@ -4233,13 +4263,12 @@ panel_save_current_file_to_clip_file (const gchar * event_group_name, const gcha /* Add empty lines after the file */ char *tmp; - tmp = - g_strconcat (flist, "\n", current_panel->dir.list[i].fname->str, - (char *) NULL); + tmp = g_strconcat (flist, "\n", fe->fname->str, (char *) NULL); g_free (flist); flist = tmp; } } + } mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_text_to_file", (gpointer) flist); g_free (flist); @@ -4314,38 +4343,38 @@ panel_dir_list_callback (dir_list_cb_state_t state, void *data) /* --------------------------------------------------------------------------------------------- */ void -try_to_select (WPanel * panel, const char *name) +panel_set_current_by_name (WPanel * panel, const char *name) { int i; char *subdir; if (name == NULL) { - do_select (panel, 0); + panel_set_current (panel, 0); return; } /* We only want the last component of the directory, * and from this only the name without suffix. * Cut prefix if the panel is not panelized */ - if (panel->is_panelized) subdir = vfs_strip_suffix_from_filename (name); else subdir = vfs_strip_suffix_from_filename (x_basename (name)); - /* Search that subdir or filename without prefix (if not panelized panel), select it if found */ + /* Search that subdir or filename without prefix (if not panelized panel), + make it current if found */ for (i = 0; i < panel->dir.len; i++) if (strcmp (subdir, panel->dir.list[i].fname->str) == 0) { - do_select (panel, i); + panel_set_current (panel, i); g_free (subdir); return; } - /* Try to select a file near the file that is missing */ - if (panel->selected >= panel->dir.len) - do_select (panel, panel->dir.len - 1); + /* Make current near the filee that is missing */ + if (panel->current >= panel->dir.len) + panel_set_current (panel, panel->dir.len - 1); g_free (subdir); select_item (panel); @@ -4357,7 +4386,7 @@ void panel_clean_dir (WPanel * panel) { panel->top_file = 0; - panel->selected = 0; + panel->current = 0; panel->marked = 0; panel->dirs_marked = 0; panel->total = 0; @@ -4603,8 +4632,8 @@ panel_reload (WPanel * panel) message (D_ERROR, MSG_ERROR, _("Cannot read directory contents")); panel->dirty = TRUE; - if (panel->selected >= panel->dir.len) - do_select (panel, panel->dir.len - 1); + if (panel->current >= panel->dir.len) + panel_set_current (panel, panel->dir.len - 1); recalculate_panel_summary (panel); } @@ -4818,27 +4847,27 @@ void panel_re_sort (WPanel * panel) { char *filename; - file_entry_t *fe; + const file_entry_t *fe; int i; if (panel == NULL) return; - fe = selection (panel); + fe = panel_current_entry (panel); filename = g_strndup (fe->fname->str, fe->fname->len); unselect_item (panel); dir_list_sort (&panel->dir, panel->sort_field->sort_routine, &panel->sort_info); - panel->selected = -1; + panel->current = -1; for (i = panel->dir.len; i != 0; i--) if (strcmp (panel->dir.list[i - 1].fname->str, filename) == 0) { - panel->selected = i - 1; + panel->current = i - 1; break; } g_free (filename); - panel->top_file = panel->selected - panel_items (panel) / 2; + panel->top_file = panel->current - panel_items (panel) / 2; select_item (panel); panel->dirty = TRUE; } @@ -4857,11 +4886,12 @@ panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order) if (sort_order->sort_routine == (GCompareFunc) unsorted) { char *current_file; + const GString *fname; - current_file = g_strndup (panel->dir.list[panel->selected].fname->str, - panel->dir.list[panel->selected].fname->len); + fname = panel_current_entry (panel)->fname; + current_file = g_strndup (fname->str, fname->len); panel_reload (panel); - try_to_select (panel, current_file); + panel_set_current_by_name (panel, current_file); g_free (current_file); } panel_re_sort (panel); @@ -4984,7 +5014,7 @@ remove_encoding_from_path (const vfs_path_t * vpath) * This routine reloads the directory in both panels. It tries to * select current_file in current_panel and other_file in other_panel. * If current_file == -1 then it automatically sets current_file and - * other_file to the currently selected files in the panels. + * other_file to the current files in the panels. * * If flags has the UP_ONLY_CURRENT bit toggled on, then it * will not reload the other panel. @@ -5203,7 +5233,7 @@ panel_panelize_cd (void) panel->is_panelized = TRUE; panel_panelize_absolutize_if_needed (panel); - try_to_select (panel, NULL); + panel_set_current_by_name (panel, NULL); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/panel.h b/src/filemanager/panel.h index dfd94e1b3..05f89757c 100644 --- a/src/filemanager/panel.h +++ b/src/filemanager/panel.h @@ -20,7 +20,6 @@ /*** typedefs(not structures) and defined constants **********************************************/ #define PANEL(x) ((WPanel *)(x)) -#define selection(p) (&(p->dir.list[p->selected])) #define DEFAULT_USER_FORMAT "half type name | size | perm" #define LIST_FORMATS 4 @@ -117,7 +116,7 @@ typedef struct uintmax_t total; /* Bytes in marked files */ int top_file; /* The file showed on the top of the panel */ - int selected; /* Index to the selected file */ + int current; /* Index to the currently selected file */ GSList *status_format; /* Mini status format */ gboolean user_mini_status; /* Is user_status_format used */ @@ -173,7 +172,7 @@ int set_panel_formats (WPanel * p); void panel_set_filter (WPanel * panel, const file_filter_t * filter); -void try_to_select (WPanel * panel, const char *name); +void panel_set_current_by_name (WPanel * panel, const char *name); void unmark_files (WPanel * panel); void select_item (WPanel * panel); @@ -275,4 +274,12 @@ panel_sized_new (const char *panel_name, int y, int x, int lines, int cols) /* --------------------------------------------------------------------------------------------- */ +static inline file_entry_t * +panel_current_entry (const WPanel * panel) +{ + return &(panel->dir.list[panel->current]); +} + +/* --------------------------------------------------------------------------------------------- */ + #endif /* MC__PANEL_H */ diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index 2e6b48a88..e90076cc9 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -427,7 +427,7 @@ do_external_panelize (const char *command) current_panel->is_panelized = TRUE; panel_panelize_absolutize_if_needed (current_panel); - try_to_select (current_panel, NULL); + panel_set_current_by_name (current_panel, NULL); panel_re_sort (current_panel); rotate_dash (FALSE); } diff --git a/src/usermenu.c b/src/usermenu.c index 444025b95..c2e5561b8 100644 --- a/src/usermenu.c +++ b/src/usermenu.c @@ -170,7 +170,9 @@ static gboolean test_type (WPanel * panel, char *arg) { int result = 0; /* False by default */ - mode_t st_mode = panel->dir.list[panel->selected].st.st_mode; + mode_t st_mode; + + st_mode = panel_current_entry (panel)->st.st_mode; for (; *arg != '\0'; arg++) { @@ -263,7 +265,7 @@ test_condition (const Widget * edit_widget, char *p, gboolean * condition) else #endif *condition = panel != NULL && - mc_search (arg, DEFAULT_CHARSET, panel->dir.list[panel->selected].fname->str, + mc_search (arg, DEFAULT_CHARSET, panel_current_entry (panel)->fname->str, search_type); break; case 'y': /* syntax pattern */ @@ -781,7 +783,7 @@ expand_format (const Widget * edit_widget, char c, gboolean do_quote) panel = other_panel; } - fname = panel->dir.list[panel->selected].fname->str; + fname = panel_current_entry (panel)->fname->str; } break; diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index c729c1a0c..147db4848 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -194,7 +194,7 @@ mcview_hook (void *v) mcview_done (view); mcview_init (view); - mcview_load (view, 0, panel->dir.list[panel->selected].fname->str, 0, 0, 0); + mcview_load (view, 0, panel_current_entry (panel)->fname->str, 0, 0, 0); mcview_display (view); } @@ -274,7 +274,7 @@ mcview_load_next_prev_init (WView * view) { /* get file list from current panel. Update it each time */ view->dir = ¤t_panel->dir; - view->dir_idx = ¤t_panel->selected; + view->dir_idx = ¤t_panel->current; } else if (view->dir == NULL) { diff --git a/tests/src/filemanager/exec_get_export_variables_ext.c b/tests/src/filemanager/exec_get_export_variables_ext.c index 38ac858e1..bc5dab0f3 100644 --- a/tests/src/filemanager/exec_get_export_variables_ext.c +++ b/tests/src/filemanager/exec_get_export_variables_ext.c @@ -76,7 +76,7 @@ START_TEST (sanitize_variables) GString *actual_string; const char *expected_string; - current_panel->selected = 0; + current_panel->current = 0; current_panel->dir.len = 3; current_panel->dir.list[0].fname = g_string_new ("selected file.txt"); current_panel->dir.list[1].fname = g_string_new ("tagged file1.txt");