static void pls_lang_active(GtkAction* action, GtkSourceLanguage* lang) { gint page_num; GtkTextBuffer* buf; page_num = gtk_notebook_get_current_page(puss_get_doc_panel(g_self->app)); if( page_num < 0 ) return; buf = g_self->app->doc_get_buffer_from_page_num(page_num); #if GTK_MAJOR_VERSION==2 if( !buf || !GTK_IS_SOURCE_BUFFER(buf) ) return; #else if( !buf || !GTK_SOURCE_IS_BUFFER(buf) ) return; #endif if( lang ) { gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(buf), lang); add_fill_favory_language(lang); } else { gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(buf), g_self->last_favory_lang); } }
static void gb_view_source_notify_cursor (GbViewSource *source, GParamSpec *pspec, GtkTextBuffer *buffer) { GbViewSourcePrivate *priv; GtkTextIter iter; guint col; guint line; guint position; gchar *s; g_return_if_fail(GB_IS_VIEW_SOURCE(source)); g_return_if_fail(pspec != NULL); g_return_if_fail(GTK_SOURCE_IS_BUFFER(buffer)); priv = source->priv; g_object_get(buffer, "cursor-position", &position, NULL); gtk_text_buffer_get_iter_at_offset(buffer, &iter, position); line = gtk_text_iter_get_line(&iter); col = gtk_source_view_get_visual_column(GTK_SOURCE_VIEW(priv->source1), &iter); s = g_strdup_printf(_("Line %d, Column %d"), line + 1, col + 1); g_object_set(priv->pos_label, "label", s, NULL); g_free(s); }
static void test_buffer_ref (void) { GtkSourcePrintCompositor *compositor; GtkSourceBuffer *buffer = NULL; GtkSourceBuffer *buffer_original = NULL; buffer_original = gtk_source_buffer_new (NULL); compositor = gtk_source_print_compositor_new (buffer_original); buffer = gtk_source_print_compositor_get_buffer (compositor); g_assert (GTK_SOURCE_IS_BUFFER (buffer)); g_object_unref (G_OBJECT (buffer_original)); buffer = gtk_source_print_compositor_get_buffer (compositor); g_assert (GTK_SOURCE_IS_BUFFER (buffer)); }
static void cedit_prefs_manager_source_style_scheme_changed (GSettings *settings, gchar *key, gpointer user_data) { cedit_debug (DEBUG_PREFS); if (strcmp (key, GPM_SOURCE_STYLE_SCHEME) == 0) { static gchar *old_scheme = NULL; gchar *scheme; GtkSourceStyleScheme *style; GList *docs; GList *l; scheme = g_settings_get_string (settings, key); if (old_scheme != NULL && (strcmp (scheme, old_scheme) == 0)) return; g_free (old_scheme); old_scheme = scheme; style = gtk_source_style_scheme_manager_get_scheme ( cedit_get_style_scheme_manager (), scheme); if (style == NULL) { g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme); style = gtk_source_style_scheme_manager_get_scheme ( cedit_get_style_scheme_manager (), "classic"); if (style == NULL) { g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); return; } } docs = cedit_app_get_documents (cedit_app_get_default ()); for (l = docs; l != NULL; l = l->next) { #if GTK_CHECK_VERSION (3, 0, 0) g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); #else g_return_if_fail (GTK_IS_SOURCE_BUFFER (l->data)); #endif gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), style); } g_list_free (docs); } }
static void test_buffer_view_ref (void) { GtkSourcePrintCompositor *compositor; GtkWidget *view = NULL; GtkSourceBuffer *buffer = NULL; view = gtk_source_view_new (); compositor = gtk_source_print_compositor_new_from_view (GTK_SOURCE_VIEW (view)); buffer = gtk_source_print_compositor_get_buffer (compositor); g_assert (GTK_SOURCE_IS_BUFFER (buffer)); gtk_widget_destroy (view); buffer = gtk_source_print_compositor_get_buffer (compositor); g_assert (GTK_SOURCE_IS_BUFFER (buffer)); g_object_unref (G_OBJECT (compositor)); }
static void cedit_prefs_manager_syntax_hl_enable_changed (GSettings *settings, gchar *key, gpointer user_data) { cedit_debug (DEBUG_PREFS); if (strcmp (key, GPM_SYNTAX_HL_ENABLE) == 0) { gboolean enable; GList *docs; GList *l; const GList *windows; enable = g_settings_get_boolean (settings, key); docs = cedit_app_get_documents (cedit_app_get_default ()); l = docs; while (l != NULL) { #if GTK_CHECK_VERSION (3, 0, 0) g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); #else g_return_if_fail (GTK_IS_SOURCE_BUFFER (l->data)); #endif gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data), enable); l = l->next; } g_list_free (docs); /* update the sensitivity of the Higlight Mode menu item */ windows = cedit_app_get_windows (cedit_app_get_default ()); while (windows != NULL) { GtkUIManager *ui; GtkAction *a; ui = cedit_window_get_ui_manager (CEDIT_WINDOW (windows->data)); a = gtk_ui_manager_get_action (ui, "/MenuBar/ViewMenu/ViewHighlightModeMenu"); gtk_action_set_sensitive (a, enable); windows = g_list_next (windows); } } }
static void wikipad_document_notify_language (GtkSourceBuffer *buffer, GParamSpec *pspec, WikipadDocument *document) { GtkSourceLanguage *language; g_return_if_fail (WIKIPAD_IS_DOCUMENT (document)); g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer)); /* the new language */ language = gtk_source_buffer_get_language (buffer); /* emit the signal */ g_signal_emit (G_OBJECT (document), document_signals[LANGUAGE_CHANGED], 0, language); }
static void connect_style_scheme (IdeLineChangeGutterRenderer *self) { GtkSourceStyleScheme *scheme; GtkTextBuffer *buffer; GtkTextView *view; if (!(view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (self))) || !(buffer = gtk_text_view_get_buffer (view)) || !GTK_SOURCE_IS_BUFFER (buffer)) return; scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (buffer)); if (!get_style_rgba (scheme, "gutter::added-line", FOREGROUND, &self->changes.add)) gdk_rgba_parse (&self->changes.add, "#8ae234"); if (!get_style_rgba (scheme, "gutter::changed-line", FOREGROUND, &self->changes.change)) gdk_rgba_parse (&self->changes.change, "#fcaf3e"); if (!get_style_rgba (scheme, "gutter::removed-line", FOREGROUND, &self->changes.remove)) gdk_rgba_parse (&self->changes.remove, "#ef2929"); }
static void test_get_buffer (void) { GtkWidget* view; GtkSourceBuffer* buffer; view = gtk_source_view_new (); buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); g_assert (buffer != NULL); g_assert (GTK_SOURCE_IS_BUFFER (buffer)); if (g_object_is_floating (view)) { g_object_ref_sink (view); } /* Here we check if notify_buffer recreates the buffer while view is being * destroyed, which causes assertion failure in GtkTextView's finalize () * function. * Please see: https://bugzilla.gnome.org/show_bug.cgi?id=634510 */ g_object_unref (view); }
gboolean gb_vim_execute (GtkSourceView *source_view, const gchar *line, GError **error) { GtkTextBuffer *buffer; g_autofree gchar *name_slice = NULL; const GbVimCommand *command; const gchar *command_name = line; const gchar *options; g_autofree gchar *all_options = NULL; gboolean result; g_return_val_if_fail (GTK_SOURCE_IS_VIEW (source_view), FALSE); g_return_val_if_fail (line, FALSE); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (source_view)); if (!GTK_SOURCE_IS_BUFFER (buffer)) { g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_SOURCE_VIEW, _("vim mode requires GtkSourceView")); return FALSE; } for (options = line; *options; options = g_utf8_next_char (options)) { gunichar ch; ch = g_utf8_get_char (options); if (g_unichar_isspace (ch)) break; } if (g_unichar_isspace (g_utf8_get_char (options))) { command_name = name_slice = g_strndup (line, options - line); options = g_utf8_next_char (options); } command = lookup_command (command_name); if (command == NULL) { if (looks_like_search_and_replace (line)) return gb_vim_command_search (source_view, line, "", error); g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_FOUND, _("Not an editor command: %s"), command_name); return FALSE; } if (command->options_sup) all_options = g_strconcat (options, " ", command->options_sup, NULL); else all_options = g_strdup (options); result = command->func (source_view, command_name, all_options, error); g_free (command->options_sup); return result; }