Skip to content

Commit

Permalink
starting to work
Browse files Browse the repository at this point in the history
  • Loading branch information
superlloyd committed Jan 3, 2015
1 parent 6acbb78 commit 59c9abb
Show file tree
Hide file tree
Showing 14 changed files with 265 additions and 187 deletions.
8 changes: 0 additions & 8 deletions MenuRibbon/CommandTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ public static bool CanExecuteCommand(ICommand command, object parameter, IInputE
return command.CanExecute(parameter);
}

public static void HandleCommandChanged(this EventHandler<EventArgs> canExecuteChanged, ICommand oldCommand, ICommand newCommand)
{
if (oldCommand != null)
CanExecuteChangedEventManager.RemoveHandler(oldCommand, canExecuteChanged);
if (newCommand != null)
CanExecuteChangedEventManager.AddHandler(newCommand, canExecuteChanged);
}

public static bool ExecuteCommand(this ICommandSource commandSource)
{
ICommand command = commandSource.Command;
Expand Down
8 changes: 6 additions & 2 deletions MenuRibbon/Controls/ActionHeaderedItemsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ void OnCommandChanged(ICommand OldValue, ICommand NewValue)
{
if (onCommandUpdated == null)
onCommandUpdated = (o, e) => UpdateFromCommand();
onCommandUpdated.HandleCommandChanged(OldValue, NewValue);
UpdateFromCommand();

if (OldValue != null)
CanExecuteChangedEventManager.RemoveHandler(OldValue, onCommandUpdated);
if (NewValue != null)
CanExecuteChangedEventManager.AddHandler(NewValue, onCommandUpdated);
onCommandUpdated(null, null);
}
EventHandler<EventArgs> onCommandUpdated;

Expand Down
8 changes: 4 additions & 4 deletions MenuRibbon/Controls/ItemsButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ protected override void OnKeyTipAccessed(KeyTipAccessedEventArgs e)

if (IsSplitButton || HasItems)
{
PopupManager.OpenedItem = this;
((IPopupItem)this).PopupChildren().SelectableItem().FirstOrDefault().NavigateItem();
this.OnNavigateChildren();
e.TargetKeyTipScope = this;
}
else
{
OnClick();
}

e.Handled = true;
if (IsOpen && KeyTipService.GetIsKeyTipScope(this))
if (!IsOpen)
{
e.TargetKeyTipScope = this;
this.CloseAllPopups();
}
}

Expand Down
26 changes: 18 additions & 8 deletions MenuRibbon/Controls/KeyTipService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

namespace MenuRibbon.WPF.Controls
{
/// <summary>
/// Handler for event fired when KeyTip mode starts or end.
/// </summary>
public delegate void KeyTipFocusEventHandler(object sender, EventArgs e);

public class KeyTipService
{
#region ctor(), Current
Expand Down Expand Up @@ -168,16 +173,19 @@ Window CurrentWindow
mCurrentWindow.LocationChanged -= eh;
mCurrentWindow.SizeChanged -= sh;
}
mCurrentPresentationSource = null;
mCurrentWindow = value;
if (mCurrentWindow != null)
{
mCurrentPresentationSource = PresentationSource.FromVisual(mCurrentWindow);
mCurrentWindow.Deactivated += eh;
mCurrentWindow.LocationChanged += eh;
mCurrentWindow.SizeChanged += sh;
}
}
}
Window mCurrentWindow;
PresentationSource mCurrentPresentationSource;

#endregion

Expand All @@ -194,7 +202,7 @@ private bool EnterKeyTipMode(DependencyObject scope, bool showAsync)

globalScope = scope;
State = KeyTipState.Pending;
InputManager.Current.PushMenuMode(PresentationSource.FromVisual(CurrentWindow));
InputManager.Current.PushMenuMode(mCurrentPresentationSource);

