Skip to content

Feature: Migrate profile/group to simplechildwindow #3087

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion Source/NETworkManager.Profiles/IProfileManagerMinimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public interface IProfileManagerMinimal
/// </summary>
public void OnProfileManagerDialogOpen()
{

}

/// <summary>
/// Event is fired when a dialog in the <see cref="ProfileManager" /> is closed.
/// </summary>
public void OnProfileManagerDialogClose()
{

}
}
}
2 changes: 1 addition & 1 deletion Source/NETworkManager.Utilities.WPF/BindingProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ protected override Freezable CreateInstanceCore()
{
return new BindingProxy();
}
}
}
21 changes: 15 additions & 6 deletions Source/NETworkManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,25 @@
</StackPanel>
</Button>
<Button Command="{Binding OpenWebsiteCommand}"
ToolTip="{x:Static localization:Strings.ToolTip_SupportThisProjectWithADonation}"
CommandParameter="{x:Static resources:Resources.NETworkManager_DonateUrl}"
Cursor="Hand"
Focusable="False">
ToolTip="{x:Static localization:Strings.ToolTip_SupportThisProjectWithADonation}"
CommandParameter="{x:Static resources:Resources.NETworkManager_DonateUrl}"
Cursor="Hand"
Focusable="False">
<StackPanel Orientation="Horizontal">
<Rectangle Width="20" Height="20"
Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
<Rectangle Width="20" Height="20">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=Heart}" />
</Rectangle.OpacityMask>
<Rectangle.Style>
<Style TargetType="Rectangle">
<Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, Path=IsMouseOver}" Value="True">
<Setter Property="Fill" Value="#b95353" />
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
</StackPanel>
</Button>
Expand Down
1 change: 0 additions & 1 deletion Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ await this.ShowMessageAsync(Strings.SettingsHaveBeenReset,
// Show welcome dialog
if (SettingsManager.Current.WelcomeDialog_Show)
{

var childWindow = new WelcomeChildWindow();

var viewModel = new WelcomeViewModel(instance =>
Expand Down
42 changes: 22 additions & 20 deletions Source/NETworkManager/ProfileDialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
using NETworkManager.Views;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Security;
using System.Threading.Tasks;
using System.Windows;
using MahApps.Metro.SimpleChildWindow;

namespace NETworkManager;

Expand Down Expand Up @@ -466,36 +468,36 @@ private static GroupInfo ParseGroupInfo(GroupViewModel instance)

#region Dialog to add, edit, copy as and delete profile

public static Task ShowAddProfileDialog(object context, IProfileManagerMinimal viewModel,
IDialogCoordinator dialogCoordinator, ProfileInfo profile = null, string group = null,
public static Task ShowAddProfileDialog(Window parentWindow,IProfileManagerMinimal viewModel,
ProfileInfo profile = null, string group = null,
ApplicationName applicationName = ApplicationName.None)
{
CustomDialog customDialog = new()
{
Title = Strings.AddProfile,
Style = (Style)Application.Current.FindResource(DialogResourceKey)
};

ProfileViewModel profileViewModel = new(async instance =>
var childWindow = new ProfileChildWindow(parentWindow);

ProfileViewModel profileViewModel = new(instance =>
{
await dialogCoordinator.HideMetroDialogAsync(context, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();

ProfileManager.AddProfile(ParseProfileInfo(instance));
}, async _ =>
}, _ =>
{
await dialogCoordinator.HideMetroDialogAsync(context, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();
}, ProfileManager.GetGroupNames(), group, ProfileEditMode.Add, profile, applicationName);

customDialog.Content = new ProfileDialog
{
DataContext = profileViewModel
};

viewModel.OnProfileManagerDialogOpen();

return dialogCoordinator.ShowMetroDialogAsync(context, customDialog);
childWindow.Title = Strings.AddProfile;

childWindow.DataContext = profileViewModel;

Settings.ConfigurationManager.Current.IsChildWindowOpen = true;

return parentWindow.ShowChildWindowAsync(childWindow);
}

public static Task ShowEditProfileDialog(IProfileManagerMinimal viewModel,
Expand Down
12 changes: 6 additions & 6 deletions Source/NETworkManager/Resources/Styles/RectangleStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Style.Resources>
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource DefaultToolTip}" />
</Style.Resources>
<Setter Property="Fill" Value="Orange" />
<Setter Property="Fill" Value="#f1b856" />
<Setter Property="OpacityMask">
<Setter.Value>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=AlertOutline}" />
Expand All @@ -54,7 +54,7 @@
<Style.Resources>
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource DefaultToolTip}" />
</Style.Resources>
<Setter Property="Fill" Value="Red" />
<Setter Property="Fill" Value="#b95353" />
<Setter Property="OpacityMask">
<Setter.Value>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=AlertOctagonOutline}" />
Expand Down Expand Up @@ -82,7 +82,7 @@
<Style.Resources>
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource DefaultToolTip}" />
</Style.Resources>
<Setter Property="Fill" Value="Orange" />
<Setter Property="Fill" Value="#f1b856" />
<Setter Property="OpacityMask">
<Setter.Value>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=AlertOutline}" />
Expand All @@ -95,7 +95,7 @@
<Style.Resources>
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource DefaultToolTip}" />
</Style.Resources>
<Setter Property="Fill" Value="Red" />
<Setter Property="Fill" Value="#b95353" />
<Setter Property="OpacityMask">
<Setter.Value>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=Close}" />
Expand Down Expand Up @@ -155,7 +155,7 @@
<Style.Resources>
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource DefaultToolTip}" />
</Style.Resources>
<Setter Property="Fill" Value="Red" />
<Setter Property="Fill" Value="#b95353" />
<Setter Property="OpacityMask">
<Setter.Value>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=LanDisconnect}" />
Expand All @@ -181,7 +181,7 @@
<Style.Resources>
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource DefaultToolTip}" />
</Style.Resources>
<Setter Property="Fill" Value="Red" />
<Setter Property="Fill" Value="#b95353" />
<Setter Property="OpacityMask">
<Setter.Value>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Modern Kind=NetworkPortDisconnect}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,73 @@
<converters:BooleansOrConverter x:Key="BooleansOrConverter" />

