[gtksourceviewmm] Add not-yet-working completion test.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceviewmm] Add not-yet-working completion test.
- Date: Wed, 3 Nov 2010 23:20:34 +0000 (UTC)
commit 4e311d580ad45d8b24b7033e51b686587c44d556
Author: Krzesimir Nowak <qdlacz gmail com>
Date: Thu Nov 4 00:17:12 2010 +0100
Add not-yet-working completion test.
* tests/Makefile.am: Removed obsolete comment about mime_types test.
* tests/completion/main.cc: Added new test checking completion. It does not
work, because I don't know how to make a GType system to know that my class
by inheriting an C++ wrapper interface inherits also a C interface.
tests/Makefile.am | 13 +--
tests/completion/main.cc | 226 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 231 insertions(+), 8 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e5cbc40..a1c1b5e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -7,14 +7,11 @@ check_PROGRAMS = \
get_buffer/test \
mime_types/test
-basic_test_SOURCES = basic/main.cc
-langs_test_SOURCES = langs/main.cc
-search_test_SOURCES = search/main.cc
-get_buffer_test_SOURCES = get_buffer/main.cc
-
-# commented for now, since it does not compile successfully.
-# when fixed, do not forget to add mime_types/test to check_PROGRAMS!
-mime_types_test_SOURCES = mime_types/main.cc
+basic_test_SOURCES = basic/main.cc
+langs_test_SOURCES = langs/main.cc
+search_test_SOURCES = search/main.cc
+get_buffer_test_SOURCES = get_buffer/main.cc
+mime_types_test_SOURCES = mime_types/main.cc
gtksourceviewmm_includes = -I$(top_builddir)/gtksourceview $(if $(srcdir:.=),-I$(top_srcdir)/gtksourceview)
gtksourceviewmm_ldadd = $(top_builddir)/gtksourceview/gtksourceviewmm/libgtksourceviewmm-$(GTKSOURCEVIEWMM_API_VERSION).la
diff --git a/tests/completion/main.cc b/tests/completion/main.cc
new file mode 100644
index 0000000..114b0bd
--- /dev/null
+++ b/tests/completion/main.cc
@@ -0,0 +1,226 @@
+// standard
+#include <list>
+// glibmm
+#include <glibmm.h>
+// gdkmm
+#include <gdkmm/pixbuf.h>
+// gtkmm
+#include <gtkmm.h>
+// gtksourceviewmm
+#include <gtksourceviewmm.h>
+
+namespace Gsv = gtksourceview;
+
+class TestProvider : public Glib::Object, public Gsv::SourceCompletionProvider
+{
+public:
+ static Glib::RefPtr<TestProvider> create();
+ virtual ~TestProvider();
+
+ void set_priority(int priority);
+ void set_name(const Glib::ustring& name);
+
+protected:
+ TestProvider();
+
+private:
+ // noncopyable
+ TestProvider(const TestProvider&);
+ TestProvider& operator=(const TestProvider&);
+
+ virtual Glib::ustring get_name_vfunc() const;
+ virtual Glib::RefPtr<Gdk::Pixbuf> get_icon_vfunc();
+ virtual Glib::RefPtr<const Gdk::Pixbuf> get_icon_vfunc() const;
+ virtual void populate_vfunc(const Glib::RefPtr<Gsv::SourceCompletionContext>& context);
+ virtual bool match_vfunc(const Glib::RefPtr<const Gsv::SourceCompletionContext>& context) const;
+ //virtual Gtk::Widget* get_info_widget_vfunc(const Glib::RefPtr<const Gsv::SourceCompletionProposal>& proposal);
+ //virtual const Gtk::Widget* get_info_widget_vfunc(const Glib::RefPtr<const Gsv::SourceCompletionProposal>& proposal) const;
+ //virtual void update_info_vfunc(const Glib::RefPtr<const Gsv::SourceCompletionProposal>& proposal, const Gsv::SourceCompletionInfo& info);
+ //virtual bool get_start_iter_vfunc(const Glib::RefPtr<const Gsv::SourceCompletionContext>& context, const Glib::RefPtr<const Gsv::SourceCompletionProposal>& proposal, Gtk::TextIter& iter);
+ //virtual bool activate_proposal_vfunc(const Glib::RefPtr<Gsv::SourceCompletionProposal>& proposal, const Gtk::TextIter& iter);
+ //virtual Gsv::SourceCompletionActivation get_activation_vfunc() const;
+ //virtual int get_interactive_delay_vfunc() const;
+ virtual int get_priority_vfunc() const;
+
+ std::list<Glib::RefPtr<Gsv::SourceCompletionItem> > m_proposals;
+ int m_priority;
+ Glib::ustring m_name;
+ Glib::RefPtr<Gdk::Pixbuf> m_pixbuf;
+};
+
+Glib::RefPtr<TestProvider> TestProvider::create()
+{
+ return Glib::RefPtr<TestProvider>(new TestProvider());
+}
+
+TestProvider::~TestProvider()
+{}
+
+void TestProvider::set_priority(int priority)
+{
+ m_priority = priority;
+}
+
+void TestProvider::set_name(const Glib::ustring& name)
+{
+ m_name = name;
+}
+
+TestProvider::TestProvider()
+{
+ m_proposals.push_back( Gsv::SourceCompletionItem::create( "Proposal 1", "Proposal 1", get_icon_vfunc(), "" ) );
+ m_proposals.push_back( Gsv::SourceCompletionItem::create( "Proposal 2", "Proposal 2", get_icon_vfunc(), "" ) );
+ m_proposals.push_back( Gsv::SourceCompletionItem::create( "Proposal 3", "Proposal 3", get_icon_vfunc(), "" ) );
+}
+
+Glib::ustring TestProvider::get_name_vfunc() const
+{
+ return m_name;
+}
+
+Glib::RefPtr<Gdk::Pixbuf> TestProvider::get_icon_vfunc()
+{
+ return m_pixbuf;
+}
+
+Glib::RefPtr<const Gdk::Pixbuf> TestProvider::get_icon_vfunc() const
+{
+ return const_cast<TestProvider*>(this)->get_icon_vfunc();
+}
+
+void TestProvider::populate_vfunc(const Glib::RefPtr<Gsv::SourceCompletionContext>& context)
+{
+ context->add_proposals(Glib::RefPtr<TestProvider>(this), m_proposals, true);
+}
+
+bool TestProvider::match_vfunc(const Glib::RefPtr<const Gsv::SourceCompletionContext>& context) const
+{
+ return true;
+}
+
+int TestProvider::get_priority_vfunc() const
+{
+ return m_priority;
+}
+
+class TestWindow : public Gtk::Window
+{
+public:
+ TestWindow();
+ virtual ~TestWindow();
+
+protected:
+ void remember_toggled();
+ void select_on_show_toggled();
+ void show_headers_toggled();
+ void show_icons_toggled();
+
+private:
+ Glib::RefPtr<Gsv::SourceCompletion> m_completion;
+ Gsv::SourceView* m_view;
+ Gtk::CheckButton* m_remember;
+ Gtk::CheckButton* m_select_on_show;
+ Gtk::CheckButton* m_show_headers;
+ Gtk::CheckButton* m_show_icons;
+};
+
+TestWindow::TestWindow()
+: Gtk::Window(),
+ m_completion(),
+ m_view(0),
+ m_remember(0),
+ m_select_on_show(0),
+ m_show_headers(0),
+ m_show_icons(0)
+{
+// layout
+ Gtk::HBox* hbox (Gtk::manage(new Gtk::HBox(false, 1)));
+ Gtk::VBox* vbox (Gtk::manage(new Gtk::VBox(false, 1)));
+ m_remember = Gtk::manage(new Gtk::CheckButton("Remember info visibility"));
+ m_select_on_show = Gtk::manage(new Gtk::CheckButton("Select first on show"));
+ m_show_headers = Gtk::manage(new Gtk::CheckButton("Show headers"));
+ m_show_icons = Gtk::manage(new Gtk::CheckButton("Show icons"));
+
+ resize(600, 400);
+
+ Gtk::ScrolledWindow* scrolledwindow (Gtk::manage(new Gtk::ScrolledWindow()));
+ m_view = Gtk::manage(new Gsv::SourceView());
+
+ scrolledwindow->add(*m_view);
+
+ m_completion = m_view->get_completion();
+
+ m_remember->set_active( m_completion->property_remember_info_visibility().get_value() );
+ m_select_on_show->set_active( m_completion->property_select_on_show().get_value() );
+ m_show_headers->set_active( m_completion->property_show_headers().get_value() );
+ m_show_icons->set_active( m_completion->property_show_icons().get_value() );
+
+ hbox->pack_start(*m_remember, false, false);
+ hbox->pack_start(*m_select_on_show, false, false);
+ hbox->pack_start(*m_show_headers, false, false);
+ hbox->pack_start(*m_show_icons, false, false);
+
+ vbox->pack_start(*scrolledwindow, true, true);
+ vbox->pack_end(*hbox, false, false);
+
+ m_remember->signal_toggled().connect(sigc::mem_fun(this, &TestWindow::remember_toggled));
+ m_select_on_show->signal_toggled().connect(sigc::mem_fun(this, &TestWindow::select_on_show_toggled));
+ m_show_headers->signal_toggled().connect(sigc::mem_fun(this, &TestWindow::show_headers_toggled));
+ m_show_icons->signal_toggled().connect(sigc::mem_fun(this, &TestWindow::show_icons_toggled));
+
+ add(*vbox);
+//completion
+ Glib::RefPtr<Gsv::SourceCompletionWords> prov_words ( Gsv::SourceCompletionWords::create("", Glib::RefPtr<Gdk::Pixbuf>()) );
+
+ prov_words->register_provider(m_view->get_buffer());
+ m_completion->add_provider(prov_words);
+
+ prov_words->property_priority().set_value( 10 );
+
+ Glib::RefPtr<TestProvider> tp (TestProvider::create());
+
+ tp->set_priority(1);
+ tp->set_name("Test Provider 1");
+ m_completion->add_provider(Glib::RefPtr<Gsv::SourceCompletionProvider>::cast_dynamic(tp));
+
+ tp = TestProvider::create();
+
+ tp->set_priority(5);
+ tp->set_name("Test Provider 5");
+ m_completion->add_provider(Glib::RefPtr<Gsv::SourceCompletionProvider>::cast_dynamic(tp));
+}
+
+TestWindow::~TestWindow()
+{}
+
+void TestWindow::remember_toggled()
+{
+ m_completion->property_remember_info_visibility().set_value( m_remember->get_active() );
+}
+
+void TestWindow::select_on_show_toggled()
+{
+ m_completion->property_select_on_show().set_value( m_select_on_show->get_active() );
+}
+
+void TestWindow::show_headers_toggled()
+{
+ m_completion->property_show_headers().set_value( m_show_headers->get_active() );
+}
+
+void TestWindow::show_icons_toggled()
+{
+ m_completion->property_show_icons().set_value( m_show_icons->get_active() );
+}
+
+int
+main (int argc, char *argv[])
+{
+ Gtk::Main kit(argc, argv);
+ Gsv::init();
+ TestWindow window;
+
+ window.show_all();
+ kit.run(window);
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]