/// <summary>
        /// Handles the assignment of shortcut keys
        /// </summary>
        /// <param name="menuItem">The menu item.</param>
        /// <param name="action">The category.</param>
        protected virtual void HandleMenuShortcutKey(MenuItem menuItem, IViewAction action)
        {
            if (action.ShortcutKey == Key.None)
            {
                return;
            }

            _menuKeyBindings.Clear();
            var text = action.ShortcutKey.ToString().ToUpper();

            switch (action.ShortcutModifiers)
            {
            case ModifierKeys.Alt:
                text = "ALT+" + text;
                break;

            case ModifierKeys.Control:
                text = "CTRL+" + text;
                break;

            case ModifierKeys.Shift:
                text = "SHIFT+" + text;
                break;

            case ModifierKeys.Windows:
                text = "Windows+" + text;
                break;
            }

            menuItem.InputGestureText = text;

            _menuKeyBindings.Add(new ViewActionMenuKeyBinding(action));
        }
        /// <summary>
        /// Determines the display title of a menu item
        /// </summary>
        /// <param name="action">The category.</param>
        /// <returns>Title</returns>
        protected virtual string GetMenuTitle(IViewAction action)
        {
            var sb              = new StringBuilder();
            var titleChars      = action.Caption.ToCharArray();
            var titleCharsLower = action.Caption.ToLower().ToCharArray();
            var foundAccessKey  = false;
            var lowerKey        = action.AccessKey.ToString(CultureInfo.CurrentUICulture).ToLower().ToCharArray()[0];

            for (var counter = 0; counter < titleChars.Length; counter++)
            {
                var character      = titleChars[counter];
                var characterLower = titleCharsLower[counter];
                if (action.AccessKey != ' ' && !foundAccessKey && characterLower == lowerKey)
                {
                    sb.Append("_"); // This is the hotkey indicator in WPF
                    foundAccessKey = true;
                }
                if (character == '_')
                {
                    sb.Append("_"); // Escaping the underscore so it really shows up in the menu rather than being interpreted special
                }
                sb.Append(character);
            }

            if (!foundAccessKey && action.AccessKey != ' ')
            {
                sb.Append(" (_");
                sb.Append(action.AccessKey);
                sb.Append(")");
            }
            return(sb.ToString());
        }
Esempio n. 3
0
        private static void CreateMenuItemBinding(IViewAction action, MenuItem menuItem)
        {
            menuItem.SetBinding(VisibilityProperty, new Binding("Availability")
            {
                Source = action, Converter = new AvailabilityToVisibleConverter()
            });

            // If this is a real ViewAction, we can listen to changed events on the availability property, which can lead us to changing the visibility on the parent menu
            var viewAction = action as ViewAction;

            if (viewAction != null)
            {
                viewAction.PropertyChanged += (s, e) =>
                {
                    if (!string.IsNullOrEmpty(e.PropertyName) && e.PropertyName != "Availability")
                    {
                        return;
                    }
                    if (menuItem.Parent == null)
                    {
                        return;
                    }
                    var parentMenu = menuItem.Parent as MenuItem;
                    if (parentMenu != null)
                    {
                        parentMenu.SetBinding(VisibilityProperty, new Binding("Count")
                        {
                            Source = parentMenu.Items, Converter = new ItemsCollectionCountToVisibleConverter(parentMenu.Items)
                        });
                    }
                }
            }
            ;
        }
 private void LoadActions()
 {
     SearchAction        = new ViewAction(caption: "Filter", execute: (action, o) => Controller.Notification("Filter happens here"));
     ClearFilterAction   = new ViewAction(caption: "Clear Filter", execute: (action, o) => Controller.Notification("Clear Filter"));
     AddSideToCartAction = new ViewAction(caption: "Add Side to Cart", execute: (action, o) => Controller.Notification("Side added to cart."));
     SetParentActions();
 }
 private void ExecuteCommand(IViewAction a, object s)
 {
     if (Application.Current is ApplicationEx appEx)
     {
         appEx.Theme = _theme;
     }
 }
