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,
StdCodeTools, SourceLog,
// IDEIntf
SrcEditorIntf, IDEMsgIntf, IDEDialogs, LazConfigStorage, PackageIntf,
TextTools, IDECommands, LazIDEIntf,
IDEWindowIntf, SrcEditorIntf, IDEMsgIntf, IDEDialogs, LazConfigStorage,
PackageIntf, TextTools, IDECommands, LazIDEIntf,
// IDE
Project, DialogProcs, PackageSystem, PackageDefs, LazarusIDEStrConsts,
IDEOptionDefs, MsgQuickFixes, BasePkgManager, AddToProjectDlg,
@ -3143,7 +3143,7 @@ begin
CreateCodeBrowser;
CodeBrowserView.SetScopeToCurUnitOwner(true,true);
CodeBrowserView.SetFilterToSimpleIdentifier(Identifier);
CodeBrowserView.ShowOnTop;
IDEWindowCreators.ShowForm(CodeBrowserView,true);
end;
end;

View File

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

View File

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

View File

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

View File

@ -132,19 +132,6 @@ type
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 = class(TBasePackageEditor)
@ -279,7 +266,6 @@ type
TPackageEditors = class
private
FItems: TList; // list of TPackageEditorForm
fLayouts: TAVLTree;// tree of TPackageEditorLayout sorted for filename
FOnAddToProject: TOnAddPkgToProject;
FOnCompilePackage: TOnCompilePackage;
FOnCreateNewFile: TOnCreateNewPkgFile;
@ -299,16 +285,11 @@ type
FOnViewPackageSource: TOnViewPackageSource;
FOnViewPackageToDos: TOnViewPackageToDos;
function GetEditors(Index: integer): TPackageEditorForm;
procedure ApplyLayout(AnEditor: TPackageEditorForm);
procedure SaveLayout(AnEditor: TPackageEditorForm);
procedure LoadLayouts;
function GetLayoutConfigFilename: string;
public
constructor Create;
destructor Destroy; override;
function Count: integer;
procedure Clear;
procedure SaveLayouts;
procedure Remove(Editor: TPackageEditorForm);
function IndexOfPackage(Pkg: TLazPackage): integer;
function FindEditor(Pkg: TLazPackage): TPackageEditorForm;
@ -398,26 +379,6 @@ var
ImageIndexBinary: 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;
var
AParent: TIDEMenuSection;
@ -848,7 +809,6 @@ procedure TPackageEditorForm.PackageEditorFormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
if LazPackage=nil then exit;
PackageEditors.SaveLayout(Self);
end;
procedure TPackageEditorForm.PackageEditorFormCloseQuery(Sender: TObject;
@ -1391,7 +1351,6 @@ begin
end;
Name:=PackageEditorWindowPrefix+LazPackage.Name;
FLazPackage.Editor:=Self;
PackageEditors.ApplyLayout(Self);
// update components
UpdateAll(true);
// show files
@ -2230,99 +2189,6 @@ begin
Result:=TPackageEditorForm(FItems[Index]);
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;
begin
FItems:=TList.Create;
@ -2332,10 +2198,6 @@ destructor TPackageEditors.Destroy;
begin
Clear;
FItems.Free;
if fLayouts<>nil then begin
fLayouts.FreeAndClear;
fLayouts.Free;
end;
inherited Destroy;
end;
@ -2349,48 +2211,6 @@ begin
FItems.Clear;
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);
begin
FItems.Remove(Editor);
@ -2584,32 +2404,6 @@ begin
Result:=mrCancel;
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
PackageEditors:=nil;

View File

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