(* ImageEn Build 7.0.0.06.2637 @ 7-4-17 14:58:42.679 *) (* Copyright (c) 1998-2017 by Carlotta Calandra. All rights reserved. Copyright (c) 2011-2017 by Xequte Software. This software comes without express or implied warranty. In no case shall the author be liable for any damage or unwanted behavior of any computer hardware and/or software. Author grants you the right to include the component in your application, whether COMMERCIAL, SHAREWARE, or FREEWARE. ImageEn, IEvolution and ImageEn ActiveX may not be included in any commercial, shareware or freeware libraries or components. www.ImageEn.com *) (* KNOWN ISSUES: - Link overlay does not appear for shortcut files *) (* File version 1021 Doc revision 1004 *) unit iexFolderMView; {$R-} {$Q-} {$I ie.inc} {$IFDEF IEINCLUDEMULTIVIEW} interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls, stdctrls, dialogs, {$ifdef IEHASTYPES} Types, {$endif} {$ifdef IEHASUITYPES} System.UITypes, {$endif} ieview, iexBitmaps, hyiedefs, ImageEnView, iemview, ieanimation, ImageEnIO, iemio, ImageEnProc, ShlObj, ActiveX, iexWindowsFunctions; const IEF_CURRENT_FILE = -999; IEF_Desktop_Folder = 'IEF_DESKTOP_FOLDER'; IEF_Drives_Folder = 'IEF_DRIVES_FOLDER'; IEF_Root_Directory = 'IEF_ROOT_DIRECTORY'; IEF_MyDocuments_Folder = 'IEF_MYDOCUMENTS_FOLDER'; IEF_MyPictures_Folder = 'IEF_MYPICTURES_FOLDER'; IEF_MyVideos_Folder = 'IEF_MYVIDEOS_FOLDER'; type {!! TIEFolderFileTypes Declaration TIEFolderFileTypes = (iefAllImages, iefAllImagesAndVideos, iefAllFiles, iefCustom); Description Specifies which files types to retrieve Value Description iefAllImages Retrieves all supported image types of ImageEn iefAllImagesAndVideos Retrieves all supported image and video types of ImageEn iefAllFiles Retrieves all files iefCustom The file types to retrieve are specified by
!!} TIEFolderFileTypes = (iefAllImages, iefAllImagesAndVideos, iefAllFiles, iefCustom); {!! TIEFileOperationOptions Declaration TIEFileOperationOptions = set of (ieioShowConfirmation, ieioShowProgress, ieioVerboseErrors, ieioSendToRecycleBin, ieioRenameOnCollision); Description Value Description ieioShowConfirmation A confirmation dialog is displayed to confirm file operations. Otherwise it automatically responds with "Yes to All" for any dialog box ieioShowProgress Displays the standard Windows progress dialog. Otherwise it is silent ieioVerboseErrors Displays an error message if a failure occurs. Otherwise failures are not reported ieioSendToRecycleBin Files are moved to the Recycle Bin rather than deleted ieioRenameOnCollision If a file already exists in the destination folder when moving or copying a new name will be given to the current file
Default: [ieioShowConfirmation, ieioShowProgress, ieioVerboseErrors, ieioSendToRecycleBin] !!} TIEFileOperationOptions = set of (ieioShowConfirmation, ieioShowProgress, ieioVerboseErrors, ieioSendToRecycleBin, ieioRenameOnCollision); {!! TIEFolderInteractOptions Declaration TIEFolderInteractOptions = set of (ieboOpenFoldersOnDblClick, ieboLaunchImagesOnDblClick, ieboLaunchFilesOnDblClick, ieboEnableFolderShortcuts, ieboEnableFileShortcuts, ieboClickToSortColumns); Description Value Description ieboOpenFoldersOnDblClick If has been enabled to show folders, then ieboOpenFoldersOnDblClick allows the user to double click or press enter to open a folder ieboLaunchImagesOnDblClick If a user double clicks a supported image type (or selects one and clicks the enter key) then it will be launched to the default windows handle for that file type ieboLaunchFilesOnDblClick If a user double clicks an unknown file type (or selects one and clicks the enter key) then it will be launched to the default windows handle for that file type ieboEnableFolderShortcuts If has been enabled to show folders, then Backspace or Alt+Up will open the parent folder. F5 will refresh the file listing ieboEnableFileShortcuts Clicking Ctrl+X/C/V will Cut, Copy or Paste files to/from Windows Explorer. Clicking Delete will move files to the Recycle Bin. Shift+Delete will permanently delete files ieboClickToSortColumns When is iemsColumns, then a header row is shown for each column. Clicking the header allows sorting by that column
Default: [ieboOpenFoldersOnDblClick, ieboEnableFolderShortcuts, ieboClickToSortColumns] !!} TIEFolderInteractOptions = set of (ieboOpenFoldersOnDblClick, ieboLaunchImagesOnDblClick, ieboLaunchFilesOnDblClick, ieboEnableFolderShortcuts, ieboEnableFileShortcuts, ieboClickToSortColumns); {!! TIEFolderChangeEvent Declaration TIEFolderChangeEvent = procedure(Sender: TObject; var sNewFolder: String; var bAllow: boolean) of object; Description Used by whenever the is being changed. sNewFolder specifies the new folder. Set bAllow to false to prevent the folder being opened. Example function TMyForm.IEFolderMView1FolderChanging(Sender: TObject; var sNewFolder: String; var bAllow: boolean); begin // Do not allow user to change from C:\ if pos( 'C:\', Uppercase( sNewFolder )) = 0 then begin bAllow := False; MessageBeep( MB_ERROR ); end; end; !!} TIEFolderChangeEvent = procedure(Sender: TObject; var sNewFolder: String; var bAllow: boolean) of object; {!! TIEDropFilesEvent Declaration TIEDropFilesEvent = procedure(Sender: TObject; ssFiles: TStrings; var DropEffect: Integer) of object; Description Used by whenever files are dropped onto the control. ssFiles is a list of files that have been dropped. DropEffect is the action that will be performed on the files. It can be modified to override the default handling. Supported values are: DROPEFFECT_NONE (0), DROPEFFECT_COPY (1) or DROPEFFECT_MOVE (2) Example function TMyForm.IEFolderMView1DropFiles(Sender: TObject; ssFiles: TStrings; var DropEffect: Integer); begin // Do not allow multiple files to be dropped if ssFiles.Count > 1 then begin DropEffect := DROPEFFECT_NONE; MessageBeep( MB_ERROR ); end; end; !!} TIEDropFilesEvent = procedure(Sender: TObject; ssFiles: TStrings; var DropEffect: Integer) of object; {!! TIEDefaultFolder Declaration TIEDefaultFolder = (iedfNone, iedfDesktop, iedfDrives, iedfRootDir, iedfMyDocuments, iedfMyPictures, iedfMyVideos, iedfSpecified); Description Value Description iedfNone The control is blank on start-up iedfDesktop The Windows Desktop is shown iedfDrives "This PC" (Windows 8 or newer) or "My Computer" (Windows XP) is shown iedfRootDir The drive containing Windows is shown (usually C:\) iedfMyDocuments The user's "Documents" folder is shown iedfMyPictures The user's "Pictures" folder is shown iedfMyVideos The user's "Videos" folder is shown iedfSpecified The path specified in is shown
!!} TIEDefaultFolder = (iedfNone, iedfDesktop, iedfDrives, iedfRootDir, iedfMyDocuments, iedfMyPictures, iedfMyVideos, iedfSpecified); {!! TImageEnFolderMView Description The TImageEnFolderMView component is a descendent of , but is designed specifically for displaying the content of file folders. While much of TImageEnFolderMView's functionality can be replicated in TImageEnMView using , there are a number of features that are only available in this control: - Dragging and dropping files from Windows - Cut, copy and paste files from Windows Explorer - Automatic refreshing when folder contents change - Display of the standard folder popup menu - File functions to move, copy, rename and delete files - In-built file navigation, file shortcuts and other functions To use TImageEnFolderMView, specify a and the file types that you wish to display. For more control you can specify your own file mask, exclusion mask and sort order. For rapid UI development TImageEnFolderMView provides a set of actions, plus you can use all actions of TImageEnMView. Demos Demos\Multi\FolderMView\FolderMView.dpr Demos\Other\Actions_Folder\FolderMViewActions.dpr Example // Set up with IEFolderMView1 do begin BorderStyle := bsNone; // Normally don't require a 3D border ThumbWidth := 140; // Choose a good size for your thumbnails ThumbHeight := 150; // Default is rfFastLinear for speed, but rfLanczos3 will give much better quality ThumbnailDisplayFilter := rfLanczos3; end; // Now display the images of a folder in the grid IEFolderMView1.Folder := 'C:\MyImages\'; IEFolderMView1.FileTypes := iefAllImages; // Images only IEFolderMView1.SortOrder := iesbImageSize; // Sort by image dimensions Methods and Properties Folder Display File Operations Display (Column count) Frame Editing Image Access Image Information Image Text Thumbnail Appearance Input/Output (Auto-Rotate) Selections Checkboxes User Interaction (Default) (Ctrl Key) Animations and Transitions Other Internal Events Unique to TImageEnFolderMView !!} {$ifdef IEHASPLATFORMATTRIBUTE} [ComponentPlatformsAttribute(pidWin32 or pidWin64)] {$endif} TImageEnFolderMView = class(TImageEnMView) private ///////////////////////// // P R I V A T E fSortOrder : TIEImageEnMViewSortBy; fSortAscending : Boolean; fSortCaseSensitive : Boolean; fFileTypes : TIEFolderFileTypes; fPopupMenuUseSystem : Boolean; fFileLimit : Integer; fFileTypesMask : string; fFolder : string; fIncludeSubFolders: Boolean; fExclusionMask : string; fAutoRefresh : Boolean; fNeedRefreshFileList : Boolean; fNeedRefreshSorting : Boolean; fInitialized : Boolean; // True after the window is created and we perform our first fill fShowHiddenFiles : Boolean; fShowFolders : Boolean; fLoadOnDemand : Boolean; fClickedFrameIndex : Integer; // The index of hte frame that was last clicked fOnFolderChanging : TIEFolderChangeEvent; fOnFolderChanged : TNotifyEvent; fAutoDragFiles : TIEFileDragDropActions; fOnCustomSortCompare : TIEImageEnMViewSortCompareEx; fAutoDropFiles : TIEFileDragDropActions; fDragDrop : TIEFileDragDrop; fMouseClickPos : TPoint; fFolderMonitor : TIEFolderWatch; fDefaultFolder : TIEDefaultFolder; fFolderInteract : TIEFolderInteractOptions; fFileOperationOptions : TIEFileOperationOptions; fCurrentFolderIndex : Integer; fEnableSpecialFolders : Boolean; fOnDropFiles: TIEDropFilesEvent; procedure SetExclusionMask(const Value: string); procedure SetFileTypes(const Value: TIEFolderFileTypes); procedure SetFileTypesMask(const Value: string); procedure SetFolder(const Value: string); procedure _SetFolder(const Value: string; bIsFirstCall : Boolean); function GetFolder : string; procedure SetIncludeSubFolders(const Value: Boolean); procedure SetSortAscending(const Value: Boolean); procedure SetSortCaseSensitive(const Value: Boolean); procedure SetAutoRefresh(const Value: Boolean); procedure SetSortOrder(const Value: TIEImageEnMViewSortBy); procedure CheckForPendingRefresh; function GetSelectedFilename: WideString; procedure SetSelectedFilename(const Value: WideString); procedure RefreshFileListEx(bNewFolder : Boolean); procedure SetFolderInteract(const Value: TIEFolderInteractOptions); procedure SetFileOperationOptions(const Value: TIEFileOperationOptions); function GetImageType(idx: integer): TIEFolderImageType; procedure HandleDblClick(idx : Integer); procedure SetAutoDragFiles(const Value: TIEFileDragDropActions); procedure SetAutoDropFiles(const Value: TIEFileDragDropActions); procedure DropFiles(Sender: TObject; ssFiles : TStrings; dwEffect: Integer); procedure StartMonitoring; procedure StopMonitoring; procedure OnFolderMonitorNotify(const Sender: TObject; const Action: TWatchAction; const FileName: string); procedure CheckIndexForConst(var idx : Integer); function DeleteSelectedFilesFromFolderEx(bForcePermanentDelete : Boolean) : Boolean; procedure SetShowFolders(const Value: Boolean); procedure SetShowHiddenFiles(const Value: Boolean); procedure SetDefaultFolder(const Value: TIEDefaultFolder); procedure _GetFillFromDirectoryParams(out bAllowUnknownFormats : Boolean; out bIncludeVideoFiles : Boolean; out sFilterMask : string); procedure CheckIfFilesInFolder(ssFilenames : TStrings); procedure CheckIfFilesDeletedFromFolder(ssFilenames : TStrings); procedure SetLoadSnapshotParameters(Sender: TObject; Stream: TStream; Version : Byte); procedure GetSaveSnapshotParameters(Sender: TObject; Stream: TStream; Version : Byte); function GetFirstFolder() : string; function GetNextFolder() : string; function GetFolders(ssDest: TStrings): integer; function NormalizeFolder(const sFolder : string) : string; function GetParentOfFolder(const sFolder : String) : String; procedure FillWithDrives(); protected /////////////////////// // P R O T E C T E D // procedure CreateWnd; override; procedure ClickColumnsHeaderRowCell(Col: TIEMTextPos); override; procedure DrawColumnsHeaderRowCell(Canvas: TCanvas; Rect: TRect; Col: TIEMTextPos); override; public ///////////////////// // P U B L I C constructor Create(Owner: TComponent); override; destructor Destroy; override; {$IFDEF UNITTESTING} procedure UnitTesting_ForceInitialize; {$ENDIF} procedure DblClick; override; procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; procedure KeyUp(var Key: Word; Shift: TShiftState); override; // display procedure LockUpdate; override; function UnlockUpdate: Integer; override; function AppendFile(const sFilename : string; bSelectIt : Boolean = True; bCheckFileType : Boolean = True) : integer; function InsertFile(idx : Integer; const sFilename : string; bSelectIt : Boolean = True; bCheckFileType : Boolean = True) : Boolean; procedure RemoveFile(const sFilename : string); property SelectedFilename : WideString read GetSelectedFilename write SetSelectedFilename; function SelectedFilenames(Dest : TStrings): Integer; property ImageType[idx: integer]: TIEFolderImageType read GetImageType; property AutoRefresh : Boolean read fAutoRefresh write SetAutoRefresh; function MoveSelectedFilesToFolder(const sDestFolder : string) : Boolean; function CopySelectedFilesToFolder(const sDestFolder : string) : Boolean; function MoveFilesToCurrentFolder(ssFiles : TStrings) : Boolean; function CopyFilesToCurrentFolder(ssFiles : TStrings) : Boolean; function DeleteSelectedFilesFromFolder : Boolean; function CopySelectedFilesToClipboard : Integer; function CutSelectedFilesToClipboard : Integer; function PasteFilesFromClipboard : Boolean; function CanPasteFilesFromClipboard : Boolean; procedure PopupSystemMenu(X, Y: Integer); {!! TImageEnFolderMView.FileLimit Declaration property FileLimit: Integer; Description Specifies the maximum number of images to retrieve from a folder. If this is -1 (default) then all images are retrieved. Default: -1 Note: Changing this property will not affect the current content. The change will occur next time the folder is refreshed. !!} property FileLimit: Integer read fFileLimit write fFileLimit; {!! TImageEnFolderMView.LoadOnDemand Declaration property LoadOnDemand : Boolean; Description If enabled, images are only loaded as they are displayed (i.e. not until they are scrolled into view). Set to false to load all images immediately (which will be much slower) Default: True Note: Changing this property will not affect the current content. The change will occur next time the folder is refreshed. !!} // Note: Not exposed in unit help index property LoadOnDemand: Boolean read fLoadOnDemand write fLoadOnDemand; procedure RefreshFileList; procedure RefreshSorting; procedure SetFolderEx(const sFolder: string; xFileTypes: TIEFolderFileTypes; const sFileTypesMask: string = ''; const sExclusionMask: string = ''); procedure SetSortOrderEx(xSortOrder: TIEImageEnMViewSortBy; bSortAscending: Boolean = True; bSortCaseSensitive: Boolean = False); function OpenFolder(idx : Integer = IEF_CURRENT_FILE) : boolean; function OpenParentFolder : boolean; function CanOpenParentFolder : boolean; function ExecuteFile(idx : Integer = IEF_CURRENT_FILE) : boolean; function RenameFile(idx : Integer; const sNewName : string): boolean; function PromptForFolder : boolean; function CreateNewFolder(const sFolderName : string) : Boolean; procedure SaveSnapshot(Stream: TStream; SaveCache: Boolean = True; Compressed: Boolean = False; SaveParams: Boolean = False); overload; override; procedure SaveSnapshot(FileName: WideString; SaveCache: Boolean = True; Compressed: Boolean = False; SaveParams: Boolean = False); overload; override; function LoadSnapshot(Stream: TStream): Boolean; overload; override; function LoadSnapshot(FileName: WideString): Boolean; overload; override; published /////////////////////// // P U B L I S H E D property SortOrder: TIEImageEnMViewSortBy read fSortOrder write SetSortOrder default iesbNone; property SortAscending: Boolean read fSortAscending write SetSortAscending default True; property SortCaseSensitive: Boolean read fSortCaseSensitive write SetSortCaseSensitive default False; property FileTypes: TIEFolderFileTypes read fFileTypes write SetFileTypes default iefAllImages; property FileTypesMask: string read fFileTypesMask write SetFileTypesMask; property Folder : string read GetFolder write SetFolder; property IncludeSubFolders : Boolean read fIncludeSubFolders write SetIncludeSubFolders default false; property ExclusionMask: string read fExclusionMask write SetExclusionMask; property FolderInteract: TIEFolderInteractOptions read fFolderInteract write SetFolderInteract default [ieboOpenFoldersOnDblClick, ieboEnableFolderShortcuts, ieboClickToSortColumns]; property FileOperationOptions: TIEFileOperationOptions read fFileOperationOptions write SetFileOperationOptions default [ieioShowConfirmation, ieioShowProgress, ieioVerboseErrors, ieioSendToRecycleBin]; property AutoDragFiles : TIEFileDragDropActions read fAutoDragFiles write SetAutoDragFiles default []; property AutoDropFiles : TIEFileDragDropActions read fAutoDropFiles write SetAutoDropFiles default []; property ShowHiddenFiles: Boolean read fShowHiddenFiles write SetShowHiddenFiles default False; property ShowFolders: Boolean read fShowFolders write SetShowFolders default True; {!! TImageEnFolderMView.EnableSpecialFolders Declaration property EnableSpecialFolders: Boolean; Description Whether the user can navigate up from a root to a drives display ("This PC") and from there to the "Desktop". When false, the top level folder of TImageEnMView is a drive root (e.g. C:\). When enabled, the folder tree is as follows: + Desktop + Drives + C:\ + Folder 1 on C + Folder 2 on C + D:\ + Folder 1 on D + Folder 2 on D Notes: - When enabled, may return the constants: IEF_Desktop_Folder or IEF_Drives_Folder - These are not true special folders. IEF_Desktop_Folder is the Windows desktop plus a "This PC" icon to access the drives folder. IEF_Drives_Folder simply lists available drives on a system. Example // Display the Windows desktop IEFolderMView1.Folder := IEF_Desktop_Folder; // Check the user is not creating a folder in the drives folder if IEFolderMView1.Folder = IEF_Drives_Folder then ShowMessage( 'You cannot create a folder in "My Computer"' ); !!} property EnableSpecialFolders: Boolean read fEnableSpecialFolders write fEnableSpecialFolders default False; {!! TImageEnFolderMView.PopupMenuUseSystem Declaration property PopupMenuUseSystem: Boolean; Description If enabled and a PopUpMenu has not been specified then a Windows Explorer popup menu will be shown when right-clicking a file. Default: True Note: If is not enabled, the control may not update the display of files that are moved or renamed See Also - !!} property PopupMenuUseSystem: Boolean read fPopupMenuUseSystem write fPopupMenuUseSystem default True; property DefaultFolder: TIEDefaultFolder read fDefaultFolder write SetDefaultFolder default iedfNone; {!! TImageEnFolderMView.OnFolderChanging Declaration property OnFolderChanging: ; Description Occurs whenever the is being changed. Example function TMyForm.IEFolderMView1FolderChanging(Sender: TObject; var sNewFolder: String; var bAllow: boolean); begin // Do not allow user to change from C:\ if pos( 'C:\', Uppercase( sNewFolder )) = 0 then begin bAllow := False; MessageBeep( MB_ERROR ); end; end; !!} property OnFolderChanging : TIEFolderChangeEvent read fOnFolderChanging write fOnFolderChanging; {!! TImageEnFolderMView.OnFolderChanged Declaration property OnFolderChanged: TNotifyEvent; Description Occurs after a folder is opened (i.e. after has been set). !!} property OnFolderChanged : TNotifyEvent read fOnFolderChanged write fOnFolderChanged; {!! TImageEnFolderMView.OnDropFiles Declaration property OnDropFiles: ; Description Occurs whenever files are dropped onto the control. ssFiles is a list of files that have been dropped. DropEffect is the action that will be performed on the files. It can be modified to override the default handling. Supported values are: DROPEFFECT_NONE (0), DROPEFFECT_COPY (1) or DROPEFFECT_MOVE (2) Note: You must enable for files to be dropped Example function TMyForm.IEFolderMView1DropFiles(Sender: TObject; ssFiles: TStrings; var DropEffect: Integer); begin // Do not allow multiple files to be dropped if ssFiles.Count > 1 then begin DropEffect := DROPEFFECT_NONE; MessageBeep( MB_ERROR ); end; end; !!} property OnDropFiles : TIEDropFilesEvent read fOnDropFiles write fOnDropFiles; {!! TImageEnFolderMView.OnCustomSortCompare Declaration property OnCustomSortCompare: ; Description Occurs whenever the content needs to be sorted if is set to iesbCustom. Example // custom sort function (by DPI) function TMyForm.IEFolderMView1CustomSortCompare(i1, i2: Integer): Integer; var dpi1, dpi2: Integer; begin dpi1 := IEFolderMView1.Params[i1].DPI; dpi2 := IEFolderMView1.Params[i2].DPI; if dpi1 < dpi2 then result := -1 else if dpi1 > dpi2 then result := 1 else result := 0; // Or more concise: Result := dpi1 - dpi2; end; // Sort By DPI procedure TForm1.btnCustomSortClick(Sender: TObject); begin IEFolderMView1.SortOrder := iesbCustom; end; !!} property OnCustomSortCompare : TIEImageEnMViewSortCompareEx read fOnCustomSortCompare write fOnCustomSortCompare; end; const IEM_Folder_Delimiter = '|'; // Delimits multiple folders implementation uses iesettings, ComObj, ShellApi, hyieutils; {$R-} constructor TImageEnFolderMView.Create(Owner: TComponent); begin inherited; fInitialized := False; fDragDrop := TIEFileDragDrop.Create(Self, DropFiles); {$IFDEF DEBUG} RegisterExpectedMemoryLeak( fDragDrop ); // we will not explicity free {$ENDIF} // CHANGED FROM TImageEnMView behaviour StoreType := ietFastThumb; ImageCacheSize := 100; LookAhead := 20; TrackMouseSelection := True; MultiSelectionOptions := [iemoRegion, iemoSelectOnRightClick, iemoOptimizeForDragging]; SetModernStyling(True, 130, 130); // Defaults fFolder := ''; fExclusionMask := ''; fFileTypesMask := ''; fSortOrder := iesbNone; fSortAscending := True; fSortCaseSensitive := False; fFileTypes := iefAllImages; fPopupMenuUseSystem := True; fFileLimit := -1; fShowHiddenFiles := False; fShowFolders := True; fLoadOnDemand := True; fFolderInteract := [ieboOpenFoldersOnDblClick, ieboEnableFolderShortcuts, ieboClickToSortColumns]; fFileOperationOptions := [ieioShowConfirmation, ieioShowProgress, ieioVerboseErrors, ieioSendToRecycleBin]; fNeedRefreshFileList := True; fNeedRefreshSorting := True; fAutoRefresh := False; fAutoDragFiles := []; fAutoDropFiles := []; fDefaultFolder := iedfNone; fEnableSpecialFolders := False; end; function DefaultFolderToStr(const Value: TIEDefaultFolder; const sDefaultFolder : string) : string; begin Result := ''; if Result = '' then case Value of iedfDesktop : Result := IEF_Desktop_Folder; iedfDrives : Result := IEF_Drives_Folder; iedfRootDir : Result := IEF_Root_Directory; iedfMyDocuments : Result := IEF_MyDocuments_Folder; iedfMyPictures : Result := IEF_MyPictures_Folder; iedfMyVideos : Result := IEF_MyVideos_Folder; iedfSpecified : Result := sDefaultFolder; end; end; procedure TImageEnFolderMView.CreateWnd; begin inherited; if fInitialized = False then begin fInitialized := True; _SetFolder(DefaultFolderToStr(fDefaultFolder, fFolder), True); if fAutoDropFiles <> [] then fDragDrop.ActivateDropping := True; end; end; {$IFDEF UNITTESTING} procedure TImageEnFolderMView.UnitTesting_ForceInitialize; begin if fInitialized = False then begin fInitialized := True; _SetFolder(DefaultFolderToStr(fDefaultFolder, fFolder), True); end; end; {$ENDIF} procedure TImageEnFolderMView.DblClick; begin inherited; HandleDblClick(fClickedFrameIndex); end; // Use GetFirstFolder and GetNextFolder to iterate through all the items specified in the Folder properties (as there may be multiple delimited by IEM_Folder_Delimiter) function TImageEnFolderMView.GetFirstFolder() : string; begin fCurrentFolderIndex := 1; Result := GetNextFolder; end; function TImageEnFolderMView.GetNextFolder() : string; procedure _GetNextFolder; var sPosCheck: string; iNextPos: Integer; begin // Because older versions of Delphi do not support PosEx() sPosCheck := Copy(fFolder, fCurrentFolderIndex, Length(fFolder) - fCurrentFolderIndex + 1); iNextPos := Pos(IEM_Folder_Delimiter, sPosCheck); if iNextPos = 0 then iNextPos := Length(sPosCheck) + 1; Result := Copy(fFolder, fCurrentFolderIndex, iNextPos - 1); fCurrentFolderIndex := fCurrentFolderIndex + iNextPos; end; begin Result := ''; While (Result = '') and (Length(fFolder) > fCurrentFolderIndex) do _GetNextFolder; if result <> '' then Result := IncludeTrailingBackslash( Result ); end; // Return a list of all folders in the "Folder" property and optionally their sub-folders if "IncludeSubFolders" is enabled function TImageEnFolderMView.GetFolders(ssDest: TStrings): integer; procedure _AddSubFolders(Folder: string); var DirName : WideString; dir: TIEDirContent; sNewFolder: String; begin Folder := IncludeTrailingBackslash( Folder ); dir := TIEDirContent.Create( Folder + '*.*' ); try while dir.GetItem( DirName, False, True, fShowHiddenFiles ) do begin // Show progress so user can abort using MIO.Aborting := True; if assigned( OnIOProgress ) then OnIOProgress( Self, 0 ); sNewFolder := IncludeTrailingBackslash( Folder + DirName ); if ssDest.IndexOf( sNewFolder ) = -1 then begin ssDest.Add( sNewFolder ); _AddSubFolders( sNewFolder ); end; end; finally dir.Free; end; end; var sFolder: string; begin ssDest.Clear; sFolder := GetFirstFolder; while ( sFolder <> '' ) and ( MIO.Aborting = False ) and ( ssDest.IndexOf( sFolder ) = -1 ) do begin ssDest.Add( sFolder ); if fIncludeSubFolders then _AddSubFolders( sFolder ); sFolder := GetNextFolder; end; if MIO.Aborting then Result := -1 else Result := ssDest.Count; end; // Tests the status of a drive to see if it's accessible function DriveIsReady(const sDrive: String): Boolean; var ErrMode: Word; iDrive: Integer; begin Result := False; if sDrive = '' then exit; iDrive := Ord( UpCase( sDrive[ 1 ] )) - 64; ErrMode := SetErrorMode( 0 ); SetErrorMode( ErrMode or SEM_FAILCRITICALERRORS ); try Result := DiskSize( iDrive ) > -1 ; finally SetErrorMode( ErrMode ); end; end; procedure TImageEnFolderMView.FillWithDrives(); var Buff: array[0..128] of Char; pDrives: PChar; Idx: Integer; sDrive: string; begin if GetLogicalDriveStrings( Length( Buff ), Buff ) = 0 then begin {$ifdef Delphi6orNewer} RaiseLastOSError; {$else} exit; {$endif} end; pDrives := @Buff; while StrLen( pDrives ) > 0 do begin sDrive := pDrives; pDrives := StrEnd( pDrives ); Inc( pDrives ); if DriveIsReady( sDrive ) then begin Idx := AppendImage( sDrive, True, iedtNone, iedtNone, iedtNone, False ); TIEImageInfo( IEMBitmap.fImageInfo[ Idx ] ).SourceType := iestFolderIcon; end; end; end; procedure TImageEnFolderMView.HandleDblClick(idx : Integer); begin if idx < 0 then exit; case ImageType[idx] of ieftFolder : if ieboOpenFoldersOnDblClick in fFolderInteract then OpenFolder(idx); ieftSupportedImage : if ieboLaunchImagesOnDblClick in fFolderInteract then ExecuteFile(idx); ieftFile : if ieboLaunchFilesOnDblClick in fFolderInteract then ExecuteFile(idx); end; end; destructor TImageEnFolderMView.Destroy; begin fDragDrop := nil; // don't free FreeAndNil(fFolderMonitor); inherited; end; {!! TImageEnFolderMView.AppendImage Note: It is better to use than as it provides better support for TImageEnFolderMView properties. See Also - - !!} {!! TImageEnFolderMView.AppendFile Declaration function AppendFile(const sFilename : string; bSelectIt : Boolean = True; bCheckFileType : Boolean = True) : integer; Description AppendFile adds a new file at last position in the grid and returns the new image position. If bSelectIt is enabled the new file will be selected. If bCheckFileType is enabled then the file is only added if it is permitted by folder parameters: , , , and Result is -1 if the file does not exist. Note: Unlike the methods, the added file will be loaded on demand and filled with the details and properties of TImageEnFolderMView Example IEFolderMView1.Add('D:\MyNewImage.jpg'); !!} function TImageEnFolderMView.AppendFile(const sFilename : string; bSelectIt : Boolean = True; bCheckFileType : Boolean = True) : integer; begin result := IEMBitmap.fImageInfo.Count; If InsertFile(Result, sFilename, bSelectIt, bCheckFileType) = False then Result := -1; end; {!! TImageEnFolderMView.InsertImage Note: It is better to use than as it provides better support for TImageEnFolderMView properties. See Also - - !!} {!! TImageEnFolderMView.InsertImageEx Note: It is better to use than as it provides better support for TImageEnFolderMView properties. See Also - - !!} {!! TImageEnFolderMView.InsertFile Declaration function InsertFile(idx : Integer; const sFilename : string; bSelectIt : Boolean = True; bCheckFileType : Boolean = True) : Boolean; Description InsertFile adds a new file at the specified position in the grid. If bSelectIt is enabled the new file will be selected. If bCheckFileType is enabled then the file is only added if it is permitted by folder parameters: , , , and Result is False if the file does not exist. Note: Unlike the methods, the added file will be loaded on demand and filled with the details and properties of TImageEnFolderMView Example // Add file to the start of the list IEFolderMView1.Add(0, 'D:\MyNewImage.jpg'); !!} function TImageEnFolderMView.InsertFile(idx : Integer; const sFilename : string; bSelectIt : Boolean = True; bCheckFileType : Boolean = True) : Boolean; function _FileExtInExtensions(sFileExt : String; const sExtensions : String) : Boolean; begin sFileExt := Lowercase(sFileExt); result := (sFileExt <> '') and (sExtensions <> '') and (pos(sFileExt + ',', Lowercase(sExtensions + ',')) > 0); end; var dir : TIEDirContent; fname : WideString; bAllowUnknownFormats: Boolean; bIncludeVideoFiles: Boolean; sFilterMask: string; bAllow: Boolean; ext: string; begin Result := False; // Need to use ExcludeTrailingBackSlash() so we support folders dir := TIEDirContent.Create(ExcludeTrailingBackSlash(sFilename)); try if dir.GetItem(fname, True, True, True) then begin bAllow := True; if bCheckFileType then begin if dir.IsFolder then bAllow := fShowFolders else begin _GetFillFromDirectoryParams(bAllowUnknownFormats, bIncludeVideoFiles, sFilterMask); ext := IEExtractFileExtW(sFilename, false); bAllow := (bAllowUnknownFormats or (( ieixLoadOnlyByFileExt in IOOptionsEx ) and (FindFileFormat(sFilename, ffContentOnly) <> ioUnknown)) or IsKnownFormat(sFilename, bIncludeVideoFiles)) and (_FileExtInExtensions(ext, fExclusionMask) = False) and ((sFilterMask = '') or _FileExtInExtensions(ext, sFilterMask)); end; if (fShowHiddenFiles = False) and dir.IsHiddenFile then bAllow := False; end; if bAllow then begin InsertImage(idx, sFilename, fLoadOnDemand, iedtNone, iedtNone, iedtNone, bSelectIt); ImageFileSize[idx] := dir.FileSizeBytes; ImageCreateDate[idx] := dir.CreateDate; ImageEditDate[idx] := dir.EditDate; If dir.IsFolder then TIEImageInfo(IEMBitmap.fImageInfo[idx]).SourceType := iestFolderIcon; Result := True; end; end; finally dir.Free; end; end; {!! TImageEnFolderMView.RemoveFile Declaration procedure RemoveFile(const sFilename : string); Description Removes the file sFilename from the control. Example IEFolderMView1.RemoveFile('D:\MyOldmage.jpg'); !!} procedure TImageEnFolderMView.RemoveFile(const sFilename : string); var idx: integer; begin idx := FilenameToIndex(sFilename); DeleteImage(idx); end; function TImageEnFolderMView.GetImageType(idx: integer): TIEFolderImageType; begin Result := Inherited GetImageType(idx); end; function TImageEnFolderMView.GetSelectedFilename: WideString; var iSel: Integer; begin Result := ''; if DisplayMode = mdSingle then iSel := VisibleFrame else iSel := SelectedImage; if iSel >= 0 then Result := ImageFilename[iSel]; end; procedure TImageEnFolderMView.KeyUp(var Key: Word; Shift: TShiftState); const VK_C = 67; VK_V = 86; VK_X = 88; begin inherited; if ieboEnableFolderShortcuts in fFolderInteract then begin if Key = VK_RETURN then begin HandleDblClick(SelectedImage); Key := 0; end else if (Key = VK_Back) or // Strictly speaking this should be "View the previous folder" ((Key = VK_RIGHT) and (Shift = [ssAlt])) then begin OpenParentFolder; Key := 0; end else if (Key = VK_F5) then begin RefreshFileList; Key := 0; end; end; if ieboEnableFileShortcuts in fFolderInteract then begin case Key of VK_DELETE : begin DeleteSelectedFilesFromFolderEx(ssShift in Shift); Key := 0; end; VK_C : if ssCtrl in Shift then begin CopySelectedFilesToClipboard; Key := 0; end; VK_X : if ssCtrl in Shift then begin CutSelectedFilesToClipboard; Key := 0; end; VK_V : if ssCtrl in Shift then begin PasteFilesFromClipboard; Key := 0; end; end; end; end; {!! TImageEnFolderMView.RefreshFileList Declaration procedure RefreshFileList; Description Refills the control with files found in the folder . This can be useful if you have not enabled . !!} procedure TImageEnFolderMView.RefreshFileList; begin RefreshFileListEx(False); end; procedure TImageEnFolderMView._GetFillFromDirectoryParams(out bAllowUnknownFormats : Boolean; out bIncludeVideoFiles : Boolean; out sFilterMask : string); begin case fFileTypes of iefAllImages : begin bAllowUnknownFormats := False; bIncludeVideoFiles := False; sFilterMask := ''; end; iefAllImagesAndVideos : begin bAllowUnknownFormats := False; bIncludeVideoFiles := True; sFilterMask := ''; end; iefAllFiles : begin bAllowUnknownFormats := True; bIncludeVideoFiles := True; sFilterMask := ''; end; else { iefCustom } begin bAllowUnknownFormats := True; bIncludeVideoFiles := True; sFilterMask := fFileTypesMask; end; end; end; procedure TImageEnFolderMView.RefreshFileListEx(bNewFolder : Boolean); var bAllowUnknownFormats: Boolean; bIncludeVideoFiles: Boolean; sFilterMask: string; sSelectedFilename: Widestring; sFolder: string; ssFolders: TStringList; {$ifdef VIDEO_THUMBNAILS} Idx: Integer; {$endif} i: Integer; begin fNeedRefreshFileList := False; LockUpdate; ssFolders := TStringList.create; try ClearCache; StopMonitoring; if bNewFolder then sSelectedFilename := '' else sSelectedFilename := SelectedFilename; Clear; if (fFolder = '') or (csDesigning in ComponentState) then exit; _GetFillFromDirectoryParams(bAllowUnknownFormats, bIncludeVideoFiles, sFilterMask); MIO.Aborting := False; GetFolders( ssFolders ); for i := 0 to ssFolders.count - 1 do begin if MIO.Aborting then Break; sFolder := ssFolders[ i ]; // Add a "My Computer" item if SameText( ExcludeTrailingBackSlash( sFolder ), IEF_Desktop_Folder ) then begin {$ifdef VIDEO_THUMBNAILS} // If video thumbnails are not supported then we will not have an icon or name for this item Idx := AppendImage( IEF_Drives_Folder, True, iedtNone, iedtNone, iedtNone, False ); TIEImageInfo( IEMBitmap.fImageInfo[ idx ] ).SourceType := iestFolderIcon; {$endif} // And display content of actual Desktop folder sFolder := WindowsDesktopFolder; end; if SameText( ExcludeTrailingBackSlash( sFolder ), IEF_Drives_Folder ) then FillWithDrives() else FillFromDirectory(sFolder, fFileLimit, bAllowUnknownFormats, fExclusionMask, ieixLoadOnlyByFileExt in IOOptionsEx, sFilterMask, bIncludeVideoFiles, fLoadOnDemand, iedtNone, iedtNone, iedtNone, fShowHiddenFiles, fShowFolders); end; if MIO.Aborting = False then RefreshSorting; SelectedFilename := sSelectedFilename; finally UnlockUpdate; FreeAndNil( ssFolders ); end; if bNewFolder and assigned(fOnFolderChanged) then fOnFolderChanged(Self); if fAutoRefresh then StartMonitoring; end; {!! TImageEnFolderMView.RefreshSorting Declaration procedure RefreshSorting; Description Reapplies the current sort settings (, and ). Note: TImageEnFolderMView will automatically apply sorting when refreshing files and setting sort properties, but this method may be used if files are added due to folder monitoring !!} procedure TImageEnFolderMView.RefreshSorting; var sSelectedFilename: string; begin fNeedRefreshSorting := False; if not (csDesigning in ComponentState) then begin LockUpdate; try sSelectedFilename := SelectedFilename; if (fSortOrder = iesbCustom) and assigned(fOnCustomSortCompare) then Sort(fOnCustomSortCompare) else Sort(fSortOrder, fSortAscending, fSortCaseSensitive); SelectedFilename := sSelectedFilename; finally UnlockUpdate; end; end; end; {!! TImageEnFolderMView.SetFolderEx Declaration procedure SetFolderEx(const sFolder: string; xFileTypes: TIEFolderFileTypes; const sFileTypesMask: string = ''; const sExclusionMask: string = ''); Description Specifies the folder and filtering options in one step (to avoid premature updating). It is the same as making the following calls: try finally end; Example // Retrieve all JPEG images in C:\Images\ IEFolderMView1.SetFolderEx('C:\Images\', iefCustom, 'jpg,jpeg,jpe'); // This is the same as calling: IEFolderMView1.LockUpdate; try IEFolderMView1.Folder := 'C:\Images\'; IEFolderMView1.FileTypes := iefCustom; IEFolderMView1.FileTypesMask := 'jpg,jpeg,jpe'; finally IEFolderMView1.UnlockUpdate; end; !!} procedure TImageEnFolderMView.SetFolderEx(const sFolder: string; xFileTypes: TIEFolderFileTypes; const sFileTypesMask: string = ''; const sExclusionMask: string = ''); begin LockUpdate; try Folder := sFolder; FileTypes := xFileTypes; FileTypesMask := sFileTypesMask; ExclusionMask := sExclusionMask; RefreshFileListEx( True ); finally UnlockUpdate; end; end; {!! TImageEnFolderMView.SetSortOrderEx Declaration procedure SetSortOrderEx(xSortOrder: ; bSortAscending: Boolean = True; bSortCaseSensitive: Boolean = False); Description Specifies both sort options in one step (to avoid premature updating). It is the same as making the following calls: try finally end; !!} procedure TImageEnFolderMView.SetSortOrderEx(xSortOrder: TIEImageEnMViewSortBy; bSortAscending: Boolean = True; bSortCaseSensitive: Boolean = False); begin LockUpdate; try SortOrder := xSortOrder; SortAscending := bSortAscending; SortCaseSensitive := bSortCaseSensitive; RefreshSorting; finally UnlockUpdate; end; end; // Replace IEF_CURRENT_FILE if specified procedure TImageEnFolderMView.CheckIndexForConst(var idx : Integer); begin if idx = IEF_CURRENT_FILE then begin if DisplayMode = mdSingle then idx := VisibleFrame else idx := SelectedImage; end; end; {!! TImageEnFolderMView.ExecuteFile Declaration function ExecuteFile(idx : Integer = IEF_CURRENT_FILE) : boolean; Description Executes the file at idx using the standard windows functionality. Note: No check is made whether the file type is supported by ImageEn or not. Result is true unless an error was encountered. If you specify IEF_CURRENT_FILE for idx then currently selected folder will be opened. Example case IEFolderMView1.ImageType[idx] of ieftFolder : IEFolderMView1.OpenFolder(idx); ieftSupportedImage : DisplayImage(idx); ieftFile : IEFolderMView1.ExecuteFile(idx); end; !!} function TImageEnFolderMView.ExecuteFile(idx : Integer = IEF_CURRENT_FILE) : boolean; var sFilename: WideString; begin CheckIndexForConst(idx); sFilename := ImageFilename[idx]; Result := sFilename <> ''; if Result then try WindowsLaunchFile(Handle, sFilename); except on E:Exception do begin Result := False; MessageDlg(e.message, mtError, [mbOK], 0); end; end; end; {!! TImageEnFolderMView.RenameFile Declaration function RenameFile(idx : Integer; const sNewName : string) : boolean; Description Renames the file at idx to sNewName using the standard windows functionality. Note: sNewName must be a name only, without a folder path Result is true unless an error was encountered. If you specify IEF_CURRENT_FILE for idx then currently selected file will be renamed. Example // Rename current file to "Selected.jpg" RenameFile(IEF_CURRENT_FILE, 'Selected.jpg'); !!} function TImageEnFolderMView.RenameFile(idx : Integer; const sNewName : string): boolean; var sFilename: WideString; begin CheckIndexForConst(idx); sFilename := ImageFilename[idx]; Result := (sFilename <> '') and (sNewName <> ''); if Result then Result := WindowsRename(Handle, sFilename, sNewName, False, True); if Result and (fAutoRefresh = False) then begin DeleteImage(Idx); AppendFile(IEAddBackSlash(ExtractFilePath(sFilename)) + sNewName); end; end; {!! TImageEnFolderMView.OpenFolder Declaration function OpenFolder(idx : Integer = IEF_CURRENT_FILE) : boolean; Description If the frame at idx is a file folder, then it will be opened (i.e. will change to that location) Result is true if the frame at idx is a folder. If you specify IEF_CURRENT_FILE for idx then currently selected folder will be opened. !!} function TImageEnFolderMView.OpenFolder(idx : Integer = IEF_CURRENT_FILE) : boolean; begin CheckIndexForConst(idx); Result := ImageType[idx] = ieftFolder; if Result then Folder := ImageFilename[idx]; end; // Converts IEF_DESKTOP_FOLDER to a physical path. Converts IEF_DRIVES_FOLDER to ''. Else returns sFolder function TImageEnFolderMView.NormalizeFolder(const sFolder : string) : string; begin result := sFolder; if SameText( Result, IEF_DESKTOP_FOLDER ) then Result := WindowsDesktopFolder else if SameText( Result, IEF_DRIVES_FOLDER ) then Result := ''; end; {!! TImageEnFolderMView.PromptForFolder Declaration function PromptForFolder : boolean; Description Display a folder selection dialog and allows the user to select a folder. The grid will be then set to that . Result is true if a folder was selected. !!} function TImageEnFolderMView.PromptForFolder : boolean; var sNewFolder: string; begin sNewFolder := NormalizeFolder( GetFirstFolder ); Result := WindowsSelectDirectory(iemsg(IEMSG_SelectAFolderToOpen), sNewFolder, Self); if Result then Folder := sNewFolder; end; // Returns the parents of sFolder or '' if there is no parent function TImageEnFolderMView.GetParentOfFolder(const sFolder : String) : String; begin if SameText( sFolder, IEF_Desktop_Folder) then Result := '' else if fEnableSpecialFolders and SameText( sFolder, IEF_Drives_Folder) then Result := IEF_Desktop_Folder else begin Result := ExtractFilePath(ExcludeTrailingBackslash(sFolder)); if SameText(ExcludeTrailingBackslash(sFolder), ExcludeTrailingBackslash(Result)) then begin // ROOT DRIVE if fEnableSpecialFolders then Result := IEF_Drives_Folder else Result := ''; end; end; end; {!! TImageEnFolderMView.CreateNewFolder Declaration function CreateNewFolder(const sFolderName : string) : Boolean; Description Creates a new folder within the current of the name sFolderName. Note: sFolderName must NOT be a full path (just a new name) Example // Create a new folder of the name, "New Folder" IEFolderMView1.CreateNewFolder('New Folder'); !!} function TImageEnFolderMView.CreateNewFolder(const sFolderName : string) : Boolean; var sNewFolder: string; begin Result := NormalizeFolder( fFolder ) <> ''; sNewFolder := IEAddBackSlash( NormalizeFolder( GetFirstFolder) ) + sFolderName; if Result then Result := CreateDir(sNewFolder); if (Result = False) and (ieioVerboseErrors in fFileOperationOptions) then MessageDlg(format('Unable to create "%s"', [sFolderName]) + #13#10 + #13#10 + SysErrorMessage(GetLastError), mtError, [mbOK], 0); if Result and (fAutoRefresh = False) then AppendFile(sNewFolder, True); end; {!! TImageEnFolderMView.OpenParentFolder Declaration function OpenParentFolder : boolean; Description Changes to the parent of the current folder Result is true if there is a parent folder. See also: Note: If ieboEnableFolderShortcuts is specified for then the control will automatically Go Up if the user clicks Backspace or Alt+Up !!} function TImageEnFolderMView.OpenParentFolder : boolean; var sParentFolder: string; begin sParentFolder := GetParentOfFolder( GetFirstFolder ); // While "Desktop" and C:\Users\UN\Desktop are both valid, the former would be much more common // Better method would be storing which desktop path we are under if SameText( Uppercase( ExcludeTrailingBackslash( sParentFolder )), Uppercase( ExcludeTrailingBackslash( WindowsDesktopFolder ))) then sParentFolder := IEF_Desktop_Folder; Result := sParentFolder <> ''; if Result then Folder := sParentFolder; end; {!! TImageEnFolderMView.CanOpenParentFolder Declaration function CanOpenParentFolder : boolean; Description Returns true if there is a folder above the current that can be accessed (e.g. using ) Example // Enable our "Go Up" button btnGoUp.Enabled := IEFolderMView1.CanOpenParentFolder; !!} function TImageEnFolderMView.CanOpenParentFolder : boolean; var sParentFolder: string; begin sParentFolder := GetParentOfFolder( GetFirstFolder ); Result := sParentFolder <> ''; end; {!! TImageEnFolderMView.LockUpdate Declaration procedure LockUpdate; Description Increments the lock update counter. While is greater than zero all component updating is disabled. Use to unlock. Example // Disable updating of component IEFolderMView1.LockUpdate; try ... Perform activities, e.g. appending many files finally // Re-enable Updating and refresh view IEFolderMView1.UnlockUpdate; end; !!} procedure TImageEnFolderMView.LockUpdate; begin inherited; end; procedure TImageEnFolderMView.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin inherited; fClickedFrameIndex := ImageAtPosEx(x, y, True); if (Button = mbRight) and fPopupMenuUseSystem and (PopupMenu = nil) then PopupSystemMenu(X, Y); end; procedure TImageEnFolderMView.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin inherited; fDragging := False; fMouseClickPos := point(X, Y); end; procedure TImageEnFolderMView.MouseMove(Shift: TShiftState; X, Y: Integer); var ssFilenames: TStringList; begin inherited; if (fAutoDragFiles <> []) and (csLButtonDown in ControlState) and (ImageAtPosEx(fMouseClickPos.x, fMouseClickPos.y, True) >= 0) and // actually clicked on the image ((Abs(X - fMouseClickPos.x) >= Mouse.DragThreshold) or (Abs(Y - fMouseClickPos.y) >= Mouse.DragThreshold)) then begin fDragging := True; // so mouse up does not occur Perform(WM_LBUTTONUP, 0, MakeLong(X, Y)); ssFilenames := TStringList.create; try SelectedFilenames(ssFilenames); fDragDrop.InitiateDragging(ssFilenames, fAutoDragFiles); finally ssFilenames.free; end; end; end; {!! TImageEnFolderMView.PopupSystemMenu Declaration procedure PopupSystemMenu(X, Y: Integer); Description Displays the system menu for the specified files at position x,y. This menu is the same as that displayed when right-clicking a selection of files in Windows Explorer. Note: If is not enabled, the control may not update the display of files that are moved or renamed Example PopupSystemMenu(Form1.Handle, ssSelectedFiles, ClickPos.X, ClickPos.Y); !!} procedure TImageEnFolderMView.PopupSystemMenu(X, Y: Integer); var ssFilenames : TStringList; begin ssFilenames := TStringList.create; try SelectedFilenames(ssFilenames); iexWindowsFunctions.PopupSystemMenu(Handle, ssFilenames, X, Y); if fAutoRefresh = False then CheckIfFilesDeletedFromFolder(ssFilenames); finally ssFilenames.free; end; end; {!! TImageEnFolderMView.UnLockUpdate Declaration function UnlockUpdate: integer; Description Decrement the lock update counter (use after calling ). If the lock count is zero, then is called to refresh the view. Returns the lock count. Example // Disable updating of component while setting properties IEFolderMView1.LockUpdate; try IEFolderMView1.Folder := 'C:\Images\'; IEFolderMView1.FileTypes := iefCustom; IEFolderMView1.FileTypesMask := 'jpg,jpeg,jpe'; IEFolderMView1.SortOrder := iesbFilename; IEFolderMView1.SortAscending := True; finally // Re-enable updating and call update IEFolderMView1.UnlockUpdate; end; !!} // decreases fLockUpdate // ret. current value (after the decrement) function TImageEnFolderMView.UnlockUpdate: integer; begin // If this call will unlock the update (set it to 0) then refresh our list if fInitialized and (LockUpdateCount = 1) then CheckForPendingRefresh; Result := UnlockUpdateEx; end; {!! TImageEnFolderMView.LockUpdateCount Declaration property LockUpdateCount: Integer; Description Returns the lock updating state. A value of 0 means no locking. A value greater than zero means locking is in place (i.e. updating is disabled). Calling increments , decrements it. !!} {!! TImageEnFolderMView.FileTypes Declaration property FileTypes: ; Description The file types that TImageEnFolderMView will retrieve from your . If FileTypes is iefCustom then use to specify your file types. See Also - - - - !!} procedure TImageEnFolderMView.SetFileTypes(const Value: TIEFolderFileTypes); begin if fFileTypes <> Value then begin StopMonitoring; fFileTypes := Value; if fInitialized and (LockUpdateCount = 0) then RefreshFileListEx( False ) else fNeedRefreshFileList := True; end; end; {!! TImageEnFolderMView.ShowFolders Declaration property ShowFolders: Boolean; Description Enable to display folders with your files. When folders are displayed they can be opened by mouse or keyboard click Default: True See Also: Example // Show folders IEFolderMView1.LockUpdate; try IEFolderMView1.Folder := 'C:\'; IEFolderMView1.ShowFolders := True; finally // Re-enable updating and refresh content IEFolderMView1.UnlockUpdate; end; !!} procedure TImageEnFolderMView.SetShowFolders(const Value: Boolean); begin if fShowFolders <> Value then begin StopMonitoring; fShowFolders := Value; if fInitialized and (LockUpdateCount = 0) then RefreshFileListEx( False ) else fNeedRefreshFileList := True; end; end; {!! TImageEnFolderMView.ShowHiddenFiles Declaration property ShowHiddenFiles: Boolean; Description Enable to display system and hidden files. Default: false See Also - Example // Show hidden files IEFolderMView1.LockUpdate; try IEFolderMView1.Folder := 'C:\'; IEFolderMView1.ShowFolders := True; IEFolderMView1.ShowHiddenFiles := True; finally // Re-enable updating and refresh content IEFolderMView1.UnlockUpdate; end; !!} procedure TImageEnFolderMView.SetShowHiddenFiles(const Value: Boolean); begin if fShowHiddenFiles <> Value then begin StopMonitoring; fShowHiddenFiles := Value; if fInitialized and (LockUpdateCount = 0) then RefreshFileListEx( False ) else fNeedRefreshFileList := True; end; end; {!! TImageEnFolderMView.DefaultFolder Declaration property DefaultFolder : ; Description The initial value for . Example 1 procedure TForm1.FormCreate(Sender: TObject); begin // Default to the "My Pictures" folder IEFolderMView1.DefaultFolder := iedfMyPictures; end; Example 2 procedure TForm1.FormCreate(Sender: TObject); begin // Default to a custom folder IEFolderMView1.DefaultFolder := iedfSpecified; // Note: This line is optional at run-time IEFolderMView1.Folder := 'D:\My Custom Folder'; end; !!} procedure TImageEnFolderMView.SetDefaultFolder(const Value: TIEDefaultFolder); begin fDefaultFolder := Value; // Display normalized default folder path in the Object Inspector if csDesigning in ComponentState then _SetFolder(DefaultFolderToStr(fDefaultFolder, fFolder), True); end; {!! TImageEnFolderMView.FileTypesMask Declaration property FileTypesMask: string; Description Specifies the file types to retrieve from your . File types must be specified as a comma-separated list of extensions (e.g. 'jpg,jpeg,jpe'). If an empty string is specified all extensions will be returned. Note: Property is ignored unless FileTypes has been set to iefCustom Example // Retrieve only JPEG images IEFolderMView1.LockUpdate; try IEFolderMView1.Folder := 'C:\Images\'; IEFolderMView1.FileTypes := iefCustom; IEFolderMView1.FileTypesMask := 'jpg,jpeg,jpe'; finally // Re-enable updating and call update IEFolderMView1.UnlockUpdate; end; See Also - - - - !!} procedure TImageEnFolderMView.SetFileTypesMask(const Value: string); begin if fFileTypesMask <> Value then begin fFileTypesMask := Value; if fFileTypes = iefCustom then begin StopMonitoring; if fInitialized and (LockUpdateCount = 0) then RefreshFileListEx( False ) else fNeedRefreshFileList := True; end; end; end; {!! TImageEnFolderMView.Folder Declaration property Folder: string; Description Specifies the folder to search for files with which we fill the control. You can specify multiple folders by delimiting them with IEM_Folder_Delimiter (which is a bar: |). Files in sub-folders will be included if is enabled. The type of files to be retrieved is specified by and . You can exclude particular types with . To update all folder properties at once, use . The following constants can be specified in place of a folder path: Constant Description IEF_Desktop_Folder Windows Desktop IEF_Drives_Folder "This PC" (Windows 8 or newer) or "My Computer" (Windows XP) IEF_Root_Directory The drive containing Windows (usually C:\) IEF_MyDocuments_Folder The user's "Documents" folder IEF_MyPictures_Folder The user's "Pictures" folder IEF_MyVideos_Folder The user's "Videos" folder
Note: The value of Folder at start-up is defined by
. If DefaultFolder is not iedfSpecified then any value you have set for Folder at design time is ignored. Example 1 // Retrieve only JPEG images IEFolderMView1.LockUpdate; try IEFolderMView1.Folder := 'C:\Images\'; IEFolderMView1.FileTypes := iefCustom; IEFolderMView1.FileTypesMask := 'jpg,jpeg,jpe'; finally // Re-enable updating and refresh content IEFolderMView1.UnlockUpdate; end; // This is the same as calling: IEFolderMView1.SetFolderEx('C:\Images\', iefCustom, 'jpg,jpeg,jpe'); Example 2 // Display "My Pictures" folder IEFolderMView1.Folder := IEF_MyPictures_Folder; Example 3 // Display content of all drives on system by delimiting them with IEM_Folder_Delimiter procedure TForm1.btnShowAllDrives(Sender: TObject); var vDrivesSize : Cardinal; vDrives : array[0..128] of Char; vDrive : PChar; sDrives: string; begin sDrives := ''; vDrivesSize := GetLogicalDriveStrings(SizeOf(vDrives), vDrives); if vDrivesSize > 0 then begin vDrive := vDrives; while vDrive^ <> #0 do begin sDrives := sDrives + StrPas(vDrive) + IEM_Folder_Delimiter; Inc(vDrive, SizeOf(vDrive)); end; end; IEFolderMView.Folder := sDrives; end; !!} procedure TImageEnFolderMView.SetFolder(const Value: string); begin _SetFolder(Value, False); end; procedure TImageEnFolderMView._SetFolder(const Value: string; bIsFirstCall : Boolean); function _FolderConstToPath(const aConst : string) : string; {$IFNDEF Delphi2007orNewer} const CSIDL_WINDOWS = $0024; // "C:\Windows" {$ENDIF} begin Result := aConst; // LEAVE AS CONST: IEF_Desktop_Folder, IEF_Drives_Folder if SameText(aConst, IEF_Root_Directory) then Result := IEAddBackSlash(ExtractFileDrive(GetWindowsSpecialFolder(CSIDL_WINDOWS))) else if SameText(aConst, IEF_MyDocuments_Folder) then Result := WindowsMyDocumentsFolder else if SameText(aConst, IEF_MyPictures_Folder) then Result := WindowsMyPicturesFolder else if SameText(aConst, IEF_MyVideos_Folder) then Result := WindowsMyVideosFolder; end; var sNewFolder: string; bAllow: Boolean; begin sNewFolder := _FolderConstToPath(Value); if pos( '..\', sNewFolder ) > 0 then sNewFolder := ExpandFileName( sNewFolder ); if bIsFirstCall or (fFolder <> sNewFolder) then begin if (bIsFirstCall = False) and (not (csLoading in ComponentState)) then begin if sNewFolder <> '' then fDefaultFolder := iedfSpecified else if fDefaultFolder = iedfSpecified then fDefaultFolder := iedfNone; end; StopMonitoring; bAllow := True; if (sNewFolder <> '') and assigned(fOnFolderChanging) then fOnFolderChanging(Self, sNewFolder, bAllow); if bAllow = False then exit; fFolder := sNewFolder; if fInitialized and (LockUpdateCount = 0) then RefreshFileListEx(True) else fNeedRefreshFileList := True; end; end; function TImageEnFolderMView.GetFolder : string; begin if (csWriting in ComponentState) and (fDefaultFolder <> iedfSpecified) then Result := '' else Result := fFolder; end; {!! TImageEnFolderMView.IncludeSubFolders Declaration property IncludeSubFolders: Boolean; Description When enabled, files within any sub-folders of will be included. Note: IncludeSubFolders has no effect with special folders such as IEF_Desktop_Folder or IEF_Drives_Folder. It will also be slow if there are many sub-folders so use with caution. Example // Retrieve JPEG images from all folders of an inserted DVD IEFolderMView1.LockUpdate; try IEFolderMView1.Folder := 'E:\'; IEFolderMView1.IncludeSubFolders := True; IEFolderMView1.FileTypesMask := 'jpg,jpeg,jpe'; finally // Re-enable updating and refresh content IEFolderMView1.UnlockUpdate; end; !!} procedure TImageEnFolderMView.SetIncludeSubFolders(const Value: Boolean); begin if fIncludeSubFolders <> Value then begin fIncludeSubFolders := Value; if ( fFolder <> '' ) and (not (csLoading in ComponentState)) then begin if fInitialized and (LockUpdateCount = 0) then RefreshFileListEx(True) else fNeedRefreshFileList := True; end; end; end; {!! TImageEnFolderMView.FillFromDirectory DO NOT USE for TImageEnFolderMView! Use and associated properties instead. See also: !!} {!! TImageEnFolderMView.SortAscending Declaration property SortAscending: Boolean; Description Whether the sort order specified by is ascending or descending. Note: you can set both sort properties at once, using . Example // Sort by file name reverse alphabetically IEFolderMView1.LockUpdate; try IEFolderMView1.SortOrder := iesbFilename; IEFolderMView1.SortAscending := False; finally IEFolderMView1.UnlockUpdate; end; // Which is the same as: IEFolderMView1.SetSortOrderEx(iesbFilename, False); !!} procedure TImageEnFolderMView.SetSortAscending(const Value: Boolean); begin if fSortAscending <> Value then begin fSortAscending := Value; if fInitialized and (LockUpdateCount = 0) then RefreshSorting else fNeedRefreshSorting := True; end; end; {!! TImageEnFolderMView.SortCaseSensitive Declaration property SortCaseSensitive: Boolean; Description Whether text comparisons when sorting are case sensitive or not. See also: !!} procedure TImageEnFolderMView.SetSortCaseSensitive(const Value: Boolean); begin if fSortCaseSensitive <> Value then begin fSortCaseSensitive := Value; if fInitialized and (LockUpdateCount = 0) then RefreshSorting else fNeedRefreshSorting := True; end; end; {!! TImageEnFolderMView.FileOperationOptions Declaration property FileOperationOptions : ; Description Configure settings for when moving, copying or deleting files. Affected Methods - - - - - - - !!} procedure TImageEnFolderMView.SetFileOperationOptions(const Value: TIEFileOperationOptions); begin if fFileOperationOptions <> Value then fFileOperationOptions := Value; end; {!! TImageEnFolderMView.FolderInteract Declaration property FolderInteract : ; Description Configure the behaviour when interacting with the control. !!} procedure TImageEnFolderMView.SetFolderInteract(const Value: TIEFolderInteractOptions); begin if fFolderInteract <> Value then fFolderInteract := Value; end; {!! TImageEnFolderMView.SelectedFilename Declaration property SelectedFilename: WideString; Description Returns the full path of the currently selected frame (using ) or '' if nothing is selected. You can set SelectedFilename to make it the selected filename. If the filename is not found, the first item will be selected See also: Example // Show preview of image in ImageEnView when a file is selected procedure TForm1.IEFolderMView1ImageSelect(Sender: TObject); begin if IEFolderMView1.SelectedFilename = '' then ImageEnView1.Blank else ImageEnView1.IO.LoadFromFile(IEFolderMView1.SelectedFilename); end; !!} procedure TImageEnFolderMView.SetSelectedFilename(const Value: WideString); var iIndex: Integer; begin if ImageCount = 0 then exit; iIndex := FilenameToIndex(Value); if iIndex >= 0 then SelectedImage := iIndex else SelectedImage := 0; // Default to the first image end; {!! TImageEnFolderMView.SelectedFilenames Declaration function SelectedFilenames(Dest : TStrings): Integer; Description Adds the filenames of all selected files to the specified strings object. Result is the count of selected files. See also: Example // Add all selected filenames to a listbox IEFolderMView1.SelectedFilenames(Listbox1.Items); !!} function TImageEnFolderMView.SelectedFilenames(Dest : TStrings): Integer; var i: Integer; iSelIndex: Integer; begin Dest.Clear; if (DisplayMode = mdSingle) or (EnableMultiSelect = False) then begin if SelectedFilename <> '' then Dest.Add(SelectedFilename); end else begin // Sort by index MultiSelectSortList; // Get filenames for i := 0 to MultiSelectedImagesCount-1 do begin iSelIndex := MultiSelectedImages[ i ]; Dest.Add( ImageFileName[ iSelIndex ] ); end; end; Result := Dest.Count; end; {!! TImageEnFolderMView.SortOrder Declaration property SortOrder: ; Description The order in which your files are displayed. You can reverse the sort order by setting to false. Note: you can set both sort properties at once, using . Example 1 // Sort by filename IEFolderMView1.SortOrder := iesbFilename; Example 2 // Sort by filename in reverse alphabetical order IEFolderMView1.LockUpdate; try IEFolderMView1.SortOrder := iesbFilename; IEFolderMView1.SortAscending := False; finally IEFolderMView1.UnlockUpdate; end; // Which is the same as: IEFolderMView1.SetSortOrderEx(iesbFilename, False); !!} procedure TImageEnFolderMView.SetSortOrder(const Value: TIEImageEnMViewSortBy); begin if fSortOrder <> Value then begin fSortOrder := Value; if fInitialized and (LockUpdateCount = 0) then RefreshSorting else fNeedRefreshSorting := True; end; end; {!! TImageEnFolderMView.Sort Declaration procedure Sort(Compare: ); procedure Sort(Compare: ); procedure Sort(OrderBy: ; Ascending: boolean = true; CaseSenstive : boolean = true); Description Sorts all images in the TImageEnFolderMView by property (filename, dimensions, etc) or using a custom comparison function. DO NOT USE for TImageEnFolderMView! Use properties and instead. !!} {!! TImageEnFolderMView.ExclusionMask Declaration property ExclusionMask: String; Description Specify any file types that you do not want to be added to the grid. Must be a comma-separated list of file extensions (e.g. 'lyr,all,iev') Note: These types will be excluded regardless of your setting for Example // Retrieve all images except JPEGs IEFolderMView1.LockUpdate; try IEFolderMView1.Folder := 'C:\Images\'; IEFolderMView1.FileTypes := iefAllImages; IEFolderMView1.ExclusionMask := 'jpg,jpeg,jpe'; finally // Re-enable updating and refresh file list IEFolderMView1.UnlockUpdate; end; !!} procedure TImageEnFolderMView.SetExclusionMask(const Value: string); begin if fExclusionMask <> Value then begin StopMonitoring; fExclusionMask := Value; if fInitialized and (LockUpdateCount = 0) then RefreshFileListEx( False ) else fNeedRefreshFileList := True; end; end; {!! TImageEnFolderMView.AutoDragFiles Declaration property AutoDragFiles : ; Description Whether files can be dragged from the grid to other Windows applications, such as Explorer. Default: [] (drag drop will not occur automatically) Value Description [] Dragging of files is not automatically initiated due to user action [iedpMove] A user can drag files to another application to move them [iedpCopy] A user can drag files to another application to copy them [iedpCopy, iedpMove] A user can drag files to another application to move or copy them (the desination application will determine which action takes place. Generally this will be copying, or moving if the Shift key is pressed
!!} procedure TImageEnFolderMView.SetAutoDragFiles(const Value: TIEFileDragDropActions); begin fAutoDragFiles := Value; end; {!! TImageEnFolderMView.AutoDropFiles Declaration property AutoDropFiles : Set of
; Description Whether files can be dropped onto the grid from other Windows applications, such as Explorer. Default: [] (drag drop is disabled) Value Description [] Dropping of files is disabled [iedpMove] Files that are dropped onto the control will be moved to the current [iedpCopy] Files that are dropped onto the control will be copied to the current [iedpCopy, iedpMove] Files that are dropped onto the control can be moved or copied to the current . If the Shift key is pressed, they will be moved, otherwise they will be copied.
Note: You can use the to override the handling of specific dropped files !!} procedure TImageEnFolderMView.SetAutoDropFiles(const Value: TIEFileDragDropActions); var bChangedDragDrop: Boolean; begin bChangedDragDrop := (Value = []) <> (fAutoDropFiles = []); fAutoDropFiles := Value; fDragDrop.DropActions := fAutoDropFiles; if fInitialized and bChangedDragDrop then fDragDrop.ActivateDropping := fAutoDropFiles <> []; end; {!! TImageEnFolderMView.AutoRefresh Declaration property AutoRefresh : Boolean; Description When enabled the current will be monitored for changes and new files that appear automatically appended and deleted files will be automatically removed !!} procedure TImageEnFolderMView.SetAutoRefresh(const Value: Boolean); begin if Value <> fAutoRefresh then begin fAutoRefresh := Value; if fAutoRefresh then StartMonitoring else StopMonitoring; end; end; // Enable monitoring for changes in the current folder procedure TImageEnFolderMView.StartMonitoring; begin if NormalizeFolder( fFolder ) = '' then exit; if not assigned(fFolderMonitor) then begin fFolderMonitor := TIEFolderWatch.Create; fFolderMonitor.OnNotify := OnFolderMonitorNotify; fFolderMonitor.WatchSubTree := False; fFolderMonitor.WatchOptions := [woFileName, woFolderName]; fFolderMonitor.WatchActions := [waAdded, waRemoved, waRenamedOld, waRenamedNew]; end; fFolderMonitor.Path := NormalizeFolder( GetFirstFolder ); fFolderMonitor.Start; end; // Disable monitoring for changes in the current folder procedure TImageEnFolderMView.StopMonitoring; begin if assigned(fFolderMonitor) then fFolderMonitor.Stop; end; procedure TImageEnFolderMView.OnFolderMonitorNotify(const Sender: TObject; const Action: TWatchAction; const FileName: string); begin case Action of waAdded, waRenamedNew : AppendFile(Filename, False, True); waRemoved, waRenamedOld : RemoveFile(Filename); end; end; procedure TImageEnFolderMView.CheckForPendingRefresh; begin if fNeedRefreshFileList then RefreshFileListEx( True ) else if fNeedRefreshSorting then RefreshSorting; end; {!! TImageEnFolderMView.MoveFilesToCurrentFolder Declaration function MoveFilesToCurrentFolder(ssFilenames : TStrings) : Boolean; Description Moves the specified files to the current and refreshes the grid. Result is False if the action failed or was aborted. Progress, confirmation and other options are controlled by . !!} function TImageEnFolderMView.MoveFilesToCurrentFolder(ssFiles : TStrings) : Boolean; begin Result := False; if ( NormalizeFolder( fFolder ) = '') or (ssFiles.Count = 0) then exit; Result := WindowsMove(Handle, ssFiles, NormalizeFolder( GetFirstFolder ), ieioRenameOnCollision in fFileOperationOptions, ieioShowConfirmation in fFileOperationOptions, ieioShowProgress in fFileOperationOptions, ieioVerboseErrors in fFileOperationOptions); if fAutoRefresh = False then begin if ieioRenameOnCollision in fFileOperationOptions then RefreshFileListEx( False ) else // Add new files in folder CheckIfFilesInFolder(ssFiles); end; end; {!! TImageEnFolderMView.CopyFilesToCurrentFolder Declaration function CopyFilesToCurrentFolder(ssFilenames : TStrings) : Boolean; Description Copies the specified files to the current and refreshes the grid. Result is False if the action failed or was aborted. Progress, confirmation and other options are controlled by . !!} function TImageEnFolderMView.CopyFilesToCurrentFolder(ssFiles : TStrings) : Boolean; begin Result := False; if ( NormalizeFolder( fFolder ) = '') or (ssFiles.Count = 0) then exit; Result := WindowsCopy(Handle, ssFiles, NormalizeFolder( fFolder ), ieioRenameOnCollision in fFileOperationOptions, ieioShowConfirmation in fFileOperationOptions, ieioShowProgress in fFileOperationOptions, ieioVerboseErrors in fFileOperationOptions); if fAutoRefresh = False then begin if ieioRenameOnCollision in fFileOperationOptions then RefreshFileListEx( False ) else // Add new files in folder CheckIfFilesInFolder(ssFiles); end; end; {!! TImageEnFolderMView.MoveSelectedFilesToFolder Declaration function MoveSelectedFilesToFolder(const sDestFolder : string) : Boolean; Description Moves the selected files from the current folder to sDestFolder (and removes them from the grid) Result is False if the action failed or was aborted. Progress, confirmation and other options are controlled by . !!} function TImageEnFolderMView.MoveSelectedFilesToFolder(const sDestFolder : string) : Boolean; var ssFiles: TStringList; begin Result := False; if NormalizeFolder( fFolder ) = '' then exit; ssFiles := TStringList.create; try if SelectedFilenames(ssFiles) = 0 then exit; Result := WindowsMove(Handle, ssFiles, sDestFolder, ieioRenameOnCollision in fFileOperationOptions, ieioShowConfirmation in fFileOperationOptions, ieioShowProgress in fFileOperationOptions, ieioVerboseErrors in fFileOperationOptions); if fAutoRefresh = False then CheckIfFilesDeletedFromFolder(ssFiles); finally ssFiles.Free; end; end; {!! TImageEnFolderMView.CopySelectedFilesToFolder Declaration function CopySelectedFilesToFolder(const sDestFolder : string) : Boolean; Description Copies the selected files from the current folder to sDestFolder Result is False if the action failed or was aborted. Progress, confirmation and other options are controlled by . !!} function TImageEnFolderMView.CopySelectedFilesToFolder(const sDestFolder : string) : Boolean; var ssFiles: TStringList; begin Result := False; if NormalizeFolder( fFolder ) = '' then exit; ssFiles := TStringList.create; try if SelectedFilenames(ssFiles) = 0 then exit; Result := WindowsCopy(Handle, ssFiles, sDestFolder, ieioRenameOnCollision in fFileOperationOptions, ieioShowConfirmation in fFileOperationOptions, ieioShowProgress in fFileOperationOptions, ieioVerboseErrors in fFileOperationOptions); finally ssFiles.Free; end; end; {!! TImageEnFolderMView.DeleteSelectedFilesFromFolder Declaration function DeleteSelectedFilesFromFolder : Boolean; Description Deletes the selected files from the current folder. Do not confuse this method with the files are deleted from the system. Result is False if the action failed or was aborted. If ieioSendToRecycleBin is specified for the files are moved to the Recycle Bin (though this will depend on the user's settings in Windows). Otherwise they are permanently deleted. Example // Send selected file to Recycle Bin IEFolderMView1.FileOperationOptions := FileOperationOptions + [ieioSendToRecycleBin]; IEFolderMView1.DeleteSelectedFilesFromFolder; // Permanently delete the selected file with confirmation IEFolderMView1.FileOperationOptions := FileOperationOptions - [ieioSendToRecycleBin] + [ieioShowConfirmation]; IEFolderMView1.DeleteSelectedFilesFromFolder; !!} function TImageEnFolderMView.DeleteSelectedFilesFromFolder : Boolean; begin Result := DeleteSelectedFilesFromFolderEx(False); end; function TImageEnFolderMView.DeleteSelectedFilesFromFolderEx(bForcePermanentDelete : Boolean) : Boolean; var ssFiles: TStringList; WasFileOperationOptions: TIEFileOperationOptions; begin Result := False; if NormalizeFolder( fFolder ) = '' then exit; WasFileOperationOptions := FileOperationOptions; if bForcePermanentDelete then FileOperationOptions := FileOperationOptions - [ieioSendToRecycleBin] + [ieioShowConfirmation]; ssFiles := TStringList.create; try if SelectedFilenames(ssFiles) = 0 then exit; Result := WindowsErase(Handle, ssFiles, ieioSendToRecycleBin in fFileOperationOptions, ieioShowConfirmation in fFileOperationOptions, ieioShowProgress in fFileOperationOptions, ieioVerboseErrors in fFileOperationOptions); if fAutoRefresh = False then CheckIfFilesDeletedFromFolder(ssFiles); finally ssFiles.Free; if bForcePermanentDelete then FileOperationOptions := WasFileOperationOptions; end; end; {!! TImageEnFolderMView.CutSelectedFilesToClipboard Declaration function CutSelectedFilesToClipboard : Integer; Description Cuts all filenames of selected files to the clipboard. These files can be pasted in Windows Explorer or using Result is the count of files added to the clipboard. Note: - This is best used in combination with - An exception will be raised if an error occurs - TImageEnFolderMView does not change the visual style of cut files !!} function TImageEnFolderMView.CutSelectedFilesToClipboard : Integer; var ssFilenames : TStringList; begin Result := 0; ssFilenames := TStringList.create; try if SelectedFilenames(ssFilenames) = 0 then exit; if iexWindowsFunctions.CutFilesToClipboard(Handle, ssFilenames) then Result := ssFilenames.Count; finally ssFilenames.free; end; end; {!! TImageEnFolderMView.CopySelectedFilesToClipboard Declaration function CopySelectedFilesToClipboard : Integer; Description Copies all filenames of selected files to the clipboard. These files can be pasted in Windows Explorer or using Result is the count of files added to the clipboard. Note: An exception will be raised if an error occurs !!} function TImageEnFolderMView.CopySelectedFilesToClipboard : Integer; var ssFilenames : TStringList; begin Result := 0; ssFilenames := TStringList.create; try if SelectedFilenames(ssFilenames) = 0 then exit; if iexWindowsFunctions.CopyFilesToClipboard(Handle, ssFilenames) then Result := ssFilenames.Count; finally ssFilenames.free; end; end; {!! TImageEnFolderMView.PasteFilesFromClipboard Declaration function PasteFilesFromClipboard : Boolean; Description Copies any files found on the clipboard to the current folder. Files can be copied using Windows Explorer or . Result is False if the action failed or was aborted. Notes: - You do NOT need to call before pasting, but is useful to enable your Paste controls - Progress, confirmation and other options are controlled by . !!} function TImageEnFolderMView.PasteFilesFromClipboard : Boolean; var ssFilenames : TStringList; bMoveFiles : Boolean; begin ssFilenames := TStringList.create; try iexWindowsFunctions.PasteFilesFromClipboard(Handle, ssFilenames, bMoveFiles); if bMoveFiles then begin // PASTE FROM CUT Result := MoveFilesToCurrentFolder(ssFilenames); // Clear from clipboard if OpenClipboard(Handle) then begin EmptyClipboard(); CloseClipboard; end; end else begin // PASTE FROM COPY Result := CopyFilesToCurrentFolder(ssFilenames); end; finally ssFilenames.free; end; end; {!! TImageEnFolderMView.CanPasteFilesFromClipboard Declaration function CanPasteFilesFromClipboard : Boolean; Description Returns true if there are files on the clipboard that can be pasted into the control. See also: Example // Enable our Paste button btnPaste.Enabled := IEFolderMView1.CanPasteFilesFromClipboard; !!} function TImageEnFolderMView.CanPasteFilesFromClipboard : Boolean; begin Result := iexWindowsFunctions.CanPasteFilesFromClipboard(Handle); end; procedure TImageEnFolderMView.DropFiles(Sender: TObject; ssFiles : TStrings; dwEffect: Integer); begin if assigned( fOnDropFiles ) then fOnDropFiles( Sender, ssFiles, dwEffect ); case dwEffect of DROPEFFECT_MOVE : MoveFilesToCurrentFolder(ssFiles); DROPEFFECT_COPY : CopyFilesToCurrentFolder(ssFiles); end; end; // Check if any of the specified files now exist in the current folder. Append them if they do procedure TImageEnFolderMView.CheckIfFilesInFolder(ssFilenames : TStrings); var I: Integer; sFilename: string; begin for I := 0 to ssFilenames.Count - 1 do begin sFilename := IEAddBackSlash( NormalizeFolder( GetFirstFolder )) + ExtractFilename(ssFilenames[i]); if (FileExists(sFilename) or DirectoryExists(sFilename)) and (FilenameToIndex(sFilename) = -1) then AppendFile(sFilename, True, True); end; end; // Check if any of the specified files no longer exist in the current folder. Remove them if they don't procedure TImageEnFolderMView.CheckIfFilesDeletedFromFolder(ssFilenames : TStrings); var I: Integer; sFilename: string; begin for I := 0 to ssFilenames.Count - 1 do begin sFilename := ssFilenames[i]; if (FileExists(sFilename) or DirectoryExists(sFilename)) = False then RemoveFile(sFilename); end; end; procedure TImageEnFolderMView.GetSaveSnapshotParameters(Sender: TObject; Stream: TStream; Version : Byte); begin // ExclusionMask IESaveStringToStream(Stream, AnsiString(fExclusionMask)); // FileTypes Stream.Write(fFileTypes, SizeOf(TIEFolderFileTypes)); // FileTypesMask IESaveStringToStream(Stream, AnsiString(fFileTypesMask)); // Folder IESaveStringToStream(Stream, AnsiString(fFolder)); // SortAscending Stream.Write(fSortAscending, SizeOf(Boolean)); // SortCaseSensitive Stream.Write(fSortCaseSensitive, SizeOf(Boolean)); // SortOrder Stream.Write(fSortOrder, SizeOf(TIEImageEnMViewSortBy)); // ShowFolders Stream.Write(fShowFolders, SizeOf(Boolean)); // ShowHiddenFiles Stream.Write(fShowHiddenFiles, SizeOf(Boolean)); end; procedure TImageEnFolderMView.SaveSnapshot(Stream: TStream; SaveCache: Boolean = True; Compressed: Boolean = False; SaveParams: Boolean = False); begin SaveSnapshotEx(Stream, SaveCache, Compressed, SaveParams, GetSaveSnapshotParameters); end; procedure TImageEnFolderMView.SaveSnapshot(FileName: WideString; SaveCache: Boolean = True; Compressed: Boolean = False; SaveParams: Boolean = False); var fs: TIEWideFileStream; begin fs := TIEWideFileStream.Create(FileName, fmCreate); try SaveSnapshotEx(fs, SaveCache, Compressed, SaveParams, GetSaveSnapshotParameters); finally fs.Free; end; end; procedure TImageEnFolderMView.SetLoadSnapshotParameters(Sender: TObject; Stream: TStream; Version : Byte); var s: AnsiString; begin if Version >= 7 then begin // ExclusionMask IELoadStringFromStream(Stream, s); fExclusionMask := string(s); // FileTypes Stream.Read(fFileTypes, SizeOf(TIEFolderFileTypes)); // FileTypesMask IELoadStringFromStream(Stream, s); fFileTypesMask := string(s); // Folder IELoadStringFromStream(Stream, s); fFolder := string(s); // SortAscending Stream.Read(fSortAscending, SizeOf(Boolean)); // SortCaseSensitive Stream.Read(fSortCaseSensitive, SizeOf(Boolean)); // SortOrder Stream.Read(fSortOrder, SizeOf(TIEImageEnMViewSortBy)); // ShowFolders Stream.Read(fShowFolders, SizeOf(Boolean)); // ShowHiddenFiles Stream.Read(fShowHiddenFiles, SizeOf(Boolean)); end; end; function TImageEnFolderMView.LoadSnapshot(Stream: TStream): Boolean; begin result := LoadSnapshotEx(Stream, SetLoadSnapshotParameters); end; function TImageEnFolderMView.LoadSnapshot(FileName: WideString): Boolean; var fs: TIEWideFileStream; begin fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try result := LoadSnapshotEx(fs, SetLoadSnapshotParameters); finally fs.Free; end; end; function _ColIsSorted(fmview: TImageEnFolderMView; Col: TIEMTextPos) : boolean; var DefaultText: TIEImageEnMViewDefaultText; begin Result := False; case Col of iemtpTop : DefaultText := fmview.DefaultTopText; iemtpBottom : DefaultText := fmview.DefaultBottomText; else { iemtpInfo } DefaultText := fmview.DefaultInfoText; end; case fmview.SortOrder of iesbFilenameWithoutPath : Result := DefaultText in [ iedtFilename, iedtFilenameNoExt ]; iesbFilename : Result := DefaultText = iedtFilePath; iesbTopText : Result := Col = iemtpTop; iesbBottomText : Result := Col = iemtpBottom; iesbInfoText : Result := Col = iemtpInfo; iesbImageSize : Result := DefaultText in [ iedtImageDimensions, iedtImageDimAndSize ]; iesbFileExtension : Result := DefaultText = iedtFileExt; iesbFileSize : Result := DefaultText = iedtFileSize; iesbCreateDate : Result := DefaultText in [ iedtFileCreateDate, iedtFileCreateDateTime, iedtFileCreateDateAndSize ]; iesbEditDate : Result := DefaultText in [ iedtFileEditDate, iedtFileEditDateTime, iedtFileEditDateAndSize ]; iesbFileType : Result := DefaultText = iedtFileType; end; end; // Clicking of column headers to change sorting procedure TImageEnFolderMView.ClickColumnsHeaderRowCell(Col: TIEMTextPos); var DefaultText: TIEImageEnMViewDefaultText; begin if not ( ieboClickToSortColumns in fFolderInteract ) then exit; case Col of iemtpTop : DefaultText := DefaultTopText; iemtpBottom : DefaultText := DefaultBottomText; else { iemtpInfo } DefaultText := DefaultInfoText; end; if _ColIsSorted( Self, Col ) then SortAscending := not SortAscending else case DefaultText of iedtFilename, iedtFilenameNoExt : SortOrder := iesbFilenameWithoutPath; iedtFilePath : SortOrder := iesbFilename; iedtImageDimensions, iedtImageDimAndSize : SortOrder := iesbImageSize; iedtFileSize : SortOrder := iesbFileSize; iedtFileExt : SortOrder := iesbFileExtension; iedtFileCreateDate, iedtFileCreateDateTime, iedtFileCreateDateAndSize : SortOrder := iesbCreateDate; iedtFileEditDate, iedtFileEditDateTime, iedtFileEditDateAndSize : SortOrder := iesbEditDate; end; end; // Display of chevron in column header to indicate sort order procedure TImageEnFolderMView.DrawColumnsHeaderRowCell(Canvas: TCanvas; Rect: TRect; Col: TIEMTextPos); const Chevron_Width = 6; Chevron_Height = 3; var iLeft: Integer; begin if ( ieboClickToSortColumns in fFolderInteract ) and _ColIsSorted( Self, Col ) then begin iLeft := Rect.Left + (( Rect.Right - Rect.Left - Chevron_Width ) div 2 ); Canvas.Pen.Style := psSolid; Canvas.Pen.Color := clScrollbar; if SortAscending then begin Canvas.MoveTo( iLeft, Chevron_Height + 1 ); Canvas.LineTo( iLeft + Chevron_Width div 2, 1 ); Canvas.LineTo( iLeft + Chevron_Width + 1, Chevron_Height + 2 ); end else begin Canvas.MoveTo( iLeft, 1 ); Canvas.LineTo( iLeft + Chevron_Width div 2, Chevron_Height + 1 ); Canvas.LineTo( iLeft + Chevron_Width + 1, 0 ); end; Canvas.Pen.Color := cl3dLight; if SortAscending then begin Canvas.MoveTo( iLeft + 1, Chevron_Height + 1 ); Canvas.LineTo( iLeft + Chevron_Width div 2, 2 ); Canvas.LineTo( iLeft + Chevron_Width, Chevron_Height + 2 ); end else begin Canvas.MoveTo( iLeft + 1, 1 ); Canvas.LineTo( iLeft + Chevron_Width div 2, Chevron_Height ); Canvas.LineTo( iLeft + Chevron_Width, 0 ); end; end; end; {$ELSE} // {$ifdef IEINCLUDEMULTIVIEW} interface implementation {$ENDIF} end.