Skip to content

Commit 19f9ddf

Browse files
committed
Started Work on Copy and Paste
1 parent e7886e1 commit 19f9ddf

File tree

5 files changed

+144
-22
lines changed

5 files changed

+144
-22
lines changed

FileLoader.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,14 @@ public async void GetItemsAsync(string path)
237237
UpdateProgUI(ProgressReported);
238238
gotName = f.Name.ToString();
239239
gotDate = f.DateCreated.ToString(); // In the future, parse date to human readable format
240-
gotType = f.FileType.ToString();
240+
if(f.FileType.ToString() == ".exe")
241+
{
242+
gotType = "Executable";
243+
}
244+
else
245+
{
246+
gotType = f.FileType.ToString();
247+
}
241248
gotPath = f.Path.ToString();
242249
gotFolImg = Visibility.Collapsed;
243250
if (isPhotoAlbumMode == false)

Files.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,25 +224,25 @@
224224
</ItemGroup>
225225
<ItemGroup>
226226
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
227-
<Version>6.0.8</Version>
227+
<Version>6.1.7</Version>
228228
</PackageReference>
229229
<PackageReference Include="Microsoft.Toolkit.Uwp">
230-
<Version>3.0.0</Version>
230+
<Version>4.0.0</Version>
231231
</PackageReference>
232232
<PackageReference Include="Microsoft.Toolkit.Uwp.DeveloperTools">
233-
<Version>3.0.0</Version>
233+
<Version>4.0.0</Version>
234234
</PackageReference>
235235
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
236-
<Version>3.0.0</Version>
236+
<Version>4.0.0</Version>
237237
</PackageReference>
238238
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Animations">
239-
<Version>3.0.0</Version>
239+
<Version>4.0.0</Version>
240240
</PackageReference>
241241
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
242-
<Version>3.0.0</Version>
242+
<Version>4.0.0</Version>
243243
</PackageReference>
244244
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.DataGrid">
245-
<Version>3.1.0-preview1</Version>
245+
<Version>4.0.0</Version>
246246
</PackageReference>
247247
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
248248
<Version>2.0.0</Version>

GenericFileBrowser.xaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@
144144
<Button x:Name="Menu" BorderThickness="1.5" Style="{ThemeResource ButtonRevealStyle}" Foreground="Black" Content="&#xE712;" FontFamily="Segoe MDL2 Assets" Background="#33FFFFFF" FontSize="20" Margin="150,52,40,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="50" Height="50">
145145
<Button.Flyout>
146146
<MenuFlyout>
147-
<MenuFlyoutItem Text="New..."/>
148-
<MenuFlyoutItem Text="Paste"/>
149-
<MenuFlyoutItem Text="Copy Path"/>
150-
<MenuFlyoutItem Text="Change View Mode..."/>
147+
<MenuFlyoutItem Name="NewItem" Text="New..."/>
148+
<MenuFlyoutItem Name="PasteItem" Text="Paste"/>
149+
<MenuFlyoutItem Name="CopyPath" Text="Copy Path"/>
150+
<MenuFlyoutItem Name="ViewModeChange" Text="Change View Mode..."/>
151151
</MenuFlyout>
152152
</Button.Flyout>
153153
</Button>
@@ -159,7 +159,7 @@
159159

160160
<Grid Padding="50,200,50,0">
161161

162-
<controls:DataGrid FocusVisualPrimaryThickness="0" SelectionMode="Single" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" Drop="AllView_DropAsync" AutoGenerateColumns="False" CanDrag="False" AllowDrop="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" IsReadOnly="True" ItemsSource="{x:Bind local2:ItemViewModel.FilesAndFolders}" Margin="0,0,0,0" Padding="0, 0, 0, 0" HorizontalAlignment="Left">
162+
<controls:DataGrid FocusVisualPrimaryThickness="0" SelectionMode="Single" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" Drop="AllView_DropAsync" AutoGenerateColumns="False" CanDrag="False" AllowDrop="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" IsReadOnly="True" ItemsSource="{x:Bind local2:ItemViewModel.FilesAndFolders}" Margin="0,0,0,0" Padding="0, 0, 0, 0" HorizontalAlignment="Left">
163163

164164
<controls:DataGrid.Resources>
165165
<MenuFlyout x:Name="HeaderRightClickMenu" x:Key="HeaderRightClickFlyout">
@@ -227,7 +227,13 @@
227227
</MenuFlyout>
228228
</controls:DataGrid.Resources>
229229

