Ticket #38: right_switch_mode.diff

File right_switch_mode.diff, 4.4 KB (added by IMDagger, 15 years ago)
  • src/layout.c

    diff --git a/src/layout.c b/src/layout.c
    index e801a99..4ec5162 100644
    a b int output_start_y = 0; 
    117117static struct { 
    118118    int    type; 
    119119    Widget *widget; 
     120    char *last_saved_dir;  /* last view_list working directory */ 
    120121} panels [MAX_VIEWS]; 
    121122 
    122123/* These variables are used to avoid updating the information unless */ 
    void set_display_type (int num, int type) 
    955956     
    956957    switch (type){ 
    957958    case view_listing: 
    958         new_widget = (Widget *) panel_new (get_nth_panel_name (num)); 
     959        new_widget = restore_into_right_dir_panel(num, old_widget); 
    959960        break; 
    960961         
    961962    case view_info: 
    void set_display_type (int num, int type) 
    979980        view_load ((WView *) new_widget, 0, file_name, 0); 
    980981        break; 
    981982    } 
     983 
     984    if (type != view_listing) 
     985        /* Must save dir, for restoring after change type to */ 
     986        /* view_listing */ 
     987        save_panel_dir(num); 
     988 
    982989    panels [num].type = type; 
    983990    panels [num].widget = (Widget *) new_widget; 
    984991     
    int get_other_type (void) 
    11501157        return panels [0].type; 
    11511158} 
    11521159 
     1160/* Save current list_view widget directory into panel */ 
     1161void save_panel_dir(int index) 
     1162{ 
     1163    if (get_display_type(index) == view_listing) { 
     1164        WPanel *w = (WPanel *) get_panel_widget(index); 
     1165        char *widget_work_dir = w->cwd; 
     1166 
     1167        g_free(panels [index].last_saved_dir);  /* last path no needed */ 
     1168        panels [index].last_saved_dir = g_strdup(widget_work_dir); 
     1169    } 
     1170} 
     1171 
     1172/* Save current list_view widget directory into panel */ 
     1173Widget *restore_into_right_dir_panel(int index, Widget *from_widget) 
     1174{ 
     1175    Widget *new_widget = 0; 
     1176    const char *saved_dir = panels [index].last_saved_dir; 
     1177    int last_was_panel = (from_widget && 
     1178            get_display_type(index) != view_listing); 
     1179 
     1180    const char *p_name = get_nth_panel_name (index); 
     1181 
     1182    if (last_was_panel) { 
     1183        new_widget = (Widget *) panel_new_with_dir (p_name, saved_dir); 
     1184    } else 
     1185        new_widget = (Widget *) panel_new (p_name); 
     1186 
     1187    return new_widget; 
     1188} 
  • src/layout.h

    diff --git a/src/layout.h b/src/layout.h
    index 7a14a09..2521c2c 100644
    a b struct Widget *get_panel_widget (int index); 
    3030 
    3131struct WPanel *get_other_panel (void); 
    3232 
     33void save_panel_dir(int index); 
     34Widget *restore_into_right_dir_panel(int index, Widget *from_widget); 
     35 
    3336void set_hintbar (const char *str); 
    3437 
    3538/* Clear screen */ 
  • src/panel.h

    diff --git a/src/panel.h b/src/panel.h
    index bed9e3d..a2adb12 100644
    a b typedef struct WPanel { 
    8383} WPanel; 
    8484 
    8585WPanel *panel_new (const char *panel_name); 
     86WPanel *panel_new_with_dir (const char *panel_name, const char *dr); 
    8687void panel_clean_dir (WPanel *panel); 
    8788 
    8889extern int torben_fj_mode; 
  • src/screen.c

    diff --git a/src/screen.c b/src/screen.c
    index 6f6c403..6e6b62c 100644
    a b panel_format_modified (WPanel *panel) 
    10961096WPanel * 
    10971097panel_new (const char *panel_name) 
    10981098{ 
     1099    return panel_new_with_dir(panel_name, NULL); 
     1100} 
     1101 
     1102/* Panel creation for specified directory */ 
     1103/* The parameter specifies the name of the panel for setup retieving */ 
     1104/* and the path of working panel directory. If path is NULL then */ 
     1105/* panel will be created for current directory */ 
     1106WPanel * 
     1107panel_new_with_dir (const char *panel_name, const char *wpath) 
     1108{ 
    10991109    WPanel *panel; 
    11001110    char *section; 
    11011111    int i, err; 
     1112    char curdir[MAXPATHLEN]; 
    11021113 
    11031114    panel = g_new0 (WPanel, 1); 
    11041115 
    panel_new (const char *panel_name) 
    11081119    /* We do not want the cursor */ 
    11091120    widget_want_cursor (panel->widget, 0); 
    11101121 
    1111     mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2); 
     1122    if (wpath) { 
     1123        g_strlcpy(panel->cwd, wpath, sizeof (panel->cwd)); 
     1124        mc_get_current_wd (curdir, sizeof (curdir) - 2); 
     1125    } else 
     1126        mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2); 
     1127 
    11121128    strcpy (panel->lwd, "."); 
    11131129 
    11141130    panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL); 
    panel_new (const char *panel_name) 
    11551171        set_panel_formats (panel); 
    11561172    } 
    11571173 
     1174     
     1175    /* Because do_load_dir lists files in current directory */ 
     1176    if (wpath) 
     1177        mc_chdir(wpath); 
     1178 
    11581179    /* Load the default format */ 
    11591180    panel->count = 
    11601181        do_load_dir (panel->cwd, &panel->dir, panel->sort_type, 
    11611182                     panel->reverse, panel->case_sensitive, 
    11621183                     panel->exec_first, panel->filter); 
     1184 
     1185    /* Restore old right path */ 
     1186    if (wpath) 
     1187        mc_chdir(curdir); 
     1188 
    11631189    return panel; 
    11641190} 
    11651191