/**
 * gb_tree_builder_node_selected:
 * @builder: (in): A #GbTreeBuilder.
 * @node: (in): A #GbTreeNode.
 *
 * Update @node for being selected and update any actions or ui based
 * on @node being selected.
 *
 * Returns: None.
 * Side effects: None.
 */
void
gb_tree_builder_node_selected (GbTreeBuilder *builder,
                               GbTreeNode    *node)
{
	g_return_if_fail(GB_IS_TREE_BUILDER(builder));
	g_return_if_fail(GB_IS_TREE_NODE(node));

	if (GB_TREE_BUILDER_GET_CLASS(builder)->node_selected) {
		GB_TREE_BUILDER_GET_CLASS(builder)->node_selected(builder, node);
	}
}
예제 #2
0
static void
gb_project_tree_actions__create_cb (GObject      *object,
                                    GAsyncResult *result,
                                    gpointer      user_data)
{
  GFile *file = (GFile *)object;
  g_autoptr(IdeProjectFile) project_file = NULL;
  g_autoptr(GbTreeNode) node = user_data;
  g_autoptr(GError) error = NULL;
  GbProjectTree *self;
  GbWorkbench *workbench;
  IdeContext *context;
  IdeProject *project;
  GbTreeNode *created;

  g_assert (G_IS_FILE (file));
  g_assert (GB_IS_TREE_NODE (node));

  if (!g_file_create_finish (file, result, &error))
    {
      /* todo: show error messsage */
      return;
    }

  self = GB_PROJECT_TREE (gb_tree_node_get_tree (node));
  if (self == NULL)
    return;

  workbench = gb_widget_get_workbench (GTK_WIDGET (self));
  if (workbench == NULL)
    return;

  context = gb_workbench_get_context (workbench);
  if (context == NULL)
    return;

  project = ide_context_get_project (context);

  project_file = create_file (context, file, G_FILE_TYPE_REGULAR);
  ide_project_add_file (project, project_file);

  gb_workbench_open (workbench, file);

  gb_tree_node_rebuild (node);
  gb_tree_node_expand (node, FALSE);

  created = gb_tree_find_item (GB_TREE (self), G_OBJECT (project_file));

  if (created != NULL)
    gb_tree_node_select (created);
}
/**
 * gb_tree_builder_node_activated:
 * @builder: (in): A #GbTreeBuilder.
 * @node: (in): A #GbTreeNode.
 *
 * Handle @node being activated. Builders may want to open a view
 * or perform an action on such an event.
 *
 * Returns: %TRUE if the node activation was handled.
 * Side effects: None.
 */
gboolean
gb_tree_builder_node_activated (GbTreeBuilder *builder,
                                GbTreeNode    *node)
{
	g_return_val_if_fail(GB_IS_TREE_BUILDER(builder), FALSE);
	g_return_val_if_fail(GB_IS_TREE_NODE(node), FALSE);

	if (GB_TREE_BUILDER_GET_CLASS(builder)->node_activated) {
		return GB_TREE_BUILDER_GET_CLASS(builder)->
			node_activated(builder, node);
	}

	return FALSE;
}
예제 #4
0
static void
gb_project_tree_actions__popover_create_file_cb (GbProjectTree    *self,
                                                 GFile            *file,
                                                 GFileType         file_type,
                                                 GbNewFilePopover *popover)
{
  GbTreeNode *selected;

  g_assert (GB_IS_PROJECT_TREE (self));
  g_assert (G_IS_FILE (file));
  g_assert ((file_type == G_FILE_TYPE_DIRECTORY) ||
            (file_type == G_FILE_TYPE_REGULAR));
  g_assert (GB_IS_NEW_FILE_POPOVER (popover));

  selected = gb_tree_get_selected (GB_TREE (self));

  g_assert (selected != NULL);
  g_assert (GB_IS_TREE_NODE (selected));

  if (file_type == G_FILE_TYPE_DIRECTORY)
    {
      g_file_make_directory_async (file,
                                   G_PRIORITY_DEFAULT,
                                   NULL, /* cancellable */
                                   gb_project_tree_actions__make_directory_cb,
                                   g_object_ref (selected));
    }
  else if (file_type == G_FILE_TYPE_REGULAR)
    {
      g_file_create_async (file,
                           G_FILE_CREATE_NONE,
                           G_PRIORITY_DEFAULT,
                           NULL, /* cancellable */
                           gb_project_tree_actions__create_cb,
                           g_object_ref (selected));
    }
  else
    {
      g_assert_not_reached ();
    }

  self->expanded_in_new = FALSE;

  gtk_widget_hide (GTK_WIDGET (popover));
  gtk_widget_destroy (GTK_WIDGET (popover));
}