Skip to content

Commit

Permalink
Fix recent editor API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-r-g committed Sep 21, 2023
1 parent 0bb0603 commit e93823a
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 9 deletions.
2 changes: 1 addition & 1 deletion code/TemplateDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public TemplateDownloader()
WindowTitle = "Template Downloader";
SetWindowIcon( MaterialIcon.Storage );

SetLayout( LayoutMode.LeftToRight );
this.SetLayout( LayoutMode.LeftToRight );
Templates = Layout.Add( new PaginatedNavigationView() );
Show();

Expand Down
21 changes: 21 additions & 0 deletions code/Util/LayoutCompat/LayoutExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Editor;

/// <summary>
/// Contains extension methods for <see cref="Layout"/>.
/// </summary>
internal static class LayoutExtensions
{
/// <summary>
/// Adds a child <see cref="Layout"/>.
/// </summary>
/// <param name="parentLayout">The parent <see cref="Layout"/> to add the newly created one to.</param>
/// <param name="layoutMode">The mode that the layout should use.</param>
/// <param name="stretch">The stretch value to pass to QT.</param>
/// <returns>The newly created <see cref="Layout"/>.</returns>
internal static Layout Add( this Layout parentLayout, LayoutMode layoutMode, int stretch = default )
{
var childLayout = layoutMode.CreateLayout();
parentLayout.Add( childLayout, stretch );
return childLayout;
}
}
12 changes: 12 additions & 0 deletions code/Util/LayoutCompat/LayoutMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Editor;

/// <summary>
/// Defines a mode for a <see cref="Layout"/> to follow.
/// </summary>
internal enum LayoutMode : byte
{
TopToBottom,
BottomToTop,
LeftToRight,
RightToLeft
}
24 changes: 24 additions & 0 deletions code/Util/LayoutCompat/LayoutModeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace Editor;

/// <summary>
/// Contains extension methods for <see cref="LayoutMode"/>.
/// </summary>
internal static class LayoutModeExtensions
{
/// <summary>
/// Creates a new <see cref="Layout"/> based on the mode.
/// </summary>
/// <param name="layoutMode">The mode for the <see cref="Layout"/> to follow.</param>
/// <returns>The newly created <see cref="Layout"/>.</returns>
/// <exception cref="ArgumentException">Thrown when the <see cref="LayoutMode"/> provided is invalid.</exception>
internal static Layout CreateLayout( this LayoutMode layoutMode ) => layoutMode switch
{
LayoutMode.TopToBottom => Layout.Column(),
LayoutMode.BottomToTop => Layout.Column( true ),
LayoutMode.LeftToRight => Layout.Row(),
LayoutMode.RightToLeft => Layout.Row( true ),
_ => throw new ArgumentException( $"Unrecognized {nameof( LayoutMode )} \"{layoutMode}\"", nameof( layoutMode ) )
};
}
20 changes: 20 additions & 0 deletions code/Util/LayoutCompat/WidgetExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Editor;

/// <summary>
/// Contains extension methods for <see cref="Widget"/>.
/// </summary>
internal static class WidgetExtensions
{
/// <summary>
/// Sets the <see cref="Layout"/> of the <see cref="Widget"/>.
/// </summary>
/// <param name="widget">The <see cref="Widget"/> whose <see cref="Layout"/> to set.</param>
/// <param name="layoutMode">The mode to use on the <see cref="Layout"/>.</param>
/// <returns>The newly created <see cref="Layout"/>.</returns>
internal static Layout SetLayout( this Widget widget, LayoutMode layoutMode )
{
var layout = layoutMode.CreateLayout();
widget.Layout = layout;
return layout;
}
}
6 changes: 3 additions & 3 deletions code/Widgets/PaginatedNavigationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public IEnumerable<VirtualOption> VisibleOptions
/// <param name="parent">The parent of this widget.</param>
public PaginatedNavigationView( Widget? parent = null ) : base( parent )
{
SetLayout( LayoutMode.LeftToRight );
this.SetLayout( LayoutMode.LeftToRight );

MenuContainer = new Widget( this );
MenuContainer.SetLayout( LayoutMode.TopToBottom );
Expand All @@ -252,7 +252,7 @@ public PaginatedNavigationView( Widget? parent = null ) : base( parent )
MenuBottom = MenuContainer.Layout.Add( LayoutMode.BottomToTop );

PageButtons = MenuBottom.AddRow();
PageButtons.HorizontalSpacing = 4;
PageButtons.Spacing = 4;

Rebuild();
}
Expand Down Expand Up @@ -395,7 +395,7 @@ private void RebuildPageButtons()
PageButtons.Add( LeftPageButton );

SpecificPageButtonLayout = PageButtons.AddRow();
SpecificPageButtonLayout.HorizontalSpacing = 2;
SpecificPageButtonLayout.Spacing = 2;

// Handle special cases so that we can try to always have 3 page buttons visible.
int startPoint = PageNumber switch
Expand Down
3 changes: 2 additions & 1 deletion code/Widgets/TemplateHeader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Editor;
using TemplateDownloader.Util;

namespace TemplateDownloader;

Expand All @@ -19,7 +20,7 @@ internal TemplateHeader( string title, Widget? parent = null, bool isDarkWindow
Title = title;
Height = HeaderHeight;

SetLayout( LayoutMode.TopToBottom );
this.SetLayout( LayoutMode.TopToBottom );
}

/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions code/Widgets/TemplatePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void SetupWindow()
{
// Setup.
{
SetLayout( LayoutMode.TopToBottom );
this.SetLayout( LayoutMode.TopToBottom );

Layout.Spacing = 8;
Layout.Margin = 24;
Expand Down Expand Up @@ -181,23 +181,23 @@ private void RefreshButtonDrawer()
/// </summary>
private void OpenGitHubPage()
{
Utility.OpenFolder( Template.Repository.Url );
EditorUtility.OpenFolder( Template.Repository.Url );
}

/// <summary>
/// Action to open the template directory.
/// </summary>
private void OpenTemplateInExplorer()
{
Utility.OpenFolder( Template.TemplatePath );
EditorUtility.OpenFolder( Template.TemplatePath );
}

/// <summary>
/// Action to open the local GitHub repository.
/// </summary>
private void OpenCachedRepoInExplorer()
{
Utility.OpenFolder( Template.CachePath );
EditorUtility.OpenFolder( Template.CachePath );
}

/// <summary>
Expand Down

0 comments on commit e93823a

Please sign in to comment.