static void
gedit_word_completion_view_activate (GeditViewActivatable *activatable)
{
	GeditWordCompletionPluginPrivate *priv;
	GtkSourceCompletion *completion;
	GtkSourceCompletionProvider *provider;
	GtkTextBuffer *buf;

	gedit_debug (DEBUG_PLUGINS);

	priv = GEDIT_WORD_COMPLETION_PLUGIN (activatable)->priv;

	priv->window = gtk_widget_get_toplevel (GTK_WIDGET (priv->view));

	/* We are disposing the window */
	g_object_ref (priv->window);

	completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (priv->view));
	buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->view));

	provider = g_object_get_data (G_OBJECT (priv->window), WINDOW_PROVIDER);

	if (provider == NULL)
	{
		/* Standalone provider */
		provider = GTK_SOURCE_COMPLETION_PROVIDER (create_provider ());
	}

	priv->provider = g_object_ref (provider);

	gtk_source_completion_add_provider (completion, provider, NULL);
	gtk_source_completion_words_register (GTK_SOURCE_COMPLETION_WORDS (provider),
	                                      buf);
}
static void
add_view (WindowData    *data,
	  GtkSourceView *view)
{
	GtkSourceCompletion *completion;
	GtkTextBuffer *buf;
	
	completion = gtk_source_view_get_completion (view);
	buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
	
	gtk_source_completion_add_provider (completion,
					    GTK_SOURCE_COMPLETION_PROVIDER (data->provider),
					    NULL);
	gtk_source_completion_words_register (data->provider,
					      buf);
}
示例#3
0
	SourceView::SourceView():
		Gtk::ScrolledWindow(), source_view(GTK_SOURCE_VIEW(gtk_source_view_new()))
	{	
		add(*Glib::wrap(GTK_WIDGET(source_view)));
		
		completion = gtk_source_view_get_completion(source_view);
		completion_words = gtk_source_completion_words_new("Suggestions", nullptr);
		gtk_source_completion_words_register(completion_words, gtk_text_view_get_buffer(GTK_TEXT_VIEW(source_view)));
		gtk_source_completion_add_provider(completion,
			GTK_SOURCE_COMPLETION_PROVIDER(completion_words), nullptr);
		gtk_source_buffer_set_highlight_matching_brackets(GetSourceBuffer(), TRUE);
		gtk_source_view_set_show_line_marks(source_view, TRUE);
		ShowLineNumbers(true);
		
		show_all();
	}
