Skip to content

Commit

Permalink
navigation way, cancel prompts
Browse files Browse the repository at this point in the history
- now warns the user of losing changes if using cancel or navigating away
  • Loading branch information
dnenov committed Oct 24, 2023
1 parent 5fec826 commit 96f7edc
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 25 deletions.
18 changes: 18 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.

6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3312,6 +3312,12 @@ Try placing the highlighted **ByOrigin** node.</value>
<data name="FileTrustWarningPopupNoCloseFile" xml:space="preserve">
<value>No, close file</value>
</data>
<data name="DiscardChangesWarningPopupCaption" xml:space="preserve">
<value>Discard changes?</value>
</data>
<data name="DiscardChangesWarningPopupMessage" xml:space="preserve">
<value>Your changes will be lost if you navigate away from the package upload screen.</value>
</data>
<data name="FileTrustWarningPopupSettings" xml:space="preserve">
<value>Settings</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3299,6 +3299,12 @@ Try placing the highlighted **ByOrigin** node.</value>
<data name="FileTrustWarningPopupNoCloseFile" xml:space="preserve">
<value>No, close file</value>
</data>
<data name="DiscardChangesWarningPopupCaption" xml:space="preserve">
<value>Discard changes?</value>
</data>
<data name="DiscardChangesWarningPopupMessage" xml:space="preserve">
<value>Your changes will be lost if you navigate away from the package upload screen.</value>
</data>
<data name="FileTrustWarningPopupSettings" xml:space="preserve">
<value>Settings</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public string RootFolder
}

#endregion

internal PublishPackageViewModel()
{
customNodeDefinitions = new List<CustomNodeDefinition>();
Expand Down Expand Up @@ -920,11 +920,6 @@ private List<PackageItemRootViewModel> BindParentToChild(Dictionary<string, Pack
parent.Value.AddChild(child.Value);
child.Value.isChild = true;
}
//if (IsSubPathOf(parent.Value.DirectoryName, child.Value.DirectoryName))
//{
// child.Value.isChild = true;
// parent.Value.ChildItems.Add(child.Value);
//}
}
}

Expand Down Expand Up @@ -1032,6 +1027,34 @@ private void ClearAllEntries()
this.ClearPackageContents();
}

/// <summary>
/// Decides if any user changes have been made in the current packge publish session
/// </summary>
/// <returns>true if any changes have been made, otehrwise false</returns>
internal bool AnyUserChanges()
{
if(!String.IsNullOrEmpty(this.Name)) return true;
if(!String.IsNullOrEmpty(this.RepositoryUrl)) return true;
if(!String.IsNullOrEmpty(this.SiteUrl)) return true;
if(!String.IsNullOrEmpty(this.License)) return true;
if(!String.IsNullOrEmpty(this.Keywords)) return true;
if(!String.IsNullOrEmpty(this.Description)) return true;
if(!String.IsNullOrEmpty(this.Group)) return true;
if(!String.IsNullOrEmpty(this.MajorVersion) && !(this.MajorVersion.Equals("0"))) return true;
if(!String.IsNullOrEmpty(this.MinorVersion) && !(this.MinorVersion.Equals("0"))) return true;
if(!String.IsNullOrEmpty(this.BuildVersion) && !(this.BuildVersion.Equals("0"))) return true;
if(this.AdditionalFiles.Any()) return true;
if(this.Dependencies.Any()) return true;
if(this.Assemblies.Any()) return true;
if(this.SelectedHosts.Any()) return true;
if(!String.IsNullOrEmpty(this.SelectedHostsString)) return true;
if(!String.IsNullOrEmpty(this.copyrightHolder)) return true;
if(!String.IsNullOrEmpty(this.copyrightYear)) return true;
if(!String.IsNullOrEmpty(this.RootFolder)) return true;

return false;
}

private void ClearPackageContents()
{
// this method clears the package contents in the publish package dialog
Expand Down Expand Up @@ -1567,7 +1590,7 @@ private void RemoveItem (object parameter)
/// The Cancel command to clear all package data and user interface
/// </summary>
private void Cancel()
{
{
this.ClearAllEntries();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
Orientation="Horizontal">

<!-- Cancel -->
<Button Command="{Binding Path=CancelCommand}"
<Button Click="CancelButton_Click"
Content="{x:Static p:Resources.CancelButton}"
DockPanel.Dock="Right"
Background="Transparent"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using Dynamo.Logging;
using Dynamo.UI;
using Dynamo.ViewModels;
using DynamoUtilities;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.UI;
using Dynamo.ViewModels;
using Dynamo.Wpf.Utilities;
using DynamoUtilities;
using Views.PackageManager.Pages;

namespace Dynamo.PackageManager.UI
Expand Down Expand Up @@ -268,5 +270,23 @@ private void mainFrame_Navigated(object sender, System.Windows.Navigation.Naviga
}
}));
}

