static void gb_editor_view_actions_reload_buffer (GSimpleAction *action, GVariant *param, gpointer user_data) { GbEditorView *self = user_data; IdeContext *context; IdeBufferManager *buffer_manager; IdeFile *file; g_autoptr(IdeProgress) progress = NULL; g_assert (GB_IS_EDITOR_VIEW (self)); context = ide_buffer_get_context (IDE_BUFFER (self->document)); file = ide_buffer_get_file (IDE_BUFFER (self->document)); buffer_manager = ide_context_get_buffer_manager (context); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (self->progress_bar), 0.0); gtk_widget_show (GTK_WIDGET (self->progress_bar)); ide_buffer_manager_load_file_async (buffer_manager, file, TRUE, &progress, NULL, gb_editor_view_actions_reload_buffer_cb, g_object_ref (self)); g_object_bind_property (progress, "fraction", self->progress_bar, "fraction", G_BINDING_SYNC_CREATE); }
static IdeLayoutView * ide_editor_perspective_create_view (IdeEditorPerspective *self, const gchar *uri, IdeLayoutGrid *grid) { g_autoptr(GFile) file = NULL; g_autoptr(IdeFile) ifile = NULL; IdeBufferManager *bufmgr; IdeContext *context; IdeBuffer *buffer; g_assert (IDE_IS_EDITOR_PERSPECTIVE (self)); g_assert (uri != NULL); g_assert (IDE_IS_LAYOUT_GRID (grid)); g_debug ("Creating view for %s", uri); context = ide_widget_get_context (GTK_WIDGET (self)); file = g_file_new_for_uri (uri); ifile = ide_file_new (context, file); bufmgr = ide_context_get_buffer_manager (context); buffer = ide_buffer_manager_find_buffer (bufmgr, file); /* * If we failed to locate an already loaded buffer, we need to start * loading the buffer. But that could take some time. Either way, after * we start the loading process, we can access the buffer and we'll * display it while it loads. */ if (buffer == NULL) { /* TODO: We probably need a generic "Open" API that allows * us to handle any sort of API and redirect it to a * given view provider. */ ide_buffer_manager_load_file_async (bufmgr, ifile, FALSE, IDE_WORKBENCH_OPEN_FLAGS_NO_VIEW, NULL, NULL, ide_editor_perspective_load_file_cb, g_object_ref (self)); buffer = ide_buffer_manager_find_buffer (bufmgr, file); } return g_object_new (IDE_TYPE_EDITOR_VIEW, "buffer", buffer, "visible", TRUE, NULL); }
void gb_view_stack_focus_location (GbViewStack *self, IdeSourceLocation *location) { IdeBufferManager *buffer_manager; IdeBuffer *buffer; IdeFile *file; GFile *gfile; g_return_if_fail (GB_IS_VIEW_STACK (self)); g_return_if_fail (location != NULL); if (self->context == NULL) return; file = ide_source_location_get_file (location); gfile = ide_file_get_file (file); g_assert (file != NULL); g_assert (IDE_IS_FILE (file)); gfile = ide_file_get_file (file); buffer_manager = ide_context_get_buffer_manager (self->context); buffer = ide_buffer_manager_find_buffer (buffer_manager, gfile); if (buffer != NULL && GB_IS_DOCUMENT (buffer)) { GtkWidget *active_view; gb_view_stack_focus_document (self, GB_DOCUMENT (buffer)); active_view = gb_view_stack_get_active_view (self); g_assert (GB_DOCUMENT (buffer) == gb_view_get_document (GB_VIEW (active_view))); gb_view_navigate_to (GB_VIEW (active_view), location); } else { g_autoptr(GTask) task = NULL; task = g_task_new (self, NULL, NULL, NULL); g_task_set_task_data (task, ide_source_location_ref (location), (GDestroyNotify)ide_source_location_unref); ide_buffer_manager_load_file_async (buffer_manager, file, FALSE, NULL, NULL, gb_view_stack__navigate_to_load_cb, g_object_ref (task)); } }
static void ide_editor_surface_actions_new_file (GSimpleAction *action, GVariant *variant, gpointer user_data) { IdeEditorSurface *self = user_data; IdeBufferManager *bufmgr; IdeContext *context; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (IDE_IS_EDITOR_SURFACE (self)); context = ide_widget_get_context (GTK_WIDGET (self)); bufmgr = ide_buffer_manager_from_context (context); ide_buffer_manager_load_file_async (bufmgr, NULL, IDE_BUFFER_OPEN_FLAGS_NONE, NULL, NULL, NULL, NULL); }
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; }