コード例 #1
0
static void
gb_project_tree_actions__trash_file_cb (GObject      *object,
                                        GAsyncResult *result,
                                        gpointer      user_data)
{
  IdeProject *project = (IdeProject *)object;
  g_autoptr(GbProjectTree) self = user_data;
  g_autoptr(GError) error = NULL;
  GbTreeNode *node;
  GObject *item = NULL;

  g_assert (IDE_IS_PROJECT (project));
  g_assert (GB_IS_PROJECT_TREE (self));

  if (!ide_project_trash_file_finish (project, result, &error))
    {
      /* todo: warning dialog */
      g_warning ("%s", error->message);
      return;
    }

  /* todo: this should be done with tree observer */
  if ((node = gb_tree_get_selected (GB_TREE (self))))
    {
      if ((node = gb_tree_node_get_parent (node)))
        item = gb_tree_node_get_item (node);
    }

  gb_tree_rebuild (GB_TREE (self));

  if ((node = gb_tree_find_item (GB_TREE (self), item)))
    gb_tree_node_expand (node, TRUE);
}
コード例 #2
0
static void
gb_project_tree_actions_refresh (GSimpleAction *action,
                                 GVariant      *variant,
                                 gpointer       user_data)
{
  GbProjectTree *self = user_data;
  GbTreeNode *selected;
  GObject *item = NULL;

  g_assert (GB_IS_PROJECT_TREE (self));

  if ((selected = gb_tree_get_selected (GB_TREE (self))))
    {
      item = gb_tree_node_get_item (selected);
      if (item != NULL)
        g_object_ref (item);
    }

  gb_tree_rebuild (GB_TREE (self));

  if (item != NULL)
    {
      selected = gb_tree_find_item (GB_TREE (self), item);
      if (selected != NULL)
        {
          gb_tree_node_expand (selected, TRUE);
          gb_tree_node_select (selected);
          gb_tree_scroll_to_node (GB_TREE (self), selected);
        }
      g_object_unref (item);
    }
}
コード例 #3
0
static void
gb_project_tree_actions__project_rename_file_cb (GObject      *object,
                                                 GAsyncResult *result,
                                                 gpointer      user_data)
{
  IdeProject *project = (IdeProject *)object;
  g_autoptr(GbRenameFilePopover) popover = user_data;
  g_autoptr(GError) error = NULL;
  GbTreeNode *node;
  GFile *file;
  GbTree *tree;
  gboolean expanded = FALSE;

  g_assert (IDE_IS_PROJECT (project));
  g_assert (GB_IS_RENAME_FILE_POPOVER (popover));

  if (!ide_project_rename_file_finish (project, result, &error))
    {
      /* todo: display error */
      g_warning ("%s", error->message);
      return;
    }

  file = g_object_get_data (G_OBJECT (popover), "G_FILE");
  tree = GB_TREE (gtk_popover_get_relative_to (GTK_POPOVER (popover)));

  g_assert (G_IS_FILE (file));
  g_assert (GB_IS_TREE (tree));

  if ((node = gb_tree_get_selected (tree)))
    expanded = gb_tree_node_get_expanded (node);

  gb_tree_rebuild (tree);

  node = gb_tree_find_custom (tree,
                              (GEqualFunc)project_item_equal_func,
                              file);

  if (node != NULL)
    {
      gb_tree_node_expand (node, TRUE);
      if (!expanded)
        gb_tree_node_collapse (node);
      gb_tree_node_select (node);
      gb_tree_scroll_to_node (tree, node);
    }

  gtk_widget_hide (GTK_WIDGET (popover));
  gtk_widget_destroy (GTK_WIDGET (popover));
}
コード例 #4
0
void
gb_project_tree_set_show_ignored_files (GbProjectTree *self,
                                        gboolean       show_ignored_files)
{
  g_return_if_fail (GB_IS_PROJECT_TREE (self));

  show_ignored_files = !!show_ignored_files;

  if (show_ignored_files != self->show_ignored_files)
    {
      self->show_ignored_files = show_ignored_files;
      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SHOW_IGNORED_FILES]);
      gb_tree_rebuild (GB_TREE (self));
    }
}
コード例 #5
0
ファイル: gb-project-tree.c プロジェクト: Dagal/gnome-builder
void
gb_project_tree_set_context (GbProjectTree *self,
                             IdeContext    *context)
{
  GbTreeNode *root;
  IdeProject *project = NULL;
  GtkTreeModel *model;

  g_return_if_fail (GB_IS_PROJECT_TREE (self));
  g_return_if_fail (!context || IDE_IS_CONTEXT (context));

  if (context != NULL)
    project = ide_context_get_project (context);

  root = gb_tree_get_root (GB_TREE (self));
  gb_tree_node_set_item (root, G_OBJECT (project));

  gb_tree_rebuild (GB_TREE (self));

  /*
   * If we only have one item at the root of the tree, expand it.
   */
  if ((model = gtk_tree_view_get_model (GTK_TREE_VIEW (self))))
    {
      GtkTreeIter iter;

      if ((gtk_tree_model_iter_n_children (model, NULL) == 1) &&
          gtk_tree_model_get_iter_first (model, &iter))
        {
          g_autoptr(GbTreeNode) node = NULL;

          gtk_tree_model_get (model, &iter, 0, &node, -1);
          if (node != NULL)
            gb_tree_node_expand (node, FALSE);
        }
    }
}