Enable adding new tabs

This commit is contained in:
Neil Brommer 2023-07-21 15:21:13 -07:00
parent 93e828beb0
commit 1f8d7a661b
5 changed files with 53 additions and 2 deletions

View file

@ -27,9 +27,19 @@ public partial class AppDelegate : NSApplicationDelegate
as MainWindow);
}
partial void NewTabMenuItemClicked(AppKit.NSMenuItem sender)
{
(NSApplication.SharedApplication.KeyWindow.WindowController
as MainWindow)
.CreateNewTab();
}
[Action("validateMenuItem:")]
public bool ValidateMenuItem(AppKit.NSMenuItem sender)
{
return true;
if (sender.Title is "Run Script" or "New Tab")
return NSApplication.SharedApplication.KeyWindow != null;
return false;
}
}

View file

@ -11,6 +11,9 @@ namespace Cauldron.Macos
{
partial class AppDelegate
{
[Action ("NewTabMenuItemClicked:")]
partial void NewTabMenuItemClicked (AppKit.NSMenuItem sender);
[Action ("RunScriptMenuItemClicked:")]
partial void RunScriptMenuItemClicked (AppKit.NSMenuItem sender);

View file

@ -65,6 +65,11 @@
<action selector="newDocument:" target="Ady-hI-5gd" id="4Si-XN-c54"/>
</connections>
</menuItem>
<menuItem title="New Tab" keyEquivalent="t" id="NId-gA-yuH">
<connections>
<action selector="NewTabMenuItemClicked:" target="Voe-Tx-rLC" id="Uat-zk-F3C"/>
</connections>
</menuItem>
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
<connections>
<action selector="openDocument:" target="Ady-hI-5gd" id="bVn-NM-KNZ"/>
@ -415,7 +420,6 @@
<windowController id="JKR-xj-8kh" customClass="MainWindow" sceneMemberID="viewController">
<window key="window" title="Cauldron" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" frameAutosaveName="" animationBehavior="default" tabbingMode="preferred" id="d7K-Gm-g9N">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" fullSizeContentView="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="211" y="264" width="620" height="406"/>
<rect key="screenRect" x="0.0" y="0.0" width="1512" height="944"/>
<value key="minSize" type="size" width="480" height="270"/>
@ -434,11 +438,17 @@
<toolbarItem implicitItemIdentifier="8EDDDA98-E8C5-404C-9832-8C97B1DAEF5C" label="Run Script" paletteLabel="Run Script" tag="-1" image="play.fill" catalog="system" bordered="YES" sizingBehavior="auto" autovalidates="NO" id="BH3-uw-K5S"/>
<toolbarItem implicitItemIdentifier="NSToolbarSpaceItem" id="ib2-fU-LMb"/>
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="GqC-ht-JU0"/>
<toolbarItem implicitItemIdentifier="3C40411F-C0EC-43C1-B18B-82BA5661BF11" label="New Tab" paletteLabel="New Tab" tag="-1" image="plus" catalog="system" bordered="YES" sizingBehavior="auto" id="uBe-lp-9U2">
<connections>
<action selector="NewTabClicked:" target="JKR-xj-8kh" id="x1O-6U-svq"/>
</connections>
</toolbarItem>
</allowedToolbarItems>
<defaultToolbarItems>
<toolbarItem reference="a3w-Fk-xXU"/>
<toolbarItem reference="eF0-yp-1b0"/>
<toolbarItem reference="BH3-uw-K5S"/>
<toolbarItem reference="uBe-lp-9U2"/>
</defaultToolbarItems>
</toolbar>
<connections>
@ -617,6 +627,7 @@
</scenes>
<resources>
<image name="play.fill" catalog="system" width="12" height="13"/>
<image name="plus" catalog="system" width="14" height="13"/>
<image name="sidebar.leading" catalog="system" width="18" height="14"/>
</resources>
</document>

View file

@ -80,6 +80,16 @@ public partial class MainWindow : NSWindowController
this.ScriptCancellationTokenSource?.Cancel();
}
partial void NewTabClicked(AppKit.NSToolbarItem sender)
{
this.CreateNewTab();
}
partial void NewTabMenuItemClicked(AppKit.NSMenuItem sender)
{
this.CreateNewTab();
}
public void SetScriptRunState(bool scriptIsRunning)
{
if (scriptIsRunning)
@ -91,4 +101,12 @@ public partial class MainWindow : NSWindowController
this.RunScriptToolbarButton.Enabled = true;
}
}
public void CreateNewTab()
{
MainWindow newWindow = this.Storyboard.InstantiateInitialController()
as MainWindow;
this.Window.AddTabbedWindow(newWindow.Window, NSWindowOrderingMode.Above);
this.Window.SelectNextTab(this);
}
}

View file

@ -17,6 +17,15 @@ namespace Cauldron.Macos
[Action ("BtnRunScriptClicked:")]
partial void BtnRunScriptClicked (AppKit.NSToolbarItem sender);
[Action ("NewTabClicked:")]
partial void NewTabClicked (AppKit.NSToolbarItem sender);
[Action ("NewTabMenuItemClicked:")]
partial void NewTabMenuItemClicked (AppKit.NSMenuItem sender);
[Action ("NewTabMenuItemClicked2:")]
partial void NewTabMenuItemClicked2 (AppKit.NSMenuItem sender);
void ReleaseDesignerOutlets ()
{