gboolean gb_document_get_modified (GbDocument *document) { g_return_val_if_fail (GB_IS_DOCUMENT (document), FALSE); return GB_DOCUMENT_GET_IFACE (document)->get_modified (document); }
gboolean gb_document_get_read_only (GbDocument *document) { g_return_val_if_fail (GB_IS_DOCUMENT (document), FALSE); if (GB_DOCUMENT_GET_IFACE (document)->get_read_only) return GB_DOCUMENT_GET_IFACE (document)->get_read_only (document); return FALSE; }
gboolean gb_document_is_untitled (GbDocument *document) { g_return_val_if_fail (GB_IS_DOCUMENT (document), FALSE); if (GB_DOCUMENT_GET_IFACE (document)->is_untitled) return GB_DOCUMENT_GET_IFACE (document)->is_untitled (document); return FALSE; }
gboolean gb_document_get_mtime (GbDocument *document, GTimeVal *mtime) { g_return_val_if_fail (GB_IS_DOCUMENT (document), FALSE); g_return_val_if_fail (mtime, FALSE); if (GB_DOCUMENT_GET_IFACE (document)->get_mtime) return GB_DOCUMENT_GET_IFACE (document)->get_mtime (document, mtime); return FALSE; }
gboolean gb_document_save_as_finish (GbDocument *document, GAsyncResult *result, GError **error) { g_return_val_if_fail (GB_IS_DOCUMENT (document), FALSE); g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE); if (GB_DOCUMENT_GET_IFACE (document)->save_as_finish) return GB_DOCUMENT_GET_IFACE (document)->save_as_finish (document, result, error); return TRUE; }
void gb_document_save_as_async (GbDocument *document, GtkWidget *toplevel, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_return_if_fail (GB_IS_DOCUMENT (document)); g_return_if_fail (GTK_IS_WIDGET (toplevel)); g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); if (GB_DOCUMENT_GET_IFACE (document)->save_as_async) GB_DOCUMENT_GET_IFACE (document)->save_as_async (document, toplevel, cancellable, callback, user_data); }
/** * gb_document_create_view: * * Returns: (transfer full): A newly created #GbView. */ GtkWidget * gb_document_create_view (GbDocument *document) { GtkWidget *ret = NULL; g_return_val_if_fail (GB_IS_DOCUMENT (document), NULL); g_signal_emit (document, signals [CREATE_VIEW], 0, &ret); if (!ret) g_warning ("%s failed to implement create_view() signal", g_type_name (G_TYPE_FROM_INSTANCE (document))); return ret; }
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)); } }
void gb_view_stack_raise_document (GbViewStack *self, GbDocument *document, gboolean focus) { GtkWidget *view; g_return_if_fail (GB_IS_VIEW_STACK (self)); g_return_if_fail (GB_IS_DOCUMENT (document)); view = gb_view_stack_find_with_document (self, document); if (view != NULL && GB_IS_VIEW (view)) { gb_view_stack_set_active_view (self, view); if (focus) gtk_widget_grab_focus (view); return; } view = gb_document_create_view (document); if (view == NULL) { g_warning ("Document %s failed to create a view", gb_document_get_title (document)); return; } if (!GB_IS_VIEW (view)) { g_warning ("Document %s did not create a GbView instance.", gb_document_get_title (document)); return; } gb_view_stack_add (GTK_CONTAINER (self), view); gb_view_stack_set_active_view (self, view); if (focus) gtk_widget_grab_focus (view); }
static void gb_view_stack__navigate_to_load_cb (GObject *object, GAsyncResult *result, gpointer user_data) { IdeBufferManager *buffer_manager = (IdeBufferManager *)object; GbViewStack *self; g_autoptr(GTask) task = user_data; IdeSourceLocation *location; g_autoptr(IdeBuffer) buffer = NULL; g_autoptr(GError) error = NULL; GtkWidget *active_view; g_assert (IDE_IS_BUFFER_MANAGER (buffer_manager)); self = g_task_get_source_object (task); location = g_task_get_task_data (task); buffer = ide_buffer_manager_load_file_finish (buffer_manager, result, &error); if (buffer == NULL) { /* todo: message dialog? */ g_warning ("%s", error->message); return; } g_assert (GB_IS_DOCUMENT (buffer)); g_assert (location != NULL); 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); g_task_return_boolean (task, TRUE); }