Example #1
0
        private void GetPictures(ShellContainer folder)
        {
            // Just for demo purposes, stop at 20 pics
            if (picturesList.Count >= 20)
            {
                return;
            }

            // First get the pictures in this folder
            foreach (ShellFile sf in folder.OfType <ShellFile>())
            {
                string ext = Path.GetExtension(sf.Path).ToLower();

                if (ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp")
                {
                    picturesList.Add(sf);
                }
            }

            // Then recurse into each subfolder
            foreach (ShellContainer subFolder in folder.OfType <ShellContainer>())
            {
                GetPictures(subFolder);
            }
        }
Example #2
0
        private void OnBrowseForFolder(object sender, RoutedEventArgs e)
        {
            // Display a CommonOpenFileDialog to select only folders
            var cfd = new CommonOpenFileDialog
            {
                EnsureReadOnly          = true,
                IsFolderPicker          = true,
                EnsurePathExists        = true,
                AllowNonFileSystemItems = true
            };

            if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                ShellContainer selectedObj = null;

                try
                {
                    // Try to get a valid selected item
                    selectedObj = cfd.FileAsShellObject as ShellContainer;
                }
                catch
                {
                    //MessageBox.Show("Could not create a ShellObject from the selected item");
                }

                if (selectedObj != null)
                {
                    // Append the deimited path in the value textbox
                    valueBox.Text = String.IsNullOrWhiteSpace(valueBox.Text)
                        ? selectedObj.ParsingName
                        : $"{valueBox.Text};{selectedObj.ParsingName}";
                }
            }
        }
Example #3
0
        void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            SetLabelButtonStatus(IndexerCurrentFileLabel, "Running search indexer ....");

            IKnownFolder docs;

            if (ShellLibrary.IsPlatformSupported)
            {
                docs = KnownFolders.DocumentsLibrary;
            }
            else
            {
                docs = KnownFolders.Documents;
            }

            ShellContainer docsContainer = docs as ShellContainer;

            foreach (ShellObject so in docs)
            {
                RecurseDisplay(so);

                if (backgroundWorker.CancellationPending)
                {
                    SetLabelButtonStatus(StartStopIndexerButton, "Start Search Indexer");
                    SetLabelButtonStatus(IndexerStatusLabel, "Click \"Start Search Indexer\" to run the indexer");
                    SetLabelButtonStatus(IndexerCurrentFileLabel, (cancelReason == "powerSourceChanged") ?
                                         "Indexing cancelled due to a change in power source" :
                                         "Indexing cancelled by the user");

                    return;
                }

                Thread.Sleep(1000); // sleep a second to indicate indexing the file
            }
        }
Example #4
0
        void SearchScopesCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            StackPanel previousSelection = e.RemovedItems[0] as StackPanel;

            if (SearchScopesCombo.SelectedIndex == 0)
            {
                // Show a folder selection dialog
                CommonOpenFileDialog cfd = new CommonOpenFileDialog();
                cfd.AllowNonFileSystemItems = true;
                cfd.IsFolderPicker          = true;

                cfd.Title = "Select a folder as your search scope...";

                if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    ShellContainer container = cfd.FileAsShellObject as ShellContainer;

                    if (container != null)
                    {
                        #region Add it to the bottom of our combobox
                        StackPanel panel = new StackPanel();
                        panel.Margin      = new Thickness(5, 2, 5, 2);
                        panel.Orientation = Orientation.Horizontal;

                        Image img = new Image();
                        img.Source = container.Thumbnail.SmallBitmapSource;
                        img.Height = 32;

                        TextBlock textBlock = new TextBlock();
                        textBlock.Background        = Brushes.Transparent;
                        textBlock.FontSize          = 10;
                        textBlock.Margin            = new Thickness(4);
                        textBlock.VerticalAlignment = VerticalAlignment.Center;
                        textBlock.Text = container.Name;

                        panel.Children.Add(img);
                        panel.Children.Add(textBlock);

                        SearchScopesCombo.Items.Add(panel);
                        #endregion

                        // Set our selected scope
                        selectedScope = container;
                        SearchScopesCombo.SelectedItem = panel;
                    }
                    else
                    {
                        SearchScopesCombo.SelectedItem = previousSelection;
                    }
                }
                else
                {
                    SearchScopesCombo.SelectedItem = previousSelection;
                }
            }
            else if (SearchScopesCombo.SelectedItem != null && SearchScopesCombo.SelectedItem is ShellContainer)
            {
                selectedScope = ((StackPanel)SearchScopesCombo.SelectedItem).Tag as ShellContainer;
            }
        }
