Skip to content

Commit 79feef0

Browse files
committed
Remote Desktop is now disconnected when closing the tab
1 parent 5e3c5cb commit 79feef0

6 files changed

Lines changed: 52 additions & 23 deletions

File tree

Source/NETworkManager/Controls/DragablzRemoteDesktopTabHostWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Controls:WindowButtonCommands Template="{DynamicResource MahApps.Metro.Templates.WindowButtonCommands.Win10}" />
1212
</Controls:MetroWindow.WindowButtonCommands>
1313
<Grid>
14-
<dragablz:TabablzControl Name="TabsContainer">
14+
<dragablz:TabablzControl Name="TabsContainer" ClosingItemCallback="{Binding CloseItemCommand}">
1515
<dragablz:TabablzControl.InterTabController>
1616
<dragablz:InterTabController Partition="3D21565B-3E97-42F1-B0B9-CCA7DA63EFB2" />
1717
</dragablz:TabablzControl.InterTabController>

Source/NETworkManager/Controls/DragablzRemoteDesktopTabHostWindow.xaml.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MahApps.Metro.Controls;
1+
using Dragablz;
2+
using MahApps.Metro.Controls;
23

34
namespace NETworkManager.Controls
45
{
@@ -10,6 +11,19 @@ public partial class DragablzRemoteDesktopTabHostWindow : MetroWindow
1011
public DragablzRemoteDesktopTabHostWindow()
1112
{
1213
InitializeComponent();
14+
DataContext = this;
1315
}
16+
17+
#region ICommand & Actions
18+
public ItemActionCallback CloseItemCommand
19+
{
20+
get { return CloseItemAction; }
21+
}
22+
23+
private void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)
24+
{
25+
((args.DragablzItem.Content as DragablzRemoteDesktopTabItem).View as RemoteDesktopControl).CloseTab();
26+
}
27+
#endregion
1428
}
1529
}

Source/NETworkManager/Controls/PuTTYControl.xaml.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,24 @@ private void Connect()
100100
ResizeEmbeddedPuTTY();
101101
}
102102

103-
public void Disconnect()
104-
{
105-
if (PuTTYProcess != null && !PuTTYProcess.HasExited)
106-
PuTTYProcess.Kill();
107-
}
108-
109103
private void ResizeEmbeddedPuTTY()
110104
{
111105
try
112106
{
113107
NativeMethods.SetWindowPos(PuTTYProcess.MainWindowHandle, IntPtr.Zero, 0, 0, puTTYHost.ClientSize.Width, puTTYHost.ClientSize.Height, NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOACTIVATE);
114108
}
115-
catch(Exception ex)
109+
catch (Exception ex)
116110
{
117111
MessageBox.Show(ex.Message);
118112
}
119113
}
120114

115+
public void Disconnect()
116+
{
117+
if (PuTTYProcess != null && !PuTTYProcess.HasExited)
118+
PuTTYProcess.Kill();
119+
}
120+
121121
public void CloseTab()
122122
{
123123
Disconnect();

Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
using System;
99
using System.Windows.Threading;
1010
using NETworkManager.Helpers;
11+
using System.Diagnostics;
1112

1213
namespace NETworkManager.Controls
1314
{
14-
1515
public partial class RemoteDesktopControl : UserControl, INotifyPropertyChanged
1616
{
1717
#region PropertyChangedEventHandler
@@ -207,17 +207,6 @@ private void Reconnect()
207207
rdpClient.Connect();
208208
}
209209

210-
private void Disconnect()
211-
{
212-
rdpClient.Disconnect();
213-
}
214-
215-
public void OnClose()
216-
{
217-
if (Connected)
218-
Disconnect();
219-
}
220-
221210
private void ReconnectAdjustScreen()
222211
{
223212
rdpClient.Reconnect((uint)rdpGrid.ActualWidth, (uint)rdpGrid.ActualHeight);
@@ -230,6 +219,22 @@ private void FixWindowsFormsHostSize()
230219
RDPClientHeight = rdpClient.DesktopHeight;
231220
}
232221

222+
private void Disconnect()
223+
{
224+
if (Connected)
225+
rdpClient.Disconnect();
226+
}
227+
228+
public void CloseTab()
229+
{
230+
Disconnect();
231+
}
232+
233+
public void OnClose()
234+
{
235+
Disconnect();
236+
}
237+
233238
// Source: https://msdn.microsoft.com/en-us/library/aa382170(v=vs.85).aspx
234239
private string GetDisconnectReasonFromResource(string reason)
235240
{

Source/NETworkManager/ViewModels/Applications/RemoteDesktopViewModel.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,19 @@ private void LoadSettings()
168168
{
169169
ExpandSessionView = SettingsManager.Current.RemoteDesktop_ExpandSessionView;
170170
}
171-
#endregion
171+
#endregion
172172

173173
#region ICommand & Actions
174+
public ItemActionCallback CloseItemCommand
175+
{
176+
get { return CloseItemAction; }
177+
}
178+
179+
private void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)
180+
{
181+
((args.DragablzItem.Content as DragablzRemoteDesktopTabItem).View as RemoteDesktopControl).CloseTab();
182+
}
183+
174184
public ICommand ConnectNewSessionCommand
175185
{
176186
get { return new RelayCommand(p => ConnectNewSessionAction(), ConnectNewSession_CanExecute); }

Source/NETworkManager/Views/Applications/RemoteDesktopView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<ColumnDefinition Width="*" />
2626
<ColumnDefinition Width="Auto" />
2727
</Grid.ColumnDefinitions>
28-
<dragablz:TabablzControl Grid.Column="0" Grid.Row="0" Margin="-0,-2,0,0" ItemsSource="{Binding TabItems}" SelectedIndex="{Binding SelectedTabIndex}">
28+
<dragablz:TabablzControl Grid.Column="0" Grid.Row="0" Margin="-0,-2,0,0" ClosingItemCallback="{Binding CloseItemCommand}" ItemsSource="{Binding TabItems}" SelectedIndex="{Binding SelectedTabIndex}">
2929
<dragablz:TabablzControl.InterTabController>
3030
<dragablz:InterTabController InterTabClient="{Binding InterTabClient}" Partition="3D21565B-3E97-42F1-B0B9-CCA7DA63EFB2"/>
3131
</dragablz:TabablzControl.InterTabController>

0 commit comments

Comments
 (0)