Skip to content

Commit

Permalink
Use SplitButton for button of selecting log profile on toolbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster620 committed Dec 7, 2024
1 parent 403b0c8 commit ff90808
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 32 deletions.
20 changes: 5 additions & 15 deletions ULogViewer/Controls/SessionView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -583,22 +583,12 @@
<StackPanel Name="toolBarLogActionItemsPanel" Orientation="Horizontal">

<!-- Select log profiles -->
<Button Name="selectAndSetLogProfileButton"
Classes="ToolBar_Button_WithDropDownButton"
Command="{Binding #root.SelectAndSetLogProfileCommand}"
ToolTip.Tip="{asXaml:StringResource SessionView.SetLogProfile}">
<asControls:SplitButton Name="selectAndSetLogProfileButton"
Classes="ToolBar_SplitButton"
Command="{Binding #root.SelectAndSetLogProfileCommand}"
ToolTip.Tip="{asXaml:StringResource SessionView.SetLogProfile}">
<Image Classes="Icon" Source="{StaticResource Image/LogProfile.Outline}"/>
</Button>
<ToggleButton Name="selectAndSetLogProfileDropDownButton"
Classes="ToolBar_DropDownButton"
Command="{Binding #root.ShowLogProfileSelectionMenu}"
IsEnabled="{Binding #selectAndSetLogProfileButton.IsEnabled}"
ToolTip.Tip="{asXaml:StringResource SessionView.SetLogProfile}">
<Panel>
<Image Classes="ToolBar_DropDownButtonIcon" IsVisible="{Binding !$parent[ToggleButton].IsChecked}" Source="{StaticResource Image/Icon.DropDown.Down}"/>
<Image Classes="ToolBar_DropDownButtonIcon" IsVisible="{Binding $parent[ToggleButton].IsChecked}" Source="{StaticResource Image/Icon.DropDown.Down.Light}"/>
</Panel>
</ToggleButton>
</asControls:SplitButton>

<!-- Set working directory -->
<Button Classes="ToolBar_Button"
Expand Down
23 changes: 6 additions & 17 deletions ULogViewer/Controls/SessionView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using AsControls = CarinaStudio.AppSuite.Controls;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
Expand Down Expand Up @@ -295,7 +296,7 @@ enum LogDataSourceType
readonly MenuItem searchLogPropertyOnInternetMenuItem;
IBrush? selectableValueLogItemBackgroundBrush;
readonly IMultiValueConverter selectableValueLogItemBackgroundConverter;
readonly ToggleButton selectAndSetLogProfileDropDownButton;
readonly AsControls.SplitButton selectAndSetLogProfileButton;
readonly MenuItem showLogPropertyMenuItem;
readonly ColumnDefinition sidePanelColumn;
readonly Control sidePanelContainer;
Expand Down Expand Up @@ -646,7 +647,7 @@ public SessionView()
this.predefinedLogTextFilterListBox.Focus();
});
});
this.selectAndSetLogProfileDropDownButton = toolBarContainer.FindControl<ToggleButton>(nameof(selectAndSetLogProfileDropDownButton)).AsNonNull();
this.selectAndSetLogProfileButton = this.Get<AsControls.SplitButton>(nameof(selectAndSetLogProfileButton));
this.sidePanelColumn = this.Get<Grid>("RootGrid").Let(grid =>
{
return grid.ColumnDefinitions[2].Also(it =>
Expand Down Expand Up @@ -800,6 +801,7 @@ public SessionView()
});
this.logProfileSelectionMenu = ((LogProfileSelectionContextMenu)this.Resources[nameof(logProfileSelectionMenu)].AsNonNull()).Also(it =>
{
this.selectAndSetLogProfileButton.DropDownMenu = it;
it.LogProfileCreated += (_, logProfile) =>
this.OnLogProfileCreatedByLogProfileSelectionMenu(logProfile);
it.LogProfileExported += (_, _, fileName) =>
Expand Down Expand Up @@ -845,12 +847,6 @@ public SessionView()
};
it.LogProfileSelected += async (_, logProfile) =>
await this.SetLogProfileAsync(logProfile);
it.Closed += (_, _) => this.SynchronizationContext.Post(() => this.selectAndSetLogProfileDropDownButton.IsChecked = false);
it.Opened += (_, _) => this.SynchronizationContext.Post(() =>
{
ToolTip.SetIsOpen(this.selectAndSetLogProfileDropDownButton, false);
this.selectAndSetLogProfileDropDownButton.IsChecked = true;
});
});
this.logsSavingMenu = ((ContextMenu)this.Resources[nameof(logsSavingMenu)].AsNonNull()).Also(it =>
{
Expand Down Expand Up @@ -5545,13 +5541,6 @@ void ShowLogFileInExplorer(string filePath) =>
/// Command to show single log file in system file manager.
/// </summary>
public ICommand ShowLogFileInExplorerCommand { get; }


/// <summary>
/// Show menu to select log profile.
/// </summary>
public void ShowLogProfileSelectionMenu() =>
this.logProfileSelectionMenu.Open(this.selectAndSetLogProfileDropDownButton);


/// <summary>
Expand Down Expand Up @@ -5610,7 +5599,7 @@ bool ShowNextTutorial()
// check state
if (this.areAllTutorialsShown)
return false;
if (this.attachedWindow is not CarinaStudio.AppSuite.Controls.Window window)
if (this.attachedWindow is not AsControls.Window window)
return false;
if ((window as MainWindow)?.AreInitialDialogsClosed == false
|| window.HasDialogs
Expand All @@ -5634,7 +5623,7 @@ bool ShowNextTutorial()
{
return window.ShowTutorial(new Tutorial().Also(it =>
{
it.Anchor = this.FindControl<Control>("selectAndSetLogProfileButton");
it.Anchor = this.selectAndSetLogProfileButton;
it.Bind(Tutorial.DescriptionProperty, this.Application.GetObservableString("SessionView.Tutorial.SelectLogProfileToStart"));
it.Dismissed += (_, _) =>
{
Expand Down

0 comments on commit ff90808

Please sign in to comment.