--- /home/yurik81/Desktop/src/gnome-commander/src/gnome-cmd-main-win.cc 2010-06-26 02:09:22.000000000 +0300 +++ /home/yurik81/Desktop/src/gnome-commander-my/new/gnome-cmd-main-win.cc 2010-06-26 01:10:29.303224000 +0300 @@ -701,6 +701,44 @@ * Gtk class implementation *******************************/ +static void gnome_cmd_main_win_save_tabs(FileSelectorID position) +{ + GnomeCmdFileSelector *fs = main_win->fs(position); + + gint tab_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(fs->notebook)); + gchar comb_path[50]; + gchar num_str[3]; + + // save tab count + sprintf(comb_path, "/options/tab_count_%s", position == LEFT ? "left" : "right"); + sprintf(num_str, "%u", tab_count); + gnome_cmd_data_set_string(comb_path, num_str); + + // save position of currently active tab + gint cur_tab_num = gtk_notebook_get_current_page(GTK_NOTEBOOK(fs->notebook)); + sprintf(comb_path, "/options/active_tab_num_%s", position == LEFT ? "left" : "right"); + sprintf(num_str, "%i", cur_tab_num); + gnome_cmd_data_set_string (comb_path, num_str); + gchar* dir_list[tab_count]; + + + for(uint i = 0; i < tab_count; i++) { + fs->list = fs->file_list(i); // switch to next tab + + // save tab path + sprintf(comb_path, "/options/start_dir_%s_%u", position == LEFT ? "left" : "right", i); + gnome_cmd_data_set_string (comb_path, gnome_cmd_file_get_path(GNOME_CMD_FILE (fs->get_directory()))); + + // save mount points + sprintf(comb_path, "/options/mount_point_%s_%u", position == LEFT ? "left" : "right", i); + const gchar *mount_point = ""; // empty string - mount point doesn't exist + if (GNOME_CMD_IS_CON_DEVICE(fs->get_connection())) + mount_point = gnome_cmd_con_device_get_alias(GNOME_CMD_CON_DEVICE(fs->get_connection())); + gnome_cmd_data_set_string(comb_path, mount_point); + + } +} + static void destroy (GtkObject *object) { GnomeCmdCon *con_home = get_home_con (); @@ -711,14 +749,10 @@ main_win->priv->key_snooper_id = 0; } - GnomeCmdDir *dir = main_win->fs(LEFT)->get_directory(); - if (con_home == gnome_cmd_dir_get_connection (dir)) - gnome_cmd_data_set_start_dir (LEFT, gnome_cmd_file_get_path (GNOME_CMD_FILE (dir))); - - dir = main_win->fs(RIGHT)->get_directory(); - if (con_home == gnome_cmd_dir_get_connection (dir)) - gnome_cmd_data_set_start_dir (RIGHT, gnome_cmd_file_get_path (GNOME_CMD_FILE (dir))); - + gnome_cmd_main_win_save_tabs(LEFT); + + gnome_cmd_main_win_save_tabs(RIGHT); + if (main_win->advrename_dlg) gtk_widget_destroy (*main_win->advrename_dlg); @@ -754,6 +788,56 @@ klass->switch_fs = gnome_cmd_main_win_real_switch_fs; } +static void gnome_cmd_main_win_restore_tabs(FileSelectorID position, gchar* default_dir = "/") +{ + GnomeCmdFileSelector *fs = main_win->fs(position); + + gchar comb_path[50]; + + // get tab count + sprintf(comb_path, "/options/tab_count_%s", position == LEFT ? "left" : "right"); + guint tab_count; + sscanf(gnome_cmd_data_get_string(comb_path, "1"), "%u", &tab_count); + + // create and initialize tabs + for(uint i = 0; i < tab_count; i++) + { + if (i != 0) { // first tab has been already created + fs->new_tab(); + } + + // get tab path + sprintf(comb_path, "/options/start_dir_%s_%u", position == LEFT ? "left" : "right", i); + gchar *dir = gnome_cmd_data_get_string(comb_path, default_dir); + + // get mount point if exist + sprintf(comb_path, "/options/mount_point_%s_%u", position == LEFT ? "left" : "right", i); + gchar *mount_point = gnome_cmd_data_get_string(comb_path, ""); + + GnomeCmdCon *con = get_home_con(); + + // restore mount point + if (g_strcmp0(mount_point, "") != 0) + { + con = gnome_cmd_con_list_find_alias (gnome_cmd_con_list_get(), mount_point); + } + + // restore directory + fs->update_connections(); + fs->set_connection(con); + fs->file_list(i)->con = con; // HACK: otherwise not possible to restore directories for mounted partitions + fs->goto_directory(dir); + + g_free(dir); + g_free(mount_point); + } + + // restore position of last active tab + sprintf(comb_path, "/options/active_tab_num_%s", position == LEFT ? "left" : "right"); + gint cur_tab_num; + sscanf(gnome_cmd_data_get_string(comb_path, "-1"), "%i", &cur_tab_num); // -1 == we have only one tab + fs->notebook->set_current_page(cur_tab_num); +} static void init (GnomeCmdMainWin *mw) { @@ -832,16 +916,11 @@ g_signal_connect (mw, "delete-event", G_CALLBACK (on_delete_event), mw); g_signal_connect (mw->priv->paned, "button-press-event", G_CALLBACK (on_slide_button_press), mw); g_signal_connect (mw, "window-state-event", G_CALLBACK (on_window_state_event), NULL); - - mw->fs(LEFT)->update_connections(); - mw->fs(RIGHT)->update_connections(); - - mw->fs(LEFT)->set_connection(get_home_con ()); - mw->fs(RIGHT)->set_connection(get_home_con ()); - - mw->fs(LEFT)->goto_directory(start_dir_left ? start_dir_left : gnome_cmd_data_get_start_dir (LEFT)); - mw->fs(RIGHT)->goto_directory(start_dir_right ? start_dir_right : gnome_cmd_data_get_start_dir (RIGHT)); - + + gnome_cmd_main_win_restore_tabs(LEFT); + + gnome_cmd_main_win_restore_tabs(RIGHT); + gtk_window_add_accel_group (*mw, mw->priv->accel_group); mw->focus_file_lists();