home *** CD-ROM | disk | FTP | other *** search
- unit FExplorer; // Copyright ⌐ 1996-2001 Plasmatech Software Design. All rights reserved.
- {
- Shell Control Pack - Demo Program
- Version 1.6
-
- This file is part of the Shell Control Pack demonstration program.
- It implements the mini-explorer form.
-
- History
- ===================================================================================================
- V1.6 2Jul01 Delphi 6 release. No changes.
- V1.5c 30Mar01 No changes.
- V1.5b 12Dec00 No changes.
- V1.5a 14May00 No changes.
- V1.5 3Mar00 C++Builder 5 release. No changes.
- V1.4a 5Nov99 No significant changes.
- V1.4 14Sep99 Delphi 5 release. No changes.
- V1.3h 29Mar99 No changes.
- V1.3g 1Dec98 No changes.
- V1.3f 12Jul98 Delphi 4 release. No changes.
- V1.3e 22Apr98 No changes.
- V1.3d 18Apr98 No changes.
- V1.3c 16Mar98 No changes.
- V1.3b 7Feb98 No changes.
- V1.3a 7Jan98 No changes.
- V1.3 28Nov97 Added internationalisation code.
- V1.2b 12Oct97 No changes.
- V1.2a 5Oct97 No significant changes.
- V1.2 6Sep97 No significant changes.
- V1.1a 6Jul97 No changes.
- V1.1 26Jun97 Added custom draw examples and menu for TPTListView.
- V1.0c 31May97 No significant changes.
- V1.0b 17May97 Minor fixes and Delphi 3 support.
- V1.0a 1May97 No significant changes.
- V1.0 21Apr97 Released version 1.0
- }
-
- {$INCLUDE PTCompVer.inc}
-
- {$RANGECHECKS OFF} {$OVERFLOWCHECKS OFF} {$WRITEABLECONST OFF}
- {$BOOLEVAL OFF} {$EXTENDEDSYNTAX ON} {$TYPEDADDRESS ON}
-
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, Menus, StdCtrls, ExtCtrls, Buttons, ShellApi,
- UPTShellControls, UPTSysFolderDlg, UPTSplitter, UPTShellUtils,
- UPTFrame, UPTShell95, UPTImageCombo, UPTTreeList, UPTShConsts;
-
- type
- TFrmExplorer = class(TForm)
- StatusBar1: TStatusBar;
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- CloseMitm: TMenuItem;
- DetailsBtn: TSpeedButton;
- ListBtn: TSpeedButton;
- SmallIconsBtn: TSpeedButton;
- LargeIconsBtn: TSpeedButton;
- F1: TMenuItem;
- TreeSelectPathnameMitm: TMenuItem;
- TreeRefreshMitm: TMenuItem;
- PTSysFolderDlg1: TPTSysFolderDlg;
- PTSplitter1: TPTSplitter;
- PTShellList1: TPTShellList;
- N4: TMenuItem;
- TreeViewSelectedPathnameMitm: TMenuItem;
- PTShellCombo1: TPTShellCombo;
- UpOneLevelBtn: TSpeedButton;
- PopupMenu1: TPopupMenu;
- Item11: TMenuItem;
- Item21: TMenuItem;
- ListPopup: TPopupMenu;
- LargeIconsMitm: TMenuItem;
- SmalliconsMItm: TMenuItem;
- ListMitm: TMenuItem;
- DetailsMitm: TMenuItem;
- View1Submenu: TMenuItem;
- LargeIcons2Mitm: TMenuItem;
- Smallicons2Mitm: TMenuItem;
- List2Mitm: TMenuItem;
- Details2Mitm: TMenuItem;
- Highlightexecutables1: TMenuItem;
- Dimreadonlyfoldersintree1: TMenuItem;
- Edit1: TMenuItem;
- SelectAll1: TMenuItem;
- Paste1: TMenuItem;
- N2: TMenuItem;
- InvertSelection1: TMenuItem;
- Cut1: TMenuItem;
- Copy1: TMenuItem;
- Cantundo1: TMenuItem;
- N3: TMenuItem;
- New1Submenu: TMenuItem;
- N5: TMenuItem;
- NewFolder1Mitm: TMenuItem;
- View2Submenu: TMenuItem;
- N6: TMenuItem;
- New2Submenu: TMenuItem;
- NewFolder2Mitm: TMenuItem;
- N7: TMenuItem;
- Properties1Mitm: TMenuItem;
- Paste2Mitm: TMenuItem;
- N8: TMenuItem;
- CustomDraw1: TMenuItem;
- Hotkeys1: TMenuItem;
- F11Mitm: TMenuItem;
- DeleteBtn: TSpeedButton;
- PTShellTree1: TPTShellTree;
- PTGroup1: TPTGroup;
- procedure ViewBtnClick(Sender: TObject);
- procedure PTShellTree1Change(Sender: TObject; Node: TTreeNode);
- procedure CloseMitmClick(Sender: TObject);
- procedure TreeRefreshMitmClick(Sender: TObject);
- procedure TreeSelectPathnameMitmClick(Sender: TObject);
- procedure FileSwapPanesMitmClick(Sender: TObject);
- procedure TreeViewSelectedPathnameMitmClick(Sender: TObject);
- procedure UpOneLevelBtnClick(Sender: TObject);
- procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure FormCreate(Sender: TObject);
- procedure PTShellList1PopupHint(aSender: TObject; const hint: string);
- procedure Highlightexecutables1Click(Sender: TObject);
- procedure PTShellList1CustomDrawSh(aSender: TObject;
- aCD: TPTCustomDraw; aItem: TListItem; aData: TPTShListData);
- procedure Dimreadonlyfoldersintree1Click(Sender: TObject);
- procedure PTShellTree1CustomDrawSh(aSender: TObject;
- aCD: TPTCustomDraw; aNode: TTreeNode; aData: TPTShTreeData);
- procedure SelectAll1Click(Sender: TObject);
- procedure NewFolder1MitmClick(Sender: TObject);
- procedure Paste1Click(Sender: TObject);
- procedure Properties1MitmClick(Sender: TObject);
- procedure InvertSelection1Click(Sender: TObject);
- procedure F11MitmClick(Sender: TObject);
- procedure DeleteBtnClick(Sender: TObject);
- procedure PTShellTree1Edited(Sender: TObject; Node: TTreeNode;
- var S: String);
- private
- mfHighlightExe: Boolean;
- mfDimReadOnly: Boolean;
- procedure OnAppHint(sender: TObject);
- procedure LoadStrings;
- public
- { Public declarations }
- end;
-
- var
- FrmExplorer: TFrmExplorer;
-
- implementation
- uses TypInfo;
- {$R *.DFM}
-
- procedure TFrmExplorer.ViewBtnClick(Sender: TObject);
- var tag: Integer;
- procedure CheckItems( a: array of TComponent; prop: ShortString );
- var i: Integer;
- begin
- for i := Low(a) to High(a) do
- SetOrdProp( a[i], GetPropInfo(a[i].ClassInfo, prop), Integer(a[i].Tag=tag) );
- end;
- begin
- tag := (sender as TComponent).Tag;
- CheckItems( [LargeIconsMitm, SmallIconsMitm, ListMitm, DetailsMitm], 'Checked' );
- CheckItems( [LargeIcons2Mitm, SmallIcons2Mitm, List2Mitm, Details2Mitm], 'Checked' );
- CheckItems( [LargeIconsBtn, SmallIconsBtn, ListBtn, DetailsBtn], 'Down' );
- PTShellList1.ViewStyle := TViewStyle(tag);
- end;
-
- procedure TFrmExplorer.PTShellTree1Change(Sender: TObject; Node: TTreeNode);
- begin
- StatusBar1.SimpleText := PTShellTree1.SelectedPathName;
- UpOneLevelBtn.Enabled := Assigned(PTShellTree1.Selected) and (PTShellTree1.Selected.Parent <> nil);
- end;
-
- procedure TFrmExplorer.CloseMitmClick(Sender: TObject);
- begin Close; end;
-
- procedure TFrmExplorer.TreeRefreshMitmClick(Sender: TObject);
- begin
- PTShellTree1.RefreshNodes;
-
- PTShellList1.FillItems;
- // We don't call RefreshItems because we want the resulting list sorted
- end;
-
- procedure TFrmExplorer.TreeSelectPathnameMitmClick(Sender: TObject);
- begin
- PTSysFolderDlg1.Title := 'Select a folder to highlight.';
- if PTSysFolderDlg1.Execute then
- PTShellCombo1.SelectedFolder.IdList := PTSysFolderDlg1.FolderIdList;
- end;
-
- procedure TFrmExplorer.FileSwapPanesMitmClick(Sender: TObject);
- begin PTSplitter1.SwapPanes(TRUE); end;
-
- procedure TFrmExplorer.TreeViewSelectedPathnameMitmClick(Sender: TObject);
- var p: String;
- begin
- p := PTShellTree1.SelectedPathname;
- if p = '' then
- ShowMessage( 'The selected item is not part of the filesystem.' )
- else
- ShowMessage( 'Selected Item: '+p );
- end;
-
- procedure TFrmExplorer.UpOneLevelBtnClick(Sender: TObject);
- begin
- PTShellTree1.GoUp(1);
- end;
-
- procedure TFrmExplorer.DeleteBtnClick(Sender: TObject);
- begin
- if PTShellTree1.Focused then
- PTShellTree1.DoCommandForNode( PTShellTree1.Selected, PTSH_CMDS_DELETE )
- else
- PTShellList1.DoCommandForAllSelected( PTSH_CMDS_DELETE );
- end;
-
- procedure TFrmExplorer.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- begin
- if Key=VK_ESCAPE then Close;
- inherited;
- end;
-
- procedure TFrmExplorer.FormCreate(Sender: TObject);
- {$IFDEF VCL30PLUS}
- var
- i: Integer;
- {$ENDIF}
- begin
- Application.OnHint := OnAppHint;
- LoadStrings;
-
- {$IFDEF VCL30PLUS}
- for i := 0 to PTGroup1.ControlCount-1 do
- if PTGroup1.Controls[i] is TSpeedButton then
- TSpeedButton(PTGroup1.Controls[i]).Flat := TRUE;
- {$ENDIF}
- end;
-
- procedure TFrmExplorer.OnAppHint(sender: TObject);
- begin
- StatusBar1.Panels[0].Text := Application.Hint;
- end;
-
- procedure TFrmExplorer.LoadStrings;
- procedure SetMenuItems( caption, hint: String; arr: array of TMenuItem );
- var i: Integer;
- begin
- for i := Low(arr) to High(arr) do
- begin
- if caption<>'' then arr[i].Caption := caption;
- if hint<>'' then arr[i].Hint := hint;
- end;
- end;
- begin
- // This procedure loads some translated strings. There are a set of strings available with the Shell
- // Control Pack that are generally useful to an explorer-like application.
- UpOneLevelBtn.Hint := PTLoadStr(SUpOneLevelHint);
- LargeIconsBtn.Hint := PTLoadStr(SViewLargeIconsHint) + '|' + PTLoadStr(SViewLargeIconsContext);
- SmallIconsBtn.Hint := PTLoadStr(SViewSmallIconsHint) + '|' + PTLoadStr(SViewSmallIconsContext);
- ListBtn.Hint := PTLoadStr(SViewListHint) + '|' + PTLoadStr(SViewListContext);
- DetailsBtn.Hint := PTLoadStr(SViewDetailsHint) + '|' + PTLoadStr(SViewDetailsContext);
-
- SetMenuItems( PTLoadStr(SEditPasteMenu), PTLoadStr(SPasteContext), [Paste2Mitm] );
- SetMenuItems( PTLoadStr(SPropertiesMenu), PTLoadStr(SPropertiesContext), [Properties1Mitm] );
- SetMenuItems( PTLoadStr(SViewLargeIconsMenu), PTLoadStr(SViewLargeIconsContext), [LargeIconsMitm, LargeIcons2Mitm] );
- SetMenuItems( PTLoadStr(SViewSmallIconsMenu), PTLoadStr(SViewSmallIconsContext), [SmallIconsMitm, SmallIcons2Mitm] );
- SetMenuItems( PTLoadStr(SViewListMenu), PTLoadStr(SViewListContext), [ListMitm, List2Mitm] );
- SetMenuItems( PTLoadStr(SViewDetailsMenu), PTLoadStr(SViewDetailsContext), [DetailsMitm, Details2Mitm] );
- SetMenuItems( PTLoadStr(SViewMenu), PTLoadStr(SViewContext), [View1Submenu, View2Submenu] );
- SetMenuItems( PTLoadStr(SNewMenu), PTLoadStr(SNewContext), [New1Submenu, New2Submenu] );
- SetMenuItems( PTLoadStr(SNewFolderMenu), PTLoadStr(SNewFolderContext), [NewFolder1Mitm, NewFolder2Mitm] );
- end;
-
- procedure TFrmExplorer.PTShellList1PopupHint(aSender: TObject; const hint: string);
- begin
- Application.Hint := hint;
- end;
-
- procedure TFrmExplorer.Highlightexecutables1Click(Sender: TObject);
- begin
- mfHighlightExe := not mfHighlightExe;
- Highlightexecutables1.Checked := mfHighlightExe;
- PTShellList1.Invalidate;
- end;
-
- procedure TFrmExplorer.Dimreadonlyfoldersintree1Click(Sender: TObject);
- begin
- mfDimReadOnly := not mfDimReadOnly;
- Dimreadonlyfoldersintree1.Checked := mfDimReadOnly;
- PTShellTree1.Invalidate;
- PTShellList1.Invalidate;
- end;
-
- procedure TFrmExplorer.PTShellList1CustomDrawSh(aSender: TObject;
- aCD: TPTCustomDraw; aItem: TListItem; aData: TPTShListData);
- var ext: ShortString;
- begin
- if mfHighlightExe then
- begin
- ext := AnsiLowercase(ExtractFileExt(aData.FileName));
- if (ext = '.exe') or (ext = '.com') or (ext = '.bat') or (ext = '.pif') then
- begin
- aCD.Font.Style := [fsBold];
- aCD.Font.Color := clBlue;
- end;
- end;
-
- if mfDimReadOnly and not aData.Editable then
- aCD.Font.Color := clBtnFace;
- end;
-
- procedure TFrmExplorer.PTShellTree1CustomDrawSh(aSender: TObject;
- aCD: TPTCustomDraw; aNode: TTreeNode; aData: TPTShTreeData);
- begin
- if mfDimReadOnly and not aNode.Selected and not aNode.DropTarget then
- if not aData.Editable then
- aCD.Font.Color := clBtnFace;
- end;
-
- procedure TFrmExplorer.SelectAll1Click(Sender: TObject);
- begin PTShellList1.SelectAll; end;
-
- procedure TFrmExplorer.NewFolder1MitmClick(Sender: TObject);
- begin PTShellList1.CreateNewFolder( TRUE ); end;
-
- procedure TFrmExplorer.Paste1Click(Sender: TObject);
- begin PTShellList1.DoCommandForFolder( PTSH_CMDS_PASTE ); end;
-
- procedure TFrmExplorer.Properties1MitmClick(Sender: TObject);
- begin PTShellList1.DoCommandForFolder( PTSH_CMDS_PROPERTIES ); end;
-
- procedure TFrmExplorer.InvertSelection1Click(Sender: TObject);
- var i: Integer;
- begin
- PTShellList1.Items.BeginUpdate;
- try
- for i := 0 to PTShellList1.Items.Count-1 do
- PTShellList1.Items[i].Selected := not PTShellList1.Items[i].Selected;
- finally
- PTShellList1.Items.EndUpdate;
- end;
- end;
-
- procedure TFrmExplorer.F11MitmClick(Sender: TObject);
- var s: String;
- i: Integer;
- p: PChar;
- begin
- if PTShellTree1.Focused then
- begin
- if InputQuery( 'Enter command string', 'Command: ', s ) then
- begin
- i := StrToIntDef( s, -1 );
- if i < 0 then p := PChar(s) else p := PChar(i);
- PTShellTree1.DoCommandForNode( PTShellTree1.Selected, p );
- end;
- end
- else if PTShellList1.Focused then
- begin
- if InputQuery( 'Enter command string', 'Command: ', s ) then
- if PTShellList1.SelCount>0 then
- PTShellList1.DoCommandForAllSelected( PChar(s) )
- else
- PTShellList1.DoCommandForFolder( PChar(s) );
- end;
- end;
-
- procedure TFrmExplorer.PTShellTree1Edited(Sender: TObject; Node: TTreeNode;
- var S: String);
- begin
- if Assigned(Node) and Assigned(Node.Parent) then
- PTShellTree1.SortNode( Node.Parent );
- end;
-
- end.
-
-
-