diff -r eb218f60e411 -r 362689624e2d PluginExtensionProtobuf.py --- a/PluginExtensionProtobuf.py Sun Dec 11 11:52:17 2022 +0100 +++ b/PluginExtensionProtobuf.py Mon Dec 12 16:55:43 2022 +0100 @@ -14,6 +14,7 @@ from eric7 import Globals, Preferences from eric7.EricWidgets import EricMessageBox from eric7.EricWidgets.EricApplication import ericApp +from ExtensionProtobuf import protoclbr from ExtensionProtobuf.ProjectProtocolsBrowser import ProjectProtocolsBrowser # Start-Of-Header @@ -21,7 +22,7 @@ author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True -version = "10.0.2" +version = "10.1.0" className = "ProtobufExtensionPlugin" packageName = "ExtensionProtobuf" shortDescription = "Support for the development of Protobuf and gRPC projects" @@ -210,6 +211,9 @@ @return tuple of None and activation status @rtype bool """ + from eric7.QScintilla import Lexers + from eric7.Utilities import ClassBrowsers + global error, protobufExtensionPluginObject error = "" # clear previous error @@ -218,6 +222,25 @@ self.__browser = ProjectProtocolsBrowser(self) + Lexers.registerLexer( + "Protocol Buffer", + self.tr("Protocol Buffer (protobuf)"), + "dummy.proto", + self.getLexer, + [self.tr("Protocol Buffer Files (*.proto)")], + [self.tr("Protocol Buffer Files (*.proto)")], + ["*.proto"], + os.path.join("ExtensionProtobuf", "icons", "protobuf"), + ) + + ClassBrowsers.registerClassBrowser( + "Protocol Buffer", + protoclbr.readmodule_ex, + protoclbr.scan, + self.getFileIcon, + [".proto"], + ) + return None, True else: EricMessageBox.warning( @@ -239,6 +262,12 @@ """ Public method to deactivate this plug-in. """ + from eric7.QScintilla import Lexers + from eric7.Utilities import ClassBrowsers + + Lexers.unregisterLexer("Protocol Buffer") + ClassBrowsers.registerClassBrowser("Protocol Buffer") + self.__browser.deactivate() self.__initialize() @@ -290,6 +319,34 @@ """ Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value) + def getLexer(self, parent=None): + """ + Public method to instantiate a Pygments Protocol Buffer lexer object. + + @param parent reference to the parent object + @type QObject + @return reference to the instanciated lexer object + @rtype QsciLexer + """ + from eric7.QScintilla.Lexers.LexerPygments import LexerPygments + + lexer = LexerPygments(parent, name="Protocol Buffer") + if lexer.canStyle(): + return lexer + else: + return None + + def getFileIcon(self, filename=""): + """ + Public method to get the name of a file icon. + + @param filename file name (defaults to "") + @type str (optional) + @return name of a file icon + @rtype str + """ + return os.path.join("ExtensionProtobuf", "icons", "protobuf") + def installDependencies(pipInstall): """