# Path: draobpilc/common.py
# APPLICATION = None
# SETTINGS_SCHEMA_ID = version.APP_ID
# SETTINGS_SCHEMA_DIR = get_data_path('schemas')
# SETTINGS = utils.get_settings(
#     SETTINGS_SCHEMA_ID,
#     SETTINGS_SCHEMA_DIR
# )
# ICON_PATH = get_data_path('draobpilc.png')
# CSS_PATH = get_data_path('style.css')
# WIDTH_PERCENTS = 'width-percents'
# PROCESSOR_WIDTH_PERCENTS = 'processor-width-percents'
# PROCESSOR_HEIGHT_PERCENTS = 'processor-height-percents'
# ITEM_MAX_LINES = 'item-max-lines'
# ITEM_MAX_HEIGHT = 'item-max-height'
# KIND_INDICATOR_WIDTH = 'kind-indicator-width'
# ITEM_PREVIEW_MARGIN = 'item-preview-margin'
# EDIT_TIMEOUT_MS = 'edit-timeout-ms'
# SHOW_INDEXES = 'show-indexes'
# SEARCH_TIMEOUT = 'search-timeout'
# FUZZY_SEARCH_MAX_DISTANCE = 'fuzzy-search-max-distance'
# STARTUP_NOTIFICATION = 'startup-notification'
# MERGE_DECORATORS = 'merge-decorators'
# MERGE_SEPARATORS = 'merge-separators'
# MERGE_DEFAULT_DECORATOR = 'merge-default-decorator'
# MERGE_DEFAULT_SEPARATOR = 'merge-default-separator'
# GPASTE_SCHEMA_ID = 'gpaste-schema-id'
# GPASTE_DBUS_NAME = 'gpaste-dbus-name'
# GPASTE_DBUS_PATH = 'gpaste-dbus-path'
# GPASTE_DBUS_IFACE = 'gpaste-dbus-iface'
# SHOW_TEXT_INFO = 'show-text-info'
# SHOW_HISTORIES = 'show-histories'
# DELETE_ITEM = 'delete-item'
# SHOW_THUMBNAILS = 'show-thumbnails'
# FOCUS_SEARCH = 'focus-search'
# RESET_SEARCH = 'reset-search'
# EDITOR_WRAP_TEXT = 'editor-wrap-text'
# EDITOR_WRAP_TEXT_SHORTCUT = 'editor-wrap-text-shortcut'
# OPEN_ITEM = 'open-item'
# BACKUP_HISTORY = 'backup-history'
# PREVIEW_TEXT_FILES = 'preview-text-files'
# KEEP_SEARCH_AND_CLOSE = 'keep-search-and-close'
# HIDE_APP = 'hide-app'
# QUIT_APP = 'quit-app'
# FOCUS_SEARCH_ON_OPEN = 'focus-search-on-open'
# SET_ITEMS_TIMEOUT = 'set-items-timeout'
# MAX_FILTER_RESULTS = 'max-filter-results'
# SHOW_HELP = 'show-help'
# SHOW_CLIPBOARD_PREVIEW = 'show-clipboard-preview'
# ITEMS_VIEW_LIMIT = 'items-view-limit'
# LOAD_ALL_HISTORY = 'load-all-history'
# ENABLE_ACTIVATE_NUMBER_KB = 'enable-activate-number-kb'
# SHORTCUTS_KEYS = {
#     SHOW_HISTORIES: _('Show histories'),
#     DELETE_ITEM: _('Delete an item'),
#     FOCUS_SEARCH: _('Focus search entry'),
#     RESET_SEARCH: _('Reset search'),
#     EDITOR_WRAP_TEXT_SHORTCUT: _('Toggle text wrap in the editor'),
#     OPEN_ITEM: _('Open selected item(file, image, url)'),
#     BACKUP_HISTORY: _('Backup current history'),
#     KEEP_SEARCH_AND_CLOSE: _('Keep search and close window'),
#     QUIT_APP: _('Quit app'),
#     SHOW_HELP: _('Show help'),
#     SHOW_CLIPBOARD_PREVIEW: _('Show clipboard preview'),
#     LOAD_ALL_HISTORY: _('Load all history')
# }
# 
# Path: draobpilc/history_item_kind.py
# class HistoryItemKind():
#     TEXT = 'Text'
#     IMAGE = 'Image'
#     FILE = 'Uris'
#     LINK = 'Link'


import re
from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import GObject
from draobpilc import common
from draobpilc.history_item_kind import HistoryItemKind
    def _on_text_changed(self, buffer, *a, **kw):
        def on_timeout():
            self._update_flags()
            self._timeout_id = 0
            match = SEARCH_INDEX_RE.findall(self.search_text)

            if match:
                self.emit('search-index', int(match[0]))
            else:
                self.emit('search-changed')

            return GLib.SOURCE_REMOVE

        if self._timeout_id != 0:
            GLib.source_remove(self._timeout_id)
            self._timeout_id = 0

        self._update_icon()
        search_timeout = common.SETTINGS[common.SEARCH_TIMEOUT]
        self._timeout_id = GLib.timeout_add(search_timeout, on_timeout)

    def _update_flags(self):
        flags = FLAGS_RE.findall(self.entry.get_text())
        self.flags.clear()

        if not flags: return
        else: flags = flags[0][1]

        if 'l' in flags: self.flags.append(HistoryItemKind.LINK)
        if 'f' in flags: self.flags.append(HistoryItemKind.FILE)