示例#4
0
static void
on_notify_autocompletion (GSettings* settings,
                         const gchar* key,
                         gpointer user_data)
{
	Sourceview *sv;
	sv = ANJUTA_SOURCEVIEW(user_data);
	GtkSourceCompletion* completion = gtk_source_view_get_completion(GTK_SOURCE_VIEW(sv->priv->view));

	if (g_settings_get_boolean (settings, key))
	{
		DEBUG_PRINT ("Register word completion provider");
		GtkSourceCompletionWords *prov_words;
		prov_words = gtk_source_completion_words_new (NULL, NULL);

		gtk_source_completion_words_register (prov_words,
		                                      gtk_text_view_get_buffer (GTK_TEXT_VIEW (sv->priv->view)));

		gtk_source_completion_add_provider (completion, 
		                                    GTK_SOURCE_COMPLETION_PROVIDER (prov_words), 
		                                    NULL);
	}
	else
	{
		GList* node;
		for (node = gtk_source_completion_get_providers(completion); node != NULL; node = g_list_next (node))
		{
			if (GTK_IS_SOURCE_COMPLETION_WORDS(node->data))
			{
				DEBUG_PRINT ("Unregister word completion provider");
				gtk_source_completion_words_unregister (GTK_SOURCE_COMPLETION_WORDS(node->data),
				                                        gtk_text_view_get_buffer (GTK_TEXT_VIEW (sv->priv->view)));
				gtk_source_completion_remove_provider(completion, GTK_SOURCE_COMPLETION_PROVIDER(node->data), NULL);
				break;
			}
		}
	}
}
示例#5
0
static void
gb_editor_tab_init (GbEditorTab *tab)
{
   GtkSourceCompletion *completion;
   GbEditorTabPrivate *priv;

   priv = tab->priv = gb_editor_tab_get_instance_private(tab);

   priv->is_empty = TRUE;

   priv->document = gb_editor_document_new();

   priv->first_change_handler =
      g_signal_connect_object (priv->document,
                               "changed",
                               G_CALLBACK (gb_editor_tab_handle_first_change),
                               tab,
                               G_CONNECT_SWAPPED);

   priv->search_settings = gtk_source_search_settings_new ();

   priv->search = gtk_source_search_context_new (GTK_SOURCE_BUFFER (priv->document),
                                                 priv->search_settings);

   g_signal_connect_object (priv->document,
                            "notify::file",
                            G_CALLBACK (gb_editor_tab_update_title),
                            tab,
                            (G_CONNECT_AFTER | G_CONNECT_SWAPPED));

   priv->vbox = g_object_new (GTK_TYPE_BOX,
                              "orientation", GTK_ORIENTATION_VERTICAL,
                              "visible", TRUE,
                              NULL);
   gtk_container_add (GTK_CONTAINER (tab), priv->vbox);

   priv->search_bar = g_object_new (GTK_TYPE_SEARCH_BAR,
                                    "search-mode-enabled", FALSE,
                                    "show-close-button", FALSE,
                                    "visible", TRUE,
                                    NULL);
   gtk_container_add (GTK_CONTAINER (priv->vbox), priv->search_bar);

   priv->search_entry = g_object_new (GTK_TYPE_SEARCH_ENTRY,
                                      "visible", TRUE,
                                      "width-chars", 32,
                                      NULL);
   g_object_bind_property (priv->search_entry, "text",
                           priv->search_settings, "search-text",
                           G_BINDING_SYNC_CREATE);
   g_signal_connect_object (priv->search_entry,
                            "changed",
                            G_CALLBACK (gb_editor_tab_search_entry_changed),
                            tab,
                            (G_CONNECT_AFTER | G_CONNECT_SWAPPED));
   gtk_container_add (GTK_CONTAINER (priv->search_bar), priv->search_entry);

   priv->overlay = g_object_new(GTK_TYPE_OVERLAY,
                                "vexpand", TRUE,
                                "visible", TRUE,
                                NULL);
   gtk_container_add(GTK_CONTAINER(priv->vbox), priv->overlay);

   priv->scroller = g_object_new(GTK_TYPE_SCROLLED_WINDOW,
                                 "visible", TRUE,
                                 NULL);
   gtk_container_add(GTK_CONTAINER(priv->overlay), priv->scroller);

   priv->text_view = g_object_new(GB_TYPE_SOURCE_VIEW,
                                  "buffer", priv->document,
                                  "visible", TRUE,
                                  NULL);
   gtk_container_add(GTK_CONTAINER(priv->scroller), priv->text_view);

   completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (priv->text_view));

   g_object_set (completion,
                 "show-headers", FALSE,
                 "select-on-show", TRUE,
                 NULL);

   priv->snippets_provider =
      g_object_new (GB_TYPE_SOURCE_SNIPPET_COMPLETION_PROVIDER,
                    "source-view", priv->text_view,
                    NULL);

   gtk_source_completion_add_provider (completion,
                                       priv->snippets_provider,
                                       NULL);

   priv->search_overlay = g_object_new (GB_TYPE_SOURCE_OVERLAY,
                                        "hexpand", TRUE,
                                        "search-context", priv->search,
                                        "source-view", priv->text_view,
                                        "vexpand", TRUE,
                                        "visible", FALSE,
                                        NULL);
   gtk_overlay_add_overlay(GTK_OVERLAY(priv->overlay), priv->search_overlay);

   priv->progress_bar = g_object_new (GTK_TYPE_PROGRESS_BAR,
                                      "halign", GTK_ALIGN_FILL,
                                      "valign", GTK_ALIGN_START,
                                      NULL);
   gtk_style_context_add_class (gtk_widget_get_style_context (priv->progress_bar),
                                GTK_STYLE_CLASS_OSD);
   gtk_overlay_add_overlay (GTK_OVERLAY (priv->overlay), priv->progress_bar);

   priv->floating_bar = g_object_new(NAUTILUS_TYPE_FLOATING_BAR,
                                     "halign", GTK_ALIGN_END,
                                     "valign", GTK_ALIGN_END,
                                     "visible", TRUE,
                                     NULL);
   gtk_overlay_add_overlay(GTK_OVERLAY(priv->overlay), priv->floating_bar);

   g_signal_connect_object (priv->text_view,
                            "toggle-overwrite",
                            G_CALLBACK (gb_editor_tab_update_location),
                            tab,
                            (G_CONNECT_AFTER | G_CONNECT_SWAPPED));

   g_signal_connect_object (priv->document,
                            "notify::language",
                            G_CALLBACK (gb_editor_tab_apply_settings),
                            tab,
                            (G_CONNECT_AFTER | G_CONNECT_SWAPPED));

   g_signal_connect_object (priv->document,
                            "delete-range",
                            G_CALLBACK (gb_editor_tab_update_location),
                            tab,
                            (G_CONNECT_AFTER | G_CONNECT_SWAPPED));

   g_signal_connect_object (priv->document,
                            "insert-text",
                            G_CALLBACK (gb_editor_tab_update_location),
                            tab,
                            (G_CONNECT_AFTER | G_CONNECT_SWAPPED));

   g_signal_connect_object (priv->document,
                            "mark-set",
                            G_CALLBACK (gb_editor_tab_update_location),
                            tab,
                            (G_CONNECT_AFTER | G_CONNECT_SWAPPED));

   g_signal_connect_object (priv->text_view,
                            "grab-focus",
                            G_CALLBACK (gb_editor_tab_emit_focused),
                            tab,
                            (G_CONNECT_AFTER | G_CONNECT_SWAPPED));

   priv->shared_settings = g_settings_new ("org.gnome.builder.preferences.editor");

   g_settings_bind (priv->shared_settings, "font", tab, "font", G_SETTINGS_BIND_GET);
   g_settings_bind (priv->shared_settings, "style-scheme", tab, "style-scheme-name", G_SETTINGS_BIND_GET);

   gb_editor_tab_update_location (tab);

   gb_editor_tab_apply_settings (tab);
}
示例#6
0
CAMLexport value ml_gtk_source_completion_add_provider (value completion, value provider) {
  return Val_bool (gtk_source_completion_add_provider
    (GtkSourceCompletion_val(completion), GtkSourceCompletionProvider_val(provider), NULL));
}