Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-01

Extending the IDE

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Napoles Martinez

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 *********************************************************************

Reply by email

Mattias Gaertner
to Reinier Napoles Martinez
Show quoted text 5 lines
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

Show quoted text 52 lines
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

Reply by email

Martin
to Reinier Napoles Martinez: I started to study, how to extend the IDE. so far I have managed to add a menu to the IDE.
Reinier Napoles Martinez wrote 13 lines
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;

Not the answer to your question, but...

SynEdit.Lines.Insert
does not work with undo/redo

Lazarus Synedit has
   SynEdit.TextBetweenPoints[ Point(1, Y), Point(1, Y)] := 'Foo'+LineEnding;

Reply by email