1
/* gb-project-tree-actions.c
3
* Copyright (C) 2015 Christian Hergert <christian@hergert.me>
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#define G_LOG_DOMAIN "gb-project-tree-actions"
21
#include <glib/gi18n.h>
22
#include <gio/gdesktopappinfo.h>
24
#include "gb-editor-workspace.h"
25
#include "gb-file-manager.h"
26
#include "gb-new-file-popover.h"
27
#include "gb-project-tree.h"
28
#include "gb-project-tree-actions.h"
29
#include "gb-project-tree-private.h"
30
#include "gb-rename-file-popover.h"
31
#include "gb-view-stack.h"
32
#include "gb-widget.h"
33
#include "gb-workbench.h"
36
action_set (GActionGroup *group,
37
const gchar *action_name,
38
const gchar *first_param,
44
g_assert (G_IS_ACTION_GROUP (group));
45
g_assert (G_IS_ACTION_MAP (group));
47
action = g_action_map_lookup_action (G_ACTION_MAP (group), action_name);
48
g_assert (G_IS_SIMPLE_ACTION (action));
50
va_start (args, first_param);
51
g_object_set_valist (G_OBJECT (action), first_param, args);
56
project_file_is_directory (GObject *object)
58
g_assert (!object || G_IS_OBJECT (object));
60
return (IDE_IS_PROJECT_FILE (object) &&
61
ide_project_file_get_is_directory (IDE_PROJECT_FILE (object)));
65
gb_project_tree_actions_refresh (GSimpleAction *action,
69
GbProjectTree *self = user_data;
73
g_assert (GB_IS_PROJECT_TREE (self));
75
if ((selected = gb_tree_get_selected (GB_TREE (self))))
77
item = gb_tree_node_get_item (selected);
82
gb_tree_rebuild (GB_TREE (self));
86
selected = gb_tree_find_item (GB_TREE (self), item);
89
gb_tree_node_expand (selected, TRUE);
90
gb_tree_node_select (selected);
91
gb_tree_scroll_to_node (GB_TREE (self), selected);
93
g_object_unref (item);
98
gb_project_tree_actions_collapse_all_nodes (GSimpleAction *action,
102
GbProjectTree *self = user_data;
104
g_assert (GB_IS_PROJECT_TREE (self));
106
gtk_tree_view_collapse_all (GTK_TREE_VIEW (self));
110
gb_project_tree_actions_open (GSimpleAction *action,
114
GbProjectTree *self = user_data;
115
GbWorkbench *workbench;
116
GbTreeNode *selected;
119
g_assert (GB_IS_PROJECT_TREE (self));
121
workbench = gb_widget_get_workbench (GTK_WIDGET (self));
122
g_assert (GB_IS_WORKBENCH (workbench));
124
if (!(selected = gb_tree_get_selected (GB_TREE (self))) ||
125
!(item = gb_tree_node_get_item (selected)))
128
item = gb_tree_node_get_item (selected);
130
if (IDE_IS_PROJECT_FILE (item))
132
GFileInfo *file_info;
135
file_info = ide_project_file_get_file_info (IDE_PROJECT_FILE (item));
139
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
142
file = ide_project_file_get_file (IDE_PROJECT_FILE (item));
146
gb_workbench_open (workbench, file);
151
gb_project_tree_actions_open_with (GSimpleAction *action,
155
g_autoptr(GDesktopAppInfo) app_info = NULL;
156
g_autoptr(GdkAppLaunchContext) launch_context = NULL;
157
GbProjectTree *self = user_data;
158
GbTreeNode *selected;
159
GbWorkbench *workbench;
161
GFileInfo *file_info;
167
g_assert (GB_IS_PROJECT_TREE (self));
168
g_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING));
170
if (!(workbench = gb_widget_get_workbench (GTK_WIDGET (self))) ||
171
!(selected = gb_tree_get_selected (GB_TREE (self))) ||
172
!(item = gb_tree_node_get_item (selected)) ||
173
!IDE_IS_PROJECT_FILE (item) ||
174
!(app_id = g_variant_get_string (variant, NULL)) ||
175
!(file_info = ide_project_file_get_file_info (IDE_PROJECT_FILE (item))) ||
176
!(file = ide_project_file_get_file (IDE_PROJECT_FILE (item))) ||
177
!(app_info = g_desktop_app_info_new (app_id)))
180
display = gtk_widget_get_display (GTK_WIDGET (self));
181
launch_context = gdk_display_get_app_launch_context (display);
183
files = g_list_append (NULL, file);
184
g_app_info_launch (G_APP_INFO (app_info), files, G_APP_LAUNCH_CONTEXT (launch_context), NULL);
189
gb_project_tree_actions_open_with_editor (GSimpleAction *action,
193
GbWorkbench *workbench;
194
GbProjectTree *self = user_data;
195
GFileInfo *file_info;
197
GbTreeNode *selected;
200
g_assert (GB_IS_PROJECT_TREE (self));
202
if (!(selected = gb_tree_get_selected (GB_TREE (self))) ||
203
!(item = gb_tree_node_get_item (selected)) ||
204
!IDE_IS_PROJECT_FILE (item) ||
205
!(file_info = ide_project_file_get_file_info (IDE_PROJECT_FILE (item))) ||
206
(g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) ||
207
!(file = ide_project_file_get_file (IDE_PROJECT_FILE (item))) ||
208
!(workbench = gb_widget_get_workbench (GTK_WIDGET (self))))
211
gb_workbench_open_with_editor (workbench, file);
215
gb_project_tree_actions_open_containing_folder (GSimpleAction *action,
219
GbEditorWorkspace *self = user_data;
220
GbTreeNode *selected;
224
g_assert (GB_IS_PROJECT_TREE (self));
226
if (!(selected = gb_tree_get_selected (GB_TREE (self))) ||
227
!(item = gb_tree_node_get_item (selected)) ||
228
!(IDE_IS_PROJECT_FILE (item) || IDE_IS_PROJECT_FILES (item)))
231
if (IDE_IS_PROJECT_FILES (item))
236
context = ide_object_get_context (IDE_OBJECT (item));
237
vcs = ide_context_get_vcs (context);
238
file = ide_vcs_get_working_directory (vcs);
240
else if (!(file = ide_project_file_get_file (IDE_PROJECT_FILE (item))))
245
gb_file_manager_show (file, NULL);
248
/* Based on gdesktopappinfo.c in GIO */
250
find_terminal_executable (void)
254
g_autoptr(GSettings) terminal_settings = NULL;
255
g_autofree gchar *gsettings_terminal = NULL;
256
const gchar *terminals[] = {
257
NULL, /* GSettings */
258
"x-terminal-emulator", /* Debian's alternative system */
260
NULL, /* getenv ("TERM") */
261
"nxterm", "color-xterm",
262
"rxvt", "xterm", "dtterm"
265
/* This is deprecated, but at least the user can specify it! */
266
terminal_settings = g_settings_new ("org.gnome.desktop.default-applications.terminal");
267
gsettings_terminal = g_settings_get_string (terminal_settings, "exec");
268
terminals[0] = gsettings_terminal;
270
/* This is generally one of the fallback terminals */
271
terminals[3] = g_getenv ("TERM");
273
for (i = 0; i < G_N_ELEMENTS (terminals) && path == NULL; ++i)
275
if (terminals[i] != NULL)
277
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
278
path = g_find_program_in_path (terminals[i]);
279
G_GNUC_END_IGNORE_DEPRECATIONS
287
gb_project_tree_actions_open_in_terminal (GSimpleAction *action,
291
GbEditorWorkspace *self = user_data;
292
GbTreeNode *selected;
295
g_autofree gchar *workdir = NULL;
296
g_autofree gchar *terminal_executable = NULL;
297
const gchar *argv[] = { NULL, NULL };
298
GError *error = NULL;
300
g_assert (GB_IS_PROJECT_TREE (self));
302
if (!(selected = gb_tree_get_selected (GB_TREE (self))) ||
303
!(item = gb_tree_node_get_item (selected)) ||
304
!(IDE_IS_PROJECT_FILE (item) || IDE_IS_PROJECT_FILES (item)))
307
if (IDE_IS_PROJECT_FILES (item))
312
context = ide_object_get_context (IDE_OBJECT (item));
313
vcs = ide_context_get_vcs (context);
314
file = ide_vcs_get_working_directory (vcs);
316
else if (!(file = ide_project_file_get_file (IDE_PROJECT_FILE (item))))
321
if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) != G_FILE_TYPE_DIRECTORY)
323
g_autoptr(GFile) parent;
325
parent = g_file_get_parent (file);
326
workdir = g_file_get_path (parent);
330
workdir = g_file_get_path (file);
335
g_warning ("Cannot load non-native file in terminal.");
339
terminal_executable = find_terminal_executable ();
340
argv[0] = terminal_executable;
341
g_return_if_fail (terminal_executable != NULL);
343
/* Can't use GdkAppLaunchContext as
344
* we cannot set the working directory.
346
if (!g_spawn_async (workdir, (gchar **)argv, NULL,
347
G_SPAWN_STDERR_TO_DEV_NULL,
348
NULL, NULL, NULL, &error))
350
g_warning ("%s", error->message);
351
g_clear_error (&error);
357
gb_project_tree_actions_show_icons (GSimpleAction *action,
361
GbProjectTree *self = user_data;
364
g_assert (GB_IS_PROJECT_TREE (self));
365
g_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN));
367
show_icons = g_variant_get_boolean (variant);
368
gb_tree_set_show_icons (GB_TREE (self), show_icons);
369
g_simple_action_set_state (action, variant);
372
static IdeProjectFile *
373
create_file (IdeContext *context,
377
g_autofree gchar *path = NULL;
378
g_autofree gchar *name = NULL;
379
g_autoptr(GFileInfo) file_info = NULL;
383
g_assert (IDE_IS_CONTEXT (context));
384
g_assert (G_IS_FILE (file));
385
g_assert ((file_type == G_FILE_TYPE_DIRECTORY) || (file_type == G_FILE_TYPE_REGULAR));
387
vcs = ide_context_get_vcs (context);
388
workdir = ide_vcs_get_working_directory (vcs);
389
path = g_file_get_relative_path (workdir, file);
390
name = g_file_get_basename (file);
392
file_info = g_file_info_new ();
393
g_file_info_set_file_type (file_info, file_type);
394
g_file_info_set_name (file_info, name);
395
g_file_info_set_display_name (file_info, name);
397
return g_object_new (IDE_TYPE_PROJECT_FILE,
400
"file-info", file_info,
407
gb_project_tree_actions__make_directory_cb (GObject *object,
408
GAsyncResult *result,
411
GFile *file = (GFile *)object;
412
g_autoptr(GbTreeNode) node = user_data;
413
g_autoptr(GError) error = NULL;
414
g_autoptr(IdeProjectFile) project_file = NULL;
416
GbWorkbench *workbench;
421
g_assert (G_IS_FILE (file));
422
g_assert (GB_IS_TREE_NODE (node));
424
if (!g_file_make_directory_finish (file, result, &error))
426
/* todo: show error messsage */
430
self = GB_PROJECT_TREE (gb_tree_node_get_tree (node));
434
workbench = gb_widget_get_workbench (GTK_WIDGET (self));
435
if (workbench == NULL)
438
context = gb_workbench_get_context (workbench);
442
project = ide_context_get_project (context);
444
project_file = create_file (context, file, G_FILE_TYPE_DIRECTORY);
445
ide_project_add_file (project, project_file);
447
gb_tree_node_rebuild (node);
448
gb_tree_node_expand (node, FALSE);
450
created = gb_tree_find_item (GB_TREE (self), G_OBJECT (project_file));
453
gb_tree_node_select (created);
457
gb_project_tree_actions__create_cb (GObject *object,
458
GAsyncResult *result,
461
GFile *file = (GFile *)object;
462
g_autoptr(IdeProjectFile) project_file = NULL;
463
g_autoptr(GbTreeNode) node = user_data;
464
g_autoptr(GError) error = NULL;
466
GbWorkbench *workbench;
471
g_assert (G_IS_FILE (file));
472
g_assert (GB_IS_TREE_NODE (node));
474
if (!g_file_create_finish (file, result, &error))
476
/* todo: show error messsage */
480
self = GB_PROJECT_TREE (gb_tree_node_get_tree (node));
484
workbench = gb_widget_get_workbench (GTK_WIDGET (self));
485
if (workbench == NULL)
488
context = gb_workbench_get_context (workbench);
492
project = ide_context_get_project (context);
494
project_file = create_file (context, file, G_FILE_TYPE_REGULAR);
495
ide_project_add_file (project, project_file);
497
gb_workbench_open (workbench, file);
499
gb_tree_node_rebuild (node);
500
gb_tree_node_expand (node, FALSE);
502
created = gb_tree_find_item (GB_TREE (self), G_OBJECT (project_file));
505
gb_tree_node_select (created);
509
gb_project_tree_actions__popover_create_file_cb (GbProjectTree *self,
512
GbNewFilePopover *popover)
514
GbTreeNode *selected;
516
g_assert (GB_IS_PROJECT_TREE (self));
517
g_assert (G_IS_FILE (file));
518
g_assert ((file_type == G_FILE_TYPE_DIRECTORY) ||
519
(file_type == G_FILE_TYPE_REGULAR));
520
g_assert (GB_IS_NEW_FILE_POPOVER (popover));
522
selected = gb_tree_get_selected (GB_TREE (self));
524
g_assert (selected != NULL);
525
g_assert (GB_IS_TREE_NODE (selected));
527
if (file_type == G_FILE_TYPE_DIRECTORY)
529
g_file_make_directory_async (file,
531
NULL, /* cancellable */
532
gb_project_tree_actions__make_directory_cb,
533
g_object_ref (selected));
535
else if (file_type == G_FILE_TYPE_REGULAR)
537
g_file_create_async (file,
540
NULL, /* cancellable */
541
gb_project_tree_actions__create_cb,
542
g_object_ref (selected));
546
g_assert_not_reached ();
549
self->expanded_in_new = FALSE;
551
gtk_widget_hide (GTK_WIDGET (popover));
552
gtk_widget_destroy (GTK_WIDGET (popover));
556
gb_project_tree_actions__popover_closed_cb (GbProjectTree *self,
559
GbTreeNode *selected;
561
g_assert (GB_IS_PROJECT_TREE (self));
562
g_assert (GTK_IS_POPOVER (popover));
564
if (!(selected = gb_tree_get_selected (GB_TREE (self))) || !self->expanded_in_new)
567
gb_tree_node_collapse (selected);
571
gb_project_tree_actions_new (GbProjectTree *self,
574
GbTreeNode *selected;
577
IdeProjectFile *project_file;
579
gboolean is_dir = FALSE;
581
g_assert (GB_IS_PROJECT_TREE (self));
582
g_assert ((file_type == G_FILE_TYPE_DIRECTORY) ||
583
(file_type == G_FILE_TYPE_REGULAR));
586
if (!(selected = gb_tree_get_selected (GB_TREE (self))) ||
587
!(item = gb_tree_node_get_item (selected)) ||
588
!(IDE_IS_PROJECT_FILES (item) || IDE_IS_PROJECT_FILE (item)))
591
if (IDE_IS_PROJECT_FILE (item))
593
if (!(project_file = IDE_PROJECT_FILE (item)) ||
594
!(file = ide_project_file_get_file (project_file)))
596
is_dir = project_file_is_directory (item);
598
else if (IDE_IS_PROJECT_FILES (item))
603
context = ide_object_get_context (IDE_OBJECT (item));
604
vcs = ide_context_get_vcs (context);
605
file = ide_vcs_get_working_directory (vcs);
610
g_assert_not_reached ();
614
g_assert (G_IS_FILE (file));
617
* If this item is an IdeProjectFile and not a directory, then we really
618
* want to create a sibling.
624
selected = gb_tree_node_get_parent (selected);
625
gb_tree_node_select (selected);
626
path = gb_tree_node_get_path (selected);
627
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (self), path, NULL, FALSE, 0, 0);
628
gtk_tree_path_free (path);
633
if ((self->expanded_in_new = !gb_tree_node_get_expanded (selected)))
634
gb_tree_node_expand (selected, FALSE);
636
popover = g_object_new (GB_TYPE_NEW_FILE_POPOVER,
638
"file-type", file_type,
639
"position", GTK_POS_RIGHT,
641
g_signal_connect_object (popover,
643
G_CALLBACK (gb_project_tree_actions__popover_create_file_cb),
646
g_signal_connect_object (popover,
648
G_CALLBACK (gb_project_tree_actions__popover_closed_cb),
652
gb_tree_node_show_popover (selected, popover);
656
gb_project_tree_actions_new_directory (GSimpleAction *action,
660
GbProjectTree *self = user_data;
662
g_assert (GB_IS_PROJECT_TREE (self));
664
gb_project_tree_actions_new (self, G_FILE_TYPE_DIRECTORY);
668
gb_project_tree_actions_new_file (GSimpleAction *action,
672
GbProjectTree *self = user_data;
674
g_assert (GB_IS_PROJECT_TREE (self));
676
gb_project_tree_actions_new (self, G_FILE_TYPE_REGULAR);
680
project_item_equal_func (GFile *key,
683
g_assert (G_IS_FILE (key));
684
g_assert (IDE_IS_PROJECT_ITEM (item));
686
if (IDE_IS_PROJECT_FILE (item))
690
file = ide_project_file_get_file (IDE_PROJECT_FILE (item));
691
g_assert (G_IS_FILE (file));
693
return g_file_equal (key, file);
700
gb_project_tree_actions__project_rename_file_cb (GObject *object,
701
GAsyncResult *result,
704
IdeProject *project = (IdeProject *)object;
705
g_autoptr(GbRenameFilePopover) popover = user_data;
706
g_autoptr(GError) error = NULL;
710
gboolean expanded = FALSE;
712
g_assert (IDE_IS_PROJECT (project));
713
g_assert (GB_IS_RENAME_FILE_POPOVER (popover));
715
if (!ide_project_rename_file_finish (project, result, &error))
717
/* todo: display error */
718
g_warning ("%s", error->message);
722
file = g_object_get_data (G_OBJECT (popover), "G_FILE");
723
tree = GB_TREE (gtk_popover_get_relative_to (GTK_POPOVER (popover)));
725
g_assert (G_IS_FILE (file));
726
g_assert (GB_IS_TREE (tree));
728
if ((node = gb_tree_get_selected (tree)))
729
expanded = gb_tree_node_get_expanded (node);
731
gb_tree_rebuild (tree);
733
node = gb_tree_find_custom (tree,
734
(GEqualFunc)project_item_equal_func,
739
gb_tree_node_expand (node, TRUE);
741
gb_tree_node_collapse (node);
742
gb_tree_node_select (node);
743
gb_tree_scroll_to_node (tree, node);
746
gtk_widget_hide (GTK_WIDGET (popover));
747
gtk_widget_destroy (GTK_WIDGET (popover));
751
gb_project_tree_actions__rename_file_cb (GbProjectTree *self,
754
GbRenameFilePopover *popover)
756
GbWorkbench *workbench;
760
g_assert (GB_IS_PROJECT_TREE (self));
761
g_assert (G_IS_FILE (orig_file));
762
g_assert (G_IS_FILE (new_file));
763
g_assert (GTK_IS_POPOVER (popover));
765
workbench = gb_widget_get_workbench (GTK_WIDGET (self));
766
context = gb_workbench_get_context (workbench);
767
project = ide_context_get_project (context);
769
/* todo: set busin spinner in popover */
771
g_object_set_data_full (G_OBJECT (popover),
773
g_object_ref (new_file),
776
ide_project_rename_file_async (project, orig_file, new_file, NULL,
777
gb_project_tree_actions__project_rename_file_cb,
778
g_object_ref (popover));
782
gb_project_tree_actions_rename_file (GSimpleAction *action,
786
GbProjectTree *self = user_data;
787
GbTreeNode *selected;
791
GFileInfo *file_info;
794
g_assert (GB_IS_PROJECT_TREE (self));
796
if (!(selected = gb_tree_get_selected (GB_TREE (self))) ||
797
!(item = gb_tree_node_get_item (selected)) ||
798
!IDE_IS_PROJECT_FILE (item) ||
799
!(file = ide_project_file_get_file (IDE_PROJECT_FILE (item))) ||
800
!(file_info = ide_project_file_get_file_info (IDE_PROJECT_FILE (item))))
803
is_dir = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
805
popover = g_object_new (GB_TYPE_RENAME_FILE_POPOVER,
807
"is-directory", is_dir,
808
"position", GTK_POS_RIGHT,
810
g_signal_connect_object (popover,
812
G_CALLBACK (gb_project_tree_actions__rename_file_cb),
815
gb_tree_node_show_popover (selected, popover);
819
gb_project_tree_actions__trash_file_cb (GObject *object,
820
GAsyncResult *result,
823
IdeProject *project = (IdeProject *)object;
824
g_autoptr(GbProjectTree) self = user_data;
825
g_autoptr(GError) error = NULL;
827
GObject *item = NULL;
829
g_assert (IDE_IS_PROJECT (project));
830
g_assert (GB_IS_PROJECT_TREE (self));
832
if (!ide_project_trash_file_finish (project, result, &error))
834
/* todo: warning dialog */
835
g_warning ("%s", error->message);
839
/* todo: this should be done with tree observer */
840
if ((node = gb_tree_get_selected (GB_TREE (self))))
842
if ((node = gb_tree_node_get_parent (node)))
843
item = gb_tree_node_get_item (node);
846
gb_tree_rebuild (GB_TREE (self));
848
if ((node = gb_tree_find_item (GB_TREE (self), item)))
849
gb_tree_node_expand (node, TRUE);
853
get_view_stack (GbView *view)
855
GtkWidget *widget = (GtkWidget *)view;
857
while ((widget != NULL) && !GB_IS_VIEW_STACK (widget))
858
widget = gtk_widget_get_parent (widget);
860
return (GbViewStack *)widget;
865
GbDocument *document;
870
gb_project_tree_actions_close_views_cb (GtkWidget *widget,
873
GbDocument *document;
874
ViewsRemoval *removal = user_data;
875
GbView *view = (GbView *)widget;
877
g_assert (GB_IS_VIEW (view));
878
g_assert (removal != NULL);
879
g_assert (GB_IS_DOCUMENT (removal->document));
881
document = gb_view_get_document (view);
883
if (document == removal->document)
884
removal->views = g_list_prepend (removal->views, g_object_ref (view));
888
gb_project_tree_actions_move_to_trash (GSimpleAction *action,
892
GbProjectTree *self = user_data;
893
IdeBufferManager *buffer_manager;
894
GbWorkbench *workbench;
896
ViewsRemoval removal = { 0 };
905
g_assert (G_IS_SIMPLE_ACTION (action));
906
g_assert (GB_IS_PROJECT_TREE (self));
908
workbench = gb_widget_get_workbench (GTK_WIDGET (self));
909
context = gb_workbench_get_context (workbench);
910
project = ide_context_get_project (context);
911
buffer_manager = ide_context_get_buffer_manager (context);
913
if (!(node = gb_tree_get_selected (GB_TREE (self))) ||
914
!(item = gb_tree_node_get_item (node)) ||
915
!IDE_IS_PROJECT_FILE (item) ||
916
!(file = ide_project_file_get_file (IDE_PROJECT_FILE (item))))
920
* Find all of the views that contain this file.
921
* We do not close them until we leave the foreach callback.
923
ifile = ide_project_get_project_file (project, file);
924
buffer = ide_buffer_manager_find_buffer (buffer_manager, ifile);
927
removal.document = g_object_ref (buffer);
928
gb_workbench_views_foreach (workbench,
929
gb_project_tree_actions_close_views_cb,
931
g_object_unref (removal.document);
935
* Close all of the views that match the document.
937
for (iter = removal.views; iter; iter = iter->next)
941
stack = get_view_stack (iter->data);
943
gb_view_stack_remove (stack, iter->data);
946
g_list_free_full (removal.views, g_object_unref);
949
* Now move the file to the trash.
951
ide_project_trash_file_async (project,
954
gb_project_tree_actions__trash_file_cb,
955
g_object_ref (self));
958
static GActionEntry GbProjectTreeActions[] = {
959
{ "collapse-all-nodes", gb_project_tree_actions_collapse_all_nodes },
960
{ "move-to-trash", gb_project_tree_actions_move_to_trash },
961
{ "new-directory", gb_project_tree_actions_new_directory },
962
{ "new-file", gb_project_tree_actions_new_file },
963
{ "open", gb_project_tree_actions_open },
964
{ "open-containing-folder", gb_project_tree_actions_open_containing_folder },
965
{ "open-in-terminal", gb_project_tree_actions_open_in_terminal },
966
{ "open-with", gb_project_tree_actions_open_with, "s" },
967
{ "open-with-editor", gb_project_tree_actions_open_with_editor },
968
{ "refresh", gb_project_tree_actions_refresh },
969
{ "rename-file", gb_project_tree_actions_rename_file },
970
{ "show-icons", NULL, NULL, "false", gb_project_tree_actions_show_icons },
974
gb_project_tree_actions_init (GbProjectTree *self)
976
g_autoptr(GSettings) settings = NULL;
977
g_autoptr(GSettings) tree_settings = NULL;
978
g_autoptr(GSimpleActionGroup) actions = NULL;
979
g_autoptr(GAction) action = NULL;
980
g_autoptr(GVariant) show_icons = NULL;
982
actions = g_simple_action_group_new ();
984
settings = g_settings_new ("org.gtk.Settings.FileChooser");
985
action = g_settings_create_action (settings, "sort-directories-first");
986
g_action_map_add_action (G_ACTION_MAP (actions), action);
988
g_action_map_add_action_entries (G_ACTION_MAP (actions),
989
GbProjectTreeActions,
990
G_N_ELEMENTS (GbProjectTreeActions),
992
gtk_widget_insert_action_group (GTK_WIDGET (self),
994
G_ACTION_GROUP (actions));
996
tree_settings = g_settings_new ("org.gnome.builder.project-tree");
997
show_icons = g_settings_get_value (tree_settings, "show-icons");
998
action_set (G_ACTION_GROUP (actions), "show-icons",
1002
gb_project_tree_actions_update (self);
1006
gb_project_tree_actions_update (GbProjectTree *self)
1008
GActionGroup *group;
1009
GbTreeNode *selection;
1010
GObject *item = NULL;
1014
g_assert (GB_IS_PROJECT_TREE (self));
1016
group = gtk_widget_get_action_group (GTK_WIDGET (self), "project-tree");
1017
g_assert (G_IS_SIMPLE_ACTION_GROUP (group));
1019
selection = gb_tree_get_selected (GB_TREE (self));
1020
if (selection != NULL)
1021
item = gb_tree_node_get_item (selection);
1023
action_set (group, "new-file",
1024
"enabled", (IDE_IS_PROJECT_FILE (item) || IDE_IS_PROJECT_FILES (item)),
1026
action_set (group, "new-directory",
1027
"enabled", (IDE_IS_PROJECT_FILE (item) || IDE_IS_PROJECT_FILES (item)),
1029
action_set (group, "open",
1030
"enabled", (IDE_IS_PROJECT_FILE (item) && !project_file_is_directory (item)),
1032
action_set (group, "open-with-editor",
1033
"enabled", (IDE_IS_PROJECT_FILE (item) && !project_file_is_directory (item)),
1035
action_set (group, "open-containing-folder",
1036
"enabled", (IDE_IS_PROJECT_FILE (item) || IDE_IS_PROJECT_FILES (item)),
1038
action_set (group, "open-in-terminal",
1039
"enabled", IDE_IS_PROJECT_FILE (item),
1041
action_set (group, "rename-file",
1042
"enabled", IDE_IS_PROJECT_FILE (item),
1044
action_set (group, "move-to-trash",
1045
"enabled", (IDE_IS_PROJECT_FILE (item) && !project_file_is_directory (item)),