Skip to content

Commit

Permalink
Add reset default command
Browse files Browse the repository at this point in the history
  • Loading branch information
junian committed May 21, 2018
1 parent 6b2eb55 commit b2bafb3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/Termission.Core/ViewModels/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Juniansoft.Termission.Core.Helpers;
using Juniansoft.MvvmReady;
using Juniansoft.Termission.Core.Helpers;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Juniansoft.Termission.Core.ViewModels
{
Expand Down Expand Up @@ -194,7 +196,39 @@ public bool IsRtsEnable
RaisePropertyChanged();
}
}
}
}

public ICommand ResetTcpListenerCommand => new Command(() =>
{
TcpListenerIp = Settings.DefaultTcpListenerIpAddress;
TcpListenerPort = Settings.DefaultTcpListenerPort;
});

public ICommand ResetTcpClientCommand => new Command(() =>
{
TcpClientIp = Settings.DefaultTcpClientIpAddress;
TcpClientPort = Settings.DefaultTcpClientPort;
});

public ICommand ResetSerialComCommand => new Command(() =>
{
SelectedBaudRate = Settings.DefaultBaudRate;
SelectedParity = Settings.DefaultParity;
SelectedDataBits = Settings.DefaultDataBits;
SelectedStopBits = Settings.DefaultStopBits;
SelectedHandshake = Settings.DefaultHandshake;
IsDtrEnable = Settings.DefaultDtrEnable;
IsRtsEnable = Settings.DefaultRtsEnable;
});

public ICommand ResetAllCommand => new Command(() =>
{
ResetTcpListenerCommand.Execute(null);
ResetTcpClientCommand.Execute(null);
ResetSerialComCommand.Execute(null);
});

public PreferencesViewModel()
{
Expand Down
12 changes: 12 additions & 0 deletions src/Termission.EtoForms/Views/PreferencesView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class PreferencesView : Panel
private CheckBox _chkDtr;
private CheckBox _chkRts;

private Button _btnResetTcpListener;
private Button _btnResetTcpClient;
private Button _btnResetSerial;

public PreferencesView()
{
Padding = 10;
Expand Down Expand Up @@ -79,6 +83,10 @@ private void ConfigureBinding()
_chkRts.CheckedBinding.BindDataContext(
Binding.Property((PreferencesViewModel m) => m.IsRtsEnable)
.Convert(x => (bool?)x, x => x == true));

_btnResetTcpListener.BindDataContext(c => c.Command, (PreferencesViewModel vm) => vm.ResetTcpListenerCommand);
_btnResetTcpClient.BindDataContext(c => c.Command, (PreferencesViewModel vm) => vm.ResetTcpClientCommand);
_btnResetSerial.BindDataContext(c => c.Command, (PreferencesViewModel vm) => vm.ResetSerialComCommand);
}

Control BuildContent()
Expand All @@ -91,10 +99,12 @@ Control BuildContent()
new TableRow(new Label{ Text = "TCP Listener Mode", Font = SystemFonts.Bold(), }),
new TableRow(new Label{ Text ="Ip Address:" }, (_textTcpListenerIp = new TextBox{ PlaceholderText="e.g. 127.0.0.1" })),
new TableRow(new Label{ Text="Port:" }, (_textTcpListenerPort = new NumericMaskedTextBox<int>{ PlaceholderText = "e.g. 8080" })),
new TableRow((_btnResetTcpListener = new Button { Text="Reset TCP Listener" }), null),
new TableRow(),
new TableRow(new Label{ Text = "TCP Client Mode", Font = SystemFonts.Bold(), }),
new TableRow(new Label{ Text ="Ip Address:" }, (_textTcpClientIp = new TextBox{ PlaceholderText="e.g. 127.0.0.1" })),
new TableRow(new Label{ Text="Port:" }, (_textTcpClientPort = new NumericMaskedTextBox<int>{ PlaceholderText = "e.g. 8080" })),
new TableRow((_btnResetTcpClient = new Button { Text="Reset TCP Client" }), null),
new TableRow(),
new TableRow( new Label { Text = "Serial COM Mode", Font = SystemFonts.Bold(), } ),
new TableRow(new Label{Text="Baud Rate" }, (_dropDownBaudRate = new ComboBox{})),
Expand All @@ -104,6 +114,8 @@ Control BuildContent()
new TableRow(new Label{Text="Stop Bits" },(_radStopBits = new EnumDropDown<StopBits>{})),
new TableRow(new Label{Text="Enable Dtr" },(_chkDtr = new CheckBox{})),
new TableRow(new Label{Text="Enable Rts" },(_chkRts = new CheckBox{})),
new TableRow((_btnResetSerial = new Button { Text="Reset Serial" }), null),
new TableRow(),
null,
},
};
Expand Down

0 comments on commit b2bafb3

Please sign in to comment.