Example #5
0
        private void GetPictures(ShellContainer folder)
        {
            // Just for demo purposes, stop at 20 pics
            if (picturesList.Count >= 20)
            {
                return;
            }

            // First get the pictures in this folder
            foreach (ShellFile sf in folder.OfType <ShellFile>())
            {
                string ext = Path.GetExtension(sf.Path).ToLower();

                if (ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp")
                {
                    ListViewItem item = new ListViewItem();
                    item.Text       = sf.Name;
                    item.ImageIndex = imgListCount;
                    item.Tag        = sf.Path;
                    imgList.Images.Add(Image.FromFile(sf.Path));

                    picturesList.Add(item);
                    imgListCount++;
                }
            }

            // Then recurse into each subfolder
            foreach (ShellContainer subFolder in folder.OfType <ShellContainer>())
            {
                GetPictures(subFolder);
            }
        }
        private void GetAllDirRec(ShellObject path)
        {
            AllDirsCount = 0;
            ShellContainer con = (ShellContainer)ShellContainer.FromParsingName(path.ParsingName);

            foreach (ShellObject item in con)
            {
                try
                {
                    if (item.IsFolder)
                    {
                        try
                        {
                            AllDirsCount++;
                            GetFilesRec(item);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
            con.Dispose();
        }
        private void AddLocation(ShellContainer so)
        {
            StackPanel sp = new StackPanel();

            sp.Orientation = Orientation.Horizontal;

            // Add the thumbnail/icon
            Image img = new Image();

            // Because we might be called from a different thread, freeze the bitmap source once
            // we get it
            BitmapSource smallBitmapSource = so.Thumbnail.SmallBitmapSource;

            smallBitmapSource.Freeze();
            img.Source = smallBitmapSource;

            img.Margin = new Thickness(5);
            sp.Children.Add(img);

            // Add the name/title
            TextBlock tb = new TextBlock();

            tb.Text   = so.Name;
            tb.Margin = new Thickness(5);
            sp.Children.Add(tb);

            // Set our tag as the shell container user picked...
            sp.Tag = so;

            //
            locationsListBox.Items.Add(sp);
        }
        private void GetFilesRec(ShellObject path)
        {
            ShellContainer con = (ShellContainer)ShellContainer.FromParsingName(path.ParsingName);

            foreach (ShellObject item in con)
            {
                try
                {
                    if (item.IsFolder)
                    {
                        try
                        {
                            GetFilesRec(item);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else
                    {
                        shol.Add(item);
                    }
                }
                catch (Exception)
                {
                }
            }
            con.Dispose();
        }
Example #9
0
        private void HandleBrowseButtonClick(object sender, RoutedEventArgs e)
        {
            var cfd = new CommonOpenFileDialog
            {
                EnsureReadOnly          = true,
                IsFolderPicker          = true,
                AllowNonFileSystemItems = true
            };

            if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                ShellContainer shellContainer = null;

                try
                {
                    // Try to get a valid selected item
                    shellContainer = (ShellContainer)cfd.FileAsShellObject;
                }
                catch
                {
                    MessageBox.Show("Could not create a ShellObject from the selected item");
                }

                FolderPath = shellContainer.ParsingName;
            }
        }
Example #10
0
        private void cfdLibraryButton_Click(object sender, EventArgs e)
        {
            // Initialize
            detailsListView.Items.Clear();
            pictureBox1.Image = null;

            // If the user has selected a library,
            // try to get the known folder path (Libraries are also known folders, so this will work)
            if (librariesComboBox.SelectedIndex > -1)
            {
                string         selection      = librariesComboBox.SelectedItem as string;
                ShellContainer selectedFolder = null;

                switch (selection)
                {
                case "Documents":
                    selectedFolder = KnownFolders.DocumentsLibrary as ShellContainer;
                    break;

                case "Music":
                    selectedFolder = KnownFolders.MusicLibrary as ShellContainer;
                    break;

                case "Pictures":
                    selectedFolder = KnownFolders.PicturesLibrary as ShellContainer;
                    break;

                case "Videos":
                    selectedFolder = KnownFolders.VideosLibrary as ShellContainer;
                    break;
                }
                ;

                // Create a CommonOpenFileDialog
                CommonOpenFileDialog cfd = new CommonOpenFileDialog();
                cfd.EnsureReadOnly = true;

                // Set the initial location as the path of the library
                cfd.InitialDirectoryShellContainer = selectedFolder;

                if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    // Get the selection from the user.
                    ShellObject so = cfd.FileAsShellObject;

                    currentlySelected = so;

                    showChildItemsButton.Enabled = so is ShellContainer ? true : false;

                    DisplayProperties(so);
                }
            }
        }
Example #11
0
        /// <summary>
        /// This method creates a shell object from a file path. This shell object will
        /// allow the retrieval of property values.
        /// </summary>
        private static ShellObject createShellObject(string filePath)
        {
            try
            {
                return(ShellContainer.FromParsingName(filePath));
            }
            catch (ShellException)
            {
                Console.WriteLine("Unable to create a ShellObject from this input. Please enter a path to an existing file or directory.");
                restartProgram = true;
            }

            return(null);
        }
Example #12
0
        private void GraphicImportButton_Clicked(object sender, RoutedEventArgs e)
        {
            string filePath = string.Empty;

            ShellContainer selectedFolder = null;

            selectedFolder = KnownFolders.Computer as ShellContainer;
            CommonOpenFileDialog openFileDialog = new CommonOpenFileDialog();

            openFileDialog.InitialDirectoryShellContainer = selectedFolder;
            openFileDialog.EnsurePathExists = true;
            openFileDialog.EnsureFileExists = true;
            openFileDialog.DefaultExtension = "dat";
            openFileDialog.EnsureReadOnly   = true;

            if (openFileDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                filePath = openFileDialog.FileName;

                TabItem newTabItem = new TabItem();
                newTabItem.Header = System.IO.Path.GetFileNameWithoutExtension(filePath);



                ScrollViewer scrollViewer = null;
                try
                {
                    using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite))
                    {
                        scrollViewer = XamlReader.Load(fs) as ScrollViewer;
                    }
                }
                catch (Exception ex)
                {
                }
                if (scrollViewer != null)
                {
                    GraphicPanelControl graphicsPanelControl = new GraphicPanelControl(scrollViewer);
                    //graphicsPanelControl.ImportFile(scrollViewer);
                    newTabItem.Content = graphicsPanelControl;
                    this.tabControl.Items.Add(newTabItem);
                    newTabItem.IsSelected = true;
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = true;
            ShellContainer     con = (ShellContainer)this.ShellObject;
            List <ShellObject> joe = new List <ShellObject>();

            foreach (ShellObject item in con)
            {
                if (item.IsFolder)
                {
                    if (!item.ParsingName.EndsWith(".zip"))
                    {
                        joe.Add(item);
                    }
                }
            }

            joe.Sort(delegate(ShellObject j1, ShellObject j2) { return(j1.GetDisplayName(DisplayNameType.Default).CompareTo(j2.GetDisplayName(DisplayNameType.Default))); });
            DropDownMenu.Items.Clear();
            foreach (ShellObject thing in joe)
            {
                Fluent.MenuItem pan = new Fluent.MenuItem();
                thing.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly;
                thing.Thumbnail.CurrentSize  = new Size(16, 16);
                pan.Icon = thing.Thumbnail.BitmapSource;
                var header        = thing.GetDisplayName(DisplayNameType.Default);
                var posunderscore = header.IndexOf("_");
                if (posunderscore != -1)
                {
                    header = header.Insert(posunderscore, "_");
                }
                pan.Header = header;
                pan.Height = 23;
                pan.Tag    = thing;

                pan.Click += new RoutedEventHandler(MenuItemClicked);
                this.DropDownMenu.Items.Add(pan);
            }
            if (DropDownMenu.Items.Count > 0)
            {
                DropDownMenu.Placement       = PlacementMode.Bottom;
                DropDownMenu.PlacementTarget = Base;
                DropDownMenu.IsOpen          = true;
            }
        }
        private void Change_Folder(object sender, RoutedEventArgs e)
        {
            ShellContainer selectedFolder = null;

            selectedFolder = KnownFolders.SampleVideos as ShellContainer;

            CommonOpenFileDialog cfd = new CommonOpenFileDialog();

            cfd.IsFolderPicker = true;
            cfd.InitialDirectoryShellContainer = selectedFolder;
            cfd.EnsureReadOnly = true;
            if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                SetConfFile(cfd.FileName);
                pathMedia = cfd.FileName;
                SetFileList();
            }
        }
Example #15
0
        private void showChildItemsButton_Click(object sender, EventArgs e)
        {
            ShellContainer container = currentlySelected as ShellContainer;

            if (container == null)
            {
                return;
            }

            SubItemsForm subItems = new SubItemsForm();

            // Populate
            foreach (ShellObject so in container)
            {
                subItems.AddItem(so.Name, so.Thumbnail.SmallBitmap);
            }

            subItems.ShowDialog();
        }
        public void LoadDirectory(ShellObject obj)
        {
            obj.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly;
            obj.Thumbnail.CurrentSize  = new Size(16, 16);
            this.PathImage.Source      = obj.Thumbnail.BitmapSource;
            this.pathName.Text         = obj.GetDisplayName(DisplayNameType.Default);
            this.so = obj;
            path    = obj.ParsingName;

            Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)(() =>
            {
                if (obj.ParsingName == KnownFolders.Network.ParsingName || obj.ParsingName.StartsWith(@"\\"))
                {
                    SetChildren(true);
                    grid1.Visibility = System.Windows.Visibility.Visible;
                    MenuBorder.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    try
                    {
                        ShellContainer con = (ShellContainer)obj;
                        List <ShellObject> joe = new List <ShellObject>();
                        foreach (ShellObject item in con)
                        {
                            if (item.IsFolder == true)
                            {
                                if (item.ParsingName.ToLower().EndsWith(".zip") == false && item.ParsingName.ToLower().EndsWith(".cab") == false)
                                {
                                    joe.Add(item);
                                }
                            }
                        }
                        SetChildren(joe.Count > 0);
                    }
                    catch
                    {
                        SetChildren(false);
                    }
                }
            }));
        }
Example #17
0
        /// <summary>
        /// Adds a location, such as a folder, library, search connector, or known folder, to the list of
        /// places available for a user to open or save items. This method actually adds an item
        /// to the <b>Favorite Links</b> or <b>Places</b> section of the Open/Save dialog.
        /// </summary>
        /// <param name="place">The item to add to the places list.</param>
        /// <param name="location">One of the enumeration values that indicates placement of the item in the list.</param>
        public void AddPlace(ShellContainer place, FileDialogAddPlaceLocation location)
        {
            if (place == null)
            {
                throw new ArgumentNullException("place");
            }

            // Get our native dialog
            if (nativeDialog == null)
            {
                InitializeNativeFileDialog();
                nativeDialog = GetNativeFileDialog();
            }

            // Add the shellitem to the places list
            if (nativeDialog != null)
            {
                nativeDialog.AddPlace(place.NativeShellItem, (ShellNativeMethods.FileDialogAddPlacement)location);
            }
        }
        private void Open_File(object sender, RoutedEventArgs e)
        {
            ShellContainer selectedFolder = null;

            selectedFolder = KnownFolders.SampleVideos as ShellContainer;
            CommonOpenFileDialog cfd = new CommonOpenFileDialog();

            cfd.InitialDirectoryShellContainer = selectedFolder;
            cfd.EnsureReadOnly = true;
            cfd.Filters.Add(new CommonFileDialogFilter("MP4 Files", "*.mp4"));
            cfd.Filters.Add(new CommonFileDialogFilter("WMV Files", "*.wmv"));
            cfd.Filters.Add(new CommonFileDialogFilter("AVI Files", "*.avi"));

            cfd.Filters.Add(new CommonFileDialogFilter("MPE Files", "*.mp3"));

            if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                mediaElement1.Source = new Uri(cfd.FileName, UriKind.Relative);
            }
        }
Example #19
0
        private void InitListView()
        {
            imgList            = new ImageList();
            imgList.ImageSize  = new Size(96, 96);
            imgList.ColorDepth = ColorDepth.Depth32Bit;

            listView1.LargeImageList = imgList;

            ShellContainer pics = (ShellContainer)KnownFolders.Pictures;

            if (ShellLibrary.IsPlatformSupported)
            {
                pics = (ShellContainer)KnownFolders.PicturesLibrary;
            }

            if (picturesList == null)
            {
                picturesList = new List <ListViewItem>();
            }
            else
            {
                picturesList.Clear();
            }

            // Recursively get the pictures
            GetPictures(pics);

            if (picturesList.Count == 0)
            {
                if (pics is ShellLibrary)
                {
                    TaskDialog.Show("Please add some pictures to the library", "Pictures library is empty", "No pictures found");
                }
                else
                {
                    TaskDialog.Show("Please add some pictures to your pictures folder", "Pictures folder is empty", "No pictures found");
                }
            }

            listView1.Items.AddRange(picturesList.ToArray());
        }
Example #20
0
        public static string SelectDirectory(ShellContainer SContainer, ILanguage Language = null)
        {
            using (var Container = SContainer)
                using (CommonOpenFileDialog SaveAs = new CommonOpenFileDialog())
                {
                    SaveAs.AddPlace(Container, FileDialogAddPlaceLocation.Top);
                    SaveAs.AddPlace(KnownFolders.Desktop as ShellContainer, FileDialogAddPlaceLocation.Top);
                    SaveAs.Title            = Language.SelectASaveDir ?? "Select a Directory";
                    SaveAs.ShowPlacesList   = true;
                    SaveAs.IsFolderPicker   = true;
                    SaveAs.EnsurePathExists = true;

                    var DR = SaveAs.ShowDialog();
                    if (DR != CommonFileDialogResult.Ok)
                    {
                        return(null);
                    }

                    return(SaveAs.FileName);
                }
        }
Example #21
0
        private void RecurseDisplay(ShellObject so)
        {
            if (backgroundWorker.CancellationPending)
            {
                return;
            }

            SetLabelButtonStatus(IndexerCurrentFileLabel,
                                 string.Format("Current {0}: {1}", so is ShellContainer ? "Folder" : "File", so.ParsingName));

            // Loop through this object's child items if it's a container
            ShellContainer container = so as ShellContainer;

            if (container != null)
            {
                foreach (ShellObject child in container)
                {
                    RecurseDisplay(child);
                }
            }
        }
Example #22
0
        internal void ExplorerTreeView_Expanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem   sourceItem     = sender as TreeViewItem;
            ShellContainer shellContainer = sourceItem.Header as ShellContainer;

            if (sourceItem.Items.Count > 0 && sourceItem.Items[0].Equals(":::"))
            {
                sourceItem.Items.Clear();
                try
                {
                    foreach (ShellObject obj in shellContainer)
                    {
                        TreeViewItem item = new TreeViewItem();
                        item.Header = obj;
                        if (obj is ShellContainer)
                        {
                            item.Items.Add(":::");
                            item.Expanded += ExplorerTreeView_Expanded;
                        }
                        item.Selected += new RoutedEventHandler(item_Selected);
                        sourceItem.Items.Add(item);
                    }
                }
                catch (FileNotFoundException)
                {
                    // Device might not be ready
                    MessageBox.Show("The device or directory is not ready.", "Shell Hierarchy Tree Demo");
                }
                catch (ArgumentException)
                {
                    // Device might not be ready
                    MessageBox.Show("The directory is currently not accessible.", "Shell Hierarchy Tree Demo");
                }
                catch (UnauthorizedAccessException)
                {
                    MessageBox.Show("You don't currently have permission to access this folder.", "Shell Hierarchy Tree Demo");
                }
            }
        }
