Difference between revisions of "Extending the IDE/de"

From Free Pascal wiki
Jump to navigationJump to search
m
Line 37: Line 37:
 
     {$I mybutton.lrs}
 
     {$I mybutton.lrs}
  
Install the package.
+
Installieren sie das Package.
  
 
== Komponenten-Editoren schreiben ==
 
== Komponenten-Editoren schreiben ==
Line 147: Line 147:
 
</Delphi>
 
</Delphi>
  
== The .lpr, .lpi and .lps file of a project ==
+
== Die .lpr, .lpi und .lps Datei eines Projekts ==
  
 
<Delphi>
 
<Delphi>
Line 155: Line 155:
 
begin
 
begin
 
   LazProject:=LazarusIDE.ActiveProject;
 
   LazProject:=LazarusIDE.ActiveProject;
   // every project has a .lpi file:
+
   // jedes Projekt hat eine .lpi Datei:
 
   DebugLn(['Project'' lpi file: ',LazProject.ProjectInfoFile]);
 
   DebugLn(['Project'' lpi file: ',LazProject.ProjectInfoFile]);
  
Line 171: Line 171:
 
== Adding a resource directive to a file ==
 
== Adding a resource directive to a file ==
  
This adds a {$R example.res} to a pascal unit:
+
Dies fügt eine {$R example.res} Direktive zu einer Pascal Unit hinzu:
  
 
<Delphi>
 
<Delphi>
Line 185: Line 185:
 
   LazarusIDE.SaveSourceEditorChangesToCodeCache(-1);
 
   LazarusIDE.SaveSourceEditorChangesToCodeCache(-1);
  
   // load the file
+
   // die Datei laden
 
   CodeBuf:=CodeToolBoss.LoadFile(ExpandedFilename,true,false);
 
   CodeBuf:=CodeToolBoss.LoadFile(ExpandedFilename,true,false);
  
   // add the resource directive
+
   // die resource Direktive hinzufügen
 
   if not CodeToolBoss.AddResourceDirective(CodeBuf,'example.res') then
 
   if not CodeToolBoss.AddResourceDirective(CodeBuf,'example.res') then
 
     LazarusIDE.DoJumpToCodeToolBossError;
 
     LazarusIDE.DoJumpToCodeToolBossError;

Revision as of 18:14, 25 May 2008

Deutsch (de) English (en) español (es) français (fr) 日本語 (ja) русский (ru) slovenčina (sk) 中文(中国大陆)‎ (zh_CN)

Erweitern der IDE

Einleitung

Die IDE unterstützt verschiedene Erweiterungen:

Komponenten
Komponenten werden in der Palette installiert. Z.B. TButton erzeugt Buttons.
Komponenten-Editoren
Komponenteneditoren werden benutzt wenn sie auf eine Komponente im Designer doppelklicken oder um einige extra Items im Popupmenü des Designers hinzuzufügen, wenn man rechts auf eine Komponente klickt.
Eigenschafts-Editoren
Stellen die Editierfähigkeiten im Objektinspektor zur Verfügung.
Experten
Alle anderen Typen von Editoren.


Es gibt 2 Möglichkeiten, Plugins in Lazarus zu integrieren:

  1. Erstellen sie ein Package, installieren sie es und registrieren sie das Plugin mit der Prozedur 'Register' in einer Unit.
  2. Erweitere den Lazarus Code und sende Dein diff an die Lazarus Mailing Liste.


Komponenten schreiben

You can create new components via the package editor. For example: Create or open a package, click on add, click on New Component, fill in the items: Ancestor Type = TButton, New class name = TMyButton, palette page = Misc, Unit file name = mybutton.pas (this file will be created), unit name MyButton and click ok.

Einer neuen Komponente ein Icon für die Komponentenpalette verpassen

For example give TMyButton an icon. Create an image file of the format .bmp, .xpm or .png with the same name as the component class. For example tmybutton.png and save it in the package source directory. The image can be created by any graphic program (e.g. gimp) and should be no bigger than 24x24 pixel. Then convert the image to a .lrs file with the lazres tool, which can be found in the lazarus/tools directory:

 ~/lazarus/tools/lazres mybutton.lrs mybutton.png

This creates an pascal include file, which is used in the initialization section of mybutton.pas:

 initialization
   {$I mybutton.lrs}

Installieren sie das Package.

Komponenten-Editoren schreiben

ToDo Hinweis: siehe componenteditors.pas für Beispiele

Eigenschafts-Editoren schreiben

ToDo Hinweis: siehe propedits.pp für Beispiele

Register event handlers

There are several events in the IDE, for which plugins can add their own handlers.

Designerereignisse

In propedits.pp there is a "GlobalDesignHook" object, which maintains several events for designing. Each event calls a list of handlers. The default handlers are added by the IDE. You can add your own handlers with the AddHandlerXXX and RemoveHandlerXXX methods. They will be called before the default handlers.

Examples:

 Adding your handler (this is normally done in the constructor of your object):
   GlobalDesignHook.AddHandlerComponentAdded(@YourOnComponentAdded);
Removing your handler: GlobalDesignHook.RemoveHandlerComponentAdded(@YourOnComponentAdded);
You can remove all handlers at once. For example, it is a good idea to add this line in the destructor of object: GlobalDesignHook.RemoveAllHandlersForObject(Self);

The handlers of GlobalDesignHook:

 // lookup root
 ChangeLookupRoot
   Called when the "LookupRoot" changed.
   The "LookupRoot" is the owner object of the currently selected components.
   Normally this is a TForm.
