|
|
1
|
+import logging
|
|
1
|
2
|
|
|
2
|
3
|
from gi.repository import Gtk
|
|
|
4
|
+from gi.repository import Gdk
|
|
3
|
5
|
from gi.repository import GLib
|
|
4
|
6
|
from gi.repository import Gio
|
|
5
|
7
|
|
| ... |
... |
@@ -23,6 +25,9 @@ |
|
23
|
25
|
from .util import open_window
|
|
24
|
26
|
|
|
25
|
27
|
|
|
|
28
|
+log = logging.getLogger('gajim.gui.main')
|
|
|
29
|
+
|
|
|
30
|
+
|
|
26
|
31
|
class MainWindow(Gtk.ApplicationWindow, EventHelper):
|
|
27
|
32
|
def __init__(self):
|
|
28
|
33
|
Gtk.ApplicationWindow.__init__(self)
|
| ... |
... |
@@ -118,6 +123,7 @@ def __init__(self): |
|
118
|
123
|
self._load_chats()
|
|
119
|
124
|
self._add_accounts()
|
|
120
|
125
|
self._add_actions()
|
|
|
126
|
+ self._add_actions2()
|
|
121
|
127
|
|
|
122
|
128
|
@staticmethod
|
|
123
|
129
|
def _on_our_show(event):
|
| ... |
... |
@@ -154,6 +160,117 @@ def _add_actions(self): |
|
154
|
160
|
act.connect('activate', func)
|
|
155
|
161
|
self.add_action(act)
|
|
156
|
162
|
|
|
|
163
|
+ def _add_actions2(self):
|
|
|
164
|
+ actions = [
|
|
|
165
|
+ 'change-nickname',
|
|
|
166
|
+ 'change-subject',
|
|
|
167
|
+ 'escape',
|
|
|
168
|
+ 'browse-history',
|
|
|
169
|
+ 'send-file',
|
|
|
170
|
+ 'show-contact-info',
|
|
|
171
|
+ 'show-emoji-chooser',
|
|
|
172
|
+ 'clear-chat',
|
|
|
173
|
+ 'delete-line',
|
|
|
174
|
+ 'close-tab',
|
|
|
175
|
+ 'move-tab-up',
|
|
|
176
|
+ 'move-tab-down',
|
|
|
177
|
+ 'switch-next-tab',
|
|
|
178
|
+ 'switch-prev-tab',
|
|
|
179
|
+ 'switch-next-unread-tab-right'
|
|
|
180
|
+ 'switch-next-unread-tab-left',
|
|
|
181
|
+ 'switch-tab-1',
|
|
|
182
|
+ 'switch-tab-2',
|
|
|
183
|
+ 'switch-tab-3',
|
|
|
184
|
+ 'switch-tab-4',
|
|
|
185
|
+ 'switch-tab-5',
|
|
|
186
|
+ 'switch-tab-6',
|
|
|
187
|
+ 'switch-tab-7',
|
|
|
188
|
+ 'switch-tab-8',
|
|
|
189
|
+ 'switch-tab-9',
|
|
|
190
|
+ ]
|
|
|
191
|
+
|
|
|
192
|
+ disabled_for_emacs = (
|
|
|
193
|
+ 'browse-history',
|
|
|
194
|
+ 'send-file',
|
|
|
195
|
+ 'close-tab'
|
|
|
196
|
+ )
|
|
|
197
|
+
|
|
|
198
|
+ key_theme = Gtk.Settings.get_default().get_property(
|
|
|
199
|
+ 'gtk-key-theme-name')
|
|
|
200
|
+
|
|
|
201
|
+ for action in actions:
|
|
|
202
|
+ if key_theme == 'Emacs' and action in disabled_for_emacs:
|
|
|
203
|
+ continue
|
|
|
204
|
+ act = Gio.SimpleAction.new(action, None)
|
|
|
205
|
+ act.connect('activate', self._on_action)
|
|
|
206
|
+ self.add_action(act)
|
|
|
207
|
+
|
|
|
208
|
+ def _on_action(self, action, _param):
|
|
|
209
|
+ control = self.get_active_control()
|
|
|
210
|
+ if control is None:
|
|
|
211
|
+ return
|
|
|
212
|
+
|
|
|
213
|
+ log.info('Activate action: %s, active control: %s',
|
|
|
214
|
+ action.get_name(), control.contact.jid)
|
|
|
215
|
+
|
|
|
216
|
+ action = action.get_name()
|
|
|
217
|
+
|
|
|
218
|
+ res = control.delegate_action(action)
|
|
|
219
|
+ if res != Gdk.EVENT_PROPAGATE:
|
|
|
220
|
+ return res
|
|
|
221
|
+
|
|
|
222
|
+ # if action == 'escape' and app.settings.get('escape_key_closes'):
|
|
|
223
|
+ # self.remove_tab(control, self.CLOSE_ESC)
|
|
|
224
|
+ # return
|
|
|
225
|
+
|
|
|
226
|
+ # if action == 'close-tab':
|
|
|
227
|
+ # self.remove_tab(control, self.CLOSE_CTRL_KEY)
|
|
|
228
|
+ # return
|
|
|
229
|
+
|
|
|
230
|
+ # if action == 'move-tab-up':
|
|
|
231
|
+ # old_position = self.notebook.get_current_page()
|
|
|
232
|
+ # self.notebook.reorder_child(control.widget,
|
|
|
233
|
+ # old_position - 1)
|
|
|
234
|
+ # return
|
|
|
235
|
+
|
|
|
236
|
+ # if action == 'move-tab-down':
|
|
|
237
|
+ # old_position = self.notebook.get_current_page()
|
|
|
238
|
+ # total_pages = self.notebook.get_n_pages()
|
|
|
239
|
+ # if old_position == total_pages - 1:
|
|
|
240
|
+ # self.notebook.reorder_child(control.widget, 0)
|
|
|
241
|
+ # else:
|
|
|
242
|
+ # self.notebook.reorder_child(control.widget,
|
|
|
243
|
+ # old_position + 1)
|
|
|
244
|
+ # return
|
|
|
245
|
+
|
|
|
246
|
+ # if action == 'switch-next-tab':
|
|
|
247
|
+ # new = self.notebook.get_current_page() + 1
|
|
|
248
|
+ # if new >= self.notebook.get_n_pages():
|
|
|
249
|
+ # new = 0
|
|
|
250
|
+ # self.notebook.set_current_page(new)
|
|
|
251
|
+ # return
|
|
|
252
|
+
|
|
|
253
|
+ # if action == 'switch-prev-tab':
|
|
|
254
|
+ # new = self.notebook.get_current_page() - 1
|
|
|
255
|
+ # if new < 0:
|
|
|
256
|
+ # new = self.notebook.get_n_pages() - 1
|
|
|
257
|
+ # self.notebook.set_current_page(new)
|
|
|
258
|
+ # return
|
|
|
259
|
+
|
|
|
260
|
+ # if action == 'switch-next-unread-tab-right':
|
|
|
261
|
+ # self.move_to_next_unread_tab(True)
|
|
|
262
|
+ # return
|
|
|
263
|
+
|
|
|
264
|
+ # if action == 'switch-next-unread-tab-left':
|
|
|
265
|
+ # self.move_to_next_unread_tab(False)
|
|
|
266
|
+ # return
|
|
|
267
|
+
|
|
|
268
|
+ # if action.startswith('switch-tab-'):
|
|
|
269
|
+ # number = int(action[-1])
|
|
|
270
|
+ # self.notebook.set_current_page(number - 1)
|
|
|
271
|
+ # return
|
|
|
272
|
+
|
|
|
273
|
+
|
|
157
|
274
|
def get_widget(self, name):
|
|
158
|
275
|
return getattr(self._ui, name)
|
|
159
|
276
|
|
| ... |
... |
@@ -286,6 +403,12 @@ def chat_exists_for_workspace(self, workspace_id, account, jid): |
|
286
|
403
|
def get_control(self, account, jid):
|
|
287
|
404
|
return self._chat_stack.get_control(account, jid)
|
|
288
|
405
|
|
|
|
406
|
+ def get_active_control(self):
|
|
|
407
|
+ chat = self._chat_list_stack.get_selected_chat()
|
|
|
408
|
+ if chat is None:
|
|
|
409
|
+ return None
|
|
|
410
|
+ return self.get_control(chat.account, chat.jid)
|
|
|
411
|
+
|
|
289
|
412
|
def _add_accounts(self):
|
|
290
|
413
|
for account in list(app.connections.keys()):
|
|
291
|
414
|
self._ui.main_stack.add_named(
|