[quick_replies] Complete rework
This commit is contained in:
85
quick_replies/gtk/config.py
Normal file
85
quick_replies/gtk/config.py
Normal file
@@ -0,0 +1,85 @@
|
||||
# Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com>
|
||||
#
|
||||
# This file is part of Quick Replies.
|
||||
#
|
||||
# Quick Replies is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published
|
||||
# by the Free Software Foundation; version 3 only.
|
||||
#
|
||||
# Quick Replies is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Quick Replies. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
|
||||
from gajim.common import app
|
||||
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
from gajim.plugins.helpers import get_builder
|
||||
|
||||
|
||||
class ConfigDialog(Gtk.ApplicationWindow):
|
||||
def __init__(self, plugin, transient):
|
||||
Gtk.ApplicationWindow.__init__(self)
|
||||
self.set_application(app.app)
|
||||
self.set_show_menubar(False)
|
||||
self.set_title(_('Quick Replies Configuration'))
|
||||
self.set_transient_for(transient)
|
||||
self.set_default_size(400, 400)
|
||||
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
|
||||
self.set_modal(True)
|
||||
self.set_destroy_with_parent(True)
|
||||
|
||||
ui_path = Path(__file__).parent
|
||||
self._ui = get_builder(ui_path.resolve() / 'config.ui')
|
||||
|
||||
self._plugin = plugin
|
||||
|
||||
self.add(self._ui.box)
|
||||
|
||||
self._fill_list()
|
||||
self.show_all()
|
||||
|
||||
self._ui.connect_signals(self)
|
||||
self.connect('destroy', self._on_destroy)
|
||||
|
||||
def _fill_list(self):
|
||||
for reply in self._plugin.quick_replies:
|
||||
self._ui.replies_store.append([reply])
|
||||
|
||||
def _on_reply_edited(self, _renderer, path, new_text):
|
||||
iter_ = self._ui.replies_store.get_iter(path)
|
||||
self._ui.replies_store.set_value(iter_, 0, new_text)
|
||||
|
||||
def _on_add_clicked(self, _button):
|
||||
self._ui.replies_store.append([_('New Quick Reply')])
|
||||
row = self._ui.replies_store[-1]
|
||||
self._ui.replies_treeview.scroll_to_cell(
|
||||
row.path, None, False, 0, 0)
|
||||
self._ui.selection.unselect_all()
|
||||
self._ui.selection.select_path(row.path)
|
||||
|
||||
def _on_remove_clicked(self, _button):
|
||||
model, paths = self._ui.selection.get_selected_rows()
|
||||
references = []
|
||||
for path in paths:
|
||||
references.append(Gtk.TreeRowReference.new(model, path))
|
||||
|
||||
for ref in references:
|
||||
iter_ = model.get_iter(ref.get_path())
|
||||
self._ui.replies_store.remove(iter_)
|
||||
|
||||
def _on_destroy(self, *args):
|
||||
replies = []
|
||||
for row in self._ui.replies_store:
|
||||
if row[0] == '':
|
||||
continue
|
||||
replies.append(row[0])
|
||||
self._plugin.set_quick_replies(replies)
|
||||
103
quick_replies/gtk/config.ui
Normal file
103
quick_replies/gtk/config.ui
Normal file
@@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.2 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkListStore" id="replies_store">
|
||||
<columns>
|
||||
<!-- column-name reply -->
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkBox" id="box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">18</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="replies_treeview">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">replies_store</property>
|
||||
<property name="search_column">1</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="selection">
|
||||
<property name="mode">multiple</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="title" translatable="yes">Quick Reply</property>
|
||||
<property name="clickable">True</property>
|
||||
<property name="sort_indicator">True</property>
|
||||
<property name="sort_column_id">0</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText">
|
||||
<property name="editable">True</property>
|
||||
<signal name="edited" handler="_on_reply_edited" swapped="no"/>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolbar">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="toolbar_style">icons</property>
|
||||
<property name="icon_size">4</property>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Add</property>
|
||||
<property name="icon_name">list-add-symbolic</property>
|
||||
<signal name="clicked" handler="_on_add_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Remove</property>
|
||||
<property name="icon_name">list-remove-symbolic</property>
|
||||
<signal name="clicked" handler="_on_remove_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<style>
|
||||
<class name="inline-toolbar"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
Reference in New Issue
Block a user