private void CancelButton_Click(object sender, RoutedEventArgs e)
{
if (!PublishPackageViewModel.AnyUserChanges()) return;

MessageBoxResult response = DynamoModel.IsTestMode ? MessageBoxResult.OK :
MessageBoxService.Show(
Owner,
Dynamo.Wpf.Properties.Resources.DiscardChangesWarningPopupMessage,
Dynamo.Wpf.Properties.Resources.DiscardChangesWarningPopupCaption,
MessageBoxButton.OKCancel,
MessageBoxImage.Warning);

if (response == MessageBoxResult.OK)
{
PublishPackageViewModel.CancelCommand.Execute();
}
}
}
}
16 changes: 11 additions & 5 deletions src/DynamoCoreWpf/Views/PackageManager/PackageManagerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@
Background="{StaticResource PreferencesWindowBackgroundColor}">

<TabItem Header="{x:Static p:Resources.PackageManagerSearchTab}"
Style="{StaticResource PackageManagerTab}">
Style="{StaticResource PackageManagerTab}"
PreviewMouseDown="tab_PreviewMouseDown">
<!--Search Packages Tab-->
<Border BorderBrush="{StaticResource BorderBrushWithOpacity}"
BorderThickness="1 1 0 0">
Expand Down Expand Up @@ -217,7 +218,9 @@
</TabItem>

<TabItem Header="{x:Static p:Resources.PackageManagerPublishTab}"
Style="{StaticResource PackageManagerTab}">
Style="{StaticResource PackageManagerTab}"
PreviewMouseDown="tab_PreviewMouseDown"
x:Name="publishTab">
<!--Publish Packages Tab-->
<Border BorderBrush="{StaticResource BorderBrushWithOpacity}"
BorderThickness="1 1 0 0">
Expand All @@ -237,7 +240,8 @@
</TabItem>

<TabItem Header="{x:Static p:Resources.PackageManagerInstalledPackagesTab}"
Style="{StaticResource PackageManagerTab}">
Style="{StaticResource PackageManagerTab}"
PreviewMouseDown="tab_PreviewMouseDown">
<!--Installed Packages Tab-->
<Border BorderBrush="{StaticResource BorderBrushWithOpacity}"
BorderThickness="1 1 0 0">
Expand Down Expand Up @@ -295,7 +299,8 @@
</TabItem>

<TabItem Header="{x:Static p:Resources.PackageManagerMyPackagesTab}"
Style="{StaticResource PackageManagerTab}">
Style="{StaticResource PackageManagerTab}"
PreviewMouseDown="tab_PreviewMouseDown">
<!--My Packages Tab-->
<Border BorderBrush="{StaticResource BorderBrushWithOpacity}"
BorderThickness="1 1 0 0">
Expand Down Expand Up @@ -447,7 +452,8 @@
</TabItem>

<TabItem Header="{x:Static p:Resources.PackageManagerPackageSettingsTab}"
Style="{StaticResource PackageManagerTab}">
Style="{StaticResource PackageManagerTab}"
PreviewMouseDown="tab_PreviewMouseDown">
<!--Package Settings Tab-->
<Border BorderBrush="{StaticResource BorderBrushWithOpacity}"
BorderThickness="1 1 0 0">
Expand Down
39 changes: 39 additions & 0 deletions src/DynamoCoreWpf/Views/PackageManager/PackageManagerView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Windows.Input;
using Dynamo.Controls;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.UI;
using Dynamo.ViewModels;
using Dynamo.Wpf.Utilities;
Expand Down Expand Up @@ -174,5 +175,43 @@ private void CloseToastButton_OnClick(object sender, RoutedEventArgs e)
this.loadingSearchWarningBar.Visibility = Visibility.Collapsed;
this.loadingMyPackagesWarningBar.Visibility = Visibility.Collapsed;
}

private void tab_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var selectedTab = sender as TabItem;
if (selectedTab == null) return;
var tabControl = selectedTab.Parent as TabControl;
if (tabControl == null) return;
var prevTab = tabControl.SelectedItem as TabItem;
if (prevTab == null) return;

