예제 #1
0
        public static void AddNewTabByPath(Type type, string path, int atIndex = -1)
        {
            Microsoft.UI.Xaml.Controls.FontIconSource fontIconSource = new Microsoft.UI.Xaml.Controls.FontIconSource();
            fontIconSource.FontFamily = App.Current.Resources["FluentUIGlyphs"] as FontFamily;

            if (string.IsNullOrEmpty(path))
            {
                path = "NewTab".GetLocalized();
            }

            TabItem tabItem = new TabItem()
            {
                Header      = null,
                IconSource  = fontIconSource,
                Description = null
            };

            tabItem.Control.NavigationArguments = new TabItemArguments()
            {
                InitialPageType = type,
                NavigationArg   = path
            };
            tabItem.Control.ContentChanged += Control_ContentChanged;
            SetSelectedTabInfo(tabItem, path);
            AppInstances.Insert(atIndex == -1 ? AppInstances.Count : atIndex, tabItem);
        }
예제 #2
0
        public void FontIconSourceTest()
        {
            FontIconSource iconSource = null;

            RunOnUIThread.Execute(() =>
            {
                iconSource = new FontIconSource();

                // IconSource.Foreground should be null to allow foreground inheritance from
                // the parent to work.
                Verify.AreEqual(iconSource.Foreground, null);

                Log.Comment("Validate the defaults match FontIcon.");

                var icon = new FontIcon();
                Verify.AreEqual(icon.Glyph, iconSource.Glyph);
                Verify.AreEqual(icon.FontSize, iconSource.FontSize);
                Verify.AreEqual(icon.FontStyle, iconSource.FontStyle);
                Verify.AreEqual(icon.FontWeight.Weight, iconSource.FontWeight.Weight);
                Verify.AreEqual(icon.FontFamily.Source, iconSource.FontFamily.Source);
                Verify.AreEqual(icon.IsTextScaleFactorEnabled, iconSource.IsTextScaleFactorEnabled);
                Verify.AreEqual(icon.MirroredWhenRightToLeft, iconSource.MirroredWhenRightToLeft);

                Log.Comment("Validate that you can change the properties.");

                iconSource.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                iconSource.Glyph      = "";
                iconSource.FontSize   = 25;
                iconSource.FontStyle  = FontStyle.Oblique;
                iconSource.FontWeight = new FontWeight()
                {
                    Weight = 250
                };
                iconSource.FontFamily = new FontFamily("Segoe UI Symbol");
                iconSource.IsTextScaleFactorEnabled = true;
                iconSource.MirroredWhenRightToLeft  = true;
            });
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                Verify.IsTrue(iconSource.Foreground is SolidColorBrush);
                Verify.AreEqual(Windows.UI.Colors.Red, (iconSource.Foreground as SolidColorBrush).Color);
                Verify.AreEqual("", iconSource.Glyph);
                Verify.AreEqual(25, iconSource.FontSize);
                Verify.AreEqual(FontStyle.Oblique, iconSource.FontStyle);
                Verify.AreEqual(250, iconSource.FontWeight.Weight);
                Verify.AreEqual("Segoe UI Symbol", iconSource.FontFamily.Source);
                Verify.AreEqual(true, iconSource.IsTextScaleFactorEnabled);
                Verify.AreEqual(true, iconSource.MirroredWhenRightToLeft);
            });
        }
예제 #3
0
        public Task <Microsoft.UI.Xaml.Controls.IconSource> LoadIconSourceAsync(ImageSource imagesource, CancellationToken cancellationToken = default(CancellationToken))
        {
            Microsoft.UI.Xaml.Controls.IconSource image = null;

            if (imagesource is FontImageSource fontImageSource)
            {
                image = new Microsoft.UI.Xaml.Controls.FontIconSource
                {
                    Glyph      = fontImageSource.Glyph,
                    FontFamily = new FontFamily(fontImageSource.FontFamily),
                    FontSize   = fontImageSource.Size,
                    Foreground = fontImageSource.Color.ToBrush()
                };
            }

            return(Task.FromResult(image));
        }
