Permalink
Browse files

Save side pane mode.

  • Loading branch information...
1 parent 5c2f12d commit ea5e99a665207057ed8940e573a99d44935ae682 @PCMan PCMan committed Jun 4, 2011
Showing with 75 additions and 21 deletions.
  1. +1 −0 data/pcmanfm.conf
  2. +25 −20 src/app-config.c
  3. +3 −0 src/app-config.h
  4. +11 −0 src/main-win-ui.c
  5. +35 −1 src/main-win.c
View
@@ -18,6 +18,7 @@ show_wm_menu=0
win_width=640
win_height=480
splitter_pos=150
+side_pane_mode=1
view_mode=0
show_hidden=0
sort_type=0
View
@@ -43,37 +43,39 @@ static void fm_app_config_class_init(FmAppConfigClass *klass)
static void fm_app_config_finalize(GObject *object)
{
- FmAppConfig *self;
+ FmAppConfig *cfg;
g_return_if_fail(object != NULL);
g_return_if_fail(IS_FM_APP_CONFIG(object));
- self = FM_APP_CONFIG(object);
- g_free(self->wallpaper);
+ cfg = FM_APP_CONFIG(object);
+ g_free(cfg->wallpaper);
G_OBJECT_CLASS(fm_app_config_parent_class)->finalize(object);
}
-static void fm_app_config_init(FmAppConfig *self)
+static void fm_app_config_init(FmAppConfig *cfg)
{
/* load libfm config file */
- fm_config_load_from_file((FmConfig*)self, NULL);
-
- self->mount_on_startup = TRUE;
- self->mount_removable = TRUE;
- self->autorun = TRUE;
-
- self->desktop_fg.red = self->desktop_fg.green = self->desktop_fg.blue = 65535;
- self->win_width = 640;
- self->win_height = 480;
- self->splitter_pos = 150;
- self->max_tab_chars = 32;
-
- self->view_mode = FM_FV_ICON_VIEW;
- self->show_hidden = FALSE;
- self->sort_type = GTK_SORT_ASCENDING;
- self->sort_by = COL_FILE_NAME;
+ fm_config_load_from_file((FmConfig*)cfg, NULL);
+
+ cfg->mount_on_startup = TRUE;
+ cfg->mount_removable = TRUE;
+ cfg->autorun = TRUE;
+
+ cfg->desktop_fg.red = cfg->desktop_fg.green = cfg->desktop_fg.blue = 65535;
+ cfg->win_width = 640;
+ cfg->win_height = 480;
+ cfg->splitter_pos = 150;
+ cfg->max_tab_chars = 32;
+
+ cfg->side_pane_mode = FM_SP_PLACES;
+
+ cfg->view_mode = FM_FV_ICON_VIEW;
+ cfg->show_hidden = FALSE;
+ cfg->sort_type = GTK_SORT_ASCENDING;
+ cfg->sort_by = COL_FILE_NAME;
}
@@ -136,6 +138,8 @@ void fm_app_config_load_from_key_file(FmAppConfig* cfg, GKeyFile* kf)
fm_key_file_get_int(kf, "ui", "splitter_pos", &cfg->splitter_pos);
+ fm_key_file_get_int(kf, "ui", "side_pane_mode", &cfg->side_pane_mode);
+
/* default values for folder views */
fm_key_file_get_int(kf, "ui", "view_mode", &cfg->view_mode);
if(!FM_FOLDER_VIEW_MODE_IS_VALID(cfg->view_mode))
@@ -251,6 +255,7 @@ void fm_app_config_save_profile(FmAppConfig* cfg, const char* name)
g_string_append_printf(buf, "win_width=%d\n", cfg->win_width);
g_string_append_printf(buf, "win_height=%d\n", cfg->win_height);
g_string_append_printf(buf, "splitter_pos=%d\n", cfg->splitter_pos);
+ g_string_append_printf(buf, "side_pane_mode=%d\n", cfg->side_pane_mode);
g_string_append_printf(buf, "view_mode=%d\n", cfg->view_mode);
g_string_append_printf(buf, "show_hidden=%d\n", cfg->show_hidden);
g_string_append_printf(buf, "sort_type=%d\n", cfg->sort_type);
View
@@ -24,6 +24,7 @@
#define __APP_CONFIG_H__
#include <libfm/fm.h>
+#include <libfm/fm-gtk.h>
#include <gtk/gtk.h>
G_BEGIN_DECLS
@@ -71,6 +72,8 @@ struct _FmAppConfig
int win_height;
int splitter_pos;
+ FmSidePaneMode side_pane_mode;
+
/* default values for folder views */
guint view_mode;
gboolean show_hidden;
View
@@ -70,6 +70,10 @@ static const char main_menu_xml[] =
"</menu>"
"<menu action='ViewMenu'>"
"<menuitem action='ShowHidden'/>"
+ "<menu action='SidePane'>"
+ "<menuitem action='Places' />"
+ "<menuitem action='DirTree' />"
+ "</menu>"
"<separator/>"
"<menuitem action='IconView'/>"
"<menuitem action='ThumbnailView'/>"
@@ -148,6 +152,7 @@ static GtkActionEntry main_win_actions[]=
{"InvSel", NULL, N_("Invert Selection"), NULL, NULL, G_CALLBACK(on_invert_select)},
{"Pref", GTK_STOCK_PREFERENCES, NULL, NULL, NULL, G_CALLBACK(on_preference)},
{"ViewMenu", NULL, N_("_View"), NULL, NULL, NULL},
+ {"SidePane", NULL, N_("Side Pane"), NULL, NULL, NULL},
{"Sort", NULL, N_("_Sort Files"), NULL, NULL, NULL},
{"HelpMenu", NULL, N_("_Help"), NULL, NULL, NULL},
{"About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(on_about)},
@@ -206,6 +211,12 @@ static GtkRadioActionEntry main_win_sort_by_actions[]=
{"ByType", NULL, N_("By File _Type"), NULL, NULL, COL_FILE_DESC}
};
+static GtkRadioActionEntry main_win_side_bar_mode_actions[]=
+{
+ {"Places", NULL, N_("Places"), NULL, NULL, FM_SP_PLACES},
+ {"DirTree", NULL, N_("Directory Tree"), NULL, NULL, FM_SP_DIR_TREE},
+ {"Remote", NULL, N_("Remote"), NULL, NULL, FM_SP_REMOTE},
+};
static const char folder_menu_xml[]=
"<popup>"
View
@@ -194,6 +194,7 @@ static void on_show_hidden(GtkToggleAction* act, FmMainWin* win);
static void on_change_mode(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win);
static void on_sort_by(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win);
static void on_sort_type(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win);
+static void on_side_pane_mode(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win);
static void on_about(GtkAction* act, FmMainWin* win);
static void on_open_folder_in_terminal(GtkAction* act, FmMainWin* win);
static void on_open_in_terminal(GtkAction* act, FmMainWin* win);
@@ -592,6 +593,14 @@ static void on_side_pane_chdir(FmSidePane* sp, guint button, FmPath* path, FmMai
fm_main_win_chdir(win, path);
}
+static void on_side_pane_mode_changed(FmSidePane* sp, FmMainWin* win)
+{
+ app_config->side_pane_mode = fm_side_pane_get_mode(sp);
+ fm_config_emit_changed(app_config, "side_pane_mode");
+
+
+}
+
static void fm_main_win_init(FmMainWin *win)
{
GtkWidget *vbox, *menubar, *toolitem, *btn;
@@ -617,10 +626,11 @@ static void fm_main_win_init(FmMainWin *win)
/* places left pane */
win->side_pane = fm_side_pane_new();
- fm_side_pane_set_mode(FM_SIDE_PANE(win->side_pane), FM_SP_PLACES);
+ fm_side_pane_set_mode(FM_SIDE_PANE(win->side_pane), app_config->side_pane_mode);
/* TODO: add a close button to side pane */
gtk_paned_add1(GTK_PANED(win->hpaned), win->side_pane);
g_signal_connect(win->side_pane, "chdir", G_CALLBACK(on_side_pane_chdir), win);
+ g_signal_connect(win->side_pane, "mode-changed", G_CALLBACK(on_side_pane_mode_changed), win);
/* notebook */
win->notebook = gtk_notebook_new();
@@ -647,6 +657,7 @@ static void fm_main_win_init(FmMainWin *win)
gtk_action_group_add_radio_actions(act_grp, main_win_mode_actions, G_N_ELEMENTS(main_win_mode_actions), app_config->view_mode, on_change_mode, win);
gtk_action_group_add_radio_actions(act_grp, main_win_sort_type_actions, G_N_ELEMENTS(main_win_sort_type_actions), app_config->sort_type, on_sort_type, win);
gtk_action_group_add_radio_actions(act_grp, main_win_sort_by_actions, G_N_ELEMENTS(main_win_sort_by_actions), app_config->sort_by, on_sort_by, win);
+ gtk_action_group_add_radio_actions(act_grp, main_win_side_bar_mode_actions, G_N_ELEMENTS(main_win_side_bar_mode_actions), app_config->side_pane_mode, on_side_pane_mode, win);
accel_grp = gtk_ui_manager_get_accel_group(ui);
gtk_window_add_accel_group(GTK_WINDOW(win), accel_grp);
@@ -869,6 +880,18 @@ void on_sort_type(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win)
}
}
+void on_side_pane_mode(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win)
+{
+ int val = gtk_radio_action_get_current_value(cur);
+ fm_side_pane_set_mode(FM_SIDE_PANE(win->side_pane), val);
+ if(val != app_config->side_pane_mode)
+ {
+ app_config->side_pane_mode = val;
+ pcmanfm_save_config(FALSE);
+ }
+}
+
+
void on_focus_in(GtkWidget* w, GdkEventFocus* evt)
{
if(all_wins->data != w)
@@ -1176,6 +1199,17 @@ gint fm_main_win_add_tab(FmMainWin* win, FmPath* path)
FmMainWin* fm_main_win_add_win(FmMainWin* win, FmPath* path)
{
+ /* Copy some settings of current window to AppConfig
+ * so the newly created window can use the same settings. */
+ if(win)
+ {
+ if(app_config->side_pane_mode != fm_side_pane_get_mode(FM_SIDE_PANE(win->side_pane)))
+ {
+ app_config->side_pane_mode = fm_side_pane_get_mode(FM_SIDE_PANE(win->side_pane));
+ fm_config_emit_changed(FM_CONFIG(app_config), "side_pane_mode");
+ }
+ }
+
win = fm_main_win_new();
gtk_window_set_default_size(GTK_WINDOW(win), app_config->win_width, app_config->win_height);
fm_main_win_chdir(win, path);

0 comments on commit ea5e99a

Please sign in to comment.