From 2f710fb9b611b915187ea433fabe7927c30cef17 Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 7 Jun 2009 12:03:16 +0000 Subject: [PATCH] SynEdit, Beautifier: added Replace current indent git-svn-id: trunk@20495 - --- components/synedit/synbeautifier.pas | 56 +++++++++++++++++----------- ide/sourceeditor.pp | 12 +++--- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/components/synedit/synbeautifier.pas b/components/synedit/synbeautifier.pas index adb2a92697..99c510c43f 100644 --- a/components/synedit/synbeautifier.pas +++ b/components/synedit/synbeautifier.pas @@ -45,7 +45,8 @@ uses type TSynBeautifierGetIndentEvent = - procedure(Sender: TObject; LogCaret: TPoint; Line: Integer; var Indent, BasedLine: Integer) of object; + procedure(Sender: TObject; LogCaret: TPoint; Line: Integer; + var Indent, BasedLine: Integer; var ReplaceIndent: Boolean) of object; { TSynCustomBeautifier } @@ -61,11 +62,13 @@ type function IndentLine(const Editor: TSynEditBase; const Lines: TSynEditStrings; const ACaret: TSynEditCaret; out CaretNewX: Integer): Boolean; virtual; abstract; // Todo DelChar are not supprted for undo - function GetDesiredIndentForLine(Editor: TSynEditBase; const Lines: TSynEditStrings; - const ACaret: TSynEditCaret): Integer; virtual; abstract; - function GetDesiredIndentForLine(Editor: TSynEditBase; const Lines: TSynEditStrings; - const ACaret: TSynEditCaret; - out DesiredIndent: String): Integer; virtual; abstract; + function GetDesiredIndentForLine + (Editor: TSynEditBase; const Lines: TSynEditStrings; + const ACaret: TSynEditCaret): Integer; virtual; abstract; + function GetDesiredIndentForLine + (Editor: TSynEditBase; const Lines: TSynEditStrings; + const ACaret: TSynEditCaret; out ReplaceIndent: Boolean; + out DesiredIndent: String): Integer; virtual; abstract; property OnGetDesiredIndent: TSynBeautifierGetIndentEvent read FOnGetDesiredIndent write FOnGetDesiredIndent; end; @@ -82,16 +85,19 @@ type Physical: boolean): Integer; function CanUnindent(const Editor: TSynEditBase; const Lines: TSynEditStrings; const ACaret: TSynEditCaret): Boolean; override; - function UnIndentLine(const Editor: TSynEditBase; const Lines: TSynEditStrings; - const ACaret: TSynEditCaret; out CaretNewX: Integer - ): Boolean; override; // Todo InsChar are not supprted for undo - function IndentLine(const Editor: TSynEditBase; const Lines: TSynEditStrings; - const ACaret: TSynEditCaret; out CaretNewX: Integer): Boolean; override; // Todo DelChar are not supprted for undo - function GetDesiredIndentForLine(Editor: TSynEditBase; const Lines: TSynEditStrings; - const ACaret: TSynEditCaret): Integer; override; - function GetDesiredIndentForLine(Editor: TSynEditBase; const Lines: TSynEditStrings; - const ACaret: TSynEditCaret; - out DesiredIndent: String): Integer; override; + function UnIndentLine + (const Editor: TSynEditBase; const Lines: TSynEditStrings; + const ACaret: TSynEditCaret; out CaretNewX: Integer): Boolean; override; + function IndentLine + (const Editor: TSynEditBase; const Lines: TSynEditStrings; + const ACaret: TSynEditCaret; out CaretNewX: Integer): Boolean; override; + function GetDesiredIndentForLine + (Editor: TSynEditBase; const Lines: TSynEditStrings; + const ACaret: TSynEditCaret): Integer; override; + function GetDesiredIndentForLine + (Editor: TSynEditBase; const Lines: TSynEditStrings; + const ACaret: TSynEditCaret; out ReplaceIndent: Boolean; + out DesiredIndent: String): Integer; override; published property IndentType: TSynBeautifierIndentType read FIndentType write FIndentType; end; @@ -161,11 +167,16 @@ function TSynBeautifier.IndentLine(const Editor: TSynEditBase; var IndentPos: Integer; InsChars: String; + ReplaceIndent: Boolean; begin - IndentPos := GetDesiredIndentForLine(Editor, Lines, ACaret, InsChars); + IndentPos := GetDesiredIndentForLine(Editor, Lines, ACaret, ReplaceIndent, InsChars); if IndentPos < 0 then exit(False); + if ReplaceIndent then + Lines.EditDelete(1, ACaret.LinePos, + GetCurrentIndent(Editor, ACaret.LineText, False)); + if (FIndentType = sbitPositionCaret) and (ACaret.LineText = '') then InsChars := ''; @@ -175,8 +186,8 @@ begin end; function TSynBeautifier.GetDesiredIndentForLine(Editor: TSynEditBase; - const Lines: TSynEditStrings; const ACaret: TSynEditCaret; out - DesiredIndent: String): Integer; + const Lines: TSynEditStrings; const ACaret: TSynEditCaret; + out ReplaceIndent: Boolean; out DesiredIndent: String): Integer; var BackCounter, PhysLen: Integer; Temp: string; @@ -192,8 +203,10 @@ begin until (BackCounter = 0) or (Temp <> ''); FoundLine := BackCounter + 1; + ReplaceIndent := False; if assigned(FOnGetDesiredIndent) then - FOnGetDesiredIndent(Editor, ACaret.LineBytePos, ACaret.LinePos, Result, FoundLine); + FOnGetDesiredIndent(Editor, ACaret.LineBytePos, ACaret.LinePos, Result, + FoundLine, ReplaceIndent); if Result < 0 then exit; @@ -221,8 +234,9 @@ function TSynBeautifier.GetDesiredIndentForLine(Editor: TSynEditBase; const Lines: TSynEditStrings; const ACaret: TSynEditCaret): Integer; var Dummy: String; + Replace: Boolean; begin - Result := GetDesiredIndentForLine(Editor, Lines, ACaret, Dummy); + Result := GetDesiredIndentForLine(Editor, Lines, ACaret, Replace, Dummy); end; end. diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index b1b9d50959..4c04c90fe5 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -161,7 +161,7 @@ type WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure EditorGetIndent(Sender: TObject; LogCaret: TPoint; Line: Integer; - var Indent, BasedLine: Integer); + var Indent, BasedLine: Integer; var ReplaceIndent: Boolean); procedure EditorStatusChanged(Sender: TObject; Changes: TSynStatusChanges); procedure SetCodeBuffer(NewCodeBuffer: TCodeBuffer); function GetSource: TStrings; @@ -603,7 +603,7 @@ type procedure EditorMouseLink( Sender: TObject; X,Y: Integer; var AllowMouseLink: Boolean); procedure EditorGetIndent(Sender: TObject; LogCaret: TPoint; Line: Integer; - var Indent, BasedLine: Integer); + var Indent, BasedLine: Integer; var ReplaceIndent: Boolean); procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure EditorMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); @@ -3005,10 +3005,10 @@ begin end; procedure TSourceEditor.EditorGetIndent(Sender: TObject; LogCaret: TPoint; - Line: Integer; var Indent, BasedLine: Integer); + Line: Integer; var Indent, BasedLine: Integer; var ReplaceIndent: Boolean); begin if Assigned(OnGetDesiredIndent) then - OnGetDesiredIndent(Sender, LogCaret, Line, Indent, BasedLine); + OnGetDesiredIndent(Sender, LogCaret, Line, Indent, BasedLine, ReplaceIndent); end; Function TSourceEditor.GetCaretPosFromCursorPos(const CursorPos: TPoint): TPoint; @@ -6693,10 +6693,10 @@ begin end; procedure TSourceNotebook.EditorGetIndent(Sender: TObject; LogCaret: TPoint; Line: Integer; - var Indent, BasedLine: Integer); + var Indent, BasedLine: Integer; var ReplaceIndent: Boolean); begin if Assigned(OnGetDesiredIndent) then - OnGetDesiredIndent(Sender, LogCaret, Line, Indent, BasedLine); + OnGetDesiredIndent(Sender, LogCaret, Line, Indent, BasedLine, ReplaceIndent); end; Procedure TSourceNotebook.HintTimer(sender: TObject);