Example #23
0
        protected ShellTreeItem(ShellObject shellObj, ShellTreeContainerItem parent, IShellItemsOperation shellItemsOperation)
        {
            _shellObj            = shellObj;
            _shellContainer      = shellObj as ShellContainer;
            _parent              = parent;
            _shellItemsOperation = shellItemsOperation;
            _childrenView        =
                new LiveListCollectionView(_children)
            {
                Filter = o => shellItemsOperation.Filter((ShellTreeItem)o)
            }; // {FilterDescriptions = shellItemsOperation.FilterDescriptionCollection};
            if (_shellObj != null)
            {
                _name = _shellObj.Name;
            }

            if (_shellContainer != null)
            {
                _children.Add(DummyChild);
                PreloadThumbnails();
            }
        }
Example #24
0
        private void BtnFolder_OnClick(object sender, RoutedEventArgs e)
        {
            // Display a CommonOpenFileDialog to select only folders
            CommonOpenFileDialog cfd = new CommonOpenFileDialog();

            cfd.EnsureReadOnly          = true;
            cfd.IsFolderPicker          = true;
            cfd.AllowNonFileSystemItems = true;
            if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                ShellContainer selectedSO = null;
                try
                {
                    selectedSO = cfd.FileAsShellObject as ShellContainer;
                }
                catch
                {
                    MessageBox.Show("Could not create a ShellObject from the selected item");
                }
                Creater.Uri = selectedSO.ParsingName;
                this.Activate();
            }
        }