예제 #4
0
        public static void AddNewTabByParam(Type type, object tabViewItemArgs, int atIndex = -1)
        {
            Microsoft.UI.Xaml.Controls.FontIconSource fontIconSource = new Microsoft.UI.Xaml.Controls.FontIconSource();
            fontIconSource.FontFamily = App.Current.Resources["FluentUIGlyphs"] as FontFamily;

            TabItem tabItem = new TabItem()
            {
                Header      = null,
                IconSource  = fontIconSource,
                Description = null
            };

            tabItem.Control.NavigationArguments = new TabItemArguments()
            {
                InitialPageType = type,
                NavigationArg   = tabViewItemArgs
            };
            tabItem.Control.ContentChanged += Control_ContentChanged;
            UpdateTabInfo(tabItem, tabViewItemArgs);
            AppInstances.Insert(atIndex == -1 ? AppInstances.Count : atIndex, tabItem);
        }
예제 #5
0
        public Task <Microsoft.UI.Xaml.Controls.IconSource> LoadIconSourceAsync(ImageSource imagesource, CancellationToken cancellationToken = default(CancellationToken))
        {
            Microsoft.UI.Xaml.Controls.IconSource image = null;

            if (imagesource is FontImageSource fontImageSource)
            {
                image = new WFontIconSource
                {
                    Glyph      = fontImageSource.Glyph,
                    FontSize   = fontImageSource.Size,
                    Foreground = fontImageSource.Color.ToBrush()
                };

                var uwpFontFamily = fontImageSource.FontFamily.ToFontFamily();

                if (!string.IsNullOrEmpty(uwpFontFamily.Source))
                {
                    ((WFontIconSource)image).FontFamily = uwpFontFamily;
                }
            }

            return(Task.FromResult(image));
        }
예제 #6
0
        public static async Task AddNewTabByPathAsync(Type type, string path, int atIndex = -1)
        {
            string tabLocationHeader = string.Empty;

            Microsoft.UI.Xaml.Controls.FontIconSource fontIconSource = new Microsoft.UI.Xaml.Controls.FontIconSource();
            fontIconSource.FontFamily = App.Current.Resources["FluentUIGlyphs"] as FontFamily;

            if (string.IsNullOrEmpty(path))
            {
                path = "NewTab".GetLocalized();
            }

            if (path != null)
            {
                var isRoot = Path.GetPathRoot(path) == path;

                if (Path.IsPathRooted(path) || isRoot) // Or is a directory or a root (drive)
                {
                    var normalizedPath = NormalizePath(path);

                    var dirName = Path.GetDirectoryName(normalizedPath);
                    if (dirName != null)
                    {
                        tabLocationHeader    = Path.GetFileName(path);
                        fontIconSource.Glyph = "\xea55";
                    }
                    else
                    {
                        // Pick the best icon for this tab
                        var remDriveNames = (await KnownFolders.RemovableDevices.GetFoldersAsync()).Select(x => x.DisplayName);

                        if (!remDriveNames.Contains(normalizedPath))
                        {
                            if (path != "A:" && path != "B:")    // Check if it's using (generally) floppy-reserved letters.
                            {
                                fontIconSource.Glyph = "\xeb4a"; // Floppy Disk icon
                            }
                            else
                            {
                                fontIconSource.Glyph = "\xeb8b"; // Hard Disk icon
                            }

                            tabLocationHeader = normalizedPath;
                        }
                        else
                        {
                            fontIconSource.Glyph = "\xec0a";
                            tabLocationHeader    = (await KnownFolders.RemovableDevices.GetFolderAsync(path)).DisplayName;
                        }
                    }
                }
                else
                {
                    // Invalid path, open new tab instead (explorer opens Documents when it fails)
                    Debug.WriteLine($"Invalid path \"{path}\" in InstanceTabsView.xaml.cs\\AddNewTab");

                    path = "NewTab".GetLocalized();
                    tabLocationHeader    = "NewTab".GetLocalized();
                    fontIconSource.Glyph = "\xe90c";
                }
            }

            TabItem tabItem = new TabItem()
            {
                Header  = tabLocationHeader,
                Path    = path,
                Content = new Grid()
                {
                    Children =
                    {
                        new Frame()
                        {
                            CacheSize = 0,
                            Tag       = new TabItemContent()
                            {
                                InitialPageType = type,
                                NavigationArg   = path
                            }
                        }
                    },
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Stretch
                },
                IconSource  = fontIconSource,
                Description = null
            };

            AppInstances.Insert(atIndex == -1 ? AppInstances.Count : atIndex, tabItem);
            var tabViewItemFrame = (tabItem.Content as Grid).Children[0] as Frame;

            tabViewItemFrame.Loaded += TabViewItemFrame_Loaded;
        }
