Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/DynamoCoreWpf/Controls/StartPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dynamo.Configuration;
using Dynamo.Logging;
using Dynamo.UI.Prompts;
using Dynamo.Utilities;
using Dynamo.ViewModels;
using Dynamo.Wpf.Properties;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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<StartPageListItem> 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 });
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

<Target Name="NpmRunBuildHomePage" BeforeTargets="BeforeBuild">
<PropertyGroup>
<PackageVersion>1.0.31</PackageVersion>
<PackageVersion>1.0.32</PackageVersion>
<PackageName>DynamoHome</PackageName>
</PropertyGroup>
<Exec Command="$(PowerShellCommand) -ExecutionPolicy Bypass -File &quot;$(SolutionDir)pkgexist.ps1&quot; &quot;$(PackageName)&quot; &quot;$(PackageVersion)&quot;" ConsoleToMSBuild="true">
Expand Down
9 changes: 9 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4180,6 +4180,9 @@ To make this file into a new template, save it to a different folder, then move
<data name="MessageErrorOpeningInvalidPath" xml:space="preserve">
<value>Invalid file path provided. In case the file is archived, please make sure to extract it before opening.\n{0}</value>
</data>
<data name="MessageHomeFileMissing" xml:space="preserve">
<value>This file is no longer available. It may have been moved, renamed, or deleted.\n{0}</value>
</data>
<data name="GroupContextMenuFreezeGroup" xml:space="preserve">
<value>Freeze Group</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4171,6 +4171,9 @@ To make this file into a new template, save it to a different folder, then move
<data name="MessageErrorOpeningInvalidPath" xml:space="preserve">
<value>Invalid file path provided. In case the file is archived, please make sure to extract it before opening.\n{0}</value>
</data>
<data name="MessageHomeFileMissing" xml:space="preserve">
<value>This file is no longer available. It may have been moved, renamed, or deleted.\n{0}</value>
</data>
<data name="GroupContextMenuFreezeGroup" xml:space="preserve">
<value>Freeze Group</value>
</data>
Expand Down
38 changes: 26 additions & 12 deletions src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Comment on lines +131 to +138

await dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.setShowStartPageChanged('{startPage.DynamoViewModel.ShowStartPage}')");
}
}
Comment on lines +127 to 142

Expand Down Expand Up @@ -338,11 +347,8 @@ private async Task SendSamplesData()
/// </summary>
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<StartPageListItem>();
await LoadTemplates(items);
}

private async Task SendRecentGraphsData()
Expand All @@ -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<StartPageListItem>();
await LoadGraphs(recentFiles);

if (startPage.DynamoViewModel != null && startPage.DynamoViewModel.RecentFiles != null)
{
startPage.DynamoViewModel.RecentFiles.CollectionChanged -= RecentFiles_CollectionChanged;
startPage.DynamoViewModel.RecentFiles.CollectionChanged += RecentFiles_CollectionChanged;
}
}
Expand Down Expand Up @@ -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<StartPageListItem>();
var templateFiles = startPage.TemplateFiles?.DistinctBy(x => x.ContextData).ToList() ?? new List<StartPageListItem>();

_ = LoadGraphs(recentFiles);
_ = LoadTemplates(templateFiles);
return;
}

var dvm = this.startPage.DynamoViewModel;
var openArg = IsListedHomePageTemplate(path)
? (object)Tuple.Create(path, false, true)
Expand Down
Loading