diff --git a/VECTO3GUI/Helper/FileDialogHelper.cs b/VECTO3GUI/Helper/FileDialogHelper.cs index dac95a213f7fe5b43bde02b98a5e86595eb06488..53d6878b111dd36834c404321fbd75d9d21e70e6 100644 --- a/VECTO3GUI/Helper/FileDialogHelper.cs +++ b/VECTO3GUI/Helper/FileDialogHelper.cs @@ -17,7 +17,7 @@ namespace VECTO3GUI.Helper public const string JobFileExtension = ".vecto"; public const string XMLFilter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*"; - public const string JobFilter = "Vecto Files (*.vecto|*.vecto|All Files (*.*)|*.*"; + public const string JobFilter = "Vecto Files (*.vecto)|*.vecto|All Files (*.*)|*.*"; public static string[] ShowSelectFilesDialog(bool multiselect) { diff --git a/VECTO3GUI/ViewModel/Impl/JoblistViewModel.cs b/VECTO3GUI/ViewModel/Impl/JoblistViewModel.cs index d502a430a90952a1b1285fa165f5e78ff32652e5..98be48bb79e1b31848ff7d219270d0347d7382ad 100644 --- a/VECTO3GUI/ViewModel/Impl/JoblistViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/JoblistViewModel.cs @@ -397,20 +397,36 @@ namespace VECTO3GUI.ViewModel.Impl if (filePath.IsNullOrEmpty() || !IsNewJobFile(filePath.First())) return; - if (IsJobFile(filePath.First())) - { - var jobEntry = SerializeHelper.DeserializeToObject<JobEntry>(filePath.First()); - jobEntry.JobEntryFilePath = filePath.First(); + HandleFileOpen(filePath.First()); + } + + public void HandleFileOpen(string filePath) + { + JobEntry jobEntry = null; + if (IsJobFile(filePath)) { + jobEntry = SerializeHelper.DeserializeToObject<JobEntry>(filePath); + jobEntry.JobEntryFilePath = filePath; jobEntry.Selected = true; - _jobs.Add(jobEntry); - } - else if(IsXmlFile(filePath.First())) - { - var jobEntry = GetAdditionalJobEntry(filePath.First()); + //_jobs.Add(jobEntry); + } else if (IsXmlFile(filePath)) { + jobEntry = GetAdditionalJobEntry(filePath); jobEntry.Selected = true; + //_jobs.Add(jobEntry); + } + if (jobEntry == null) { + return; + } + + var newJob = Path.GetFullPath(jobEntry.JobEntryFilePath); + var existing = _jobs.Where(x => Path.GetFullPath(x.JobEntryFilePath).Equals(newJob, StringComparison.InvariantCultureIgnoreCase)).ToArray(); + if (existing.Length == 0) { _jobs.Add(jobEntry); + return; } + + SelectedJobEntry = existing.First(); } + private bool IsJobFile(string filePath) { var extension = Path.GetExtension(filePath)?.ToLower(); diff --git a/VECTO3GUI/ViewModel/Interfaces/IJoblistViewModel.cs b/VECTO3GUI/ViewModel/Interfaces/IJoblistViewModel.cs index d43218b833d3dece9302a65662eb19f701c51569..8978d18cb42a760a9ff35525871b3cc6d57f71ee 100644 --- a/VECTO3GUI/ViewModel/Interfaces/IJoblistViewModel.cs +++ b/VECTO3GUI/ViewModel/Interfaces/IJoblistViewModel.cs @@ -11,6 +11,7 @@ namespace VECTO3GUI.ViewModel.Interfaces ObservableCollection<MessageEntry> Messages { get; } ICommand AddBusJob { get; } ICommand AddJob { get; } + void HandleFileOpen(string filename); ICommand RemoveJob { get; } ICommand RemoveAllJobs { get; } ICommand MoveJobUp { get; } diff --git a/VECTO3GUI/Views/JoblistTabView.xaml b/VECTO3GUI/Views/JoblistTabView.xaml index bfccdb6c4c4c816f8412b14aa149a192f03d3955..46414464f6f9537e1c1334eae723a6735f0cd8b7 100644 --- a/VECTO3GUI/Views/JoblistTabView.xaml +++ b/VECTO3GUI/Views/JoblistTabView.xaml @@ -7,7 +7,7 @@ xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:converter="clr-namespace:VECTO3GUI.Helper.Converter" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800" + d:DesignHeight="800" d:DesignWidth="500" xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro" xmlns:interfaces="clr-namespace:VECTO3GUI.ViewModel.Interfaces" Dialog:DialogParticipation.Register="{Binding}"> diff --git a/VECTO3GUI/Views/JoblistView.xaml b/VECTO3GUI/Views/JoblistView.xaml index f0ba443646d4371929658855d47b25a3f0af51ca..e85bdc932bffbad53512bbc9bb85e3c63ca5024f 100644 --- a/VECTO3GUI/Views/JoblistView.xaml +++ b/VECTO3GUI/Views/JoblistView.xaml @@ -74,7 +74,8 @@ <DataGrid x:Name="JobList" ItemsSource="{Binding Jobs}" SelectedValue="{Binding DataContext.SelectedJobEntry, RelativeSource={RelativeSource AncestorType=views:JoblistView}}" Style="{DynamicResource AzureDataGrid}" BorderThickness="1" CanUserAddRows="False" AutoGenerateColumns="False" SelectionUnit="FullRow" - IsReadOnly="False" HeadersVisibility="All" RowHeaderWidth="5" IsSynchronizedWithCurrentItem="True" > + IsReadOnly="False" HeadersVisibility="All" RowHeaderWidth="5" IsSynchronizedWithCurrentItem="True" + Drop="JobList_OnDrop" AllowDrop="True"> <DataGrid.InputBindings> <MouseBinding diff --git a/VECTO3GUI/Views/JoblistView.xaml.cs b/VECTO3GUI/Views/JoblistView.xaml.cs index 26e113c61c6462d03c4515883dd3701e25d620fa..d5837d9ab0070ec4768b22320f186343835e1cb9 100644 --- a/VECTO3GUI/Views/JoblistView.xaml.cs +++ b/VECTO3GUI/Views/JoblistView.xaml.cs @@ -33,10 +33,28 @@ namespace VECTO3GUI.Views private void AutoScroll(object sender, NotifyCollectionChangedEventArgs e) { - if (MessageList.Items.Count > 0) { - var border = VisualTreeHelper.GetChild(MessageList, 0) as Decorator; - var scroll = border?.Child as ScrollViewer; - scroll?.ScrollToEnd(); + if (MessageList.Items.Count <= 0) { + return; + } + + var border = VisualTreeHelper.GetChild(MessageList, 0) as Decorator; + var scroll = border?.Child as ScrollViewer; + scroll?.ScrollToEnd(); + } + + private void JobList_OnDrop(object sender, DragEventArgs e) + { + if (!e.Data.GetDataPresent(DataFormats.FileDrop)) { + return; + } + + var files = (string[])e.Data.GetData(DataFormats.FileDrop); + if (files == null) { + return; + } + var vm = (IJoblistViewModel)DataContext; + foreach (var file in files) { + vm.HandleFileOpen(file); } } }