IDE: SearchResultView, fix form hiding with AnchorDocking and implement shortcut for closing page. Issue #19939, patch from Flávio Etrusco

git-svn-id: trunk@31940 -
This commit is contained in:
juha 2011-08-10 23:19:47 +00:00
parent d993bf9d70
commit f2de67ee6b
2 changed files with 61 additions and 16 deletions

View File

@ -8,6 +8,7 @@ object SearchResultsView: TSearchResultsView
ClientHeight = 273 ClientHeight = 273
ClientWidth = 799 ClientWidth = 799
KeyPreview = True KeyPreview = True
OnClose = FormClose
OnCreate = Form1Create OnCreate = Form1Create
OnKeyDown = FormKeyDown OnKeyDown = FormKeyDown
Position = poScreenCenter Position = poScreenCenter
@ -272,4 +273,14 @@ object SearchResultsView: TSearchResultsView
OnClick = mniCopySelectedClick OnClick = mniCopySelectedClick
end end
end end
object ActionList: TActionList
Images = ImageList
left = 93
top = 133
object actClosePage: TAction
ImageIndex = 1
OnExecute = ClosePageButtonClick
ShortCut = 16499
end
end
end end

View File

@ -40,7 +40,7 @@ uses
Classes, SysUtils, LCLProc, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, LCLProc, Forms, Controls, Graphics, Dialogs,
ComCtrls, ExtCtrls, StdCtrls, Buttons, LCLType, LCLIntf, Menus, strutils, ComCtrls, ExtCtrls, StdCtrls, Buttons, LCLType, LCLIntf, Menus, strutils,
IDEWindowIntf, IDEOptionDefs, LazarusIDEStrConsts, EnvironmentOpts, IDEWindowIntf, IDEOptionDefs, LazarusIDEStrConsts, EnvironmentOpts,
InputHistory, IDEProcs, Project, MainIntf, Clipbrd; InputHistory, IDEProcs, Project, MainIntf, Clipbrd, ActnList, IDECommands;
type type
{ TLazSearchMatchPos } { TLazSearchMatchPos }
@ -119,7 +119,7 @@ type
property Filtered: Boolean read fFiltered write fFiltered; property Filtered: Boolean read fFiltered write fFiltered;
property SearchInListPhrases: string read FSearchInListPhrases write FSearchInListPhrases; property SearchInListPhrases: string read FSearchInListPhrases write FSearchInListPhrases;
property UpdateItems: TStrings read fUpdateStrings write fUpdateStrings; property UpdateItems: TStrings read fUpdateStrings write fUpdateStrings;
property UpdateState: boolean read fUpdating; property Updating: boolean read fUpdating;
property Skipped: integer read FSkipped write SetSkipped; property Skipped: integer read FSkipped write SetSkipped;
property Items; property Items;
function ItemsAsStrings: TStrings; function ItemsAsStrings: TStrings;
@ -129,6 +129,8 @@ type
{ TSearchResultsView } { TSearchResultsView }
TSearchResultsView = class(TForm) TSearchResultsView = class(TForm)
actClosePage: TAction;
ActionList: TActionList;
mniCopySelected: TMenuItem; mniCopySelected: TMenuItem;
mniCopyAll: TMenuItem; mniCopyAll: TMenuItem;
mniCopyItem: TMenuItem; mniCopyItem: TMenuItem;
@ -145,6 +147,7 @@ type
ResetResultsButton: TToolButton; ResetResultsButton: TToolButton;
procedure ClosePageButtonClick(Sender: TObject); procedure ClosePageButtonClick(Sender: TObject);
procedure Form1Create(Sender: TObject); procedure Form1Create(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure mniCopyAllClick(Sender: TObject); procedure mniCopyAllClick(Sender: TObject);
procedure mniCopyItemClick(Sender: TObject); procedure mniCopyItemClick(Sender: TObject);
@ -274,6 +277,8 @@ begin
end; end;
procedure TSearchResultsView.Form1Create(Sender: TObject); procedure TSearchResultsView.Form1Create(Sender: TObject);
var
CloseCommand: TIDECommand;
begin begin
FMaxItems:=50000; FMaxItems:=50000;
@ -288,6 +293,15 @@ begin
ForwardSearchButton.Hint:=rsGoToTheNextItemInTheSearchList; ForwardSearchButton.Hint:=rsGoToTheNextItemInTheSearchList;
ResetResultsButton.Hint:=rsResetFilter; ResetResultsButton.Hint:=rsResetFilter;
SearchInListEdit.Hint:=rsEnterOneOrMorePhrasesThatYouWantToSearchOrFilterIn; SearchInListEdit.Hint:=rsEnterOneOrMorePhrasesThatYouWantToSearchOrFilterIn;
CloseCommand := IDECommandList.FindIDECommand(ecClose);
if CloseCommand <> nil then
begin
if CloseCommand.AsShortCut <> 0 then
actClosePage.ShortCut:=CloseCommand.AsShortCut;
if (CloseCommand.ShortcutB.Key1 <> 0) and (CloseCommand.ShortcutB.Key2 = 0) then
actClosePage.SecondaryShortCuts.Append(ShortCutToText(
ShortCut(CloseCommand.ShortcutB.Key1, CloseCommand.ShortcutB.Shift1)));
end;
Name := NonModalIDEWindowNames[nmiwSearchResultsViewName]; Name := NonModalIDEWindowNames[nmiwSearchResultsViewName];
fOnSelectionChanged:= nil; fOnSelectionChanged:= nil;
@ -299,10 +313,29 @@ begin
mniCopyAll.Caption := lisCopyAllItemsToClipboard; mniCopyAll.Caption := lisCopyAllItemsToClipboard;
end;//Create end;//Create
procedure TSearchResultsView.FormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
// Using a dock manager...
if Parent<>nil then
begin
CloseAction := caNone;
//todo: helper function in DockManager or IDEDockMaster for closing forms.
// Only close the window if it's floating.
// AnchorDocking doesn't seem to initialize 'FloatingDockSiteClass' so we can't just check 'Floating'.
// Also, AnchorDocking use nested forms, so the check for HostDockSite.Parent.
if Assigned(HostDockSite) and (HostDockSite.DockClientCount <= 1)
and (HostDockSite is TCustomForm) and (HostDockSite.Parent = nil) then
begin
TCustomForm(HostDockSite).Close;
end;
end;
end;
procedure TSearchResultsView.FormKeyDown(Sender: TObject; var Key: Word; procedure TSearchResultsView.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState); Shift: TShiftState);
begin begin
if (Key = VK_ESCAPE) and (Parent=nil) then if (Key = VK_ESCAPE) then
begin begin
Key := VK_UNKNOWN; Key := VK_UNKNOWN;
Close; Close;
@ -606,7 +639,7 @@ begin
CurrentTV:=GetTreeView(APageIndex); CurrentTV:=GetTreeView(APageIndex);
if Assigned(CurrentTV) then if Assigned(CurrentTV) then
begin begin
if CurrentTV.UpdateState then begin if CurrentTV.Updating then begin
if CurrentTV.UpdateItems.Count>=MaxItems then begin if CurrentTV.UpdateItems.Count>=MaxItems then begin
CurrentTV.Skipped:=CurrentTV.Skipped+1; CurrentTV.Skipped:=CurrentTV.Skipped+1;
exit; exit;
@ -628,7 +661,7 @@ begin
SearchPos.ShownFilename:=SearchPos.Filename; SearchPos.ShownFilename:=SearchPos.Filename;
ShownText:=CurrentTV.BeautifyLine(SearchPos); ShownText:=CurrentTV.BeautifyLine(SearchPos);
LastPos:=nil; LastPos:=nil;
if CurrentTV.UpdateState then begin if CurrentTV.Updating then begin
if (CurrentTV.UpdateItems.Count>0) if (CurrentTV.UpdateItems.Count>0)
and (CurrentTV.UpdateItems.Objects[CurrentTV.UpdateItems.Count-1] is TLazSearchMatchPos) then and (CurrentTV.UpdateItems.Objects[CurrentTV.UpdateItems.Count-1] is TLazSearchMatchPos) then
LastPos:=TLazSearchMatchPos(CurrentTV.UpdateItems.Objects[CurrentTV.UpdateItems.Count-1]); LastPos:=TLazSearchMatchPos(CurrentTV.UpdateItems.Objects[CurrentTV.UpdateItems.Count-1]);
@ -643,7 +676,7 @@ begin
LastPos := LastPos.NextInThisLine; LastPos := LastPos.NextInThisLine;
LastPos.NextInThisLine:=SearchPos LastPos.NextInThisLine:=SearchPos
end end
else if CurrentTV.UpdateState then else if CurrentTV.Updating then
CurrentTV.UpdateItems.AddObject(ShownText, SearchPos) CurrentTV.UpdateItems.AddObject(ShownText, SearchPos)
else else
CurrentTV.AddNode(ShownText, SearchPos); CurrentTV.AddNode(ShownText, SearchPos);
@ -705,15 +738,16 @@ procedure TSearchResultsView.ClosePage(PageIndex: integer);
var var
CurrentTV: TLazSearchResultTV; CurrentTV: TLazSearchResultTV;
begin begin
if (PageIndex<0) or (PageIndex>=ResultsNoteBook.PageCount) then exit; if (PageIndex>=0) and (PageIndex<ResultsNoteBook.PageCount) then
begin
CurrentTV:= GetTreeView(PageIndex); CurrentTV:= GetTreeView(PageIndex);
if Assigned(CurrentTV) and CurrentTV.UpdateState then if Assigned(CurrentTV) and CurrentTV.Updating then
exit; exit;
ResultsNoteBook.Pages[PageIndex].Free; ResultsNoteBook.Pages[PageIndex].Free;
end;
if ResultsNoteBook.PageCount = 0 then if ResultsNoteBook.PageCount = 0 then
Hide; Close;
end; end;
{Sets the Items from the treeview on the currently selected page in the TNoteBook} {Sets the Items from the treeview on the currently selected page in the TNoteBook}
@ -726,7 +760,7 @@ begin
CurrentTV:= GetTreeView(Index); CurrentTV:= GetTreeView(Index);
if Assigned(CurrentTV) then if Assigned(CurrentTV) then
begin begin
if CurrentTV.UpdateState then if CurrentTV.Updating then
CurrentTV.UpdateItems.Assign(Value) CurrentTV.UpdateItems.Assign(Value)
else else
CurrentTV.Items.Assign(Value); CurrentTV.Items.Assign(Value);
@ -743,7 +777,7 @@ begin
CurrentTV:= GetTreeView(Index); CurrentTV:= GetTreeView(Index);
if Assigned(CurrentTV) then if Assigned(CurrentTV) then
begin begin
if CurrentTV.UpdateState then if CurrentTV.Updating then
result:= CurrentTV.UpdateItems result:= CurrentTV.UpdateItems
else else
Result := CurrentTV.ItemsAsStrings; Result := CurrentTV.ItemsAsStrings;
@ -762,7 +796,7 @@ var
state: Boolean; state: Boolean;
begin begin
CurrentTV:= GetTreeView(ResultsNoteBook.PageIndex); CurrentTV:= GetTreeView(ResultsNoteBook.PageIndex);
state := Assigned(CurrentTV) and not CurrentTV.UpdateState; state := Assigned(CurrentTV) and not CurrentTV.Updating;
SearchAgainButton.Enabled := state; SearchAgainButton.Enabled := state;
ClosePageButton.Enabled := state; ClosePageButton.Enabled := state;
FilterButton.Enabled := state; FilterButton.Enabled := state;