Changed the shell language menu to be dynamic.

Sat, 03 Oct 2015 14:09:05 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 03 Oct 2015 14:09:05 +0200
changeset 4479
fd9ceecf5a65
parent 4477
014e27865a07
child 4480
2dec66f0b518

Changed the shell language menu to be dynamic.

QScintilla/Shell.py file | annotate | diff | comparison | revisions
--- a/QScintilla/Shell.py	Thu Oct 01 19:05:11 2015 +0200
+++ b/QScintilla/Shell.py	Sat Oct 03 14:09:05 2015 +0200
@@ -203,11 +203,7 @@
         
         # Create a little language context menu
         self.lmenu = QMenu(self.tr('Start'))
-        self.clientLanguages = self.dbs.getSupportedLanguages(shellOnly=True)
-        self.clientLanguages.sort()
-        for language in self.clientLanguages:
-            act = self.lmenu.addAction(language)
-            act.setData(language)
+        self.lmenu.aboutToShow.connect(self.__showLanguageMenu)
         self.lmenu.triggered.connect(self.__startDebugClient)
         
         # Create the history context menu
@@ -282,6 +278,16 @@
         
         self.grabGesture(Qt.PinchGesture)
         
+    def __showLanguageMenu(self):
+        """
+        Private slot to prepare the language submenu.
+        """
+        self.lmenu.clear()
+        clientLanguages = self.dbs.getSupportedLanguages(shellOnly=True)
+        for language in sorted(clientLanguages):
+            act = self.lmenu.addAction(language)
+            act.setData(language)
+        
     def __resizeLinenoMargin(self):
         """
         Private slot to resize the line numbers margin.
@@ -1371,10 +1377,12 @@
                     if len(cmdList) < 2:
                         self.dbs.startClient(False)  # same as reset
                     else:
+                        clientLanguages = self.dbs.getSupportedLanguages(
+                            shellOnly=True)
                         language = cmdList[1]
-                        if language not in self.clientLanguages:
+                        if language not in clientLanguages:
                             language = cmdList[1].capitalize()
-                            if language not in self.clientLanguages:
+                            if language not in clientLanguages:
                                 language = ""
                         if language:
                             self.dbs.startClient(False, language)
@@ -1388,7 +1396,8 @@
                         return
                     cmd = ''
             elif cmd == 'languages':
-                s = '{0}\n'.format(', '.join(self.clientLanguages))
+                s = '{0}\n'.format(', '.join(sorted(
+                    self.dbs.getSupportedLanguages(shellOnly=True))))
                 self.__write(s)
                 self.__clientStatement(False)
                 return
@@ -1569,14 +1578,6 @@
                 self.dbs.clientProcessStderr.disconnect(self.__writeStdErr)
             self.__showStdOutErr = showStdOutErr
         
-        # recreate the languages menu
-        self.lmenu.clear()
-        self.clientLanguages = self.dbs.getSupportedLanguages(shellOnly=True)
-        self.clientLanguages.sort()
-        for language in self.clientLanguages:
-            act = self.lmenu.addAction(language)
-            act.setData(language)
-        
     def __showCompletions(self, completions, text):
         """
         Private method to display the possible completions.

eric ide

mercurial