ide: implement Copy to Clipboard behavior in Search results dialog by Flávio Etrusco (issue #0015851)

git-svn-id: trunk@23809 -
This commit is contained in:
paul 2010-03-01 04:29:29 +00:00
parent a204eebb53
commit eb52aebd64
3 changed files with 76 additions and 2 deletions

View File

@ -280,6 +280,9 @@ resourcestring
lisCopyAllMessagesToClipboard = 'Copy all messages to clipboard';
lisCopyAllAndHiddenMessagesToClipboard = 'Copy all and hidden messages '
+'to clipboard';
lisCopyItemToClipboard = 'Copy item to clipboard';
lisCopySelectedItemToClipboard = 'Copy selected items to clipboard';
lisCopyAllItemsToClipboard = 'Copy all items to clipboard';
lisSaveAllMessagesToFile = 'Save all messages to file';
lisMVDocking = 'Docking';
lisMenuViewSearchResults = 'Search Results';

View File

@ -254,4 +254,20 @@ object SearchResultsView: TSearchResultsView
0000000000000000000000000000
}
end
object popList: TPopupMenu
left = 190
top = 133
object mniCopyItem: TMenuItem
Caption = 'Copy Item'
OnClick = mniCopyItemClick
end
object mniCopyAll: TMenuItem
Caption = 'Copy All'
OnClick = mniCopyAllClick
end
object mniCopySelected: TMenuItem
Caption = 'Copy Selected'
OnClick = mniCopySelectedClick
end
end
end

View File

@ -38,9 +38,9 @@ interface
uses
Classes, SysUtils, LCLProc, Forms, Controls, Graphics, Dialogs,
ComCtrls, ExtCtrls, StdCtrls, Buttons, LCLType, LCLIntf,
ComCtrls, ExtCtrls, StdCtrls, Buttons, LCLType, LCLIntf, Menus,
IDEOptionDefs, LazarusIDEStrConsts, EnvironmentOpts, EditorOptions, InputHistory,
IDEProcs, FindInFilesDlg, Project, MainIntf;
IDEProcs, FindInFilesDlg, Project, MainIntf, Clipbrd;
type
{ TLazSearchMatchPos }
@ -129,6 +129,10 @@ type
{ TSearchResultsView }
TSearchResultsView = class(TForm)
mniCopySelected: TMenuItem;
mniCopyAll: TMenuItem;
mniCopyItem: TMenuItem;
popList: TPopupMenu;
SearchInListEdit: TEdit;
ImageList: TImageList;
ResultsNoteBook: TNotebook;
@ -142,6 +146,9 @@ type
procedure ClosePageButtonClick(Sender: TObject);
procedure Form1Create(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure mniCopyAllClick(Sender: TObject);
procedure mniCopyItemClick(Sender: TObject);
procedure mniCopySelectedClick(Sender: TObject);
procedure TreeViewKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ResultsNoteBookClosetabclicked(Sender: TObject);
procedure SearchAgainButtonClick(Sender: TObject);
@ -225,6 +232,22 @@ begin
Result := True;
end;
function GetTreeSelectedItemsAsText(ATreeView: TCustomTreeView): string;
var
sl: TStringList;
node: TTreeNode;
begin
sl:=TStringList.Create;
node := ATreeView.GetFirstMultiSelected;
while assigned(node) do
begin
sl.Add(node.Text);
node := node.GetNextMultiSelected;
end;
Result:=sl.Text;
sl.Free;
end;
procedure TSearchResultsView.Form1Create(Sender: TObject);
var
ALayout: TIDEWindowLayout;
@ -251,6 +274,10 @@ begin
fOnSelectionChanged:= nil;
ShowHint:= True;
fMouseOverIndex:= -1;
mniCopyItem.Caption := lisCopyItemToClipboard;
mniCopySelected.Caption := lisCopySelectedItemToClipboard;
mniCopyAll.Caption := lisCopyAllItemsToClipboard;
end;//Create
procedure TSearchResultsView.FormKeyDown(Sender: TObject; var Key: Word;
@ -263,6 +290,32 @@ begin
end;
end;
procedure TSearchResultsView.mniCopyAllClick(Sender: TObject);
var
sl: TStrings;
begin
sl := (popList.PopupComponent as TLazSearchResultTV).ItemsAsStrings;
Clipboard.AsText := sl.Text;
sl.Free;
end;
procedure TSearchResultsView.mniCopyItemClick(Sender: TObject);
var
tv: TCustomTreeView;
node: TTreeNode;
begin
tv := popList.PopupComponent as TCustomTreeView;
with tv.ScreenToClient(popList.PopupPoint) do
node := tv.GetNodeAt(X, Y);
if node <> nil then
Clipboard.AsText := node.Text;
end;
procedure TSearchResultsView.mniCopySelectedClick(Sender: TObject);
begin
Clipboard.AsText := GetTreeSelectedItemsAsText(popList.PopupComponent as TCustomTreeView);
end;
procedure TSearchResultsView.ClosePageButtonClick(Sender: TObject);
begin
ClosePage(ResultsNoteBook.PageIndex);
@ -770,6 +823,8 @@ begin
OnMouseWheel:= @LazTVMouseWheel;
ShowHint:= true;
RowSelect := True;
Options := Options + [tvoAllowMultiselect];
PopupMenu := popList;
NewTreeView.Canvas.Brush.Color:= clWhite;
end;//with
end;//if