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 gboolean load_split_async (GtkWidget *active_widget, const gchar *options, GAsyncReadyCallback callback, GError **error) { IdeWorkbench *workbench; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *file = NULL; gchar *file_path; SplitCallbackData *split_callback_data; g_assert (GTK_IS_WIDGET (active_widget)); g_assert (options != NULL); g_assert (callback != NULL); if (!(workbench = ide_widget_get_workbench (active_widget)) || !(context = ide_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)) { g_autofree gchar *workdir_path = NULL; workdir_path = g_file_get_path (workdir); file_path = g_build_filename (workdir_path, options, NULL); } else file_path = g_strdup (options); file = g_file_new_for_path (file_path); split_callback_data = g_slice_new (SplitCallbackData); split_callback_data->active_widget = g_object_ref (active_widget); split_callback_data->file_path = file_path; ide_workbench_open_files_async (workbench, &file, 1, "editor", IDE_WORKBENCH_OPEN_FLAGS_NO_VIEW, NULL, callback, split_callback_data); g_clear_object (&file); return TRUE; }
static gboolean gb_vim_command_vsplit (GtkWidget *active_widget, const gchar *command, const gchar *options, GError **error) { IdeWorkbench *workbench; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *file = NULL; gchar *file_path; SplitCallbackData *split_callback_data; GVariant *variant; g_assert (GTK_IS_WIDGET (active_widget)); if (!IDE_IS_LAYOUT_VIEW (active_widget)) return gb_vim_set_no_view_error (error); if (ide_str_empty0 (options)) { variant = g_variant_new_string (""); ide_widget_action (GTK_WIDGET (active_widget), "view-stack", "split-left", variant); } else { if (!(workbench = ide_widget_get_workbench (active_widget)) || !(context = ide_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; } file_path = g_strdup (options); if (!g_path_is_absolute (file_path)) file_path = g_build_filename (g_file_get_path (workdir), file_path, NULL); file = g_file_new_for_path (file_path); split_callback_data = g_slice_new (SplitCallbackData); split_callback_data->active_widget = g_object_ref (active_widget); split_callback_data->file_path = file_path; ide_workbench_open_files_async (workbench, &file, 1, "editor", IDE_WORKBENCH_OPEN_FLAGS_BACKGROUND, NULL, gb_vim_command_vsplit_cb, split_callback_data); g_clear_object (&file); } return TRUE; }
static void ide_editor_perspective_actions_open_file (GSimpleAction *action, GVariant *variant, gpointer user_data) { IdeEditorPerspective *self = user_data; GtkFileChooserNative *chooser; IdeWorkbench *workbench; gint ret; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (IDE_IS_EDITOR_PERSPECTIVE (self)); workbench = ide_widget_get_workbench (GTK_WIDGET (self)); if (workbench == NULL) { g_warning ("Failed to locate workbench"); return; } chooser = gtk_file_chooser_native_new (_("Open File"), GTK_WINDOW (workbench), GTK_FILE_CHOOSER_ACTION_OPEN, _("Open"), _("Cancel")); gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE); gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE); ret = gtk_native_dialog_run (GTK_NATIVE_DIALOG (chooser)); if (ret == GTK_RESPONSE_ACCEPT) { g_autoptr(GPtrArray) ar = NULL; GSList *files; ar = g_ptr_array_new_with_free_func (g_object_unref); files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (chooser)); for (const GSList *iter = files; iter; iter = iter->next) g_ptr_array_add (ar, iter->data); g_slist_free (files); if (ar->len > 0) ide_workbench_open_files_async (workbench, (GFile **)ar->pdata, ar->len, "editor", IDE_WORKBENCH_OPEN_FLAGS_NONE, NULL, NULL, NULL); } gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (chooser)); }
static GFile * find_workdir (GtkWidget *active_widget) { g_autoptr(GFile) workdir = NULL; IdeWorkbench *workbench; IdeContext *context; if (!(workbench = ide_widget_get_workbench (active_widget)) || !(context = ide_workbench_get_context (workbench)) || !(workdir = ide_context_ref_workdir (context))) return NULL; return g_steal_pointer (&workdir); }
static gboolean is_topmost_workspace_with_editor (GbpEditorWorkspaceAddin *self) { IdeWorkbench *workbench; IdeWorkspace *topmost = NULL; g_assert (IDE_IS_MAIN_THREAD ()); g_assert (GBP_IS_EDITOR_WORKSPACE_ADDIN (self)); workbench = ide_widget_get_workbench (GTK_WIDGET (self->workspace)); ide_workbench_foreach_workspace (workbench, find_topmost_editor, &topmost); return topmost == self->workspace; }
static gboolean load_split_async (GtkWidget *active_widget, const gchar *options, GAsyncReadyCallback callback, GError **error) { g_autoptr(GFile) workdir = NULL; g_autoptr(GFile) file = NULL; g_autofree gchar *file_path = NULL; SplitCallbackData *split_callback_data; g_assert (GTK_IS_WIDGET (active_widget)); g_assert (options != NULL); g_assert (callback != NULL); if (!(workdir = find_workdir (active_widget))) { 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)) { g_autofree gchar *workdir_path = NULL; workdir_path = g_file_get_path (workdir); file_path = g_build_filename (workdir_path, options, NULL); } else file_path = g_strdup (options); file = g_file_new_for_path (file_path); split_callback_data = g_slice_new0 (SplitCallbackData); split_callback_data->active_widget = g_object_ref (active_widget); split_callback_data->file_path = g_steal_pointer (&file_path); ide_workbench_open_async (ide_widget_get_workbench (active_widget), file, "editor", IDE_BUFFER_OPEN_FLAGS_NO_VIEW, NULL, callback, split_callback_data); return TRUE; }
static void ide_editor_frame__source_view_focus_location (IdeEditorFrame *self, IdeSourceLocation *location, IdeSourceView *source_view) { IdeWorkbench *workbench; IdePerspective *editor; g_assert (IDE_IS_EDITOR_FRAME (self)); g_assert (location != NULL); g_assert (IDE_IS_SOURCE_VIEW (source_view)); workbench = ide_widget_get_workbench (GTK_WIDGET (self)); editor = ide_workbench_get_perspective_by_name (workbench, "editor"); ide_editor_perspective_focus_location (IDE_EDITOR_PERSPECTIVE (editor), location); }
static gboolean gb_vim_command_edit (GtkWidget *active_widget, const gchar *command, const gchar *options, GError **error) { IdeWorkbench *workbench; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *file = NULL; g_assert (GTK_IS_WIDGET (active_widget)); if (ide_str_empty0 (options)) { ide_widget_action (GTK_WIDGET (active_widget), "win", "open-with-dialog", NULL); return TRUE; } if (!(workbench = ide_widget_get_workbench (active_widget)) || !(context = ide_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); ide_workbench_open_files_async (workbench, &file, 1, "editor", IDE_WORKBENCH_OPEN_FLAGS_NONE, NULL, NULL, NULL); g_clear_object (&file); return TRUE; }
static void ide_editor_perspective_actions_new_file (GSimpleAction *action, GVariant *variant, gpointer user_data) { IdeEditorPerspective *self = user_data; IdeWorkbench *workbench; IdeContext *context; IdeBufferManager *bufmgr; IdeBuffer *buffer; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (IDE_IS_EDITOR_PERSPECTIVE (self)); workbench = ide_widget_get_workbench (GTK_WIDGET (self)); context = ide_workbench_get_context (workbench); bufmgr = ide_context_get_buffer_manager (context); buffer = ide_buffer_manager_create_temporary_buffer (bufmgr); g_clear_object (&buffer); }
static void ide_workbench_show_parents (GtkWidget *widget) { GtkWidget *parent; g_assert (GTK_IS_WIDGET (widget)); parent = gtk_widget_get_parent (widget); if (IDE_IS_LAYOUT_PANE (widget)) pnl_dock_revealer_set_reveal_child (PNL_DOCK_REVEALER (widget), TRUE); if (IDE_IS_PERSPECTIVE (widget)) ide_workbench_set_visible_perspective (ide_widget_get_workbench (widget), IDE_PERSPECTIVE (widget)); if (GTK_IS_STACK (parent)) gtk_stack_set_visible_child (GTK_STACK (parent), widget); if (parent != NULL) ide_workbench_show_parents (parent); }
static void find_other_file_cb (GObject *object, GAsyncResult *result, gpointer user_data) { g_autoptr(IdeEditorView) self = user_data; g_autoptr(IdeFile) ret = NULL; IdeFile *file = (IdeFile *)object; ret = ide_file_find_other_finish (file, result, NULL); if (ret != NULL) { IdeWorkbench *workbench; GFile *gfile; IdeWorkbenchOpenFlags flags; gfile = ide_file_get_file (ret); workbench = ide_widget_get_workbench (GTK_WIDGET (self)); flags = WORKBENCH_OPEN_FLAGS_NONE; ide_workbench_open_files_async (workbench, &gfile, 1, "editor", flags, NULL, NULL, NULL); } }
static void ide_editor_frame_actions_spellcheck (GSimpleAction *action, GVariant *variant, gpointer user_data) { IdeEditorFrame *self = user_data; IdeWorkbench *workbench; IdePerspective *editor; gboolean state; g_assert (IDE_IS_EDITOR_FRAME (self)); state = !!g_variant_get_int32 (variant); if (state == TRUE) { if (IDE_IS_SOURCE_VIEW (self->source_view) && NULL != (workbench = ide_widget_get_workbench (GTK_WIDGET (self))) && NULL != (editor = ide_workbench_get_perspective_by_name (workbench, "editor"))) ide_editor_perspective_show_spellchecker (IDE_EDITOR_PERSPECTIVE (editor), self->source_view); } else gtk_widget_grab_focus (GTK_WIDGET (self->source_view)); }
static gboolean gb_vim_command_bprevious (GtkWidget *active_widget, const gchar *command, const gchar *options, GError **error) { IdeWorkbench *workbench; IdeContext *context; IdeBufferManager *bufmgr; guint n_buffers; g_assert (GTK_IS_WIDGET (active_widget)); workbench = ide_widget_get_workbench (GTK_WIDGET (active_widget)); context = ide_workbench_get_context (workbench); bufmgr = ide_context_get_buffer_manager (context); n_buffers = ide_buffer_manager_get_n_buffers (bufmgr); if (n_buffers > 0) ide_widget_action (GTK_WIDGET (active_widget), "view-stack", "previous-view", NULL); return TRUE; }
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); }
static gboolean gb_vim_command_edit (GtkWidget *active_widget, const gchar *command, const gchar *options, GError **error) { g_autoptr(GFile) workdir = NULL; g_autoptr(GFile) file = NULL; IdeWorkbench *workbench; g_assert (GTK_IS_WIDGET (active_widget)); if (ide_str_empty0 (options)) { dzl_gtk_widget_action (GTK_WIDGET (active_widget), "workbench", "open", NULL); return TRUE; } if (!(workdir = find_workdir (active_widget))) { 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); workbench = ide_widget_get_workbench (active_widget); ide_workbench_open_async (workbench, file, "editor", 0, NULL, NULL, NULL); return TRUE; }
static gboolean open_after_timeout (gpointer user_data) { IdeGitCloneWidget *self; IdeWorkbench *workbench; g_autoptr(GTask) task = user_data; g_autoptr(GError) error = NULL; CloneRequest *req; IDE_ENTRY; g_assert (G_IS_TASK (task)); self = g_task_get_source_object (task); req = g_task_get_task_data (task); workbench = ide_widget_get_workbench (GTK_WIDGET (self)); g_assert (req != NULL); g_assert (IDE_IS_GIT_CLONE_WIDGET (self)); g_assert (IDE_IS_WORKBENCH (workbench)); if (error) { g_warning ("%s", error->message); gtk_label_set_label (self->clone_error_label, error->message); gtk_widget_show (GTK_WIDGET (self->clone_error_label)); } else { ide_workbench_open_project_async (workbench, req->project_file, NULL, NULL, NULL); } g_task_return_boolean (task, TRUE); IDE_RETURN (G_SOURCE_REMOVE); }
static void ide_editor_perspective_focus_location_full (IdeEditorPerspective *self, IdeSourceLocation *location, gboolean open_if_not_found) { struct { IdeFile *file; IdeEditorView *view; } lookup = { 0 }; GtkWidget *stack; guint line; guint line_offset; IDE_ENTRY; g_assert (IDE_IS_EDITOR_PERSPECTIVE (self)); g_assert (location != NULL); lookup.file = ide_source_location_get_file (location); lookup.view = NULL; if (lookup.file == NULL) { g_warning ("IdeSourceLocation does not contain a file"); IDE_EXIT; } #ifdef IDE_ENABLE_TRACE { const gchar *path = ide_file_get_path (lookup.file); IDE_TRACE_MSG ("Locating %s, open_if_not_found=%d", path, open_if_not_found); } #endif ide_perspective_views_foreach (IDE_PERSPECTIVE (self), ide_editor_perspective_find_source_location, &lookup); if (!open_if_not_found && lookup.view == NULL) IDE_EXIT; if (lookup.view == NULL) { FocusLocation *state; IdeBufferManager *bufmgr; IdeWorkbench *workbench; IdeContext *context; workbench = ide_widget_get_workbench (GTK_WIDGET (self)); context = ide_workbench_get_context (workbench); bufmgr = ide_context_get_buffer_manager (context); state = g_slice_new0 (FocusLocation); state->self = g_object_ref (self); state->location = ide_source_location_ref (location); ide_buffer_manager_load_file_async (bufmgr, lookup.file, FALSE, IDE_WORKBENCH_OPEN_FLAGS_NONE, NULL, NULL, ide_editor_perspective_focus_location_cb, state); IDE_EXIT; } line = ide_source_location_get_line (location); line_offset = ide_source_location_get_line_offset (location); stack = gtk_widget_get_ancestor (GTK_WIDGET (lookup.view), IDE_TYPE_LAYOUT_STACK); ide_layout_stack_set_visible_child (IDE_LAYOUT_STACK (stack), IDE_LAYOUT_VIEW (lookup.view)); ide_editor_view_scroll_to_line_offset (lookup.view, line, line_offset); IDE_EXIT; }
static void gb_vim_complete_edit_files (GtkWidget *active_widget, const gchar *command, GPtrArray *ar, const gchar *prefix) { IdeWorkbench *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 = ide_widget_get_workbench (GTK_WIDGET (active_widget))) || !(context = ide_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; GFileInfo *descendent; const gchar *slash; const gchar *partial_name; g_autofree gchar *prefix_dir = NULL; #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))) { partial_name = slash + 1; prefix_dir = g_strndup (prefix, slash - prefix + 1); } else { partial_name = prefix; } 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, partial_name)) { gchar *completed_command; const gchar *descendent_name; g_autofree gchar *full_path = NULL; g_autofree gchar *parent_path = NULL; parent_path = g_file_get_path (parent); descendent_name = g_file_info_get_name (descendent); full_path = g_build_filename (parent_path, descendent_name, NULL); if (prefix[0] == G_DIR_SEPARATOR) completed_command = g_strdup_printf ("%s %s", command, full_path); else if (strchr (prefix, G_DIR_SEPARATOR) == NULL) completed_command = g_strdup_printf ("%s %s", command, descendent_name); else completed_command = g_strdup_printf ("%s %s%s", command, prefix_dir, descendent_name); IDE_TRACE_MSG ("edit completion: %s", completed_command); g_ptr_array_add (ar, completed_command); } g_object_unref (descendent); } IDE_EXIT; } IDE_EXIT; }
static void ide_debugger_editor_addin_load (IdeEditorAddin *addin, IdeEditorSurface *editor) { IdeDebuggerEditorAddin *self = (IdeDebuggerEditorAddin *)addin; IdeContext *context; IdeRunManager *run_manager; IdeDebugManager *debug_manager; IDE_ENTRY; g_assert (IDE_IS_DEBUGGER_EDITOR_ADDIN (self)); g_assert (IDE_IS_EDITOR_SURFACE (editor)); self->editor = editor; self->workbench = ide_widget_get_workbench (GTK_WIDGET (editor)); if (!ide_workbench_has_project (self->workbench)) return; context = ide_widget_get_context (GTK_WIDGET (editor)); run_manager = ide_run_manager_from_context (context); debug_manager = ide_debug_manager_from_context (context); ide_debugger_editor_addin_add_ui (self); ide_run_manager_add_handler (run_manager, "debugger", _("Run with Debugger"), "builder-debugger-symbolic", "F5", debugger_run_handler, g_object_ref (self), g_object_unref); self->debugger_signals = dzl_signal_group_new (IDE_TYPE_DEBUGGER); dzl_signal_group_connect_swapped (self->debugger_signals, "log", G_CALLBACK (debugger_log), self); dzl_signal_group_connect_swapped (self->debugger_signals, "stopped", G_CALLBACK (debugger_stopped), self); self->debug_manager_signals = dzl_signal_group_new (IDE_TYPE_DEBUG_MANAGER); dzl_signal_group_connect_swapped (self->debug_manager_signals, "notify::active", G_CALLBACK (debug_manager_notify_active), self); dzl_signal_group_connect_swapped (self->debug_manager_signals, "notify::debugger", G_CALLBACK (debug_manager_notify_debugger), self); dzl_signal_group_set_target (self->debug_manager_signals, debug_manager); IDE_EXIT; }