diff --git a/src/filemanager/filemanager.c b/src/filemanager/filemanager.c index ffa0f3197..68f1e0248 100644 --- a/src/filemanager/filemanager.c +++ b/src/filemanager/filemanager.c @@ -1262,7 +1262,7 @@ midnight_execute_cmd (Widget * sender, long command) break; #endif case CK_Panelize: - cd_panelize_cmd (); + panel_panelize_cd (); break; case CK_Help: help_cmd (); diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 03faa20c8..ed215f62c 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -1876,8 +1876,8 @@ do_find (WPanel * panel, const char *start_dir, ssize_t start_dir_len, const cha } panel->is_panelized = TRUE; - panelize_absolutize_if_needed (panel); - panelize_save_panel (panel); + panel_panelize_absolutize_if_needed (panel); + panel_panelize_save (panel); } kill_gui (); diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 04adca1f8..aabdc443e 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -5127,6 +5127,147 @@ panel_get_user_possible_fields (gsize * array_size) /* --------------------------------------------------------------------------------------------- */ +void +panel_panelize_cd (void) +{ + WPanel *panel; + int i; + dir_list *list; + gboolean panelized_same; + + if (!SELECTED_IS_PANEL) + create_panel (MENU_PANEL_IDX, view_listing); + + panel = PANEL (get_panel_widget (MENU_PANEL_IDX)); + + dir_list_clean (&panel->dir); + if (panelized_panel.root_vpath == NULL) + panel_panelize_change_root (current_panel->cwd_vpath); + + if (panelized_panel.list.len < 1) + dir_list_init (&panelized_panel.list); + else if (panelized_panel.list.len > panel->dir.size) + dir_list_grow (&panel->dir, panelized_panel.list.len - panel->dir.size); + + list = &panel->dir; + list->len = panelized_panel.list.len; + + panelized_same = vfs_path_equal (panelized_panel.root_vpath, panel->cwd_vpath); + + for (i = 0; i < panelized_panel.list.len; i++) + { + if (panelized_same || DIR_IS_DOTDOT (panelized_panel.list.list[i].fname->str)) + list->list[i].fname = mc_g_string_dup (panelized_panel.list.list[i].fname); + else + { + vfs_path_t *tmp_vpath; + + tmp_vpath = + vfs_path_append_new (panelized_panel.root_vpath, + panelized_panel.list.list[i].fname->str, (char *) NULL); + list->list[i].fname = g_string_new (vfs_path_as_str (tmp_vpath)); + vfs_path_free (tmp_vpath, TRUE); + } + list->list[i].f.link_to_dir = panelized_panel.list.list[i].f.link_to_dir; + list->list[i].f.stale_link = panelized_panel.list.list[i].f.stale_link; + list->list[i].f.dir_size_computed = panelized_panel.list.list[i].f.dir_size_computed; + list->list[i].f.marked = panelized_panel.list.list[i].f.marked; + list->list[i].st = panelized_panel.list.list[i].st; + list->list[i].sort_key = panelized_panel.list.list[i].sort_key; + list->list[i].second_sort_key = panelized_panel.list.list[i].second_sort_key; + } + + panel->is_panelized = TRUE; + panel_panelize_absolutize_if_needed (panel); + + try_to_select (panel, NULL); +} + +/* --------------------------------------------------------------------------------------------- */ + +/** + * Change root directory of panelized content. + * @param new_root - object with new path. + */ +void +panel_panelize_change_root (const vfs_path_t * new_root) +{ + vfs_path_free (panelized_panel.root_vpath, TRUE); + panelized_panel.root_vpath = vfs_path_clone (new_root); +} + +/* --------------------------------------------------------------------------------------------- */ + +/** + * Conditionally switches a panel's directory to "/" (root). + * + * If a panelized panel's listing contain absolute paths, this function + * sets the panel's directory to "/". Otherwise it does nothing. + * + * Rationale: + * + * This makes tokenized strings like "%d/%p" work. This also makes other + * places work where such naive concatenation is done in code (e.g., when + * pressing ctrl+shift+enter, for CK_PutCurrentFullSelected). + * + * When to call: + * + * You should always call this function after you populate the listing + * of a panelized panel. + */ +void +panel_panelize_absolutize_if_needed (WPanel * panel) +{ + const dir_list *const list = &panel->dir; + + /* Note: We don't support mixing of absolute and relative paths, which is + * why it's ok for us to check only the 1st entry. */ + if (list->len > 1 && g_path_is_absolute (list->list[1].fname->str)) + { + vfs_path_t *root; + + root = vfs_path_from_str (PATH_SEP_STR); + panel_set_cwd (panel, root); + if (panel == current_panel) + mc_chdir (root); + vfs_path_free (root, TRUE); + } +} + +/* --------------------------------------------------------------------------------------------- */ + +void +panel_panelize_save (WPanel * panel) +{ + int i; + dir_list *list = &panel->dir; + + panel_panelize_change_root (current_panel->cwd_vpath); + + if (panelized_panel.list.len > 0) + dir_list_clean (&panelized_panel.list); + if (panel->dir.len == 0) + return; + + if (panel->dir.len > panelized_panel.list.size) + dir_list_grow (&panelized_panel.list, panel->dir.len - panelized_panel.list.size); + panelized_panel.list.len = panel->dir.len; + + for (i = 0; i < panel->dir.len; i++) + { + panelized_panel.list.list[i].fname = mc_g_string_dup (list->list[i].fname); + panelized_panel.list.list[i].f.link_to_dir = list->list[i].f.link_to_dir; + panelized_panel.list.list[i].f.stale_link = list->list[i].f.stale_link; + panelized_panel.list.list[i].f.dir_size_computed = list->list[i].f.dir_size_computed; + panelized_panel.list.list[i].f.marked = list->list[i].f.marked; + panelized_panel.list.list[i].st = list->list[i].st; + panelized_panel.list.list[i].sort_key = list->list[i].sort_key; + panelized_panel.list.list[i].second_sort_key = list->list[i].second_sort_key; + } +} + +/* --------------------------------------------------------------------------------------------- */ + void panel_init (void) { diff --git a/src/filemanager/panel.h b/src/filemanager/panel.h index f7cbfa4b5..e989a8ff2 100644 --- a/src/filemanager/panel.h +++ b/src/filemanager/panel.h @@ -194,6 +194,11 @@ char **panel_get_user_possible_fields (gsize * array_size); void panel_set_cwd (WPanel * panel, const vfs_path_t * vpath); void panel_set_lwd (WPanel * panel, const vfs_path_t * vpath); +void panel_panelize_cd (void); +void panel_panelize_change_root (const vfs_path_t * new_root); +void panel_panelize_absolutize_if_needed (WPanel * panel); +void panel_panelize_save (WPanel * panel); + void panel_init (void); void panel_deinit (void); diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index acc6672d8..4b17c1fa1 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -31,29 +31,20 @@ #include -#include -#include -#include -#include -#include -#include - #include "lib/global.h" #include "lib/skin.h" +#include "lib/tty/tty.h" #include "lib/vfs/vfs.h" #include "lib/mcconfig.h" /* Load/save directories panelize */ #include "lib/strutil.h" -#include "lib/util.h" #include "lib/widget.h" -#include "src/setup.h" /* For profile_bname */ #include "src/history.h" -#include "dir.h" #include "filemanager.h" /* current_panel */ #include "layout.h" /* rotate_dash() */ -#include "panel.h" /* WPanel */ +#include "panel.h" /* WPanel, dir.h */ #include "panelize.h" @@ -322,7 +313,7 @@ do_external_panelize (char *command) /* Clear the counters and the directory list */ panel_clean_dir (current_panel); - panelize_change_root (current_panel->cwd_vpath); + panel_panelize_change_root (current_panel->cwd_vpath); dir_list_init (list); @@ -430,163 +421,17 @@ do_external_panelize (char *command) mc_pclose (external, NULL); current_panel->is_panelized = TRUE; - panelize_absolutize_if_needed (current_panel); + panel_panelize_absolutize_if_needed (current_panel); try_to_select (current_panel, NULL); panel_re_sort (current_panel); rotate_dash (FALSE); } -/* --------------------------------------------------------------------------------------------- */ - -static void -do_panelize_cd (WPanel * panel) -{ - int i; - dir_list *list; - gboolean panelized_same; - - dir_list_clean (&panel->dir); - if (panelized_panel.root_vpath == NULL) - panelize_change_root (current_panel->cwd_vpath); - - if (panelized_panel.list.len < 1) - dir_list_init (&panelized_panel.list); - else if (panelized_panel.list.len > panel->dir.size) - dir_list_grow (&panel->dir, panelized_panel.list.len - panel->dir.size); - - list = &panel->dir; - list->len = panelized_panel.list.len; - - panelized_same = vfs_path_equal (panelized_panel.root_vpath, panel->cwd_vpath); - - for (i = 0; i < panelized_panel.list.len; i++) - { - if (panelized_same || DIR_IS_DOTDOT (panelized_panel.list.list[i].fname->str)) - list->list[i].fname = mc_g_string_dup (panelized_panel.list.list[i].fname); - else - { - vfs_path_t *tmp_vpath; - - tmp_vpath = - vfs_path_append_new (panelized_panel.root_vpath, - panelized_panel.list.list[i].fname->str, (char *) NULL); - list->list[i].fname = g_string_new (vfs_path_as_str (tmp_vpath)); - vfs_path_free (tmp_vpath, TRUE); - } - list->list[i].f.link_to_dir = panelized_panel.list.list[i].f.link_to_dir; - list->list[i].f.stale_link = panelized_panel.list.list[i].f.stale_link; - list->list[i].f.dir_size_computed = panelized_panel.list.list[i].f.dir_size_computed; - list->list[i].f.marked = panelized_panel.list.list[i].f.marked; - list->list[i].st = panelized_panel.list.list[i].st; - list->list[i].sort_key = panelized_panel.list.list[i].sort_key; - list->list[i].second_sort_key = panelized_panel.list.list[i].second_sort_key; - } - - panel->is_panelized = TRUE; - panelize_absolutize_if_needed (panel); - - try_to_select (panel, NULL); -} - /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ -/** - * Change root directory of panelized content. - * @param new_root - object with new path. - */ -void -panelize_change_root (const vfs_path_t * new_root) -{ - vfs_path_free (panelized_panel.root_vpath, TRUE); - panelized_panel.root_vpath = vfs_path_clone (new_root); -} - -/* --------------------------------------------------------------------------------------------- */ - -void -panelize_save_panel (WPanel * panel) -{ - int i; - dir_list *list = &panel->dir; - - panelize_change_root (current_panel->cwd_vpath); - - if (panelized_panel.list.len > 0) - dir_list_clean (&panelized_panel.list); - if (panel->dir.len == 0) - return; - - if (panel->dir.len > panelized_panel.list.size) - dir_list_grow (&panelized_panel.list, panel->dir.len - panelized_panel.list.size); - panelized_panel.list.len = panel->dir.len; - - for (i = 0; i < panel->dir.len; i++) - { - panelized_panel.list.list[i].fname = mc_g_string_dup (list->list[i].fname); - panelized_panel.list.list[i].f.link_to_dir = list->list[i].f.link_to_dir; - panelized_panel.list.list[i].f.stale_link = list->list[i].f.stale_link; - panelized_panel.list.list[i].f.dir_size_computed = list->list[i].f.dir_size_computed; - panelized_panel.list.list[i].f.marked = list->list[i].f.marked; - panelized_panel.list.list[i].st = list->list[i].st; - panelized_panel.list.list[i].sort_key = list->list[i].sort_key; - panelized_panel.list.list[i].second_sort_key = list->list[i].second_sort_key; - } -} - -/* --------------------------------------------------------------------------------------------- */ - -/** - * Conditionally switches a panel's directory to "/" (root). - * - * If a panelized panel's listing contain absolute paths, this function - * sets the panel's directory to "/". Otherwise it does nothing. - * - * Rationale: - * - * This makes tokenized strings like "%d/%p" work. This also makes other - * places work where such naive concatenation is done in code (e.g., when - * pressing ctrl+shift+enter, for CK_PutCurrentFullSelected). - * - * When to call: - * - * You should always call this function after you populate the listing - * of a panelized panel. - */ -void -panelize_absolutize_if_needed (WPanel * panel) -{ - const dir_list *const list = &panel->dir; - - /* Note: We don't support mixing of absolute and relative paths, which is - * why it's ok for us to check only the 1st entry. */ - if (list->len > 1 && g_path_is_absolute (list->list[1].fname->str)) - { - vfs_path_t *root; - - root = vfs_path_from_str (PATH_SEP_STR); - panel_set_cwd (panel, root); - if (panel == current_panel) - mc_chdir (root); - vfs_path_free (root, TRUE); - } -} - -/* --------------------------------------------------------------------------------------------- */ - -void -cd_panelize_cmd (void) -{ - if (!SELECTED_IS_PANEL) - create_panel (MENU_PANEL_IDX, view_listing); - - do_panelize_cd (PANEL (get_panel_widget (MENU_PANEL_IDX))); -} - -/* --------------------------------------------------------------------------------------------- */ - void external_panelize (void) { diff --git a/src/filemanager/panelize.h b/src/filemanager/panelize.h index f230b2956..3feb7d6d4 100644 --- a/src/filemanager/panelize.h +++ b/src/filemanager/panelize.h @@ -19,10 +19,7 @@ void external_panelize (void); void load_panelize (void); void save_panelize (void); void done_panelize (void); -void cd_panelize_cmd (void); -void panelize_save_panel (WPanel * panel); -void panelize_change_root (const vfs_path_t * new_root); -void panelize_absolutize_if_needed (WPanel * panel); /*** inline functions ****************************************************************************/ + #endif /* MC__PANELIZE_H */