Skip to content

Commit

Permalink
Revert "Enabling ShortcutBar items (#13761)" (#13784)
Browse files Browse the repository at this point in the history
This reverts commit 39fd836.
  • Loading branch information
QilongTang authored and sm6srw committed Apr 5, 2023
1 parent 4b85f6f commit afd1d63
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 174 deletions.
10 changes: 5 additions & 5 deletions src/DynamoCoreWpf/Controls/ShortcutToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
Style="{StaticResource MainMenu}"
Margin="0,0,10,0"
IsMainMenu="True">
<MenuItem Name="loginMenu" Margin="0,-3,-10,0">
<MenuItem Name="loginMenu" Margin="0,-3,-15,0">
<MenuItem.Header>
<Button Name="LoginButton" Click="LoginButton_OnClick" Foreground="#DCDCDC" Padding="5,0,5,0">
<StackPanel FlowDirection="LeftToRight" Orientation="Horizontal">
Expand Down Expand Up @@ -222,11 +222,11 @@
</MenuItem>
</MenuItem>
<MenuItem Name="exportMenu"
Cursor="Hand"
Cursor="Hand"
Focusable="False"
Margin="10,-3,-10,0"
Margin="0,-3,-10,0"
MouseEnter="exportMenu_MouseEnter"
MouseLeave="exportMenu_MouseLeave">
MouseLeave="exportMenu_MouseLeave">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<Image x:Name="Icon"
Expand Down Expand Up @@ -262,7 +262,7 @@
</MenuItem>
</MenuItem>
<MenuItem Name="NotificationCenter"
Margin="-16 0 -30 0">
Margin="-15 0 -30 0">
<MenuItem.Header>
<Button x:Name="notificationsButton"
BorderBrush="Transparent"
Expand Down
117 changes: 2 additions & 115 deletions src/DynamoCoreWpf/Controls/ShortcutToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Greg.AuthProviders;
using System.Linq;
using System.Windows;
using System.Collections.Generic;

namespace Dynamo.UI.Controls
{
Expand Down Expand Up @@ -46,9 +45,9 @@ public ObservableCollection<ShortcutBarItem> ShortcutBarRightSideItems
public ShortcutToolbar(DynamoViewModel dynamoViewModel)
{
shortcutBarItems = new ObservableCollection<ShortcutBarItem>();
shortcutBarRightSideItems = new ObservableCollection<ShortcutBarItem>();
shortcutBarRightSideItems = new ObservableCollection<ShortcutBarItem>();

InitializeComponent();
InitializeComponent();

var shortcutToolbar = new ShortcutToolbarViewModel(dynamoViewModel);
DataContext = shortcutToolbar;
Expand All @@ -60,14 +59,6 @@ public ShortcutToolbar(DynamoViewModel dynamoViewModel)
else {
logoutOption.Visibility = Visibility.Collapsed;
}

this.Loaded += ShortcutToolbar_Loaded;
}

private void ShortcutToolbar_Loaded(object sender, RoutedEventArgs e)
{
IsSaveButtonEnabled = false;
IsExportMenuEnabled = false;
}

private void SignOutHandler(LoginState status)
Expand Down Expand Up @@ -116,110 +107,6 @@ private void LoginButton_OnClick(object sender, RoutedEventArgs e)
}
}
}

public List<Control> AllChildren(DependencyObject parent)
{
var _list = new List<Control> { };
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
{
var _child = VisualTreeHelper.GetChild(parent, i);
if (_child is Control)
{
_list.Add(_child as Control);
_list.AddRange(AllChildren(_child));
}
}
return _list;
}

private Button GetButton(string buttonKey)
{
if (this.shortcutBarItems.Count > 1)
{
try
{
int buttonIndex = ShortcutBarItems.ToList().FindIndex(item => item.ShortcutToolTip.ToUpper().Contains(buttonKey));
var _container = ShortcutItemsControl.ItemContainerGenerator.ContainerFromIndex(buttonIndex);
var _children = AllChildren(_container);
var _control = (Button)_children.First();
return _control;
}
catch (System.Exception)
{
return null;
}
}
else
{
return null;
}
}