Example #25
0
        private void cfdFolderButton_Click(object sender, EventArgs e)
        {
            // Initialize
            detailsListView.Items.Clear();
            pictureBox1.Image = null;

            // Display a CommonOpenFileDialog to select only folders
            CommonOpenFileDialog cfd = new CommonOpenFileDialog();

            cfd.EnsureReadOnly          = true;
            cfd.IsFolderPicker          = true;
            cfd.AllowNonFileSystemItems = true;

            if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
            {
                ShellContainer selectedSO = null;

                try
                {
                    // Try to get a valid selected item
                    selectedSO = cfd.FileAsShellObject as ShellContainer;
                }
                catch
                {
                    MessageBox.Show("Could not create a ShellObject from the selected item");
                }

                currentlySelected = selectedSO;

                // Set the path in our filename textbox
                selectedFolderTextBox.Text = selectedSO.ParsingName;

                DisplayProperties(selectedSO);

                showChildItemsButton.Enabled = selectedSO is ShellContainer ? true : false;
            }
        }
Example #26
0
        void SearchScopesCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            StackPanel previousSelection = e.RemovedItems[0] as StackPanel;

            if (SearchScopesCombo.SelectedIndex == 0)
            {
                // Show a folder selection dialog
                CommonOpenFileDialog cfd = new CommonOpenFileDialog();
                cfd.AllowNonFileSystemItems = true;
                cfd.IsFolderPicker = true;

                cfd.Title = "Select a folder as your search scope...";

                if (cfd.ShowDialog() == CommonFileDialogResult.OK)
                {
                    ShellContainer container = cfd.FileAsShellObject as ShellContainer;

                    if (container != null)
                    {
                        #region Add it to the bottom of our combobox
                        StackPanel panel = new StackPanel();
                        panel.Margin = new Thickness(5, 2, 5, 2);
                        panel.Orientation = Orientation.Horizontal;

                        Image img = new Image();
                        img.Source = container.Thumbnail.SmallBitmapSource;
                        img.Height = 32;

                        TextBlock textBlock = new TextBlock();
                        textBlock.Background = Brushes.Transparent;
                        textBlock.FontSize = 10;
                        textBlock.Margin = new Thickness(4);
                        textBlock.VerticalAlignment = VerticalAlignment.Center;
                        textBlock.Text = container.Name;

                        panel.Children.Add(img);
                        panel.Children.Add(textBlock);

                        SearchScopesCombo.Items.Add(panel);
                        #endregion

                        // Set our selected scope
                        selectedScope = container;
                        SearchScopesCombo.SelectedItem = panel;
                    }
                    else
                        SearchScopesCombo.SelectedItem = previousSelection;
                }
                else
                    SearchScopesCombo.SelectedItem = previousSelection;
            }
            else if (SearchScopesCombo.SelectedItem != null && SearchScopesCombo.SelectedItem is ShellContainer)
                selectedScope = ((StackPanel)SearchScopesCombo.SelectedItem).Tag as ShellContainer;
        }
