Merge destroy handlers, connect ESC key, remove transient

This commit is contained in:
Daniel Brötzmann 2018-11-01 16:42:09 +01:00
parent d106c0d316
commit 43f07c19e5
4 changed files with 24 additions and 18 deletions

View File

@ -251,8 +251,7 @@ def on_manage_proxies(action, param):
if 'manage_proxies' in app.interface.instances: if 'manage_proxies' in app.interface.instances:
app.interface.instances['manage_proxies'].window.present() app.interface.instances['manage_proxies'].window.present()
else: else:
app.interface.instances['manage_proxies'] = \ app.interface.instances['manage_proxies'] = ManageProxies()
ManageProxies(interface.roster.window)
# Admin Actions # Admin Actions

View File

@ -29,7 +29,8 @@
<property name="default_width">500</property> <property name="default_width">500</property>
<property name="default_height">440</property> <property name="default_height">440</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>
<signal name="destroy" handler="on_manage_proxies_window_destroy" swapped="no"/> <signal name="destroy" handler="_on_destroy" swapped="no"/>
<signal name="key-press-event" handler="_on_key_press" swapped="no"/>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>

View File

@ -1025,7 +1025,7 @@ class Preferences(Gtk.ApplicationWindow):
if 'manage_proxies' in app.interface.instances: if 'manage_proxies' in app.interface.instances:
app.interface.instances['manage_proxies'].window.present() app.interface.instances['manage_proxies'].window.present()
else: else:
app.interface.instances['manage_proxies'] = ManageProxies(self) app.interface.instances['manage_proxies'] = ManageProxies()
def update_proxy_list(self): def update_proxy_list(self):
our_proxy = app.config.get('global_proxy') our_proxy = app.config.get('global_proxy')

View File

@ -12,8 +12,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>. # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import Gtk
from gajim.common import app from gajim.common import app
from gajim.common.i18n import _ from gajim.common.i18n import _
@ -22,15 +22,16 @@ from gajim.gtk.util import get_builder
class ManageProxies: class ManageProxies:
def __init__(self, transient_for=None): def __init__(self):
self._ui = get_builder('manage_proxies_window.ui') self._ui = get_builder('manage_proxies_window.ui')
self._ui.manage_proxies_window.set_transient_for(transient_for) self.window = self._ui.manage_proxies_window
self.window.set_transient_for(app.app.get_active_window())
self.init_list() self.init_list()
self.block_signal = False self.block_signal = False
self._ui.connect_signals(self) self._ui.connect_signals(self)
self._ui.manage_proxies_window.connect('destroy', self._on_destroy) self.window.show_all()
self._ui.manage_proxies_window.show_all()
# hide the BOSH fields by default # hide the BOSH fields by default
self.show_bosh_fields() self.show_bosh_fields()
self._ui.boshuri_entry.hide() self._ui.boshuri_entry.hide()
@ -76,12 +77,6 @@ class ManageProxies:
self.fill_proxies_treeview() self.fill_proxies_treeview()
self._ui.proxytype_combobox.set_active(0) self._ui.proxytype_combobox.set_active(0)
def on_manage_proxies_window_destroy(self, _widget):
window = app.get_app_window('AccountsWindow')
if window is not None:
window.update_proxy_list()
del app.interface.instances['manage_proxies']
def on_add_proxy_button_clicked(self, _widget): def on_add_proxy_button_clicked(self, _widget):
model = self._ui.proxies_treeview.get_model() model = self._ui.proxies_treeview.get_model()
proxies = app.config.get_per('proxies') proxies = app.config.get_per('proxies')
@ -101,6 +96,8 @@ class ManageProxies:
if not iter_: if not iter_:
return return
proxy = model[iter_][0] proxy = model[iter_][0]
if proxy == _('None'):
return
model.remove(iter_) model.remove(iter_)
app.config.del_per('proxies', proxy) app.config.del_per('proxies', proxy)
self._ui.remove_proxy_button.set_sensitive(False) self._ui.remove_proxy_button.set_sensitive(False)
@ -268,7 +265,16 @@ class ManageProxies:
proxy = self._ui.proxyname_entry.get_text() proxy = self._ui.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'pass', value) app.config.set_per('proxies', proxy, 'pass', value)
def _on_key_press(self, widget, event):
if event.keyval == Gdk.KEY_Escape:
self.window.destroy()
def _on_destroy(self, *args): def _on_destroy(self, *args):
window = app.get_app_window('Preferences') window_pref = app.get_app_window('Preferences')
if window is not None: window_accounts = app.get_app_window('AccountsWindow')
window.update_proxy_list() if window_pref is not None:
window_pref.update_proxy_list()
if window_accounts is not None:
window_accounts.update_proxy_list()
self.window.destroy()
del app.interface.instances['manage_proxies']