[Lazarus] Extending the IDE

Reinier Napoles Martinez rnapoles at hlg.uci.cu
Sun Jan 29 07:49:17 CET 2012


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.


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;


end.


-- 
*********************************************************************
En la tierra hace falta personas que trabajen más y critiquen menos,
que construyan más y destruyan menos, que prometan menos y
resuelvan más que esperen recibir menos y dar más que digan mejor
ahora que mañana.
                                                 Che
*********************************************************************




More information about the Lazarus mailing list