Esempio n. 6
0
        private void ExecuteCommand(IViewAction a, object s)
        {
            var appEx = Application.Current as ApplicationEx;

            if (appEx != null)
            {
                appEx.Theme = _theme;
            }
        }
        private void Login(IViewAction action, object parameter)
        {
            // TODO: Perform actual user login here

            AppDomain.CurrentDomain.SetThreadPrincipal(new CODEFrameworkPrincipal(new CODEFrameworkUser(UserName)));

            Controller.CloseViewForModel(this);

            StartViewModel.Current.LoadActions();
        }
        private void Login(IViewAction action, object parameter)
        {
            // TODO: Perform actual user login here

            AppDomain.CurrentDomain.SetThreadPrincipal(new CODEFrameworkPrincipal(new CODEFrameworkUser(UserName)));

            Controller.CloseViewForModel(this);

            StartViewModel.Current.LoadActions();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="originalAction"></param>
        public WildcatActionWrapper(IViewAction originalAction)
        {
            _originalAction = originalAction;
            Position = WildcatButtonPosition.Middle;

            originalAction.CanExecuteChanged += (s, e) =>
            {
                if (CanExecuteChanged != null)
                    CanExecuteChanged(s, e);
            };
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="originalAction"></param>
        public WildcatActionWrapper(IViewAction originalAction)
        {
            _originalAction = originalAction;
            Position        = WildcatButtonPosition.Middle;

            originalAction.CanExecuteChanged += (s, e) =>
            {
                if (CanExecuteChanged != null)
                {
                    CanExecuteChanged(s, e);
                }
            };
        }
Esempio n. 11
0
        private void Login(IViewAction action, object parameter)
        {
            // Perform actual user login here

            _loginTriggered = true;
            AppDomain.CurrentDomain.SetThreadPrincipal(new CODEFrameworkPrincipal(new CODEFrameworkUser(UserName)));

            Controller.CloseViewForModel(this);

            StartViewModel.Current.LoadActions();

            //Controller.Action("Home", "Dashboard", new {user = UserName});
        }
 private void ExecuteCommand(IViewAction a, object s)
 {
     if (_model.AssociatedView != null)
     {
         if (_model.AssociatedView is FrameworkElement element)
         {
             var element2 = element.FindName(_targetElementName);
             if (element2 != null)
             {
                 if (element2 is FrameworkElement element3)
                 {
                     element3.Focus();
                 }
             }
         }
     }
 }
Esempio n. 13
0
 private void ExecuteCommand(IViewAction a, object s)
 {
     if (_model.AssociatedView != null)
     {
         var element = _model.AssociatedView as FrameworkElement;
         if (element != null)
         {
             var element2 = element.FindName(_targetElementName);
             if (element2 != null)
             {
                 var element3 = element2 as FrameworkElement;
                 if (element3 != null)
                     element3.Focus();
             }
         }
     }
 }
Esempio n. 14
0
        public void RegisterRightAction(IViewAction viewAction)
        {
            if (_rightButton != null) {
                _mainMenu.MenuItems.Remove(_rightButton);
                _rightButton.Dispose();
            }
            _rightButton = new MenuItem {
                Text = _localizationManager.Localization.GetLocalizedValue(viewAction.Caption)
            };
            if (!(viewAction is StubAction)) {
                _rightButton.Click += viewAction.Do;
            }
            else {
                _rightButton.Enabled = false;
            }

            _mainMenu.MenuItems.Add(_rightButton);
        }
Esempio n. 15
0
 /// <summary>
 /// This method is designed to be overridden in subclasses. It can be use to indicate
 /// whether a certain action should be included in the display, or not.
 /// </summary>
 /// <param name="action">The action.</param>
 /// <returns><c>true</c> if the action is to be included, <c>false</c> otherwise.</returns>
 protected virtual bool IncludeAction(IViewAction action)
 {
     return(true);
 }
Esempio n. 16
0
 /// <summary>
 /// Creates the menu item binding.
 /// </summary>
 /// <param name="action">The action.</param>
 /// <param name="ribbonButton">The ribbon button.</param>
 private void CreateMenuItemBinding(IViewAction action, FrameworkElement ribbonButton)
 {
     var binding = new MultiBinding {Converter = new MinimumVisibilityMultiConverter()};
     binding.Bindings.Add(new Binding("Availability") {Source = action, Converter = new AvailabilityToVisibleConverter()});
     binding.Bindings.Add(new Binding("Visibility") {Source = action});
     ribbonButton.SetBinding(VisibilityProperty, binding);
 }
Esempio n. 17
0
 /// <summary>
 /// Handles the assignment of shortcut keys
 /// </summary>
 /// <param name="button">The button.</param>
 /// <param name="action">The category.</param>
 /// <param name="ribbonPage">The ribbon page.</param>
 protected virtual void HandleRibbonShortcutKey(RibbonButton button, IViewAction action, RibbonPage ribbonPage)
 {
     if (action.ShortcutKey == Key.None) return;
     MenuKeyBindings.Add(new ViewActionMenuKeyBinding(action));
 }
Esempio n. 18
0
 /// <summary>
 /// Creates the menu item binding.
 /// </summary>
 /// <param name="action">The action.</param>
 /// <param name="ribbonButton">The ribbon button.</param>
 private static void CreateMenuItemBinding(IViewAction action, FrameworkElement ribbonButton)
 {
     ribbonButton.SetBinding(VisibilityProperty, new Binding("Availability") {Source = action, Converter = new AvailabilityToVisibleConverter()});
 }
Esempio n. 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewActionToolbarButton" /> class.
        /// </summary>
        /// <param name="action">The action associated with this toolbar button.</param>
        public ViewActionToolbarButton(IViewAction action)
        {
            Action = action;

            var viewAction = Action as ViewAction;
            if (viewAction != null)
            {
                ToolTip = viewAction.ToolTipText;
                HasIcon = viewAction.HasBrush;
                if (!HasIcon) Title = action.Caption;
                else
                {
                    switch (TitleDisplayFilter)
                    {
                        case ViewActionDisplayMode.All:
                            Title = action.Caption;
                            break;
                        case ViewActionDisplayMode.AboveNormalSignificanceAndHigher:
                            if (action.Significance == ViewActionSignificance.AboveNormal || action.Significance == ViewActionSignificance.Highest)
                                Title = action.Caption;
                            break;
                        case ViewActionDisplayMode.HighestSignificance:
                            if (action.Significance == ViewActionSignificance.Highest)
                                Title = action.Caption;
                            break;
                        case ViewActionDisplayMode.NormalSignificanceAndHigher:
                            if (action.Significance == ViewActionSignificance.Normal || action.Significance == ViewActionSignificance.AboveNormal || action.Significance == ViewActionSignificance.Highest)
                                Title = action.Caption;
                            break;
                        case ViewActionDisplayMode.BelowNormalSignificanceAndHigher:
                            if (action.Significance == ViewActionSignificance.BelowNormal || action.Significance == ViewActionSignificance.Normal || action.Significance == ViewActionSignificance.AboveNormal || action.Significance == ViewActionSignificance.Highest)
                                Title = action.Caption;
                            break;
                    }
                }
            }
            else
                Title = action.Caption;

            HasTitle = !string.IsNullOrEmpty(Title);

            Command = action;

            SetBinding(VisibilityProperty, new Binding("Availability") { Source = Action, Converter = new AvailabilityToVisibleConverter() });
        }
Esempio n. 20
0
 private void ExecuteCommand(IViewAction a, object s)
 {
     Controller.CloseViewForModel(_model);
 }
Esempio n. 21
0
        private static void CreateMenuItemBinding(IViewAction action, MenuItem menuItem)
        {
            menuItem.SetBinding(VisibilityProperty, new Binding("Availability") { Source = action, Converter = new AvailabilityToVisibleConverter() });

            // If this is a real ViewAction, we can listen to changed events on the availability property, which can lead us to changing the visibility on the parent menu
            var viewAction = action as ViewAction;
            if (viewAction != null)
                viewAction.PropertyChanged += (s, e) =>
                                                  {
                                                      if (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "Availability")
                                                          // We force the system to re-evaluate the Visibility property on the parent item, just in case the change in availability triggered a visibility change of the entire parent item
                                                          if (menuItem.Parent != null)
                                                          {
                                                              var parentMenu = menuItem.Parent as MenuItem;
                                                              if (parentMenu != null)
                                                                  parentMenu.SetBinding(VisibilityProperty, new Binding("Count") {Source = parentMenu.Items, Converter = new ItemsCollectionCountToVisibleConverter(parentMenu.Items)});
                                                          }
                                                  };
        }
 private void LoadActions()
 {
     ReviewPizzasAction = new ViewAction("Pizza Selection", execute: (a, o) => ReviewPizzas());
     ReviewSidesAction = new ViewAction("Side Orders", execute: (a, o) => ReviewSides());
     Actions.Add(new CloseCurrentViewAction(this, beginGroup: true));
 }
Esempio n. 23
0
 private static void ExecuteCommand(IViewAction a, object s)
 {
     Application.Current.Shutdown();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="originalAction"></param>
 public WildcatActionWrapper(IViewAction originalAction)
 {
     _originalAction = originalAction;
     Position        = WildcatButtonPosition.Middle;
     originalAction.CanExecuteChanged += (s, e) => CanExecuteChanged?.Invoke(s, e);
 }
Esempio n. 25
0
 private static void ExecuteCommand(IViewAction a, object s)
 {
     Application.Current.Shutdown();
 }
Esempio n. 26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewActionToolbarButton" /> class.
        /// </summary>
        /// <param name="action">The action associated with this toolbar button.</param>
        public ViewActionToolbarButton(IViewAction action)
        {
            Action = action;

            var viewAction = Action as ViewAction;

            if (viewAction != null)
            {
                ToolTip = viewAction.ToolTipText;
                HasIcon = viewAction.HasBrush;
                if (!HasIcon)
                {
                    Title = action.Caption;
                }
                else

                {
                    switch (TitleDisplayFilter)
                    {
                    case ViewActionDisplayMode.All:
                        SetBinding(TitleProperty, new Binding("Caption")
                        {
                            Source = action
                        });
                        break;

                    case ViewActionDisplayMode.AboveNormalSignificanceAndHigher:
                        if (action.Significance == ViewActionSignificance.AboveNormal || action.Significance == ViewActionSignificance.Highest)
                        {
                            SetBinding(TitleProperty, new Binding("Caption")
                            {
                                Source = action
                            });
                        }
                        break;

                    case ViewActionDisplayMode.HighestSignificance:
                        if (action.Significance == ViewActionSignificance.Highest)
                        {
                            SetBinding(TitleProperty, new Binding("Caption")
                            {
                                Source = action
                            });
                        }
                        break;

                    case ViewActionDisplayMode.NormalSignificanceAndHigher:
                        if (action.Significance == ViewActionSignificance.Normal || action.Significance == ViewActionSignificance.AboveNormal || action.Significance == ViewActionSignificance.Highest)
                        {
                            SetBinding(TitleProperty, new Binding("Caption")
                            {
                                Source = action
                            });
                        }
                        break;

                    case ViewActionDisplayMode.BelowNormalSignificanceAndHigher:
                        if (action.Significance == ViewActionSignificance.BelowNormal || action.Significance == ViewActionSignificance.Normal || action.Significance == ViewActionSignificance.AboveNormal || action.Significance == ViewActionSignificance.Highest)
                        {
                            SetBinding(TitleProperty, new Binding("Caption")
                            {
                                Source = action
                            });
                        }
                        break;
                    }
                }
            }
            else
            {
                SetBinding(TitleProperty, new Binding("Caption")
                {
                    Source = action
                });
            }

            SetBinding(HasTitleProperty, new Binding("Title")
            {
                Source = this, Converter = new EmptyStringToBooleanConverter()
            });

            Command = action;

            SetBinding(VisibilityProperty, new Binding("Availability")
            {
                Source = Action, Converter = new AvailabilityToVisibleConverter()
            });
            SetBinding(IsCheckedProperty, new Binding("IsChecked")
            {
                Source = Action
            });
            SetBinding(SignificanceProperty, new Binding("Significance")
            {
                Source = Action
            });
        }
Esempio n. 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ViewActionMenuKeyBinding"/> class.
 /// </summary>
 /// <param name="action">The category.</param>
 public ViewActionMenuKeyBinding(IViewAction action)
 {
     Key = action.ShortcutKey;
     Modifiers = action.ShortcutModifiers;
     Command = action;
 }
        /// <summary>
        /// Detirmines the display title of a menu item
        /// </summary>
        /// <param name="action">The category.</param>
        /// <returns>Title</returns>
        protected virtual string GetMenuTitle(IViewAction action)
        {
            var sb = new StringBuilder();
            var titleChars = action.Caption.ToCharArray();
            var titleCharsLower = action.Caption.ToLower().ToCharArray();
            var foundAccessKey = false;
            var lowerKey = action.AccessKey.ToString(CultureInfo.CurrentUICulture).ToLower().ToCharArray()[0];
            for (var counter = 0; counter < titleChars.Length; counter++)
            {
                var character = titleChars[counter];
                var characterLower = titleCharsLower[counter];
                if (action.AccessKey != ' ' && !foundAccessKey && characterLower == lowerKey)
                {
                    sb.Append("_"); // This is the hotkey indicator in WPF
                    foundAccessKey = true;
                }
                if (character == '_')
                    sb.Append("_"); // Escaping the underscore so it really shows up in the menu rather than being interpreted special
                sb.Append(character);
            }

            if (!foundAccessKey && action.AccessKey != ' ')
            {
                sb.Append(" (_");
                sb.Append(action.AccessKey);
                sb.Append(")");
            }
            return sb.ToString();
        }
Esempio n. 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ViewActionMenuKeyBinding"/> class.
 /// </summary>
 /// <param name="action">The category.</param>
 public ViewActionMenuKeyBinding(IViewAction action)
 {
     Key       = action.ShortcutKey;
     Modifiers = action.ShortcutModifiers;
     Command   = action;
 }
Esempio n. 30
0
 private void ExecuteCommand(IViewAction a, object s)
 {
     Controller.CloseViewForModel(_model);
 }
        /// <summary>
        /// Handles the assignment of shortcut keys
        /// </summary>
        /// <param name="menuItem">The menu item.</param>
        /// <param name="action">The category.</param>
        protected virtual void HandleMenuShortcutKey(MenuItem menuItem, IViewAction action)
        {
            if (action.ShortcutKey == Key.None) return;

            _menuKeyBindings.Clear();
            var text = action.ShortcutKey.ToString().ToUpper();

            switch (action.ShortcutModifiers)
            {
                case ModifierKeys.Alt:
                    text = "ALT+" + text;
                    break;
                case ModifierKeys.Control:
                    text = "CTRL+" + text;
                    break;
                case ModifierKeys.Shift:
                    text = "SHIFT+" + text;
                    break;
                case ModifierKeys.Windows:
                    text = "Windows+" + text;
                    break;
            }

            menuItem.InputGestureText = text;

            _menuKeyBindings.Add(new ViewActionMenuKeyBinding(action));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ViewActionAndOpenViewItem"/> class.
 /// </summary>
 /// <param name="viewTabs">The view tabs control.</param>
 /// <param name="action">The action.</param>
 public ViewActionAndOpenViewItem(IViewAction action, TabControl viewTabs)
 {
     Action = action;
     CreateSubItemsCollection();
     ViewTabs = viewTabs;
 }
Esempio n. 33
0
 private void ExecuteCommand(IViewAction a, object s)
 {
     var appEx = Application.Current as ApplicationEx;
     if (appEx != null)
         appEx.Theme = _theme;
 }