diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels')
2 files changed, 80 insertions, 9 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/ImportProjectTabViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/ImportProjectTabViewVM.cs new file mode 100644 index 000000000..751a563bf --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/ImportProjectTabViewVM.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.MachineStudio.Technician.Project; +using Tango.SharedUI; +using Tango.SharedUI.Components; + +namespace Tango.MachineStudio.Technician.ViewModels +{ + public class ImportProjectTabViewVM : DialogViewVM + { + public String ProjectName { get; set; } + + public SelectedObjectCollection<MachineTechViewProjectTab> Tabs { get; set; } + + public ImportProjectTabViewVM(List<MachineTechViewProjectTab> tabs, String projectName) + { + ProjectName = projectName; + Tabs = new SelectedObjectCollection<MachineTechViewProjectTab>(new ObservableCollection<MachineTechViewProjectTab>(tabs), new ObservableCollection<MachineTechViewProjectTab>()); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 59cd6fe19..46d745139 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -38,6 +38,7 @@ using Microsoft.WindowsAPICodePack.Dialogs; using RealTimeGraphX; using RealTimeGraphX.WPF.DataSeries; using RealTimeGraphX.DataPoints; +using Tango.MachineStudio.Technician.Views; namespace Tango.MachineStudio.Technician.ViewModels { @@ -267,6 +268,15 @@ namespace Tango.MachineStudio.Technician.ViewModels /// Gets or sets the rename tab command. /// </summary> public RelayCommand RenameTabCommand { get; set; } + + /// <summary> + /// Gets or sets the import project tabs command. + /// </summary> + /// <value> + /// The import project tabs command. + /// </value> + public RelayCommand ImportProjectTabsCommand { get; set; } + #endregion #region Constructors @@ -340,6 +350,7 @@ namespace Tango.MachineStudio.Technician.ViewModels RemoveTabCommand = new RelayCommand<MachineTechTabVM>(RemoveTab); NewProjectCommand = new RelayCommand(CreateNewProject); RenameTabCommand = new RelayCommand(RenameTab); + ImportProjectTabsCommand = new RelayCommand(ImportProjectTabs); } #endregion @@ -1788,12 +1799,12 @@ namespace Tango.MachineStudio.Technician.ViewModels /// Opens the specified project file path. /// </summary> /// <param name="fileName">File path.</param> - public void OpenProjectFile(String fileName) + public MachineTechViewProject OpenProjectFile(String fileName, bool load = true) { + MachineTechViewProject project = null; + try { - MachineTechViewProject project = null; - project = MachineTechViewProject.Load(fileName); if (project.Tabs.Count == 0) @@ -1807,27 +1818,35 @@ namespace Tango.MachineStudio.Technician.ViewModels project.Tabs.Add(tab); } - LoadProject(project); - _lastTechProjectFile = fileName; + if (load) + { + LoadProject(project); + _lastTechProjectFile = fileName; + } } catch (Exception ex) { LogManager.Log(ex, $"Error loading project file {fileName}."); _notification.ShowError("An error occurred while trying to load the tech board project file."); } + + return project; } /// <summary> /// Loads the specified project. /// </summary> /// <param name="project">The project.</param> - public void LoadProject(MachineTechViewProject project) + public void LoadProject(MachineTechViewProject project, bool appendToCurrentProject = false) { using (_notification.PushTaskItem("Loading technician project file...")) { - Tabs.Clear(); - _singleControllers.Clear(); - _multiControllers.Clear(); + if (!appendToCurrentProject) + { + Tabs.Clear(); + _singleControllers.Clear(); + _multiControllers.Clear(); + } foreach (var tab in project.Tabs) { @@ -2012,6 +2031,33 @@ namespace Tango.MachineStudio.Technician.ViewModels } } + /// <summary> + /// Imports a project file tabs to the current project. + /// </summary> + private void ImportProjectTabs() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select Technician Project File"; + dlg.Filter = "Technician Project File|*.tpf"; + + if (dlg.ShowDialog().Value) + { + var project = OpenProjectFile(dlg.FileName, false); + + if (project != null) + { + var vm = new ImportProjectTabViewVM(project.Tabs, Path.GetFileNameWithoutExtension(dlg.FileName)); + _notification.ShowModalDialog<ImportProjectTabViewVM, ImportProjectTabView>(vm, (x) => + { + project.Tabs.Clear(); + project.Tabs.AddRange(vm.Tabs.SynchedSource.ToList()); + LoadProject(project, true); + + }, () => { }); + } + } + } + #endregion #region IStudioModuleVM |
