IDE: package editors: using the IDEWindowCreators

git-svn-id: trunk@26234 -
This commit is contained in:
mattias 2010-06-21 12:17:14 +00:00
parent bb984eaa31
commit fa00aff123
6 changed files with 39 additions and 234 deletions

View File

@ -51,8 +51,8 @@ uses
CodeToolManager, PascalParserTool, LinkScanner, FileProcs, CodeIndex, CodeToolManager, PascalParserTool, LinkScanner, FileProcs, CodeIndex,
StdCodeTools, SourceLog, StdCodeTools, SourceLog,
// IDEIntf // IDEIntf
SrcEditorIntf, IDEMsgIntf, IDEDialogs, LazConfigStorage, PackageIntf, IDEWindowIntf, SrcEditorIntf, IDEMsgIntf, IDEDialogs, LazConfigStorage,
TextTools, IDECommands, LazIDEIntf, PackageIntf, TextTools, IDECommands, LazIDEIntf,
// IDE // IDE
Project, DialogProcs, PackageSystem, PackageDefs, LazarusIDEStrConsts, Project, DialogProcs, PackageSystem, PackageDefs, LazarusIDEStrConsts,
IDEOptionDefs, MsgQuickFixes, BasePkgManager, AddToProjectDlg, IDEOptionDefs, MsgQuickFixes, BasePkgManager, AddToProjectDlg,
@ -3143,7 +3143,7 @@ begin
CreateCodeBrowser; CreateCodeBrowser;
CodeBrowserView.SetScopeToCurUnitOwner(true,true); CodeBrowserView.SetScopeToCurUnitOwner(true,true);
CodeBrowserView.SetFilterToSimpleIdentifier(Identifier); CodeBrowserView.SetFilterToSimpleIdentifier(Identifier);
CodeBrowserView.ShowOnTop; IDEWindowCreators.ShowForm(CodeBrowserView,true);
end; end;
end; end;

View File

@ -300,7 +300,7 @@ begin
OldSearchPageIndex:=SearchPageIndex; OldSearchPageIndex:=SearchPageIndex;
SearchPageIndex:=nil; SearchPageIndex:=nil;
SearchResultsView.EndUpdate(OldSearchPageIndex.PageIndex); SearchResultsView.EndUpdate(OldSearchPageIndex.PageIndex);
SearchResultsView.ShowOnTop; IDEWindowCreators.ShowForm(SearchResultsView,true);
finally finally
if SearchPageIndex <> nil then if SearchPageIndex <> nil then
SearchResultsView.EndUpdate(SearchPageIndex.PageIndex); SearchResultsView.EndUpdate(SearchPageIndex.PageIndex);

View File

@ -12529,7 +12529,7 @@ begin
TopLine:=LogCaretXY.Y-(SrcEdit.EditorComponent.LinesInWindow div 2); TopLine:=LogCaretXY.Y-(SrcEdit.EditorComponent.LinesInWindow div 2);
if TopLine<1 then TopLine:=1; if TopLine<1 then TopLine:=1;
if FocusEditor then begin if FocusEditor then begin
MessagesView.ShowOnTop; IDEWindowCreators.ShowForm(MessagesView,true);
SourceEditorManager.ShowActiveWindowOnTop(True); SourceEditorManager.ShowActiveWindowOnTop(True);
end; end;
SrcEdit.EditorComponent.LogicalCaretXY:=LogCaretXY; SrcEdit.EditorComponent.LogicalCaretXY:=LogCaretXY;
@ -12636,7 +12636,7 @@ begin
if LogCaretXY.Y>SrcEdit.EditorComponent.Lines.Count then if LogCaretXY.Y>SrcEdit.EditorComponent.Lines.Count then
LogCaretXY.Y:=SrcEdit.EditorComponent.Lines.Count; LogCaretXY.Y:=SrcEdit.EditorComponent.Lines.Count;
if FocusEditor then begin if FocusEditor then begin
SearchResultsView.ShowOnTop; IDEWindowCreators.ShowForm(SearchResultsView,true);
SourceEditorManager.ShowActiveWindowOnTop(True); SourceEditorManager.ShowActiveWindowOnTop(True);
end; end;
try try
@ -12674,13 +12674,11 @@ begin
else else
MessagesView.MessageTreeView.Images := IDEImages.Images_12; MessagesView.MessageTreeView.Images := IDEImages.Images_12;
if not MessagesView.IsVisible then begin // don't move the messagesview, if it was already visible.
// don't move the messagesview, if it was already visible. IDEWindowCreators.ShowForm(MessagesView,BringToFront);
IDEWindowCreators.ShowForm(MessagesView,true); if BringToFront then
if IDEDockMaster=nil then // the sourcenotebook is more interesting than the messages
// the sourcenotebook is more interesting than the messages SourceEditorManager.ShowActiveWindowOnTop(False);
SourceEditorManager.ShowActiveWindowOnTop(False);
end;
end; end;
procedure TMainIDE.DoShowSearchResultsView(Show: boolean); procedure TMainIDE.DoShowSearchResultsView(Show: boolean);
@ -12715,8 +12713,7 @@ begin
MessagesView.Top-SrcNoteBook.Top)); MessagesView.Top-SrcNoteBook.Top));
if PutOnTop then if PutOnTop then
begin begin
if MessagesView.Parent = nil then IDEWindowCreators.ShowForm(MessagesView,true);
MessagesView.ShowOnTop;
SourceEditorManager.ShowActiveWindowOnTop(False); SourceEditorManager.ShowActiveWindowOnTop(False);
end; end;
end; end;
@ -14091,7 +14088,7 @@ begin
ActiveSrcEdit:=SourceEditorManager.ActiveEditor; ActiveSrcEdit:=SourceEditorManager.ActiveEditor;
end; end;
if ActiveSrcEdit<> nil then begin if ActiveSrcEdit<> nil then begin
MessagesView.ShowOnTop; IDEWindowCreators.ShowForm(MessagesView,true);
with ActiveSrcEdit.EditorComponent do begin with ActiveSrcEdit.EditorComponent do begin
LogicalCaretXY:=ErrorCaret; LogicalCaretXY:=ErrorCaret;
if ErrorTopLine>0 then if ErrorTopLine>0 then