230-
230+
<!--<controls:DataGrid.RowStyle>
231+
<Style TargetType="controls:DataGridRow">
232+
<Setter Property="Template">
233+
<Grid/>
234+
</Setter>
235+
</Style>
236+
</controls:DataGrid.RowStyle>-->
231237

232238
<controls:DataGrid.Columns>
233239
<controls:DataGridTemplateColumn>

GenericFileBrowser.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ public GenericFileBrowser()
6363
DeleteItem.Click += Interact.Interaction.DeleteItem_Click;
6464
RenameItem.Click += Interact.Interaction.RenameItem_Click;
6565
CutItem.Click += Interact.Interaction.CutItem_Click;
66-
CopyItem.Click += Interact.Interaction.CopyItem_Click;
66+
CopyItem.Click += Interact.Interaction.CopyItem_ClickAsync;
6767
AllView.RightTapped += Interact.Interaction.AllView_RightTapped;
6868
Back.Click += Navigation.NavigationActions.Back_Click;
6969
Forward.Click += Navigation.NavigationActions.Forward_Click;
7070
Refresh.Click += Navigation.NavigationActions.Refresh_Click;
7171
AllView.DoubleTapped += Interact.Interaction.List_ItemClick;
72-
72+
PasteItem.Click += Interact.Interaction.PasteItem_ClickAsync;
7373
}
7474

7575

@@ -157,7 +157,7 @@ private void Button_Click(object sender, RoutedEventArgs e)
157157
ProgressBox.Visibility = Visibility.Collapsed;
158158
}
159159

160-
160+
161161
}
162162

163163
public class EmptyFolderTextState : INotifyPropertyChanged

ItemInteractions.cs

Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
using Windows.Storage.Streams;
2727
using System.ComponentModel;
2828
using System.Diagnostics;
29+
using Windows.ApplicationModel.DataTransfer;
30+
using System.Collections;
31+
using System.Collections.Generic;
32+
using System.Linq;
33+
using Windows.Storage.Search;
34+
using Windows.UI.Popups;
2935

3036
namespace Interact
3137
{
@@ -43,6 +49,8 @@ public Interaction(Page p)
4349
page = p;
4450
}
4551

52+
public static MessageDialog message;
53+
private static Uri site_uri = new Uri(@"https://duke58701.wixsite.com/files-windows10/sideloading-help");
4654

4755
// Double-tap event for DataGrid
4856
public static async void List_ItemClick(object sender, DoubleTappedRoutedEventArgs e)
@@ -66,11 +74,22 @@ public static async void List_ItemClick(object sender, DoubleTappedRoutedEventAr
6674
GenericFileBrowser.P.path = clickedOnItem.FilePath;
6775
GenericFileBrowser.UpdateAllBindings();
6876
}
77+
else if (clickedOnItem.FileExtension == "Executable")
78+
{
79+
message = new MessageDialog("We noticed you’re trying to run an executable file. This type of file may be a security risk to your device, and is not supported by the Universal Windows Platform. If you're not sure what this means, check out the Microsoft Store for a large selection of secure apps, games, and more.");
80+
message.Title = "Unsupported Functionality";
81+
message.Commands.Add(new UICommand("Continue...", new UICommandInvokedHandler(Interaction.CommandInvokedHandler)));
82+
message.Commands.Add(new UICommand("Cancel"));
83+
await message.ShowAsync();
84+
}
6985
else
7086
{
7187
StorageFile file = await StorageFile.GetFileFromPathAsync(clickedOnItem.FilePath);
72-
var options = new Windows.System.LauncherOptions();
73-
options.DisplayApplicationPicker = true;
88+
var options = new LauncherOptions
89+
{
90+
DisplayApplicationPicker = true
91+
92+
};
7493
await Launcher.LaunchFileAsync(file, options);
7594
}
7695
}
@@ -84,6 +103,11 @@ public static async void List_ItemClick(object sender, DoubleTappedRoutedEventAr
84103

85104
}
86105

106+
private static async void CommandInvokedHandler(IUICommand command)
107+
{
108+
await Launcher.LaunchUriAsync(new Uri("ms-windows-store://home"));
109+
}
110+
87111
public static async void PhotoAlbumItemList_ClickAsync(object sender, ItemClickEventArgs e)
88112
{
89113
GridView grid = sender as GridView;
@@ -193,13 +217,98 @@ public static void CutItem_Click(object sender, RoutedEventArgs e)
193217

194218
}
195219