Example #27
0
 public WindowsShellFolder(ShellContainer folder, IWindowsShellFolder parent, Func <WindowsShellFolder, Task <IReadOnlyCollection <IWindowsShellFile> > > filesFunc) : base(parent)
 {
     _folder    = folder;
     _filesFunc = filesFunc;
 }
        private void AddLocation(ShellContainer so)
        {
            StackPanel sp = new StackPanel();
            sp.Orientation = Orientation.Horizontal;

            // Add the thumbnail/icon
            Image img = new Image();

            // Because we might be called from a different thread, freeze the bitmap source once
            // we get it
            BitmapSource smallBitmapSource = so.Thumbnail.SmallBitmapSource;
            smallBitmapSource.Freeze();
            img.Source = smallBitmapSource;

            img.Margin = new Thickness(5);
            sp.Children.Add(img);

            // Add the name/title
            TextBlock tb = new TextBlock();
            tb.Text = so.Name;
            tb.Margin = new Thickness(5);
            sp.Children.Add(tb);

            // Set our tag as the shell container user picked...
            sp.Tag = so;

            //
            locationsListBox.Items.Add(sp);
        }
        /// <summary>
        /// Constructs a new Shell object from IDList pointer
        /// </summary>
        /// <param name="idListPtr"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        internal static ShellObject Create(IntPtr idListPtr, ShellContainer parent)
        {
            IShellItem nativeShellItem;

            int retCode = ShellNativeMethods.SHCreateShellItem(
                IntPtr.Zero,
                parent.NativeShellFolder,
                idListPtr, out nativeShellItem);

            if (!CoreErrorHelper.Succeeded(retCode)) { return null; }

            return ShellObjectFactory.Create(nativeShellItem);
        }
        /// <summary>
        /// Adds a location, such as a folder, library, search connector, or known folder, to the list of
        /// places available for a user to open or save items. This method actually adds an item
        /// to the <b>Favorite Links</b> or <b>Places</b> section of the Open/Save dialog.
        /// </summary>
        /// <param name="place">The item to add to the places list.</param>
        /// <param name="location">One of the enumeration values that indicates placement of the item in the list.</param>
        public void AddPlace(ShellContainer place, FileDialogAddPlaceLocation location)
        {
            if (place == null)
            {
                throw new ArgumentNullException("place");
            }

            // Get our native dialog
            if (nativeDialog == null)
            {
                InitializeNativeFileDialog();
                nativeDialog = GetNativeFileDialog();
            }

            // Add the shellitem to the places list
            if (nativeDialog != null)
            {
                nativeDialog.AddPlace(place.NativeShellItem, (ShellNativeMethods.FileDialogAddPlacement)location);
            }
        }
        private void GetPictures(ShellContainer folder)
        {
            // Just for demo purposes, stop at 20 pics
            if (picturesList.Count >= 20)
                return;

            // First get the pictures in this folder
            foreach (ShellFile sf in folder.OfType<ShellFile>())
            {
                string ext = Path.GetExtension(sf.Path).ToLower();

                if (ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp")
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = sf.Name;
                    item.ImageIndex = imgListCount;
                    item.Tag = sf.Path;
                    imgList.Images.Add(Image.FromFile(sf.Path));

                    picturesList.Add(item);
                    imgListCount++;
                }
            }

            // Then recurse into each subfolder
            foreach (ShellContainer subFolder in folder.OfType<ShellContainer>())
                GetPictures(subFolder);
        }
        /// <summary>
        /// Constructs a new Shell object from IDList pointer
        /// </summary>
        /// <param name="idListPtr"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        internal static ShellObject Create(IntPtr idListPtr, ShellContainer parent)
        {
            IShellItem nativeShellItem;

            int retCode = ShellNativeMethods.SHCreateShellItem(
                IntPtr.Zero,
                parent.NativeShellFolder,
                idListPtr, out nativeShellItem);

            if (CoreErrorHelper.Succeeded(retCode))
            {
                return ShellObjectFactory.Create(nativeShellItem);
            }
            else
            {
                // Since this is an internal method, return null instead of throwing an exception.
                // Let the caller know we weren't able to create a valid ShellObject with the given PIDL
                return null;
            }
        }
