diff --git a/src/DynamoCoreWpf/Controls/StartPage.xaml.cs b/src/DynamoCoreWpf/Controls/StartPage.xaml.cs index 9ed317b147a..cc23ef8d88b 100644 --- a/src/DynamoCoreWpf/Controls/StartPage.xaml.cs +++ b/src/DynamoCoreWpf/Controls/StartPage.xaml.cs @@ -1,5 +1,6 @@ using Dynamo.Configuration; using Dynamo.Logging; +using Dynamo.UI.Prompts; using Dynamo.Utilities; using Dynamo.ViewModels; using Dynamo.Wpf.Properties; @@ -279,6 +280,17 @@ private void AddTemplateListItemFromPath(string filePath) this.TemplateFiles.Add(templateItem); } + internal void RefreshTemplateFiles() + { + TemplateFiles.Clear(); + LoadTemplates(); + } + + internal void RefreshRecentFiles() + { + RefreshRecentFileList(DynamoViewModel.RecentFiles, true); + } + internal void WalkDirectoryTree(System.IO.DirectoryInfo root, SampleFileEntry rootProperty) { try @@ -654,6 +666,11 @@ private void HandleRegularCommand(StartPageListItem item) private void HandleFilePath(StartPageListItem item) { var path = item.ContextData; + if (HandleMissingFilePath(path)) + { + return; + } + // Listed templates: use the same open path as the template file-picker (ShowOpenTemplateDialog), // i.e. open as a new graph from the file contents, not as the saved template path on disk. object openArg = IsTemplateFilePath(path) @@ -671,6 +688,38 @@ private bool IsTemplateFilePath(string path) string.Equals(template.ContextData, path, StringComparison.OrdinalIgnoreCase)); } + internal bool HandleMissingFilePath(string path) + { + if (File.Exists(path)) + { + return false; + } + + DynamoMessageBox.Show( + DynamoViewModel.Owner, + string.Format(Resources.MessageHomeFileMissing.Replace("\\n", Environment.NewLine), path), + Resources.MessageErrorOpeningFileGeneral, + MessageBoxButton.OK, + MessageBoxImage.Warning); + + RemoveMissingFilePath(RecentFiles, path); + RemoveMissingFilePath(TemplateFiles, path); + + return true; + } + + private static void RemoveMissingFilePath(ObservableCollection files, string path) + { + var missingFiles = files + .Where(file => string.Equals(file.ContextData, path, StringComparison.OrdinalIgnoreCase)) + .ToList(); + + foreach (var missingFile in missingFiles) + { + files.Remove(missingFile); + } + } + private void HandleExternalUrl(StartPageListItem item) { System.Diagnostics.Process.Start(new ProcessStartInfo(item.ContextData) { UseShellExecute = true }); diff --git a/src/DynamoCoreWpf/DynamoCoreWpf.csproj b/src/DynamoCoreWpf/DynamoCoreWpf.csproj index c888413372c..4c3aece3f5b 100644 --- a/src/DynamoCoreWpf/DynamoCoreWpf.csproj +++ b/src/DynamoCoreWpf/DynamoCoreWpf.csproj @@ -59,7 +59,7 @@ - 1.0.31 + 1.0.32 DynamoHome diff --git a/src/DynamoCoreWpf/Properties/Resources.Designer.cs b/src/DynamoCoreWpf/Properties/Resources.Designer.cs index 03f501a0c71..34ef23247b3 100644 --- a/src/DynamoCoreWpf/Properties/Resources.Designer.cs +++ b/src/DynamoCoreWpf/Properties/Resources.Designer.cs @@ -4692,6 +4692,15 @@ public static string MessageErrorOpeningInvalidPath { } } + /// + /// Looks up a localised string similar to This file is no longer available. It may have been moved, renamed, or deleted.\n{0}. + /// + public static string MessageHomeFileMissing { + get { + return ResourceManager.GetString("MessageHomeFileMissing", resourceCulture); + } + } + /// /// Looks up a localized string similar to Loading the packages is taking longer than expected. What would you like to do?. /// diff --git a/src/DynamoCoreWpf/Properties/Resources.en-US.resx b/src/DynamoCoreWpf/Properties/Resources.en-US.resx index 14958c67a51..a2152291a40 100644 --- a/src/DynamoCoreWpf/Properties/Resources.en-US.resx +++ b/src/DynamoCoreWpf/Properties/Resources.en-US.resx @@ -4180,6 +4180,9 @@ To make this file into a new template, save it to a different folder, then move Invalid file path provided. In case the file is archived, please make sure to extract it before opening.\n{0} + + This file is no longer available. It may have been moved, renamed, or deleted.\n{0} + Freeze Group diff --git a/src/DynamoCoreWpf/Properties/Resources.resx b/src/DynamoCoreWpf/Properties/Resources.resx index 5f1aae9c455..1341f2516ed 100644 --- a/src/DynamoCoreWpf/Properties/Resources.resx +++ b/src/DynamoCoreWpf/Properties/Resources.resx @@ -4171,6 +4171,9 @@ To make this file into a new template, save it to a different folder, then move Invalid file path provided. In case the file is archived, please make sure to extract it before opening.\n{0} + + This file is no longer available. It may have been moved, renamed, or deleted.\n{0} + Freeze Group diff --git a/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs b/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs index c9a02c05804..d8f8989b986 100644 --- a/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs +++ b/src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs @@ -124,11 +124,20 @@ private void OnDataContextChanged(object sender, DependencyPropertyChangedEventA } } - private void DynamoViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + private async void DynamoViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if(e.PropertyName == nameof(startPage.DynamoViewModel.ShowStartPage) && dynWebView?.CoreWebView2 != null) { - dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.setShowStartPageChanged('{startPage.DynamoViewModel.ShowStartPage}')"); + if (startPage.DynamoViewModel.ShowStartPage) + { + startPage.RefreshTemplateFiles(); + startPage.RefreshRecentFiles(); + + await SendTemplateData(); + await SendRecentGraphsData(); + } + + await dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.setShowStartPageChanged('{startPage.DynamoViewModel.ShowStartPage}')"); } } @@ -338,11 +347,8 @@ private async Task SendSamplesData() /// private async Task SendTemplateData() { - var items = startPage.TemplateFiles?.DistinctBy(x => x.ContextData).ToList(); - if (items != null && items.Any()) - { - await LoadTemplates(items); - } + var items = startPage.TemplateFiles?.DistinctBy(x => x.ContextData).ToList() ?? new List(); + await LoadTemplates(items); } private async Task SendRecentGraphsData() @@ -361,14 +367,12 @@ private async Task SendRecentGraphsData() } // Load recent files - var recentFiles = startPage.RecentFiles?.DistinctBy(x => x.ContextData).ToList(); - if (recentFiles != null && recentFiles.Any()) - { - await LoadGraphs(recentFiles); - } + var recentFiles = startPage.RecentFiles?.DistinctBy(x => x.ContextData).ToList() ?? new List(); + await LoadGraphs(recentFiles); if (startPage.DynamoViewModel != null && startPage.DynamoViewModel.RecentFiles != null) { + startPage.DynamoViewModel.RecentFiles.CollectionChanged -= RecentFiles_CollectionChanged; startPage.DynamoViewModel.RecentFiles.CollectionChanged += RecentFiles_CollectionChanged; } } @@ -542,6 +546,16 @@ internal void OpenFile(string path) return; } + if (startPage.HandleMissingFilePath(path)) + { + var recentFiles = startPage.RecentFiles?.DistinctBy(x => x.ContextData).ToList() ?? new List(); + var templateFiles = startPage.TemplateFiles?.DistinctBy(x => x.ContextData).ToList() ?? new List(); + + _ = LoadGraphs(recentFiles); + _ = LoadTemplates(templateFiles); + return; + } + var dvm = this.startPage.DynamoViewModel; var openArg = IsListedHomePageTemplate(path) ? (object)Tuple.Create(path, false, true)