Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 689eebbd authored by Markus QUARITSCH's avatar Markus QUARITSCH
Browse files

allow file drag&drop to job list, avoid having multiple entries with jame job in job list

parent 463d82e0
No related branches found
No related tags found
No related merge requests found
......@@ -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)
{
......
......@@ -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();
......
......@@ -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; }
......
......@@ -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}">
......
......@@ -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
......
......@@ -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);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment