Skip to content

Commit 1a3674b

Browse files
committed
Initial Directory Clone Support
1 parent 742388f commit 1a3674b

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

ItemInteractions.cs

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ public static async void PhotoAlbumItemList_ClickAsync(object sender, ItemClickE
143143
}
144144
}
145145

146+
public static DataGrid dataGrid;
146147

147148
public static void AllView_RightTapped(object sender, RightTappedRoutedEventArgs e)
148149
{
149-
DataGrid dataGrid = (DataGrid)sender;
150+
dataGrid = (DataGrid)sender;
150151
var RowPressed = FindParent<DataGridRow>(e.OriginalSource as DependencyObject);
151152

152153
// If user clicks on header
@@ -213,6 +214,21 @@ public static async void OpenItem_Click(object sender, RoutedEventArgs e)
213214

214215
public static void ShareItem_Click(object sender, RoutedEventArgs e)
215216
{
217+
DataTransferManager manager = DataTransferManager.GetForCurrentView();
218+
manager.DataRequested += Manager_DataRequested;
219+
DataTransferManager.ShowShareUI();
220+
}
221+
222+
private static void Manager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
223+
{
224+
foreach(IStorageItem item in dataGrid.ItemsSource)
225+
{
226+
227+
}
228+
DataRequest dataRequest = args.Request;
229+
dataRequest.Data.SetStorageItems(dataGrid.ItemsSource as IEnumerable<IStorageItem>);
230+
dataRequest.Data.Properties.Title = "Data Shared From Files UWP";
231+
dataRequest.Data.Properties.Description = "The files/folders you selected will be shared";
216232

217233
}
218234

@@ -277,15 +293,15 @@ public static async void PasteItem_ClickAsync(object sender, RoutedEventArgs e)
277293
var DestinationPath = ItemViewModel.PUIP.Path;
278294
DataPackageView packageView = Clipboard.GetContent();
279295
var ItemsToPaste = await packageView.GetStorageItemsAsync();
296+
280297
foreach(IStorageItem item in ItemsToPaste)
281298
{
282-
StorageFolder SourceFolder = await StorageFolder.GetFolderFromPathAsync(PathSnapshot);
283-
299+
284300
if (item.IsOfType(StorageItemTypes.Folder))
285301
{
286-
//CloneDirectory(item.Path, DestinationPath);
287-
StorageFolder ClipboardFolder = await StorageFolder.GetFolderFromPathAsync(item.Path);
288-
//await ClipboardFolder.
302+
CloneDirectoryAsync(item.Path, DestinationPath, item.Name);
303+
304+
289305
}
290306
else if (item.IsOfType(StorageItemTypes.File))
291307
{
@@ -294,15 +310,35 @@ public static async void PasteItem_ClickAsync(object sender, RoutedEventArgs e)
294310
}
295311

296312
}
297-
Navigation.NavigationActions.Refresh_Click(null, null);
313+
NavigationActions.Refresh_Click(null, null);
298314

299315
}
300-
301-
public static async void CloneDirectory(string root, string dest)
316+
static int passNum = 0;
317+
private static async void CloneDirectoryAsync(string SourcePath, string DestinationPath, string DirName)
302318
{
303-
StorageFolder SourceFolder = await StorageFolder.GetFolderFromPathAsync(root);
304-
StorageFolder DestinationFolder = await StorageFolder.GetFolderFromPathAsync(dest);
305-
319+
passNum++;
320+
StorageFolder SourceFolder = await StorageFolder.GetFolderFromPathAsync(SourcePath);
321+
StorageFolder DestinationFolder = await StorageFolder.GetFolderFromPathAsync(DestinationPath);
322+
323+
if(passNum == 1)
324+
{
325+
await DestinationFolder.CreateFolderAsync(DirName);
326+
DestinationPath = DestinationPath + @"\" + DirName;
327+
DestinationFolder = await StorageFolder.GetFolderFromPathAsync(DestinationPath);
328+
// SourcePath = SourcePath + @"\" + DirName;
329+
// SourceFolder = await StorageFolder.GetFolderFromPathAsync(SourcePath);
330+
}
331+
332+
Debug.WriteLine("Pass " + passNum);
333+
foreach (StorageFile file in await SourceFolder.GetFilesAsync())
334+
{
335+
await file.CopyAsync(DestinationFolder);
336+
}
337+
foreach (StorageFolder folder in await SourceFolder.GetFoldersAsync())
338+
{
339+
await DestinationFolder.CreateFolderAsync(folder.DisplayName);
340+
CloneDirectoryAsync(folder.Path, DestinationPath + @"\" + folder.DisplayName, folder.DisplayName);
341+
}
306342
}
307343
}
308344

0 commit comments

Comments
 (0)