Skip to content

Commit

Permalink
Close #65
Browse files Browse the repository at this point in the history
  • Loading branch information
BornToBeRoot committed Nov 27, 2017
1 parent 647bbca commit 4d8d879
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 40 deletions.
23 changes: 2 additions & 21 deletions Source/NETworkManager/Controls/DragablzRemoteDesktopTabItem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using NETworkManager.ViewModels;

namespace NETworkManager.Controls
{
public class DragablzRemoteDesktopTabItem : IDisposable
public class DragablzRemoteDesktopTabItem : ViewModelBase
{
public string Header { get; set; }
public RemoteDesktopControl Control { get; set; }
Expand All @@ -12,24 +12,5 @@ public DragablzRemoteDesktopTabItem(string header, RemoteDesktopControl control)
Header = header;
Control = control;
}

private bool _disposed;

protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;

if (disposing)
Control.OnClose();

_disposed = true;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}
11 changes: 9 additions & 2 deletions Source/NETworkManager/Controls/DragablzTabHostWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@
<Controls:MetroWindow.WindowButtonCommands>
<Controls:WindowButtonCommands Template="{DynamicResource MahApps.Metro.Templates.WindowButtonCommands.Win10}" />
</Controls:MetroWindow.WindowButtonCommands>
<Grid Margin="10">
<Grid>
<dragablz:TabablzControl Name="TabsContainer">
<dragablz:TabablzControl.InterTabController>
<dragablz:InterTabController></dragablz:InterTabController>
</dragablz:TabablzControl.InterTabController>
<dragablz:TabablzControl.Style>
<Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource DefaultTabablzControl}">
<Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource DefaultTabablzControl}">
<!-- If not null, the header suffix will be removed in the main window -->
<Setter Property="HeaderSuffixContent" Value="{x:Null}" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<ContentPresenter Content="{Binding Control}" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</dragablz:TabablzControl.Style>
</dragablz:TabablzControl>
Expand Down
22 changes: 18 additions & 4 deletions Source/NETworkManager/Controls/RemoteDesktopControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
using System.Windows.Input;
using System;
using System.Windows.Threading;
using System.Diagnostics;

namespace NETworkManager.Controls
{

public partial class RemoteDesktopControl : UserControl, INotifyPropertyChanged
{
#region PropertyChangedEventHandler
Expand All @@ -23,6 +24,8 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
#endregion

#region Variables
private bool _initialized = false;

private const string RemoteDesktopDisconnectReasonIdentifier = "String_RemoteDesktopDisconnectReason_";

private RemoteDesktopSessionInfo _rdpSessionInfo;
Expand Down Expand Up @@ -112,13 +115,24 @@ public RemoteDesktopControl(RemoteDesktopSessionInfo info)

reconnectAdjustScreenTimer.Tick += ReconnectAdjustScreenTimer_Tick;
reconnectAdjustScreenTimer.Interval = new TimeSpan(0, 0, 0, 0, 500);

Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
}

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
if (!Connected)
// Connect after the control is drawn and only on the first init
if (!_initialized)
{
Connect();
}
_initialized = true;
}
}

private void Dispatcher_ShutdownStarted(object sender, EventArgs e)
{
OnClose();
}
#endregion

#region ICommands & Actions
Expand Down Expand Up @@ -348,7 +362,7 @@ private void ReconnectAdjustScreenTimer_Tick(object sender, EventArgs e)

// Reconnect with new resulution
ReconnectAdjustScreen();
}
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ public RemoteDesktopViewModel(IDialogCoordinator instance)
InterTabClient = new DragablzMainInterTabClient();
TabItems = new ObservableCollection<DragablzRemoteDesktopTabItem>();

TabItems.CollectionChanged += TabItems_CollectionChanged;

// Load sessions
if (RemoteDesktopSessionManager.Sessions == null)
RemoteDesktopSessionManager.Load();
Expand Down Expand Up @@ -397,16 +395,5 @@ private async void DeleteSessionAction()
await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
}
#endregion

#region Events
private void TabItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Remove)
{
DragablzRemoteDesktopTabItem item = (DragablzRemoteDesktopTabItem)e.OldItems[0];
item.Dispose();
}
}
#endregion
}
}

0 comments on commit 4d8d879

Please sign in to comment.