/// <summary> /// Adds the item to the navigation page /// </summary> /// <param name="item">Item to remove</param> public async void AddItem(string item) { // add to `FavoriteItems` and `favoritesList` must be atomic await addSyncSemaphore.WaitAsync(); try { if (!string.IsNullOrEmpty(item) && !FavoriteItems.Contains(item)) { FavoriteItems.Add(item); await AddItemToSidebarAsync(item); Save(); if (item == CommonPaths.RecycleBinPath) { UserSettingsService.AppearanceSettingsService.PinRecycleBinToSidebar = true; } } } finally { addSyncSemaphore.Release(); } }
/// <summary> /// Moves the location item in the Favorites sidebar section from the old position to the new position /// </summary> /// <param name="locationItem">Location item to move</param> /// <param name="oldIndex">The old position index of the location item</param> /// <param name="newIndex">The new position index of the location item</param> /// <returns>True if the move was successful</returns> public bool MoveItem(INavigationControlItem locationItem, int oldIndex, int newIndex) { if (locationItem is null || newIndex > FavoriteItems.Count) { return(false); } // A backup of the items, because the swapping of items requires removing and inserting them in the correct position var sidebarItemsBackup = new List <string>(FavoriteItems); try { FavoriteItems.RemoveAt(oldIndex); FavoriteItems.Insert(newIndex, locationItem.Path); lock (favoriteList) { favoriteList.RemoveAt(oldIndex); favoriteList.Insert(newIndex, locationItem); } var e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, locationItem, newIndex, oldIndex); controller.DataChanged?.Invoke(SectionType.Favorites, e); Save(); return(true); } catch (Exception ex) { Debug.WriteLine($"An error occurred while moving pinned items in the Favorites sidebar section. {ex.Message}"); FavoriteItems = sidebarItemsBackup; RemoveStaleSidebarItems(); _ = AddAllItemsToSidebar(); return(false); } }
/// <summary> /// Adds the default items to the navigation page /// </summary> public void AddDefaultItems() { var udp = UserDataPaths.GetDefault(); FavoriteItems.Add(CommonPaths.DesktopPath); FavoriteItems.Add(CommonPaths.DownloadsPath); FavoriteItems.Add(udp.Documents); }
/// <summary> /// Removes the item from the navigation page /// </summary> /// <param name="item">Item to remove</param> public void RemoveItem(string item) { if (FavoriteItems.Contains(item)) { FavoriteItems.Remove(item); RemoveStaleSidebarItems(); Save(); if (item == CommonPaths.RecycleBinPath) { UserSettingsService.AppearanceSettingsService.PinRecycleBinToSidebar = false; } } }
/// <summary> /// Removes stale items in the navigation sidebar /// </summary> public void RemoveStaleSidebarItems() { // Remove unpinned items from favoriteList foreach (var childItem in Favorites) { if (childItem is LocationItem item) { if (!item.IsDefaultLocation && !FavoriteItems.Contains(item.Path)) { lock (favoriteList) { favoriteList.Remove(item); } controller.DataChanged?.Invoke(SectionType.Favorites, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item)); } } } // Remove unpinned items from sidebar controller.DataChanged?.Invoke(SectionType.Favorites, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }
private static void createDefaultData() { if (Session.Count == 0) { Session.Add(new ColumnData( typeof(DirectoryColumn).FullName, Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) )); } if (FavoriteItems.Count == 0) { FavoriteItems.Add(new ColumnData( typeof(DirectoryColumn).FullName, Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) )); } CreatePreference("directorycolumn.directory_exclude_patterns", new List <object>(new object[] { "*\\$RECYCLE.BIN", "*\\.*", "*\\System Volume Information" })); CreatePreference("directorycolumn.file_exclude_patterns", new List <object>(new object[] { "*\\desktop.ini", "*\\.*" })); CreatePreference("directorycolumn.individual_icon_files", new List <object>(new object[] { "*.exe", "*.ico", "*.lnk", "*.msi", "*.cur", "*.ani" })); CreatePreference("column.default_width", 200); CreatePreference("sidebar.width", 196); CreatePreference("sidebar.remember_width", true); CreatePreference("sidebar.visible", true); CreatePreference("tabbar.tab_index", 0); CreatePreference("tabbar.visible", true); CreatePreference("window.size", new List <object>(new object[] { 850, 413 })); CreatePreference("window.remember_size", false); }