-
Notifications
You must be signed in to change notification settings - Fork 635
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
Dyn 5404 disable menu items #13786
Changes from all commits
548550d
18d9fe5
8fb6531
5aeb4e8
036f849
ca149fc
648cc5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
using Greg.AuthProviders; | ||
using System.Linq; | ||
using System.Windows; | ||
using System.Collections.Generic; | ||
|
||
namespace Dynamo.UI.Controls | ||
{ | ||
|
@@ -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; | ||
|
@@ -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; | ||
} | ||
|
||
private void SignOutHandler(LoginState status) | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Their class There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
@@ -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 | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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