if (prevTab.Name.Equals("publishTab") && !selectedTab.Name.Equals("publishTab"))
{

if (!PackageManagerViewModel.PublishPackageViewModel.AnyUserChanges())
{
selectedTab.IsSelected = true;
return;
}

MessageBoxResult response = DynamoModel.IsTestMode ? MessageBoxResult.OK :
MessageBoxService.Show(
this,
Dynamo.Wpf.Properties.Resources.DiscardChangesWarningPopupMessage,
Dynamo.Wpf.Properties.Resources.DiscardChangesWarningPopupCaption,
MessageBoxButton.OKCancel,
MessageBoxImage.Warning);

if (response == MessageBoxResult.OK)
{
PackageManagerViewModel.PublishPackageViewModel.CancelCommand.Execute();
selectedTab.IsSelected = true;
}
else
{
e.Handled = true;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<Thumb x:Name="PART_RightHeaderGripper"
Width="1"
HorizontalAlignment="Right"
BorderBrush="#5E5E5E"
BorderBrush="Transparent"
BorderThickness="1,0,0,0"
Cursor="SizeWE" />
</Grid>
Expand Down Expand Up @@ -139,7 +139,7 @@
<Thumb x:Name="PART_RightHeaderGripper"
Width="1"
HorizontalAlignment="Right"
BorderBrush="#5E5E5E"
BorderBrush="Transparent"
BorderThickness="1,0,0,0"
Cursor="SizeWE" />
</Grid>
Expand Down Expand Up @@ -174,8 +174,7 @@
<Setter Property="CellStyle" Value="{DynamicResource DataGridCellStyle}" />
<Setter Property="RowStyle" Value="{DynamicResource DataGridRowStyle}" />
<Setter Property="HeadersVisibility" Value="Column" />
<Setter Property="GridLinesVisibility" Value="Vertical" />
<Setter Property="VerticalGridLinesBrush" Value="{StaticResource GridLineColorBrush}" />
<Setter Property="GridLinesVisibility" Value="None" />
<Setter Property="SelectionMode" Value="Extended" />
<Setter Property="HorizontalScrollBarVisibility" Value="Visible" />
<Setter Property="VerticalScrollBarVisibility" Value="Auto" />
Expand Down Expand Up @@ -467,5 +466,14 @@
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<Rectangle Stroke="{StaticResource GridLineColorBrush}"
StrokeThickness="1"
Margin="295 0 0 0"
Width="1"
Height="{Binding ElementName=rootContentsDataGrid, Path=ActualHeight}"
Grid.Column="1"
Grid.Row="1">

</Rectangle>
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
<Thumb x:Name="PART_RightHeaderGripper"
Width="1"
HorizontalAlignment="Right"
BorderBrush="#5E5E5E"
BorderBrush="Transparent"
BorderThickness="1,0,0,0"
Cursor="SizeWE" />
</Grid>
Expand Down Expand Up @@ -315,7 +315,7 @@
<Thumb x:Name="PART_RightHeaderGripper"
Width="1"
HorizontalAlignment="Right"
BorderBrush="#5E5E5E"
BorderBrush="Transparent"
BorderThickness="1,0,0,0"
Cursor="SizeWE" />
</Grid>
Expand Down Expand Up @@ -374,8 +374,7 @@
<Setter Property="CellStyle" Value="{DynamicResource DataGridCellStyle}" />
<Setter Property="RowStyle" Value="{DynamicResource DataGridRowStyle}" />
<Setter Property="HeadersVisibility" Value="Column" />
<Setter Property="GridLinesVisibility" Value="Vertical" />
<Setter Property="VerticalGridLinesBrush" Value="{StaticResource GridLineColorBrush}"/>
<Setter Property="GridLinesVisibility" Value="None" />
<Setter Property="SelectionMode" Value="Extended" />
<Setter Property="HorizontalScrollBarVisibility" Value="Visible" />
<Setter Property="VerticalScrollBarVisibility" Value="Auto" />
Expand Down Expand Up @@ -566,6 +565,16 @@
</DataGrid.Columns>
</DataGrid>

<Rectangle Stroke="{StaticResource GridLineColorBrush}"
StrokeThickness="1"
Margin="295 0 0 0"
Width="1"
Height="{Binding ElementName=rootContentsDataGrid, Path=ActualHeight}"
Grid.Column="1"
Grid.Row="1">

</Rectangle>

<!--Toggle-->
<StackPanel Orientation="Horizontal"
Grid.Column="1"
Expand Down

0 comments on commit 96f7edc

Please sign in to comment.