save queries
This commit is contained in:
@@ -21,3 +21,7 @@ class Tab(QWidget):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def destruct(self):
|
def destruct(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def on_reveal(self):
|
||||||
|
pass
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import threading
|
|||||||
from typing import Optional, Callable
|
from typing import Optional, Callable
|
||||||
|
|
||||||
from PySide6.QtCore import QRunnable, QThreadPool, Signal
|
from PySide6.QtCore import QRunnable, QThreadPool, Signal
|
||||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLineEdit, QCheckBox, QPushButton
|
from PySide6.QtGui import QIcon
|
||||||
|
from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLineEdit, QCheckBox, QPushButton, QComboBox, \
|
||||||
|
QSizePolicy
|
||||||
|
|
||||||
from src.ui.bigtext.bigtext import BigText
|
from src.ui.bigtext.bigtext import BigText
|
||||||
from src.ui.bigtext.logFileModel import LogFileModel
|
from src.ui.bigtext.logFileModel import LogFileModel
|
||||||
@@ -96,14 +98,23 @@ class FilterWidget(QWidget):
|
|||||||
self.layout = QVBoxLayout(self)
|
self.layout = QVBoxLayout(self)
|
||||||
self.layout.setContentsMargins(0, 0, 0, 0)
|
self.layout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
self.query_field = QLineEdit()
|
self.query_field = QComboBox()
|
||||||
self.query_field.textChanged.connect(self.filter_changed)
|
self.query_field.setEditable(True)
|
||||||
|
self.query_field.addItem("")
|
||||||
|
self.query_field.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||||
|
self.query_field.lineEdit().textChanged.connect(self.filter_changed)
|
||||||
|
self.query_field.lineEdit().returnPressed.connect(self.filter_changed)
|
||||||
|
self.query_field.setInsertPolicy(QComboBox.NoInsert)
|
||||||
|
|
||||||
self.btn_cancel_search = QPushButton(_("Cancel"))
|
self.btn_cancel_search = QPushButton(_("Cancel"))
|
||||||
self.btn_cancel_search.setVisible(False)
|
self.btn_cancel_search.setVisible(False)
|
||||||
self.btn_cancel_search.pressed.connect(self._cancel_search)
|
self.btn_cancel_search.pressed.connect(self._cancel_search)
|
||||||
self.search_is_running.connect(lambda is_running: self.btn_cancel_search.setVisible(is_running))
|
self.search_is_running.connect(lambda is_running: self.btn_cancel_search.setVisible(is_running))
|
||||||
|
|
||||||
|
self.btn_bookmark = QPushButton(QIcon("icons/ionicons/star.svg"), "")
|
||||||
|
self.btn_bookmark.setToolTip(_("save query"))
|
||||||
|
self.btn_bookmark.pressed.connect(self._save_query)
|
||||||
|
|
||||||
self.ignore_case = QCheckBox(_("ignore case"))
|
self.ignore_case = QCheckBox(_("ignore case"))
|
||||||
self.ignore_case.setChecked(True)
|
self.ignore_case.setChecked(True)
|
||||||
self.ignore_case.stateChanged.connect(self.filter_changed)
|
self.ignore_case.stateChanged.connect(self.filter_changed)
|
||||||
@@ -117,6 +128,7 @@ class FilterWidget(QWidget):
|
|||||||
filter_bar.layout.setContentsMargins(0, 0, 0, 0)
|
filter_bar.layout.setContentsMargins(0, 0, 0, 0)
|
||||||
filter_bar.layout.addWidget(self.query_field)
|
filter_bar.layout.addWidget(self.query_field)
|
||||||
filter_bar.layout.addWidget(self.btn_cancel_search)
|
filter_bar.layout.addWidget(self.btn_cancel_search)
|
||||||
|
filter_bar.layout.addWidget(self.btn_bookmark)
|
||||||
filter_bar.layout.addWidget(self.ignore_case)
|
filter_bar.layout.addWidget(self.ignore_case)
|
||||||
filter_bar.layout.addWidget(self.is_regex)
|
filter_bar.layout.addWidget(self.is_regex)
|
||||||
|
|
||||||
@@ -130,12 +142,31 @@ class FilterWidget(QWidget):
|
|||||||
|
|
||||||
self.filter_match_found_listeners: [Callable[[int], None]] = []
|
self.filter_match_found_listeners: [Callable[[int], None]] = []
|
||||||
|
|
||||||
|
def on_reveal(self):
|
||||||
|
self._reload_save_queries()
|
||||||
|
|
||||||
|
def _reload_save_queries(self):
|
||||||
|
current_text = self.query_field.currentText()
|
||||||
|
self.query_field.clear()
|
||||||
|
saved_queries = PluginRegistry.execute_single("saved_queries")
|
||||||
|
self.query_field.addItem("")
|
||||||
|
for saved_query in saved_queries:
|
||||||
|
self.query_field.addItem(saved_query)
|
||||||
|
|
||||||
|
self.query_field.setCurrentText(current_text)
|
||||||
|
|
||||||
def add_line_click_listener(self, listener: Callable[[int], None]):
|
def add_line_click_listener(self, listener: Callable[[int], None]):
|
||||||
self.hits_view.add_line_click_listener(listener)
|
self.hits_view.add_line_click_listener(listener)
|
||||||
|
|
||||||
def add_filter_match_found_listener(self, listener: Callable[[int], None]):
|
def add_filter_match_found_listener(self, listener: Callable[[int], None]):
|
||||||
self.filter_match_found_listeners.append(listener)
|
self.filter_match_found_listeners.append(listener)
|
||||||
|
|
||||||
|
def _save_query(self):
|
||||||
|
query = self.query_field.currentText()
|
||||||
|
if len(query) > 0:
|
||||||
|
PluginRegistry.execute("save_query", query)
|
||||||
|
self._reload_save_queries()
|
||||||
|
|
||||||
def destruct(self):
|
def destruct(self):
|
||||||
# print("cleanup: ", self.tmpfilename)
|
# print("cleanup: ", self.tmpfilename)
|
||||||
self._cancel_search()
|
self._cancel_search()
|
||||||
@@ -156,7 +187,7 @@ class FilterWidget(QWidget):
|
|||||||
PluginRegistry.execute("update_ui")
|
PluginRegistry.execute("update_ui")
|
||||||
|
|
||||||
def filter_changed(self):
|
def filter_changed(self):
|
||||||
query = self.query_field.text()
|
query = self.query_field.currentText()
|
||||||
ignore_case = self.ignore_case.isChecked()
|
ignore_case = self.ignore_case.isChecked()
|
||||||
is_regex = self.is_regex.isChecked()
|
is_regex = self.is_regex.isChecked()
|
||||||
|
|
||||||
|
|||||||
@@ -45,3 +45,7 @@ class FullTabWidget(Tab):
|
|||||||
file = self._model.get_file()
|
file = self._model.get_file()
|
||||||
file_size = humanbytes(self._model.byte_count())
|
file_size = humanbytes(self._model.byte_count())
|
||||||
return "%s - %s" % (file_size, file)
|
return "%s - %s" % (file_size, file)
|
||||||
|
|
||||||
|
# overriding abstract method
|
||||||
|
def on_reveal(self):
|
||||||
|
self.filter_hit_view.on_reveal()
|
||||||
|
|||||||
@@ -34,3 +34,18 @@ class LogFilePlugin(PluginBase):
|
|||||||
tab = FullTabWidget(model, unique_id=realpath, title=filename)
|
tab = FullTabWidget(model, unique_id=realpath, title=filename)
|
||||||
|
|
||||||
return tab
|
return tab
|
||||||
|
|
||||||
|
def saved_queries(self) -> [str]:
|
||||||
|
saved_queries = self.settings.get_session("general", "saved_queries", "").splitlines()
|
||||||
|
if "" in saved_queries:
|
||||||
|
saved_queries.remove("")
|
||||||
|
saved_queries.sort()
|
||||||
|
return saved_queries
|
||||||
|
|
||||||
|
def save_query(self, query: str):
|
||||||
|
saved_queries = self.settings.get_session("general", "saved_queries", "").splitlines()
|
||||||
|
if "" in saved_queries:
|
||||||
|
saved_queries.remove("")
|
||||||
|
if not query in saved_queries:
|
||||||
|
saved_queries.append(query)
|
||||||
|
self.settings.set_session("general", "saved_queries", "\n".join(saved_queries))
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class Tabs(QWidget):
|
|||||||
if tab:
|
if tab:
|
||||||
PluginRegistry.execute("update_window_title", tab.title)
|
PluginRegistry.execute("update_window_title", tab.title)
|
||||||
PluginRegistry.execute("update_status_bar", tab.get_status_text())
|
PluginRegistry.execute("update_status_bar", tab.get_status_text())
|
||||||
|
tab.on_reveal()
|
||||||
else:
|
else:
|
||||||
PluginRegistry.execute("update_window_title", "")
|
PluginRegistry.execute("update_window_title", "")
|
||||||
PluginRegistry.execute("update_status_bar", "")
|
PluginRegistry.execute("update_status_bar", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user