Merge pull request #340 from telerik/Nasko/radial-navigateback

Added NavigateBack command for the RadialMenu
This commit is contained in:
Atanas Popatanasov 2018-11-15 17:50:05 +02:00 коммит произвёл GitHub
Родитель de0aa56120 8c24ab30c9
Коммит 11faa7b2ad
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 49 добавлений и 34 удалений

Просмотреть файл

@ -108,6 +108,7 @@
<Compile Include="RadialMenu\Services\CommandService.cs" />
<Compile Include="RadialMenu\Services\Commands\CloseMenuCommand.cs" />
<Compile Include="RadialMenu\Services\Commands\CommandId.cs" />
<Compile Include="RadialMenu\Services\Commands\NavigateBackCommand.cs" />
<Compile Include="RadialMenu\Services\Commands\NavigateCommand.cs" />
<Compile Include="RadialMenu\Services\Commands\NavigateContext.cs" />
<Compile Include="RadialMenu\Services\Commands\OpenMenuCommand.cs" />

Просмотреть файл

@ -67,6 +67,7 @@ namespace Telerik.UI.Xaml.Controls.Primitives.Menu
this.defaultCommands[(int)CommandId.Open] = this.CreateKnownCommand(CommandId.Open);
this.defaultCommands[(int)CommandId.Close] = this.CreateKnownCommand(CommandId.Close);
this.defaultCommands[(int)CommandId.NavigateToView] = this.CreateKnownCommand(CommandId.NavigateToView);
this.defaultCommands[(int)CommandId.NavigateBack] = this.CreateKnownCommand(CommandId.NavigateBack);
}
private RadialMenuCommand CreateKnownCommand(CommandId id)
@ -84,6 +85,9 @@ namespace Telerik.UI.Xaml.Controls.Primitives.Menu
case CommandId.NavigateToView:
command = new NavigateCommand();
break;
case CommandId.NavigateBack:
command = new NavigateBackCommand();
break;
default:
throw new ArgumentException("Unknown command id!", "id");
}

Просмотреть файл

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Telerik.UI.Xaml.Controls.Primitives.Menu.Commands
namespace Telerik.UI.Xaml.Controls.Primitives.Menu.Commands
{
/// <summary>
/// Defines the known commands that are available within a <see cref="RadRadialMenu"/> control.
@ -30,5 +24,10 @@ namespace Telerik.UI.Xaml.Controls.Primitives.Menu.Commands
/// A command associated with the action of navigating to specific <see cref="RadialMenuItem"/>.
/// </summary>
NavigateToView,
/// <summary>
/// A command associated with the action of navigating back to the previous <see cref="RadialMenuItem"/>.
/// </summary>
NavigateBack
}
}
}

Просмотреть файл

@ -0,0 +1,36 @@
using System.Linq;
namespace Telerik.UI.Xaml.Controls.Primitives.Menu.Commands
{
internal class NavigateBackCommand : RadialMenuCommand
{
public override bool CanExecute(object parameter)
{
return this.Owner.model.viewState.MenuLevels.Count > 0;
}
public override void Execute(object parameter)
{
base.Execute(parameter);
var menuLevels = this.Owner.model.viewState.MenuLevels;
if (menuLevels.Count > 0)
{
var sourceItem = menuLevels.Pop();
var targetLevel = menuLevels.FirstOrDefault();
var startAngleLevels = this.Owner.model.viewState.StartAngleLevels;
startAngleLevels.RemoveAt(startAngleLevels.Count - 1);
var startAngle = startAngleLevels.LastOrDefault();
this.Owner.RaiseNavigateCommand(targetLevel, sourceItem, startAngle, true);
if (targetLevel == null)
{
this.Owner.menuButton.TransformToNormal();
}
}
}
}
}

Просмотреть файл

@ -505,31 +505,6 @@ namespace Telerik.UI.Xaml.Controls.Primitives
return calculatedPosition;
}
/// <summary>
/// Exposed for testing purposes.
/// </summary>
internal void HandleOnBackButtonPressed()
{
var menuLevels = this.model.viewState.MenuLevels;
if (menuLevels.Count > 0)
{
var sourceItem = menuLevels.Pop();
var targetLevel = menuLevels.FirstOrDefault();
var startAngleLevels = this.model.viewState.StartAngleLevels;
startAngleLevels.RemoveAt(startAngleLevels.Count - 1);
var startAngle = startAngleLevels.LastOrDefault();
this.RaiseNavigateCommand(targetLevel, sourceItem, startAngle, true);
if (targetLevel == null)
{
this.menuButton.TransformToNormal();
}
}
}
/// <summary>
/// Called when selection is changed .
/// </summary>
@ -867,7 +842,7 @@ namespace Telerik.UI.Xaml.Controls.Primitives
}
else
{
this.HandleOnBackButtonPressed();
this.CommandService.ExecuteCommand(CommandId.NavigateBack, null);
}
}
}