Daniel Brötzmann pushed to branch master at gajim / gajim


Commits:
aa968238 by wurstsalat at 2022-05-30T14:43:14+02:00
imprv: ComponentSearch: Show Start Chat for JIDs only

- - - - -


2 changed files:

- gajim/gtk/component_search.py
- gajim/gtk/menus.py


Changes:

=====================================
gajim/gtk/component_search.py
=====================================
@@ -40,7 +40,7 @@
 from .assistant import Page
 from .assistant import ProgressPage
 from .dataform import DataFormWidget
-from .menus import get_directory_search_menu
+from .menus import get_component_search_menu
 from .util import ensure_not_destroyed
 from .util import EventHelper
 
@@ -208,6 +208,8 @@ def __init__(self) -> None:
         Page.__init__(self)
         self.title = _('Search Result')
 
+        self._jid_col: Optional[int] = None
+
         self._label = Gtk.Label(label=_('No results found'))
         self._label.get_style_context().add_class('bold16')
         self._label.set_no_show_all(True)
@@ -241,15 +243,20 @@ def process_result(self, form: Optional[Node]) -> None:
 
         fieldtypes: list[Union[Type[bool], Type[str]]] = []
         fieldvars: list[Any] = []
+        index = 0
         for field in form.reported.iter_fields():
             if field.type_ == 'boolean':
                 fieldtypes.append(bool)
             elif field.type_ in ('jid-single', 'text-single'):
                 fieldtypes.append(str)
+                if field.type_ == 'jid-single' or field.var == 'jid':
+                    # Enable Start Chat context menu entry
+                    self._jid_col = index
             else:
                 log.warning('Not supported field received: %s', field.type_)
                 continue
             fieldvars.append(field.var)
+            index += 1
 
         liststore = Gtk.ListStore(*fieldtypes)
 
@@ -298,7 +305,10 @@ def _on_button_press(self,
         column_values = store[iter_]
         text = ' '.join(column_values)
 
-        menu = get_directory_search_menu(column_values[0], text)
+        jid = None
+        if self._jid_col is not None:
+            jid = column_values[self._jid_col]
+        menu = get_component_search_menu(jid, text)
 
         rectangle = Gdk.Rectangle()
         rectangle.x = int(event.x)


=====================================
gajim/gtk/menus.py
=====================================
@@ -549,11 +549,14 @@ def get_groupchat_roster_menu(account: str,
     return menu
 
 
-def get_directory_search_menu(jid: str, copy_text: str) -> Gio.Menu:
+def get_component_search_menu(jid: Optional[str], copy_text: str) -> Gio.Menu:
     menu_items: list[tuple[str, str]] = [
         ('app.copy-text', _('Copy')),
-        ('app.start-chat', _('Start Chat…'))
     ]
+    if jid is not None:
+        menu_items.append(
+            ('app.start-chat', _('Start Chat…')))
+
     menu = Gio.Menu()
     for item in menu_items:
         action, label = item



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/aa96823872c7aa07b0b5dc530d2beb92ad4f0e3f

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/aa96823872c7aa07b0b5dc530d2beb92ad4f0e3f
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to