Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups and minor improvements to Code #531

Merged
merged 4 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 18 additions & 47 deletions Files/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public static IShellPage CurrentInstance
}
}
}
public static Dialogs.ExceptionDialog exceptionDialog { get; set; }
public static Dialogs.ConsentDialog consentDialog { get; set; }
public static Dialogs.PropertiesDialog propertiesDialog { get; set; }
public static Dialogs.LayoutDialog layoutDialog { get; set; }
public static Dialogs.AddItemDialog addItemDialog { get; set; }
public static Dialogs.ExceptionDialog ExceptionDialogDisplay { get; set; }
public static Dialogs.ConsentDialog ConsentDialogDisplay { get; set; }
public static Dialogs.PropertiesDialog PropertiesDialogDisplay { get; set; }
public static Dialogs.LayoutDialog LayoutDialogDisplay { get; set; }
public static Dialogs.AddItemDialog AddItemDialogDisplay { get; set; }
public static ObservableCollection<INavigationControlItem> sideBarItems = new ObservableCollection<INavigationControlItem>();
public static ObservableCollection<LocationItem> locationItems = new ObservableCollection<LocationItem>();
public static ObservableCollection<WSLDistroItem> linuxDistroItems = new ObservableCollection<WSLDistroItem>();
Expand All @@ -68,11 +68,11 @@ public App()

RegisterUncaughtExceptionLogger();

consentDialog = new Dialogs.ConsentDialog();
propertiesDialog = new Dialogs.PropertiesDialog();
layoutDialog = new Dialogs.LayoutDialog();
addItemDialog = new Dialogs.AddItemDialog();
exceptionDialog = new Dialogs.ExceptionDialog();
ConsentDialogDisplay = new Dialogs.ConsentDialog();
PropertiesDialogDisplay = new Dialogs.PropertiesDialog();
LayoutDialogDisplay = new Dialogs.LayoutDialog();
AddItemDialogDisplay = new Dialogs.AddItemDialog();
ExceptionDialogDisplay = new Dialogs.ExceptionDialog();
// this.UnhandledException += App_UnhandledException;
Clipboard.ContentChanged += Clipboard_ContentChanged;
Clipboard_ContentChanged(null, null);
Expand Down Expand Up @@ -129,54 +129,27 @@ public static void Clipboard_ContentChanged(object sender, object e)
DataPackageView packageView = Clipboard.GetContent();
if (packageView.Contains(StandardDataFormats.StorageItems) && App.CurrentInstance.CurrentPageType != typeof(YourHome))
{
App.PS.isEnabled = true;
App.PS.IsEnabled = true;
}
else
{
App.PS.isEnabled = false;
App.PS.IsEnabled = false;
}
}
else
{
App.PS.isEnabled = false;
App.PS.IsEnabled = false;
}
}
catch (Exception)
{
App.PS.isEnabled = false;
App.PS.IsEnabled = false;
}

}

public static Windows.UI.Xaml.UnhandledExceptionEventArgs exceptionInfo { get; set; }
public static string exceptionStackTrace { get; set; }

private async void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
e.Handled = true;
exceptionInfo = e;
exceptionStackTrace = e.Exception.StackTrace;
await exceptionDialog.ShowAsync(ContentDialogPlacement.Popup);
}

public static IReadOnlyList<ContentDialog> FindDisplayedContentDialogs<T>()
{
var popupElements = VisualTreeHelper.GetOpenPopupsForXamlRoot(Window.Current.Content.XamlRoot);
List<ContentDialog> dialogs = new List<ContentDialog>();
List<ContentDialog> openDialogs = new List<ContentDialog>();
Interaction.FindChildren<ContentDialog>(dialogs, Window.Current.Content.XamlRoot.Content as DependencyObject);
foreach (var dialog in dialogs)
{
var popups = new List<Popup>();
Interaction.FindChildren<Popup>(popups, dialog);
if (popups.First().IsOpen && popups.First() is T)
{
openDialogs.Add(dialog);
}
}
return openDialogs;
}

