Skip to content

Commit 9f094bc

Browse files
committed
Drag & Drop added
1 parent 653eb78 commit 9f094bc

6 files changed

Lines changed: 60 additions & 14 deletions

File tree

Source/NETworkManager/ViewModels/SettingsImportExportViewModel.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ public class SettingsImportExportViewModel : ViewModelBase
1919

2020
#region Variables
2121
#region Import
22-
private string _importLocationSelectedPath;
23-
public string ImportLocationSelectedPath
22+
private string _importFilePath;
23+
public string ImportFilePath
2424
{
25-
get { return _importLocationSelectedPath; }
25+
get { return _importFilePath; }
2626
set
2727
{
28-
if (value == _importLocationSelectedPath)
28+
if (value == _importFilePath)
2929
return;
3030

3131
ImportFileIsValid = false;
3232

33-
_importLocationSelectedPath = value;
33+
_importFilePath = value;
3434
OnPropertyChanged();
3535
}
3636
}
@@ -48,7 +48,7 @@ public bool ImportFileIsValid
4848
OnPropertyChanged();
4949
}
5050
}
51-
51+
5252
public bool _importEverything = true;
5353
public bool ImportEverything
5454
{
@@ -718,7 +718,7 @@ private void BrowseFileAction()
718718
};
719719

720720
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
721-
ImportLocationSelectedPath = openFileDialog.FileName;
721+
ImportFilePath = openFileDialog.FileName;
722722
}
723723

724724
public ICommand ValidateImportSettingsCommand
@@ -730,7 +730,7 @@ private async void ValidateImportSettingsAction()
730730
{
731731
try
732732
{
733-
List<ImportExportManager.ImportExportOptions> importOptions = ImportExportManager.ValidateImportFile(ImportLocationSelectedPath);
733+
List<ImportExportManager.ImportExportOptions> importOptions = ImportExportManager.ValidateImportFile(ImportFilePath);
734734

735735
ImportFileIsValid = true;
736736
ImportApplicationSettingsExists = importOptions.Contains(ImportExportManager.ImportExportOptions.ApplicationSettings);
@@ -848,7 +848,7 @@ private async void ImportSettingsAction()
848848
}
849849

850850
// Import (copy) files from zip archive
851-
ImportExportManager.Import(ImportLocationSelectedPath, importOptions);
851+
ImportExportManager.Import(ImportFilePath, importOptions);
852852

853853
// Do the import (replace or add)
854854
if (importOptions.Contains(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles))
@@ -1013,6 +1013,13 @@ public void SaveAndCheckSettings()
10131013
PuTTYSessionsExists = File.Exists(PuTTYSessionManager.GetSessionsFilePath());
10141014
WakeOnLANClientsExists = File.Exists(WakeOnLANClientManager.GetClientsFilePath());
10151015
}
1016+
1017+
public void SetImportLocationFilePathFromDragDrop(string filePath)
1018+
{
1019+
ImportFilePath = filePath;
1020+
1021+
OnPropertyChanged(nameof(ImportFilePath));
1022+
}
10161023
#endregion
10171024
}
10181025
}

Source/NETworkManager/ViewModels/SettingsSettingsViewModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public bool MovingFiles
4646
OnPropertyChanged();
4747
}
4848
}
49-
49+
5050
private bool _isPortable;
5151
public bool IsPortable
5252
{
@@ -650,6 +650,13 @@ public void SaveAndCheckSettings()
650650
PuTTYSessionsExists = File.Exists(PuTTYSessionManager.GetSessionsFilePath());
651651
WakeOnLANClientsExists = File.Exists(WakeOnLANClientManager.GetClientsFilePath());
652652
}
653+
654+
public void SetLocationPathFromDragDrop(string path)
655+
{
656+
LocationSelectedPath = path;
657+
658+
OnPropertyChanged(nameof(LocationSelectedPath));
659+
}
653660
#endregion
654661
}
655662
}

