#!/usr/bin/python3
import sys

from gi.repository import Gtk, GObject

libgd_libdir = '/usr/lib64/gnome-documents'
libgd_typelibdir = '/usr/lib64/gnome-documents/girepository-1.0'

from gi.repository import GIRepository
GIRepository.Repository.prepend_search_path(libgd_typelibdir)
GIRepository.Repository.prepend_library_path(libgd_libdir)

from gi.repository import Gd


class Window(Gtk.ApplicationWindow):

    def __init__(self, app):
        Gtk.Window.__init__(self, application=app)
        self.set_default_size(400, 300)

        headerBar = Gtk.HeaderBar(show_close_button=True)
        self.set_titlebar(headerBar)

        searchImage = Gtk.Image(icon_name='edit-find-symbolic')
        searchButton = Gtk.ToggleButton(child=searchImage)
        headerBar.pack_end(searchButton)

        searchEntry = Gd.TaggedEntry()
        searchEntry.add_tag(Gd.TaggedEntryTag(label='Test'))

        searchBar = Gtk.SearchBar(child=searchEntry)
        searchBar.bind_property('search-mode-enabled',
                                searchButton, 'active',
                                GObject.BindingFlags.BIDIRECTIONAL)
        self.add(searchBar)


class Application(Gtk.Application):

    def __init__(self):
        Gtk.Application.__init__(self)

    def do_activate(self):
        win = Window(self)
        win.show_all()

    def do_startup(self):
        Gtk.Application.do_startup(self)


app = Application()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
