HRESULT IExplorerBrowserEvents.OnNavigationFailed(IntPtr pidlFolder)
        {
            var failedLocation = ShellFactory.FromShellItem(ShellItem.FromPIDL((PIDL)pidlFolder));
            var args           = new NavigationFailedEventArgs(failedLocation);

            OnNavigationFailed(args);

            return(COMErrorCodes.S_OK);
        }
        HRESULT IExplorerBrowserEvents.OnNavigationPending(IntPtr pidlFolder)
        {
            var pendingLocation = ShellFactory.FromShellItem(ShellItem.FromPIDL((PIDL)pidlFolder));
            var args            = new NavigationPendingEventArgs(pendingLocation);

            OnNavigationPending(args);

            return(args.Cancel ? COMErrorCodes.Cancelled : COMErrorCodes.S_OK);
        }
        private ShellObject CreateShellObject(IShellItem shellItem)
        {
            if (shellItem == null)
            {
                return(null);
            }

            return(ShellFactory.FromShellItem(new ShellItem((IShellItem2)shellItem)));
        }
        /// <summary>
        ///     Create a new instance of the <see cref="ShellObject" /> class.
        /// </summary>
        /// <param name="pidl"><c>PIDL</c>。</param>
        /// <param name="riid"><c>GUID</c>。</param>
        /// <returns></returns>
        private static ShellObject CreateShellObject(IntPtr pidl, ref Guid riid)
        {
            IShellItem2 shellItem2;
            var         code = ShellNativeMethods.SHCreateItemFromIDList(pidl, ref riid, out shellItem2);

            if (HRESULT.Failed(code))
            {
                return(null);
            }

            return(ShellFactory.FromShellItem(new ShellItem(shellItem2)));
        }
        /// <summary>
        ///     Get the file selected by user.
        /// </summary>
        /// <returns><see cref="ShellFile" />.</returns>
        public ShellFile GetShellFile()
        {
            var        fileDialogNative = (IFileSaveDialog)this.FileDialogInternal.FileDialogNative;
            IShellItem shellItem;

            fileDialogNative.GetResult(out shellItem);
            if (shellItem == null)
            {
                return(null);
            }
            return(ShellFactory.FromShellItem(new ShellItem((IShellItem2)shellItem)) as ShellFile);
        }
Example #6
0
        public HRESULT OnFolderChanging(IFileDialog pfd, IShellItem psiFolder)
        {
            var shellFolder = ShellFactory.FromShellItem(new ShellItem(psiFolder)) as ShellFolder;

            var change = true;

            if (!this.firstFolderChanged)
            {
                change = this.Dialog.RaiseFolderChangingEvent(shellFolder);
            }

            return(change ? COMErrorCodes.S_OK : COMErrorCodes.S_FALSE);
        }
        HRESULT IExplorerBrowserEvents.OnNavigationComplete(IntPtr pidlFolder)
        {
            using (var folderView = FolderView.Create(this))
            {
                this.FolderSettings.ViewMode = folderView.ViewMode;
            }

            var newLocation = ShellFactory.FromShellItem(ShellItem.FromPIDL((PIDL)pidlFolder));
            var args        = new NavigationCompletedEventArgs(newLocation);

            OnNavigationCompleted(args);

            return(COMErrorCodes.S_OK);
        }
        public IEnumerable <ShellObject> GetSelectedItems()
        {
            var shellItemArray = GetSelectedItemsArray();

            var count = ShellItemArray.GetShellItemCount(shellItemArray);

            for (var index = 0; index < count; ++index)
            {
                var shellItem   = ShellItemArray.GetShellItemAt(shellItemArray, index);
                var shellObject = ShellFactory.FromShellItem(new ShellItem((IShellItem2)shellItem));
                if (shellObject != null)
                {
                    yield return(shellObject);
                }
            }
        }
Example #9
0
        public bool MoveNext()
        {
            if (this.enumIdList == null)
            {
                return(false);
            }

            const uint itemsRequested = 1;
            IntPtr     item;
            uint       numItemsReturned;
            var        hr = this.enumIdList.Next(itemsRequested, out item, out numItemsReturned);

            if (HRESULT.Failed(hr) || numItemsReturned < itemsRequested)
            {
                return(false);
            }

            this.Current = ShellFactory.FromShellItem(ShellItem.FromIdList(item, this.Parent.ShellFolderItem));
            return(true);
        }
        /// <summary>
        ///     Gets a collection of files selected by the user.
        /// </summary>
        /// <returns>A collection of files.</returns>
        public IEnumerable <ShellFile> GetShellFiles()
        {
            var fileDialogNative = (IFileOpenDialog)this.FileDialogInternal.FileDialogNative;

            IShellItemArray shellItemArray;

            fileDialogNative.GetResults(out shellItemArray);

            var count = ShellItemArray.GetShellItemCount(shellItemArray);

            for (var index = 0; index < count; ++index)
            {
                var shellItem = ShellItemArray.GetShellItemAt(shellItemArray, index);
                var shellFile = ShellFactory.FromShellItem(new ShellItem((IShellItem2)shellItem)) as ShellFile;
                if (shellFile != null)
                {
                    yield return(shellFile);
                }
            }
        }