[Lazarus] Extending the IDE

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Jan 29 11:43:46 CET 2012


On Sun, 29 Jan 2012 01:49:17 -0500 (CST)
Reinier  Napoles Martinez <rnapoles at hlg.uci.cu> wrote:

> Hello list,
> 
> I started to study, how to extend the IDE.
> so far I have managed to add a menu to the IDE.
> How I can override the default behavior of the editor when I press Ctrl + D to run my code.

The defaults are fixed and the user settings are loaded before the
packages are registered. There is currently no way to alter them.

I added a function to search for all commands with some keys.

http://wiki.lazarus.freepascal.org/Extending_the_IDE#Shortcuts


> 
> 
> thanks.
> 
> This is my code.
> 
> unit DuplicateLine; 
> 
> {$mode objfpc}{$H+}
> 
> interface
> 
> 
> uses
>   Classes,Controls,SysUtils,IDECommands,MenuIntf,LCLType,SrcEditorIntf,SynEdit;
> 
> 
> procedure DuplicateLine(Sender: TObject);
> procedure Register;
> 
> implementation
> 
> 
> procedure DuplicateLine(Sender: TObject);
> var
>   Editor: TSourceEditorInterface;
>   ASynEdit: TSynEdit;
> begin
> 
>      Editor:=SourceEditorManagerIntf.ActiveEditor;
>      if Editor=nil then exit;
>      if Editor.EditorControl is TSynEdit then begin
>          ASynEdit:=TSynEdit(Editor.EditorControl);
>          ASynEdit.Lines.Insert(ASynEdit.CaretY, ASynEdit.LineText);
>      end;
> 
> 
> end;
> 
> 
> procedure Register;
> var
>   Key: TIDEShortCut;
>   Cat: TIDECommandCategory;
>   DuplicateCmd: TIDECommand;
> begin
>      Key := IDEShortCut(VK_D,[ssCtrl],VK_UNKNOWN,[]);
>      Cat:=IDECommandList.FindCategoryByName(CommandCategoryToolMenuName);
>      DuplicateCmd := RegisterIDECommand(Cat,'Duplicate Line', 'Duplicate a Line', Key, nil, @DuplicateLine);
>      RegisterIDEMenuCommand(itmEditBlockIndentation, 'DuplicateLine', 'Duplicate a Line', nil, nil, DuplicateCmd);
> 
> end;

:)

Mattias




More information about the Lazarus mailing list