public static Windows.UI.Xaml.UnhandledExceptionEventArgs ExceptionInfo { get; set; }
public static string ExceptionStackTrace { get; set; }
public static PasteState PS { get; set; } = new PasteState();
public static List<string> pathsToDeleteAfterPaste = new List<string>();

Expand Down Expand Up @@ -206,11 +179,10 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)

bool canEnablePrelaunch = Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.ApplicationModel.Core.CoreApplication", "EnablePrelaunch");

Frame rootFrame = Window.Current.Content as Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
if (!(Window.Current.Content is Frame rootFrame))
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
Expand Down Expand Up @@ -255,8 +227,7 @@ protected override void OnActivated(IActivatedEventArgs args)
Logger.Info("App activated");

// Window management
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
if (!(Window.Current.Content is Frame rootFrame))
{
rootFrame = new Frame();
Window.Current.Content = rootFrame;
Expand Down
34 changes: 21 additions & 13 deletions Files/BaseLayout.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Files.Filesystem;
using Files.Interacts;
using Files.View_Models;
using Files.Views.Pages;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -50,7 +51,14 @@ public List<ListedItem> SelectedItems
{
get
{
return _SelectedItems;
if(_SelectedItems == null)
{
return new List<ListedItem>();
}
else
{
return _SelectedItems;
}
}
internal set
{
Expand Down Expand Up @@ -116,15 +124,15 @@ private void AppSettings_LayoutModeChangeRequested(object sender, EventArgs e)
if (App.CurrentInstance.ContentPage != null)
{
App.CurrentInstance.ViewModel.CancelLoadAndClearFiles();
App.CurrentInstance.ViewModel.isLoadingItems = true;
App.CurrentInstance.ViewModel.isLoadingItems = false;
App.CurrentInstance.ViewModel.IsLoadingItems = true;
App.CurrentInstance.ViewModel.IsLoadingItems = false;
if (App.AppSettings.LayoutMode == 0)
{
App.CurrentInstance.ContentFrame.Navigate(typeof(GenericFileBrowser), App.CurrentInstance.ViewModel.Universal.WorkingDirectory, null);
App.CurrentInstance.ContentFrame.Navigate(typeof(GenericFileBrowser), App.CurrentInstance.ViewModel.WorkingDirectory, null);
}
else
{
App.CurrentInstance.ContentFrame.Navigate(typeof(PhotoAlbum), App.CurrentInstance.ViewModel.Universal.WorkingDirectory, null);
App.CurrentInstance.ContentFrame.Navigate(typeof(PhotoAlbum), App.CurrentInstance.ViewModel.WorkingDirectory, null);
}
}

Expand All @@ -135,7 +143,7 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private bool isStale = false;

protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
{
base.OnNavigatedTo(eventArgs);
Expand All @@ -151,10 +159,10 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
}
App.CurrentInstance.NavigationToolbar.CanRefresh = true;
IsItemSelected = false;
AssociatedViewModel.EmptyTextState.isVisible = Visibility.Collapsed;
App.CurrentInstance.ViewModel.Universal.WorkingDirectory = parameters;
AssociatedViewModel.EmptyTextState.IsVisible = Visibility.Collapsed;
App.CurrentInstance.ViewModel.WorkingDirectory = parameters;

if (App.CurrentInstance.ViewModel.Universal.WorkingDirectory == Path.GetPathRoot(App.CurrentInstance.ViewModel.Universal.WorkingDirectory))
if (App.CurrentInstance.ViewModel.WorkingDirectory == Path.GetPathRoot(App.CurrentInstance.ViewModel.WorkingDirectory))
{
App.CurrentInstance.NavigationToolbar.CanNavigateToParent = false;
}
Expand All @@ -163,7 +171,7 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
App.CurrentInstance.NavigationToolbar.CanNavigateToParent = true;
}

App.CurrentInstance.ViewModel.AddItemsToCollectionAsync(App.CurrentInstance.ViewModel.Universal.WorkingDirectory);
App.CurrentInstance.ViewModel.AddItemsToCollectionAsync(App.CurrentInstance.ViewModel.WorkingDirectory);
App.Clipboard_ContentChanged(null, null);

App.CurrentInstance.NavigationToolbar.PathControlDisplayText = parameters;
Expand Down Expand Up @@ -191,7 +199,7 @@ public void RightClickContextMenu_Opening(object sender, object e)
var selectedFileSystemItems = (App.CurrentInstance.ContentPage as BaseLayout).SelectedItems;

// Find selected items that are not folders
if (selectedFileSystemItems.Cast<ListedItem>().Any(x => x.FileType != "Folder"))
if (selectedFileSystemItems.Cast<ListedItem>().Any(x => x.PrimaryItemAttribute != StorageItemTypes.Folder))
{
UnloadMenuFlyoutItemByName("SidebarPinItem");
UnloadMenuFlyoutItemByName("OpenInNewTab");
Expand All @@ -201,12 +209,12 @@ public void RightClickContextMenu_Opening(object sender, object e)
{
var selectedDataItem = selectedFileSystemItems[0] as ListedItem;

if (selectedDataItem.DotFileExtension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
if (selectedDataItem.FileExtension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
{
UnloadMenuFlyoutItemByName("OpenItem");
this.FindName("UnzipItem");
}
else if (!selectedDataItem.DotFileExtension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
else if (!selectedDataItem.FileExtension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
{
this.FindName("OpenItem");
UnloadMenuFlyoutItemByName("UnzipItem");
Expand Down
18 changes: 9 additions & 9 deletions Files/Dialogs/AddItemDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public AddItemDialog()
public void AddItemsToList()
{
AddItemsList.Clear();
AddItemsList.Add(new AddListItem { Header = "Folder", SubHeader = "Creates an empty folder", Icon = "\xE838", isEnabled = true });
AddItemsList.Add(new AddListItem { Header = "Text Document", SubHeader = "Creates a simple text file", Icon = "\xE8A5", isEnabled = true });
AddItemsList.Add(new AddListItem { Header = "Bitmap Image", SubHeader = "Creates an empty bitmap image file", Icon = "\xEB9F", isEnabled = true });
AddItemsList.Add(new AddListItem { Header = "Folder", SubHeader = "Creates an empty folder", Icon = "\xE838", IsItemEnabled = true });
AddItemsList.Add(new AddListItem { Header = "Text Document", SubHeader = "Creates a simple text file", Icon = "\xE8A5", IsItemEnabled = true });
AddItemsList.Add(new AddListItem { Header = "Bitmap Image", SubHeader = "Creates an empty bitmap image file", Icon = "\xEB9F", IsItemEnabled = true });

}

private void ListView_ItemClick(object sender, ItemClickEventArgs e)
{
App.addItemDialog.Hide();
App.AddItemDialogDisplay.Hide();
switch((e.ClickedItem as AddListItem).Header)
{
case "Folder":
Expand All @@ -52,7 +52,7 @@ public static async void CreateFile(AddItemType fileType)
string currentPath = null;
if (TabInstance.ContentPage != null)
{
currentPath = TabInstance.ViewModel.Universal.WorkingDirectory;
currentPath = TabInstance.ViewModel.WorkingDirectory;
}
StorageFolder folderToCreateItem = await StorageFolder.GetFolderFromPathAsync(currentPath);
RenameDialog renameDialog = new RenameDialog();
Expand All @@ -71,7 +71,7 @@ public static async void CreateFile(AddItemType fileType)
{
folder = await folderToCreateItem.CreateFolderAsync("New Folder", CreationCollisionOption.GenerateUniqueName);
}
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(folder.FolderRelativeId) { FileName = folder.DisplayName, FileDateReal = DateTimeOffset.Now, EmptyImgVis = Visibility.Collapsed, FolderImg = Visibility.Visible, FileIconVis = Visibility.Collapsed, FileType = "Folder", FileImg = null, FilePath = folder.Path });
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(folder.FolderRelativeId) { ItemName = folder.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = false, LoadFolderGlyph = true, LoadFileIcon = false, ItemType = "Folder", FileImage = null, ItemPath = folder.Path });
}
else if (fileType == AddItemType.TextDocument)
{
Expand All @@ -84,7 +84,7 @@ public static async void CreateFile(AddItemType fileType)
{
item = await folderToCreateItem.CreateFileAsync("New Text Document" + ".txt", CreationCollisionOption.GenerateUniqueName);
}
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId) { FileName = item.DisplayName, FileDateReal = DateTimeOffset.Now, EmptyImgVis = Visibility.Visible, FolderImg = Visibility.Collapsed, FileIconVis = Visibility.Collapsed, FileType = item.DisplayType, FileImg = null, FilePath = item.Path, DotFileExtension = item.FileType });
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId) { ItemName = item.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = true, LoadFolderGlyph = false, LoadFileIcon = false, ItemType = item.DisplayType, FileImage = null, ItemPath = item.Path, FileExtension = item.FileType });
}
else if (fileType == AddItemType.BitmapImage)
{
Expand All @@ -97,7 +97,7 @@ public static async void CreateFile(AddItemType fileType)
{
item = await folderToCreateItem.CreateFileAsync("New Bitmap Image" + ".bmp", CreationCollisionOption.GenerateUniqueName);
}
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId) { FileName = item.DisplayName, FileDateReal = DateTimeOffset.Now, EmptyImgVis = Visibility.Visible, FolderImg = Visibility.Collapsed, FileIconVis = Visibility.Collapsed, FileType = item.DisplayType, FileImg = null, FilePath = item.Path, DotFileExtension = item.FileType });
TabInstance.ViewModel.AddFileOrFolder(new ListedItem(item.FolderRelativeId) { ItemName = item.DisplayName, ItemDateModifiedReal = DateTimeOffset.Now, LoadUnknownTypeGlyph = true, LoadFolderGlyph = false, LoadFileIcon = false, ItemType = item.DisplayType, FileImage = null, ItemPath = item.Path, FileExtension = item.FileType });
}
}
}
Expand All @@ -115,6 +115,6 @@ public class AddListItem
public string Header { get; set; }
public string SubHeader { get; set; }
public string Icon { get; set; }
public bool isEnabled { get; set; }
public bool IsItemEnabled { get; set; }
}
}
10 changes: 5 additions & 5 deletions Files/Dialogs/ExceptionDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ private void ExpandMoreInfo_Click(object sender, RoutedEventArgs e)

