static void
gb_project_tree_vcs_changed (GbProjectTree *self,
                             IdeVcs        *vcs)
{
  g_autoptr(GFile) file = NULL;
  IdeTreeNode *node;
  GObject *item;

  g_assert (GB_IS_PROJECT_TREE (self));
  g_assert (IDE_IS_VCS (vcs));

  if (NULL != (node = ide_tree_get_selected (IDE_TREE (self))) &&
      NULL != (item = ide_tree_node_get_item (node)) &&
      GB_IS_PROJECT_FILE (item))
    {
      if (NULL != (file = gb_project_file_get_file (GB_PROJECT_FILE (item))))
        g_object_ref (file);
    }


  ide_tree_rebuild (IDE_TREE (self));

  if (file != NULL)
    gb_project_tree_reveal (self, file);
}
static void
gb_project_tree_actions_refresh (GSimpleAction *action,
                                 GVariant      *variant,
                                 gpointer       user_data)
{
  GbProjectTree *self = user_data;
  IdeTreeNode *selected;
  GObject *item = NULL;

  g_assert (GB_IS_PROJECT_TREE (self));

  if ((selected = ide_tree_get_selected (IDE_TREE (self))))
    {
      item = ide_tree_node_get_item (selected);
      if (item != NULL)
        g_object_ref (item);
    }

  ide_tree_rebuild (IDE_TREE (self));

  if (item != NULL)
    {
      selected = ide_tree_find_item (IDE_TREE (self), item);
      if (selected != NULL)
        {
          ide_tree_node_expand (selected, TRUE);
          ide_tree_node_select (selected);
          ide_tree_scroll_to_node (IDE_TREE (self), selected);
        }
      g_object_unref (item);
    }
}
static void
gb_project_tree_actions_open_with_editor (GSimpleAction *action,
                                          GVariant      *variant,
                                          gpointer       user_data)
{
  IdeWorkbench *workbench;
  GbProjectTree *self = user_data;
  GFileInfo *file_info;
  GFile *file;
  IdeTreeNode *selected;
  GObject *item;

  g_assert (GB_IS_PROJECT_TREE (self));

  if (!(selected = ide_tree_get_selected (IDE_TREE (self))) ||
      !(item = ide_tree_node_get_item (selected)) ||
      !GB_IS_PROJECT_FILE (item) ||
      !(file_info = gb_project_file_get_file_info (GB_PROJECT_FILE (item))) ||
      (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) ||
      !(file = gb_project_file_get_file (GB_PROJECT_FILE (item))) ||
      !(workbench = ide_widget_get_workbench (GTK_WIDGET (self))))
    return;

  ide_workbench_open_files_async (workbench, &file, 1, "editor", NULL, NULL, NULL);
}
static void
gb_project_tree_actions_open_containing_folder (GSimpleAction *action,
                                                GVariant      *variant,
                                                gpointer       user_data)
{
  GbProjectTree *self = user_data;
  IdeTreeNode *selected;
  GObject *item;
  GFile *file;

  g_assert (GB_IS_PROJECT_TREE (self));

  if (!(selected = ide_tree_get_selected (IDE_TREE (self))) ||
      !(item = ide_tree_node_get_item (selected)) ||
      !GB_IS_PROJECT_FILE (item))
    return;

  file = gb_project_file_get_file (GB_PROJECT_FILE (item));

  ide_file_manager_show (file, NULL);
}
static void
gb_project_tree_actions_open_with (GSimpleAction *action,
                                   GVariant      *variant,
                                   gpointer       user_data)
{
  g_autoptr(GDesktopAppInfo) app_info = NULL;
  g_autoptr(GdkAppLaunchContext) launch_context = NULL;
  GbProjectTree *self = user_data;
  IdeTreeNode *selected;
  IdeWorkbench *workbench;
  GdkDisplay *display;
  GFileInfo *file_info;
  GFile *file;
  const gchar *app_id;
  GObject *item;
  GList *files;

  g_assert (GB_IS_PROJECT_TREE (self));
  g_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING));

  if (!(workbench = ide_widget_get_workbench (GTK_WIDGET (self))) ||
      !(selected = ide_tree_get_selected (IDE_TREE (self))) ||
      !(item = ide_tree_node_get_item (selected)) ||
      !GB_IS_PROJECT_FILE (item) ||
      !(app_id = g_variant_get_string (variant, NULL)) ||
      !(file_info = gb_project_file_get_file_info (GB_PROJECT_FILE (item))) ||
      !(file = gb_project_file_get_file (GB_PROJECT_FILE (item))) ||
      !(app_info = g_desktop_app_info_new (app_id)))
    return;

  display = gtk_widget_get_display (GTK_WIDGET (self));
  launch_context = gdk_display_get_app_launch_context (display);

  files = g_list_append (NULL, file);
  g_app_info_launch (G_APP_INFO (app_info), files, G_APP_LAUNCH_CONTEXT (launch_context), NULL);
  g_list_free (files);
}