예제 #7
0
        private static void SetSelectedTabInfo(TabItem selectedTabItem, string currentPath, string tabHeader = null)
        {
            selectedTabItem.AllowStorageItemDrop = true;

            string tabLocationHeader;

            Microsoft.UI.Xaml.Controls.FontIconSource fontIconSource = new Microsoft.UI.Xaml.Controls.FontIconSource();
            Microsoft.UI.Xaml.Controls.IconSource     tabIcon;
            fontIconSource.FontFamily = App.Current.Resources["FluentUIGlyphs"] as FontFamily;

            if (currentPath == null || currentPath == "SidebarSettings/Text".GetLocalized())
            {
                tabLocationHeader    = "SidebarSettings/Text".GetLocalized();
                fontIconSource.Glyph = "\xeb5d";
            }
            else if (currentPath == null || currentPath == "NewTab".GetLocalized() || currentPath == "Home")
            {
                tabLocationHeader    = "NewTab".GetLocalized();
                fontIconSource.Glyph = "\xe90c";
            }
            else if (currentPath.Equals(App.AppSettings.DesktopPath, StringComparison.OrdinalIgnoreCase))
            {
                tabLocationHeader    = "SidebarDesktop".GetLocalized();
                fontIconSource.Glyph = "\xe9f1";
            }
            else if (currentPath.Equals(App.AppSettings.DownloadsPath, StringComparison.OrdinalIgnoreCase))
            {
                tabLocationHeader    = "SidebarDownloads".GetLocalized();
                fontIconSource.Glyph = "\xe91c";
            }
            else if (currentPath.Equals(App.AppSettings.DocumentsPath, StringComparison.OrdinalIgnoreCase))
            {
                tabLocationHeader    = "SidebarDocuments".GetLocalized();
                fontIconSource.Glyph = "\xEA11";
            }
            else if (currentPath.Equals(App.AppSettings.PicturesPath, StringComparison.OrdinalIgnoreCase))
            {
                tabLocationHeader    = "SidebarPictures".GetLocalized();
                fontIconSource.Glyph = "\xEA83";
            }
            else if (currentPath.Equals(App.AppSettings.MusicPath, StringComparison.OrdinalIgnoreCase))
            {
                tabLocationHeader    = "SidebarMusic".GetLocalized();
                fontIconSource.Glyph = "\xead4";
            }
            else if (currentPath.Equals(App.AppSettings.VideosPath, StringComparison.OrdinalIgnoreCase))
            {
                tabLocationHeader    = "SidebarVideos".GetLocalized();
                fontIconSource.Glyph = "\xec0d";
            }
            else if (currentPath.Equals(App.AppSettings.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
            {
                var localSettings = ApplicationData.Current.LocalSettings;
                tabLocationHeader         = localSettings.Values.Get("RecycleBin_Title", "Recycle Bin");
                fontIconSource.FontFamily = Application.Current.Resources["RecycleBinIcons"] as FontFamily;
                fontIconSource.Glyph      = "\xEF87";
            }
            else if (App.AppSettings.OneDrivePath != null && currentPath.Equals(App.AppSettings.OneDrivePath, StringComparison.OrdinalIgnoreCase))
            {
                tabLocationHeader    = "OneDrive";
                fontIconSource.Glyph = "\xe9b7";
            }
            else if (App.AppSettings.OneDriveCommercialPath != null && currentPath.Equals(App.AppSettings.OneDriveCommercialPath, StringComparison.OrdinalIgnoreCase))
            {
                tabLocationHeader    = "OneDrive Commercial";
                fontIconSource.Glyph = "\xe9b7";
            }
            else
            {
                // If path is a drive's root
                if (NormalizePath(Path.GetPathRoot(currentPath)) == NormalizePath(currentPath))
                {
                    try
                    {
                        List <DriveInfo> drives        = DriveInfo.GetDrives().ToList();
                        DriveInfo        matchingDrive = drives.FirstOrDefault(x => NormalizePath(currentPath).Contains(NormalizePath(x.Name)));

                        if (matchingDrive != null)
                        {
                            //Go through types and set the icon according to type
                            string type = GetDriveTypeIcon(matchingDrive);
                            if (!string.IsNullOrWhiteSpace(type))
                            {
                                fontIconSource.Glyph = type;
                            }
                            else
                            {
                                fontIconSource.Glyph = "\xeb8b";    //Drive icon
                            }
                        }
                        else
                        {
                            fontIconSource.Glyph = "\xeb4a";    //Floppy icon
                        }
                    }
                    catch (Exception)
                    {
                        fontIconSource.Glyph = "\xeb8b";    //Fallback
                    }

                    tabLocationHeader = NormalizePath(currentPath);
                }
                else
                {
                    fontIconSource.Glyph = "\xea55";    //Folder icon
                    tabLocationHeader    = currentPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Split('\\', StringSplitOptions.RemoveEmptyEntries).Last();
                }
            }
            if (tabHeader != null)
            {
                tabLocationHeader = tabHeader;
            }
            tabIcon = fontIconSource;
            selectedTabItem.Header     = tabLocationHeader;
            selectedTabItem.IconSource = tabIcon;
        }
예제 #8
0
        public static async Task AddNewTab(Type t, string path, int atIndex = -1)
        {
            string tabLocationHeader = null;

            Microsoft.UI.Xaml.Controls.FontIconSource fontIconSource = new Microsoft.UI.Xaml.Controls.FontIconSource();
            fontIconSource.FontFamily = App.Current.Resources["FluentUIGlyphs"] as FontFamily;

            if (path != null)
            {
                if (path == "Settings")
                {
                    tabLocationHeader    = ResourceController.GetTranslation("SidebarSettings/Text");
                    fontIconSource.Glyph = "\xeb5d";
                }
                else if (path.Equals(App.AppSettings.DesktopPath, StringComparison.OrdinalIgnoreCase))
                {
                    tabLocationHeader    = ResourceController.GetTranslation("SidebarDesktop");
                    fontIconSource.Glyph = "\xe9f1";
                }
                else if (path.Equals(App.AppSettings.DownloadsPath, StringComparison.OrdinalIgnoreCase))
                {
                    tabLocationHeader    = ResourceController.GetTranslation("SidebarDownloads");
                    fontIconSource.Glyph = "\xe91c";
                }
                else if (path.Equals(App.AppSettings.DocumentsPath, StringComparison.OrdinalIgnoreCase))
                {
                    tabLocationHeader    = ResourceController.GetTranslation("SidebarDocuments");
                    fontIconSource.Glyph = "\xEA11";
                }
                else if (path.Equals(App.AppSettings.PicturesPath, StringComparison.OrdinalIgnoreCase))
                {
                    tabLocationHeader    = ResourceController.GetTranslation("SidebarPictures");
                    fontIconSource.Glyph = "\xEA83";
                }
                else if (path.Equals(App.AppSettings.MusicPath, StringComparison.OrdinalIgnoreCase))
                {
                    tabLocationHeader    = ResourceController.GetTranslation("SidebarMusic");
                    fontIconSource.Glyph = "\xead4";
                }
                else if (path.Equals(App.AppSettings.VideosPath, StringComparison.OrdinalIgnoreCase))
                {
                    tabLocationHeader    = ResourceController.GetTranslation("SidebarVideos");
                    fontIconSource.Glyph = "\xec0d";
                }
                else if (path.Equals(App.AppSettings.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
                {
                    var localSettings = ApplicationData.Current.LocalSettings;
                    tabLocationHeader         = localSettings.Values.Get("RecycleBin_Title", "Recycle Bin");
                    fontIconSource.FontFamily = Application.Current.Resources["RecycleBinIcons"] as FontFamily;
                    fontIconSource.Glyph      = "\xEF87";
                }
                else if (App.AppSettings.OneDrivePath != null && path.Equals(App.AppSettings.OneDrivePath, StringComparison.OrdinalIgnoreCase))
                {
                    tabLocationHeader    = "OneDrive";
                    fontIconSource.Glyph = "\xe9b7";
                }
                else if (path == ResourceController.GetTranslation("NewTab"))
                {
                    tabLocationHeader    = ResourceController.GetTranslation("NewTab");
                    fontIconSource.Glyph = "\xe90c";
                }
                else
                {
                    var isRoot = Path.GetPathRoot(path) == path;

                    if (Path.IsPathRooted(path) || isRoot) // Or is a directory or a root (drive)
                    {
                        var normalizedPath = NormalizePath(path);

                        var dirName = Path.GetDirectoryName(normalizedPath);
                        if (dirName != null)
                        {
                            tabLocationHeader    = Path.GetFileName(path);
                            fontIconSource.Glyph = "\xea55";
                        }
                        else
                        {
                            // Pick the best icon for this tab
                            var remDriveNames = (await KnownFolders.RemovableDevices.GetFoldersAsync()).Select(x => x.DisplayName);

                            if (!remDriveNames.Contains(normalizedPath))
                            {
                                if (path != "A:" && path != "B:")    // Check if it's using (generally) floppy-reserved letters.
                                {
                                    fontIconSource.Glyph = "\xeb4a"; // Floppy Disk icon
                                }
                                else
                                {
                                    fontIconSource.Glyph = "\xeb8b"; // Hard Disk icon
                                }
                                tabLocationHeader = normalizedPath;
                            }
                            else
                            {
                                fontIconSource.Glyph = "\xec0a";
                                tabLocationHeader    = (await KnownFolders.RemovableDevices.GetFolderAsync(path)).DisplayName;
                            }
                        }
                    }
                    else
                    {
                        // Invalid path, open new tab instead (explorer opens Documents when it fails)
                        Debug.WriteLine($"Invalid path \"{path}\" in InstanceTabsView.xaml.cs\\AddNewTab");

                        path = ResourceController.GetTranslation("NewTab");
                        tabLocationHeader    = ResourceController.GetTranslation("NewTab");
                        fontIconSource.Glyph = "\xe90c";
                    }
                }
            }

            TabItem tvi = new TabItem()
            {
                Header  = tabLocationHeader,
                Content = new Grid()
                {
                    Children =
                    {
                        new Frame()
                        {
                            CacheSize = 0,
                            Tag       = new TabItemContent()
                            {
                                InitialPageType = t,
                                NavigationArg   = path
                            }
                        }
                    },
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Stretch
                },
                IconSource  = fontIconSource,
                Description = null
            };

            MainPage.AppInstances.Insert(atIndex == -1 ? AppInstances.Count : atIndex, tvi);
            var tabViewItemFrame = (tvi.Content as Grid).Children[0] as Frame;

            tabViewItemFrame.Loaded += TabViewItemFrame_Loaded;
        }