Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dyn 5404 disable menu items #13786

Merged
merged 7 commits into from
Mar 3, 2023
Merged
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
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,-15,0">
<MenuItem Name="loginMenu" Margin="0,-3,-10,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="0,-3,-10,0"
Margin="10,-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="-15 0 -30 0">
Margin="-16 0 -30 0">
<MenuItem.Header>
<Button x:Name="notificationsButton"
BorderBrush="Transparent"
Expand Down
122 changes: 120 additions & 2 deletions src/DynamoCoreWpf/Controls/ShortcutToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Greg.AuthProviders;
using System.Linq;
using System.Windows;
using System.Collections.Generic;

namespace Dynamo.UI.Controls
{
Expand Down Expand Up @@ -45,9 +46,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 @@ -59,6 +60,14 @@ 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;
Copy link
Contributor

@QilongTang QilongTang Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the initial state of these controls is already disabled from xaml, why disable these again on view loaded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you are referring to the MenuItems, yes they are disabled in the xaml side, the above code is for the Toolbar buttons

}

private void SignOutHandler(LoginState status)
Expand Down Expand Up @@ -107,6 +116,110 @@ 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 shortcutName)
{
if (this.shortcutBarItems.Count > 1)
{
try
{
int buttonIndex = ShortcutBarItems.ToList().FindIndex(item => item.Name.ToUpper() == shortcutName);
var _container = ShortcutItemsControl.ItemContainerGenerator.ContainerFromIndex(buttonIndex);
var _children = AllChildren(_container);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to retrieve the button in this complex way? Can we grab it by name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually We don't have access to the new, open and save buttons by name since they are dynamically created

Copy link
Contributor

@QilongTang QilongTang Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Their class ShortcutBarItem is our own class, we can modify the class to add properties for searching.. When we create them, we just need to add name as well..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my point is that lets not rely on the tooltip to search for controls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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 Expand Up @@ -149,6 +262,11 @@ public virtual string ShortcutToolTip
get { return shortcutToolTip; }
set { shortcutToolTip = value; }
}

/// <summary>
/// The Name of the shortcut
/// </summary>
public string Name { get; set; }
}

internal partial class ImageExportShortcutBarItem : ShortcutBarItem
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCoreWpf/UI/GuidedTour/GuidesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ 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
3 changes: 3 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,7 @@ private void ShowNewFunctionDialogAndMakeFunction(object parameter)
this.ShowStartPage = false;

SetDefaultScaleFactor(Workspaces.FirstOrDefault(viewModels => viewModels.Model is CustomNodeWorkspaceModel));
OnEnableShortcutBarItems(true);
}
}

Expand Down Expand Up @@ -2527,6 +2528,7 @@ public void MakeNewHomeWorkspace(object parameter)
ShowStartPage = false; // Hide start page if there's one.

SetDefaultScaleFactor(Workspaces.FirstOrDefault());
OnEnableShortcutBarItems(true);
}
}

Expand All @@ -2540,6 +2542,7 @@ 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: 7 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModelEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ 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: 6 additions & 3 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,14 @@
<MenuItem Header="{x:Static p:Resources.DynamoViewFileMenuSave}"
Command="{Binding ShowSaveDialogIfNeededAndSaveResultCommand}"
Name="saveThisButton"
InputGestureText="Ctrl + S">
InputGestureText="Ctrl + S"
IsEnabled="False">
</MenuItem>
<MenuItem Header="{x:Static p:Resources.DynamoViewFileMenuSaveAs}"
Command="{Binding ShowSaveDialogAndSaveResultCommand}"
Name="saveButton"
InputGestureText="Ctrl + Shift + S">
InputGestureText="Ctrl + Shift + S"
IsEnabled="False">
</MenuItem>
<Separator />
<MenuItem Header="{x:Static p:Resources.DynamoViewFileMenuImport}"
Expand All @@ -377,7 +379,8 @@
<Separator />
<MenuItem Header="{x:Static p:Resources.DynamoViewFileMenuExport}"
Name="exportMenu"
Tag="NoDownArrow">
Tag="NoDownArrow"
IsEnabled="False">
<MenuItem Header="{x:Static p:Resources.DynamoViewFileMenuExportAsImage}"
Command="{Binding ShowSaveImageDialogAndSaveResultCommand}"
Name="saveImage">
Expand Down
Loading