196-
public static void CopyItem_Click(object sender, RoutedEventArgs e)
220+
public static async void CopyItem_ClickAsync(object sender, RoutedEventArgs e)
197221
{
222+
DataPackage dataPackage = new DataPackage();
223+
dataPackage.RequestedOperation = DataPackageOperation.Copy;
224+
var DataGridSelectedItem = ItemViewModel.FilesAndFolders[GenericFileBrowser.data.SelectedIndex];
225+
if(DataGridSelectedItem != null)
226+
{
227+
var path = ItemViewModel.PUIP.Path;
228+
var fol = await StorageFolder.GetFolderFromPathAsync(path);
229+
var item = await fol.GetItemAsync(DataGridSelectedItem.FileName);
230+
List<IStorageItem> items = new List<IStorageItem>();
231+
items.Add(item);
232+
IEnumerable<IStorageItem> EnumerableOfItems = items;
233+
dataPackage.SetStorageItems(EnumerableOfItems);
234+
Clipboard.SetContent(dataPackage);
235+
236+
}
237+
}
238+
239+
public static async void PasteItem_ClickAsync(object sender, RoutedEventArgs e)
240+
{
241+
// TODO: Add progress box and collision for this operation
242+
var DestinationPath = ItemViewModel.PUIP.Path;
243+
DataPackageView packageView = Clipboard.GetContent();
244+
var ItemsToPaste = await packageView.GetStorageItemsAsync();
245+
foreach(IStorageItem item in ItemsToPaste)
246+
{
247+
StorageFolder SourceFolder = await StorageFolder.GetFolderFromPathAsync(item.Path);
248+
249+
if (item.IsOfType(StorageItemTypes.Folder))
250+
{
251+
CloneDirectory(item.Path, DestinationPath);
252+
253+
}
254+
else if (item.IsOfType(StorageItemTypes.File))
255+
{
256+
StorageFile DestinationFile = await StorageFile.GetFileFromPathAsync(item.Path);
257+
await DestinationFile.CopyAsync(await StorageFolder.GetFolderFromPathAsync(DestinationPath));
258+
}
259+
260+
}
261+
262+
}
263+
264+
public static async void CloneDirectory(string root, string dest)
265+
{
266+
StorageFolder SourceFolder = await StorageFolder.GetFolderFromPathAsync(root);
267+
StorageFolder DestinationFolder = await StorageFolder.GetFolderFromPathAsync(dest);
268+
//// Check for clone of source folder in destination folder
269+
//var FolderCreate = await DestinationFolder.TryGetItemAsync(SourceFolder.Name);
270+
//// if not there, then create it
271+
//if (FolderCreate == null)
272+
//{
273+
// await DestinationFolder.CreateFolderAsync(SourceFolder.Name);
274+
// Debug.WriteLine("Source folder clone not found in destination");
275+
//}
276+
//// If there, then update dest folder to reflect this
277+
//else
278+
//{
279+
// DestinationFolder = await StorageFolder.GetFolderFromPathAsync(dest + @"\" + SourceFolder.Name);
280+
// foreach (var directory in await SourceFolder.GetFoldersAsync())
281+
// {
282+
// string DirName = directory.Name;
283+
// if (await DestinationFolder.TryGetItemAsync(DirName) == null)
284+
// {
285+
// await DestinationFolder.CreateFolderAsync(DirName);
286+
// }
287+
// CloneDirectory(directory.Path, dest + @"\" + DirName);
288+
// }
289+
//}
290+
291+
var FolderCreate = await DestinationFolder.TryGetItemAsync(SourceFolder.Name);
292+
// Create initial root directory in dest if not there already
293+
if (FolderCreate == null)
294+
{
295+
await DestinationFolder.CreateFolderAsync(SourceFolder.Name);
296+
Debug.WriteLine("Source folder clone not found in destination");
297+
}
298+
foreach (var directory in await SourceFolder.GetFoldersAsync())
299+
{
300+
string DirName = directory.Name;
301+
if (await DestinationFolder.TryGetItemAsync(DirName) == null)
302+
{
303+
await DestinationFolder.CreateFolderAsync(DirName);
304+
}
305+
}
306+
307+
308+
198309

199310
}
200311
}
201312

202-
203313

204-
205314
}

0 commit comments

Comments
 (0)