<ControlTemplate x:Key="DefaultErrorTemplate">
<StackPanel Orientation="Horizontal">
<Grid>
<Polygon x:Name="toolTipCorner" Grid.ZIndex="2" Margin="0" Points="8,8 8,0 0,0"
Fill="{DynamicResource MahApps.Brushes.Accent}" HorizontalAlignment="Right"
<!--
<Grid>
<Border BorderBrush="#b95353" BorderThickness="1">
-->
<Grid>
<Polygon x:Name="ToolTipCorner" Grid.ZIndex="1" Margin="0" Points="12,12 12,0 0,0"
Fill="#b95353" HorizontalAlignment="Right"
VerticalAlignment="Top" IsHitTestVisible="True" />
<AdornedElementPlaceholder x:Name="adorner" />
<Popup PlacementTarget="{Binding ElementName=adorner}" PopupAnimation="Fade" HorizontalOffset="5">
<Popup.Style>
<Style TargetType="{x:Type Popup}">
<Style.Triggers>
<DataTrigger
Binding="{Binding ElementName=adorner, Path=AdornedElement.IsKeyboardFocusWithin}"

<AdornedElementPlaceholder x:Name="Adorner" />
<Popup PlacementTarget="{Binding ElementName=Adorner}" PopupAnimation="Fade" HorizontalOffset="5">
<Popup.Style>
<Style TargetType="{x:Type Popup}">
<Style.Triggers>
<DataTrigger
Binding="{Binding ElementName=Adorner, Path=AdornedElement.IsKeyboardFocusWithin}"
Value="True">
<Setter Property="PlacementTarget" Value="{Binding ElementName=adorner}" />
<Setter Property="Placement" Value="Right" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=toolTipCorner, Path=IsMouseOver}"
<Setter Property="PlacementTarget" Value="{Binding ElementName=Adorner}" />
<Setter Property="Placement" Value="Right" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=ToolTipCorner, Path=IsMouseOver}"
Value="True">
<Setter Property="PlacementTarget" Value="{Binding ElementName=toolTipCorner}" />
<Setter Property="Placement" Value="Mouse" />
</DataTrigger>
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource BooleansOrConverter}">
<Binding ElementName="adorner" Path="AdornedElement.IsKeyboardFocusWithin" />
<Binding ElementName="toolTipCorner" Path="IsMouseOver" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="IsOpen" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</Popup.Style>
<StackPanel>
<Border MaxWidth="300" Background="{DynamicResource MahApps.Brushes.Window.Background}"
<Setter Property="PlacementTarget" Value="{Binding ElementName=ToolTipCorner}" />
<Setter Property="Placement" Value="Mouse" />
</DataTrigger>
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource BooleansOrConverter}">
<Binding ElementName="Adorner" Path="AdornedElement.IsKeyboardFocusWithin" />
<Binding ElementName="ToolTipCorner" Path="IsMouseOver" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="IsOpen" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</Popup.Style>
<StackPanel>
<Border MaxWidth="300" Background="{DynamicResource MahApps.Brushes.Window.Background}"
BorderBrush="{DynamicResource MahApps.Brushes.Gray8}" BorderThickness="1" Padding="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Width="20" Height="20"
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Width="20" Height="20"
Fill="{DynamicResource MahApps.Brushes.Gray3}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform"
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform"
Visual="{iconPacks:Material Kind=InformationVariant}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Grid.Column="1" Text="{Binding Path=/ErrorContent}"
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Grid.Column="1" Text="{Binding Path=/ErrorContent}"
Foreground="{DynamicResource MahApps.Brushes.Text}" FontSize="14"
TextWrapping="Wrap" VerticalAlignment="Center" Margin="10,0,0,0" />
</Grid>
</Border>
</StackPanel>
</Popup>
</Grid>
</StackPanel>
</Grid>
</Border>
</StackPanel>
</Popup>
</Grid>
<!--
</Border>
</Grid>
-->
</ControlTemplate>