if (showAsync)
{
Expand Down Expand Up @@ -226,6 +234,9 @@ private void ShowKeyTips()
if (State == KeyTipState.Pending)
{
Debug.Assert(globalScope != null);

PopupManager.CloseAll();

if (PushKeyTipsScope(globalScope))
{
State = KeyTipState.Enabled;
Expand Down Expand Up @@ -326,9 +337,9 @@ private void LeaveKeyTipMode(bool restoreFocus = true)
{
RaiseKeyTipExitRestoreFocus();
}
InputManager.Current.PopMenuMode(PresentationSource.FromVisual(CurrentWindow));


InputManager.Current.PopMenuMode(mCurrentPresentationSource);
CurrentWindow = null;
State = KeyTipState.None;

Expand Down Expand Up @@ -425,6 +436,7 @@ private void OnKeyTipExactMatch(DependencyObject exactMatchElement)
if (!((bool)(exactMatchElement.GetValue(UIElement.IsEnabledProperty))))
{
Menu.MenuRibbon.Beep();
_prefixText = string.Empty;
return;
}

Expand Down Expand Up @@ -702,13 +714,11 @@ public static void RemoveKeyTipAccessedHandler(DependencyObject element, KeyTipA

#region Focus Events

internal delegate bool KeyTipFocusEventHandler(object sender, EventArgs e);

/// <summary>
/// Event used to notify ribbon to obtain focus
/// while entering KeyTip mode.
/// </summary>
internal event KeyTipFocusEventHandler KeyTipEnterFocus
public event KeyTipFocusEventHandler KeyTipEnterFocus
{
add { elKeyTipEnterFocus.Add(value); }
remove { elKeyTipEnterFocus.Remove(value); }
Expand All @@ -727,7 +737,7 @@ void RaiseKeyTipEnterFocus()
/// Event used to notify ribbon to restore focus
/// while exiting KeyTip mode.
/// </summary>
internal event KeyTipFocusEventHandler KeyTipExitRestoreFocus
public event KeyTipFocusEventHandler KeyTipExitRestoreFocus
{
add { elKeyTipExitRestoreFocus.Add(value); }
remove { elKeyTipExitRestoreFocus.Remove(value); }
Expand Down
52 changes: 36 additions & 16 deletions MenuRibbon/Controls/Menu/MenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,40 +98,60 @@ public override void OnApplyTemplate()
}
DisposableBag events = new DisposableBag();

protected override void OnClick(RoutedEventArgs e)
protected void OnMainUI_LeftMouseDown(MouseButtonEventArgs e)
{
switch (Role)
{
case MenuItemRole.TopLevelHeader:
Focus();
if (PopupRoot != null)
PopupRoot.PopupManager.Enter(this, true);
break;
case MenuItemRole.TopLevelItem:
case MenuItemRole.SubmenuItem:
base.OnClick(e);
break;
case MenuItemRole.TopLevelHeader:
Focus();
goto case MenuItemRole.SubmenuHeader;
case MenuItemRole.SubmenuHeader:
PopupRoot.PopupManager.HighlightedItem = this;
default:
PopupRoot.PopupManager.OpenedItem = this;
break;
}
}

protected void OnMainUI_LeftMouseDown(MouseButtonEventArgs e)
protected override void OnClick(RoutedEventArgs e)
{
switch (Role)
{
case MenuItemRole.TopLevelHeader:
Focus();
if (PopupRoot != null)
PopupRoot.PopupManager.Enter(this, true);
break;
case MenuItemRole.TopLevelItem:
case MenuItemRole.SubmenuItem:
base.OnClick(e);
if (PopupRoot != null)
PopupRoot.PopupManager.Tracking = false;
break;
case MenuItemRole.SubmenuHeader:
default:
PopupRoot.PopupManager.OpenedItem = this;
break;
}
}
#endregion

#region OnActivatingKeyTip(), OnKeyTipAccessed()

protected override void OnKeyTipAccessed(KeyTipAccessedEventArgs e)
{
if (e.OriginalSource != this)
return;

if (HasItems)
{
this.OnNavigateChildren();
e.TargetKeyTipScope = this;
}
else
{
OnClick();
}

e.Handled = true;
if (!IsOpen)
{
this.CloseAllPopups();
}
}

Expand Down
61 changes: 59 additions & 2 deletions MenuRibbon/Controls/Menu/MenuRibbon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,47 @@ internal static void Beep()

public MenuRibbon()
{
FocusOnEnterKeyTip = true;
}


#region FocusOnEnterKeyTip

public bool FocusOnEnterKeyTip
{
get { return (bool)GetValue(FocusOnEnterKeyTipProperty); }
set { SetValue(FocusOnEnterKeyTipProperty, BooleanBoxes.Box(value)); }
}

// Using a DependencyProperty as the backing store for FocusOnEnterKeyTip. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FocusOnEnterKeyTipProperty =
DependencyProperty.Register("FocusOnEnterKeyTip", typeof(bool), typeof(MenuRibbon)
, new PropertyMetadata(BooleanBoxes.FalseBox, OnFocusOnEnterKeyTipChanged));

private static void OnFocusOnEnterKeyTipChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var t = (MenuRibbon)d;
if (t.keyTipFocuHandler == null)
t.keyTipFocuHandler = (o, ev) =>
{
if (t.Items.Count == 0)
return;
var p = (IPopupItem)t.ItemContainerGenerator.ContainerFromItem(t.Items[0]);
Keyboard.Focus(p.FirstFocusableElement());
};
if ((bool)e.NewValue)
{
KeyTipService.Current.KeyTipEnterFocus += t.keyTipFocuHandler;
}
else
{
KeyTipService.Current.KeyTipEnterFocus -= t.keyTipFocuHandler;
}
}
KeyTipFocusEventHandler keyTipFocuHandler;

#endregion

#region RibbonHeight

public double RibbonHeight
Expand Down Expand Up @@ -184,21 +223,39 @@ public RibbonItem DroppedRibbonItem
}

static readonly DependencyPropertyKey DroppedRibbonItemPropertyKey = DependencyProperty.RegisterReadOnly(
"DroppedRibbonItem", typeof(RibbonItem), typeof(MenuRibbon), new PropertyMetadata(null));
"DroppedRibbonItem", typeof(RibbonItem), typeof(MenuRibbon)
, new PropertyMetadata(null, (o, e) => ((MenuRibbon)o).OnDroppedRibbonItemChanged((RibbonItem)e.OldValue, (RibbonItem)e.NewValue)));

public static readonly DependencyProperty DroppedRibbonItemProperty = DroppedRibbonItemPropertyKey.DependencyProperty;

private void OnDroppedRibbonItemChanged(RibbonItem OldValue, RibbonItem NewValue)
{
if (OldValue != null)
OldValue.RibbonDisplay = RibbonDisplay.None;
if (NewValue != null)
NewValue.RibbonDisplay = RibbonDisplay.Drop;
}

public RibbonItem PinnedRibbonItem
{
get { return (RibbonItem)GetValue(PinnedRibbonItemProperty); }
private set { SetValue(PinnedRibbonItemPropertyKey, value); }
}

static readonly DependencyPropertyKey PinnedRibbonItemPropertyKey = DependencyProperty.RegisterReadOnly(
"PinnedRibbonItem", typeof(RibbonItem), typeof(MenuRibbon), new PropertyMetadata(null));
"PinnedRibbonItem", typeof(RibbonItem), typeof(MenuRibbon),
new PropertyMetadata(null, (o,e) => ((MenuRibbon)o).OnPinnedRibbonItemChanged((RibbonItem)e.OldValue, (RibbonItem)e.NewValue)));

public static readonly DependencyProperty PinnedRibbonItemProperty = PinnedRibbonItemPropertyKey.DependencyProperty;

private void OnPinnedRibbonItemChanged(RibbonItem OldValue, RibbonItem NewValue)
{
if (OldValue != null)
OldValue.RibbonDisplay = RibbonDisplay.None;
if (NewValue != null)
NewValue.RibbonDisplay = RibbonDisplay.Pin;
}

void UpdateRibbonAppearance()
{
RibbonItem h = DroppedRibbonItem;
Expand Down
Loading

0 comments on commit 59c9abb

Please sign in to comment.