Example #33
0
        private void GetPictures(ShellContainer folder)
        {
            // Just for demo purposes, stop at 20 pics
            if (picturesList.Count >= 20)
                return;

            // First get the pictures in this folder
            foreach (ShellFile sf in folder.OfType<ShellFile>())
            {
                string ext = Path.GetExtension(sf.Path).ToLower();

                if (ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp")
                    picturesList.Add(sf);
            }

            // Then recurse into each subfolder
            foreach (ShellContainer subFolder in folder.OfType<ShellContainer>())
                GetPictures(subFolder);
        }
        /// <summary>
        /// Adds a location, such as a folder, library, search connector, or known folder, to the list of
        /// places available for a user to open or save items. This method actually adds an item
        /// to the <b>Favorite Links</b> or <b>Places</b> section of the Open/Save dialog.
        /// </summary>
        /// <param name="place">The item to add to the places list.</param>
        /// <param name="location">One of the enumeration values that indicates placement of the item in the list.</param>
        public void AddPlace(ShellContainer place, FileDialogAddPlaceLocation location)
        {
            // Get our native dialog
            if (nativeDialog == null)
            {
                InitializeNativeFileDialog();
                nativeDialog = GetNativeFileDialog();
            }

            // Add the shellitem to the places list
            if (nativeDialog != null)
                nativeDialog.AddPlace(((ShellObject)place).NativeShellItem, (ShellNativeMethods.FDAP)location);
        }