-
Notifications
You must be signed in to change notification settings - Fork 10
Code Editor Refactor
This is caused by the earily design. There're something we don't understand so those two module have some trouble on work devision. This project is aimed to clear their relationship.
All the panels have been moved from KCCodeEditor to KCTextEditor. This can not only reduce the CPU usage, but also make the geometry of the text to the right place, and totally fixed the rect is not exactly at the same line of text bug.
A new class called KCPanelManager will manage all the panels, and refresh them when it need. All the panel should be init when KCTextEditor is loaded. Panels can get text block, user data when every paintEvent.
Here is the latest designed framework:
KCCodeEditor
|-KCTextEditor
|-KCLanguageMode
|-KCHighlighter
|-KCCompiler
KCTextEditor is the basic editor. All the functions which related to code edit should be a function of KCTextEditor. KCLanguageMode is the language controller, all the function which related to a specific language should be here. In the KCLanguageMode class, there should have the following elements: KCHighlighter and KCCompiler.
KCHighlighter now is not only a class which manage the highlight rules of a specific language, but also a class who manage the keyPressEvent and syntax analysis.
KCCompiler, as its name, manage the specific language compiler.
KCTextEditor is the base class of the whole code editor. This class is a non-language-related class. It contains all the functions relate to text editing. Currently, it should contain the following functions:
Load a plain text file
This function should be here, but not in the Code Editor module. The parameters should contain two elements: the file path and the specific text codec. The text codec will be UTF-8 as default.
Save the current document to a file
This function should be here, but not in the Code Editor module. The parameters should contain two elements: the proper file path and the specific text codec. Like the file loading module, the codec will be UTF-8 as default.
KCLanguageMode now contains all the functions relate to a specific programming language. In a KCLanguage module, it should contain the highlighter module, the compiler module. These entire modules will be linked by KCCodeEditor.
In the KCHighLighter, we should know that this class is called at the time the block changed or a new block create. This is related to the keyboard event. So now, KCHighlighter is not only a class which managed the highlight, but the class contains the highlight, key pressed event and grammar analysis.
In this framework, KCCodeEditor is no more likely a editor, it much more like a plugins manager. It should connect all the signals and slots between the KCTextEditor and KCLanguageMode. It should also connect the signals and slots which declare in KCCodeEditor itself to those two modules.