SynEdit: Starting on Ifdef Markup

git-svn-id: trunk@41103 -
This commit is contained in:
martin 2013-05-09 22:27:23 +00:00
parent c12c9eb25b
commit 24f0786690
3 changed files with 122 additions and 61 deletions

View File

@ -330,6 +330,7 @@ type
FFoldView: TSynEditFoldedView;
FHighlighter: TSynPasSyn;
FIfDefTree: TSynMarkupHighIfDefLinesTree;
FOnNodeStateRequest: TSynMarkupIfdefStateRequest;
FOuterLines: TLazSynEditNestedFoldsList;
FNeedValidate: Boolean;
@ -353,6 +354,9 @@ type
procedure IncPaintLock; override;
procedure DecPaintLock; override;
procedure InvalidateAll;
procedure SetNodeState(ALinePos, AstartPos: Integer; AState: TSynMarkupIfdefNodeState);
// AFirst/ ALast are 1 based
//Procedure Invalidate(SkipPaint: Boolean = False);
//Procedure InvalidateLines(AFirstLine: Integer = 0; ALastLine: Integer = 0; SkipPaint: Boolean = False);
@ -360,6 +364,7 @@ type
property FoldView: TSynEditFoldedView read FFoldView write SetFoldView;
property Highlighter: TSynPasSyn read FHighlighter write SetHighlighter;
property OnNodeStateRequest: TSynMarkupIfdefStateRequest read FOnNodeStateRequest write FOnNodeStateRequest;
end;
function dbgs(AFlag: SynMarkupIfDefLineFlag): String; overload;
@ -1567,20 +1572,8 @@ begin
idnIfdef: begin
assert(PeerList[i].NodeType in [idnElse, idnElseIf, idnEndIf], 'PeerList[i].NodeType in [idnElse, idnEndIf] for other ifdef');
if PeerList[i].IfDefPeer <> OtherLine.Entry[j] then begin
if OtherLine.Entry[j].GetPeer(PeerList[i].NodeType) <> nil then begin
debugln(['COMPARING MaxPeerdepth for ',dbgs(PeerList[i].NodeType), ' to ifdef other line']);
if (OtherLine.NestDepthAtNodeStart + OtherLine.Entry[j].RelativeNestDepth + 1 = i
// ANode.NestDepthAtNodeStart + PeerList[i].RelativeNestDepth
)
then begin
Debugln(['New Peer (REPLACE) for ',dbgs(PeerList[i].NodeType), ' to ifdef other line']);
PeerList[i].IfDefPeer := OtherLine.Entry[j];
end;
end
else begin
Debugln(['New Peer for ',dbgs(PeerList[i].NodeType), ' to ifdef other line']);
PeerList[i].IfDefPeer := OtherLine.Entry[j];
end;
Debugln(['New Peer for ',dbgs(PeerList[i].NodeType), ' to ifdef other line']);
PeerList[i].IfDefPeer := OtherLine.Entry[j];
end;
j := -1;
break;
@ -1589,20 +1582,8 @@ begin
assert(PeerList[i].NodeType in [idnElse, idnElseIf, idnEndIf], 'PeerList[i].NodeType in [idnElse, idnEndIf] for other else');
if (PeerList[i].NodeType = idnEndIf) then begin
if PeerList[i].ElsePeer <> OtherLine.Entry[j] then begin
if OtherLine.Entry[j].GetPeer(PeerList[i].NodeType) <> nil then begin
debugln(['COMPARING MaxPeerdepth for ',dbgs(PeerList[i].NodeType), ' to else other line']);
if OtherLine.NestDepthAtNodeStart + OtherLine.Entry[j].RelativeNestDepth = i
// ANode.NestDepthAtNodeStart + PeerList[i].RelativeNestDepth
then begin
Debugln(['New Peer (REPLACE) for ',dbgs(PeerList[i].NodeType), ' to else other line']);
PeerList[i].ElsePeer := OtherLine.Entry[j];
end;
end
else begin
Debugln(['New Peer for ',dbgs(PeerList[i].NodeType), ' to else other line']);
PeerList[i].ElsePeer := OtherLine.Entry[j];
end;
Debugln(['New Peer for ',dbgs(PeerList[i].NodeType), ' to else other line']);
PeerList[i].ElsePeer := OtherLine.Entry[j];
end;
j := -1;
end
@ -1610,19 +1591,8 @@ begin
if (PeerList[i].NodeType in [idnElseIf, idnElse]) and (OtherLine.Entry[j].NodeType = idnElseIf)
then begin
if PeerList[i].IfDefPeer <> OtherLine.Entry[j] then begin
if OtherLine.Entry[j].GetPeer(PeerList[i].NodeType) <> nil then begin
debugln(['COMPARING MaxPeerdepth for ',dbgs(PeerList[i].NodeType), ' to else other line']);
if OtherLine.NestDepthAtNodeStart + OtherLine.Entry[j].RelativeNestDepth = i
// ANode.NestDepthAtNodeStart + PeerList[i].RelativeNestDepth
then begin
Debugln(['New Peer (REPLACE) for ',dbgs(PeerList[i].NodeType), ' to else other line']);
PeerList[i].IfDefPeer := OtherLine.Entry[j];
end;
end
else begin
Debugln(['New Peer for ',dbgs(PeerList[i].NodeType), ' to else other line']);
PeerList[i].IfDefPeer := OtherLine.Entry[j];
end;
Debugln(['New Peer for ',dbgs(PeerList[i].NodeType), ' to else other line']);
PeerList[i].IfDefPeer := OtherLine.Entry[j];
end;
j := -1;
end
@ -2863,7 +2833,12 @@ end;
function TSynEditMarkupIfDef.DoNodeStateRequest(Sender: TObject; LinePos,
XStartPos: Integer): TSynMarkupIfdefNodeState;
begin
Result := idnEnabled;
if FOnNodeStateRequest <> nil then
Result := FOnNodeStateRequest(Self, LinePos, XStartPos)
else
Result := idnInvalid;
//Result := idnEnabled;
if pos('y', copy(SynEdit.Lines[LinePos-1], XStartPos, 100)) > 1 then
Result := idnDisabled;
DebugLn(['STATE REQUEST ', LinePos, ' ', XStartPos, ' : ', dbgs(Result)]);
@ -2920,6 +2895,17 @@ begin
ValidateMatches;
end;
procedure TSynEditMarkupIfDef.InvalidateAll;
begin
FIfDefTree.Clear;
end;
procedure TSynEditMarkupIfDef.SetNodeState(ALinePos, AstartPos: Integer;
AState: TSynMarkupIfdefNodeState);
begin
FIfDefTree.SetNodeState(ALinePos, AstartPos, AState);
end;
var OldAssert: TAssertErrorProc = @SysAssert;
Procedure MyAssert(const Msg,FName:ShortString;LineNo:Longint;ErrorAddr:Pointer);

