-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from yuto-trd/dev
1.0.2
- Loading branch information
Showing
7 changed files
with
162 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
samples/ReDocking.Sample/Views/SideBarButtonMenuFlyout.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System.Collections.Generic; | ||
|
||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.Templates; | ||
using Avalonia.Interactivity; | ||
using Avalonia.VisualTree; | ||
|
||
using ReDocking.ViewModels; | ||
|
||
namespace ReDocking.Views; | ||
|
||
public class CustomSideBarButtonMenuFlyout : MenuFlyout | ||
{ | ||
private readonly ReDockHost _dockHost; | ||
|
||
public CustomSideBarButtonMenuFlyout(ReDockHost dockHost) | ||
{ | ||
_dockHost = dockHost; | ||
var list = new List<Control>(); | ||
|
||
{ | ||
var moveMenu = new MenuItem(); | ||
moveMenu.Header = "Move to"; | ||
moveMenu.ItemsSource = dockHost.DockAreas; | ||
moveMenu.DataTemplates.Add(new FuncDataTemplate<DockArea>(_ => true, | ||
o => new TextBlock | ||
{ | ||
[!TextBlock.TextProperty] = o.GetObservable(DockArea.LocalizedNameProperty).ToBinding(), | ||
})); | ||
|
||
moveMenu.AddHandler(MenuItem.ClickEvent, OnMoveToSubItemClick); | ||
list.Add(moveMenu); | ||
} | ||
|
||
{ | ||
var closeMenu = new MenuItem(); | ||
closeMenu.Header = "Close"; | ||
closeMenu.AddHandler(MenuItem.ClickEvent, OnCloseClick); | ||
list.Add(closeMenu); | ||
} | ||
|
||
if (dockHost.IsFloatingEnabled) | ||
{ | ||
var displayMenu = new MenuItem(); | ||
displayMenu.Header = "Display mode"; | ||
displayMenu.ItemsSource = new List<Control> | ||
{ | ||
new MenuItem { Header = "Docked", Tag = DockableDisplayMode.Docked }, | ||
new MenuItem { Header = "Floating", Tag = DockableDisplayMode.Floating }, | ||
}; | ||
displayMenu.AddHandler(MenuItem.ClickEvent, OnDisplayModeClick); | ||
list.Add(displayMenu); | ||
} | ||
|
||
ItemsSource = list; | ||
} | ||
|
||
private void OnCloseClick(object? sender, RoutedEventArgs e) | ||
{ | ||
if (Target is not SideBarButton button) return; | ||
if (button is not { DockLocation: { } location }) return; | ||
if (button is not { DataContext: ToolWindowViewModel buttonViewModel }) return; | ||
if (button.FindAncestorOfType<MainWindow>() is not { DataContext: MainWindowViewModel viewModel }) return; | ||
|
||
buttonViewModel.IsSelected.Value = false; | ||
var itemsSource = MainWindow.GetItemsSource(viewModel, location); | ||
itemsSource.Remove(buttonViewModel); | ||
} | ||
|
||
private void OnDisplayModeClick(object? sender, RoutedEventArgs e) | ||
{ | ||
if (e.Source is MenuItem { Tag: DockableDisplayMode mode } && | ||
Target is SideBarButton button) | ||
{ | ||
var args = new SideBarButtonDisplayModeChangedEventArgs(ReDockHost.ButtonDisplayModeChangedEvent, this) | ||
{ | ||
DisplayMode = mode, Item = button.DataContext, Button = button | ||
}; | ||
_dockHost.RaiseEvent(args); | ||
} | ||
} | ||
|
||
private void OnMoveToSubItemClick(object? sender, RoutedEventArgs e) | ||
{ | ||
if (e.Source is MenuItem { DataContext: DockArea area } && | ||
Target is SideBarButton button) | ||
{ | ||
// Target | ||
var oldSideBar = button.FindAncestorOfType<SideBar>(); | ||
var newSideBar = area.SideBar; | ||
if (oldSideBar is null || newSideBar is null) return; | ||
var oldLocation = button.DockLocation; | ||
var newLocation = area.Location; | ||
if (oldLocation is null || oldLocation == newLocation) return; | ||
|
||
var args = new SideBarButtonMoveEventArgs(ReDockHost.ButtonMoveEvent, this) | ||
{ | ||
Item = button.DataContext, | ||
Button = button, | ||
SourceSideBar = oldSideBar, | ||
SourceLocation = oldLocation, | ||
DestinationSideBar = newSideBar, | ||
DestinationLocation = newLocation, | ||
DestinationIndex = 0 | ||
}; | ||
_dockHost.RaiseEvent(args); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Avalonia.Interactivity; | ||
|
||
namespace ReDocking; | ||
|
||
public class SideBarButtonFlyoutRequestedEventArgs( | ||
SideBarButton button, | ||
ReDockHost dockHost, | ||
RoutedEvent routedEvent, | ||
object source) | ||
: RoutedEventArgs(routedEvent, source) | ||
{ | ||
public SideBarButton Button { get; } = button; | ||
public ReDockHost DockHost { get; } = dockHost; | ||
} |