From 883b7f5e6c09719d837f5bb2d8572fb92cd13cab Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Sun, 4 Apr 2021 15:58:48 +0200
Subject: [PATCH 01/15] Moved widgets to GridView
---
Files/Files.csproj | 15 ++++--
Files/UserControls/Widgets/Bundles.xaml.cs | 9 +++-
.../UserControls/Widgets/DrivesWidget.xaml.cs | 3 +-
.../Widgets/WidgetsListControl.xaml | 46 +++++++++++++++++++
.../Widgets/WidgetsListControl.xaml.cs | 23 ++++++++++
.../Bundles/BundleContainerViewModel.cs | 2 +-
.../Bundles/BundleItemViewModel.cs | 2 +-
.../{ => Widgets}/Bundles/BundlesViewModel.cs | 2 +-
Files/ViewModels/Widgets/IWidgetItemModel.cs | 9 ++++
.../Widgets/WidgetsListControlViewModel.cs | 38 +++++++++++++++
Files/Views/YourHome.xaml | 7 +++
Files/Views/YourHome.xaml.cs | 11 ++++-
12 files changed, 156 insertions(+), 11 deletions(-)
create mode 100644 Files/UserControls/Widgets/WidgetsListControl.xaml
create mode 100644 Files/UserControls/Widgets/WidgetsListControl.xaml.cs
rename Files/ViewModels/{ => Widgets}/Bundles/BundleContainerViewModel.cs (99%)
rename Files/ViewModels/{ => Widgets}/Bundles/BundleItemViewModel.cs (99%)
rename Files/ViewModels/{ => Widgets}/Bundles/BundlesViewModel.cs (99%)
create mode 100644 Files/ViewModels/Widgets/IWidgetItemModel.cs
create mode 100644 Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
diff --git a/Files/Files.csproj b/Files/Files.csproj
index d7f281d7cebc..7acf9d2f7657 100644
--- a/Files/Files.csproj
+++ b/Files/Files.csproj
@@ -290,11 +290,14 @@
Bundles.xaml
+
+ WidgetsListControl.xaml
+
-
-
-
+
+
+
@@ -455,6 +458,8 @@
+
+
ColumnShellPage.xaml
@@ -916,6 +921,10 @@
MSBuild:Compile
Designer
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/Files/UserControls/Widgets/Bundles.xaml.cs b/Files/UserControls/Widgets/Bundles.xaml.cs
index b77b65d4992c..0f7e0c636152 100644
--- a/Files/UserControls/Widgets/Bundles.xaml.cs
+++ b/Files/UserControls/Widgets/Bundles.xaml.cs
@@ -1,12 +1,15 @@
-using Files.ViewModels.Bundles;
+using Files.ViewModels.Widgets;
+using Files.ViewModels.Widgets.Bundles;
using System;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
using Windows.UI.Xaml.Controls;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace Files.UserControls.Widgets
{
- public sealed partial class Bundles : UserControl, IDisposable
+ public sealed partial class Bundles : UserControl, IWidgetItemModel, IDisposable
{
public BundlesViewModel ViewModel
{
@@ -14,6 +17,8 @@ public BundlesViewModel ViewModel
private set => DataContext = value;
}
+ public Control WidgetContent => this;
+
public Bundles()
{
this.InitializeComponent();
diff --git a/Files/UserControls/Widgets/DrivesWidget.xaml.cs b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
index 54dac5f60714..cd2846ab78e2 100644
--- a/Files/UserControls/Widgets/DrivesWidget.xaml.cs
+++ b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
@@ -2,6 +2,7 @@
using Files.Helpers;
using Files.Interacts;
using Files.ViewModels;
+using Files.ViewModels.Widgets;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
@@ -32,6 +33,7 @@ public sealed partial class DrivesWidget : UserControl, INotifyPropertyChanged
public static ObservableCollection ItemsAdded = new ObservableCollection();
+
private IShellPage associatedInstance;
public IShellPage AppInstance
@@ -42,7 +44,6 @@ public IShellPage AppInstance
if (value != associatedInstance)
{
associatedInstance = value;
- NotifyPropertyChanged(nameof(AppInstance));
}
}
}
diff --git a/Files/UserControls/Widgets/WidgetsListControl.xaml b/Files/UserControls/Widgets/WidgetsListControl.xaml
new file mode 100644
index 000000000000..dfa37389c61b
--- /dev/null
+++ b/Files/UserControls/Widgets/WidgetsListControl.xaml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Files/UserControls/Widgets/WidgetsListControl.xaml.cs b/Files/UserControls/Widgets/WidgetsListControl.xaml.cs
new file mode 100644
index 000000000000..cd362c4222e1
--- /dev/null
+++ b/Files/UserControls/Widgets/WidgetsListControl.xaml.cs
@@ -0,0 +1,23 @@
+using Windows.UI.Xaml.Controls;
+using Files.ViewModels.Widgets;
+
+// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
+
+namespace Files.UserControls.Widgets
+{
+ public sealed partial class WidgetsListControl : UserControl
+ {
+ public WidgetsListControlViewModel ViewModel
+ {
+ get => (WidgetsListControlViewModel)DataContext;
+ set => DataContext = value;
+ }
+
+ public WidgetsListControl()
+ {
+ this.InitializeComponent();
+
+ this.ViewModel = new WidgetsListControlViewModel();
+ }
+ }
+}
diff --git a/Files/ViewModels/Bundles/BundleContainerViewModel.cs b/Files/ViewModels/Widgets/Bundles/BundleContainerViewModel.cs
similarity index 99%
rename from Files/ViewModels/Bundles/BundleContainerViewModel.cs
rename to Files/ViewModels/Widgets/Bundles/BundleContainerViewModel.cs
index 0ef69e02d1d0..db754fa36892 100644
--- a/Files/ViewModels/Bundles/BundleContainerViewModel.cs
+++ b/Files/ViewModels/Widgets/Bundles/BundleContainerViewModel.cs
@@ -19,7 +19,7 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
-namespace Files.ViewModels.Bundles
+namespace Files.ViewModels.Widgets.Bundles
{
///
/// Bundle's contents view model
diff --git a/Files/ViewModels/Bundles/BundleItemViewModel.cs b/Files/ViewModels/Widgets/Bundles/BundleItemViewModel.cs
similarity index 99%
rename from Files/ViewModels/Bundles/BundleItemViewModel.cs
rename to Files/ViewModels/Widgets/Bundles/BundleItemViewModel.cs
index d41b457df3c4..65ce873c1167 100644
--- a/Files/ViewModels/Bundles/BundleItemViewModel.cs
+++ b/Files/ViewModels/Widgets/Bundles/BundleItemViewModel.cs
@@ -16,7 +16,7 @@
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
-namespace Files.ViewModels.Bundles
+namespace Files.ViewModels.Widgets.Bundles
{
public class BundleItemViewModel : ObservableObject, IDisposable
{
diff --git a/Files/ViewModels/Bundles/BundlesViewModel.cs b/Files/ViewModels/Widgets/Bundles/BundlesViewModel.cs
similarity index 99%
rename from Files/ViewModels/Bundles/BundlesViewModel.cs
rename to Files/ViewModels/Widgets/Bundles/BundlesViewModel.cs
index 0b2e5b671003..2f903e210d70 100644
--- a/Files/ViewModels/Bundles/BundlesViewModel.cs
+++ b/Files/ViewModels/Widgets/Bundles/BundlesViewModel.cs
@@ -21,7 +21,7 @@
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
-namespace Files.ViewModels.Bundles
+namespace Files.ViewModels.Widgets.Bundles
{
///
/// Bundles list View Model
diff --git a/Files/ViewModels/Widgets/IWidgetItemModel.cs b/Files/ViewModels/Widgets/IWidgetItemModel.cs
new file mode 100644
index 000000000000..ef65e57088a5
--- /dev/null
+++ b/Files/ViewModels/Widgets/IWidgetItemModel.cs
@@ -0,0 +1,9 @@
+using Windows.UI.Xaml.Controls;
+
+namespace Files.ViewModels.Widgets
+{
+ public interface IWidgetItemModel
+ {
+ Control WidgetContent { get; }
+ }
+}
diff --git a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
new file mode 100644
index 000000000000..935b1f9892e6
--- /dev/null
+++ b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
@@ -0,0 +1,38 @@
+using Microsoft.Toolkit.Mvvm.ComponentModel;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Windows.UI.Xaml.Controls;
+
+namespace Files.ViewModels.Widgets
+{
+ public class WidgetsListControlViewModel : ObservableObject
+ {
+ public ObservableCollection Widgets { get; private set; } = new ObservableCollection();
+
+ public bool AddWidget(IWidgetItemModel widgetModel)
+ {
+ if (widgetModel == null)
+ {
+ return false;
+ }
+
+ Widgets.Add(widgetModel);
+ return true;
+ }
+
+ public bool RemoveWidget(IWidgetItemModel widgetModel)
+ {
+ return Widgets.Remove(widgetModel);
+ }
+
+ public void ReorderWidget(IWidgetItemModel widgetModel, int place)
+ {
+ int widgetIndex = Widgets.IndexOf(widgetModel);
+ Widgets.Move(widgetIndex, place);
+ }
+ }
+}
diff --git a/Files/Views/YourHome.xaml b/Files/Views/YourHome.xaml
index c3d8753d88ce..352447d731f3 100644
--- a/Files/Views/YourHome.xaml
+++ b/Files/Views/YourHome.xaml
@@ -16,6 +16,13 @@
+
+
+
Date: Sun, 4 Apr 2021 16:11:13 +0200
Subject: [PATCH 02/15] CodeFactor
---
Files/UserControls/Widgets/DrivesWidget.xaml.cs | 2 +-
Files/UserControls/Widgets/WidgetsListControl.xaml | 4 +---
Files/Views/YourHome.xaml.cs | 9 ++++-----
3 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/Files/UserControls/Widgets/DrivesWidget.xaml.cs b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
index cd2846ab78e2..0d50084327d0 100644
--- a/Files/UserControls/Widgets/DrivesWidget.xaml.cs
+++ b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
@@ -33,7 +33,6 @@ public sealed partial class DrivesWidget : UserControl, INotifyPropertyChanged
public static ObservableCollection ItemsAdded = new ObservableCollection();
-
private IShellPage associatedInstance;
public IShellPage AppInstance
@@ -44,6 +43,7 @@ public IShellPage AppInstance
if (value != associatedInstance)
{
associatedInstance = value;
+ NotifyPropertyChanged(nameof(AppInstance));
}
}
}
diff --git a/Files/UserControls/Widgets/WidgetsListControl.xaml b/Files/UserControls/Widgets/WidgetsListControl.xaml
index dfa37389c61b..6d5120c7af4f 100644
--- a/Files/UserControls/Widgets/WidgetsListControl.xaml
+++ b/Files/UserControls/Widgets/WidgetsListControl.xaml
@@ -35,9 +35,7 @@
-
-
-
+
diff --git a/Files/Views/YourHome.xaml.cs b/Files/Views/YourHome.xaml.cs
index 0e61f4f8cdc7..5806db2eb06c 100644
--- a/Files/Views/YourHome.xaml.cs
+++ b/Files/Views/YourHome.xaml.cs
@@ -30,12 +30,11 @@ public YourHome()
private async void YourHome_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
- Bundles b_widget = new Bundles();
- b_widget.ViewModel.Initialize(AppInstance);
- await b_widget.ViewModel.Load();
+ Bundles bundlesWidget = new Bundles();
+ bundlesWidget.ViewModel.Initialize(AppInstance);
+ await bundlesWidget.ViewModel.Load();
-
- Widgets.ViewModel.AddWidget(b_widget);
+ Widgets.ViewModel.AddWidget(bundlesWidget);
if (DrivesWidget != null)
{
From a2eef9f067cf43bfd93a88af06fbcbd9b19dc025 Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Sun, 4 Apr 2021 22:26:57 +0200
Subject: [PATCH 03/15] Bug fixes
---
Files/Files.csproj | 1 +
Files/Helpers/WidgetsHelpers.cs | 60 ++++++++++++++++++
Files/UserControls/Widgets/Bundles.xaml.cs | 10 ++-
.../UserControls/Widgets/DrivesWidget.xaml.cs | 4 +-
.../UserControls/Widgets/LibraryCards.xaml.cs | 5 +-
.../UserControls/Widgets/RecentFiles.xaml.cs | 5 +-
.../Widgets/WidgetsListControl.xaml | 10 +--
Files/ViewModels/Widgets/IWidgetItemModel.cs | 8 ++-
.../Widgets/WidgetsListControlViewModel.cs | 23 ++++---
Files/Views/YourHome.xaml | 16 -----
Files/Views/YourHome.xaml.cs | 63 ++++++++++---------
11 files changed, 134 insertions(+), 71 deletions(-)
create mode 100644 Files/Helpers/WidgetsHelpers.cs
diff --git a/Files/Files.csproj b/Files/Files.csproj
index 7acf9d2f7657..471f80427dfa 100644
--- a/Files/Files.csproj
+++ b/Files/Files.csproj
@@ -220,6 +220,7 @@
+
RestartControl.xaml
diff --git a/Files/Helpers/WidgetsHelpers.cs b/Files/Helpers/WidgetsHelpers.cs
new file mode 100644
index 000000000000..a297e2fa87f3
--- /dev/null
+++ b/Files/Helpers/WidgetsHelpers.cs
@@ -0,0 +1,60 @@
+using Files.UserControls.Widgets;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Files.Helpers
+{
+ public static class WidgetsHelpers
+ {
+ public static LibraryCards GetLibraryCards()
+ {
+ if (App.AppSettings.ShowLibraryCardsWidget)
+ {
+ return new LibraryCards();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public static DrivesWidget GetDrivesWidget()
+ {
+ if (App.AppSettings.ShowDrivesWidget)
+ {
+ return new DrivesWidget();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public static Bundles GetBundles()
+ {
+ if (App.AppSettings.ShowBundlesWidget)
+ {
+ return new Bundles();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public static RecentFiles GetRecentFiles()
+ {
+ if (App.AppSettings.ShowBundlesWidget)
+ {
+ return new RecentFiles();
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+}
diff --git a/Files/UserControls/Widgets/Bundles.xaml.cs b/Files/UserControls/Widgets/Bundles.xaml.cs
index 0f7e0c636152..ce7ee17f5867 100644
--- a/Files/UserControls/Widgets/Bundles.xaml.cs
+++ b/Files/UserControls/Widgets/Bundles.xaml.cs
@@ -1,9 +1,7 @@
-using Files.ViewModels.Widgets;
-using Files.ViewModels.Widgets.Bundles;
-using System;
-using System.ComponentModel;
-using System.Runtime.CompilerServices;
+using System;
using Windows.UI.Xaml.Controls;
+using Files.ViewModels.Widgets.Bundles;
+using Files.ViewModels.Widgets;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
@@ -17,7 +15,7 @@ public BundlesViewModel ViewModel
private set => DataContext = value;
}
- public Control WidgetContent => this;
+ public string WidgetName => nameof(Bundles);
public Bundles()
{
diff --git a/Files/UserControls/Widgets/DrivesWidget.xaml.cs b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
index 0d50084327d0..7f724ad7da44 100644
--- a/Files/UserControls/Widgets/DrivesWidget.xaml.cs
+++ b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
@@ -17,7 +17,7 @@
namespace Files.UserControls.Widgets
{
- public sealed partial class DrivesWidget : UserControl, INotifyPropertyChanged
+ public sealed partial class DrivesWidget : UserControl, IWidgetItemModel, INotifyPropertyChanged
{
public SettingsViewModel AppSettings => App.AppSettings;
@@ -48,6 +48,8 @@ public IShellPage AppInstance
}
}
+ public string WidgetName => nameof(DrivesWidget);
+
public DrivesWidget()
{
InitializeComponent();
diff --git a/Files/UserControls/Widgets/LibraryCards.xaml.cs b/Files/UserControls/Widgets/LibraryCards.xaml.cs
index 8dc05eaf0d79..3d65ec19a22f 100644
--- a/Files/UserControls/Widgets/LibraryCards.xaml.cs
+++ b/Files/UserControls/Widgets/LibraryCards.xaml.cs
@@ -5,6 +5,7 @@
using Files.Interacts;
using Files.ViewModels;
using Files.ViewModels.Dialogs;
+using Files.ViewModels.Widgets;
using Microsoft.Toolkit.Mvvm.Input;
using Microsoft.Toolkit.Uwp;
using System;
@@ -21,7 +22,7 @@
namespace Files.UserControls.Widgets
{
- public sealed partial class LibraryCards : UserControl, INotifyPropertyChanged
+ public sealed partial class LibraryCards : UserControl, IWidgetItemModel, INotifyPropertyChanged
{
public SettingsViewModel AppSettings => App.AppSettings;
@@ -45,6 +46,8 @@ public sealed partial class LibraryCards : UserControl, INotifyPropertyChanged
public BulkConcurrentObservableCollection ItemsAdded = new BulkConcurrentObservableCollection();
+ public string WidgetName => nameof(LibraryCards);
+
public RelayCommand LibraryCardClicked => new RelayCommand(item =>
{
if (string.IsNullOrEmpty(item.Path))
diff --git a/Files/UserControls/Widgets/RecentFiles.xaml.cs b/Files/UserControls/Widgets/RecentFiles.xaml.cs
index 525c3846f4fb..bdcb43ec07d6 100644
--- a/Files/UserControls/Widgets/RecentFiles.xaml.cs
+++ b/Files/UserControls/Widgets/RecentFiles.xaml.cs
@@ -1,6 +1,7 @@
using Files.Enums;
using Files.Filesystem;
using Files.ViewModels;
+using Files.ViewModels.Widgets;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
@@ -15,7 +16,7 @@
namespace Files.UserControls.Widgets
{
- public sealed partial class RecentFiles : UserControl
+ public sealed partial class RecentFiles : UserControl, IWidgetItemModel
{
public delegate void RecentFilesOpenLocationInvokedEventHandler(object sender, PathNavigationEventArgs e);
@@ -29,6 +30,8 @@ public sealed partial class RecentFiles : UserControl
private EmptyRecentsText Empty { get; set; } = new EmptyRecentsText();
public SettingsViewModel AppSettings => App.AppSettings;
+ public string WidgetName => nameof(RecentFiles);
+
public RecentFiles()
{
InitializeComponent();
diff --git a/Files/UserControls/Widgets/WidgetsListControl.xaml b/Files/UserControls/Widgets/WidgetsListControl.xaml
index 6d5120c7af4f..5f814eda1a9a 100644
--- a/Files/UserControls/Widgets/WidgetsListControl.xaml
+++ b/Files/UserControls/Widgets/WidgetsListControl.xaml
@@ -14,11 +14,13 @@
+ ItemsSource="{x:Bind ViewModel.Widgets, Mode=OneWay}">
-
-
-
-
-
-
diff --git a/Files/ViewModels/Widgets/IWidgetItemModel.cs b/Files/ViewModels/Widgets/IWidgetItemModel.cs
index ef65e57088a5..cbff50a0dd0b 100644
--- a/Files/ViewModels/Widgets/IWidgetItemModel.cs
+++ b/Files/ViewModels/Widgets/IWidgetItemModel.cs
@@ -1,9 +1,13 @@
-using Windows.UI.Xaml.Controls;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
namespace Files.ViewModels.Widgets
{
public interface IWidgetItemModel
{
- Control WidgetContent { get; }
+ string WidgetName { get; }
}
}
diff --git a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
index 935b1f9892e6..985dffc3433b 100644
--- a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
+++ b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
@@ -1,21 +1,24 @@
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System;
-using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
namespace Files.ViewModels.Widgets
{
public class WidgetsListControlViewModel : ObservableObject
{
- public ObservableCollection Widgets { get; private set; } = new ObservableCollection();
+ public ObservableCollection Widgets { get; private set; } = new ObservableCollection();
- public bool AddWidget(IWidgetItemModel widgetModel)
+ public bool AddWidget(Control widgetModel)
{
- if (widgetModel == null)
+ // The widget must not be null and must implement IWidgetItemModel
+ if (!(widgetModel is IWidgetItemModel widgetItemModel))
+ {
+ return false;
+ }
+
+ if (Widgets.Any((item) => (item as IWidgetItemModel).WidgetName == widgetItemModel.WidgetName))
{
return false;
}
@@ -24,12 +27,14 @@ public bool AddWidget(IWidgetItemModel widgetModel)
return true;
}
- public bool RemoveWidget(IWidgetItemModel widgetModel)
+ public void RemoveWidget(Control widgetModel)
{
- return Widgets.Remove(widgetModel);
+ int indexToRemove = Widgets.IndexOf(widgetModel);
+ (Widgets[indexToRemove] as IDisposable)?.Dispose();
+ Widgets.RemoveAt(indexToRemove);
}
- public void ReorderWidget(IWidgetItemModel widgetModel, int place)
+ public void ReorderWidget(Control widgetModel, int place)
{
int widgetIndex = Widgets.IndexOf(widgetModel);
Widgets.Move(widgetIndex, place);
diff --git a/Files/Views/YourHome.xaml b/Files/Views/YourHome.xaml
index 352447d731f3..05e035911827 100644
--- a/Files/Views/YourHome.xaml
+++ b/Files/Views/YourHome.xaml
@@ -19,24 +19,8 @@
-
-
-
-
-
-
-
-
diff --git a/Files/Views/YourHome.xaml.cs b/Files/Views/YourHome.xaml.cs
index 5806db2eb06c..ba207a6ce58d 100644
--- a/Files/Views/YourHome.xaml.cs
+++ b/Files/Views/YourHome.xaml.cs
@@ -30,41 +30,48 @@ public YourHome()
private async void YourHome_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
- Bundles bundlesWidget = new Bundles();
- bundlesWidget.ViewModel.Initialize(AppInstance);
- await bundlesWidget.ViewModel.Load();
+ var libraryCards = WidgetsHelpers.GetLibraryCards();
+ var drivesWidget = WidgetsHelpers.GetDrivesWidget();
+ var bundles = WidgetsHelpers.GetBundles();
+ var recentFiles = WidgetsHelpers.GetRecentFiles();
- Widgets.ViewModel.AddWidget(bundlesWidget);
-
- if (DrivesWidget != null)
+ if (libraryCards != null)
{
- DrivesWidget.DrivesWidgetInvoked -= DrivesWidget_DrivesWidgetInvoked;
- DrivesWidget.DrivesWidgetNewPaneInvoked -= DrivesWidget_DrivesWidgetNewPaneInvoked;
- DrivesWidget.DrivesWidgetInvoked += DrivesWidget_DrivesWidgetInvoked;
- DrivesWidget.DrivesWidgetNewPaneInvoked += DrivesWidget_DrivesWidgetNewPaneInvoked;
+ libraryCards.LibraryCardInvoked -= LibraryWidget_LibraryCardInvoked;
+ libraryCards.LibraryCardNewPaneInvoked -= LibraryWidget_LibraryCardNewPaneInvoked;
+ libraryCards.LibraryCardInvoked += LibraryWidget_LibraryCardInvoked;
+ libraryCards.LibraryCardNewPaneInvoked += LibraryWidget_LibraryCardNewPaneInvoked;
+ libraryCards.LibraryCardPropertiesInvoked -= LibraryWidget_LibraryCardPropertiesInvoked;
+ libraryCards.LibraryCardPropertiesInvoked += LibraryWidget_LibraryCardPropertiesInvoked;
+ libraryCards.LibraryCardDeleteInvoked -= LibraryWidget_LibraryCardDeleteInvoked;
+ libraryCards.LibraryCardDeleteInvoked += LibraryWidget_LibraryCardDeleteInvoked;
+
+ Widgets.ViewModel.AddWidget(libraryCards);
}
- if (LibraryWidget != null)
+ if (drivesWidget != null)
{
- LibraryWidget.LibraryCardInvoked -= LibraryWidget_LibraryCardInvoked;
- LibraryWidget.LibraryCardNewPaneInvoked -= LibraryWidget_LibraryCardNewPaneInvoked;
- LibraryWidget.LibraryCardInvoked += LibraryWidget_LibraryCardInvoked;
- LibraryWidget.LibraryCardNewPaneInvoked += LibraryWidget_LibraryCardNewPaneInvoked;
- LibraryWidget.LibraryCardPropertiesInvoked -= LibraryWidget_LibraryCardPropertiesInvoked;
- LibraryWidget.LibraryCardPropertiesInvoked += LibraryWidget_LibraryCardPropertiesInvoked;
- LibraryWidget.LibraryCardDeleteInvoked -= LibraryWidget_LibraryCardDeleteInvoked;
- LibraryWidget.LibraryCardDeleteInvoked += LibraryWidget_LibraryCardDeleteInvoked;
+ drivesWidget.DrivesWidgetInvoked -= DrivesWidget_DrivesWidgetInvoked;
+ drivesWidget.DrivesWidgetNewPaneInvoked -= DrivesWidget_DrivesWidgetNewPaneInvoked;
+ drivesWidget.DrivesWidgetInvoked += DrivesWidget_DrivesWidgetInvoked;
+ drivesWidget.DrivesWidgetNewPaneInvoked += DrivesWidget_DrivesWidgetNewPaneInvoked;
+
+ Widgets.ViewModel.AddWidget(drivesWidget);
}
- if (RecentFilesWidget != null)
+ if (bundles != null)
{
- RecentFilesWidget.RecentFilesOpenLocationInvoked -= RecentFilesWidget_RecentFilesOpenLocationInvoked;
- RecentFilesWidget.RecentFileInvoked -= RecentFilesWidget_RecentFileInvoked;
- RecentFilesWidget.RecentFilesOpenLocationInvoked += RecentFilesWidget_RecentFilesOpenLocationInvoked;
- RecentFilesWidget.RecentFileInvoked += RecentFilesWidget_RecentFileInvoked;
+ Widgets.ViewModel.AddWidget(bundles);
+
+ bundles.ViewModel.Initialize(AppInstance);
+ await bundles.ViewModel.Load();
}
- if (BundlesWidget != null)
+ if (recentFiles != null)
{
- (BundlesWidget?.DataContext as BundlesViewModel)?.Initialize(AppInstance);
- (BundlesWidget?.DataContext as BundlesViewModel)?.Load();
+ recentFiles.RecentFilesOpenLocationInvoked -= RecentFilesWidget_RecentFilesOpenLocationInvoked;
+ recentFiles.RecentFileInvoked -= RecentFilesWidget_RecentFileInvoked;
+ recentFiles.RecentFilesOpenLocationInvoked += RecentFilesWidget_RecentFilesOpenLocationInvoked;
+ recentFiles.RecentFileInvoked += RecentFilesWidget_RecentFileInvoked;
+
+ Widgets.ViewModel.AddWidget(recentFiles);
}
}
@@ -194,7 +201,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
// This IDisposable.Dispose() needs to be called to unhook events in BundlesWidget to avoid memory leaks.
public void Dispose()
{
- BundlesWidget?.Dispose();
+ //BundlesWidget?.Dispose();
}
#endregion IDisposable
From 245766335b651eda28c80ef7720b98772c5d37a6 Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Sun, 4 Apr 2021 22:47:54 +0200
Subject: [PATCH 04/15] Added IDisposable for widgets
---
.../Widgets/WidgetsListControl.xaml.cs | 8 +++++++-
.../Widgets/WidgetsListControlViewModel.cs | 14 +++++++++++++-
Files/Views/YourHome.xaml.cs | 2 +-
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/Files/UserControls/Widgets/WidgetsListControl.xaml.cs b/Files/UserControls/Widgets/WidgetsListControl.xaml.cs
index cd362c4222e1..c473873e858d 100644
--- a/Files/UserControls/Widgets/WidgetsListControl.xaml.cs
+++ b/Files/UserControls/Widgets/WidgetsListControl.xaml.cs
@@ -1,11 +1,12 @@
using Windows.UI.Xaml.Controls;
using Files.ViewModels.Widgets;
+using System;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace Files.UserControls.Widgets
{
- public sealed partial class WidgetsListControl : UserControl
+ public sealed partial class WidgetsListControl : UserControl, IDisposable
{
public WidgetsListControlViewModel ViewModel
{
@@ -19,5 +20,10 @@ public WidgetsListControl()
this.ViewModel = new WidgetsListControlViewModel();
}
+
+ public void Dispose()
+ {
+ ViewModel?.Dispose();
+ }
}
}
diff --git a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
index 985dffc3433b..71ee2ea505a4 100644
--- a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
+++ b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
@@ -6,7 +6,7 @@
namespace Files.ViewModels.Widgets
{
- public class WidgetsListControlViewModel : ObservableObject
+ public class WidgetsListControlViewModel : ObservableObject, IDisposable
{
public ObservableCollection Widgets { get; private set; } = new ObservableCollection();
@@ -18,6 +18,7 @@ public bool AddWidget(Control widgetModel)
return false;
}
+ // Don't add existing ones!
if (Widgets.Any((item) => (item as IWidgetItemModel).WidgetName == widgetItemModel.WidgetName))
{
return false;
@@ -39,5 +40,16 @@ public void ReorderWidget(Control widgetModel, int place)
int widgetIndex = Widgets.IndexOf(widgetModel);
Widgets.Move(widgetIndex, place);
}
+
+ public void Dispose()
+ {
+ for (int i = 0; i < Widgets.Count; i++)
+ {
+ (Widgets[i] as IDisposable)?.Dispose();
+ }
+
+ Widgets.Clear();
+ Widgets = null;
+ }
}
}
diff --git a/Files/Views/YourHome.xaml.cs b/Files/Views/YourHome.xaml.cs
index ba207a6ce58d..dafebe65f2d5 100644
--- a/Files/Views/YourHome.xaml.cs
+++ b/Files/Views/YourHome.xaml.cs
@@ -201,7 +201,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
// This IDisposable.Dispose() needs to be called to unhook events in BundlesWidget to avoid memory leaks.
public void Dispose()
{
- //BundlesWidget?.Dispose();
+ Widgets?.Dispose();
}
#endregion IDisposable
From 00a7a827c7c338cffe31fb8567fa6ae30e948813 Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Sun, 4 Apr 2021 23:04:19 +0200
Subject: [PATCH 05/15] Improved code
---
.../Widgets/WidgetsListControlViewModel.cs | 7 +++++-
Files/Views/YourHome.xaml.cs | 25 ++++++++++++++++---
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
index 71ee2ea505a4..4140938b68e3 100644
--- a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
+++ b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
@@ -19,7 +19,7 @@ public bool AddWidget(Control widgetModel)
}
// Don't add existing ones!
- if (Widgets.Any((item) => (item as IWidgetItemModel).WidgetName == widgetItemModel.WidgetName))
+ if (!CanAddWidget(widgetItemModel.WidgetName))
{
return false;
}
@@ -28,6 +28,11 @@ public bool AddWidget(Control widgetModel)
return true;
}
+ public bool CanAddWidget(string widgetName)
+ {
+ return !(Widgets.Any((item) => (item as IWidgetItemModel).WidgetName == widgetName));
+ }
+
public void RemoveWidget(Control widgetModel)
{
int indexToRemove = Widgets.IndexOf(widgetModel);
diff --git a/Files/Views/YourHome.xaml.cs b/Files/Views/YourHome.xaml.cs
index dafebe65f2d5..abc7bebea0a7 100644
--- a/Files/Views/YourHome.xaml.cs
+++ b/Files/Views/YourHome.xaml.cs
@@ -30,10 +30,27 @@ public YourHome()
private async void YourHome_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
- var libraryCards = WidgetsHelpers.GetLibraryCards();
- var drivesWidget = WidgetsHelpers.GetDrivesWidget();
- var bundles = WidgetsHelpers.GetBundles();
- var recentFiles = WidgetsHelpers.GetRecentFiles();
+ LibraryCards libraryCards = null;
+ DrivesWidget drivesWidget = null;
+ Bundles bundles = null;
+ RecentFiles recentFiles = null;
+
+ if (Widgets.ViewModel.CanAddWidget(nameof(LibraryCards)))
+ {
+ libraryCards = WidgetsHelpers.GetLibraryCards();
+ }
+ if (Widgets.ViewModel.CanAddWidget(nameof(DrivesWidget)))
+ {
+ drivesWidget = WidgetsHelpers.GetDrivesWidget();
+ }
+ if (Widgets.ViewModel.CanAddWidget(nameof(Bundles)))
+ {
+ bundles = WidgetsHelpers.GetBundles();
+ }
+ if (Widgets.ViewModel.CanAddWidget(nameof(RecentFiles)))
+ {
+ recentFiles = WidgetsHelpers.GetRecentFiles();
+ }
if (libraryCards != null)
{
From 71f4a35a5cc6a21ba428d275bd142c7daa1aad0c Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Mon, 5 Apr 2021 13:00:24 +0200
Subject: [PATCH 06/15] Fix DrivesWidget
---
Files/UserControls/Widgets/DrivesWidget.xaml.cs | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/Files/UserControls/Widgets/DrivesWidget.xaml.cs b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
index 7f724ad7da44..7f87722f12a9 100644
--- a/Files/UserControls/Widgets/DrivesWidget.xaml.cs
+++ b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
@@ -118,19 +118,9 @@ private void GridScaleNormal(object sender, Windows.UI.Xaml.Input.PointerRoutedE
visual.Scale = new Vector3(1);
}
- private bool showMultiPaneControls;
-
public bool ShowMultiPaneControls
{
- get => showMultiPaneControls;
- set
- {
- if (value != showMultiPaneControls)
- {
- showMultiPaneControls = value;
- NotifyPropertyChanged(nameof(ShowMultiPaneControls));
- }
- }
+ get => AppInstance.IsMultiPaneEnabled && AppInstance.IsPageMainPane;
}
private void OpenInNewPane_Click(object sender, RoutedEventArgs e)
From f5e04caff7040c53ba83192111088c1a70030988 Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Mon, 5 Apr 2021 13:17:51 +0200
Subject: [PATCH 07/15] Fix library cards and drives
---
Files/UserControls/Widgets/LibraryCards.xaml.cs | 9 ++++++++-
Files/Views/YourHome.xaml.cs | 10 ++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/Files/UserControls/Widgets/LibraryCards.xaml.cs b/Files/UserControls/Widgets/LibraryCards.xaml.cs
index 3d65ec19a22f..8215fed8e90b 100644
--- a/Files/UserControls/Widgets/LibraryCards.xaml.cs
+++ b/Files/UserControls/Widgets/LibraryCards.xaml.cs
@@ -42,6 +42,8 @@ public sealed partial class LibraryCards : UserControl, IWidgetItemModel, INotif
public event LibraryCardDeleteInvokedEventHandler LibraryCardDeleteInvoked;
+ public event EventHandler LibraryCardShowMultiPaneControlsInvoked;
+
public event PropertyChangedEventHandler PropertyChanged;
public BulkConcurrentObservableCollection ItemsAdded = new BulkConcurrentObservableCollection();
@@ -157,7 +159,12 @@ private void GridScaleNormal(object sender, Windows.UI.Xaml.Input.PointerRoutedE
public bool ShowMultiPaneControls
{
- get => showMultiPaneControls;
+ get
+ {
+ LibraryCardShowMultiPaneControlsInvoked?.Invoke(this, EventArgs.Empty);
+
+ return showMultiPaneControls;
+ }
set
{
if (value != showMultiPaneControls)
diff --git a/Files/Views/YourHome.xaml.cs b/Files/Views/YourHome.xaml.cs
index abc7bebea0a7..7eafbe31ab63 100644
--- a/Files/Views/YourHome.xaml.cs
+++ b/Files/Views/YourHome.xaml.cs
@@ -62,11 +62,14 @@ private async void YourHome_Loaded(object sender, Windows.UI.Xaml.RoutedEventArg
libraryCards.LibraryCardPropertiesInvoked += LibraryWidget_LibraryCardPropertiesInvoked;
libraryCards.LibraryCardDeleteInvoked -= LibraryWidget_LibraryCardDeleteInvoked;
libraryCards.LibraryCardDeleteInvoked += LibraryWidget_LibraryCardDeleteInvoked;
+ libraryCards.LibraryCardShowMultiPaneControlsInvoked -= LibraryCards_LibraryCardShowMultiPaneControlsInvoked;
+ libraryCards.LibraryCardShowMultiPaneControlsInvoked += LibraryCards_LibraryCardShowMultiPaneControlsInvoked;
Widgets.ViewModel.AddWidget(libraryCards);
}
if (drivesWidget != null)
{
+ drivesWidget.AppInstance = AppInstance;
drivesWidget.DrivesWidgetInvoked -= DrivesWidget_DrivesWidgetInvoked;
drivesWidget.DrivesWidgetNewPaneInvoked -= DrivesWidget_DrivesWidgetNewPaneInvoked;
drivesWidget.DrivesWidgetInvoked += DrivesWidget_DrivesWidgetInvoked;
@@ -92,6 +95,13 @@ private async void YourHome_Loaded(object sender, Windows.UI.Xaml.RoutedEventArg
}
}
+ private void LibraryCards_LibraryCardShowMultiPaneControlsInvoked(object sender, EventArgs e)
+ {
+ LibraryCards libraryCards = sender as LibraryCards;
+
+ libraryCards.ShowMultiPaneControls = AppInstance.IsMultiPaneEnabled && AppInstance.IsPageMainPane;
+ }
+
private async void RecentFilesWidget_RecentFileInvoked(object sender, UserControls.PathNavigationEventArgs e)
{
try
From 45b4c1761629ebf25c6b80120769af112816d6c9 Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Mon, 5 Apr 2021 13:44:28 +0200
Subject: [PATCH 08/15] Made the code very flexible
---
Files/Files.csproj | 1 +
Files/Helpers/WidgetsHelpers.cs | 56 +++++++------------
.../UserControls/Widgets/DrivesWidget.xaml.cs | 5 ++
.../UserControls/Widgets/LibraryCards.xaml.cs | 5 ++
.../UserControls/Widgets/RecentFiles.xaml.cs | 5 ++
.../Widgets/ICustomWidgetItemModel.cs | 9 +++
Files/ViewModels/Widgets/IWidgetItemModel.cs | 6 +-
Files/Views/YourHome.xaml | 11 +---
Files/Views/YourHome.xaml.cs | 26 ++-------
9 files changed, 54 insertions(+), 70 deletions(-)
create mode 100644 Files/ViewModels/Widgets/ICustomWidgetItemModel.cs
diff --git a/Files/Files.csproj b/Files/Files.csproj
index 471f80427dfa..889e95416dc8 100644
--- a/Files/Files.csproj
+++ b/Files/Files.csproj
@@ -459,6 +459,7 @@
+
diff --git a/Files/Helpers/WidgetsHelpers.cs b/Files/Helpers/WidgetsHelpers.cs
index a297e2fa87f3..d24462f2365b 100644
--- a/Files/Helpers/WidgetsHelpers.cs
+++ b/Files/Helpers/WidgetsHelpers.cs
@@ -1,60 +1,46 @@
using Files.UserControls.Widgets;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using Files.ViewModels.Widgets;
namespace Files.Helpers
{
public static class WidgetsHelpers
{
- public static LibraryCards GetLibraryCards()
+ public static TWidget TryGetWidget(WidgetsListControlViewModel widgetsViewModel) where TWidget : IWidgetItemModel, new()
{
- if (App.AppSettings.ShowLibraryCardsWidget)
+ if (widgetsViewModel.CanAddWidget(nameof(TWidget)) && TryGetIsWidgetSettingEnabled())
{
- return new LibraryCards();
- }
- else
- {
- return null;
+ return new TWidget();
}
+
+ return default(TWidget);
}
- public static DrivesWidget GetDrivesWidget()
+ public static bool TryGetIsWidgetSettingEnabled() where TWidget : IWidgetItemModel, new()
{
- if (App.AppSettings.ShowDrivesWidget)
+ if (typeof(TWidget) == typeof(LibraryCards))
{
- return new DrivesWidget();
+ return App.AppSettings.ShowLibraryCardsWidget;
}
- else
- {
- return null;
- }
- }
-
- public static Bundles GetBundles()
- {
- if (App.AppSettings.ShowBundlesWidget)
+ if (typeof(TWidget) == typeof(DrivesWidget))
{
- return new Bundles();
+ return App.AppSettings.ShowDrivesWidget;
}
- else
+ if (typeof(TWidget) == typeof(Bundles))
{
- return null;
+ return App.AppSettings.ShowBundlesWidget;
}
- }
-
- public static RecentFiles GetRecentFiles()
- {
- if (App.AppSettings.ShowBundlesWidget)
+ if (typeof(TWidget) == typeof(RecentFiles))
{
- return new RecentFiles();
+ return App.AppSettings.ShowRecentFilesWidget;
}
- else
+ // A custom widget it is - TWidget implements ICustomWidgetItemModel
+ if (typeof(ICustomWidgetItemModel).IsAssignableFrom(typeof(TWidget)))
{
- return null;
+ // Return true for custom widgets - they're always enabled
+ return true;
}
+
+ return false;
}
}
}
diff --git a/Files/UserControls/Widgets/DrivesWidget.xaml.cs b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
index 7f87722f12a9..1cabbd53ac1e 100644
--- a/Files/UserControls/Widgets/DrivesWidget.xaml.cs
+++ b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
@@ -168,5 +168,10 @@ private async void GoToStorageSense_Click(object sender, RoutedEventArgs e)
{
await Launcher.LaunchUriAsync(new Uri("ms-settings:storagesense"));
}
+
+ public void Dispose()
+ {
+ throw new NotImplementedException();
+ }
}
}
\ No newline at end of file
diff --git a/Files/UserControls/Widgets/LibraryCards.xaml.cs b/Files/UserControls/Widgets/LibraryCards.xaml.cs
index 8215fed8e90b..a9c32780da2c 100644
--- a/Files/UserControls/Widgets/LibraryCards.xaml.cs
+++ b/Files/UserControls/Widgets/LibraryCards.xaml.cs
@@ -306,6 +306,11 @@ private async void DeleteLibrary_Click(object sender, RoutedEventArgs e)
await dialog.ShowAsync();
}
}
+
+ public void Dispose()
+ {
+ throw new NotImplementedException();
+ }
}
public class LibraryCardInvokedEventArgs : EventArgs
diff --git a/Files/UserControls/Widgets/RecentFiles.xaml.cs b/Files/UserControls/Widgets/RecentFiles.xaml.cs
index bdcb43ec07d6..8a4e7d028e37 100644
--- a/Files/UserControls/Widgets/RecentFiles.xaml.cs
+++ b/Files/UserControls/Widgets/RecentFiles.xaml.cs
@@ -209,6 +209,11 @@ private void ClearRecentItems_Click(object sender, RoutedEventArgs e)
mru.Clear();
Empty.Visibility = Visibility.Visible;
}
+
+ public void Dispose()
+ {
+ throw new NotImplementedException();
+ }
}
public class RecentItem
diff --git a/Files/ViewModels/Widgets/ICustomWidgetItemModel.cs b/Files/ViewModels/Widgets/ICustomWidgetItemModel.cs
new file mode 100644
index 000000000000..4b291b1f772f
--- /dev/null
+++ b/Files/ViewModels/Widgets/ICustomWidgetItemModel.cs
@@ -0,0 +1,9 @@
+namespace Files.ViewModels.Widgets
+{
+ ///
+ /// This interface is used to mark widgets that are not standard to Files
+ ///
+ public interface ICustomWidgetItemModel : IWidgetItemModel
+ {
+ }
+}
diff --git a/Files/ViewModels/Widgets/IWidgetItemModel.cs b/Files/ViewModels/Widgets/IWidgetItemModel.cs
index cbff50a0dd0b..3a9f58deffdb 100644
--- a/Files/ViewModels/Widgets/IWidgetItemModel.cs
+++ b/Files/ViewModels/Widgets/IWidgetItemModel.cs
@@ -1,12 +1,8 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Files.ViewModels.Widgets
{
- public interface IWidgetItemModel
+ public interface IWidgetItemModel : IDisposable
{
string WidgetName { get; }
}
diff --git a/Files/Views/YourHome.xaml b/Files/Views/YourHome.xaml
index 05e035911827..d753aa959b62 100644
--- a/Files/Views/YourHome.xaml
+++ b/Files/Views/YourHome.xaml
@@ -2,7 +2,6 @@
x:Class="Files.Views.YourHome"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:converters="using:Files.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:widgets="using:Files.UserControls.Widgets"
@@ -10,17 +9,11 @@
mc:Ignorable="d">
-
-
-
-
-
-
-
+
-
+
diff --git a/Files/Views/YourHome.xaml.cs b/Files/Views/YourHome.xaml.cs
index 7eafbe31ab63..294964aa9d1b 100644
--- a/Files/Views/YourHome.xaml.cs
+++ b/Files/Views/YourHome.xaml.cs
@@ -30,28 +30,12 @@ public YourHome()
private async void YourHome_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
- LibraryCards libraryCards = null;
- DrivesWidget drivesWidget = null;
- Bundles bundles = null;
- RecentFiles recentFiles = null;
-
- if (Widgets.ViewModel.CanAddWidget(nameof(LibraryCards)))
- {
- libraryCards = WidgetsHelpers.GetLibraryCards();
- }
- if (Widgets.ViewModel.CanAddWidget(nameof(DrivesWidget)))
- {
- drivesWidget = WidgetsHelpers.GetDrivesWidget();
- }
- if (Widgets.ViewModel.CanAddWidget(nameof(Bundles)))
- {
- bundles = WidgetsHelpers.GetBundles();
- }
- if (Widgets.ViewModel.CanAddWidget(nameof(RecentFiles)))
- {
- recentFiles = WidgetsHelpers.GetRecentFiles();
- }
+ var libraryCards = WidgetsHelpers.TryGetWidget(Widgets.ViewModel);
+ var drivesWidget = WidgetsHelpers.TryGetWidget(Widgets.ViewModel);
+ var bundles = WidgetsHelpers.TryGetWidget(Widgets.ViewModel);
+ var recentFiles = WidgetsHelpers.TryGetWidget(Widgets.ViewModel);
+ // Now prepare widgets
if (libraryCards != null)
{
libraryCards.LibraryCardInvoked -= LibraryWidget_LibraryCardInvoked;
From 6da9ec629c3d10fb36d5240c7ac9544c93a3d2a6 Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Mon, 5 Apr 2021 13:57:17 +0200
Subject: [PATCH 09/15] Fixes
---
Files/Helpers/WidgetsHelpers.cs | 4 ++--
Files/ViewModels/Widgets/ICustomWidgetItemModel.cs | 2 +-
Files/Views/YourHome.xaml.cs | 2 --
3 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/Files/Helpers/WidgetsHelpers.cs b/Files/Helpers/WidgetsHelpers.cs
index d24462f2365b..f0f5c9988a3b 100644
--- a/Files/Helpers/WidgetsHelpers.cs
+++ b/Files/Helpers/WidgetsHelpers.cs
@@ -7,7 +7,7 @@ public static class WidgetsHelpers
{
public static TWidget TryGetWidget(WidgetsListControlViewModel widgetsViewModel) where TWidget : IWidgetItemModel, new()
{
- if (widgetsViewModel.CanAddWidget(nameof(TWidget)) && TryGetIsWidgetSettingEnabled())
+ if (widgetsViewModel.CanAddWidget(typeof(TWidget).Name) && TryGetIsWidgetSettingEnabled())
{
return new TWidget();
}
@@ -15,7 +15,7 @@ public static class WidgetsHelpers
return default(TWidget);
}
- public static bool TryGetIsWidgetSettingEnabled() where TWidget : IWidgetItemModel, new()
+ public static bool TryGetIsWidgetSettingEnabled() where TWidget : IWidgetItemModel
{
if (typeof(TWidget) == typeof(LibraryCards))
{
diff --git a/Files/ViewModels/Widgets/ICustomWidgetItemModel.cs b/Files/ViewModels/Widgets/ICustomWidgetItemModel.cs
index 4b291b1f772f..78739fb6f372 100644
--- a/Files/ViewModels/Widgets/ICustomWidgetItemModel.cs
+++ b/Files/ViewModels/Widgets/ICustomWidgetItemModel.cs
@@ -1,7 +1,7 @@
namespace Files.ViewModels.Widgets
{
///
- /// This interface is used to mark widgets that are not standard to Files
+ /// This interface is used to mark widgets that are not standard to Files i.e. custom widgets
///
public interface ICustomWidgetItemModel : IWidgetItemModel
{
diff --git a/Files/Views/YourHome.xaml.cs b/Files/Views/YourHome.xaml.cs
index 294964aa9d1b..03aa7f707897 100644
--- a/Files/Views/YourHome.xaml.cs
+++ b/Files/Views/YourHome.xaml.cs
@@ -3,13 +3,11 @@
using Files.Helpers;
using Files.UserControls.Widgets;
using Files.ViewModels;
-using Files.ViewModels.Widgets.Bundles;
using Microsoft.Toolkit.Uwp;
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
-using Windows.ApplicationModel.AppService;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
From 3c882c7ef1a7825fb538ffb7f76a83dbdc992f43 Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Mon, 5 Apr 2021 14:15:47 +0200
Subject: [PATCH 10/15] Bug fixes
---
Files/Helpers/WidgetsHelpers.cs | 10 ++++++++-
.../UserControls/Widgets/DrivesWidget.xaml.cs | 3 ++-
.../UserControls/Widgets/LibraryCards.xaml.cs | 3 ++-
.../UserControls/Widgets/RecentFiles.xaml.cs | 3 ++-
.../Widgets/WidgetsListControlViewModel.cs | 22 +++++++++++++++++++
5 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/Files/Helpers/WidgetsHelpers.cs b/Files/Helpers/WidgetsHelpers.cs
index f0f5c9988a3b..ef2037c0f2ed 100644
--- a/Files/Helpers/WidgetsHelpers.cs
+++ b/Files/Helpers/WidgetsHelpers.cs
@@ -7,10 +7,18 @@ public static class WidgetsHelpers
{
public static TWidget TryGetWidget(WidgetsListControlViewModel widgetsViewModel) where TWidget : IWidgetItemModel, new()
{
- if (widgetsViewModel.CanAddWidget(typeof(TWidget).Name) && TryGetIsWidgetSettingEnabled())
+ bool canAddWidget = widgetsViewModel.CanAddWidget(typeof(TWidget).Name);
+ bool isWidgetSettingEnabled = TryGetIsWidgetSettingEnabled();
+
+ if (canAddWidget && isWidgetSettingEnabled)
{
return new TWidget();
}
+ else if (!canAddWidget && !isWidgetSettingEnabled) // The widgets exists but the setting has been disabled for it
+ {
+ // Remove the widget
+ widgetsViewModel.RemoveWidget();
+ }
return default(TWidget);
}
diff --git a/Files/UserControls/Widgets/DrivesWidget.xaml.cs b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
index 1cabbd53ac1e..bb22eae7cc9e 100644
--- a/Files/UserControls/Widgets/DrivesWidget.xaml.cs
+++ b/Files/UserControls/Widgets/DrivesWidget.xaml.cs
@@ -6,6 +6,7 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
+using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -171,7 +172,7 @@ private async void GoToStorageSense_Click(object sender, RoutedEventArgs e)
public void Dispose()
{
- throw new NotImplementedException();
+ Debugger.Break();
}
}
}
\ No newline at end of file
diff --git a/Files/UserControls/Widgets/LibraryCards.xaml.cs b/Files/UserControls/Widgets/LibraryCards.xaml.cs
index a9c32780da2c..77e26f2a3156 100644
--- a/Files/UserControls/Widgets/LibraryCards.xaml.cs
+++ b/Files/UserControls/Widgets/LibraryCards.xaml.cs
@@ -11,6 +11,7 @@
using System;
using System.Collections.Specialized;
using System.ComponentModel;
+using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -309,7 +310,7 @@ private async void DeleteLibrary_Click(object sender, RoutedEventArgs e)
public void Dispose()
{
- throw new NotImplementedException();
+ Debugger.Break();
}
}
diff --git a/Files/UserControls/Widgets/RecentFiles.xaml.cs b/Files/UserControls/Widgets/RecentFiles.xaml.cs
index 8a4e7d028e37..ba2167aff529 100644
--- a/Files/UserControls/Widgets/RecentFiles.xaml.cs
+++ b/Files/UserControls/Widgets/RecentFiles.xaml.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
+using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
@@ -212,7 +213,7 @@ private void ClearRecentItems_Click(object sender, RoutedEventArgs e)
public void Dispose()
{
- throw new NotImplementedException();
+ Debugger.Break();
}
}
diff --git a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
index 4140938b68e3..3b820f463c58 100644
--- a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
+++ b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
@@ -40,6 +40,28 @@ public void RemoveWidget(Control widgetModel)
Widgets.RemoveAt(indexToRemove);
}
+ public void RemoveWidget() where TWidget : IWidgetItemModel
+ {
+ int indexToRemove = -1;
+
+ for (int i = 0; i < Widgets.Count; i++)
+ {
+ if (typeof(TWidget).IsAssignableFrom(Widgets[i].GetType()))
+ {
+ // Found matching types
+ indexToRemove = i;
+ break;
+ }
+ }
+
+ if (indexToRemove == -1)
+ {
+ return;
+ }
+
+ RemoveWidget(Widgets[indexToRemove]);
+ }
+
public void ReorderWidget(Control widgetModel, int place)
{
int widgetIndex = Widgets.IndexOf(widgetModel);
From ed3e485ac113a99a053fb62187ad9c53f27205f8 Mon Sep 17 00:00:00 2001
From: Yair Aichenbaum <39923744+yaichenbaum@users.noreply.github.com>
Date: Mon, 5 Apr 2021 11:23:09 -0400
Subject: [PATCH 11/15] Improved xaml
---
Files/Views/YourHome.xaml | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/Files/Views/YourHome.xaml b/Files/Views/YourHome.xaml
index d753aa959b62..fd6175bb023b 100644
--- a/Files/Views/YourHome.xaml
+++ b/Files/Views/YourHome.xaml
@@ -9,11 +9,10 @@
mc:Ignorable="d">
-
-
-
+
From e3c36ff279a761a46644e5554ece60b81f6c1c64 Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Mon, 5 Apr 2021 17:33:12 +0200
Subject: [PATCH 12/15] Couple of code fixes and performance improvements
---
Files/Helpers/WidgetsHelpers.cs | 4 ++--
.../Widgets/WidgetsListControl.xaml | 2 ++
.../Widgets/WidgetsListControlViewModel.cs | 15 ++++++++++++-
Files/Views/YourHome.xaml.cs | 21 ++++++++++++-------
4 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/Files/Helpers/WidgetsHelpers.cs b/Files/Helpers/WidgetsHelpers.cs
index ef2037c0f2ed..d268ac3b3607 100644
--- a/Files/Helpers/WidgetsHelpers.cs
+++ b/Files/Helpers/WidgetsHelpers.cs
@@ -5,7 +5,7 @@ namespace Files.Helpers
{
public static class WidgetsHelpers
{
- public static TWidget TryGetWidget(WidgetsListControlViewModel widgetsViewModel) where TWidget : IWidgetItemModel, new()
+ public static TWidget TryGetWidget(WidgetsListControlViewModel widgetsViewModel, TWidget defaultValue = default(TWidget)) where TWidget : IWidgetItemModel, new()
{
bool canAddWidget = widgetsViewModel.CanAddWidget(typeof(TWidget).Name);
bool isWidgetSettingEnabled = TryGetIsWidgetSettingEnabled();
@@ -20,7 +20,7 @@ public static class WidgetsHelpers
widgetsViewModel.RemoveWidget();
}
- return default(TWidget);
+ return defaultValue;
}
public static bool TryGetIsWidgetSettingEnabled() where TWidget : IWidgetItemModel
diff --git a/Files/UserControls/Widgets/WidgetsListControl.xaml b/Files/UserControls/Widgets/WidgetsListControl.xaml
index 5f814eda1a9a..478fe9527a18 100644
--- a/Files/UserControls/Widgets/WidgetsListControl.xaml
+++ b/Files/UserControls/Widgets/WidgetsListControl.xaml
@@ -26,6 +26,8 @@
diff --git a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
index 3b820f463c58..45f16854ced4 100644
--- a/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
+++ b/Files/ViewModels/Widgets/WidgetsListControlViewModel.cs
@@ -11,6 +11,11 @@ public class WidgetsListControlViewModel : ObservableObject, IDisposable
public ObservableCollection Widgets { get; private set; } = new ObservableCollection();
public bool AddWidget(Control widgetModel)
+ {
+ return InsertWidget(widgetModel, Widgets.Count + 1);
+ }
+
+ public bool InsertWidget(Control widgetModel, int atIndex)
{
// The widget must not be null and must implement IWidgetItemModel
if (!(widgetModel is IWidgetItemModel widgetItemModel))
@@ -24,7 +29,15 @@ public bool AddWidget(Control widgetModel)
return false;
}
- Widgets.Add(widgetModel);
+ if (atIndex > Widgets.Count)
+ {
+ Widgets.Add(widgetModel);
+ }
+ else
+ {
+ Widgets.Insert(atIndex, widgetModel);
+ }
+
return true;
}
diff --git a/Files/Views/YourHome.xaml.cs b/Files/Views/YourHome.xaml.cs
index 03aa7f707897..97fd3117cf47 100644
--- a/Files/Views/YourHome.xaml.cs
+++ b/Files/Views/YourHome.xaml.cs
@@ -20,6 +20,11 @@ public sealed partial class YourHome : Page, IDisposable
public FolderSettingsViewModel FolderSettings => AppInstance?.InstanceViewModel.FolderSettings;
public NamedPipeAsAppServiceConnection Connection => AppInstance?.ServiceConnection;
+ LibraryCards libraryCards;
+ DrivesWidget drivesWidget;
+ Bundles bundles;
+ RecentFiles recentFiles;
+
public YourHome()
{
InitializeComponent();
@@ -28,10 +33,10 @@ public YourHome()
private async void YourHome_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
- var libraryCards = WidgetsHelpers.TryGetWidget(Widgets.ViewModel);
- var drivesWidget = WidgetsHelpers.TryGetWidget(Widgets.ViewModel);
- var bundles = WidgetsHelpers.TryGetWidget(Widgets.ViewModel);
- var recentFiles = WidgetsHelpers.TryGetWidget(Widgets.ViewModel);
+ libraryCards = WidgetsHelpers.TryGetWidget(Widgets.ViewModel, libraryCards);
+ drivesWidget = WidgetsHelpers.TryGetWidget(Widgets.ViewModel, drivesWidget);
+ bundles = WidgetsHelpers.TryGetWidget(Widgets.ViewModel, bundles);
+ recentFiles = WidgetsHelpers.TryGetWidget(Widgets.ViewModel, recentFiles);
// Now prepare widgets
if (libraryCards != null)
@@ -47,7 +52,7 @@ private async void YourHome_Loaded(object sender, Windows.UI.Xaml.RoutedEventArg
libraryCards.LibraryCardShowMultiPaneControlsInvoked -= LibraryCards_LibraryCardShowMultiPaneControlsInvoked;
libraryCards.LibraryCardShowMultiPaneControlsInvoked += LibraryCards_LibraryCardShowMultiPaneControlsInvoked;
- Widgets.ViewModel.AddWidget(libraryCards);
+ Widgets.ViewModel.InsertWidget(libraryCards, 0);
}
if (drivesWidget != null)
{
@@ -57,11 +62,11 @@ private async void YourHome_Loaded(object sender, Windows.UI.Xaml.RoutedEventArg
drivesWidget.DrivesWidgetInvoked += DrivesWidget_DrivesWidgetInvoked;
drivesWidget.DrivesWidgetNewPaneInvoked += DrivesWidget_DrivesWidgetNewPaneInvoked;
- Widgets.ViewModel.AddWidget(drivesWidget);
+ Widgets.ViewModel.InsertWidget(drivesWidget, 1);
}
if (bundles != null)
{
- Widgets.ViewModel.AddWidget(bundles);
+ Widgets.ViewModel.InsertWidget(bundles, 2);
bundles.ViewModel.Initialize(AppInstance);
await bundles.ViewModel.Load();
@@ -73,7 +78,7 @@ private async void YourHome_Loaded(object sender, Windows.UI.Xaml.RoutedEventArg
recentFiles.RecentFilesOpenLocationInvoked += RecentFilesWidget_RecentFilesOpenLocationInvoked;
recentFiles.RecentFileInvoked += RecentFilesWidget_RecentFileInvoked;
- Widgets.ViewModel.AddWidget(recentFiles);
+ Widgets.ViewModel.InsertWidget(recentFiles, 3);
}
}
From 9968775a0f257e7ecd999c5464f6a4b1fa365576 Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Mon, 5 Apr 2021 17:42:24 +0200
Subject: [PATCH 13/15] Fixed UI
---
Files/UserControls/Widgets/WidgetsListControl.xaml | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/Files/UserControls/Widgets/WidgetsListControl.xaml b/Files/UserControls/Widgets/WidgetsListControl.xaml
index 478fe9527a18..5de00be9e2f5 100644
--- a/Files/UserControls/Widgets/WidgetsListControl.xaml
+++ b/Files/UserControls/Widgets/WidgetsListControl.xaml
@@ -12,18 +12,18 @@
-
-
-
-
-
+
+
From 5ea863c932daa7635b6b8ac8c114db965ff1d8a9 Mon Sep 17 00:00:00 2001
From: Yair Aichenbaum <39923744+yaichenbaum@users.noreply.github.com>
Date: Mon, 5 Apr 2021 11:50:21 -0400
Subject: [PATCH 14/15] Fixed padding
---
Files/Views/YourHome.xaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Files/Views/YourHome.xaml b/Files/Views/YourHome.xaml
index fd6175bb023b..5ab5e68c77a1 100644
--- a/Files/Views/YourHome.xaml
+++ b/Files/Views/YourHome.xaml
@@ -11,7 +11,7 @@
From 0165a74db650bdfbcd0704c348c82771e6ffdfb2 Mon Sep 17 00:00:00 2001
From: d2dyno006 <53011783+d2dyno006@users.noreply.github.com>
Date: Mon, 5 Apr 2021 17:52:02 +0200
Subject: [PATCH 15/15] Fixed an issue where widgets would still appear after
they were disabled
---
Files/Helpers/WidgetsHelpers.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/Files/Helpers/WidgetsHelpers.cs b/Files/Helpers/WidgetsHelpers.cs
index d268ac3b3607..7ea36d3fc93c 100644
--- a/Files/Helpers/WidgetsHelpers.cs
+++ b/Files/Helpers/WidgetsHelpers.cs
@@ -18,6 +18,7 @@ public static class WidgetsHelpers
{
// Remove the widget
widgetsViewModel.RemoveWidget();
+ return default(TWidget);
}
return defaultValue;