internal bool IsNewButtonEnabled
{
set
{
Button saveButton = GetButton("NEW");
if (saveButton != null)
{
saveButton.IsEnabled = value;
saveButton.Opacity = value ? 1 : 0.5;
}
}
}

internal bool IsOpenButtonEnabled
{
set
{
Button saveButton = GetButton("OPEN");
if (saveButton != null)
{
saveButton.IsEnabled = value;
saveButton.Opacity = value ? 1 : 0.5;
}
}
}

internal bool IsSaveButtonEnabled
{
set
{
Button saveButton = GetButton("SAVE");
if (saveButton != null)
{
saveButton.IsEnabled = value;
saveButton.Opacity = value ? 1 : 0.5;
}
}
}

internal bool IsLoginMenuEnabled
{
set
{
this.loginMenu.IsEnabled = value;
this.loginMenu.Opacity = value ? 1 : 0.5;
}
}

internal bool IsExportMenuEnabled
{
set
{
this.exportMenu.IsEnabled = value;
this.exportMenu.Opacity = value ? 1 : 0.5;
}
}

internal bool IsNotificationCenterEnabled
{
set
{
this.NotificationCenter.IsEnabled = value;
this.NotificationCenter.Opacity = value ? 1 : 0.5;
}
}
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/DynamoCoreWpf/UI/GuidedTour/GuidesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ internal Guide GetNextGuide()

private void Popup_StepClosed(string name, Step.StepTypes stepType)
{
dynamoViewModel.OnEnableShortcutBarItems(true);
GuideFlowEvents.OnGuidedTourFinish(currentGuide.Name);

//The exit tour popup will be shown only when a popup (doesn't apply for survey) is closed or when the tour is closed.
Expand Down
1 change: 0 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2545,7 +2545,6 @@ private void CloseHomeWorkspace(object parameter)
// workspaces opened at the time, then we should show the start page.
this.ShowStartPage = (Model.Workspaces.Count() <= 1);
RunSettings.ForceBlockRun = false;
OnEnableShortcutBarItems(false);
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModelEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,6 @@ internal void OnRequestReturnFocusToView()
RequestReturnFocusToView();
}

public event Action<bool> RequestEnableShortcutBarItems;
public virtual void OnEnableShortcutBarItems(bool enable)
{
if (RequestEnableShortcutBarItems != null)
RequestEnableShortcutBarItems(enable);
}

/// <summary>
/// Event used to verify that the correct dialog is being showed when saving a graph with unresolved linter issues.
/// This is only meant to be used for unit testing purposes.
Expand Down
9 changes: 3 additions & 6 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,12 @@
<MenuItem Header="{x:Static p:Resources.DynamoViewFileMenuSave}"
Command="{Binding ShowSaveDialogIfNeededAndSaveResultCommand}"
Name="saveThisButton"
InputGestureText="Ctrl + S"
IsEnabled="False">
InputGestureText="Ctrl + S">
</MenuItem>
<MenuItem Header="{x:Static p:Resources.DynamoViewFileMenuSaveAs}"
Command="{Binding ShowSaveDialogAndSaveResultCommand}"
Name="saveButton"
InputGestureText="Ctrl + Shift + S"
IsEnabled="False">
InputGestureText="Ctrl + Shift + S">
</MenuItem>
<Separator />
<MenuItem Header="{x:Static p:Resources.DynamoViewFileMenuImport}"
Expand All @@ -379,8 +377,7 @@
<Separator />
<MenuItem Header="{x:Static p:Resources.DynamoViewFileMenuExport}"
Name="exportMenu"
Tag="NoDownArrow"
IsEnabled="False">
Tag="NoDownArrow">
<MenuItem Header="{x:Static p:Resources.DynamoViewFileMenuExportAsImage}"
Command="{Binding ShowSaveImageDialogAndSaveResultCommand}"
Name="saveImage">
Expand Down
45 changes: 6 additions & 39 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ public DynamoView(DynamoViewModel dynamoViewModel)
this.dynamoViewModel.RequestReturnFocusToView += OnRequestReturnFocusToView;
this.dynamoViewModel.Model.WorkspaceSaving += OnWorkspaceSaving;
this.dynamoViewModel.Model.WorkspaceOpened += OnWorkspaceOpened;
this.dynamoViewModel.RequestEnableShortcutBarItems += DynamoViewModel_RequestEnableShortcutBarItems;
FocusableGrid.InputBindings.Clear();