View File

@ -37,7 +37,7 @@ uses
// synedit, codetools // synedit, codetools
SynEditSearch, SynRegExpr, SourceLog, KeywordFuncLists, BasicCodeTools, SynEditSearch, SynRegExpr, SourceLog, KeywordFuncLists, BasicCodeTools,
// IDEIntf // IDEIntf
LazIDEIntf, SrcEditorIntf, MainIntf, IDEWindowIntf, LazIDEIntf, SrcEditorIntf, MainIntf,
// ide // ide
LazarusIDEStrConsts, InputHistory, SearchResultView, Project; LazarusIDEStrConsts, InputHistory, SearchResultView, Project;
@ -902,7 +902,7 @@ begin
ResultsList.Clear; ResultsList.Clear;
ResultsWindow:= ListPage; ResultsWindow:= ListPage;
try try
Show; IDEWindowCreators.ShowForm(SearchResultsView,true);
// update Window Menu, the OnIdle event does not occur while searching // update Window Menu, the OnIdle event does not occur while searching
MainIDEInterface.UpdateWindowMenu; MainIDEInterface.UpdateWindowMenu;
DoSearch; DoSearch;
@ -913,7 +913,7 @@ begin
end; end;
finally finally
SearchResultsView.EndUpdate(ListPage.PageIndex); SearchResultsView.EndUpdate(ListPage.PageIndex);
SearchResultsView.ShowOnTop; IDEWindowCreators.ShowForm(SearchResultsView,false);
end; end;
end; end;

View File

