static void gb_project_tree_actions__rename_file_cb (GbProjectTree *self, GFile *orig_file, GFile *new_file, GbRenameFilePopover *popover) { GbWorkbench *workbench; IdeContext *context; IdeProject *project; g_assert (GB_IS_PROJECT_TREE (self)); g_assert (G_IS_FILE (orig_file)); g_assert (G_IS_FILE (new_file)); g_assert (GTK_IS_POPOVER (popover)); workbench = gb_widget_get_workbench (GTK_WIDGET (self)); context = gb_workbench_get_context (workbench); project = ide_context_get_project (context); /* todo: set busin spinner in popover */ g_object_set_data_full (G_OBJECT (popover), "G_FILE", g_object_ref (new_file), g_object_unref); ide_project_rename_file_async (project, orig_file, new_file, NULL, gb_project_tree_actions__project_rename_file_cb, g_object_ref (popover)); }
static void gb_project_tree_actions_move_to_trash (GSimpleAction *action, GVariant *param, gpointer user_data) { GbProjectTree *self = user_data; GbWorkbench *workbench; IdeContext *context; IdeProject *project; GbTreeNode *node; GFile *file; GObject *item; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (GB_IS_PROJECT_TREE (self)); workbench = gb_widget_get_workbench (GTK_WIDGET (self)); context = gb_workbench_get_context (workbench); project = ide_context_get_project (context); if (!(node = gb_tree_get_selected (GB_TREE (self))) || !(item = gb_tree_node_get_item (node)) || !IDE_IS_PROJECT_FILE (item) || !(file = ide_project_file_get_file (IDE_PROJECT_FILE (item)))) return; ide_project_trash_file_async (project, file, NULL, gb_project_tree_actions__trash_file_cb, g_object_ref (self)); }
static void gb_terminal_respawn (GbTerminalView *self, VteTerminal *terminal) { g_autoptr(GPtrArray) args = NULL; g_autofree gchar *workpath = NULL; GtkWidget *toplevel; GError *error = NULL; IdeContext *context; IdeVcs *vcs; GFile *workdir; GPid child_pid; gint64 now; g_assert (GB_IS_TERMINAL_VIEW (self)); vte_terminal_reset (terminal, TRUE, TRUE); toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); if (!GB_IS_WORKBENCH (toplevel)) return; /* Prevent flapping */ now = g_get_monotonic_time (); if ((now - self->last_respawn) < (G_USEC_PER_SEC / 10)) return; self->last_respawn = now; context = gb_workbench_get_context (GB_WORKBENCH (toplevel)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); workpath = g_file_get_path (workdir); args = g_ptr_array_new_with_free_func (g_free); g_ptr_array_add (args, vte_get_user_shell ()); g_ptr_array_add (args, NULL); vte_terminal_spawn_sync (terminal, VTE_PTY_DEFAULT | VTE_PTY_NO_LASTLOG | VTE_PTY_NO_UTMP | VTE_PTY_NO_WTMP, workpath, (gchar **)args->pdata, NULL, G_SPAWN_DEFAULT, NULL, NULL, &child_pid, NULL, &error); if (error != NULL) { g_warning ("%s", error->message); g_clear_error (&error); return; } vte_terminal_watch_child (terminal, child_pid); }
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); }
IdeContext * gb_widget_get_context (GtkWidget *widget) { GbWorkbench *workbench; IdeContext *context = NULL; g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); if ((workbench = gb_widget_get_workbench (widget))) context = gb_workbench_get_context (workbench); g_return_val_if_fail (!context || IDE_IS_CONTEXT (context), NULL); return context; }
IdeSearchEngine * gb_search_box_get_search_engine (GbSearchBox *self) { IdeContext *context; IdeSearchEngine *search_engine; g_return_val_if_fail (GB_IS_SEARCH_BOX (self), NULL); if (self->workbench == NULL) return NULL; context = gb_workbench_get_context (self->workbench); if (context == NULL) return NULL; search_engine = ide_context_get_search_engine (context); return search_engine; }
static gboolean gb_vim_command_edit (GtkSourceView *source_view, const gchar *command, const gchar *options, GError **error) { GbWorkbench *workbench; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *file = NULL; if (ide_str_empty0 (options)) { gb_widget_activate_action (GTK_WIDGET (source_view), "workbench", "open", NULL); return TRUE; } if (!(workbench = gb_widget_get_workbench (GTK_WIDGET (source_view))) || !(context = gb_workbench_get_context (workbench)) || !(vcs = ide_context_get_vcs (context)) || !(workdir = ide_vcs_get_working_directory (vcs))) { g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_SOURCE_VIEW, _("Failed to locate working directory")); return FALSE; } if (g_path_is_absolute (options)) file = g_file_new_for_path (options); else file = g_file_get_child (workdir, options); gb_workbench_open (workbench, file); g_clear_object (&file); return TRUE; }
static void gb_vim_complete_edit_files (GtkSourceView *source_view, const gchar *command, GPtrArray *ar, const gchar *prefix) { GbWorkbench *workbench; IdeContext *context; IdeVcs *vcs; GFile *workdir; g_autoptr(GFile) child = NULL; g_autoptr(GFile) parent = NULL; IDE_ENTRY; g_assert (command); g_assert (ar); g_assert (prefix); if (!(workbench = gb_widget_get_workbench (GTK_WIDGET (source_view))) || !(context = gb_workbench_get_context (workbench)) || !(vcs = ide_context_get_vcs (context)) || !(workdir = ide_vcs_get_working_directory (vcs))) IDE_EXIT; child = g_file_get_child (workdir, prefix); if (g_file_query_exists (child, NULL)) { if (g_file_query_file_type (child, 0, NULL) == G_FILE_TYPE_DIRECTORY) { g_autoptr(GFileEnumerator) fe = NULL; GFileInfo *descendent; if (!g_str_has_suffix (prefix, "/")) { g_ptr_array_add (ar, g_strdup_printf ("%s %s/", command, prefix)); IDE_EXIT; } fe = g_file_enumerate_children (child, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (fe == NULL) IDE_EXIT; while ((descendent = g_file_enumerator_next_file (fe, NULL, NULL))) { const gchar *name; name = g_file_info_get_display_name (descendent); g_ptr_array_add (ar, g_strdup_printf ("%s %s%s", command, prefix, name)); g_object_unref (descendent); } IDE_EXIT; } } parent = g_file_get_parent (child); if (parent != NULL) { g_autoptr(GFileEnumerator) fe = NULL; g_autofree gchar *relpath = NULL; GFileInfo *descendent; const gchar *slash; relpath = g_file_get_relative_path (workdir, parent); if (relpath && g_str_has_prefix (relpath, "./")) { gchar *tmp = relpath; relpath = g_strdup (relpath + 2); g_free (tmp); } #ifdef IDE_ENABLE_TRACE { g_autofree gchar *parent_path = g_file_get_path (parent); IDE_TRACE_MSG ("parent_path: %s", parent_path); } #endif if ((slash = strrchr (prefix, G_DIR_SEPARATOR))) prefix = slash + 1; fe = g_file_enumerate_children (parent, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (fe == NULL) IDE_EXIT; while ((descendent = g_file_enumerator_next_file (fe, NULL, NULL))) { const gchar *name; name = g_file_info_get_display_name (descendent); IDE_TRACE_MSG ("name=%s prefix=%s", name, prefix); if (name && g_str_has_prefix (name, prefix)) { gchar *path; if (relpath) path = g_strdup_printf ("%s %s/%s", command, relpath, name); else path = g_strdup_printf ("%s %s", command, name); IDE_TRACE_MSG ("edit completion: %s", path); g_ptr_array_add (ar, path); } g_object_unref (descendent); } IDE_EXIT; } IDE_EXIT; }