mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-24 00:19:20 +02:00
IDE: refactor methods PrepareFile and ChangeEditorPage out of OpenEditorFile.
git-svn-id: trunk@45685 -
This commit is contained in:
parent
253b7b7eb2
commit
042d8fed63
@ -75,15 +75,17 @@ type
|
|||||||
// Used by OpenFileAtCursor
|
// Used by OpenFileAtCursor
|
||||||
FActiveSrcEdit: TSourceEditor;
|
FActiveSrcEdit: TSourceEditor;
|
||||||
FActiveUnitInfo: TUnitInfo;
|
FActiveUnitInfo: TUnitInfo;
|
||||||
//
|
// Used by OpenEditorFile
|
||||||
|
function OpenResource: TModalResult;
|
||||||
|
function ChangeEditorPage: TModalResult;
|
||||||
|
function CheckInternalFile: TModalResult;
|
||||||
|
function CheckRevert: TModalResult;
|
||||||
|
function PrepareFile: TModalResult;
|
||||||
|
function PrepareRevert(DiskFilename: String): TModalResult;
|
||||||
|
// Used by OpenFileAtCursor
|
||||||
function CheckIfIncludeDirectiveInFront(const Line: string; X: integer): boolean;
|
function CheckIfIncludeDirectiveInFront(const Line: string; X: integer): boolean;
|
||||||
function FindFile(var CurFileName: String; CurSearchPath: String): Boolean;
|
function FindFile(var CurFileName: String; CurSearchPath: String): Boolean;
|
||||||
function GetFilenameAtRowCol(XY: TPoint; var IsIncludeDirective: boolean): string;
|
function GetFilenameAtRowCol(XY: TPoint; var IsIncludeDirective: boolean): string;
|
||||||
// Used by OpenEditorFile
|
|
||||||
function OpenResource: TModalResult;
|
|
||||||
function CheckInternalFile: TModalResult;
|
|
||||||
function CheckRevert: TModalResult;
|
|
||||||
function PrepareRevert(DiskFilename: String): TModalResult;
|
|
||||||
public
|
public
|
||||||
constructor Create(AManager: TLazSourceFileManager);
|
constructor Create(AManager: TLazSourceFileManager);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -467,6 +469,39 @@ begin
|
|||||||
exit(mrOK);
|
exit(mrOK);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TFileOpenClose.PrepareFile: TModalResult;
|
||||||
|
begin
|
||||||
|
FUnitIndex:=Project1.IndexOfFilename(FFilename);
|
||||||
|
FUnknownFile := (FUnitIndex < 0);
|
||||||
|
FNewEditorInfo := nil;
|
||||||
|
if not FUnknownFile then begin
|
||||||
|
FNewUnitInfo := Project1.Units[FUnitIndex];
|
||||||
|
if FEditorInfo <> nil then
|
||||||
|
FNewEditorInfo := FEditorInfo
|
||||||
|
else if (ofProjectLoading in FFlags) then
|
||||||
|
FNewEditorInfo := FNewUnitInfo.GetClosedOrNewEditorInfo
|
||||||
|
else
|
||||||
|
FNewEditorInfo := FNewUnitInfo.EditorInfo[0];
|
||||||
|
end;
|
||||||
|
Result := mrOK;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TFileOpenClose.ChangeEditorPage: TModalResult;
|
||||||
|
// file already open -> change source notebook page
|
||||||
|
begin
|
||||||
|
//DebugLn(['TFileOpenClose.ChangeEditorPage file already open ',FNewUnitInfo.Filename,' WindowIndex=',FNewEditorInfo.WindowID,' PageIndex=',FNewEditorInfo.PageIndex]);
|
||||||
|
with SourceEditorManager do begin
|
||||||
|
ActiveSourceWindowIndex := IndexOfSourceWindowWithID(FNewEditorInfo.WindowID);
|
||||||
|
ActiveSourceWindow.PageIndex:= FNewEditorInfo.PageIndex;
|
||||||
|
end;
|
||||||
|
if ofDoLoadResource in FFlags then
|
||||||
|
Result:=OpenResource
|
||||||
|
else
|
||||||
|
Result:=mrOk;
|
||||||
|
end;
|
||||||
|
|
||||||
function TFileOpenClose.OpenEditorFile(AFileName: string; APageIndex, AWindowIndex: integer;
|
function TFileOpenClose.OpenEditorFile(AFileName: string; APageIndex, AWindowIndex: integer;
|
||||||
AEditorInfo: TUnitEditorInfo; AFlags: TOpenFlags; AUseWindowID: Boolean): TModalResult;
|
AEditorInfo: TUnitEditorInfo; AFlags: TOpenFlags; AUseWindowID: Boolean): TModalResult;
|
||||||
var // WindowIndex is WindowID
|
var // WindowIndex is WindowID
|
||||||
@ -599,18 +634,8 @@ begin
|
|||||||
Result := PrepareRevert(DiskFilename);
|
Result := PrepareRevert(DiskFilename);
|
||||||
if Result <> mrOK then exit;
|
if Result <> mrOK then exit;
|
||||||
end else begin
|
end else begin
|
||||||
FUnitIndex:=Project1.IndexOfFilename(FFilename);
|
Result := PrepareFile;
|
||||||
FUnknownFile := (FUnitIndex < 0);
|
if Result <> mrOK then exit;
|
||||||
FNewEditorInfo := nil;
|
|
||||||
if not FUnknownFile then begin
|
|
||||||
FNewUnitInfo:=Project1.Units[FUnitIndex];
|
|
||||||
if FEditorInfo <> nil then
|
|
||||||
FNewEditorInfo := FEditorInfo
|
|
||||||
else if (ofProjectLoading in FFlags) then
|
|
||||||
FNewEditorInfo := FNewUnitInfo.GetClosedOrNewEditorInfo
|
|
||||||
else
|
|
||||||
FNewEditorInfo := FNewUnitInfo.EditorInfo[0];
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (FNewEditorInfo <> nil) and (ofAddToProject in FFlags) and (not FNewUnitInfo.IsPartOfProject) then
|
if (FNewEditorInfo <> nil) and (ofAddToProject in FFlags) and (not FNewUnitInfo.IsPartOfProject) then
|
||||||
@ -619,16 +644,10 @@ begin
|
|||||||
Project1.Modified:=true;
|
Project1.Modified:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (FNewEditorInfo <> nil) and (FFlags * [ofProjectLoading, ofRevert] = []) and (FNewEditorInfo.EditorComponent <> nil) then
|
if (FNewEditorInfo <> nil) and (FFlags * [ofProjectLoading, ofRevert] = [])
|
||||||
|
and (FNewEditorInfo.EditorComponent <> nil) then
|
||||||
begin
|
begin
|
||||||
//DebugLn(['TFileOpenClose.OpenEditorFile file already open ',FNewUnitInfo.Filename,' WindowIndex=',FNewEditorInfo.WindowID,' PageIndex=',FNewEditorInfo.PageIndex]);
|
Result := ChangeEditorPage;
|
||||||
// file already open -> change source notebook page
|
|
||||||
SourceEditorManager.ActiveSourceWindowIndex := SourceEditorManager.IndexOfSourceWindowWithID(FNewEditorInfo.WindowID);
|
|
||||||
SourceEditorManager.ActiveSourceWindow.PageIndex:= FNewEditorInfo.PageIndex;
|
|
||||||
if ofDoLoadResource in FFlags then
|
|
||||||
Result:=OpenResource
|
|
||||||
else
|
|
||||||
Result:=mrOk;
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user