[Lazarus] Extending the IDE

Reinier Napoles Martinez rnapoles at hlg.uci.cu
Fri Feb 3 00:05:38 CET 2012


thanks martin and  mattias. My small expert is this way.


unit Unit1; 

{$mode objfpc}{$H+}

interface


uses
  Classes,Controls, SysUtils,IDECommands,MenuIntf,Dialogs,LCLType,SrcEditorIntf,SynEdit,LCLProc,IDEMsgIntf;

procedure ExchangeLineUp(Sender: TObject);
procedure ExchangeLineDown(Sender: TObject);

procedure DuplicateLine(Sender: TObject);
procedure Register;

implementation

procedure ExchangeLineUp(Sender: TObject);
var
Editor: TSourceEditorInterface;
ASynEdit: TSynEdit;
tempStr:String;
tempStr1:String;
y: LongInt;
begin

     Editor:=SourceEditorManagerIntf.ActiveEditor;
     if Editor=nil then exit;
     if Editor.EditorControl is TSynEdit then begin
         ASynEdit:=TSynEdit(Editor.EditorControl);
         if ASynEdit.CaretY - 1 >= 1 then
         begin
           y := ASynEdit.CaretY;
           tempStr := ASynEdit.LineText;
           ASynEdit.TextBetweenPoints[Point(1, y), Point(1, y + 1)]:= ASynEdit.Lines.Strings[y - 2] +LineEnding;
           ASynEdit.TextBetweenPoints[Point(1, y-1), Point(1, y)]:=tempStr+LineEnding;
           ASynEdit.CaretY := y - 1;
         end;
     end;
end;

procedure ExchangeLineDown(Sender: TObject);
var
Editor: TSourceEditorInterface;
ASynEdit: TSynEdit;
y: LongInt;
tempStr: String;
begin
     Editor:=SourceEditorManagerIntf.ActiveEditor;
     if Editor=nil then exit;
     if Editor.EditorControl is TSynEdit then begin
        ASynEdit:=TSynEdit(Editor.EditorControl);
        if (ASynEdit.CaretY + 1 <= ASynEdit.Lines.Count) then
        begin
           y:= ASynEdit.CaretY;
           tempStr := ASynEdit.LineText;
           ASynEdit.TextBetweenPoints[Point(1, y), Point(1, y+1)]:= ASynEdit.Lines.Strings[y] +LineEnding;
           ASynEdit.TextBetweenPoints[Point(1, y+1), Point(1, y+2)]:=tempStr+LineEnding;
           ASynEdit.CaretY := y + 1;
        end;
     end;
end;

procedure DuplicateLine(Sender: TObject);
var
  Editor: TSourceEditorInterface;
  TextPos: TPoint;
  ScreenPos: TPoint;
  Filename: String;
  ASynEdit: TSynEdit;
begin
     Editor:=SourceEditorManagerIntf.ActiveEditor;
     if Editor=nil then exit;
     if Editor.EditorControl is TSynEdit then begin
         ASynEdit:=TSynEdit(Editor.EditorControl);
         ASynEdit.TextBetweenPoints[ Point(1, ASynEdit.CaretY), Point(1, ASynEdit.CaretY)] := ASynEdit.LineText+LineEnding;
     end;

     Filename:=Editor.FileName;
     ScreenPos:=Editor.CursorScreenXY;
     TextPos:=Editor.CursorTextXY;

end;


procedure Register;
var
  Key: TIDEShortCut;
  Cat: TIDECommandCategory;
  SectionLines:TIDEMenuSection;
  SectionLinesMenu:TIDEMenuSection;
  DuplicateCmd: TIDECommand;
  ExchangeLineUpCmd: TIDECommand;
  ExchangeLineDownCmd: TIDECommand;
begin
     SectionLines:=RegisterIDEMenuSection(mnuEdit,'Lines');
     SectionLinesMenu:= RegisterIDESubMenu(SectionLines,'Lines','Lines');

     Key := IDEShortCut(VK_UP,[ssCtrl,ssShift],VK_UNKNOWN,[]);
     Cat:=IDECommandList.FindCategoryByName(CommandCategoryToolMenuName);
     ExchangeLineUpCmd := RegisterIDECommand(Cat,'ExchangeLineUpCmd', 'Move up', Key, nil, @ExchangeLineUp);
     RegisterIDEMenuCommand(SectionLinesMenu, 'ExchangeLineUpCmd', 'Move line up', nil, nil, ExchangeLineUpCmd);

     Key := IDEShortCut(VK_DOWN,[ssCtrl,ssShift],VK_UNKNOWN,[]);
     ExchangeLineDownCmd := RegisterIDECommand(Cat,'ExchangeLineDownCmd', 'Move down', Key, nil, @ExchangeLineDown);
     RegisterIDEMenuCommand(SectionLinesMenu, 'ExchangeLineDownCmd', 'Move line down', nil, nil, ExchangeLineDownCmd);


     Key := IDEShortCut(VK_Q,[ssCtrl],VK_UNKNOWN,[]);
     DuplicateCmd := RegisterIDECommand(Cat,'Duplicate Line', 'Duplicate a Line', Key, nil, @DuplicateLine);
     RegisterIDEMenuCommand(SectionLinesMenu, 'DuplicateLine', 'Duplicate a Line', nil, nil, DuplicateCmd);
end;


end.


sorry for my english.


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