if (fileTrustWarningPopup == null)
Expand All @@ -247,44 +246,15 @@ public DynamoView(DynamoViewModel dynamoViewModel)
}
}

private void DynamoViewModel_RequestEnableShortcutBarItems(bool enable)
{
saveThisButton.IsEnabled = enable;
saveButton.IsEnabled = enable;
exportMenu.IsEnabled = enable;

shortcutBar.IsNewButtonEnabled = enable;
shortcutBar.IsOpenButtonEnabled = enable;
shortcutBar.IsSaveButtonEnabled = enable;
shortcutBar.IsLoginMenuEnabled = enable;
shortcutBar.IsExportMenuEnabled = enable;
shortcutBar.IsNotificationCenterEnabled = enable;

if(dynamoViewModel.ShowStartPage)
{
shortcutBar.IsNewButtonEnabled = true;
shortcutBar.IsOpenButtonEnabled = true;
shortcutBar.IsLoginMenuEnabled = true;
shortcutBar.IsNotificationCenterEnabled = true;
}
}

private void OnWorkspaceOpened(WorkspaceModel workspace)
{
saveThisButton.IsEnabled = true;
saveButton.IsEnabled = true;
exportMenu.IsEnabled = true;

ShortcutBar.IsSaveButtonEnabled = true;
shortcutBar.IsExportMenuEnabled = true;

if (!(workspace is HomeWorkspaceModel hws))
return;
return;

foreach (var extension in viewExtensionManager.StorageAccessViewExtensions)
{
DynamoModel.RaiseIExtensionStorageAccessWorkspaceOpened(hws, extension, dynamoViewModel.Model.Logger);
}
}
}

private void OnWorkspaceSaving(WorkspaceModel workspace, Graph.SaveContext saveContext)
Expand Down Expand Up @@ -894,7 +864,7 @@ private void InitializeShortcutBar()
shortcutBar.ShortcutBarItems.Add(saveButton);
shortcutBar.ShortcutBarItems.Add(undoButton);
shortcutBar.ShortcutBarItems.Add(redoButton);

shortcutBarGrid.Children.Add(shortcutBar);
}

Expand Down Expand Up @@ -1088,7 +1058,7 @@ private void DynamoView_Loaded(object sender, EventArgs e)
else
{
DynamoUtilities.DynamoFeatureFlagsManager.FlagsRetrieved += CheckTestFlags;
}
}
}

private void GuideFlowEvents_GuidedTourStart(GuidedTourStateEventArgs args)
Expand Down Expand Up @@ -1687,8 +1657,6 @@ private void WindowClosed(object sender, EventArgs e)
this.dynamoViewModel.Model.WorkspaceOpened -= OnWorkspaceOpened;
DynamoUtilities.DynamoFeatureFlagsManager.FlagsRetrieved -= CheckTestFlags;

this.dynamoViewModel.RequestEnableShortcutBarItems -= DynamoViewModel_RequestEnableShortcutBarItems;

this.Dispose();
sharedViewExtensionLoadedParams?.Dispose();
}
Expand Down Expand Up @@ -2503,9 +2471,8 @@ private void ShowGetStartedGuidedTour()
{
//We pass the root UIElement to the GuidesManager so we can found other child UIElements
try
{
{
dynamoViewModel.MainGuideManager.LaunchTour(GuidesManager.GetStartedGuideName);
dynamoViewModel.OnEnableShortcutBarItems(false);
}
catch (Exception)
{
Expand Down

0 comments on commit afd1d63

Please sign in to comment.