private void ContentDialog_Loaded(object sender, RoutedEventArgs e)
{
message = App.exceptionInfo.Exception.Message;
if (!string.IsNullOrWhiteSpace(App.exceptionStackTrace))
stackTrace = App.exceptionStackTrace;
message = App.ExceptionInfo.Exception.Message;
if (!string.IsNullOrWhiteSpace(App.ExceptionStackTrace))
stackTrace = App.ExceptionStackTrace;
else
stackTrace = "No stack trace found.";

if (!string.IsNullOrWhiteSpace(App.exceptionInfo.Exception.TargetSite?.ReflectedType.FullName))
offendingMethod = App.exceptionInfo.Exception.TargetSite.ReflectedType.FullName;
if (!string.IsNullOrWhiteSpace(App.ExceptionInfo.Exception.TargetSite?.ReflectedType.FullName))
offendingMethod = App.ExceptionInfo.Exception.TargetSite.ReflectedType.FullName;
else
offendingMethod = "(Method name unknown)";

Expand Down
8 changes: 4 additions & 4 deletions Files/Enums/FormFactorMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
public enum FormFactorMode
{
Regular = 0,
TouchEnhancedRegular = 1,
Tablet = 2,
Cloud = 3,
Classic = 4
//TouchEnhancedRegular = 1,
//Tablet = 2,
//Cloud = 3,
//Classic = 4
}
}
Loading