Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix: Try to update dialog coordinator #2517

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 2 deletions Source/NETworkManager/Controls/DragablzTabHostWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
xmlns:application="clr-namespace:NETworkManager.Models;assembly=NETworkManager.Models"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:wpfHelpers="clr-namespace:NETworkManager.Utilities.WPF;assembly=NETworkManager.Utilities.WPF"
mc:Ignorable="d"
mah:DialogParticipation.Register="{Binding}"
Style="{DynamicResource DefaultWindow}" MinWidth="800" Width="1024" Height="768" MinHeight="600" TitleAlignment="Left" Activated="MetroWindow_Activated"
d:DataContext="{d:DesignInstance controls:DragablzTabHostWindow}">
mc:Ignorable="d" d:DataContext="{d:DesignInstance controls:DragablzTabHostWindow}">
<mah:MetroWindow.WindowButtonCommands>
<mah:WindowButtonCommands Template="{DynamicResource MahApps.Templates.WindowButtonCommands.Win10}" />
</mah:MetroWindow.WindowButtonCommands>
Expand Down
22 changes: 21 additions & 1 deletion Source/NETworkManager/Controls/DragablzTabHostWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using NETworkManager.Settings;
using NETworkManager.Views;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using NETworkManager.Utilities;
Expand All @@ -28,6 +30,9 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null)

#region Variables
public IInterTabClient InterTabClient { get; }

private readonly IDialogCoordinator _dialogCoordinator;

private ApplicationName _applicationName;

public ApplicationName ApplicationName
Expand Down Expand Up @@ -64,14 +69,28 @@ public DragablzTabHostWindow(ApplicationName applicationName)
InitializeComponent();
DataContext = this;

_dialogCoordinator = DialogCoordinator.Instance;

ApplicationName = applicationName;

InterTabClient = new DragablzInterTabClient(applicationName);

InterTabController.Partition = applicationName.ToString();

AddHandler(DragablzItem.DragCompleted, new DragablzDragCompletedEventHandler(ItemDragCompleted), true);

Title = $"NETworkManager {AssemblyManager.Current.Version} - {ResourceTranslator.Translate(ResourceIdentifier.ApplicationName, applicationName)}";
}

private void ItemDragCompleted(object sender, DragablzDragCompletedEventArgs e)
{
if (_applicationName == ApplicationName.DNSLookup)
{
Debug.WriteLine("Dragged: " + ((DragablzTabItem)e.DragablzItem.Content).Id);
((DNSLookupView)((DragablzTabItem)e.DragablzItem.Content).View).OnDragCompleted();
}
}

#endregion

#region ICommand & Actions
Expand Down Expand Up @@ -209,7 +228,8 @@ private async void RemoteDesktop_SendCtrlAltDelAction(object view)
{
ConfigurationManager.OnDialogOpen();

await this.ShowMessageAsync(Localization.Resources.Strings.Error, string.Format("{0}\n\nMessage:\n{1}", NETworkManager.Localization.Resources.Strings.CouldNotSendKeystroke, ex.Message, MessageDialogStyle.Affirmative, AppearanceManager.MetroDialog));
await this.ShowMessageAsync(Localization.Resources.Strings.Error,
$"{Localization.Resources.Strings.CouldNotSendKeystroke}\n\nMessage:\n{ex.Message}");

ConfigurationManager.OnDialogClose();
}
Expand Down
3 changes: 2 additions & 1 deletion Source/NETworkManager/Controls/DragablzTabItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NETworkManager.ViewModels;
using System;
using NETworkManager.ViewModels;
using System.Windows.Controls;

namespace NETworkManager.Controls;
Expand Down
6 changes: 4 additions & 2 deletions Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DNSLookupHostViewModel : ViewModelBase, IProfileManager
public IInterTabClient InterTabClient { get; }
public ObservableCollection<DragablzTabItem> TabItems { get; }

private readonly bool _isLoading = true;
private readonly bool _isLoading;
private bool _isViewActive = true;

private int _tabId;
Expand Down Expand Up @@ -159,13 +159,15 @@ public GridLength ProfileWidth
#region Constructor, load settings
public DNSLookupHostViewModel(IDialogCoordinator instance)
{
_isLoading = true;

_dialogCoordinator = instance;

InterTabClient = new DragablzInterTabClient(ApplicationName.DNSLookup);

TabItems = new ObservableCollection<DragablzTabItem>
{
new DragablzTabItem(Localization.Resources.Strings.NewTab, new DNSLookupView (_tabId), _tabId)
new(Localization.Resources.Strings.NewTab, new DNSLookupView (_tabId), _tabId)
};

// Profiles
Expand Down
7 changes: 6 additions & 1 deletion Source/NETworkManager/ViewModels/DNSLookupViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class DNSLookupViewModel : ViewModelBase
{
#region Variables

private readonly IDialogCoordinator _dialogCoordinator;
private IDialogCoordinator _dialogCoordinator;

private readonly int _tabId;
private bool _firstLoad = true;
Expand Down Expand Up @@ -467,4 +467,9 @@ private void SettingsManager_PropertyChanged(object sender, PropertyChangedEvent
}
}
#endregion

public void UpdateDialogCoordinator(IDialogCoordinator instance)
{
_dialogCoordinator = instance;
}
}
13 changes: 8 additions & 5 deletions Source/NETworkManager/Views/DNSLookupHostView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters"
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
dialogs:DialogParticipation.Register="{Binding}"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
mah:DialogParticipation.Register="{Binding}"
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:DNSLookupHostViewModel}">
<UserControl.Resources>
<converters:BooleanReverseToVisibilityCollapsedConverter x:Key="BooleanReverseToVisibilityCollapsedConverter" />
Expand All @@ -27,9 +26,13 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition MinWidth="{x:Static settings:GlobalStaticConfiguration.Profile_WidthCollapsed}" Width="{Binding ProfileWidth, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" MaxWidth="{x:Static settings:GlobalStaticConfiguration.Profile_MaxWidthExpanded}" />
</Grid.ColumnDefinitions>
<dragablz:TabablzControl Grid.Column="0" ClosingItemCallback="{Binding CloseItemCommand}" ItemsSource="{Binding TabItems}" SelectedIndex="{Binding SelectedTabIndex}">
<dragablz:TabablzControl Grid.Column="0" Grid.Row="0"
ClosingItemCallback="{Binding CloseItemCommand}" ItemsSource="{Binding TabItems}"
SelectedIndex="{Binding SelectedTabIndex}">
<dragablz:TabablzControl.InterTabController>
<dragablz:InterTabController InterTabClient="{Binding InterTabClient}" MoveWindowWithSolitaryTabs="False" x:Name="InterTabController" />
<dragablz:InterTabController x:Name="InterTabController"
InterTabClient="{Binding InterTabClient}"
MoveWindowWithSolitaryTabs="False" />
</dragablz:TabablzControl.InterTabController>
<dragablz:TabablzControl.HeaderSuffixContent>
<Grid HorizontalAlignment="Right" Width="32" Height="32">
Expand Down
5 changes: 5 additions & 0 deletions Source/NETworkManager/Views/DNSLookupView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ private void ColumnHeader_Click(object sender, RoutedEventArgs e)
if (sender is DataGridColumnHeader columnHeader)
_viewModel.SortResultByPropertyName(columnHeader.Column.SortMemberPath);
}

public void OnDragCompleted()
{
_viewModel.UpdateDialogCoordinator(DialogCoordinator.Instance);
}
}