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 void ide_autotools_build_system_constructed (GObject *object) { IdeAutotoolsBuildSystem *self = (IdeAutotoolsBuildSystem *)object; IdeBufferManager *buffer_manager; IdeContext *context; G_OBJECT_CLASS (ide_autotools_build_system_parent_class)->constructed (object); context = ide_object_get_context (IDE_OBJECT (self)); buffer_manager = ide_context_get_buffer_manager (context); /* * FIXME: * * We could setup and try to track all of the makefiles in the system * with inotify watches. That would require that 1) we can tell if a file * is an automake file (or a dependent included file), and 2) lots of * inotify watches. * * What is cheap, easy, and can be done right now is to just watch for save * events on files that look like makefiles, and invalidate the makecache. */ g_signal_connect_object (buffer_manager, "buffer-saved", G_CALLBACK (ide_autotools_build_system__buffer_saved_cb), self, G_CONNECT_SWAPPED); }
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); }
static void save_temp_response (GtkWidget *widget, gint response, gpointer user_data) { g_autoptr(IdeEditorView) self = user_data; g_autoptr(GFile) target = NULL; g_autoptr(IdeProgress) progress = NULL; GtkFileChooser *chooser = (GtkFileChooser *)widget; g_assert (GTK_IS_FILE_CHOOSER (chooser)); g_assert (IDE_IS_EDITOR_VIEW (self)); switch (response) { case GTK_RESPONSE_OK: target = gtk_file_chooser_get_file (chooser); break; case GTK_RESPONSE_CANCEL: default: break; } if (target != NULL) { IdeBufferManager *buffer_manager; IdeContext *context; IdeProject *project; IdeBuffer *buffer = IDE_BUFFER (self->document); g_autoptr(IdeFile) file = NULL; context = ide_buffer_get_context (buffer); project = ide_context_get_project (context); buffer_manager = ide_context_get_buffer_manager (context); file = ide_project_get_project_file (project, target); ide_buffer_set_file (buffer, file); ide_buffer_manager_save_file_async (buffer_manager, buffer, file, &progress, NULL, ide_editor_view_actions__save_temp_cb, g_object_ref (self)); } gtk_widget_destroy (widget); }
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_workbench_actions_save_all (GSimpleAction *action, GVariant *variant, gpointer user_data) { IdeWorkbench *workbench = user_data; IdeContext *context; IdeBufferManager *bufmgr; g_assert (IDE_IS_WORKBENCH (workbench)); context = ide_workbench_get_context (workbench); if (context == NULL) return; bufmgr = ide_context_get_buffer_manager (context); ide_buffer_manager_save_all_async (bufmgr, NULL, NULL, NULL); }
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 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 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 ide_editor_view_actions_save (GSimpleAction *action, GVariant *param, gpointer user_data) { IdeEditorView *self = user_data; IdeContext *context; IdeBufferManager *buffer_manager; IdeFile *file; IdeProgress *progress = NULL; IdeVcs *vcs; GFile *workdir; g_assert (IDE_IS_EDITOR_VIEW (self)); file = ide_buffer_get_file (IDE_BUFFER (self->document)); context = ide_buffer_get_context (IDE_BUFFER (self->document)); buffer_manager = ide_context_get_buffer_manager (context); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); if (ide_file_get_is_temporary (file)) { GtkDialog *dialog; GtkWidget *toplevel; GtkWidget *suggested; toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, "action", GTK_FILE_CHOOSER_ACTION_SAVE, "do-overwrite-confirmation", TRUE, "local-only", FALSE, "modal", TRUE, "select-multiple", FALSE, "show-hidden", FALSE, "transient-for", toplevel, "title", _("Save Document"), NULL); gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog), workdir, NULL); gtk_dialog_add_buttons (GTK_DIALOG (dialog), _("Cancel"), GTK_RESPONSE_CANCEL, _("Save"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); suggested = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); gtk_style_context_add_class (gtk_widget_get_style_context (suggested), GTK_STYLE_CLASS_SUGGESTED_ACTION); g_signal_connect (dialog, "response", G_CALLBACK (save_temp_response), g_object_ref (self)); gtk_window_present (GTK_WINDOW (dialog)); return; } ide_buffer_manager_save_file_async (buffer_manager, IDE_BUFFER (self->document), file, &progress, NULL, save_file_cb, g_object_ref (self)); g_object_bind_property (progress, "fraction", self->progress_bar, "fraction", G_BINDING_SYNC_CREATE); gtk_widget_show (GTK_WIDGET (self->progress_bar)); g_clear_object (&progress); }