// methods CreateMethod GetMethodName GetMethods MethodExists RenameMethod ShowMethod Called MethodFromAncestor ChainCall
// components GetComponent GetComponentName GetComponentNames GetRootClassName ComponentRenamed Called when a component was renamed ComponentAdded Called when a new component was added to the LookupRoot ComponentDeleting Called before a component is freed. DeleteComponent Called by the IDE to delete a component. GetSelectedComponents Get the current selection of components.
// persistent objects GetObject GetObjectName GetObjectNames
// modifing Modified Revert RefreshPropertyValues

Projektereignisse

Diese Ereignisse sind definiert in der Unit LazIDEIntf.

 LazarusIDE.AddHandlerOnProjectClose
 LazarusIDE.AddHandlerOnProjectOpened
 LazarusIDE.AddHandlerOnSavedAll
 LazarusIDE.AddHandlerOnSavingAll

Aktuelles Projekt

The current main project can be obtained by LazarusIDE.ActiveProject. (unit LazIDEIntf)

Alle Units des aktuellen Projekts

To iterate through all pascal units of the current main project of the IDE you can use for example:

<Delphi> uses LCLProc, FileUtil, LazIDEIntf, ProjectIntf;

procedure ListProjectUnits; var

 LazProject: TLazProject;
 i: Integer;
 LazFile: TLazProjectFile;

begin

 LazProject:=LazarusIDE.ActiveProject;
 if LazProject<>nil then
   for i:=0 to LazProject.FileCount-1 do
   begin
     LazFile:=LazProject.Files[i];
     if LazFile.IsPartOfProject
     and FilenameIsPascalUnit(LazFile.Filename)
     then
       debugln(LazFile.Filename);
   end;

end; </Delphi>

Die .lpr, .lpi und .lps Datei eines Projekts

<Delphi> uses LCLProc, FileUtil, ProjectIntf, LazIDEIntf; var

 LazProject: TLazProject;

begin

 LazProject:=LazarusIDE.ActiveProject;
 // jedes Projekt hat eine .lpi Datei:
 DebugLn(['Project lpi file: ',LazProject.ProjectInfoFile]);
 // if the project session information is stored in a separate .lps file:
 if LazProject.SessionStorage<>pssNone then
   DebugLn(['Project lps file: ',LazProject.ProjectSessionFile]);
 // If the project has a .lpr file it is the main source file:
 if (LazProject.MainFile<>nil)
 and (CompareFileExt(LazProject.MainFile.Filename,'lpr')=0) then
   DebugLn(['Project has lpr file: ',LazProject.MainFile.Filename]);

end; </Delphi>

Adding a resource directive to a file

Dies fügt eine {$R example.res} Direktive zu einer Pascal Unit hinzu:

<Delphi> procedure AddResourceDirectiveToPascalSource(const Filename: string); var

 ExpandedFilename: String;
 CodeBuf: TCodeBuffer;

begin

 // make sure the filename is trimmed and contains a full path
 ExpandedFilename:=CleanAndExpandFilename(Filename);
 
 // save changes in source editor to codetools
 LazarusIDE.SaveSourceEditorChangesToCodeCache(-1);
 // die Datei laden
 CodeBuf:=CodeToolBoss.LoadFile(ExpandedFilename,true,false);
 // die resource Direktive hinzufügen
 if not CodeToolBoss.AddResourceDirective(CodeBuf,'example.res') then
   LazarusIDE.DoJumpToCodeToolBossError;

end; </Delphi>

The codetools provides also functions like FindResourceDirective and RemoveDirective.


 Adding your handler (this is normally done in the constructor of your object):
   GlobalDesignHook.AddHandlerComponentAdded(@YourOnComponentAdded);
Removing your handler: GlobalDesignHook.RemoveHandlerComponentAdded(@YourOnComponentAdded);
You can remove all handlers at once. For example, it is a good idea to add this line in the destructor of object: GlobalDesignHook.RemoveAllHandlersForObject(Self);

Die Handlers des GlobalDesignHook:

 // lookup root
 ChangeLookupRoot
   Called when the "LookupRoot" changed.
   The "LookupRoot" is the owner object of the currently selected components.
   Normally this is a TForm.
// Methoden CreateMethod GetMethodName GetMethods MethodExists RenameMethod ShowMethod Called MethodFromAncestor ChainCall
// Komponenten GetComponent GetComponentName GetComponentNames GetRootClassName ComponentRenamed Called when a component was renamed ComponentAdded Called when a new component was added to the LookupRoot ComponentDeleting Called before a component is freed. DeleteComponent Called by the IDE to delete a component. GetSelectedComponents Get the current selection of components.
// persistente Objekte GetObject GetObjectName GetObjectNames
// modifing Modified Revert RefreshPropertyValues

Hilfe für die Quellen hinzufügen

Erzeugen sie zuerst eine THelpDatabase: <delphi>

 HelpDB:=TFPDocHTMLHelpDatabase(
    HelpDatabases.CreateHelpDatabase('EinNameIhrerWahlFürDieDatenbank',
                                            TFPDocHTMLHelpDatabase,true));
 HelpDB.DefaultBaseURL:='http://ihre.hilfe.org/';
 FPDocNode:=THelpNode.CreateURL(HelpDB,
                  'Package1 - A new package',
                  'file://index.html');
 HelpDB.TOCNode:=THelpNode.Create(HelpDB,FPDocNode);// einmal als Inhaltsverzeichnis
 DirectoryItem:=THelpDBISourceDirectory.Create(FPDocNode,'$(PkgDir)/lcl',
                                 '*.pp;*.pas',false);// und einmal als normale Seite
 HelpDB.RegisterItem(DirectoryItem);

</delphi>

Originale Mitwirkende und Änderungen

Diese Seite wurde von der epikwiki Version konvertiert.

This document was authored by Mattias Gaertner Initial import and formatted for Lazarus-CCR - VlxAdmin 9/26/2003