Пример #1
0
 /// <summary>
 /// Returns the index of the location item in the navigation sidebar
 /// </summary>
 /// <param name="locationItem">The location item</param>
 /// <returns>Index of the item</returns>
 public int IndexOfItem(INavigationControlItem locationItem)
 {
     lock (favoriteList)
     {
         return(favoriteList.FindIndex(x => x.Path == locationItem.Path));
     }
 }
Пример #2
0
        protected override DataTemplate SelectTemplateCore(object item)
        {
            if (item != null && item is INavigationControlItem)
            {
                INavigationControlItem navControlItem = item as INavigationControlItem;
                switch (navControlItem.ItemType)
                {
                case NavigationControlItemType.Location:
                    return(LocationNavItemTemplate);

                case NavigationControlItemType.Drive:
                    return(DriveNavItemTemplate);

                case NavigationControlItemType.CloudDrive:
                    return(DriveNavItemTemplate);

                case NavigationControlItemType.LinuxDistro:
                    return(LinuxNavItemTemplate);

                case NavigationControlItemType.Header:
                    return(HeaderNavItemTemplate);
                }
            }
            return(null);
        }
Пример #3
0
        /// <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);
            }
        }
Пример #4
0
        /// <summary>
        /// Swaps two location items in the navigation sidebar
        /// </summary>
        /// <param name="firstLocationItem">The first location item</param>
        /// <param name="secondLocationItem">The second location item</param>
        public void SwapItems(INavigationControlItem firstLocationItem, INavigationControlItem secondLocationItem)
        {
            if (firstLocationItem == null || secondLocationItem == null)
            {
                return;
            }

            var indexOfFirstItemInMainPage  = IndexOfItem(firstLocationItem);
            var indexOfSecondItemInMainPage = IndexOfItem(secondLocationItem);

            // Moves the items in the MainPage
            MoveItem(firstLocationItem, indexOfFirstItemInMainPage, indexOfSecondItemInMainPage);
        }
Пример #5
0
        /// <summary>
        /// Moves the location item in the navigation sidebar 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 == null)
            {
                return(false);
            }

            if (oldIndex >= 0 && newIndex >= 0)
            {
                MainPage.SideBarItems.RemoveAt(oldIndex);
                MainPage.SideBarItems.Insert(newIndex, locationItem);
                return(true);
            }

            return(false);
        }
Пример #6
0
        /// <summary>
        /// Moves the location item in the navigation sidebar 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 == null)
            {
                return(false);
            }

            if (oldIndex >= 0 && newIndex >= 0)
            {
                favoriteSection.ChildItems.RemoveAt(oldIndex);
                favoriteSection.ChildItems.Insert(newIndex, locationItem);
                return(true);
            }

            return(false);
        }
Пример #7
0
        /// <summary>
        /// Swaps two location items in the navigation sidebar
        /// </summary>
        /// <param name="firstLocationItem">The first location item</param>
        /// <param name="secondLocationItem">The second location item</param>
        public void SwapItems(INavigationControlItem firstLocationItem, INavigationControlItem secondLocationItem)
        {
            if (firstLocationItem == null || secondLocationItem == null)
            {
                return;
            }

            // A backup of the items, because the swapping of items requires removing and inserting them in the corrent position
            var sidebarItemsBackup = new List <string>(this.Items);

            try
            {
                var indexOfFirstItemInMainPage  = IndexOfItem(firstLocationItem);
                var indexOfSecondItemInMainPage = IndexOfItem(secondLocationItem);

                // Moves the items in the MainPage
                var result = MoveItem(firstLocationItem, indexOfFirstItemInMainPage, indexOfSecondItemInMainPage);

                // Moves the items in this model and saves the model
                if (result == true)
                {
                    var indexOfFirstItemInModel  = this.Items.IndexOf(firstLocationItem.Path);
                    var indexOfSecondItemInModel = this.Items.IndexOf(secondLocationItem.Path);
                    if (indexOfFirstItemInModel >= 0 && indexOfSecondItemInModel >= 0)
                    {
                        this.Items.RemoveAt(indexOfFirstItemInModel);
                        this.Items.Insert(indexOfSecondItemInModel, firstLocationItem.Path);
                    }

                    Save();
                }
            }
            catch (Exception ex) when(
                ex is ArgumentException || // Pinned item was invalid
                ex is FileNotFoundException || // Pinned item was deleted
                ex is System.Runtime.InteropServices.COMException || // Pinned item's drive was ejected
                (uint)ex.HResult == 0x8007000F || // The system cannot find the drive specified
                (uint)ex.HResult == 0x800700A1)    // The specified path is invalid (usually an mtp device was disconnected)
            {
                Debug.WriteLine($"An error occured while swapping pinned items in the navigation sidebar. {ex.Message}");
                this.Items = sidebarItemsBackup;
                this.RemoveStaleSidebarItems();
                this.AddAllItemsToSidebar();
            }
        }
Пример #8
0
        /// <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 == null)
            {
                return(false);
            }

            if (oldIndex >= 1 && newIndex >= 1 && newIndex <= FavoriteItems.Count())
            {
                // 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 - 1);
                    FavoriteItems.Insert(newIndex - 1, locationItem.Path);
                    favoriteSection.ChildItems.RemoveAt(oldIndex);
                    favoriteSection.ChildItems.Insert(newIndex, locationItem);
                    Save();
                }
                catch (Exception ex) when(
                    ex is ArgumentException || // Pinned item was invalid
                    ex is FileNotFoundException || // Pinned item was deleted
                    ex is System.Runtime.InteropServices.COMException || // Pinned item's drive was ejected
                    (uint)ex.HResult == 0x8007000F || // The system cannot find the drive specified
                    (uint)ex.HResult == 0x800700A1)    // The specified path is invalid (usually an mtp device was disconnected)
                {
                    Debug.WriteLine($"An error occurred while moving pinned items in the Favorites sidebar section. {ex.Message}");
                    FavoriteItems = sidebarItemsBackup;
                    RemoveStaleSidebarItems();
                    _ = AddAllItemsToSidebar();
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Пример #9
0
 /// <summary>
 /// Returns the index of the location item in the collection containing Navigation control items
 /// </summary>
 /// <param name="locationItem">The location item</param>
 /// <param name="collection">The collection in which to find the location item</param>
 /// <returns>Index of the item</returns>
 public int IndexOfItem(INavigationControlItem locationItem, List <INavigationControlItem> collection)
 {
     return(collection.IndexOf(locationItem));
 }
Пример #10
0
 /// <summary>
 /// Returns the index of the location item in the navigation sidebar
 /// </summary>
 /// <param name="locationItem">The location item</param>
 /// <returns>Index of the item</returns>
 public int IndexOfItem(INavigationControlItem locationItem)
 {
     return(MainPage.SideBarItems.IndexOf(locationItem));
 }
Пример #11
0
 /// <summary>
 /// Returns the index of the location item in the navigation sidebar
 /// </summary>
 /// <param name="locationItem">The location item</param>
 /// <returns>Index of the item</returns>
 public int IndexOfItem(INavigationControlItem locationItem)
 {
     return(favoriteSection.ChildItems.IndexOf(locationItem));
 }