Skip to content

Commit

Permalink
Simplify creation of PackagesPages, move building method to the const…
Browse files Browse the repository at this point in the history
…ructor
  • Loading branch information
marticliment committed Jun 21, 2024
1 parent e4b6d3d commit 2247f64
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public AbstractPackageLoader(IEnumerable<PackageManager> managers, bool AllowMul
/// Will trigger a forceful reload of the packages
/// </summary>
/// <returns></returns>
public async Task ReloadPackages()
public virtual async Task ReloadPackages()
{
IsLoading = true;
StartedLoading?.Invoke(this, new EventArgs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ public DiscoverablePackagesLoader(IEnumerable<PackageManager> managers)
LOADER_IDENTIFIER = "DISCOVERABLE_PACKAGES";
}

public async Task ReloadPackages(string query)
{
QUERY_TEXT = query;
await ReloadPackages();
}

public override async Task ReloadPackages()
{
if (QUERY_TEXT == "") return;
else await base.ReloadPackages();
}

#pragma warning disable
protected override async Task<bool> IsPackageValid(Package package)
{
Expand Down
8 changes: 4 additions & 4 deletions src/UniGetUI/Interface/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public sealed partial class MainView : UserControl
{
public SettingsInterface SettingsPage;
public NewDiscoverSoftwarePage DiscoverPage;
public NewSoftwareUpdatesPage UpdatesPage;
public NewInstalledPackagesPage InstalledPage;
public SoftwareUpdatesPage UpdatesPage;
public InstalledPackagesPage InstalledPage;
public HelpDialog? HelpPage;
public PackageBundlePage BundlesPage;
public Page? OldPage;
Expand All @@ -43,9 +43,9 @@ public MainView()
BundleBadge = __bundle_count_badge;
OperationStackPanel = __operations_list_stackpanel;
DiscoverPage = new NewDiscoverSoftwarePage();
UpdatesPage = new NewSoftwareUpdatesPage();
UpdatesPage = new SoftwareUpdatesPage();
UpdatesPage.ExternalCountBadge = UpdatesBadge;
InstalledPage = new NewInstalledPackagesPage();
InstalledPage = new InstalledPackagesPage();
BundlesPage = new PackageBundlePage();
SettingsPage = new SettingsInterface();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@
</Grid.RowDefinitions>
<FontIcon Grid.Column="0" Grid.Row="0" Grid.RowSpan="3"
x:Name="HeaderIcon" FontSize="50" FontWeight="Normal" Height="60" Width="60"/>
<widgets:TranslatedTextBlock x:Name="MainTitle" x:FieldModifier="protected"
<TextBlock x:Name="MainTitle" x:FieldModifier="protected"
Grid.Column="1" Grid.Row="0" Grid.RowSpan="2"
Text="" FontSize="30" Height="48"
HorizontalAlignment="Left"
Expand Down
193 changes: 101 additions & 92 deletions src/UniGetUI/Interface/SoftwarePages/AbstractPackagesPage.xaml.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System.Threading.Tasks.Dataflow;
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;
using UniGetUI.Interface.Enums;
Expand All @@ -9,6 +10,8 @@
using UniGetUI.PackageEngine.ManagerClasses.Manager;
using UniGetUI.PackageEngine.Operations;
using UniGetUI.PackageEngine.PackageClasses;
using UniGetUI.PackageEngine.PackageLoader;
using Windows.System;

namespace UniGetUI.Interface.SoftwarePages
{
Expand All @@ -18,8 +21,38 @@ public class NewDiscoverSoftwarePage : AbstractPackagesPage
BetterMenuItem? MenuInteractive;
BetterMenuItem? MenuSkipHash;
public NewDiscoverSoftwarePage()
: base(PEInterface.DiscoveredPackagesLoader)
: base(new PackagesPageData()
{
DisableAutomaticPackageLoadOnStart = true,
MegaQueryBlockEnabled = true,
ShowLastLoadTime = false,
PageName = "Discover",

Loader = PEInterface.DiscoveredPackagesLoader,
PageRole = OperationType.Install,

NoPackages_BackgroundText = CoreTools.Translate("No results were found matching the input criteria"),
NoPackages_SourcesText = CoreTools.Translate("No packages were found"),
NoPackages_SubtitleText_Base = CoreTools.Translate("No packages were found"),
MainSubtitle_StillLoading = CoreTools.Translate("Loading packages"),
NoMatches_BackgroundText = CoreTools.Translate("No results were found matching the input criteria"),

PageTitle = CoreTools.AutoTranslated("Discover Packages"),
Glyph = "\uF6FA"
})
{
InstantSearchCheckbox.IsEnabled = false;
InstantSearchCheckbox.Visibility = Visibility.Collapsed;

FindButton.Click += Event_SearchPackages;
MegaFindButton.Click += Event_SearchPackages;

QueryBlock.KeyUp += (s, e) => { if (e.Key == VirtualKey.Enter) Event_SearchPackages(s, e); };
MegaQueryBlock.KeyUp += (s, e) => { if (e.Key == VirtualKey.Enter) Event_SearchPackages(s, e); };

QueryOptionsGroup.SelectedIndex = 1;
QueryOptionsGroup.SelectedIndex = 2;
QueryOptionsGroup.SelectedItem = QueryBothRadio;
}

public override BetterMenu GenerateContextMenu()
Expand Down Expand Up @@ -229,40 +262,10 @@ public override async Task LoadPackages()
if(QueryBlock.Text.Trim() != "") await LoadPackages(ReloadReason.External);
}

public override void GenerateUIText()
private void Event_SearchPackages(object sender, RoutedEventArgs e)
{
DISABLE_AUTOMATIC_PACKAGE_LOAD_ON_START = true;
MEGA_QUERY_BOX_ENABLED = true;
PAGE_NAME = "Discover";

PageRole = OperationType.Install;
InstantSearchCheckbox.IsEnabled = false;
InstantSearchCheckbox.Visibility = Visibility.Collapsed;

FindButton.Click += (s, e) => { if(QueryBlock.Text.Trim() != "") _ = LoadPackages(ReloadReason.Manual); };
QueryBlock.KeyUp += (s, e) =>
{
if (QueryBlock.Text.Trim() != "" && e.Key == Windows.System.VirtualKey.Enter)
_ = LoadPackages(ReloadReason.Manual);
};

MegaFindButton.Click += (s, e) => { if (QueryBlock.Text.Trim() != "") _ = LoadPackages(ReloadReason.Manual); };
MegaQueryBlock.KeyUp += (s, e) => { if (QueryBlock.Text.Trim() != "" && e.Key == Windows.System.VirtualKey.Enter) _ = LoadPackages(ReloadReason.Manual); };


NoPackages_BackgroundText = CoreTools.Translate("No results were found matching the input criteria");
NoPackages_SourcesText = CoreTools.Translate("No packages were found");
NoPackages_SubtitleMainText = NoPackages_SourcesText;

NoMatches_BackgroundText = NoPackages_BackgroundText;
NoMatches_SourcesText = NoPackages_SourcesText;

MainTitleText = CoreTools.AutoTranslated("Discover Packages");
MainTitleGlyph = "\uF6FA";

QueryOptionsGroup.SelectedIndex = 1;
QueryOptionsGroup.SelectedIndex = 2;
QueryOptionsGroup.SelectedItem = QueryBothRadio;
if (QueryBlock.Text.Trim() != "")
_ = (Loader as DiscoverablePackagesLoader)?.ReloadPackages();
}

protected override void WhenPackageCountUpdated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,39 @@

namespace UniGetUI.Interface.SoftwarePages
{
public class NewInstalledPackagesPage : AbstractPackagesPage
public class InstalledPackagesPage : AbstractPackagesPage
{
bool HasDoneBackup = false;

BetterMenuItem? MenuAsAdmin;
BetterMenuItem? MenuInteractive;
BetterMenuItem? MenuRemoveData;

public NewInstalledPackagesPage()
: base(PEInterface.InstalledPackagesLoader)
public InstalledPackagesPage()
: base(new PackagesPageData()
{
DisableAutomaticPackageLoadOnStart = false,
MegaQueryBlockEnabled = false,
ShowLastLoadTime = false,
PageName = "Installed",

Loader = PEInterface.InstalledPackagesLoader,
PageRole = OperationType.Uninstall,

NoPackages_BackgroundText = CoreTools.Translate("No results were found matching the input criteria"),
NoPackages_SourcesText = CoreTools.Translate("No packages were found"),
NoPackages_SubtitleText_Base = CoreTools.Translate("No packages were found"),
MainSubtitle_StillLoading = CoreTools.Translate("Loading packages"),
NoMatches_BackgroundText = CoreTools.Translate("No results were found matching the input criteria"),

PageTitle = CoreTools.AutoTranslated("Installed Packages"),
Glyph = "\uE977"
})
{
QuerySimilarResultsRadio.IsEnabled = false;
QueryOptionsGroup.SelectedIndex = 1;
QueryOptionsGroup.SelectedIndex = 2;
QueryOptionsGroup.SelectedItem = QueryBothRadio;
}

public override BetterMenu GenerateContextMenu()
Expand Down Expand Up @@ -251,29 +273,6 @@ public override void GenerateToolBar()
SelectNone.Click += (s, e) => { ClearItemSelection(); };
}

public override void GenerateUIText()
{
PAGE_NAME = "Installed";


PageRole = OperationType.Uninstall;

NoPackages_BackgroundText = CoreTools.Translate("No packages were found");
NoPackages_SourcesText = CoreTools.Translate("No packages were found");
NoPackages_SubtitleMainText = NoPackages_SourcesText;

NoMatches_BackgroundText = CoreTools.Translate("No results were found matching the input criteria");
NoMatches_SourcesText = CoreTools.Translate("No matches were found");

MainTitleText = CoreTools.AutoTranslated("Installed Packages");
MainTitleGlyph = "\uE977";

QuerySimilarResultsRadio.IsEnabled = false;
QueryOptionsGroup.SelectedIndex = 1;
QueryOptionsGroup.SelectedIndex = 2;
QueryOptionsGroup.SelectedItem = QueryBothRadio;
}

protected override void WhenPackageCountUpdated()
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,33 @@

namespace UniGetUI.Interface.SoftwarePages
{
public class NewSoftwareUpdatesPage : AbstractPackagesPage
public class SoftwareUpdatesPage : AbstractPackagesPage
{
private BetterMenuItem? MenuAsAdmin;
private BetterMenuItem? MenuInteractive;
private BetterMenuItem? MenuskipHash;

public NewSoftwareUpdatesPage()
: base(PEInterface.UpgradablePackagesLoader)
public SoftwareUpdatesPage()
: base(new PackagesPageData()
{

}

public override void GenerateUIText()
DisableAutomaticPackageLoadOnStart = false,
MegaQueryBlockEnabled = false,
ShowLastLoadTime = true,
PageName = "Updates",

Loader = PEInterface.UpgradablePackagesLoader,
PageRole = OperationType.Update,

NoPackages_BackgroundText = CoreTools.Translate("Hooray! No updates were found."),
NoPackages_SourcesText = CoreTools.Translate("Everything is up to date"),
NoPackages_SubtitleText_Base = CoreTools.Translate("Everything is up to date"),
MainSubtitle_StillLoading = CoreTools.Translate("Loading packages"),
NoMatches_BackgroundText = CoreTools.Translate("No results were found matching the input criteria"),

PageTitle = CoreTools.AutoTranslated("Software Updates"),
Glyph = "\uE895"
})
{
PAGE_NAME = "Updates";
SHOW_LAST_CHECKED_TIME = true;

PageRole = OperationType.Update;
NoPackages_BackgroundText = CoreTools.Translate("Hooray! No updates were found.");
NoPackages_SourcesText = CoreTools.Translate("Everything is up to date");
NoPackages_SubtitleMainText = NoPackages_SourcesText;

NoMatches_BackgroundText = CoreTools.Translate("No results were found matching the input criteria");
NoMatches_SourcesText = CoreTools.Translate("No packages were found");

MainTitleText = CoreTools.AutoTranslated("Software Updates");
MainTitleGlyph = "\uE895";

QuerySimilarResultsRadio.IsEnabled = false;
QueryOptionsGroup.SelectedIndex = 1;
QueryOptionsGroup.SelectedIndex = 2;
Expand Down Expand Up @@ -165,10 +164,8 @@ protected override void WhenShowingContextMenu(Package package)
MenuAsAdmin.IsEnabled = package.Manager.Capabilities.CanRunAsAdmin;
MenuInteractive.IsEnabled = package.Manager.Capabilities.CanRunInteractively;
MenuskipHash.IsEnabled = package.Manager.Capabilities.CanSkipIntegrityChecks;

}


public override void GenerateToolBar()
{
AppBarButton UpdateSelected = new();
Expand Down

0 comments on commit 2247f64

Please sign in to comment.