33using Files . Navigation ;
44using Microsoft . UI . Xaml . Controls ;
55using System ;
6+ using System . Collections . Generic ;
67using System . Collections . ObjectModel ;
78using System . Diagnostics ;
89using System . IO ;
@@ -79,6 +80,8 @@ public ProHome()
7980 accessiblePasteButton = PasteButton ;
8081 LocationsList . SelectedIndex = 0 ;
8182 RibbonTeachingTip = RibbonTip ;
83+ ApplicationDataContainer localSettings = ApplicationData . Current . LocalSettings ;
84+ PopulatePinnedSidebarItems ( ) ;
8285 PopulateNavViewWithExternalDrives ( ) ;
8386 BackButton . Click += NavigationActions . Back_Click ;
8487 ForwardButton . Click += NavigationActions . Forward_Click ;
@@ -90,7 +93,6 @@ public ProHome()
9093 }
9194
9295 // Overwrite paths for common locations if Custom Locations setting is enabled
93- ApplicationDataContainer localSettings = ApplicationData . Current . LocalSettings ;
9496 if ( localSettings . Values [ "customLocationsSetting" ] . Equals ( true ) )
9597 {
9698 DesktopPath = localSettings . Values [ "DesktopLocation" ] . ToString ( ) ;
@@ -103,6 +105,127 @@ public ProHome()
103105
104106 }
105107
108+ List < string > LinesToRemoveFromFile = new List < string > ( ) ;
109+
110+ public async void PopulatePinnedSidebarItems ( )
111+ {
112+ StorageFolder cacheFolder = Windows . Storage . ApplicationData . Current . LocalCacheFolder ;
113+ var ListFile = await cacheFolder . GetFileAsync ( "PinnedItems.txt" ) ;
114+ if ( ListFile != null )
115+ {
116+ var ListFileLines = await FileIO . ReadLinesAsync ( ListFile ) ;
117+ foreach ( string s in ListFileLines )
118+ {
119+ try
120+ {
121+ StorageFolder fol = await StorageFolder . GetFolderFromPathAsync ( s ) ;
122+ var name = fol . DisplayName ;
123+ var content = name ;
124+ var icon = "\uE8B7 " ;
125+
126+ FontFamily fontFamily = new FontFamily ( "Segoe MDL2 Assets" ) ;
127+ FontIcon fontIcon = new FontIcon ( )
128+ {
129+ FontSize = 16 ,
130+ FontFamily = fontFamily ,
131+ Glyph = icon
132+ } ;
133+
134+ TextBlock text = new TextBlock ( )
135+ {
136+ Text = content ,
137+ FontSize = 12
138+ } ;
139+
140+ StackPanel stackPanel = new StackPanel ( )
141+ {
142+ Spacing = 15 ,
143+ Orientation = Orientation . Horizontal
144+ } ;
145+
146+ stackPanel . Children . Add ( fontIcon ) ;
147+ stackPanel . Children . Add ( text ) ;
148+ MenuFlyout flyout = new MenuFlyout ( ) ;
149+ MenuFlyoutItem flyoutItem = new MenuFlyoutItem ( )
150+ {
151+ Text = "Unpin item"
152+ } ;
153+ flyoutItem . Click += FlyoutItem_Click ;
154+ flyout . Items . Add ( flyoutItem ) ;
155+ bool isDuplicate = false ;
156+ foreach ( ListViewItem lvi in LocationsList . Items )
157+ {
158+ if ( lvi . Tag . ToString ( ) == s )
159+ {
160+ isDuplicate = true ;
161+
162+ }
163+ }
164+
165+ if ( ! isDuplicate )
166+ {
167+ ListViewItem newItem = new ListViewItem ( ) ;
168+ newItem . Content = stackPanel ;
169+ newItem . Tag = s ;
170+ newItem . ContextFlyout = flyout ;
171+ newItem . IsRightTapEnabled = true ;
172+ newItem . RightTapped += NewItem_RightTapped ;
173+ LocationsList . Items . Add ( newItem ) ;
174+ }
175+ }
176+ catch ( UnauthorizedAccessException e )
177+ {
178+ Debug . WriteLine ( e . Message ) ;
179+ }
180+ catch ( FileNotFoundException e )
181+ {
182+ Debug . WriteLine ( "Pinned item was deleted and will be removed from the file lines list soon: " + e . Message ) ;
183+ LinesToRemoveFromFile . Add ( s ) ;
184+ }
185+ catch ( System . Runtime . InteropServices . COMException e )
186+ {
187+ Debug . WriteLine ( "Pinned item's drive was ejected and will be removed from the file lines list soon: " + e . Message ) ;
188+ LinesToRemoveFromFile . Add ( s ) ;
189+ }
190+ }
191+
192+ foreach ( string path in LinesToRemoveFromFile )
193+ {
194+ ListFileLines . Remove ( path ) ;
195+ }
196+ await FileIO . WriteLinesAsync ( ListFile , ListFileLines ) ;
197+ ListFileLines = await FileIO . ReadLinesAsync ( ListFile ) ;
198+
199+ // Remove unpinned items from sidebar
200+ foreach ( ListViewItem location in LocationsList . Items )
201+ {
202+ if ( ! ( location . Tag . ToString ( ) == "Favorites" || location . Tag . ToString ( ) == "Desktop" || location . Tag . ToString ( ) == "Documents" || location . Tag . ToString ( ) == "Downloads" || location . Tag . ToString ( ) == "Pictures" || location . Tag . ToString ( ) == "Music" || location . Tag . ToString ( ) == "Videos" ) )
203+ {
204+
205+ if ( ! ListFileLines . Contains ( location . Tag . ToString ( ) ) )
206+ {
207+ if ( LocationsList . SelectedItem == location )
208+ {
209+ LocationsList . SelectedIndex = 0 ;
210+ accessibleContentFrame . Navigate ( typeof ( YourHome ) ) ;
211+ PathText . Text = "Favorites" ;
212+ LayoutItems . isEnabled = false ;
213+ }
214+ LocationsList . Items . Remove ( location ) ;
215+ }
216+ }
217+ }
218+ LinesToRemoveFromFile . Clear ( ) ;
219+ }
220+ }
221+
222+ ListViewItem rightClickedItem ;
223+
224+ private void NewItem_RightTapped ( object sender , RightTappedRoutedEventArgs e )
225+ {
226+ rightClickedItem = sender as ListViewItem ;
227+ }
228+
106229 public async void PopulateNavViewWithExternalDrives ( )
107230 {
108231 var knownRemDevices = new ObservableCollection < string > ( ) ;
@@ -168,6 +291,22 @@ public async void PopulateNavViewWithExternalDrives()
168291 } ) ;
169292 }
170293
294+ private async void FlyoutItem_Click ( object sender , RoutedEventArgs e )
295+ {
296+ StorageFolder cacheFolder = Windows . Storage . ApplicationData . Current . LocalCacheFolder ;
297+ var ListFile = await cacheFolder . GetFileAsync ( "PinnedItems.txt" ) ;
298+ var ListFileLines = await FileIO . ReadLinesAsync ( ListFile ) ;
299+ foreach ( string s in ListFileLines )
300+ {
301+ if ( s == rightClickedItem . Tag . ToString ( ) )
302+ {
303+ LinesToRemoveFromFile . Add ( s ) ;
304+ PopulatePinnedSidebarItems ( ) ;
305+ return ;
306+ }
307+ }
308+ }
309+
171310 private void NameDialog_PrimaryButtonClick ( ContentDialog sender , ContentDialogButtonClickEventArgs args )
172311 {
173312 inputForRename = inputFromRename . Text ;
@@ -468,6 +607,20 @@ private void LocationsList_ItemClick(object sender, ItemClickEventArgs e)
468607 }
469608 LayoutItems . isEnabled = true ;
470609 }
610+ else
611+ {
612+ ItemDisplayFrame . Navigate ( typeof ( GenericFileBrowser ) , clickedItem . Tag ) ;
613+ PathText . Text = clickedItem . Tag . ToString ( ) ;
614+ instance = ( this . accessibleContentFrame . Content as GenericFileBrowser ) . instanceViewModel ;
615+ HomeItems . isEnabled = false ;
616+ ShareItems . isEnabled = false ;
617+ if ( DrivesList . SelectedItem != null )
618+ {
619+ DrivesList . SelectedItem = null ;
620+ LayoutItems . isEnabled = false ;
621+ }
622+ LayoutItems . isEnabled = true ;
623+ }
471624
472625 }
473626
0 commit comments