2022-07-21 04:57:06 +00:00
|
|
|
# Python imports
|
2022-11-29 04:34:13 +00:00
|
|
|
import os
|
|
|
|
import time
|
2022-07-21 04:57:06 +00:00
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
2022-11-29 04:34:13 +00:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import GLib
|
2022-07-21 04:57:06 +00:00
|
|
|
|
|
|
|
# Application imports
|
2022-09-06 02:21:04 +00:00
|
|
|
from plugins.plugin_base import PluginBase
|
2022-10-04 03:14:18 +00:00
|
|
|
from .mixins.file_search_mixin import FileSearchMixin
|
|
|
|
from .mixins.grep_search_mixin import GrepSearchMixin
|
|
|
|
from .utils.ipc_server import IPCServer
|
2022-07-21 04:57:06 +00:00
|
|
|
|
2022-10-03 05:52:50 +00:00
|
|
|
|
|
|
|
|
2022-07-21 04:57:06 +00:00
|
|
|
|
2022-10-04 03:14:18 +00:00
|
|
|
class Plugin(IPCServer, FileSearchMixin, GrepSearchMixin, PluginBase):
|
2022-07-21 04:57:06 +00:00
|
|
|
def __init__(self):
|
2022-09-06 02:21:04 +00:00
|
|
|
super().__init__()
|
|
|
|
|
2022-11-30 04:34:25 +00:00
|
|
|
self.name = "Search" # NOTE: Need to remove after establishing private bidirectional 1-1 message bus
|
|
|
|
# where self.name should not be needed for message comms
|
2023-02-21 01:18:45 +00:00
|
|
|
self.path = os.path.dirname(os.path.realpath(__file__))
|
2022-11-30 04:34:25 +00:00
|
|
|
self._GLADE_FILE = f"{self.path}/search_dialog.glade"
|
|
|
|
|
2022-10-04 03:14:18 +00:00
|
|
|
self.update_list_ui_buffer = ()
|
2022-11-30 04:34:25 +00:00
|
|
|
self._search_dialog = None
|
|
|
|
self._active_path = None
|
|
|
|
self.file_list_parent = None
|
|
|
|
self.grep_list_parent = None
|
|
|
|
self._file_list = None
|
|
|
|
self._grep_list = None
|
|
|
|
self._grep_proc = None
|
|
|
|
self._list_proc = None
|
|
|
|
self.pause_fifo_update = False
|
2023-02-21 19:16:53 +00:00
|
|
|
|
|
|
|
self.grep_query = ""
|
|
|
|
self.grep_time_stamp = None
|
|
|
|
self._queue_grep = False
|
|
|
|
self._grep_watcher_running = False
|
|
|
|
|
|
|
|
self.search_query = ""
|
|
|
|
self.fsearch_time_stamp = None
|
|
|
|
self._queue_search = False
|
|
|
|
self._search_watcher_running = False
|
2022-07-21 04:57:06 +00:00
|
|
|
|
|
|
|
|
2022-09-06 02:21:04 +00:00
|
|
|
def run(self):
|
2023-02-21 01:18:45 +00:00
|
|
|
self._builder = Gtk.Builder()
|
2022-07-21 04:57:06 +00:00
|
|
|
self._builder.add_from_file(self._GLADE_FILE)
|
2023-02-21 01:18:45 +00:00
|
|
|
self._connect_builder_signals(self, self._builder)
|
2022-07-21 04:57:06 +00:00
|
|
|
|
|
|
|
self._search_dialog = self._builder.get_object("search_dialog")
|
2022-10-03 05:52:50 +00:00
|
|
|
self.fsearch = self._builder.get_object("fsearch")
|
2022-07-21 04:57:06 +00:00
|
|
|
|
2022-10-07 01:48:44 +00:00
|
|
|
self.grep_list_parent = self._builder.get_object("grep_list_parent")
|
|
|
|
self.file_list_parent = self._builder.get_object("file_list_parent")
|
|
|
|
|
2022-10-03 05:52:50 +00:00
|
|
|
self._event_system.subscribe("update-file-ui", self._load_file_ui)
|
|
|
|
self._event_system.subscribe("update-grep-ui", self._load_grep_ui)
|
2022-10-27 22:23:27 +00:00
|
|
|
self._event_system.subscribe("show_search_page", self._show_page)
|
|
|
|
|
2022-10-04 01:50:38 +00:00
|
|
|
self.create_ipc_listener()
|
2022-10-03 05:52:50 +00:00
|
|
|
|
2022-10-10 01:59:44 +00:00
|
|
|
def generate_reference_ui_element(self):
|
2022-10-26 04:27:21 +00:00
|
|
|
item = Gtk.ImageMenuItem(self.name)
|
|
|
|
item.set_image( Gtk.Image(stock=Gtk.STOCK_FIND) )
|
|
|
|
item.connect("activate", self._show_page)
|
|
|
|
item.set_always_show_image(True)
|
|
|
|
return item
|
2022-10-10 01:59:44 +00:00
|
|
|
|
2022-10-03 05:52:50 +00:00
|
|
|
|
2022-10-04 03:14:18 +00:00
|
|
|
def _show_page(self, widget=None, eve=None):
|
2022-10-03 05:52:50 +00:00
|
|
|
self._event_system.emit("get_current_state")
|
2022-07-21 04:57:06 +00:00
|
|
|
|
2022-09-29 22:22:33 +00:00
|
|
|
state = self._fm_state
|
2022-07-21 04:57:06 +00:00
|
|
|
self._event_message = None
|
|
|
|
|
|
|
|
self._active_path = state.tab.get_current_directory()
|
|
|
|
response = self._search_dialog.run()
|
|
|
|
self._search_dialog.hide()
|
|
|
|
|
2022-10-07 01:48:44 +00:00
|
|
|
# TODO: Merge the below methods into some unified logic
|
|
|
|
def reset_grep_box(self) -> None:
|
|
|
|
try:
|
|
|
|
child = self.grep_list_parent.get_children()[0]
|
|
|
|
self._grep_list = None
|
|
|
|
self.grep_list_parent.remove(child)
|
|
|
|
except Exception:
|
|
|
|
...
|
|
|
|
|
|
|
|
self._grep_list = Gtk.Box()
|
|
|
|
self._grep_list.set_orientation(Gtk.Orientation.VERTICAL)
|
|
|
|
self.grep_list_parent.add(self._grep_list)
|
|
|
|
self.grep_list_parent.show_all()
|
|
|
|
|
2022-10-26 04:27:21 +00:00
|
|
|
time.sleep(0.05)
|
2022-10-10 01:59:44 +00:00
|
|
|
Gtk.main_iteration()
|
|
|
|
|
2022-10-07 01:48:44 +00:00
|
|
|
def reset_file_list_box(self) -> None:
|
|
|
|
try:
|
|
|
|
child = self.file_list_parent.get_children()[0]
|
|
|
|
self._file_list = None
|
|
|
|
self.file_list_parent.remove(child)
|
|
|
|
except Exception:
|
|
|
|
...
|
|
|
|
|
|
|
|
self._file_list = Gtk.Box()
|
|
|
|
self._file_list.set_orientation(Gtk.Orientation.VERTICAL)
|
|
|
|
self.file_list_parent.add(self._file_list)
|
|
|
|
self.file_list_parent.show_all()
|
2022-10-10 01:59:44 +00:00
|
|
|
|
2022-10-26 04:27:21 +00:00
|
|
|
time.sleep(0.05)
|
2022-10-10 01:59:44 +00:00
|
|
|
Gtk.main_iteration()
|