When project is closed, some plugins are unloaded. Use flag for loadProjectPart(...
[kdevelopdvcssupport.git] / Architecture.dox
blob8653344d047021cd15d37f3a8b2bfc5c779b0377
1 /** \file  Architecture.dox
2   * \brief KDevelop architecture
3   */
5 /** \page architecture KDevelop 4 Architecture
7 \section source_overview Platform Source Overview
9 \subsection what_is_platform Platform VS Others
11 The idea is that platform code (currently in lib/) contains:
12 - everything to create platform plugins
13 - everything to create platform applications
14 - commonly used/important plugins
17 \subsection platform_code Platform Code Layout
19 Platform consists of
20 - lib/interfaces
21   -  interfaces that expose everything necessary for plugins
22   .
23 - lib/shell
24   -  shell that implements interfaces and basically provides a ready-to-use and extend application
25   .
26 - lib/sublime
27   -  the user interface library
28   .
29 - lib/project and lib/language
30   -  additional libraries for project managers and language supports (usable for other plugins as well)
31   .
32 - lib/config, etc.
33   -  additional libraries usable for both shell and plugins
34   .
37 \subsection platform_for_plugins What to Use in Plugins
39 - plugins need to link to interfaces
40 - plugins shall never link to shell
41 - plugins need not to link to sublime library
42 - plugins can optionally link to other helper libraries in platform when necessary
45 \subsection platform_coding_conventions Current Platform Coding Conventions
47 - preferred coding style is http://www.kdevelop.org/mediawiki/index.php/Coding_Guidelines
48 - all platform classes shall be in KDevelop namespace
49 - all files have to be named without kdev* prefix
50 - all files have to be installed in subdirectories under ${INCLUDE_INSTALL_DIR}/kdevplatform/
51 - all interfaces are named KDevelop::IFoo and their files ifoo.h/cpp
52 - all interface implementations are named KDevelop::Foo and their files foo.h/cpp
56 \section code_overview Platform Code Overview
58 \subsection core ICore/Core
60 As in KDevelop3, the central object that gives access to all shell functionality is Core.
61 There's a KDevelop::ICore interface and KDevelop::Core implementation. KDevelop::ICore interface gives
62 access to all controllers exposed via interfaces. Each plugin is initialized with ICore pointer so it
63 always has access to core via \ref KDevelop::IPlugin::core method. There's no need for something like KDevelop3's
64 KDevAPI class anymore.
66 Core is a singleton that needs to be manually initialized by platform application using
67 \ref KDevelop::Core::initialize right after the KApplication object is created and ShellExtension is initialized.
68 KDevelop::ShellExtension is the same thing as in KDevelop3 - the way to platform application to tell
69 which UI configuration files are used and what is the default profile. KDevelop4 shell extension's
70 only difference is defaultArea() method which shall return the name of default UI area
71 (see below for more information about areas).
73 \subsection plugin IPlugin
75 Just like in KDevelop3, KDevelop::IPlugin is what all plugins need to inherit. But unlike KDevelop3
76 IPlugin is not meant to be subclassed via other interfaces. In KDevelop3 several interfaces
77 were called "extension interfaces" (like KDevMakeFrontend, KDevCreateFile and others) and they
78 subclassed KDevPlugin and provided their own .desktop files with servicetypes.
79 This is not necessary anymore in KDevelop4. We have another extension framework in place (see \ref extensions below).
81 It was necessary to create KDevPluginInfo instance to instantiate any KDevPlugin implementation in KDevelop3.
82 This is also not needed in KDevelop4. It is sufficient to write plugin information to plugin's
83 .desktop file as described in KPluginInfo class documentation.
85 \subsection extensions Extension Interfaces and Plugins
87 The idea behind extension interfaces is to provide following features:
88 - To allow plugins to expose their functionality via abstract interfaces
89   and at the same time do not care about BC and do not force other plugins to link with them.\n
90   Documentation plugin would be a good example of non-core but still sometimes useful functionality
91   that might be exported via IDocumentation extension interface with methods like
92   lookupInDocumentation(const QString &) and others.
93   KDevelop4's outputview plugin with IOutputView interface is also a good and actually working
94   example of such use-case.
96 - To have implementations of important functionality not in a shell, but in plugins.\n
97   Good examples are buildsystem managers, builders and language supports in KDevelop4.
98   When a project is opened, a buildsystem manager plugin (that implements either
99   IBuildSystemManager interface or IProjectFileManager) is looked for by the shell an loaded.
101 - To forget about BC issues of dependent plugins. In case the plugin has something new to expose,
102   the new version of extension interface has to be defined. All other plugins will either
103   continue using old interface or ask for the new one.
106 The extension interfaces framework is implemented with QExtensionManager and Co. See the Qt
107 documentation for reference.
109 \subsubsection declare_extension To declare extension interface:
110 - Create an abstract class
111 - Include <iextension.h>
112 - Add following macros to the header file with a class (if you use namespace):
113     \code
114     KDEV_DECLARE_EXTENSION_INTERFACE_NS( KDevelop, IMyInterface, "org.kdevelop.IMyInterface")
115     Q_DECLARE_INTERFACE( KDevelop::IMyInterface, "org.kdevelop.IMyInterface" )
116     \endcode
117 - Or use (when the interface is not in namespace)
118     \code
119     KDEV_DECLARE_EXTENSION_INTERFACE( IMyInterface, "org.kdevelop.IMyInterface" )
120     Q_DECLARE_INTERFACE( IMyInterface, "org.kdevelop.IMyInterface" )
121     \endcode
124 \subsubsection implement_extension To implement extension interface:
125 - Create a plugin as usual
126 - Subclass it from your interface
127 - Use Q_INTERFACES macro in class declaration
128 - use KDEV_USE_EXTENSION_INTERFACE macro in the constructor of the plugin:
129     \code
130     KDEV_USE_EXTENSION_INTERFACE( IMyInterface )
131     \endcode
132 - declare in plugin's .desktop file:
133     \code
134     X-KDevelop-Interfaces=IMyInterface
135     \endcode
136   Code Example:
137     \code
138     class MyPlugin: public KDevelop::IPlugin, public KDevelop::IMyInterface {
139         Q_OBJECT
140         Q_INTERFACES(KDevelop::IMyInterface)
141     public:
142         MyPlugin(QObject* parent) : IPlugin( parent )
143         {
144             KDEV_USE_EXTENSION_INTERFACE( KDevelop::IMyInterface )
145         }
146     };
147     \endcode
150 \subsubsection load_extension To load a plugin that supports extension interface:
151 - Use \ref KDevelop::IPluginController::pluginForExtension method if you have only one possible
152   plugin implementing the extension interface
153 - Or use \ref KDevelop::IPluginController::allPluginsForExtension method to return a list of plugins.\n
154   Note, that those methods will load plugins if they are not yet loaded
155 - Once IPlugin pointer is returned by one of two methods above, it can be asked for an
156   extension using \ref KDevelop::IPlugin::extension method ( like plugin->extension<IMyInterface>() )
158 \subsubsection interplugin_dependency To set a dependency between plugins:
159 - Set the list of required interfaces in plugin's .desktop file
160     \code
161     X-KDevelop-IRequired=IMyInterface,IMyOtherInterface
162     \endcode
163 It is not possible to set direct inter-plugin dependencies. The plugin shall never depend on another
164 plugin, it shall only depend on something that implements the interface.
167 \subsection project IProject, IProjectController and Project Management Infrastructure
169 Unlike KDevelop3, KDevelop4 can load many projects at the same time.
171 The project management infrastructure can be represented with following diagram:
172 \code
173                                         |--------------------|       |-------------------------------|
174                                   |---->| KDevelop::IProject |------>| KDevelop::IProjectFileManager |
175                                   |     |--------------------|       |-------------------------------|
176                                   |                 |
177 |------------------------------|  |     |------------------------|
178 | KDevelop::IProjectController |------->| KDevelop::ProjectModel |
179 |------------------------------|  |     |------------------------|
180                                   |                 |
181                                   |     |--------------------|       |-------------------------------|
182                                   |---->| KDevelop::IProject |------>| KDevelop::IBuildSystemManager |
183                                         |--------------------|       |-------------------------------|
184 \endcode
185 Project controller is a container for projects (\ref KDevelop::IProject interface). Each project contributes
186 its contents (files, folders, targets, etc.) to the \ref KDevelop::ProjectModel. Each project also have
187 a "project file manager" associated with it.\n
188 Project file manager is the plugin which implements either KDevelop::IProjectFileManager or
189 \ref KDevelop::IBuildSystemManager and provides all actual project management facilities.\n
190 This way KDevelop4 is able to load as many projects as desired and each of the project can
191 have different build system. Every plugin that wants to display whatever is in projects
192 can use \ref KDevelop::ProjectModel.
194 %KDevelop currently supports the notion of "current project" (the one which is currently selected) in the
195 project management view). But plugins are encouraged to not depend on it. The selection might be
196 empty or project management view might be closed at any time.
198 %KDevelop Platform provides by default "GenericProjectManager" which just threats all files and
199 subdirectories under project directory as project items and currently provides no building facilities.
201 The project file (&lt;projectname&gt.kdev4) controls which project file manager will be loaded.
202 For example, this .kdev4 file will load Generic manager:
203 \code
204     [General Options]
205     Manager=KDevGenericManager
206 \endcode
209 \subsection language ILanguage, ILanguageController and Language Support Infrastructure
211 The language support infrastructure is designed to be similar to project management.
212 Its goals are:
213 - use as many language supports as necessary at the same time
214 - be able to load several language supports for one source file
215   good examples are mixed-source files like .php (php+html), .rhtml (ruby + html)
216 - be not dependent on projects
219 The language support infrastructure can be represented with following diagram:
220 \code
221                                                                           |----------------------------|
222                                                                     |---->| KDevelop::ILanguageSupport |
223                                          |---------------------|    |     |----------------------------|
224                                    |---->| KDevelop::ILanguage |----|
225                                    |     |---------------------|    |     |----------------------------|
226                                    |                                |---->| KDevelop::BackgroundParser |
227 |-------------------------------|  |                                      |----------------------------|
228 | KDevelop::ILanguageController |--|
229 |-------------------------------|  |                                      |----------------------------|
230                                    |                                |---->| KDevelop::ILanguageSupport |
231                                    |     |---------------------|    |     |----------------------------|
232                                    |---->| KDevelop::ILanguage |----|
233                                          |---------------------|    |     |----------------------------|
234                                                                     |---->| KDevelop::BackgroundParser |
235                                                                           |----------------------------|
236 \endcode
237 Language controller holds the set of already loaded languages and provides means to load more.
238 For each language (defined by its "name") Language object exists. Each such language has
239 a background parser and a actual support plugin that implements KDevelop::ILanguageSupport.
240 This way the basic shell functionality (like language loading algorithm and background parser)
241 is separated from language-specific stuff (like parsing).
243 Unlike KDevelop3, language support plugin is loaded not among with a project. Instead, when the
244 source file is opened, the language controller asks plugin controller whether there are
245 any language plugins (those that implement KDevelop::ILanguageSupport) that support a mime type
246 of the file (those who set X-KDevelop-SupportedMimeTypes=...).
248 For each language support plugin found, the KDevelop::Language object (that implements KDevelop::ILanguage interface)
249 is created and language support plugin is associated with it. Then each language is asked to return
250 a KDevelop::ParseJob to process the file. This way several language supports are able to parse one file.
252 If KDevelop::Language object for given mimetype already exists, it is used and no plugin loading is performed.
255 \subsection uicontroller IUiController
257 KDevelop::UiController is closely connected to the Sublime UI and basically is an subclass of
258 \ref Sublime::Controller which will be explained later.
260 The main job of UiController is to allow plugins to manager their views and toolviews. Currently only
261 toolviews can be added and removed.
263 Sublime UI wants plugins to add and remove not actual toolviews, but factories to create them.
264 This is because user can request from Sublime UI to show a new toolview at any time. For example,
265 it is possible to have more than one Konsole toolviews. The user just have to ask for them.
266 Automatically factory will be used only once, when UI controller is asked to add a toolview.
267 This means for example that only one Konsole toolview will be opened automatically.
269 To create a factory, a plugin needs to subclass KDevelop::IToolViewFactory and implement two methods:
270 - virtual QWidget* KDevelop::IToolViewFactory::create(QWidget *parent = 0)
271   where the actual toolview widget will be created
272 - virtual Qt::DockWidgetArea KDevelop::IToolViewFactory::defaultPosition(const QString &areaName)
273   which will give the UI a hint on where to place the toolview
276 Once the factory is ready, it has to be added to the UiController using IUiController::addToolView() method.
277 It is not absolutely necessary for a plugin to remove or delete toolview factory. UiController will
278 delete them all upon unload.
280 NOTE: temporarily IUiController has KDevelop::IUiController::openUrl() method which is the only
281 way to open files in KDevelop until DocumentController is ported.
285 \section sublime Sublime UI
287 \subsection sublime_operation Modus Operandi
289 - UI provides support for "areas" (alike Eclipse's perspectives)
290 - The basic set of areas is:
291   - code editing area with splitted editor windows \n
292     (with kate/konqueror-like splitting)
293   - debugging area \n
294     (Xcode-like debugger window with only one editor view by default but with possiblility to show more)
295   - profiling area \n
296     (like KCacheGrind)
297   - user interface design area \n
298     (like Qt designer)
299 - Area configuration includes code editor windows (unlike eclipse)
300 - Each area can be displayed in usual Qt mainwindow with toolviews in dockwidgets
301 - Areas are shown in separate mainwindows so that multiple-monitor setups become the best supported
302 - One area can be shown in two and more mainwindows by "cloning" the area \n
303   (unlike Eclipse that pretends that two mainwindows show the same area)
304 - Optionally areas can be switched inside the same mainwindow without opening new ones
305   (like in Eclipse), but this mode of operation is currently not implemented. \n
306   Also Sublime was not optimized for this use-case. See wiki pages for a detailed discussion and
307   explanation of possible problems.
308 - It is possible to open as many similar toolviews as necessary (for example, several konsole's)
309 - It is possible to open several views for the same file in code editor view (unlike KDevelop 3.x)
310 - Instead of tabs for editor windows a "switcher" is provided. \n
311   Currently the switcher is a combobox but that will change for sure.
314 \subsection sublime_architecture Brief Architecture Overview
316 Sublime::Controller is the central point of the whole Sublime infrastructure. It contains areas,
317 documents and controlls mainwindows. \n
318 Sublime::Controller::showArea() is the only way to show an area in the mainwindow.
320 Sublime::MainWindow is just a KParts::MainWindow which just knows how to "reconstruct" the area,
321 react on area changes. Additionally it knows which view and toolview is "active" (i.e. last focused).
323 Sublime::Area is the object that controls views, toolviews and defines their placement
324 inside the mainwindow. Provides varous view management (e.g. add/remove/etc.) methods and signals.
325 Also Area is responsible to store/restore view layout (on-disk storage is not implemented currently).
327 Area is identified by its name. Each KDevelop platform application, for example, has to define
328 a concept of "default area" in ShellExtension so that UiController can load it by default.
330 While areas operate on views, the Sublime Controller deals with \ref Sublime::Document 's only.
331 Sublime::View is only a thin wrapper around actual QWidget.
333 Document is what provides views. Sublime::Document::createView() is the only way to get a view.
334 When createView() is called, the protected Sublime::Document::createViewWidget() is called to
335 return the actual widget for a view.
337 There is an abstract Sublime::Document class with no createViewWidget() implementation and
338 there's a convenience class Sublime::ToolDocument that can create widgets of user-specified type.
340 KDevelop currently uses Sublime::PartDocument which is subclassed by KDevelop::PartDocument.
341 This PartDocument creates a view by loading a part and then asking a part about its widget.