mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-26 15:00:26 +02:00
IDE,IDEIntf: added TSourceEditorManagerInterface.ReIndent, added parameter Beautify to TLazProjectFile.SetSourceText
git-svn-id: trunk@40813 -
This commit is contained in:
parent
53774998ef
commit
fd4d0497fc
@ -377,7 +377,7 @@ type
|
||||
procedure UpdateUsageCount(TheUsage: TUnitUsage; const Factor: TDateTime);
|
||||
procedure UpdateSourceDirectoryReference;
|
||||
|
||||
procedure SetSourceText(const SourceText: string); override;
|
||||
procedure SetSourceText(const SourceText: string; Beautify: boolean = false); override;
|
||||
function GetSourceText: string; override;
|
||||
|
||||
// component dependencies
|
||||
@ -2125,9 +2125,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TUnitInfo.SetSourceText(const SourceText: string);
|
||||
procedure TUnitInfo.SetSourceText(const SourceText: string; Beautify: boolean);
|
||||
var
|
||||
Src: String;
|
||||
begin
|
||||
Source.Source:=SourceText;
|
||||
Src:=SourceText;
|
||||
if Beautify then
|
||||
Src:=SourceEditorManagerIntf.ReIndent(Src);
|
||||
Source.Source:=Src;
|
||||
end;
|
||||
|
||||
function TUnitInfo.GetSourceText: string;
|
||||
|
@ -1309,7 +1309,7 @@ begin
|
||||
+' Application.Run;'+LineEnding
|
||||
+'end.'+LineEnding
|
||||
+LineEnding;
|
||||
AProject.MainFile.SetSourceText(NewSource);
|
||||
AProject.MainFile.SetSourceText(NewSource,true);
|
||||
|
||||
// add lcl pp/pas dirs to source search path
|
||||
AProject.AddPackageDependency('LCL');
|
||||
@ -1363,7 +1363,7 @@ begin
|
||||
+'begin'+LineEnding
|
||||
+'end.'+LineEnding
|
||||
+LineEnding;
|
||||
AProject.MainFile.SetSourceText(NewSource);
|
||||
AProject.MainFile.SetSourceText(NewSource,true);
|
||||
|
||||
AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)';
|
||||
AProject.LazCompilerOptions.TargetFilename:='project1';
|
||||
@ -1422,7 +1422,7 @@ begin
|
||||
+'begin'+LineEnding
|
||||
+'end.'+LineEnding
|
||||
+LineEnding;
|
||||
AProject.MainFile.SetSourceText(NewSource);
|
||||
AProject.MainFile.SetSourceText(NewSource,true);
|
||||
|
||||
AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)';
|
||||
AProject.LazCompilerOptions.TargetFilename:='project1';
|
||||
@ -1484,7 +1484,7 @@ begin
|
||||
+'begin'+LineEnding
|
||||
+'end.'+LineEnding
|
||||
+LineEnding;
|
||||
AProject.MainFile.SetSourceText(NewSource);
|
||||
AProject.MainFile.SetSourceText(NewSource,true);
|
||||
AProject.LazCompilerOptions.Win32GraphicApp:=false;
|
||||
end;
|
||||
end;
|
||||
@ -1664,7 +1664,7 @@ begin
|
||||
NewSource.Add(' Application.Free;');
|
||||
NewSource.Add('end.');
|
||||
NewSource.Add('');
|
||||
AProject.MainFile.SetSourceText(NewSource.Text);
|
||||
AProject.MainFile.SetSourceText(NewSource.Text,true);
|
||||
NewSource.Free;
|
||||
end;
|
||||
|
||||
@ -1720,7 +1720,7 @@ begin
|
||||
+'begin'+LineEnding
|
||||
+'end.'+LineEnding
|
||||
+LineEnding;
|
||||
AProject.MainFile.SetSourceText(NewSource);
|
||||
AProject.MainFile.SetSourceText(NewSource,true);
|
||||
|
||||
AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)';
|
||||
AProject.LazCompilerOptions.TargetFilename:='project1';
|
||||
|
@ -1015,6 +1015,8 @@ type
|
||||
procedure ClearExecutionMarks;
|
||||
procedure FillExecutionMarks;
|
||||
procedure ReloadEditorOptions;
|
||||
function ReIndent(const Src: string; OldIndent: integer=0;
|
||||
OldTabWidth: integer=4): string; override;
|
||||
// find / replace text
|
||||
procedure FindClicked(Sender: TObject);
|
||||
procedure FindNextClicked(Sender: TObject);
|
||||
@ -5463,7 +5465,7 @@ begin
|
||||
Manager.DeactivateCompletionForm;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.CreateNotebook;
|
||||
procedure TSourceNotebook.CreateNotebook;
|
||||
var
|
||||
APage: TTabSheet;
|
||||
Begin
|
||||
@ -6026,7 +6028,7 @@ begin
|
||||
Result:=TSourceEditorInterface(FSourceEditorList[Index]);
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.BuildPopupMenu;
|
||||
procedure TSourceNotebook.BuildPopupMenu;
|
||||
begin
|
||||
//debugln('TSourceNotebook.BuildPopupMenu');
|
||||
|
||||
@ -6308,7 +6310,7 @@ end;
|
||||
|
||||
Called whenever an editor status changes. Sender is normally a TSynEdit.
|
||||
-------------------------------------------------------------------------------}
|
||||
Procedure TSourceNotebook.EditorChanged(Sender: TObject);
|
||||
procedure TSourceNotebook.EditorChanged(Sender: TObject);
|
||||
var SenderDeleted: boolean;
|
||||
Begin
|
||||
SenderDeleted:=(Sender as TControl).Parent=nil;
|
||||
@ -6398,8 +6400,8 @@ begin
|
||||
Result := SourceEditorManager.CompletionPlugins[Index];
|
||||
end;
|
||||
|
||||
function TSourceNotebook.NewSE(PageNum: Integer; NewPageNum: Integer = -1;
|
||||
ASharedEditor: TSourceEditor = nil; ATabCaption: String = ''): TSourceEditor;
|
||||
function TSourceNotebook.NewSE(Pagenum: Integer; NewPagenum: Integer;
|
||||
ASharedEditor: TSourceEditor; ATabCaption: String): TSourceEditor;
|
||||
begin
|
||||
{$IFDEF IDE_DEBUG}
|
||||
debugln('TSourceNotebook.NewSE A ');
|
||||
@ -6477,7 +6479,7 @@ begin
|
||||
Result := TSourceEditor(FSourceEditorList[i]);
|
||||
end;
|
||||
|
||||
Function TSourceNotebook.GetActiveSE: TSourceEditor;
|
||||
function TSourceNotebook.GetActiveSE: TSourceEditor;
|
||||
Begin
|
||||
Result := nil;
|
||||
if (FSourceEditorList=nil) or (FSourceEditorList.Count=0) or (PageIndex<0) then
|
||||
@ -6713,7 +6715,7 @@ begin
|
||||
UpdateStatusBar;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.NextEditor;
|
||||
procedure TSourceNotebook.NextEditor;
|
||||
Begin
|
||||
if PageIndex < PageCount-1 then
|
||||
PageIndex := PageIndex+1
|
||||
@ -6721,7 +6723,7 @@ Begin
|
||||
PageIndex := 0;
|
||||
End;
|
||||
|
||||
Procedure TSourceNotebook.PrevEditor;
|
||||
procedure TSourceNotebook.PrevEditor;
|
||||
Begin
|
||||
if PageIndex > 0 then
|
||||
PageIndex := PageIndex-1
|
||||
@ -7091,13 +7093,13 @@ begin
|
||||
MainIDEInterface.DoShowProjectInspector(True);
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.OpenAtCursorClicked(Sender: TObject);
|
||||
procedure TSourceNotebook.OpenAtCursorClicked(Sender: TObject);
|
||||
begin
|
||||
if assigned(Manager) and Assigned(Manager.OnOpenFileAtCursorClicked) then
|
||||
Manager.OnOpenFileAtCursorClicked(Sender);
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.CutClicked(Sender: TObject);
|
||||
procedure TSourceNotebook.CutClicked(Sender: TObject);
|
||||
var ActSE: TSourceEditor;
|
||||
begin
|
||||
ActSE := GetActiveSE;
|
||||
@ -7105,7 +7107,7 @@ begin
|
||||
ActSE.DoEditorExecuteCommand(ecCut);
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.CopyClicked(Sender: TObject);
|
||||
procedure TSourceNotebook.CopyClicked(Sender: TObject);
|
||||
var ActSE: TSourceEditor;
|
||||
begin
|
||||
ActSE := GetActiveSE;
|
||||
@ -7113,7 +7115,7 @@ begin
|
||||
ActSE.DoEditorExecuteCommand(ecCopy);
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.PasteClicked(Sender: TObject);
|
||||
procedure TSourceNotebook.PasteClicked(Sender: TObject);
|
||||
var ActSE: TSourceEditor;
|
||||
begin
|
||||
ActSE := GetActiveSE;
|
||||
@ -7374,7 +7376,7 @@ begin
|
||||
Result:=FSourceEditorList.Count;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.CloseClicked(Sender: TObject; CloseOthers: Boolean = False);
|
||||
procedure TSourceNotebook.CloseClicked(Sender: TObject; CloseOthers: Boolean);
|
||||
Begin
|
||||
if assigned(Manager) and Assigned(Manager.OnCloseClicked) then
|
||||
Manager.OnCloseClicked(Sender, CloseOthers);
|
||||
@ -7472,7 +7474,7 @@ begin
|
||||
GetActiveSE.IsLocked := not GetActiveSE.IsLocked;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.UpdateStatusBar;
|
||||
procedure TSourceNotebook.UpdateStatusBar;
|
||||
var
|
||||
tempEditor: TSourceEditor;
|
||||
PanelFilename: String;
|
||||
@ -7685,7 +7687,7 @@ begin
|
||||
FUpdateTabAndPageTimer.Enabled := True;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.NotebookPageChanged(Sender: TObject);
|
||||
procedure TSourceNotebook.NotebookPageChanged(Sender: TObject);
|
||||
var
|
||||
TempEditor:TSourceEditor;
|
||||
CaretXY: TPoint;
|
||||
@ -7745,7 +7747,7 @@ Begin
|
||||
DebugLnExit(SRCED_PAGES, ['<< TSourceNotebook.NotebookPageChanged ']);
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.ProcessParentCommand(Sender: TObject;
|
||||
procedure TSourceNotebook.ProcessParentCommand(Sender: TObject;
|
||||
var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer;
|
||||
var Handled: boolean);
|
||||
var
|
||||
@ -7858,7 +7860,7 @@ begin
|
||||
FProcessingCommand:=false;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.ParentCommandProcessed(Sender: TObject;
|
||||
procedure TSourceNotebook.ParentCommandProcessed(Sender: TObject;
|
||||
var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer;
|
||||
var Handled: boolean);
|
||||
begin
|
||||
@ -7873,7 +7875,7 @@ begin
|
||||
if Handled then Command:=ecNone;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.ReloadEditorOptions;
|
||||
procedure TSourceNotebook.ReloadEditorOptions;
|
||||
var
|
||||
I: integer;
|
||||
Begin
|
||||
@ -7935,8 +7937,8 @@ begin
|
||||
dec(fAutoFocusLock);
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.EditorMouseMove(Sender: TObject; Shift: TShiftstate;
|
||||
X,Y: Integer);
|
||||
procedure TSourceNotebook.EditorMouseMove(Sender: TObject; Shift: TShiftstate;
|
||||
X, Y: Integer);
|
||||
begin
|
||||
MaybeHideHint;
|
||||
|
||||
@ -8021,7 +8023,7 @@ begin
|
||||
SrcEdit.CursorScreenXY:=Point(Indent+1,SrcEdit.CursorScreenXY.Y);
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.HintTimer(sender: TObject);
|
||||
procedure TSourceNotebook.HintTimer(Sender: TObject);
|
||||
var
|
||||
MousePos: TPoint;
|
||||
AControl: TControl;
|
||||
@ -9272,6 +9274,24 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSourceEditorManager.ReIndent(const Src: string; OldIndent: integer;
|
||||
OldTabWidth: integer): string;
|
||||
var
|
||||
NewTabWidth: Integer;
|
||||
NewIndent: Integer;
|
||||
begin
|
||||
if OldIndent=0 then
|
||||
GuessIndentSize(Src,OldIndent,EditorOpts.TabWidth);
|
||||
if (eoTabsToSpaces in EditorOpts.SynEditOptions)
|
||||
or (EditorOpts.BlockTabIndent=0) then
|
||||
NewTabWidth:=0
|
||||
else
|
||||
NewTabWidth:=EditorOpts.TabWidth;
|
||||
NewIndent:=EditorOpts.BlockTabIndent*EditorOpts.TabWidth+EditorOpts.BlockIndent;
|
||||
//debugln(['TSourceEditorManager.ReIndent OldIndent=',OldIndent,' OldTabWidth=',OldTabWidth,' NewIndent=',NewIndent,' NewTabWidth=',NewTabWidth]);
|
||||
Result:=BasicCodeTools.ReIndent(Src,OldIndent,OldTabWidth,NewIndent,NewTabWidth);
|
||||
end;
|
||||
|
||||
procedure TSourceEditorManager.FindClicked(Sender: TObject);
|
||||
begin
|
||||
if ActiveEditor <> nil then ActiveEditor.StartFindAndReplace(false);
|
||||
@ -9708,7 +9728,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSourceEditorManager.OnFilesDroping(Sender: TObject; const FileNames: Array of String);
|
||||
procedure TSourceEditorManager.OnFilesDroping(Sender: TObject;
|
||||
const FileNames: array of String);
|
||||
begin
|
||||
if Sender is TSourceNotebook then
|
||||
ActiveSourceWindow := TSourceNotebook(Sender);
|
||||
|
@ -107,7 +107,6 @@ type
|
||||
AncestorType: TPersistentClass; ResourceCode: TCodeBuffer;
|
||||
UseCreateFormStatements, DisableAutoSize: Boolean): TModalResult;
|
||||
function NewUniqueComponentName(Prefix: string): string;
|
||||
function ReIndent(const Src: string; OldIndent: integer = 0; OldTabWidth: integer = 4): string;
|
||||
|
||||
// methods for 'save unit'
|
||||
function ShowSaveFileAsDialog(var AFilename: string; AnUnitInfo: TUnitInfo;
|
||||
@ -536,7 +535,7 @@ begin
|
||||
NewUnitInfo.ComponentResourceName:='';
|
||||
end;
|
||||
Src:=NewFileDescriptor.CreateSource(NewUnitInfo.Filename,NewUnitName,NewUnitInfo.ComponentName);
|
||||
Src:=ReIndent(Src);
|
||||
Src:=SourceEditorManager.ReIndent(Src);
|
||||
//debugln(['TLazSourceFileManager.NewFile ',dbgtext(Src)]);
|
||||
Src:=CodeToolBoss.SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(Src,0);
|
||||
NewUnitInfo.Source.Source:=Src;
|
||||
@ -2542,24 +2541,6 @@ begin
|
||||
until IdentifierIsOk(Result);
|
||||
end;
|
||||
|
||||
function TLazSourceFileManager.ReIndent(const Src: string; OldIndent: integer;
|
||||
OldTabWidth: integer): string;
|
||||
var
|
||||
NewTabWidth: Integer;
|
||||
NewIndent: Integer;
|
||||
begin
|
||||
if OldIndent=0 then
|
||||
GuessIndentSize(Src,OldIndent,EditorOpts.TabWidth);
|
||||
if (eoTabsToSpaces in EditorOpts.SynEditOptions)
|
||||
or (EditorOpts.BlockTabIndent=0) then
|
||||
NewTabWidth:=0
|
||||
else
|
||||
NewTabWidth:=EditorOpts.TabWidth;
|
||||
NewIndent:=EditorOpts.BlockTabIndent*EditorOpts.TabWidth+EditorOpts.BlockIndent;
|
||||
//debugln(['TLazSourceFileManager.ReIndent OldIndent=',OldIndent,' OldTabWidth=',OldTabWidth,' NewIndent=',NewIndent,' NewTabWidth=',NewTabWidth]);
|
||||
Result:=BasicCodeTools.ReIndent(Src,OldIndent,OldTabWidth,NewIndent,NewTabWidth);
|
||||
end;
|
||||
|
||||
function TLazSourceFileManager.ShowSaveFileAsDialog(var AFilename: string;
|
||||
AnUnitInfo: TUnitInfo; var LFMCode, LRSCode: TCodeBuffer; CanAbort: boolean): TModalResult;
|
||||
var
|
||||
|
@ -65,7 +65,7 @@ type
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure SetSourceText(const SourceText: string); virtual; abstract;
|
||||
procedure SetSourceText(const SourceText: string; Beautify: boolean = false); virtual; abstract;
|
||||
function GetSourceText: string; virtual; abstract;
|
||||
procedure ClearModifieds; virtual; abstract;
|
||||
public
|
||||
|
@ -312,7 +312,10 @@ type
|
||||
// Editor Preferences
|
||||
function GetEditorControlSettings(EditControl: TControl): boolean; virtual; abstract;
|
||||
function GetHighlighterSettings(Highlighter: TObject): boolean; virtual; abstract;
|
||||
// Messages
|
||||
procedure ClearErrorLines; virtual; abstract;
|
||||
// General source functions
|
||||
function ReIndent(const Src: string; OldIndent: integer = 0; OldTabWidth: integer = 4): string; virtual; abstract;
|
||||
protected
|
||||
// Completion Plugins
|
||||
function GetActiveCompletionPlugin: TSourceEditorCompletionPlugin; virtual; abstract;
|
||||
|
Loading…
Reference in New Issue
Block a user