diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-10-12 00:37:41 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-10-12 00:37:41 +0300 |
| commit | 87437f979da7baf9a65d98140b361ee85d6966d5 (patch) | |
| tree | a6e58c154c33d82dfb18ad36764bfd151df0964c /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs | |
| parent | 4461a1fc4b57415fa781c83fdaad1c3725e0be46 (diff) | |
| download | Tango-87437f979da7baf9a65d98140b361ee85d6966d5.tar.gz Tango-87437f979da7baf9a65d98140b361ee85d6966d5.zip | |
Implemented import project tabs in tech board.
Implemented auto update of observables LAST_UPDATE via ObservableContext.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs | 64 |
1 files changed, 55 insertions, 9 deletions
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 |
