Message search (yeah finally)
This commit is contained in:
parent
3653af7b81
commit
5150fd769a
@ -72,7 +72,8 @@ class chat(Gtk.ScrolledWindow):
|
||||
self.welcome_screen = None
|
||||
self.regenerate_button = None
|
||||
self.busy = False
|
||||
self.get_vadjustment().connect('notify::page-size', lambda va, *_: va.set_value(va.get_upper() - va.get_page_size()) if va.get_value() == 0 else None)
|
||||
#self.get_vadjustment().connect('notify::page-size', lambda va, *_: va.set_value(va.get_upper() - va.get_page_size()) if va.get_value() == 0 else None)
|
||||
##TODO Figure out how to do this with the search thing
|
||||
|
||||
def stop_message(self):
|
||||
self.busy = False
|
||||
@ -436,6 +437,10 @@ class chat_list(Gtk.ListBox):
|
||||
if row:
|
||||
current_tab_i = next((i for i, t in enumerate(self.tab_list) if t.chat_window == window.chat_stack.get_visible_child()), -1)
|
||||
if self.tab_list.index(row) != current_tab_i:
|
||||
if window.searchentry_messages.get_text() != '':
|
||||
window.searchentry_messages.set_text('')
|
||||
window.message_search_changed(window.searchentry_messages, window.chat_stack.get_visible_child())
|
||||
window.message_searchbar.set_search_mode(False)
|
||||
window.chat_stack.set_transition_type(4 if self.tab_list.index(row) > current_tab_i else 5)
|
||||
window.chat_stack.set_visible_child(row.chat_window)
|
||||
window.switch_send_stop_button(not row.chat_window.busy)
|
||||
|
@ -92,6 +92,9 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
||||
file_preview_remove_button = Gtk.Template.Child()
|
||||
secondary_menu_button = Gtk.Template.Child()
|
||||
model_searchbar = Gtk.Template.Child()
|
||||
message_searchbar = Gtk.Template.Child()
|
||||
message_search_button = Gtk.Template.Child()
|
||||
searchentry_messages = Gtk.Template.Child()
|
||||
no_results_page = Gtk.Template.Child()
|
||||
model_link_button = Gtk.Template.Child()
|
||||
title_stack = Gtk.Template.Child()
|
||||
@ -321,6 +324,10 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
||||
self.model_manager.pulling_list.set_visible(not button.get_active() and len(list(self.model_manager.pulling_list)) > 0)
|
||||
self.model_manager.local_list.set_visible(not button.get_active() and len(list(self.model_manager.local_list)) > 0)
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def message_search_toggle(self, button):
|
||||
self.message_searchbar.set_search_mode(button.get_active())
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def model_search_changed(self, entry):
|
||||
results = 0
|
||||
@ -336,6 +343,23 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
||||
self.model_scroller.set_visible(True)
|
||||
self.no_results_page.set_visible(False)
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def message_search_changed(self, entry, current_chat=None):
|
||||
search_term=entry.get_text()
|
||||
results = 0
|
||||
if not current_chat:
|
||||
current_chat = self.chat_list_box.get_current_chat()
|
||||
if current_chat:
|
||||
for key, message in current_chat.messages.items():
|
||||
message.set_visible(re.search(search_term, message.text, re.IGNORECASE))
|
||||
for block in message.content_children:
|
||||
if isinstance(block, message_widget.text_block):
|
||||
if search_term:
|
||||
highlighted_text = re.sub(f"({re.escape(search_term)})", r"<span background='yellow' bgalpha='30%'>\1</span>", block.get_text(),flags=re.IGNORECASE)
|
||||
block.set_markup(highlighted_text)
|
||||
else:
|
||||
block.set_markup(block.get_text())
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_clipboard_paste(self, textview):
|
||||
logger.debug("Pasting from clipboard")
|
||||
@ -827,7 +851,7 @@ Generate a title following these rules:
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.message_searchbar.connect('notify::search-mode-enabled', lambda *_: self.message_search_button.set_active(self.message_searchbar.get_search_mode()))
|
||||
message_widget.window = self
|
||||
chat_widget.window = self
|
||||
model_widget.window = self
|
||||
@ -864,7 +888,8 @@ Generate a title following these rules:
|
||||
'export_chat': [self.chat_actions],
|
||||
'export_current_chat': [self.current_chat_actions],
|
||||
'toggle_sidebar': [lambda *_: self.split_view_overlay.set_show_sidebar(not self.split_view_overlay.get_show_sidebar()), ['F9']],
|
||||
'manage_models': [lambda *_: self.manage_models_dialog.present(self), ['<primary>m']]
|
||||
'manage_models': [lambda *_: self.manage_models_dialog.present(self), ['<primary>m']],
|
||||
'search_messages': [lambda *_: self.message_searchbar.set_search_mode(not self.message_searchbar.get_search_mode()), ['<primary>f']]
|
||||
}
|
||||
|
||||
for action_name, data in universal_actions.items():
|
||||
|
@ -54,6 +54,7 @@
|
||||
</property>
|
||||
<child>
|
||||
<object class="AdwToolbarView">
|
||||
<property name="height-request">140</property>
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar">
|
||||
<child type="start">
|
||||
@ -63,6 +64,13 @@
|
||||
<property name="active" bind-source="split_view_overlay" bind-property="show-sidebar" bind-flags="sync-create"/>
|
||||
</object>
|
||||
</child>
|
||||
<child type="start">
|
||||
<object class="GtkToggleButton" id="message_search_button">
|
||||
<property name="icon-name">edit-find-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Search Messages</property>
|
||||
<signal name="clicked" handler="message_search_toggle"/>
|
||||
</object>
|
||||
</child>
|
||||
<child type="title">
|
||||
<object class="GtkStack" id="title_stack">
|
||||
<property name="transition_duration">100</property>
|
||||
@ -100,6 +108,24 @@
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="top">
|
||||
<object class="GtkSearchBar" id="message_searchbar">
|
||||
<accessibility>
|
||||
<property name="label" translatable="yes">Message search bar</property>
|
||||
</accessibility>
|
||||
<property name="key-capture-widget">AlpacaWindow</property>
|
||||
<child>
|
||||
<object class="GtkSearchEntry" id="searchentry_messages">
|
||||
<signal name="search-changed" handler="message_search_changed"/>
|
||||
<property name="search-delay">200</property>
|
||||
<property name="placeholder-text" translatable="yes">Search messages</property>
|
||||
<accessibility>
|
||||
<property name="label" translatable="yes">Search messages</property>
|
||||
</accessibility>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="GtkBox"><!--ACTUAL CONTENT-->
|
||||
<property name="orientation">1</property>
|
||||
|
Loading…
x
Reference in New Issue
Block a user