81
87
static void on_go_computer(GtkAction* act, FmMainWin* win);
82
88
static void on_go_network(GtkAction* act, FmMainWin* win);
83
89
static void on_go_apps(GtkAction* act, FmMainWin* win);
90
static void on_go_connect(GtkAction* act, FmMainWin* win);
84
91
static void on_reload(GtkAction* act, FmMainWin* win);
92
#if FM_CHECK_VERSION(1, 0, 2)
93
static void on_filter(GtkAction* act, FmMainWin* win);
85
95
static void on_show_hidden(GtkToggleAction* act, FmMainWin* win);
96
#if FM_CHECK_VERSION(1, 2, 0)
97
static void on_mingle_dirs(GtkToggleAction* act, FmMainWin* win);
99
#if FM_CHECK_VERSION(1, 0, 2)
100
static void on_sort_ignore_case(GtkToggleAction* act, FmMainWin* win);
102
static void on_save_per_folder(GtkToggleAction* act, FmMainWin* win);
86
103
static void on_show_side_pane(GtkToggleAction* act, FmMainWin* win);
104
static void on_dual_pane(GtkToggleAction* act, FmMainWin* win);
105
static void on_show_toolbar(GtkToggleAction *action, FmMainWin *win);
106
static void on_toolbar_new_win(GtkToggleAction *act, FmMainWin *win);
107
static void on_toolbar_new_tab(GtkToggleAction *act, FmMainWin *win);
108
static void on_toolbar_nav(GtkToggleAction *act, FmMainWin *win);
109
static void on_toolbar_home(GtkToggleAction *act, FmMainWin *win);
110
static void on_show_status(GtkToggleAction *action, FmMainWin *win);
87
111
static void on_change_mode(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win);
88
112
static void on_sort_by(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win);
89
113
static void on_sort_type(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win);
91
115
static void on_about(GtkAction* act, FmMainWin* win);
92
116
static void on_key_nav_list(GtkAction* act, FmMainWin* win);
93
117
static void on_open_in_terminal(GtkAction* act, FmMainWin* win);
94
static void on_open_as_root(GtkAction* act, FmMainWin* win);
118
/*static void on_open_as_root(GtkAction* act, FmMainWin* win);*/
95
119
#if FM_CHECK_VERSION(1, 0, 2)
96
120
static void on_search(GtkAction* act, FmMainWin* win);
122
#if FM_CHECK_VERSION(1, 2, 0)
123
static void on_launch(GtkAction* act, FmMainWin* win);
98
125
static void on_fullscreen(GtkToggleAction* act, FmMainWin* win);
100
127
static void on_location(GtkAction* act, FmMainWin* win);
129
static void on_size_increment(GtkAction *act, FmMainWin *win);
130
static void on_size_decrement(GtkAction *act, FmMainWin *win);
131
static void on_size_default(GtkAction *act, FmMainWin *win);
102
133
static void on_notebook_switch_page(GtkNotebook* nb, gpointer* page, guint num, FmMainWin* win);
103
134
static void on_notebook_page_added(GtkNotebook* nb, GtkWidget* page, guint num, FmMainWin* win);
104
135
static void on_notebook_page_removed(GtkNotebook* nb, GtkWidget* page, guint num, FmMainWin* win);
106
static void on_folder_view_clicked(FmFolderView* fv, FmFolderViewClickType type, FmFileInfo* fi, FmMainWin* win);
108
137
#include "main-win-ui.c" /* ui xml definitions and actions */
110
139
static GSList* all_wins = NULL;
111
static GtkDialog* about_dlg = NULL;
140
static GtkAboutDialog* about_dlg = NULL;
112
141
static GtkWidget* key_nav_list_dlg = NULL;
143
static GQuark main_win_qdata;
114
145
static void fm_main_win_class_init(FmMainWinClass *klass)
116
147
GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
166
211
* priority than GtkEntry's idle function (They use G_PRIORITY_HIGH).
168
213
if(win->idle_handler == 0)
169
win->idle_handler = g_idle_add_full(G_PRIORITY_LOW, idle_focus_view, win, NULL);
214
win->idle_handler = gdk_threads_add_idle_full(G_PRIORITY_LOW, idle_focus_view, win, NULL);
217
static void on_path_bar_chdir(FmPathBar *bar, FmPath *path, FmMainWin *win)
219
fm_main_win_chdir(win, path);
222
static void on_path_bar_mode(GtkRadioAction *act, GtkRadioAction *cur, FmMainWin *win)
224
int mode = gtk_radio_action_get_current_value(cur);
226
if (app_config->pathbar_mode_buttons != mode)
228
app_config->pathbar_mode_buttons = mode;
229
pcmanfm_save_config(FALSE);
231
gtk_widget_set_visible(GTK_WIDGET(win->location), mode == 0);
232
gtk_widget_set_visible(gtk_ui_manager_get_widget(win->ui, "/toolbar/Go"), mode == 0);
233
gtk_widget_set_visible(GTK_WIDGET(win->path_bar), mode);
172
236
static void update_sort_menu(FmMainWin* win)
175
239
FmFolderView* fv = win->folder_view;
176
FmFolderModelViewCol by = fm_folder_view_get_sort_by(fv);
177
241
#if FM_CHECK_VERSION(1, 0, 2)
247
win->in_update = TRUE;
248
/* we have to update this any time */
249
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/SavePerFolder");
250
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), win->current_page->own_config);
251
win->in_update = FALSE;
178
252
if(fv == NULL || fm_folder_view_get_model(fv) == NULL)
179
253
/* since 1.0.2 libfm have sorting only in FmFolderModel therefore
180
254
if there is no model then we cannot get last sorting from it */
256
if(!fm_folder_model_get_sort(fm_folder_view_get_model(fv), &by, &mode))
258
type = FM_SORT_IS_ASCENDING(mode) ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
259
/* we don't handle extended modes in radio actions so do that here */
260
if(mode != win->current_page->sort_type)
262
win->current_page->sort_type = mode;
263
if (win->current_page->own_config)
265
fm_app_config_save_config_for_path(fm_folder_view_get_cwd(fv),
267
win->current_page->show_hidden,
272
app_config->sort_type = mode;
273
pcmanfm_save_config(FALSE);
277
FmFolderModelViewCol by = fm_folder_view_get_sort_by(fv);
279
type = fm_folder_view_get_sort_type(fv);
281
win->in_update = TRUE;
183
282
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Sort/Asc");
184
gtk_radio_action_set_current_value(GTK_RADIO_ACTION(act), fm_folder_view_get_sort_type(fv));
283
gtk_radio_action_set_current_value(GTK_RADIO_ACTION(act), type);
185
284
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Sort/ByName");
186
285
#if FM_CHECK_VERSION(1, 0, 2)
187
286
if(by == FM_FOLDER_MODEL_COL_DEFAULT)
188
287
by = FM_FOLDER_MODEL_COL_NAME;
190
289
gtk_radio_action_set_current_value(GTK_RADIO_ACTION(act), by);
290
#if FM_CHECK_VERSION(1, 0, 2)
291
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Sort/SortIgnoreCase");
292
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act),
293
(mode & FM_SORT_CASE_SENSITIVE) == 0);
295
#if FM_CHECK_VERSION(1, 2, 0)
296
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Sort/MingleDirs");
297
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act),
298
(mode & FM_SORT_NO_FOLDER_FIRST) != 0);
300
win->in_update = FALSE;
193
303
static void update_view_menu(FmMainWin* win)
196
306
FmFolderView* fv = win->folder_view;
197
308
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/ShowHidden");
311
win->in_update = TRUE;
198
312
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), fm_folder_view_get_show_hidden(fv));
199
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/IconView");
200
gtk_radio_action_set_current_value(GTK_RADIO_ACTION(act),
313
gtk_radio_action_set_current_value(win->first_view_mode,
201
314
fm_standard_view_get_mode(FM_STANDARD_VIEW(fv)));
315
win->in_update = FALSE;
318
static void update_file_menu(FmMainWin* win, FmPath *path)
321
/* FmFolderView *fv = win->folder_view; */
323
act = gtk_ui_manager_get_action(win->ui, "/menubar/ToolMenu/Term");
324
gtk_action_set_sensitive(act, path && fm_path_is_native(path));
325
#if FM_CHECK_VERSION(1, 2, 0)
326
act = gtk_ui_manager_get_action(win->ui, "/menubar/ToolMenu/Launch");
327
gtk_action_set_sensitive(act, path && fm_path_is_native(path));
329
act = gtk_ui_manager_get_action(win->ui, "/menubar/GoMenu/Up");
330
gtk_action_set_sensitive(act, path && fm_path_get_parent(path));
204
333
static void on_folder_view_sort_changed(FmFolderView* fv, FmMainWin* win)
216
345
if(fv != win->folder_view)
347
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/Open");
348
gtk_action_set_sensitive(act, has_selected);
218
349
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/Cut");
219
350
gtk_action_set_sensitive(act, has_selected);
220
351
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/Copy");
221
352
gtk_action_set_sensitive(act, has_selected);
353
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/ToTrash");
354
gtk_action_set_sensitive(act, has_selected);
222
355
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/Del");
223
356
gtk_action_set_sensitive(act, has_selected);
357
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/CopyPath");
358
gtk_action_set_sensitive(act, has_selected);
224
359
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/Rename");
360
gtk_action_set_sensitive(act, n_sel == 1); /* can rename only single file */
361
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/Link");
225
362
gtk_action_set_sensitive(act, has_selected);
226
363
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/CopyTo");
227
364
gtk_action_set_sensitive(act, has_selected);
228
365
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/MoveTo");
229
366
gtk_action_set_sensitive(act, has_selected);
367
act = gtk_ui_manager_get_action(win->ui, "/menubar/EditMenu/FileProp");
368
gtk_action_set_sensitive(act, has_selected);
232
371
static gboolean on_view_key_press_event(FmFolderView* fv, GdkEventKey* evt, FmMainWin* win)
337
495
gtk_container_foreach(GTK_CONTAINER(menu), disconnect_history_item, win);
498
#if FM_CHECK_VERSION(1, 2, 0)
499
static void on_show_history_menu(FmMenuToolItem* btn, FmMainWin* win)
340
501
static void on_show_history_menu(GtkMenuToolButton* btn, FmMainWin* win)
504
#if FM_CHECK_VERSION(1, 2, 0)
505
GtkMenuShell* menu = (GtkMenuShell*)fm_menu_tool_item_get_menu(btn);
342
507
GtkMenuShell* menu = (GtkMenuShell*)gtk_menu_tool_button_get_menu(btn);
509
#if FM_CHECK_VERSION(1, 0, 2)
510
guint i, cur = fm_nav_history_get_cur_index(win->nav_history);
344
514
const GList* cur = fm_nav_history_get_cur_link(win->nav_history);
346
517
/* delete old items */
347
518
gtk_container_foreach(GTK_CONTAINER(menu), (GtkCallback)gtk_widget_destroy, NULL);
520
#if FM_CHECK_VERSION(1, 0, 2)
521
for (i = 0; (path = fm_nav_history_get_nth_path(win->nav_history, i)); i++)
349
524
for(l = fm_nav_history_list(win->nav_history); l; l=l->next)
351
526
const FmNavHistoryItem* item = (FmNavHistoryItem*)l->data;
352
527
FmPath* path = item->path;
353
529
char* str = fm_path_display_name(path, TRUE);
531
#if FM_CHECK_VERSION(1, 0, 2)
357
537
mi = gtk_check_menu_item_new_with_label(str);
358
538
gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(mi), TRUE);
624
static void on_always_show_tabs_changed(FmAppConfig *cfg, FmMainWin *win)
626
/* it will affect only the case when window has exactly 1 tab,
627
all other cases will be handled when tab is added or removed */
628
if (gtk_notebook_get_n_pages(win->notebook) == 1)
629
gtk_notebook_set_show_tabs(win->notebook, app_config->always_show_tabs);
632
static void on_toolsbar_changed(FmAppConfig *cfg, FmMainWin *win)
641
win->in_update = TRUE; /* avoid recursion */
642
active = cfg->tb.visible;
643
gtk_widget_set_visible(GTK_WIDGET(win->toolbar), active);
644
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Toolbar/ToolbarNewWin");
645
gtk_action_set_sensitive(act, active);
646
if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(act)) != app_config->tb.new_win)
647
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->tb.new_win);
648
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Toolbar/ToolbarNewTab");
649
gtk_action_set_sensitive(act, active);
650
if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(act)) != app_config->tb.new_tab)
651
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->tb.new_tab);
652
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Toolbar/ToolbarNav");
653
gtk_action_set_sensitive(act, active);
654
if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(act)) != app_config->tb.nav)
655
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->tb.nav);
656
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Toolbar/ToolbarHome");
657
gtk_action_set_sensitive(act, active);
658
if (gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(act)) != app_config->tb.home)
659
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->tb.home);
660
if (active) /* it it's hidden no reason to update its children */
662
toolitem = gtk_ui_manager_get_widget(win->ui, "/toolbar/New");
663
gtk_widget_set_visible(toolitem, cfg->tb.new_win);
664
toolitem = gtk_ui_manager_get_widget(win->ui, "/toolbar/NewTab");
665
gtk_widget_set_visible(toolitem, cfg->tb.new_tab);
666
active = cfg->tb.nav;
667
toolitem = gtk_ui_manager_get_widget(win->ui, "/toolbar/Next");
668
gtk_widget_set_visible(toolitem, active);
669
n = gtk_toolbar_get_item_index(win->toolbar, GTK_TOOL_ITEM(toolitem));
670
toolitem = GTK_WIDGET(gtk_toolbar_get_nth_item(win->toolbar, n-1));
671
gtk_widget_set_visible(toolitem, active); /* Hist */
672
#if FM_CHECK_VERSION(1, 2, 0)
673
toolitem = GTK_WIDGET(gtk_toolbar_get_nth_item(win->toolbar, n-2));
674
gtk_widget_set_visible(toolitem, active); /* Prev */
676
toolitem = GTK_WIDGET(gtk_toolbar_get_nth_item(win->toolbar, n+1));
677
gtk_widget_set_visible(toolitem, active); /* Up */
678
toolitem = gtk_ui_manager_get_widget(win->ui, "/toolbar/Home");
679
gtk_widget_set_visible(toolitem, cfg->tb.home);
681
win->in_update = FALSE;
684
static void on_statusbar_changed(FmAppConfig *cfg, FmMainWin *win)
686
gtk_widget_set_visible(GTK_WIDGET(win->statusbar), cfg->show_statusbar);
687
update_statusbar(win);
690
static gboolean settings_hack_done = FALSE;
691
static gint old_gtk_timeout_expand = 0;
693
static void on_change_tab_on_drop_changed(FmAppConfig *cfg, gpointer _unused)
695
if (app_config->change_tab_on_drop)
696
g_object_set(gtk_settings_get_default(), "gtk-timeout-expand",
697
old_gtk_timeout_expand, NULL);
699
g_object_set(gtk_settings_get_default(), "gtk-timeout-expand", 600000, NULL);
702
static void _do_settings_hack(void)
704
GtkSettings *settings;
706
if (settings_hack_done)
708
settings_hack_done = TRUE;
709
settings = gtk_settings_get_default();
710
g_object_get(settings, "gtk-timeout-expand", &old_gtk_timeout_expand, NULL);
711
if (!app_config->change_tab_on_drop)
712
/* dirty hack to override crazy GtkNotebook which unfolds tab
713
each time it sees some drag comes to the tab label */
714
g_object_set(settings, "gtk-timeout-expand", 600000, NULL);
715
g_signal_connect(app_config, "changed::change_tab_on_drop",
716
G_CALLBACK(on_change_tab_on_drop_changed), NULL);
451
719
static void fm_main_win_init(FmMainWin *win)
454
722
GtkWidget *menubar;
455
724
GtkToolItem *toolitem;
456
725
GtkUIManager* ui;
457
726
GtkActionGroup* act_grp;
459
728
GtkAccelGroup* accel_grp;
729
AtkObject *atk_obj, *atk_view;
730
AtkRelation *relation;
731
#if FM_CHECK_VERSION(1, 2, 0)
732
GtkRadioAction *mode_action;
735
static char accel_str[] = "<Ctrl>1";
460
739
GtkShadowType shadow_type;
480
759
gtk_action_group_add_actions(act_grp, main_win_actions, G_N_ELEMENTS(main_win_actions), win);
481
760
gtk_action_group_add_toggle_actions(act_grp, main_win_toggle_actions,
482
761
G_N_ELEMENTS(main_win_toggle_actions), win);
762
#if FM_CHECK_VERSION(1, 2, 0)
763
/* generate list of modes dynamically from FmStandardView widget data */
766
str = g_string_new("ViewMode:");
767
xml = g_string_new("<menubar><menu action='ViewMenu'><menu action='FolderView'><placeholder name='ViewModes'>");
769
for(i = 0; i < fm_standard_view_get_n_modes(); i++)
771
if(fm_standard_view_get_mode_label(i))
773
g_string_append(str, fm_standard_view_mode_to_str(i));
774
mode_action = gtk_radio_action_new(str->str,
775
fm_standard_view_get_mode_label(i),
776
fm_standard_view_get_mode_tooltip(i),
777
fm_standard_view_get_mode_icon(i),
779
gtk_radio_action_set_group(mode_action, radio_group);
780
radio_group = gtk_radio_action_get_group(mode_action);
781
gtk_action_group_add_action_with_accel(act_grp,
782
GTK_ACTION(mode_action),
784
if (is_first) /* work on first one only */
786
win->first_view_mode = mode_action;
787
g_signal_connect(mode_action, "changed", G_CALLBACK(on_change_mode), win);
790
g_object_unref(mode_action);
791
g_string_append_printf(xml, "<menuitem action='%s'/>", str->str);
792
accel_str[6]++; /* <Ctrl>2 and so on */
793
g_string_truncate(str, 9); /* reset it to just "ViewMode:" */
796
g_string_append(xml, "</placeholder></menu>"); /* it will be continued below */
483
798
gtk_action_group_add_radio_actions(act_grp, main_win_mode_actions,
484
799
G_N_ELEMENTS(main_win_mode_actions),
485
800
app_config->view_mode,
486
801
G_CALLBACK(on_change_mode), win);
487
803
gtk_action_group_add_radio_actions(act_grp, main_win_sort_type_actions,
488
804
G_N_ELEMENTS(main_win_sort_type_actions),
805
#if FM_CHECK_VERSION(1, 0, 2)
806
FM_SORT_IS_ASCENDING(app_config->sort_type) ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING,
489
808
app_config->sort_type,
490
810
G_CALLBACK(on_sort_type), win);
491
811
gtk_action_group_add_radio_actions(act_grp, main_win_sort_by_actions,
492
812
G_N_ELEMENTS(main_win_sort_by_actions),
493
813
app_config->sort_by,
494
814
G_CALLBACK(on_sort_by), win);
815
#if FM_CHECK_VERSION(1, 2, 0)
816
/* generate list of modes dynamically from FmSidePane widget data */
819
g_string_assign(str, "SidePaneMode:");
820
g_string_append(xml, "<menu action='SidePane'><placeholder name='SidePaneModes'>");
822
for(i = 1; i <= fm_side_pane_get_n_modes(); i++)
824
if(fm_side_pane_get_mode_label(i))
826
g_string_append(str, fm_side_pane_get_mode_name(i));
827
mode_action = gtk_radio_action_new(str->str,
828
fm_side_pane_get_mode_label(i),
829
fm_side_pane_get_mode_tooltip(i),
832
gtk_radio_action_set_group(mode_action, radio_group);
833
radio_group = gtk_radio_action_get_group(mode_action);
834
gtk_action_group_add_action_with_accel(act_grp,
835
GTK_ACTION(mode_action),
837
if (is_first) /* work on first one only */
839
win->first_side_pane_mode = mode_action;
840
g_signal_connect(mode_action, "changed", G_CALLBACK(on_side_pane_mode), win);
843
g_object_unref(mode_action);
844
g_string_append_printf(xml, "<menuitem action='%s'/>", str->str);
845
accel_str[6]++; /* <Ctrl>7 and so on */
846
g_string_truncate(str, 13); /* reset it to just "SidePaneMode:" */
849
gtk_radio_action_set_current_value(win->first_side_pane_mode,
850
(app_config->side_pane_mode & FM_SP_MODE_MASK));
851
g_string_append(xml, "</placeholder></menu></menu></menubar>");
852
g_string_free(str, TRUE);
495
854
gtk_action_group_add_radio_actions(act_grp, main_win_side_bar_mode_actions,
496
855
G_N_ELEMENTS(main_win_side_bar_mode_actions),
497
856
(app_config->side_pane_mode & FM_SP_MODE_MASK),
498
857
G_CALLBACK(on_side_pane_mode), win);
859
gtk_action_group_add_radio_actions(act_grp, main_win_path_bar_mode_actions,
860
G_N_ELEMENTS(main_win_path_bar_mode_actions),
861
0, G_CALLBACK(on_path_bar_mode), win);
500
863
accel_grp = gtk_ui_manager_get_accel_group(ui);
501
864
gtk_window_add_accel_group(GTK_WINDOW(win), accel_grp);
503
866
gtk_ui_manager_insert_action_group(ui, act_grp, 0);
504
867
gtk_ui_manager_add_ui_from_string(ui, main_menu_xml, -1, NULL);
868
#if FM_CHECK_VERSION(1, 2, 0)
869
/* add ui generated above */
870
gtk_ui_manager_add_ui_from_string(ui, xml->str, xml->len, NULL);
871
g_string_free(xml, TRUE);
873
act = gtk_ui_manager_get_action(ui, "/menubar/ViewMenu/FolderView/IconView");
874
win->first_view_mode = GTK_RADIO_ACTION(act);
875
act = gtk_ui_manager_get_action(ui, "/menubar/ViewMenu/SidePane/Places");
876
win->first_side_pane_mode = GTK_RADIO_ACTION(act);
878
#if !FM_CHECK_VERSION(1, 0, 2)
505
879
act = gtk_ui_manager_get_action(ui, "/menubar/ViewMenu/ShowHidden");
506
#if !FM_CHECK_VERSION(1, 0, 2)
507
880
/* we cannot keep it in sync without callback from folder view which
508
881
is available only in 1.0.2 so just hide it */
509
882
gtk_action_set_visible(act, FALSE);
512
885
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act),
513
886
(app_config->side_pane_mode & FM_SP_HIDE) == 0);
888
#if FM_CHECK_VERSION(1, 2, 0)
889
/* disable "Find Files" button if module isn't available */
890
if (!fm_module_is_in_use("vfs", "search"))
892
act = gtk_ui_manager_get_action(ui, "/menubar/ToolMenu/Search");
893
gtk_action_set_sensitive(act, FALSE);
895
/* disable "Applications" button if module isn't available */
896
if (!fm_module_is_in_use("vfs", "menu"))
898
act = gtk_ui_manager_get_action(ui, "/menubar/GoMenu/Apps");
899
gtk_action_set_sensitive(act, FALSE);
515
903
menubar = gtk_ui_manager_get_widget(ui, "/menubar");
516
904
win->toolbar = GTK_TOOLBAR(gtk_ui_manager_get_widget(ui, "/toolbar"));
517
905
/* FIXME: should make these optional */
518
906
gtk_toolbar_set_icon_size(win->toolbar, GTK_ICON_SIZE_SMALL_TOOLBAR);
519
907
gtk_toolbar_set_style(win->toolbar, GTK_TOOLBAR_ICONS);
909
#if FM_CHECK_VERSION(1, 2, 0)
910
/* create history button after 'Prev' and add a popup menu to it */
911
toolitem = fm_menu_tool_item_new();
912
gtk_toolbar_insert(win->toolbar, toolitem, 3);
521
914
/* create 'Prev' button manually and add a popup menu to it */
522
915
toolitem = (GtkToolItem*)g_object_new(GTK_TYPE_MENU_TOOL_BUTTON, NULL);
523
916
gtk_toolbar_insert(win->toolbar, toolitem, 1);
524
917
act = gtk_ui_manager_get_action(ui, "/menubar/GoMenu/Prev");
525
918
gtk_activatable_set_related_action(GTK_ACTIVATABLE(toolitem), act);
527
921
/* set up history menu */
528
922
win->history_menu = gtk_menu_new();
923
#if FM_CHECK_VERSION(1, 2, 0)
924
fm_menu_tool_item_set_menu(FM_MENU_TOOL_ITEM(toolitem), win->history_menu);
925
gtk_tool_item_set_tooltip_text(toolitem, _("Show history of visited folders"));
529
927
gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolitem), win->history_menu);
928
gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(toolitem),
929
_("Show history of visited folders"));
530
931
g_signal_connect(toolitem, "show-menu", G_CALLBACK(on_show_history_menu), win);
932
atk_obj = gtk_widget_get_accessible(GTK_WIDGET(toolitem));
934
atk_object_set_name(atk_obj, _("History"));
532
936
gtk_box_pack_start( vbox, menubar, FALSE, TRUE, 0 );
533
937
gtk_box_pack_start( vbox, GTK_WIDGET(win->toolbar), FALSE, TRUE, 0 );
550
954
gtk_toolbar_insert(win->toolbar, toolitem, 0);
957
win->path_bar = fm_path_bar_new();
958
g_signal_connect(win->path_bar, "chdir", G_CALLBACK(on_path_bar_chdir), win);
959
pathbox = (GtkBox*)gtk_hbox_new(FALSE, 0);
960
gtk_box_pack_start(pathbox, GTK_WIDGET(win->location), TRUE, TRUE, 0);
961
gtk_box_pack_start(pathbox, GTK_WIDGET(win->path_bar), TRUE, TRUE, 0);
553
963
toolitem = (GtkToolItem*)gtk_tool_item_new();
554
gtk_container_add(GTK_CONTAINER(toolitem), GTK_WIDGET(win->location));
964
gtk_container_add(GTK_CONTAINER(toolitem), GTK_WIDGET(pathbox));
555
965
gtk_tool_item_set_expand(toolitem, TRUE);
556
966
gtk_toolbar_insert(win->toolbar, toolitem, gtk_toolbar_get_n_items(win->toolbar) - 1);
967
g_signal_connect(app_config, "changed::toolsbar",
968
G_CALLBACK(on_toolsbar_changed), win);
558
970
/* notebook - it contains both side pane and folder view(s) */
559
971
win->notebook = (GtkNotebook*)gtk_notebook_new();
560
972
gtk_notebook_set_scrollable(win->notebook, TRUE);
561
973
gtk_container_set_border_width(GTK_CONTAINER(win->notebook), 0);
562
974
gtk_notebook_set_show_border(win->notebook, FALSE);
975
_do_settings_hack(); /* do it after GtkNotebook initialized */
564
977
/* We need to use connect_after here.
565
978
* GtkNotebook handles the real page switching stuff in default
584
999
gtk_box_pack_start( vbox, GTK_WIDGET(win->statusbar), FALSE, TRUE, 0 );
585
1000
win->statusbar_ctx = gtk_statusbar_get_context_id(win->statusbar, "status");
586
1001
win->statusbar_ctx2 = gtk_statusbar_get_context_id(win->statusbar, "status2");
1002
g_signal_connect(app_config, "changed::statusbar",
1003
G_CALLBACK(on_statusbar_changed), win);
588
1005
g_object_unref(act_grp);
1008
/* accessibility: setup relation for Go button and location entry */
1009
atk_obj = gtk_widget_get_accessible(GTK_WIDGET(win->location));
1010
relation = atk_relation_new(&atk_obj, 1, ATK_RELATION_LABEL_FOR);
1011
/* use atk_view for button temporarily */
1012
atk_view = gtk_widget_get_accessible(gtk_ui_manager_get_widget(ui, "/toolbar/Go"));
1013
atk_relation_set_add(atk_object_ref_relation_set(atk_view), relation);
1014
g_object_unref(relation);
1015
/* setup relations with view */
1016
atk_view = gtk_widget_get_accessible(GTK_WIDGET(win->notebook));
1017
relation = atk_relation_new(&atk_obj, 1, ATK_RELATION_CONTROLLED_BY);
1018
atk_relation_set_add(atk_object_ref_relation_set(atk_view), relation);
1019
g_object_unref(relation);
1020
atk_obj = gtk_widget_get_accessible(GTK_WIDGET(win->statusbar));
1021
relation = atk_relation_new(&atk_obj, 1, ATK_RELATION_DESCRIBED_BY);
1022
atk_relation_set_add(atk_object_ref_relation_set(atk_view), relation);
1023
g_object_unref(relation);
591
1025
gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(vbox));
729
1180
static void on_open_in_terminal(GtkAction* act, FmMainWin* win)
1183
#if FM_CHECK_VERSION(1, 0, 2)
1184
path = fm_nav_history_get_nth_path(win->nav_history,
1185
fm_nav_history_get_cur_index(win->nav_history));
731
1188
const FmNavHistoryItem* item = fm_nav_history_get_cur(win->nav_history);
732
if(item && item->path)
733
pcmanfm_open_folder_in_terminal(GTK_WINDOW(win), item->path);
736
static const char* su_cmd_subst(char opt, gpointer user_data)
741
static FmAppCommandParseOption su_cmd_opts[] =
743
{ 's', su_cmd_subst },
747
static void on_open_as_root(GtkAction* act, FmMainWin* win)
751
if(!app_config->su_cmd)
753
fm_show_error(GTK_WINDOW(win), NULL, _("Switch user command is not set."));
754
fm_edit_preference(GTK_WINDOW(win), PREF_ADVANCED);
757
/* FIXME: need to rename to pcmanfm when we reach stable release. */
758
if(fm_app_command_parse(app_config->su_cmd, su_cmd_opts, &cmd, "pcmanfm %U") == 0)
760
/* no %s found so just append to it */
762
cmd = g_strconcat(app_config->su_cmd, " pcmanfm %U", NULL);
764
app = g_app_info_create_from_commandline(cmd, NULL, 0, NULL);
768
FmPath* cwd = fm_tab_page_get_cwd(win->current_page);
770
GdkAppLaunchContext* ctx = gdk_app_launch_context_new();
771
char* uri = fm_path_to_uri(cwd);
772
GList* uris = g_list_prepend(NULL, uri);
773
gdk_app_launch_context_set_screen(ctx, gtk_widget_get_screen(GTK_WIDGET(win)));
774
gdk_app_launch_context_set_timestamp(ctx, gtk_get_current_event_time());
775
if(!g_app_info_launch_uris(app, uris, G_APP_LAUNCH_CONTEXT(ctx), &err))
777
fm_show_error(GTK_WINDOW(win), NULL, err->message);
779
fm_edit_preference(GTK_WINDOW(win), PREF_ADVANCED);
1189
if(item && (path = item->path))
1191
pcmanfm_open_folder_in_terminal(GTK_WINDOW(win), path);
788
1194
#if FM_CHECK_VERSION(1, 0, 2)
835
1269
static void on_change_mode(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win)
837
1271
int mode = gtk_radio_action_get_current_value(cur);
838
1274
fm_standard_view_set_mode(FM_STANDARD_VIEW(win->folder_view), mode);
1275
if (win->current_page->own_config)
1276
fm_app_config_save_config_for_path(fm_folder_view_get_cwd(win->folder_view),
1277
win->current_page->sort_type,
1278
win->current_page->sort_by, mode,
1279
win->current_page->show_hidden, NULL);
1281
win->current_page->view_mode = mode;
841
1284
static void on_sort_by(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win)
843
1286
int val = gtk_radio_action_get_current_value(cur);
844
fm_folder_view_sort(win->folder_view, -1, val);
845
if(val != app_config->sort_by)
847
app_config->sort_by = val;
848
pcmanfm_save_config(FALSE);
1287
FmFolderView *fv = win->folder_view;
1288
#if FM_CHECK_VERSION(1, 0, 2)
1289
FmFolderModel *model = fm_folder_view_get_model(fv);
1292
fm_folder_model_set_sort(model, val, FM_SORT_DEFAULT);
1294
fm_folder_view_sort(fv, -1, val);
1296
if(val != (int)win->current_page->sort_by)
1298
win->current_page->sort_by = val;
1299
if (win->current_page->own_config)
1301
fm_app_config_save_config_for_path(fm_folder_view_get_cwd(fv),
1302
win->current_page->sort_type,
1304
win->current_page->show_hidden,
1309
app_config->sort_by = val;
1310
pcmanfm_save_config(FALSE);
1315
#if FM_CHECK_VERSION(1, 0, 2)
1316
static inline void update_sort_type_for_page(FmTabPage *page, FmFolderView *fv, FmSortMode mode)
1318
static inline void update_sort_type_for_page(FmTabPage *page, FmFolderView *fv, guint mode)
1321
if(mode != page->sort_type)
1323
page->sort_type = mode;
1324
if (page->own_config)
1326
fm_app_config_save_config_for_path(fm_folder_view_get_cwd(fv), mode,
1328
page->show_hidden, NULL);
1332
app_config->sort_type = mode;
1333
pcmanfm_save_config(FALSE);
852
1338
static void on_sort_type(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win)
854
1340
guint val = gtk_radio_action_get_current_value(cur);
1341
FmFolderView *fv = win->folder_view;
1342
#if FM_CHECK_VERSION(1, 0, 2)
1343
FmFolderModel *model = fm_folder_view_get_model(fv);
1348
fm_folder_model_get_sort(model, NULL, &mode);
1349
mode &= ~FM_SORT_ORDER_MASK;
1350
mode |= (val == GTK_SORT_ASCENDING) ? FM_SORT_ASCENDING : FM_SORT_DESCENDING;
1351
fm_folder_model_set_sort(model, -1, mode);
1352
update_sort_type_for_page(win->current_page, fv, mode);
855
1355
fm_folder_view_sort(win->folder_view, val, -1);
856
if(val != app_config->sort_type)
858
app_config->sort_type = val;
859
pcmanfm_save_config(FALSE);
1356
update_sort_type_for_page(win->current_page, fv, val);
1360
#if FM_CHECK_VERSION(1, 2, 0)
1361
static void on_mingle_dirs(GtkToggleAction* act, FmMainWin* win)
1363
FmFolderView *fv = win->folder_view;
1364
FmFolderModel *model = fm_folder_view_get_model(fv);
1370
fm_folder_model_get_sort(model, NULL, &mode);
1371
active = gtk_toggle_action_get_active(act);
1372
mode &= ~FM_SORT_NO_FOLDER_FIRST;
1374
mode |= FM_SORT_NO_FOLDER_FIRST;
1375
fm_folder_model_set_sort(model, -1, mode);
1376
update_sort_type_for_page(win->current_page, fv, mode);
1381
#if FM_CHECK_VERSION(1, 0, 2)
1382
static void on_sort_ignore_case(GtkToggleAction* act, FmMainWin* win)
1384
FmFolderView *fv = win->folder_view;
1385
FmFolderModel *model = fm_folder_view_get_model(fv);
1391
fm_folder_model_get_sort(model, NULL, &mode);
1392
active = gtk_toggle_action_get_active(act);
1393
mode &= ~FM_SORT_CASE_SENSITIVE;
1395
mode |= FM_SORT_CASE_SENSITIVE;
1396
fm_folder_model_set_sort(model, -1, mode);
1397
update_sort_type_for_page(win->current_page, fv, mode);
1402
static void on_save_per_folder(GtkToggleAction* act, FmMainWin* win)
1404
gboolean active = gtk_toggle_action_get_active(act);
1405
FmTabPage *page = win->current_page;
1406
FmFolderView *fv = win->folder_view;
1410
if (page->own_config) /* not changed */
1412
page->own_config = TRUE;
1413
#if FM_CHECK_VERSION(1, 0, 2)
1414
page->columns = g_strdupv(app_config->columns);
1416
fm_app_config_save_config_for_path(fm_folder_view_get_cwd(fv),
1417
page->sort_type, page->sort_by,
1418
fm_standard_view_get_mode(FM_STANDARD_VIEW(fv)),
1419
#if FM_CHECK_VERSION(1, 0, 2)
1420
page->show_hidden, page->columns);
1422
page->show_hidden, NULL);
1425
else if (page->own_config) /* attribute removed */
1427
page->own_config = FALSE;
1428
#if FM_CHECK_VERSION(1, 0, 2)
1429
g_strfreev(page->columns);
1430
page->columns = NULL;
1432
fm_app_config_clear_config_for_path(fm_folder_view_get_cwd(fv));
863
1436
static void on_side_pane_mode(GtkRadioAction* act, GtkRadioAction *cur, FmMainWin* win)
865
1438
FmTabPage* cur_page = win->current_page;
866
FmSidePane* sp = fm_tab_page_get_side_pane(cur_page);
1441
if (cur_page == NULL) /* it can be NULL if we are in FmMainWin setup */
1443
sp = fm_tab_page_get_side_pane(cur_page);
867
1444
int val = gtk_radio_action_get_current_value(cur);
868
1445
fm_side_pane_set_mode(sp, val);
914
1500
FmNavHistory *nh = fm_tab_page_get_history(win->current_page);
916
1502
act = gtk_ui_manager_get_action(win->ui, "/menubar/GoMenu/Next");
1503
#if FM_CHECK_VERSION(1, 0, 2)
1504
gtk_action_set_sensitive(act, fm_nav_history_get_cur_index(nh) > 0);
917
1506
gtk_action_set_sensitive(act, fm_nav_history_can_forward(nh));
918
1508
act = gtk_ui_manager_get_action(win->ui, "/menubar/GoMenu/Prev");
919
1509
gtk_action_set_sensitive(act, fm_nav_history_can_back(nh));
1510
update_file_menu(win, fm_tab_page_get_cwd(win->current_page));
922
1513
static void on_go_back(GtkAction* act, FmMainWin* win)
924
1515
fm_tab_page_back(win->current_page);
1516
/* update folder popup */
1517
fm_folder_view_set_active(win->folder_view, FALSE);
1518
fm_folder_view_add_popup(win->folder_view, GTK_WINDOW(win), NULL);
925
1519
_update_hist_buttons(win);
928
1522
static void on_go_forward(GtkAction* act, FmMainWin* win)
930
1524
fm_tab_page_forward(win->current_page);
1525
/* update folder popup */
1526
fm_folder_view_set_active(win->folder_view, FALSE);
1527
fm_folder_view_add_popup(win->folder_view, GTK_WINDOW(win), NULL);
931
1528
_update_hist_buttons(win);
1669
static gboolean on_window_state_event(GtkWidget *widget, GdkEventWindowState *evt, FmMainWin *win)
1671
if (evt->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
1672
win->fullscreen = ((evt->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0);
1673
if (evt->changed_mask & GDK_WINDOW_STATE_MAXIMIZED)
1674
win->maximized = ((evt->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0);
1055
1678
FmMainWin* fm_main_win_add_win(FmMainWin* win, FmPath* path)
1057
1682
win = fm_main_win_new();
1058
1683
gtk_window_set_default_size(GTK_WINDOW(win),
1059
1684
app_config->win_width,
1060
1685
app_config->win_height);
1686
if (app_config->maximized)
1687
gtk_window_maximize(GTK_WINDOW(win));
1061
1688
gtk_widget_show_all(GTK_WIDGET(win));
1689
g_signal_connect(win, "window-state-event", G_CALLBACK(on_window_state_event), win);
1062
1690
/* create new tab */
1063
1691
fm_main_win_add_tab(win, path);
1064
1692
gtk_window_present(GTK_WINDOW(win));
1693
/* set toolbar visibility and menu toggleables from config */
1694
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Toolbar/ShowToolbar");
1695
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->tb.visible);
1696
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Toolbar/ToolbarNewWin");
1697
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->tb.new_win);
1698
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Toolbar/ToolbarNewTab");
1699
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->tb.new_tab);
1700
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Toolbar/ToolbarNav");
1701
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->tb.nav);
1702
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/Toolbar/ToolbarHome");
1703
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->tb.home);
1704
/* the same for statusbar */
1705
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/ShowStatus");
1706
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), app_config->show_statusbar);
1707
gtk_widget_set_visible(GTK_WIDGET(win->statusbar), app_config->show_statusbar);
1708
/* the same for path bar mode */
1709
gtk_widget_hide(GTK_WIDGET(win->path_bar));
1710
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/PathMode/PathEntry");
1711
gtk_radio_action_set_current_value(GTK_RADIO_ACTION(act), app_config->pathbar_mode_buttons);
1715
static void on_open(GtkAction* act, FmMainWin* win)
1717
FmFileInfoList *files = fm_folder_view_dup_selected_files(win->folder_view);
1720
GList* l = fm_file_info_list_peek_head_link(files);
1721
if (g_list_length(l) > 0)
1722
fm_launch_files_simple(GTK_WINDOW(win), NULL, l, pcmanfm_open_folder, NULL);
1723
fm_file_info_list_unref(files);
1727
static void on_link(GtkAction *act, FmMainWin *win)
1729
FmPathList *files = fm_folder_view_dup_selected_file_paths(win->folder_view);
1732
FmPath *dest = fm_select_folder(GTK_WINDOW(win), NULL);
1735
fm_link_files(GTK_WINDOW(win), files, dest);
1736
fm_path_unref(dest);
1738
fm_path_list_unref(files);
1068
1742
static void on_copy_to(GtkAction* act, FmMainWin* win)
1070
1744
FmPathList* files = fm_folder_view_dup_selected_file_paths(win->folder_view);
1773
static void on_trash(GtkAction* act, FmMainWin* win)
1775
FmPathList* files = fm_folder_view_dup_selected_file_paths(win->folder_view);
1778
fm_trash_files(GTK_WINDOW(win), files);
1779
fm_path_list_unref(files);
1783
static void on_del(GtkAction* act, FmMainWin* win)
1785
FmPathList* files = fm_folder_view_dup_selected_file_paths(win->folder_view);
1788
fm_delete_files(GTK_WINDOW(win), files);
1789
fm_path_list_unref(files);
1793
static void on_copy_path(GtkAction* action, FmMainWin* win)
1795
GdkDisplay *dpy = gtk_widget_get_display(GTK_WIDGET(win));
1796
GtkClipboard *clipboard = gtk_clipboard_get_for_display(dpy, GDK_SELECTION_CLIPBOARD);
1797
GString *str = g_string_sized_new(128);
1798
FmPathList *files = fm_folder_view_dup_selected_file_paths(win->folder_view);
1801
for (fl = fm_path_list_peek_head_link(files); fl; fl = fl->next)
1803
char *path = fm_path_to_str(fl->data);
1805
g_string_append_c(str, '\n');
1806
g_string_append(str, path);
1809
gtk_clipboard_set_text(clipboard, str->str, str->len);
1810
g_string_free(str, TRUE);
1099
1813
static void on_preference(GtkAction* act, FmMainWin* win)
1101
1815
fm_edit_preference(GTK_WINDOW(win), 0);
1836
static void on_show_toolbar(GtkToggleAction *action, FmMainWin *win)
1838
gboolean active = gtk_toggle_action_get_active(action);
1840
app_config->tb.visible = active;
1841
fm_config_emit_changed(fm_config, "toolsbar");
1842
pcmanfm_save_config(FALSE);
1845
/* toolbar items: NewWin NewTab Prev (Hist) Next Up Home (Location) Go */
1846
static void on_toolbar_new_win(GtkToggleAction *act, FmMainWin *win)
1848
gboolean active = gtk_toggle_action_get_active(act);
1850
app_config->tb.new_win = active;
1851
fm_config_emit_changed(fm_config, "toolsbar");
1852
pcmanfm_save_config(FALSE);
1855
static void on_toolbar_new_tab(GtkToggleAction *act, FmMainWin *win)
1857
gboolean active = gtk_toggle_action_get_active(act);
1859
app_config->tb.new_tab = active;
1860
fm_config_emit_changed(fm_config, "toolsbar");
1861
pcmanfm_save_config(FALSE);
1864
static void on_toolbar_nav(GtkToggleAction *act, FmMainWin *win)
1866
gboolean active = gtk_toggle_action_get_active(act);
1868
app_config->tb.nav = active;
1869
fm_config_emit_changed(fm_config, "toolsbar");
1870
pcmanfm_save_config(FALSE);
1873
static void on_toolbar_home(GtkToggleAction *act, FmMainWin *win)
1875
gboolean active = gtk_toggle_action_get_active(act);
1877
app_config->tb.home = active;
1878
fm_config_emit_changed(fm_config, "toolsbar");
1879
pcmanfm_save_config(FALSE);
1122
1882
static void on_location(GtkAction* act, FmMainWin* win)
1124
1884
gtk_widget_grab_focus(GTK_WIDGET(win->location));
1885
if (app_config->pathbar_mode_buttons)
1887
gtk_widget_show(GTK_WIDGET(win->location));
1888
gtk_widget_show(gtk_ui_manager_get_widget(win->ui, "/toolbar/Go"));
1889
gtk_widget_hide(GTK_WIDGET(win->path_bar));
1127
1893
static void bounce_action(GtkAction* act, FmMainWin* win)
1895
GtkWindow *window = GTK_WINDOW(win);
1896
GtkWidget *current_focus;
1129
1898
g_debug("bouncing action %s to popup", gtk_action_get_name(act));
1130
fm_folder_view_bounce_action(act, FM_FOLDER_VIEW(win->folder_view));
1899
/* save current focus */
1900
current_focus = gtk_window_get_focus(window);
1901
/* bug #3615003: if folder view does not have the focus, action will not work */
1902
gtk_window_set_focus(window, GTK_WIDGET(win->folder_view));
1903
fm_folder_view_bounce_action(act, win->folder_view);
1904
/* restore focus back */
1905
gtk_window_set_focus(window, current_focus);
1908
static guint icon_sizes[] =
1916
32, /* 30 would be better */
1929
static void on_size_decrement(GtkAction *act, FmMainWin *win)
1931
FmStandardViewMode mode;
1934
if (win->folder_view == NULL)
1936
mode = fm_standard_view_get_mode(FM_STANDARD_VIEW(win->folder_view));
1939
case FM_FV_ICON_VIEW:
1940
size = fm_config->big_icon_size;
1944
case FM_FV_COMPACT_VIEW:
1945
case FM_FV_LIST_VIEW:
1946
size = fm_config->small_icon_size;
1950
case FM_FV_THUMBNAIL_VIEW:
1951
size = fm_config->thumbnail_size;
1958
for (i = G_N_ELEMENTS(icon_sizes); i > 0; )
1961
if (icon_sizes[i] < size)
1966
case FM_FV_ICON_VIEW:
1967
fm_config->big_icon_size = icon_sizes[i];
1968
fm_config_emit_changed(fm_config, "big_icon_size");
1970
case FM_FV_COMPACT_VIEW:
1971
case FM_FV_LIST_VIEW:
1972
fm_config->small_icon_size = icon_sizes[i];
1973
fm_config_emit_changed(fm_config, "small_icon_size");
1975
case FM_FV_THUMBNAIL_VIEW:
1976
fm_config->thumbnail_size = icon_sizes[i];
1977
fm_config_emit_changed(fm_config, "thumbnail_size");
1979
pcmanfm_save_config(FALSE);
1982
static void on_size_increment(GtkAction *act, FmMainWin *win)
1984
FmStandardViewMode mode;
1987
if (win->folder_view == NULL)
1989
mode = fm_standard_view_get_mode(FM_STANDARD_VIEW(win->folder_view));
1992
case FM_FV_ICON_VIEW:
1993
size = fm_config->big_icon_size;
1997
case FM_FV_COMPACT_VIEW:
1998
case FM_FV_LIST_VIEW:
1999
size = fm_config->small_icon_size;
2003
case FM_FV_THUMBNAIL_VIEW:
2004
size = fm_config->thumbnail_size;
2011
for (i = 1; i < G_N_ELEMENTS(icon_sizes); i++)
2013
if (icon_sizes[i] > size)
2018
case FM_FV_ICON_VIEW:
2019
fm_config->big_icon_size = icon_sizes[i];
2020
fm_config_emit_changed(fm_config, "big_icon_size");
2022
case FM_FV_COMPACT_VIEW:
2023
case FM_FV_LIST_VIEW:
2024
fm_config->small_icon_size = icon_sizes[i];
2025
fm_config_emit_changed(fm_config, "small_icon_size");
2027
case FM_FV_THUMBNAIL_VIEW:
2028
fm_config->thumbnail_size = icon_sizes[i];
2029
fm_config_emit_changed(fm_config, "thumbnail_size");
2031
pcmanfm_save_config(FALSE);
2034
static void on_size_default(GtkAction *act, FmMainWin *win)
2036
FmStandardViewMode mode;
2038
if (win->folder_view == NULL)
2040
mode = fm_standard_view_get_mode(FM_STANDARD_VIEW(win->folder_view));
2043
case FM_FV_ICON_VIEW:
2044
if (fm_config->big_icon_size == 48)
2046
fm_config->big_icon_size = 48;
2047
fm_config_emit_changed(fm_config, "big_icon_size");
2049
case FM_FV_COMPACT_VIEW:
2050
case FM_FV_LIST_VIEW:
2051
if (fm_config->small_icon_size == 20)
2053
fm_config->small_icon_size = 20;
2054
fm_config_emit_changed(fm_config, "small_icon_size");
2056
case FM_FV_THUMBNAIL_VIEW:
2057
if (fm_config->thumbnail_size == 128)
2059
fm_config->thumbnail_size = 128;
2060
fm_config_emit_changed(fm_config, "thumbnail_size");
2065
pcmanfm_save_config(FALSE);
1133
2068
/* This callback is only connected to folder view of current active tab page. */
1189
2126
fm_path_entry_set_path(win->location, path);
2127
fm_path_bar_set_path(win->path_bar, path);
1190
2128
gtk_window_set_title(GTK_WINDOW(win), fm_tab_page_get_title(page));
2131
static void on_tab_page_got_focus(FmTabPage* page, FmMainWin* win)
2133
int n = gtk_notebook_page_num(win->notebook, GTK_WIDGET(page));
2134
/* sometimes views receive focus while they are in rendering process
2135
therefore click on tab will not always work as expected because it
2136
is reset in this callback, the trick is if notebook is in update
2137
process then focus change is pending (see on_notebook_switch_page()
2138
for details) therefore we can check that and do nothing */
2139
if (n >= 0 && win->idle_handler == 0) /* don't change page if it is pending */
2140
gtk_notebook_set_current_page(win->notebook, n);
1193
2143
#if FM_CHECK_VERSION(1, 0, 2)
1194
2144
static void on_folder_view_filter_changed(FmFolderView* fv, FmMainWin* win)
1196
2146
GtkAction* act;
1197
2147
gboolean active;
2149
if (fv != win->folder_view)
1199
2152
active = fm_folder_view_get_show_hidden(fv);
1201
2154
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/ShowHidden");
1202
2155
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), active);
1203
if(active != app_config->show_hidden)
2156
if(active != win->current_page->show_hidden)
1205
app_config->show_hidden = active;
1206
pcmanfm_save_config(FALSE);
2158
win->current_page->show_hidden = active;
2159
if (win->current_page->own_config)
2161
fm_app_config_save_config_for_path(fm_folder_view_get_cwd(fv),
2162
win->current_page->sort_type,
2163
win->current_page->sort_by, -1,
2168
app_config->show_hidden = active;
2169
pcmanfm_save_config(FALSE);
2175
static inline FmTabPage *_find_tab_page(FmMainWin *win, FmFolderView *fv)
2180
for (n = gtk_notebook_get_n_pages(win->notebook); n > 0; )
2182
page = FM_TAB_PAGE(gtk_notebook_get_nth_page(win->notebook, --n));
2183
if (fv == fm_tab_page_get_folder_view(page))
1211
2189
static void on_notebook_switch_page(GtkNotebook* nb, gpointer* new_page, guint num, FmMainWin* win)
1213
2191
GtkWidget* sw_page = gtk_notebook_get_nth_page(nb, num);
1214
2192
FmTabPage* page;
2193
FmFolderView *old_view = NULL, *passive_view = NULL;
1216
2195
g_return_if_fail(FM_IS_TAB_PAGE(sw_page));
1217
2196
page = (FmTabPage*)sw_page;
1218
2197
/* deactivate gestures from old view first */
1219
2198
if(win->folder_view)
1220
2200
fm_folder_view_set_active(win->folder_view, FALSE);
2201
g_object_unref(win->folder_view);
2204
/* remember old views for checks below */
2205
if (win->current_page)
2207
passive_view = fm_tab_page_get_passive_view(win->current_page);
2208
old_view = fm_tab_page_get_folder_view(win->current_page);
1222
2211
/* connect to the new active page */
1223
2212
win->current_page = page;
1224
2213
win->folder_view = fm_tab_page_get_folder_view(page);
2214
if(win->folder_view)
2215
g_object_ref(win->folder_view);
1225
2216
win->nav_history = fm_tab_page_get_history(page);
1226
2217
win->side_pane = fm_tab_page_get_side_pane(page);
2219
/* set active and passive panes */
2220
if (win->enable_passive_view && passive_view)
2222
FmTabPage *psv_page;
2224
if (win->folder_view == passive_view)
2226
/* we moved to other pane so we have to set passive_view_on_right */
2227
win->passive_view_on_right = win->passive_view_on_right ? FALSE : TRUE;
2228
passive_view = old_view;
2231
fm_tab_page_set_passive_view(page, passive_view, win->passive_view_on_right);
2232
/* FIXME: log errors */
2233
/* ok, passive view was just changed, we have to update the button */
2234
psv_page = _find_tab_page(win, passive_view);
2236
gtk_widget_set_state(GTK_WIDGET(psv_page->tab_label), GTK_STATE_SELECTED);
2240
/* FIXME: log errors */
2241
fm_tab_page_take_view_back(page);
1228
2244
/* reactivate gestures */
1229
2245
fm_folder_view_set_active(win->folder_view, TRUE);
1230
2246
g_debug("reactivated gestures to page %u", num);
1315
2336
on_tab_page_chdir, win);
1316
2337
g_signal_handlers_disconnect_by_func(tab_page,
1317
2338
on_tab_page_status_text, win);
2339
g_signal_handlers_disconnect_by_func(tab_page,
2340
on_tab_page_got_focus, win);
1318
2341
if(folder_view)
1320
2343
g_signal_handlers_disconnect_by_func(folder_view,
1321
2344
on_view_key_press_event, win);
1322
g_signal_handlers_disconnect_by_func(tab_page->folder_view,
2345
g_signal_handlers_disconnect_by_func(folder_view,
1323
2346
on_folder_view_sort_changed, win);
1324
g_signal_handlers_disconnect_by_func(tab_page->folder_view,
2347
g_signal_handlers_disconnect_by_func(folder_view,
1325
2348
on_folder_view_sel_changed, win);
1326
2349
#if FM_CHECK_VERSION(1, 0, 2)
1327
g_signal_handlers_disconnect_by_func(tab_page->folder_view,
2350
g_signal_handlers_disconnect_by_func(folder_view,
1328
2351
on_folder_view_filter_changed, win);
1330
g_signal_handlers_disconnect_by_func(tab_page->folder_view,
2353
g_signal_handlers_disconnect_by_func(folder_view,
1331
2354
on_folder_view_clicked, win);
2355
/* update menu if passive pane was removed */
2356
if (win->current_page && win->enable_passive_view &&
2357
fm_tab_page_get_passive_view(win->current_page) == folder_view)
2359
win->enable_passive_view = FALSE;
2360
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/DualPane");
2361
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(act), FALSE);
1333
2364
g_signal_handlers_disconnect_by_func(tab_page->side_pane,
1334
2365
on_side_pane_mode_changed, win);
2513
static gboolean on_scroll_event(GtkWidget* w, GdkEventScroll* evt)
2515
FmMainWin* win = FM_MAIN_WIN(w);
2517
int modifier = evt->state & gtk_accelerator_get_default_mod_mask();
2519
/* g_debug("on_scroll_event:%d", evt->direction); */
2520
if (modifier != GDK_CONTROL_MASK) ;
2521
else if(evt->direction == GDK_SCROLL_UP)
2523
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/SizeBigger");
2524
gtk_action_activate(act);
2527
else if(evt->direction == GDK_SCROLL_DOWN)
2529
act = gtk_ui_manager_get_action(win->ui, "/menubar/ViewMenu/SizeSmaller");
2530
gtk_action_activate(act);
2533
if(GTK_WIDGET_CLASS(fm_main_win_parent_class)->scroll_event)
2534
return GTK_WIDGET_CLASS(fm_main_win_parent_class)->scroll_event(w, evt);
1477
2539
static void on_reload(GtkAction* act, FmMainWin* win)
1479
2541
FmTabPage* page = win->current_page;
1480
2542
fm_tab_page_reload(page);
2545
#if FM_CHECK_VERSION(1, 0, 2)
2546
static void on_filter(GtkAction* act, FmMainWin* win)
2548
FmTabPage *page = win->current_page;
2549
const char *old_filter = page->filter_pattern ? page->filter_pattern : "*";
2552
new_filter = fm_get_user_input(GTK_WINDOW(win), _("Select filter"),
2553
_("Choose a new shell pattern to show files:"),
2555
if (!new_filter) /* cancelled */
2557
if (strcmp(new_filter, "*"))
2558
fm_tab_page_set_filter_pattern(page, new_filter);
2560
fm_tab_page_set_filter_pattern(page, NULL);
2562
gtk_window_set_title(GTK_WINDOW(win), fm_tab_page_get_title(page));
1483
2566
static void on_show_side_pane(GtkToggleAction* act, FmMainWin* win)
1485
2568
gboolean active;
1495
2578
app_config->side_pane_mode |= FM_SP_HIDE;
1496
2579
gtk_widget_hide(GTK_WIDGET(win->side_pane));
2581
/* FIXME: propagate the event to other windows? */
2582
pcmanfm_save_config(FALSE);
2585
static void on_dual_pane(GtkToggleAction* act, FmMainWin* win)
2592
active = gtk_toggle_action_get_active(act);
2593
/* g_debug("on_dual_pane: %d", active); */
2594
if (active && !win->enable_passive_view)
2596
num = gtk_notebook_get_n_pages(win->notebook);
2597
if (num < 2) /* single page yet */
2599
win->passive_view_on_right = FALSE;
2600
num = fm_main_win_add_tab(win, fm_tab_page_get_cwd(win->current_page));
2601
g_debug("on_dual_pane: added duplicate of the single page");
2602
page = gtk_notebook_get_nth_page(win->notebook, 0);
2604
else if (gtk_notebook_get_current_page(win->notebook) < num - 1)
2606
/* there is a page on right */
2607
win->passive_view_on_right = TRUE;
2608
num = gtk_notebook_get_current_page(win->notebook) + 1;
2609
g_debug("on_dual_pane: adding passive page %d to right pane", num);
2610
page = gtk_notebook_get_nth_page(win->notebook, num);
2614
/* it is the most right page */
2615
win->passive_view_on_right = FALSE;
2616
g_debug("on_dual_pane: adding passive page %d to left pane", num - 2);
2617
page = gtk_notebook_get_nth_page(win->notebook, num - 2);
2619
fv = fm_tab_page_get_folder_view(FM_TAB_PAGE(page));
2620
fm_tab_page_set_passive_view(win->current_page, fv,
2621
win->passive_view_on_right);
2622
/* ok, passive view was just changed, we have to update the button */
2623
gtk_widget_set_state(GTK_WIDGET(FM_TAB_PAGE(page)->tab_label), GTK_STATE_SELECTED);
2624
win->enable_passive_view = TRUE;
2626
else if (!active && win->enable_passive_view)
2628
/* take passive pane back to the tab page */
2629
fv = fm_tab_page_get_passive_view(win->current_page);
2632
FmTabPage *tp = _find_tab_page(win, fv);
2635
fm_tab_page_take_view_back(tp);
2636
gtk_widget_set_state(GTK_WIDGET(FM_TAB_PAGE(tp)->tab_label), GTK_STATE_ACTIVE);
2639
win->enable_passive_view = FALSE;
2643
static void on_show_status(GtkToggleAction *action, FmMainWin *win)
2647
active = gtk_toggle_action_get_active(action);
2648
if (active != app_config->show_statusbar)
2650
app_config->show_statusbar = active;
2651
fm_config_emit_changed(fm_config, "statusbar");
2652
pcmanfm_save_config(FALSE);