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 a6303fa commit 4f54299
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
11 changes: 6 additions & 5 deletions code/IconBrowser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Editor;
using Sandbox;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -44,7 +45,7 @@ private void SetupWindow()
{
MinimumSize = new Vector2( 192, 192 );

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

// Toolbar.
{
Expand Down Expand Up @@ -118,7 +119,7 @@ private static void OpenDumpIconDialog()
filePath += ".cs";

DumpIconsToCsFile( filePath );
Utility.OpenFileFolder( filePath );
EditorUtility.OpenFileFolder( filePath );
}

/// <summary>
Expand Down Expand Up @@ -201,9 +202,9 @@ private void IconContextMenu( object obj )

var menu = new Menu();

menu.AddOption( "Copy Name", null, () => Clipboard.Copy( iconData.Name ) );
menu.AddOption( "Copy C# Name", null, () => Clipboard.Copy( iconData.CsName ) );
menu.AddOption( "Copy S&&box Name", null, () => Clipboard.Copy( iconData.IconName ) );
menu.AddOption( "Copy Name", null, () => EditorUtility.Clipboard.Copy( iconData.Name ) );
menu.AddOption( "Copy C# Name", null, () => EditorUtility.Clipboard.Copy( iconData.CsName ) );
menu.AddOption( "Copy S&&box Name", null, () => EditorUtility.Clipboard.Copy( iconData.IconName ) );

menu.OpenAtCursor();
}
Expand Down
21 changes: 21 additions & 0 deletions code/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/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/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/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;
}
}

0 comments on commit 4f54299

Please sign in to comment.