unit fExtendIde;
{$mode objfpc}{$H+}
interface
uses
Classes, Controls, Dialogs, IDECommands, IDEMsgIntf, LCLProc, LCLType, MenuIntf,
SrcEditorIntf, SynEdit, SysUtils, Menus;
type
TIDEExtensions = class
private
public
procedure ExchangeLineUp(Sender: TObject);
procedure ExchangeLineDown(Sender: TObject);
procedure DuplicateLine(Sender: TObject);
end;
procedure Register;
implementation
{ TIDEExtensions }
procedure TIDEExtensions.ExchangeLineUp(Sender: TObject);
var
Editor: TSourceEditorInterface;
ASynEdit: TSynEdit;
tempStr: 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 TIDEExtensions.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 TIDEExtensions.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.TextBetweenPoints[Point(1, ASynEdit.CaretY), Point(1, ASynEdit.CaretY)] := ASynEdit.LineText + LineEnding;
end;
end;
procedure Register;
var
Key: TIDEShortCut;
Cat: TIDECommandCategory;
SectionLines: TIDEMenuSection;
SectionLinesMenu: TIDEMenuSection;
DuplicateCmd: TIDECommand;
ExchangeLineUpCmd: TIDECommand;
ExchangeLineDownCmd: TIDECommand;
{%H-}IDEExtensions: TIDEExtensions;
begin
IDEExtensions := TIDEExtensions.Create;
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, @IDEExtensions.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, @IDEExtensions.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, @IDEExtensions.DuplicateLine);
RegisterIDEMenuCommand(SectionLinesMenu, 'DuplicateLine', 'Duplicate a Line', nil, nil, DuplicateCmd);
end;
end.