From 3dbc61124f1d14f86f0f616598bb55edd6527b7f Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 17 Nov 2011 16:27:26 +0300 Subject: [PATCH 1/5] Ticket #275: panelization fixes. "File listing" menu command should switch panel from panelization to the file listing mode. Signed-off-by: Andrew Borodin --- src/filemanager/cmd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index d9bd66591..df756f247 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -83,6 +83,7 @@ #include "file.h" /* file operation routines */ #include "find.h" /* find_file() */ #include "hotlist.h" /* hotlist_show() */ +#include "panel.h" /* WPanel */ #include "tree.h" /* tree_chdir() */ #include "midnight.h" /* change_panel() */ #include "usermenu.h" /* MC_GLOBAL_MENU */ @@ -581,6 +582,17 @@ switch_to_listing (int panel_index) { if (get_display_type (panel_index) != view_listing) set_display_type (panel_index, view_listing); + else + { + WPanel *p; + + p = (WPanel *) get_panel_widget (panel_index); + if (p->is_panelized) + { + p->is_panelized = 0; + panel_reload (p); + } + } } /* --------------------------------------------------------------------------------------------- */ From 44b827bb9f4d6a4248f79436c59597fe8345241e Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 17 Nov 2011 16:30:23 +0300 Subject: [PATCH 2/5] Fixes segfault after switch panel mode ...from non-listing one (info, tree, quick view) to panelization. Signed-off-by: Andrew Borodin --- src/filemanager/panelize.c | 6 ++++-- src/filemanager/panelize.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index 48ecc2a00..df8f3b1f9 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -52,6 +52,7 @@ #include "dir.h" #include "midnight.h" /* current_panel */ +#include "panel.h" /* WPanel */ #include "panelize.h" @@ -484,9 +485,10 @@ panelize_save_panel (struct WPanel *panel) void cd_panelize_cmd (void) { - WPanel *panel = MENU_PANEL_IDX == 0 ? left_panel : right_panel; + if (get_display_type (MENU_PANEL_IDX) != view_listing) + set_display_type (MENU_PANEL_IDX, view_listing); - do_panelize_cd (panel); + do_panelize_cd ((struct WPanel *) get_panel_widget (MENU_PANEL_IDX)); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/panelize.h b/src/filemanager/panelize.h index e7f47dada..13addb1b4 100644 --- a/src/filemanager/panelize.h +++ b/src/filemanager/panelize.h @@ -11,6 +11,8 @@ /*** structures declarations (and typedefs of structures)*****************************************/ +struct WPanel; + /*** global variables defined in .c file *********************************************************/ /*** declarations of public functions ************************************************************/ From 068b5b49489e4b0329d624d748a4a06b202f0e55 Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Thu, 17 Nov 2011 17:12:37 +0400 Subject: [PATCH 3/5] Changed type of the WPanel::is_panelized member from int to gboolean. Signed-off-by: Ilia Maslakov --- src/filemanager/cmd.c | 2 +- src/filemanager/find.c | 2 +- src/filemanager/panel.c | 6 +++--- src/filemanager/panel.h | 2 +- src/filemanager/panelize.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index df756f247..c2eb6c127 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -589,7 +589,7 @@ switch_to_listing (int panel_index) p = (WPanel *) get_panel_widget (panel_index); if (p->is_panelized) { - p->is_panelized = 0; + p->is_panelized = FALSE; panel_reload (p); } } diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 60ffca917..007a7d8ff 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -1681,7 +1681,7 @@ do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs, if (next_free) { current_panel->count = next_free; - current_panel->is_panelized = 1; + current_panel->is_panelized = TRUE; /* absolute path */ if (start_dir_len < 0) diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 9e9086f58..ecb82748c 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -3403,7 +3403,7 @@ update_one_panel_widget (WPanel * panel, panel_update_flags_t flags, const char if ((flags & UP_RELOAD) != 0) { - panel->is_panelized = 0; + panel->is_panelized = FALSE; mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0); memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat)); } @@ -3637,7 +3637,7 @@ panel_clean_dir (WPanel * panel) panel->dirs_marked = 0; panel->total = 0; panel->searching = FALSE; - panel->is_panelized = 0; + panel->is_panelized = FALSE; panel->dirty = 1; clean_dir (&panel->dir, count); @@ -3703,7 +3703,7 @@ panel_new_with_dir (const char *panel_name, const char *wpath) panel->dirty = 1; panel->searching = FALSE; panel->dirs_marked = 0; - panel->is_panelized = 0; + panel->is_panelized = FALSE; panel->format = 0; panel->status_format = 0; panel->format_modified = 1; diff --git a/src/filemanager/panel.h b/src/filemanager/panel.h index 7e8e3c9c7..5f43d03d8 100644 --- a/src/filemanager/panel.h +++ b/src/filemanager/panel.h @@ -108,7 +108,7 @@ typedef struct WPanel int top_file; /* The file showed on the top of the panel */ int selected; /* Index to the selected file */ int split; /* Split panel to allow two columns */ - int is_panelized; /* Flag: special filelisting, can't reload */ + gboolean is_panelized; /* Flag: special filelisting, can't reload */ panel_display_t frame_size; /* half or full frame */ char *filter; /* File name filter */ panel_sort_info_t sort_info; /* Sort descriptor */ diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index df8f3b1f9..bbfd8a014 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -380,7 +380,7 @@ do_external_panelize (char *command) rotate_dash (); } - current_panel->is_panelized = 1; + current_panel->is_panelized = TRUE; if (next_free) { current_panel->count = next_free; @@ -425,7 +425,7 @@ do_panelize_cd (struct WPanel *panel) list->size = panelized_panel.count; } panel->count = panelized_panel.count; - panel->is_panelized = 1; + panel->is_panelized = TRUE; for (i = 0; i < panelized_panel.count; i++) { From 7f6655e865528f14fab220d6db622476425c8009 Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Thu, 17 Nov 2011 20:31:22 +0400 Subject: [PATCH 4/5] Show the relative filename path in the panel ...if current panel->cwd is equal to the panelization root. Signed-off-by: Ilia Maslakov --- src/filemanager/panelize.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index bbfd8a014..e60a48b46 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -409,6 +409,7 @@ do_panelize_cd (struct WPanel *panel) { int i; dir_list *list = &panel->dir; + gboolean panelized_same; clean_dir (list, panel->count); if (panelized_panel.root[0] == '\0') @@ -427,10 +428,25 @@ do_panelize_cd (struct WPanel *panel) panel->count = panelized_panel.count; panel->is_panelized = TRUE; + panelized_same = (strcmp (panelized_panel.root, panel->cwd) == 0); + for (i = 0; i < panelized_panel.count; i++) { - list->list[i].fnamelen = panelized_panel.list.list[i].fnamelen; - list->list[i].fname = g_strdup (panelized_panel.list.list[i].fname); + if (panelized_same + || (panelized_panel.list.list[i].fname[0] == '.' + && panelized_panel.list.list[i].fname[1] == '.' + && panelized_panel.list.list[i].fname[2] == '\0')) + { + list->list[i].fname = g_stndup (panelized_panel.list.list[i].fname); + list->list[i].fnamelen = panelized_panel.list.list[i].fnamelen; + } + else + { + list->list[i].fname = mc_build_filename (panelized_panel.root, + panelized_panel.list.list[i].fname, + (char *) NULL); + list->list[i].fnamelen = strlen (list->list[i].fname); + } 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; From 0fcd9fdfa30d7bdef7f9cfdcfeef0d42ddcce4e1 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 18 Nov 2011 10:13:45 +0300 Subject: [PATCH 5/5] Minor optimization in file list creation. Signed-off-by: Andrew Borodin --- src/filemanager/dir.c | 6 +++--- src/filemanager/find.c | 2 +- src/filemanager/panelize.c | 11 ++++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/filemanager/dir.c b/src/filemanager/dir.c index b50f13c84..477025b38 100644 --- a/src/filemanager/dir.c +++ b/src/filemanager/dir.c @@ -458,7 +458,7 @@ set_zero_dir (dir_list * list) memset (&(list->list)[0], 0, sizeof (file_entry)); list->list[0].fnamelen = 2; - list->list[0].fname = g_strdup (".."); + list->list[0].fname = g_strndup ("..", list->list[0].fnamelen); list->list[0].f.link_to_dir = 0; list->list[0].f.stale_link = 0; list->list[0].f.dir_size_computed = 0; @@ -558,7 +558,7 @@ do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean lc_rever return next_free; } list->list[next_free].fnamelen = NLENGTH (dp); - list->list[next_free].fname = g_strdup (dp->d_name); + list->list[next_free].fname = g_strndup (dp->d_name, list->list[next_free].fnamelen); list->list[next_free].f.marked = 0; list->list[next_free].f.link_to_dir = link_to_dir; list->list[next_free].f.stale_link = stale_link; @@ -693,7 +693,7 @@ do_reload_dir (const char *path, dir_list * list, sortfn * sort, int count, } list->list[next_free].fnamelen = NLENGTH (dp); - list->list[next_free].fname = g_strdup (dp->d_name); + list->list[next_free].fname = g_strndup (dp->d_name, list->list[next_free].fnamelen); list->list[next_free].f.link_to_dir = link_to_dir; list->list[next_free].f.stale_link = stale_link; list->list[next_free].f.dir_size_computed = 0; diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 007a7d8ff..b56210a86 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -1664,7 +1664,7 @@ do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs, if (next_free == 0) /* first turn i.e clean old list */ panel_clean_dir (current_panel); list->list[next_free].fnamelen = strlen (p); - list->list[next_free].fname = g_strdup (p); + list->list[next_free].fname = g_strndup (p, list->list[next_free].fnamelen); list->list[next_free].f.marked = 0; list->list[next_free].f.link_to_dir = link_to_dir; list->list[next_free].f.stale_link = stale_link; diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index e60a48b46..49d4bd763 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -367,7 +367,7 @@ do_external_panelize (char *command) if (status == -1) break; list->list[next_free].fnamelen = strlen (name); - list->list[next_free].fname = g_strdup (name); + list->list[next_free].fname = g_strndup (name, list->list[next_free].fnamelen); file_mark (current_panel, next_free, 0); list->list[next_free].f.link_to_dir = link_to_dir; list->list[next_free].f.stale_link = stale_link; @@ -422,7 +422,7 @@ do_panelize_cd (struct WPanel *panel) } else if (panelized_panel.count >= list->size) { - list->list = g_try_realloc (list->list, sizeof (file_entry) * (panelized_panel.count)); + list->list = g_try_realloc (list->list, sizeof (file_entry) * panelized_panel.count); list->size = panelized_panel.count; } panel->count = panelized_panel.count; @@ -437,8 +437,9 @@ do_panelize_cd (struct WPanel *panel) && panelized_panel.list.list[i].fname[1] == '.' && panelized_panel.list.list[i].fname[2] == '\0')) { - list->list[i].fname = g_stndup (panelized_panel.list.list[i].fname); list->list[i].fnamelen = panelized_panel.list.list[i].fnamelen; + list->list[i].fname = g_strndup (panelized_panel.list.list[i].fname, + panelized_panel.list.list[i].fnamelen); } else { @@ -479,13 +480,13 @@ panelize_save_panel (struct WPanel *panel) if (panel->count >= panelized_panel.list.size) { panelized_panel.list.list = g_try_realloc (panelized_panel.list.list, - sizeof (file_entry) * panel->count); + sizeof (file_entry) * panel->count); panelized_panel.list.size = panel->count; } for (i = 0; i < panel->count; i++) { panelized_panel.list.list[i].fnamelen = list->list[i].fnamelen; - panelized_panel.list.list[i].fname = g_strdup (list->list[i].fname); + panelized_panel.list.list[i].fname = g_strndup (list->list[i].fname, list->list[i].fnamelen); 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;