# Path: draobpilc/common.py
# APPLICATION = None
# SETTINGS_SCHEMA_ID = version.APP_ID
# SETTINGS_SCHEMA_DIR = get_data_path('schemas')
# SETTINGS = utils.get_settings(
#     SETTINGS_SCHEMA_ID,
#     SETTINGS_SCHEMA_DIR
# )
# ICON_PATH = get_data_path('draobpilc.png')
# CSS_PATH = get_data_path('style.css')
# WIDTH_PERCENTS = 'width-percents'
# PROCESSOR_WIDTH_PERCENTS = 'processor-width-percents'
# PROCESSOR_HEIGHT_PERCENTS = 'processor-height-percents'
# ITEM_MAX_LINES = 'item-max-lines'
# ITEM_MAX_HEIGHT = 'item-max-height'
# KIND_INDICATOR_WIDTH = 'kind-indicator-width'
# ITEM_PREVIEW_MARGIN = 'item-preview-margin'
# EDIT_TIMEOUT_MS = 'edit-timeout-ms'
# SHOW_INDEXES = 'show-indexes'
# SEARCH_TIMEOUT = 'search-timeout'
# FUZZY_SEARCH_MAX_DISTANCE = 'fuzzy-search-max-distance'
# STARTUP_NOTIFICATION = 'startup-notification'
# MERGE_DECORATORS = 'merge-decorators'
# MERGE_SEPARATORS = 'merge-separators'
# MERGE_DEFAULT_DECORATOR = 'merge-default-decorator'
# MERGE_DEFAULT_SEPARATOR = 'merge-default-separator'
# GPASTE_SCHEMA_ID = 'gpaste-schema-id'
# GPASTE_DBUS_NAME = 'gpaste-dbus-name'
# GPASTE_DBUS_PATH = 'gpaste-dbus-path'
# GPASTE_DBUS_IFACE = 'gpaste-dbus-iface'
# SHOW_TEXT_INFO = 'show-text-info'
# SHOW_HISTORIES = 'show-histories'
# DELETE_ITEM = 'delete-item'
# SHOW_THUMBNAILS = 'show-thumbnails'
# FOCUS_SEARCH = 'focus-search'
# RESET_SEARCH = 'reset-search'
# EDITOR_WRAP_TEXT = 'editor-wrap-text'
# EDITOR_WRAP_TEXT_SHORTCUT = 'editor-wrap-text-shortcut'
# OPEN_ITEM = 'open-item'
# BACKUP_HISTORY = 'backup-history'
# PREVIEW_TEXT_FILES = 'preview-text-files'
# KEEP_SEARCH_AND_CLOSE = 'keep-search-and-close'
# HIDE_APP = 'hide-app'
# QUIT_APP = 'quit-app'
# FOCUS_SEARCH_ON_OPEN = 'focus-search-on-open'
# SET_ITEMS_TIMEOUT = 'set-items-timeout'
# MAX_FILTER_RESULTS = 'max-filter-results'
# SHOW_HELP = 'show-help'
# SHOW_CLIPBOARD_PREVIEW = 'show-clipboard-preview'
# ITEMS_VIEW_LIMIT = 'items-view-limit'
# LOAD_ALL_HISTORY = 'load-all-history'
# ENABLE_ACTIVATE_NUMBER_KB = 'enable-activate-number-kb'
# SHORTCUTS_KEYS = {
#     SHOW_HISTORIES: _('Show histories'),
#     DELETE_ITEM: _('Delete an item'),
#     FOCUS_SEARCH: _('Focus search entry'),
#     RESET_SEARCH: _('Reset search'),
#     EDITOR_WRAP_TEXT_SHORTCUT: _('Toggle text wrap in the editor'),
#     OPEN_ITEM: _('Open selected item(file, image, url)'),
#     BACKUP_HISTORY: _('Backup current history'),
#     KEEP_SEARCH_AND_CLOSE: _('Keep search and close window'),
#     QUIT_APP: _('Quit app'),
#     SHOW_HELP: _('Show help'),
#     SHOW_CLIPBOARD_PREVIEW: _('Show clipboard preview'),
#     LOAD_ALL_HISTORY: _('Load all history')
# }
# 
# Path: draobpilc/history_item_kind.py
# class HistoryItemKind():
#     TEXT = 'Text'
#     IMAGE = 'Image'
#     FILE = 'Uris'
#     LINK = 'Link'


# Path: draobpilc/widgets/search_box.py
import re
from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import GObject
from draobpilc import common
from draobpilc.history_item_kind import HistoryItemKind

    def _on_text_changed(self, buffer, *a, **kw):
        def on_timeout():
            self._update_flags()
            self._timeout_id = 0
            match = SEARCH_INDEX_RE.findall(self.search_text)

            if match:
                self.emit('search-index', int(match[0]))
            else:
                self.emit('search-changed')

            return GLib.SOURCE_REMOVE

        if self._timeout_id != 0:
            GLib.source_remove(self._timeout_id)
            self._timeout_id = 0

        self._update_icon()
        search_timeout = common.SETTINGS[common.SEARCH_TIMEOUT]
        self._timeout_id = GLib.timeout_add(search_timeout, on_timeout)

    def _update_flags(self):
        flags = FLAGS_RE.findall(self.entry.get_text())
        self.flags.clear()

        if not flags: return
        else: flags = flags[0][1]

        if 'l' in flags: self.flags.append(HistoryItemKind.LINK)
        if 'f' in flags: self.flags.append(HistoryItemKind.FILE)

        if 'i' in flags: self.flags.append(HistoryItemKind.IMAGE)