Skip to content

Commit

Permalink
Refactor UI code structuring
Browse files Browse the repository at this point in the history
109 changed files :D
  • Loading branch information
pizzaboxer committed Jul 2, 2023
1 parent 9ea7900 commit 94fe522
Show file tree
Hide file tree
Showing 57 changed files with 165 additions and 182 deletions.
6 changes: 3 additions & 3 deletions Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
using Bloxstrap.Models;
using Bloxstrap.Models.Attributes;
using Bloxstrap.UI;
using Bloxstrap.UI.BootstrapperDialogs;
using Bloxstrap.UI.MessageBox;
using Bloxstrap.Utility;

namespace Bloxstrap
Expand Down Expand Up @@ -105,6 +103,7 @@ void GlobalExceptionHandler(object sender, DispatcherUnhandledExceptionEventArgs

void FinalizeExceptionHandling(Exception exception)
{
#pragma warning disable 162
#if DEBUG
throw exception;
#endif
Expand All @@ -113,6 +112,7 @@ void FinalizeExceptionHandling(Exception exception)
Controls.ShowExceptionDialog(exception);

Terminate(Bootstrapper.ERROR_INSTALL_FAILURE);
#pragma warning restore 162
}

protected override void OnStartup(StartupEventArgs e)
Expand Down Expand Up @@ -248,7 +248,7 @@ protected override void OnStartup(StartupEventArgs e)
else
{
if (Process.GetProcessesByName(ProjectName).Length > 1 && !IsQuiet)
FluentMessageBox.Show(
Controls.ShowMessageBox(
$"{ProjectName} is currently running, likely as a background Roblox process. Please note that not all your changes will immediately apply until you close all currently open Roblox instances.",
MessageBoxImage.Information
);
Expand Down
1 change: 0 additions & 1 deletion Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using Bloxstrap.Models;
using Bloxstrap.Tools;
using Bloxstrap.UI;
using Bloxstrap.UI.BootstrapperDialogs;

namespace Bloxstrap
{
Expand Down
18 changes: 2 additions & 16 deletions Bloxstrap/Extensions/BootstrapperStyleEx.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
using Bloxstrap.Enums;
using Bloxstrap.UI.BootstrapperDialogs;
using Bloxstrap.UI.BootstrapperDialogs.WinForms;
using Bloxstrap.UI.BootstrapperDialogs.WPF.Views;
using Bloxstrap.UI;

namespace Bloxstrap.Extensions
{
static class BootstrapperStyleEx
{
public static IBootstrapperDialog GetNew(this BootstrapperStyle bootstrapperStyle)
{
return bootstrapperStyle switch
{
BootstrapperStyle.VistaDialog => new VistaDialog(),
BootstrapperStyle.LegacyDialog2009 => new LegacyDialog2009(),
BootstrapperStyle.LegacyDialog2011 => new LegacyDialog2011(),
BootstrapperStyle.ProgressDialog => new ProgressDialog(),
BootstrapperStyle.FluentDialog => new FluentDialog(),
BootstrapperStyle.ByfronDialog => new ByfronDialog(),
_ => new FluentDialog()
};
}
public static IBootstrapperDialog GetNew(this BootstrapperStyle bootstrapperStyle) => Controls.GetBootstrapperDialog(bootstrapperStyle);
}
}
31 changes: 27 additions & 4 deletions Bloxstrap/UI/Controls.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Drawing;
using System.Windows;

using Bloxstrap.Enums;
using Bloxstrap.UI.Menu.Views;
using Bloxstrap.Extensions;
using Bloxstrap.UI.Elements.Bootstrapper;
using Bloxstrap.UI.Menu;
using Bloxstrap.UI.MessageBox;

namespace Bloxstrap.UI
Expand All @@ -14,14 +15,22 @@ static class Controls

public static MessageBoxResult ShowMessageBox(string message, MessageBoxImage icon = MessageBoxImage.None, MessageBoxButton buttons = MessageBoxButton.OK, MessageBoxResult defaultResult = MessageBoxResult.None)
{
if (App.IsQuiet)
return defaultResult;

switch (App.Settings.Prop.BootstrapperStyle)
{
case BootstrapperStyle.FluentDialog:
case BootstrapperStyle.ByfronDialog:
return FluentMessageBox.Show(message, icon, buttons, defaultResult);
return Application.Current.Dispatcher.Invoke(new Func<MessageBoxResult>(() =>
{
var messagebox = new FluentMessageBox(message, icon, buttons);
messagebox.ShowDialog();
return messagebox.Result;
}));

default:
return NativeMessageBox.Show(message, icon, buttons, defaultResult);
return System.Windows.MessageBox.Show(message, App.ProjectName, buttons, icon);
}
}

Expand All @@ -32,5 +41,19 @@ public static void ShowExceptionDialog(Exception exception)
new ExceptionDialog(exception).ShowDialog();
});
}

public static IBootstrapperDialog GetBootstrapperDialog(BootstrapperStyle style)
{
return style switch
{
BootstrapperStyle.VistaDialog => new VistaDialog(),
BootstrapperStyle.LegacyDialog2009 => new LegacyDialog2009(),
BootstrapperStyle.LegacyDialog2011 => new LegacyDialog2011(),
BootstrapperStyle.ProgressDialog => new ProgressDialog(),
BootstrapperStyle.FluentDialog => new FluentDialog(),
BootstrapperStyle.ByfronDialog => new ByfronDialog(),
_ => new FluentDialog()
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Windows;

namespace Bloxstrap.UI.BootstrapperDialogs
namespace Bloxstrap.UI.Elements.Bootstrapper.Base
{
static class BaseFunctions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
using System.Windows.Forms;

using Bloxstrap.Extensions;
using Bloxstrap.Utility;
using Bloxstrap.UI.Utility;

namespace Bloxstrap.UI.BootstrapperDialogs.WinForms
namespace Bloxstrap.UI.Elements.Bootstrapper.Base
{
public class DialogBase : Form, IBootstrapperDialog
public class WinFormsDialogBase : Form, IBootstrapperDialog
{
public Bootstrapper? Bootstrapper { get; set; }
public Bloxstrap.Bootstrapper? Bootstrapper { get; set; }

#region UI Elements
protected virtual string _message { get; set; } = "Please wait...";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="Bloxstrap.UI.BootstrapperDialogs.WPF.Views.ByfronDialog"
<Window x:Class="Bloxstrap.UI.Elements.Bootstrapper.ByfronDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

using Bloxstrap.Enums;
using Bloxstrap.Extensions;
using Bloxstrap.UI.BootstrapperDialogs.WPF.ViewModels;
using Bloxstrap.UI.Elements.Bootstrapper.Base;
using Bloxstrap.UI.ViewModels.Bootstrapper;

namespace Bloxstrap.UI.BootstrapperDialogs.WPF.Views
namespace Bloxstrap.UI.Elements.Bootstrapper
{
/// <summary>
/// Interaction logic for ByfronDialog.xaml
Expand All @@ -17,7 +18,7 @@ public partial class ByfronDialog : IBootstrapperDialog
{
private readonly ByfronDialogViewModel _viewModel;

public Bootstrapper? Bootstrapper { get; set; }
public Bloxstrap.Bootstrapper? Bootstrapper { get; set; }

#region UI Elements
public string Message
Expand Down Expand Up @@ -52,10 +53,12 @@ public int ProgressValue

public bool CancelEnabled
{
get => _viewModel.CancelButtonVisibility == Visibility.Visible;
get => _viewModel.CancelEnabled;
set
{
_viewModel.CancelButtonVisibility = (value ? Visibility.Visible : Visibility.Collapsed);
_viewModel.CancelEnabled = value;

_viewModel.OnPropertyChanged(nameof(_viewModel.CancelEnabled));
_viewModel.OnPropertyChanged(nameof(_viewModel.CancelButtonVisibility));

_viewModel.OnPropertyChanged(nameof(_viewModel.VersionTextVisibility));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ui:UiWindow x:Class="Bloxstrap.UI.BootstrapperDialogs.WPF.Views.FluentDialog"
<ui:UiWindow x:Class="Bloxstrap.UI.Elements.Bootstrapper.FluentDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down Expand Up @@ -38,7 +38,7 @@
</Grid>

<Border Grid.Row="2" Padding="15" Background="{ui:ThemeResource SolidBackgroundFillColorSecondaryBrush}">
<Button Margin="0" Content="{Binding CancelButtonText, Mode=OneWay}" Width="120" HorizontalAlignment="Right" IsEnabled="{Binding CancelButtonEnabled, Mode=OneWay}" Command="{Binding CancelInstallCommand}" />
<Button Margin="0" Content="Cancel" Width="120" HorizontalAlignment="Right" IsEnabled="{Binding CancelButtonEnabled, Mode=OneWay}" Command="{Binding CancelInstallCommand}" />
</Border>
</Grid>
</ui:UiWindow>
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using System.Windows;
using System.Windows.Forms;

using Bloxstrap.Extensions;
using Bloxstrap.UI.BootstrapperDialogs.WPF.ViewModels;

using Wpf.Ui.Appearance;
using Wpf.Ui.Mvvm.Contracts;
using Wpf.Ui.Mvvm.Services;

namespace Bloxstrap.UI.BootstrapperDialogs.WPF.Views
using Bloxstrap.Extensions;
using Bloxstrap.UI.ViewModels.Bootstrapper;
using Bloxstrap.UI.Elements.Bootstrapper.Base;

namespace Bloxstrap.UI.Elements.Bootstrapper
{
/// <summary>
/// Interaction logic for FluentDialog.xaml
Expand All @@ -18,9 +19,9 @@ public partial class FluentDialog : IBootstrapperDialog
{
private readonly IThemeService _themeService = new ThemeService();

private readonly FluentDialogViewModel _viewModel;
private readonly BootstrapperDialogViewModel _viewModel;

public Bootstrapper? Bootstrapper { get; set; }
public Bloxstrap.Bootstrapper? Bootstrapper { get; set; }

#region UI Elements
public string Message
Expand Down Expand Up @@ -55,21 +56,20 @@ public int ProgressValue

public bool CancelEnabled
{
get => _viewModel.CancelButtonVisibility == Visibility.Visible;
get => _viewModel.CancelEnabled;
set
{
_viewModel.CancelButtonVisibility = (value ? Visibility.Visible : Visibility.Collapsed);
_viewModel.CancelButtonEnabled = value;
_viewModel.CancelEnabled = value;

_viewModel.OnPropertyChanged(nameof(_viewModel.CancelButtonVisibility));
_viewModel.OnPropertyChanged(nameof(_viewModel.CancelButtonEnabled));
_viewModel.OnPropertyChanged(nameof(_viewModel.CancelEnabled));
}
}
#endregion

public FluentDialog()
{
_viewModel = new FluentDialogViewModel(this);
_viewModel = new BootstrapperDialogViewModel(this);
DataContext = _viewModel;
Title = App.Settings.Prop.BootstrapperTitle;
Icon = App.Settings.Prop.BootstrapperIcon.GetIcon().GetImageSource();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Windows.Forms;

namespace Bloxstrap.UI.BootstrapperDialogs.WinForms
using Bloxstrap.UI.Elements.Bootstrapper.Base;

namespace Bloxstrap.UI.Elements.Bootstrapper
{
// windows: https://youtu.be/VpduiruysuM?t=18
// mac: https://youtu.be/ncHhbcVDRgQ?t=63

public partial class LegacyDialog2009 : DialogBase
public partial class LegacyDialog2009 : WinFormsDialogBase
{
protected override string _message
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using System.Windows.Forms;

using Bloxstrap.Extensions;
using Bloxstrap.UI.Elements.Bootstrapper.Base;

namespace Bloxstrap.UI.BootstrapperDialogs.WinForms
namespace Bloxstrap.UI.Elements.Bootstrapper
{
// https://youtu.be/3K9oCEMHj2s?t=35

public partial class LegacyDialog2011 : DialogBase
public partial class LegacyDialog2011 : WinFormsDialogBase
{
protected override string _message
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

using Bloxstrap.Enums;
using Bloxstrap.Extensions;
using Bloxstrap.UI.Elements.Bootstrapper.Base;

namespace Bloxstrap.UI.BootstrapperDialogs.WinForms
namespace Bloxstrap.UI.Elements.Bootstrapper
{
// basically just the modern dialog

public partial class ProgressDialog : DialogBase
public partial class ProgressDialog : WinFormsDialogBase
{
protected override string _message
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
using System.Windows.Forms;

using Bloxstrap.Extensions;
using Bloxstrap.UI.Elements.Bootstrapper.Base;

namespace Bloxstrap.UI.BootstrapperDialogs.WinForms
namespace Bloxstrap.UI.Elements.Bootstrapper
{
// https://youtu.be/h0_AL95Sc3o?t=48

// a bit hacky, but this is actually a hidden form
// since taskdialog is part of winforms, it can't really be properly used without a form
// for example, cross-threaded calls to ui controls can't really be done outside of a form

public partial class VistaDialog : DialogBase
public partial class VistaDialog : WinFormsDialogBase
{
private TaskDialogPage _dialogPage;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 94fe522

Please sign in to comment.