Source/NETworkManager/Views/SettingsImportExportView.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
</UserControl.Resources>
1919
<StackPanel >
2020
<TextBlock Style="{StaticResource HeaderTextBlock}" Text="{DynamicResource String_Header_Import}" />
21-
<TextBox x:Name="txtImportLocation" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_LocationOfTheImport}" Style="{StaticResource BrowseFolderTextBox}" mah:TextBoxHelper.ButtonCommand="{Binding BrowseFileCommand}" Margin="0,0,0,10">
21+
<TextBox x:Name="txtImportFilePath" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_LocationOfTheImport}" Style="{StaticResource BrowseFolderTextBox}" mah:TextBoxHelper.ButtonCommand="{Binding BrowseFileCommand}" AllowDrop="True" Drop="txtImportFilePath_Drop" PreviewDragOver="txtImportFilePath_PreviewDragOver" Margin="0,0,0,10">
2222
<TextBox.Text>
23-
<Binding Path="ImportLocationSelectedPath" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
23+
<Binding Path="ImportFilePath" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
2424
<Binding.ValidationRules>
2525
<Validator:EmptyValidator ValidatesOnTargetUpdated="True" />
2626
<Validator:FileExistsValidator ValidatesOnTargetUpdated="True" />
@@ -33,7 +33,7 @@
3333
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButton}">
3434
<Setter Property="IsEnabled" Value="False" />
3535
<Style.Triggers>
36-
<DataTrigger Binding="{Binding ElementName=txtImportLocation, Path=(Validation.HasError)}" Value="False">
36+
<DataTrigger Binding="{Binding ElementName=txtImportFilePath, Path=(Validation.HasError)}" Value="False">
3737
<Setter Property="IsEnabled" Value="True" />
3838
</DataTrigger>
3939
</Style.Triggers>

Source/NETworkManager/Views/SettingsImportExportView.xaml.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,21 @@ public void SaveAndCheckSettings()
2525
{
2626
viewModel.SaveAndCheckSettings();
2727
}
28+
29+
private void txtImportFilePath_Drop(object sender, DragEventArgs e)
30+
{
31+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
32+
{
33+
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
34+
35+
viewModel.SetImportLocationFilePathFromDragDrop(files[0]);
36+
}
37+
}
38+
39+
private void txtImportFilePath_PreviewDragOver(object sender, DragEventArgs e)
40+
{
41+
e.Effects = DragDropEffects.Copy;
42+
e.Handled = true;
43+
}
2844
}
2945
}

Source/NETworkManager/Views/SettingsSettingsView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</UserControl.Resources>
2222
<StackPanel >
2323
<TextBlock Style="{StaticResource HeaderTextBlock}" Text="{DynamicResource String_Header_Location}" />
24-
<TextBox x:Name="txtLocation" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_EnterLocation}" mah:TextBoxHelper.ButtonCommand="{Binding BrowseFolderCommand}" Margin="0,0,0,10">
24+
<TextBox x:Name="txtLocation" mah:TextBoxHelper.Watermark="{DynamicResource String_Watermark_EnterLocation}" mah:TextBoxHelper.ButtonCommand="{Binding BrowseFolderCommand}" AllowDrop="True" Drop="txtLocation_Drop" PreviewDragOver="txtLocation_PreviewDragOver" Margin="0,0,0,10">
2525
<TextBox.Text>
2626
<Binding Path="LocationSelectedPath" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
2727
<Binding.ValidationRules>

Source/NETworkManager/Views/SettingsSettingsView.xaml.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,21 @@ public void SaveAndCheckSettings()
2525
{
2626
viewModel.SaveAndCheckSettings();
2727
}
28+
29+
private void txtLocation_Drop(object sender, DragEventArgs e)
30+
{
31+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
32+
{
33+
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
34+
35+
viewModel.SetLocationPathFromDragDrop(files[0]);
36+
}
37+
}
38+
39+
private void txtLocation_PreviewDragOver(object sender, DragEventArgs e)
40+
{
41+
e.Effects = DragDropEffects.Copy;
42+
e.Handled = true;
43+
}
2844
}
2945
}

0 commit comments

Comments
 (0)