View File

@ -54,7 +54,7 @@ uses
SynEditMiscClasses, SynEditMarkupHighAll, SynEditMarks,
SynBeautifier, LazSynEditText,
SynPluginSyncronizedEditBase, SourceSynEditor, SynMacroRecorder,
SynExportHTML, SynHighlighterPas, SynEditMarkup,
SynExportHTML, SynHighlighterPas, SynEditMarkup, SynEditMarkupIfDef,
// Intf
SrcEditorIntf, MenuIntf, LazIDEIntf, PackageIntf, IDEHelpIntf, IDEImagesIntf,
IDEWindowIntf, ProjectIntf, MacroDefIntf,
@ -237,6 +237,9 @@ type
FTempTopLine: Integer;
FEditPlugin: TSynEditPlugin1; // used to get the LinesInserted and
// LinesDeleted messages
{$IFDEF WithSynMarkupIfDef}
FOnIfdefNodeStateRequest: TSynMarkupIfdefStateRequest;
{$ENDIF}
FSyncroLockCount: Integer;
FPageName: string;
@ -298,6 +301,11 @@ type
procedure UpdateNoteBook(const ANewNoteBook: TSourceNotebook; ANewPage: TTabSheet);
procedure SetVisible(Value: boolean);
procedure UnbindEditor;
{$IFDEF WithSynMarkupIfDef}
function DoIfDefNodeStateRequest(Sender: TObject; LinePos,
XStartPos: Integer): TSynMarkupIfdefNodeState;
{$ENDIF}
protected
ErrorMsgs: TStrings;
@ -491,6 +499,12 @@ type
procedure LineInfoNotificationChange(const ASender: TObject; const ASource: String);
function SourceToDebugLine(aLinePos: Integer): Integer;
function DebugToSourceLine(aLinePos: Integer): Integer;
{$IFDEF WithSynMarkupIfDef}
procedure InvalidateAllIfdefNodes;
procedure SetIfdefNodeState(ALinePos, AstartPos: Integer; AState: TSynMarkupIfdefNodeState);
property OnIfdefNodeStateRequest: TSynMarkupIfdefStateRequest read FOnIfdefNodeStateRequest write FOnIfdefNodeStateRequest;
{$ENDIF}
public
// properties
property CodeBuffer: TCodeBuffer read GetCodeBuffer write SetCodeBuffer;
@ -2647,7 +2661,7 @@ begin
end;
{------------------------------G O T O L I N E -----------------------------}
Function TSourceEditor.GotoLine(Value: Integer): Integer;
function TSourceEditor.GotoLine(Value: Integer): Integer;
Var
P: TPoint;
NewTopLine: integer;
@ -2874,7 +2888,7 @@ begin
end;
function TSourceEditor.DoFindAndReplace(aFindText, aReplaceText: String;
anOptions: TSynSearchOptions): integer;
anOptions: TSynSearchOptions): Integer;
var
AText, ACaption: String;
OldEntireScope, Again: Boolean;
@ -2962,7 +2976,7 @@ end;
//-----------------------------------------------------------------------------
Procedure TSourceEditor.FocusEditor;
procedure TSourceEditor.FocusEditor;
Begin
DebugLnEnter(SRCED_PAGES, ['>> TSourceEditor.FocusEditor A ',PageName,' ',FEditor.Name]);
IDEWindowCreators.ShowForm(SourceNotebook,true);
@ -2976,7 +2990,7 @@ Begin
DebugLnExit(SRCED_PAGES, ['<< TSourceEditor.FocusEditor END ',PageName,' ',FEditor.Name]);
end;
Function TSourceEditor.GetReadOnly: Boolean;
function TSourceEditor.GetReadOnly: Boolean;
Begin
Result:=FEditor.ReadOnly;
End;
@ -4073,7 +4087,7 @@ begin
UpdateExecutionSourceMark;
end;
Function TSourceEditor.RefreshEditorSettings: Boolean;
function TSourceEditor.RefreshEditorSettings: Boolean;
var
SimilarEditor: TSynEdit;
Begin
@ -4089,7 +4103,7 @@ Begin
SourceNotebook.UpdateActiveEditColors(FEditor);
end;
Procedure TSourceEditor.ccAddMessage(Texts: String);
procedure TSourceEditor.ccAddMessage(Texts: String);
Begin
ErrorMsgs.Add(Texts);
End;
@ -4271,7 +4285,7 @@ end;
{ AOwner is the TSourceNotebook
AParent is a page of the TPageControl }
Procedure TSourceEditor.CreateEditor(AOwner: TComponent; AParent: TWinControl);
procedure TSourceEditor.CreateEditor(AOwner: TComponent; AParent: TWinControl);
var
NewName: string;
i: integer;
@ -4323,6 +4337,9 @@ Begin
RegisterMouseActionExecHandler(@EditorHandleMouseAction);
// IMPORTANT: when you change above, don't forget updating UnbindEditor
Parent := AParent;
{$IFDEF WithSynMarkupIfDef}
OnIfdefNodeStateRequest := @DoIfDefNodeStateRequest;;
{$ENDIF}
end;
Manager.CodeTemplateModul.AddEditor(FEditor);
Manager.FMacroRecorder.AddEditor(FEditor);
@ -4439,7 +4456,7 @@ begin
Result := FSharedValues.NeedsUpdateCodeBuffer;
end;
Function TSourceEditor.GetSource: TStrings;
function TSourceEditor.GetSource: TStrings;
Begin
//return synedit's source.
Result := FEditor.Lines;
@ -4484,32 +4501,32 @@ begin
end;
end;
Procedure TSourceEditor.SetSource(value: TStrings);
procedure TSourceEditor.SetSource(Value: TStrings);
Begin
FEditor.Lines.Assign(Value);
end;
Function TSourceEditor.GetCurrentCursorXLine: Integer;
function TSourceEditor.GetCurrentCursorXLine: Integer;
Begin
Result := FEditor.CaretX
end;
Procedure TSourceEditor.SetCurrentCursorXLine(num: Integer);
procedure TSourceEditor.SetCurrentCursorXLine(num: Integer);
Begin
FEditor.CaretX := Num;
end;
Function TSourceEditor.GetCurrentCursorYLine: Integer;
function TSourceEditor.GetCurrentCursorYLine: Integer;
Begin
Result := FEditor.CaretY;
end;
Procedure TSourceEditor.SetCurrentCursorYLine(num: Integer);
procedure TSourceEditor.SetCurrentCursorYLine(num: Integer);
Begin
FEditor.CaretY := Num;
end;
Procedure TSourceEditor.SelectText(const StartPos, EndPos: TPoint);
procedure TSourceEditor.SelectText(const StartPos, EndPos: TPoint);
Begin
FEditor.BlockBegin := StartPos;
FEditor.BlockEnd := EndPos;
@ -4566,7 +4583,7 @@ begin
FEditor.LogicalCaretXY:=NewCaretXY;
end;
Function TSourceEditor.GetModified: Boolean;
function TSourceEditor.GetModified: Boolean;
Begin
Result := FSharedValues.Modified;
end;
@ -4576,12 +4593,12 @@ begin
FSharedValues.SetModified(NewValue);
end;
Function TSourceEditor.GetInsertMode: Boolean;
function TSourceEditor.GetInsertMode: Boolean;
Begin
Result := FEditor.Insertmode;
end;
Function TSourceEditor.Close: Boolean;
function TSourceEditor.Close: Boolean;
Begin
DebugLnEnter(SRCED_CLOSE, ['TSourceEditor.Close ShareCount=', FSharedValues.SharedEditorCount]);
Result := True;
@ -4842,7 +4859,7 @@ begin
OnMouseWheel(Self, Shift, WheelDelta, MousePos, Handled)
end;
Procedure TSourceEditor.EditorMouseDown(Sender: TObject; Button: TMouseButton;
procedure TSourceEditor.EditorMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
CheckActiveWindow;
@ -5243,6 +5260,29 @@ begin
Result := FEditor.IDEGutterMarks.DebugLineToSourceLine(aLinePos);
end;
{$IFDEF WithSynMarkupIfDef}
procedure TSourceEditor.InvalidateAllIfdefNodes;
begin
FEditor.InvalidateAllIfdefNodes;
end;
procedure TSourceEditor.SetIfdefNodeState(ALinePos, AstartPos: Integer;
AState: TSynMarkupIfdefNodeState);
begin
FEditor.SetIfdefNodeState(ALinePos, AstartPos, AState);
end;
function TSourceEditor.DoIfDefNodeStateRequest(Sender: TObject; LinePos,
XStartPos: Integer): TSynMarkupIfdefNodeState;
begin
if FOnIfdefNodeStateRequest <> nil then
Result := FOnIfdefNodeStateRequest(Self, LinePos, XStartPos)
else
Result := idnInvalid;
end;
{$ENDIF}
function TSourceEditor.SharedEditorCount: Integer;
begin
Result := FSharedValues.SharedEditorCount;

View File

@ -209,6 +209,7 @@ type
FTemplateEdit: TSynPluginTemplateEdit;
FMarkupForGutterMark: TSynEditMarkupGutterMark;
{$IFDEF WithSynMarkupIfDef}
FOnIfdefNodeStateRequest: TSynMarkupIfdefStateRequest;
FMarkupIfDef: TSynEditMarkupIfDef;
{$ENDIF}
FTopInfoDisplay: TSourceLazSynTopInfoView;
@ -218,6 +219,10 @@ type
FTopInfoMarkup: TSynSelectedColor;
FUserWordsList: TList;
{$IFDEF WithSynMarkupIfDef}
function DoIfDefNodeStateRequest(Sender: TObject; LinePos,
XStartPos: Integer): TSynMarkupIfdefNodeState;
{$ENDIF}
function GetHighlightUserWordCount: Integer;
function GetHighlightUserWords(AIndex: Integer): TSourceSynEditMarkupHighlightAllMulti;
function GetIDEGutterMarks: TIDESynGutterMarks;
@ -252,6 +257,11 @@ type
property HighlightUserWordCount: Integer read GetHighlightUserWordCount write SetHighlightUserWordCount;
property HighlightUserWords[AIndex: Integer]: TSourceSynEditMarkupHighlightAllMulti read GetHighlightUserWords;
property MarkupMgr;
{$IFDEF WithSynMarkupIfDef}
procedure InvalidateAllIfdefNodes;
procedure SetIfdefNodeState(ALinePos, AstartPos: Integer; AState: TSynMarkupIfdefNodeState);
property OnIfdefNodeStateRequest: TSynMarkupIfdefStateRequest read FOnIfdefNodeStateRequest write FOnIfdefNodeStateRequest;
{$ENDIF}
end;
TIDESynHighlighterPasRangeList = class(TSynHighlighterPasRangeList)
@ -1487,6 +1497,29 @@ begin
Result := TIDESynGutterMarks(Gutter.Parts.ByClass[TIDESynGutterMarks, 0]);
end;
{$IFDEF WithSynMarkupIfDef}
function TIDESynEditor.DoIfDefNodeStateRequest(Sender: TObject; LinePos,
XStartPos: Integer): TSynMarkupIfdefNodeState;
begin
if FOnIfdefNodeStateRequest <> nil then
Result := FOnIfdefNodeStateRequest(Self, LinePos, XStartPos)
else
Result := idnInvalid;
end;
procedure TIDESynEditor.InvalidateAllIfdefNodes;
begin
FMarkupIfDef.InvalidateAll;
end;
procedure TIDESynEditor.SetIfdefNodeState(ALinePos, AstartPos: Integer;
AState: TSynMarkupIfdefNodeState);
begin
FMarkupIfDef.SetNodeState(ALinePos, AstartPos, AState);
end;
{$ENDIF}
function TIDESynEditor.GetHighlightUserWordCount: Integer;
begin
Result := FUserWordsList.Count;
@ -1544,6 +1577,7 @@ begin
{$IFDEF WithSynMarkupIfDef}
FMarkupIfDef := TSynEditMarkupIfDef.Create(Self);
FMarkupIfDef.FoldView := TSynEditFoldedView(FoldedTextBuffer);
FMarkupIfDef.OnNodeStateRequest := @DoIfDefNodeStateRequest;
TSynEditMarkupManager(MarkupMgr).AddMarkUp(FMarkupIfDef);
{$ENDIF}
@ -1613,6 +1647,7 @@ begin
Ime.InvalidateLinesMethod := @InvalidateLines;
ImeHandler := Ime;
end;
{$ENDIF}
{ TIDESynPasSyn }