message menu update - plugins, quotes

This commit is contained in:
ingvar1995 2016-07-19 23:19:42 +03:00
parent 6297da1c69
commit 697a9efb51
5 changed files with 44 additions and 3 deletions

View file

@ -42,10 +42,31 @@ class MessageEdit(QtGui.QTextBrowser):
def contextMenuEvent(self, event):
menu = create_menu(self.createStandardContextMenu(event.pos()))
quote = menu.addAction(QtGui.QApplication.translate("MainWindow", 'Quote selected text', None, QtGui.QApplication.UnicodeUTF8))
quote.triggered.connect(self.quote_text)
text = self.textCursor().selection().toPlainText()
if not text:
quote.setEnabled(False)
else:
import plugin_support
submenu = plugin_support.PluginLoader.get_instance().get_message_menu(menu, text)
if len(submenu):
plug = menu.addMenu(QtGui.QApplication.translate("MainWindow", 'Plugins', None, QtGui.QApplication.UnicodeUTF8))
plug.addActions(submenu)
menu.popup(event.globalPos())
menu.exec_(event.globalPos())
del menu
def quote_text(self):
text = self.textCursor().selection().toPlainText()
if text:
import mainscreen
window = mainscreen.MainWindow.get_instance()
text = '>' + '\n>'.join(text.split('\n'))
if window.messageEdit.toPlainText():
text = '\n' + text
window.messageEdit.appendPlainText(text)
def on_anchor_clicked(self, url):
text = str(url.toString())
if text.startswith('tox:'):

View file

@ -8,10 +8,11 @@ import plugin_support
from mainscreen_widgets import *
class MainWindow(QtGui.QMainWindow):
class MainWindow(QtGui.QMainWindow, Singleton):
def __init__(self, tox, reset, tray):
super(MainWindow, self).__init__()
super().__init__()
Singleton.__init__(self)
self.reset = reset
self.tray = tray
self.setAcceptDrops(True)

View file

@ -147,6 +147,16 @@ class PluginLoader(util.Singleton):
continue
return result
def get_message_menu(self, menu, selected_text):
result = []
for elem in self._plugins.values():
if elem[1]:
try:
result.extend(elem[0].get_message_menu(menu, selected_text))
except:
continue
return result
def stop(self):
"""
App is closing, stop all plugins

View file

@ -88,6 +88,15 @@ class PluginSuperClass:
"""
return []
def get_message_menu(self, menu, text):
"""
This method creates items for menu which called on right click in message
:param menu: menu instance
:param text: selected text
:return list of QAction's
"""
return []
def get_window(self):
"""
This method should return window for plugins with GUI or None

View file

@ -171,7 +171,7 @@ class Profile(contact.Contact, Singleton):
self.send_typing(False)
self._screen.typing.setVisible(False)
if value is not None:
if self._active_friend + 1:
if self._active_friend + 1 and self._active_friend != value:
try:
self._friends[self._active_friend].curr_text = self._screen.messageEdit.toPlainText()
except: