Ejemplo n.º 1
0
static gboolean
find_child_node (IdeTree     *tree,
                 IdeTreeNode *node,
                 IdeTreeNode *child,
                 gpointer    user_data)
{
  const gchar *name = user_data;
  GObject *item;

  g_assert (IDE_IS_TREE (tree));
  g_assert (IDE_IS_TREE_NODE (node));
  g_assert (IDE_IS_TREE_NODE (child));

  item = ide_tree_node_get_item (child);

  if (GB_IS_PROJECT_FILE (item))
    {
      const gchar *item_name;

      item_name = gb_project_file_get_display_name (GB_PROJECT_FILE (item));

      return ide_str_equal0 (item_name, name);
    }

  return FALSE;
}
Ejemplo n.º 2
0
static void
gb_project_tree_builder_node_popup (IdeTreeBuilder *builder,
                                    IdeTreeNode    *node,
                                    GMenu          *menu)
{
  GObject *item;
  IdeVcs *vcs;
  GFile *workdir;
  GFile *file;

  g_assert (GB_IS_PROJECT_TREE_BUILDER (builder));
  g_assert (IDE_IS_TREE_NODE (node));
  g_assert (G_IS_MENU (menu));

  item = ide_tree_node_get_item (node);
  vcs = get_vcs (node);
  workdir = ide_vcs_get_working_directory (vcs);

  if (GB_IS_PROJECT_FILE (item) &&
      (file = gb_project_file_get_file (GB_PROJECT_FILE (item))) &&
      !g_file_equal (file, workdir))
    {
      GMenu *mime_section;

      mime_section = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT,
                                                     "gb-project-tree-open-by-mime-section");
      populate_mime_handlers (mime_section, GB_PROJECT_FILE (item));
    }
}
Ejemplo n.º 3
0
static gboolean
find_files_node (IdeTree     *tree,
                 IdeTreeNode *node,
                 IdeTreeNode *child,
                 gpointer    user_data)
{
  GObject *item;

  g_assert (IDE_IS_TREE (tree));
  g_assert (IDE_IS_TREE_NODE (node));
  g_assert (IDE_IS_TREE_NODE (child));

  item = ide_tree_node_get_item (child);

  return GB_IS_PROJECT_FILE (item);
}
Ejemplo n.º 4
0
void
_ide_tree_builder_build_node (IdeTreeBuilder *builder,
                              IdeTreeNode    *node)
{
	g_return_if_fail (IDE_IS_TREE_BUILDER (builder));
	g_return_if_fail (IDE_IS_TREE_NODE (node));

  g_signal_emit (builder, signals [BUILD_NODE], 0, node);
}
Ejemplo n.º 5
0
void
_ide_tree_builder_node_unselected (IdeTreeBuilder *builder,
                                   IdeTreeNode    *node)
{
	g_return_if_fail (IDE_IS_TREE_BUILDER (builder));
	g_return_if_fail (IDE_IS_TREE_NODE (node));

  g_signal_emit (builder, signals [NODE_UNSELECTED], 0, node);
}
Ejemplo n.º 6
0
void
_ide_tree_builder_node_popup (IdeTreeBuilder *builder,
                              IdeTreeNode    *node,
                              GMenu          *menu)
{
  g_return_if_fail (IDE_IS_TREE_BUILDER (builder));
  g_return_if_fail (IDE_IS_TREE_NODE (node));
  g_return_if_fail (G_IS_MENU (menu));

  g_signal_emit (builder, signals [NODE_POPUP], 0, node, menu);
}
Ejemplo n.º 7
0
gboolean
_ide_tree_builder_node_activated (IdeTreeBuilder *builder,
                                  IdeTreeNode    *node)
{
  gboolean ret = FALSE;

	g_return_val_if_fail (IDE_IS_TREE_BUILDER(builder), FALSE);
	g_return_val_if_fail (IDE_IS_TREE_NODE(node), FALSE);

  g_signal_emit (builder, signals [NODE_ACTIVATED], 0, node, &ret);

	return ret;
}
Ejemplo n.º 8
0
static IdeVcs *
get_vcs (IdeTreeNode *node)
{
  IdeTree *tree;
  IdeTreeNode *root;
  IdeContext *context;

  g_assert (IDE_IS_TREE_NODE (node));

  tree = ide_tree_node_get_tree (node);
  root = ide_tree_get_root (tree);
  context = IDE_CONTEXT (ide_tree_node_get_item (root));

  return ide_context_get_vcs (context);
}
Ejemplo n.º 9
0
static void
gbp_grep_tree_addin_selection_changed (IdeTreeAddin *addin,
                                       IdeTreeNode  *node)
{
  GbpGrepTreeAddin *self = (GbpGrepTreeAddin *)addin;
  gboolean enabled;

  g_assert (IDE_IS_MAIN_THREAD ());
  g_assert (GBP_IS_GREP_TREE_ADDIN (self));
  g_assert (!node || IDE_IS_TREE_NODE (node));

  enabled = node && ide_tree_node_holds (node, IDE_TYPE_PROJECT_FILE);

  dzl_gtk_widget_action_set (GTK_WIDGET (self->tree), "grep", "find-in-files",
                             "enabled", enabled,
                             NULL);
}
Ejemplo n.º 10
0
static void
build_context (GbProjectTreeBuilder *self,
               IdeTreeNode          *node)
{
  g_autoptr(GbProjectFile) item = NULL;
  g_autoptr(GFileInfo) file_info = NULL;
  g_autofree gchar *name = NULL;
  IdeTreeNode *child;
  IdeContext *context;
  IdeProject *project;
  IdeVcs *vcs;
  GFile *workdir;

  g_return_if_fail (GB_IS_PROJECT_TREE_BUILDER (self));
  g_return_if_fail (IDE_IS_TREE_NODE (node));

  context = IDE_CONTEXT (ide_tree_node_get_item (node));
  vcs = ide_context_get_vcs (context);
  workdir = ide_vcs_get_working_directory (vcs);
  project = ide_context_get_project (context);

  file_info = g_file_info_new ();

  g_file_info_set_file_type (file_info, G_FILE_TYPE_DIRECTORY);

  name = g_file_get_basename (workdir);
  g_file_info_set_name (file_info, name);
  g_file_info_set_display_name (file_info, name);

  item = g_object_new (GB_TYPE_PROJECT_FILE,
                       "file", workdir,
                       "file-info", file_info,
                       NULL);

  child = g_object_new (IDE_TYPE_TREE_NODE,
                        "item", item,
                        "icon-name", "folder-symbolic",
                        NULL);
  g_object_bind_property (project, "name", child, "text", G_BINDING_SYNC_CREATE);
  ide_tree_node_append (node, child);
}
Ejemplo n.º 11
0
static void
build_file (GbProjectTreeBuilder *self,
            IdeTreeNode          *node)
{
  g_autoptr(GFileEnumerator) enumerator = NULL;
  GbProjectFile *project_file;
  gpointer file_info_ptr;
  IdeVcs *vcs;
  GFile *file;
  IdeTree *tree;
  gint count = 0;
  gboolean show_ignored_files;

  g_return_if_fail (GB_IS_PROJECT_TREE_BUILDER (self));
  g_return_if_fail (IDE_IS_TREE_NODE (node));

  project_file = GB_PROJECT_FILE (ide_tree_node_get_item (node));

  tree = ide_tree_builder_get_tree (IDE_TREE_BUILDER (self));
  show_ignored_files = gb_project_tree_get_show_ignored_files (GB_PROJECT_TREE (tree));

  vcs = get_vcs (node);

  /*
   * TODO: Make this all async.
   */

  if (!gb_project_file_get_is_directory (project_file))
    return;

  file = gb_project_file_get_file (project_file);

  enumerator = g_file_enumerate_children (file,
                                          G_FILE_ATTRIBUTE_STANDARD_NAME","
                                          G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME","
                                          G_FILE_ATTRIBUTE_STANDARD_TYPE,
                                          G_FILE_QUERY_INFO_NONE,
                                          NULL,
                                          NULL);

  if (enumerator == NULL)
    return;

  while ((file_info_ptr = g_file_enumerator_next_file (enumerator, NULL, NULL)))
    {
      g_autoptr(GFileInfo) item_file_info = file_info_ptr;
      g_autoptr(GFile) item_file = NULL;
      g_autoptr(GbProjectFile) item = NULL;
      IdeTreeNode *child;
      const gchar *name;
      const gchar *display_name;
      const gchar *icon_name;
      gboolean ignored;

      name = g_file_info_get_name (item_file_info);
      item_file = g_file_get_child (file, name);

      ignored = ide_vcs_is_ignored (vcs, item_file, NULL);
      if (ignored && !show_ignored_files)
        continue;

      item = gb_project_file_new (item_file, item_file_info);

      display_name = gb_project_file_get_display_name (item);
      icon_name = gb_project_file_get_icon_name (item);

      child = g_object_new (IDE_TYPE_TREE_NODE,
                            "icon-name", icon_name,
                            "text", display_name,
                            "item", item,
                            "use-dim-label", ignored,
                            NULL);

      ide_tree_node_insert_sorted (node, child, compare_nodes_func, self);

      if (g_file_info_get_file_type (item_file_info) == G_FILE_TYPE_DIRECTORY)
        ide_tree_node_set_children_possible (child, TRUE);

      count++;
    }

  /*
   * If we didn't add any children to this node, insert an empty node to
   * notify the user that nothing was found.
   */
  if (count == 0)
    {
      IdeTreeNode *child;

      child = g_object_new (IDE_TYPE_TREE_NODE,
                            "icon-name", NULL,
                            "text", _("Empty"),
                            "use-dim-label", TRUE,
                            NULL);
      ide_tree_node_append (node, child);
    }
}