@ -132,19 +132,6 @@ type
TOnFreePkgEditor = procedure(APackage: TLazPackage) of object; TOnFreePkgEditor = procedure(APackage: TLazPackage) of object;
{ TPackageEditorLayout }
TPackageEditorLayout = class
public
Filename: string;
Rectangle: TRect;
constructor Create;
destructor Destroy; override;
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string);
end;
{ TPackageEditorForm } { TPackageEditorForm }
TPackageEditorForm = class(TBasePackageEditor) TPackageEditorForm = class(TBasePackageEditor)
@ -279,7 +266,6 @@ type
TPackageEditors = class TPackageEditors = class
private private
FItems: TList; // list of TPackageEditorForm FItems: TList; // list of TPackageEditorForm
fLayouts: TAVLTree;// tree of TPackageEditorLayout sorted for filename
FOnAddToProject: TOnAddPkgToProject; FOnAddToProject: TOnAddPkgToProject;
FOnCompilePackage: TOnCompilePackage; FOnCompilePackage: TOnCompilePackage;
FOnCreateNewFile: TOnCreateNewPkgFile; FOnCreateNewFile: TOnCreateNewPkgFile;
@ -299,16 +285,11 @@ type
FOnViewPackageSource: TOnViewPackageSource; FOnViewPackageSource: TOnViewPackageSource;
FOnViewPackageToDos: TOnViewPackageToDos; FOnViewPackageToDos: TOnViewPackageToDos;
function GetEditors(Index: integer): TPackageEditorForm; function GetEditors(Index: integer): TPackageEditorForm;
procedure ApplyLayout(AnEditor: TPackageEditorForm);
procedure SaveLayout(AnEditor: TPackageEditorForm);
procedure LoadLayouts;
function GetLayoutConfigFilename: string;
public public
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
function Count: integer; function Count: integer;
procedure Clear; procedure Clear;
procedure SaveLayouts;
procedure Remove(Editor: TPackageEditorForm); procedure Remove(Editor: TPackageEditorForm);
function IndexOfPackage(Pkg: TLazPackage): integer; function IndexOfPackage(Pkg: TLazPackage): integer;
function FindEditor(Pkg: TLazPackage): TPackageEditorForm; function FindEditor(Pkg: TLazPackage): TPackageEditorForm;
@ -398,26 +379,6 @@ var
ImageIndexBinary: integer; ImageIndexBinary: integer;
ImageIndexConflict: integer; ImageIndexConflict: integer;
function CompareLayouts(Data1, Data2: Pointer): integer;
var
Layout1: TPackageEditorLayout;
Layout2: TPackageEditorLayout;
begin
Layout1:=TPackageEditorLayout(Data1);
Layout2:=TPackageEditorLayout(Data2);
Result:=CompareFilenames(Layout1.Filename,Layout2.Filename);
end;
function CompareFilenameWithLayout(Key, Data: Pointer): integer;
var
Filename: String;
Layout: TPackageEditorLayout;
begin
Filename:=String(Key);
Layout:=TPackageEditorLayout(Data);
Result:=CompareFilenames(Filename,Layout.Filename);
end;
procedure RegisterStandardPackageEditorMenuItems; procedure RegisterStandardPackageEditorMenuItems;
var var
AParent: TIDEMenuSection; AParent: TIDEMenuSection;
@ -848,7 +809,6 @@ procedure TPackageEditorForm.PackageEditorFormClose(Sender: TObject;
var CloseAction: TCloseAction); var CloseAction: TCloseAction);
begin begin
if LazPackage=nil then exit; if LazPackage=nil then exit;
PackageEditors.SaveLayout(Self);
end; end;
procedure TPackageEditorForm.PackageEditorFormCloseQuery(Sender: TObject; procedure TPackageEditorForm.PackageEditorFormCloseQuery(Sender: TObject;
@ -1391,7 +1351,6 @@ begin
end; end;
Name:=PackageEditorWindowPrefix+LazPackage.Name; Name:=PackageEditorWindowPrefix+LazPackage.Name;
FLazPackage.Editor:=Self; FLazPackage.Editor:=Self;
PackageEditors.ApplyLayout(Self);
// update components // update components
UpdateAll(true); UpdateAll(true);
// show files // show files
@ -2230,99 +2189,6 @@ begin
Result:=TPackageEditorForm(FItems[Index]); Result:=TPackageEditorForm(FItems[Index]);
end; end;
procedure TPackageEditors.ApplyLayout(AnEditor: TPackageEditorForm);
var
PkgFilename: String;
ANode: TAVLTreeNode;
ARect, ABounds: TRect;
begin
if fLayouts = nil then LoadLayouts;
PkgFilename := AnEditor.LazPackage.Filename;
ANode := fLayouts.FindKey(Pointer(PkgFilename), @CompareFilenameWithLayout);
// find a nice position for the editor
if ANode <> nil then
ARect := TPackageEditorLayout(ANode.Data).Rectangle
else
ARect := Rect(0, 0, 0, 0);
if Screen.ActiveCustomForm <> nil then
ABounds := Screen.ActiveCustomForm.Monitor.BoundsRect
else
ABounds := Screen.PrimaryMonitor.BoundsRect;
if (ARect.Bottom < ARect.Top + 50) or (ARect.Right < ARect.Left + 50) or
(ARect.Bottom > ABounds.Bottom) or (ARect.Right > ABounds.Right) or
(Arect.Top < ABounds.Top) or (ARect.Left < ABounds.Left) then
ARect := CreateNiceWindowPosition(500, 400);
AnEditor.SetBounds(ARect.Left, ARect.Top,
ARect.Right - ARect.Left, ARect.Bottom - ARect.Top);
end;
procedure TPackageEditors.SaveLayout(AnEditor: TPackageEditorForm);
var
PkgFilename: String;
ANode: TAVLTreeNode;
CurLayout: TPackageEditorLayout;
begin
if fLayouts=nil then exit;
PkgFilename:=AnEditor.LazPackage.Filename;
ANode:=fLayouts.FindKey(Pointer(PkgFilename),@CompareFilenameWithLayout);
if ANode<>nil then begin
CurLayout:=TPackageEditorLayout(ANode.Data);
fLayouts.Remove(CurLayout);
end else begin
CurLayout:=TPackageEditorLayout.Create;
end;
CurLayout.Filename:=PkgFilename;
with AnEditor do
CurLayout.Rectangle:=Bounds(Left,Top,Width,Height);
fLayouts.Add(CurLayout);
end;
procedure TPackageEditors.LoadLayouts;
var
Filename: String;
Path: String;
XMLConfig: TXMLConfig;
LayoutCount: Integer;
NewLayout: TPackageEditorLayout;
i: Integer;
begin
if fLayouts=nil then fLayouts:=TAVLTree.Create(@CompareLayouts);
fLayouts.FreeAndClear;
Filename:=GetLayoutConfigFilename;
if not FileExistsUTF8(Filename) then exit;
try
XMLConfig:=TXMLConfig.Create(Filename);
except
DebugLn('ERROR: unable to open package editor layouts "',Filename,'"');
exit;
end;
try
try
Path:='PackageEditorLayouts/';
LayoutCount:=XMLConfig.GetValue(Path+'Count/Value',0);
for i:=1 to LayoutCount do begin
NewLayout:=TPackageEditorLayout.Create;
NewLayout.LoadFromXMLConfig(XMLConfig,Path+'Layout'+IntToStr(i));
if (NewLayout.Filename='') or (fLayouts.Find(NewLayout)<>nil) then
NewLayout.Free
else
fLayouts.Add(NewLayout);
end;
finally
XMLConfig.Free;
end;
except
on E: Exception do begin
DebugLn('ERROR: unable read miscellaneous options from "',Filename,'": ',E.Message);
end;
end;
end;
function TPackageEditors.GetLayoutConfigFilename: string;
begin
Result:=SetDirSeparators(GetPrimaryConfigPath+'/packageeditorlayouts.xml');
end;
constructor TPackageEditors.Create; constructor TPackageEditors.Create;
begin begin
FItems:=TList.Create; FItems:=TList.Create;
@ -2332,10 +2198,6 @@ destructor TPackageEditors.Destroy;
begin begin
Clear; Clear;
FItems.Free; FItems.Free;
if fLayouts<>nil then begin
fLayouts.FreeAndClear;
fLayouts.Free;
end;
inherited Destroy; inherited Destroy;
end; end;
@ -2349,48 +2211,6 @@ begin
FItems.Clear; FItems.Clear;
end; end;
procedure TPackageEditors.SaveLayouts;
var
Filename: String;
XMLConfig: TXMLConfig;
Path: String;
LayoutCount: Integer;
ANode: TAVLTreeNode;
CurLayout: TPackageEditorLayout;
begin
if fLayouts=nil then exit;
Filename:=GetLayoutConfigFilename;
try
XMLConfig:=TXMLConfig.CreateClean(Filename);
except
on E: Exception do begin
DebugLn('ERROR: unable to open miscellaneous options "',Filename,'": ',E.Message);
exit;
end;
end;
try
try
Path:='PackageEditorLayouts/';
LayoutCount:=0;
ANode:=fLayouts.FindLowest;
while ANode<>nil do begin
inc(LayoutCount);
CurLayout:=TPackageEditorLayout(ANode.Data);
CurLayout.SaveToXMLConfig(XMLConfig,Path+'Layout'+IntToStr(LayoutCount));
ANode:=fLayouts.FindSuccessor(ANode);
end;
XMLConfig.SetDeleteValue(Path+'Count/Value',LayoutCount,0);
InvalidateFileStateCache;
XMLConfig.Flush;
finally
XMLConfig.Free;
end;
except
DebugLn('ERROR: unable read miscellaneous options from "',Filename,'"');
end;
end;
procedure TPackageEditors.Remove(Editor: TPackageEditorForm); procedure TPackageEditors.Remove(Editor: TPackageEditorForm);
begin begin
FItems.Remove(Editor); FItems.Remove(Editor);
@ -2584,32 +2404,6 @@ begin
Result:=mrCancel; Result:=mrCancel;
end; end;
{ TPackageEditorLayout }
constructor TPackageEditorLayout.Create;
begin
end;
destructor TPackageEditorLayout.Destroy;
begin
inherited Destroy;
end;
procedure TPackageEditorLayout.LoadFromXMLConfig(XMLConfig: TXMLConfig;
const Path: string);
begin
Filename:=XMLConfig.GetValue(Path+'Filename/Value','');
LoadRect(XMLConfig,Path+'Rect/',Rectangle);
end;
procedure TPackageEditorLayout.SaveToXMLConfig(XMLConfig: TXMLConfig;
const Path: string);
begin
XMLConfig.SetDeleteValue(Path+'Filename/Value',Filename,'');
SaveRect(XMLConfig,Path+'Rect/',Rectangle);
end;
initialization initialization
PackageEditors:=nil; PackageEditors:=nil;

View File

@ -717,8 +717,12 @@ end;
procedure TPkgManager.CreateIDEWindow(Sender: TObject; aFormName: string; var procedure TPkgManager.CreateIDEWindow(Sender: TObject; aFormName: string; var
AForm: TCustomForm; DoDisableAutoSizing: boolean); AForm: TCustomForm; DoDisableAutoSizing: boolean);
var var
PkgName: String; APackageName: String;
NewDependency: TPkgDependency;
APackage: TLazPackage;
LoadResult: TLoadPackageResult;
begin begin
//debugln(['TPkgManager.CreateIDEWindow ',aFormName]);
if SysUtils.CompareText(aFormName,NonModalIDEWindowNames[nmiwPkgGraphExplorer])=0 if SysUtils.CompareText(aFormName,NonModalIDEWindowNames[nmiwPkgGraphExplorer])=0
then begin then begin
DoShowPackageGraph(false); DoShowPackageGraph(false);
@ -728,9 +732,19 @@ begin
end else if SysUtils.CompareText(PackageEditorWindowPrefix, end else if SysUtils.CompareText(PackageEditorWindowPrefix,
copy(aFormName,1,length(PackageEditorWindowPrefix)))=0 copy(aFormName,1,length(PackageEditorWindowPrefix)))=0
then begin then begin
PkgName:=copy(aFormName,length(PackageEditorWindowPrefix)+1,length(aFormName)); APackageName:=copy(aFormName,length(PackageEditorWindowPrefix)+1,length(aFormName));
if (PkgName='') or not IsValidIdent(PkgName) then exit; if (APackageName='') or not IsValidIdent(APackageName) then exit;
NewDependency:=TPkgDependency.Create;
try
NewDependency.PackageName:=APackageName;
LoadResult:=PackageGraph.OpenDependency(NewDependency,false);
if LoadResult<>lprSuccess then exit;
finally
NewDependency.Free;
end;
APackage:=PackageGraph.FindAPackageWithName(APackageName,nil);
if APackage=nil then exit;
AForm:=PackageEditors.OpenEditor(APackage);
end; end;
end; end;
@ -1966,7 +1980,7 @@ end;
procedure TPkgManager.SaveSettings; procedure TPkgManager.SaveSettings;
begin begin
PackageEditors.SaveLayouts;
end; end;
function TPkgManager.GetDefaultSaveDirectoryForFile(const Filename: string function TPkgManager.GetDefaultSaveDirectoryForFile(const Filename: string
@ -2390,7 +2404,7 @@ begin
// open a package editor // open a package editor
CurEditor:=PackageEditors.OpenEditor(NewPackage); CurEditor:=PackageEditors.OpenEditor(NewPackage);
CurEditor.Show; IDEWindowCreators.ShowForm(CurEditor,true);
Result:=DoSavePackage(NewPackage,[psfSaveAs]); Result:=DoSavePackage(NewPackage,[psfSaveAs]);
end; end;
@ -2420,8 +2434,8 @@ begin
// open a package editor // open a package editor
CurEditor:=PackageEditors.OpenEditor(APackage); CurEditor:=PackageEditors.OpenEditor(APackage);
CurEditor.ShowOnTop; IDEWindowCreators.ShowForm(CurEditor,true);
// add to recent packages // add to recent packages
if (pofAddToRecent in Flags) then begin if (pofAddToRecent in Flags) then begin
AFilename:=APackage.Filename; AFilename:=APackage.Filename;
@ -2604,7 +2618,7 @@ begin
if (APackage.Editor=nil) and APackage.Modified if (APackage.Editor=nil) and APackage.Modified
and (APackage.UserIgnoreChangeStamp<>APackage.ChangeStamp) then begin and (APackage.UserIgnoreChangeStamp<>APackage.ChangeStamp) then begin
Editor:=PackageEditors.OpenEditor(APackage); Editor:=PackageEditors.OpenEditor(APackage);
Editor.Visible:=true; IDEWindowCreators.ShowForm(Editor,false);
end; end;
end; end;
end; end;