From 6a4124c8ea87ed04a47ec6f1e5237db914620303 Mon Sep 17 00:00:00 2001 From: IMDagger Date: Sun, 4 Oct 2009 20:09:06 +0400 Subject: [PATCH] Ticket #38: fixed saving other_dir path into panels.ini. Save Info, Tree and etc. panels state, and restore after. Signed-off-by: Andrew Borodin --- src/layout.c | 35 ++++++++++++++++++++++++++++++++--- src/layout.h | 5 +++-- src/setup.c | 10 +++++----- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/layout.c b/src/layout.c index aa3f37eca..e61e4ea13 100644 --- a/src/layout.c +++ b/src/layout.c @@ -913,6 +913,14 @@ set_display_type (int num, int type) } } + /* Restoring saved path from panels.ini for nonlist panel */ + /* when it's first creation (for example view_info) */ + if (old_widget == NULL && type != view_listing) { + char panel_dir[MC_MAXPATHLEN]; + mc_get_current_wd (panel_dir, sizeof (panel_dir)); + panels[num].last_saved_dir = g_strdup (panel_dir); + } + switch (type){ case view_listing: new_widget = restore_into_right_dir_panel(num, old_widget); @@ -1133,7 +1141,8 @@ save_panel_dir (int index) } /* Save current list_view widget directory into panel */ -Widget *restore_into_right_dir_panel(int index, Widget *from_widget) +Widget * +restore_into_right_dir_panel (int index, Widget *from_widget) { Widget *new_widget = 0; const char *saved_dir = panels [index].last_saved_dir; @@ -1141,10 +1150,30 @@ Widget *restore_into_right_dir_panel(int index, Widget *from_widget) get_display_type(index) != view_listing); const char *p_name = get_nth_panel_name (index); - if (last_was_panel) { + if (last_was_panel) new_widget = (Widget *) panel_new_with_dir (p_name, saved_dir); - } else + else new_widget = (Widget *) panel_new (p_name); return new_widget; } + +/* Return working dir, if it's view_listing - cwd, + but for other types - last_saved_dir */ +const char * +get_panel_dir_for (const WPanel *widget) +{ + int i; + + for (i = 0; i < MAX_VIEWS; i++) + if ((WPanel *) get_panel_widget (i) == widget) + break; + + if (i >= MAX_VIEWS) + return "."; + + if (get_display_type (i) == view_listing) + return ((WPanel *) get_panel_widget (i))->cwd; + + return panels[i].last_saved_dir; +} diff --git a/src/layout.h b/src/layout.h index 6a68055f5..746bec8b5 100644 --- a/src/layout.h +++ b/src/layout.h @@ -27,8 +27,9 @@ struct Widget *get_panel_widget (int index); struct WPanel *get_other_panel (void); -void save_panel_dir(int index); -Widget *restore_into_right_dir_panel(int index, Widget *from_widget); +void save_panel_dir (int index); +Widget *restore_into_right_dir_panel (int index, Widget *from_widget); +const char *get_panel_dir_for (const WPanel *widget); void set_hintbar (const char *str); diff --git a/src/setup.c b/src/setup.c index 2f1d8e04a..8571b7632 100644 --- a/src/setup.c +++ b/src/setup.c @@ -352,12 +352,12 @@ save_panel_types (void) if (type == view_listing) panel_save_setup (right_panel, right_panel->panel_name); - mc_config_set_string(mc_panels_config, "Dirs" , "other_dir", - get_other_type () == view_listing - ? other_panel->cwd : "."); + mc_config_set_string (mc_panels_config, "Dirs" , "other_dir", + get_panel_dir_for (other_panel)); + if (current_panel != NULL) - mc_config_set_string(mc_panels_config, "Dirs" , "current_is_left", - get_current_index () == 0 ? "1" : "0"); + mc_config_set_string (mc_panels_config, "Dirs" , "current_is_left", + get_current_index () == 0 ? "1" : "0"); if (mc_panels_config->ini_path == NULL) mc_panels_config->ini_path = g_strdup(panels_profile_name);