<ControlTemplate x:Key="ErrorTemplateOffset">

</ControlTemplate>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ private void ConnectProfileExternalAction()
private void AddProfileAction()
{
ProfileDialogManager
.ShowAddProfileDialog(this, this, _dialogCoordinator, null, null, ApplicationName.AWSSessionManager)
.ShowAddProfileDialog(Application.Current.MainWindow, this, null, null, ApplicationName.AWSSessionManager)
.ConfigureAwait(false);
}

Expand Down Expand Up @@ -999,8 +999,8 @@ private void SetProfilesView(ProfileInfo profile = null)
Profiles.Filter = o =>
{
if (string.IsNullOrEmpty(Search))
return true ;
return true;

if (o is not ProfileInfo info)
return false;

Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private void LookupProfileAction()

private void AddProfileAction()
{
ProfileDialogManager.ShowAddProfileDialog(this, this, _dialogCoordinator, null, null, ApplicationName.DNSLookup)
ProfileDialogManager.ShowAddProfileDialog(Application.Current.MainWindow, this, null, null, ApplicationName.DNSLookup)
.ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private void QueryProfileAction()
private void AddProfileAction()
{
ProfileDialogManager
.ShowAddProfileDialog(this, this, _dialogCoordinator, null, null, ApplicationName.IPGeolocation)
.ShowAddProfileDialog(Application.Current.MainWindow, this, null, null, ApplicationName.IPGeolocation)
.ConfigureAwait(false);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private void ScanProfileAction()

private void AddProfileAction()
{
ProfileDialogManager.ShowAddProfileDialog(this, this, _dialogCoordinator, null, null, ApplicationName.IPScanner)
ProfileDialogManager.ShowAddProfileDialog(Application.Current.MainWindow, this, null, null, ApplicationName.IPScanner)
.ConfigureAwait(false);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/ViewModels/IPScannerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private async void AddProfileSelectedHostAction()

var window = Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.IsActive);

await ProfileDialogManager.ShowAddProfileDialog(window, this, _dialogCoordinator, profileInfo, null,
await ProfileDialogManager.ShowAddProfileDialog(window, this, profileInfo, null,
ApplicationName.IPScanner);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ private void ApplyProfileProfileAction()
private void AddProfileAction()
{
ProfileDialogManager
.ShowAddProfileDialog(this, this, _dialogCoordinator, null, null, ApplicationName.NetworkInterface)
.ShowAddProfileDialog(Application.Current.MainWindow, this, null, null, ApplicationName.NetworkInterface)
.ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private void ExportAction()
private void AddProfileAction()
{
ProfileDialogManager
.ShowAddProfileDialog(this, this, _dialogCoordinator, null, null, ApplicationName.PingMonitor)
.ShowAddProfileDialog(Application.Current.MainWindow, this, null, null, ApplicationName.PingMonitor)
.ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private void ScanProfileAction()
private void AddProfileAction()
{
ProfileDialogManager
.ShowAddProfileDialog(this, this, _dialogCoordinator, null, null, ApplicationName.PortScanner)
.ShowAddProfileDialog(Application.Current.MainWindow, this, null, null, ApplicationName.PortScanner)
.ConfigureAwait(false);
}

Expand Down
Loading