2023-07-19 19:30:39 +00:00
|
|
|
using System;
|
2023-07-19 22:09:25 +00:00
|
|
|
using System.Threading;
|
2023-07-19 19:30:39 +00:00
|
|
|
using AppKit;
|
|
|
|
|
|
|
|
namespace Papercut.Macos;
|
|
|
|
|
|
|
|
public partial class MainWindow : NSWindowController
|
|
|
|
{
|
2023-07-19 22:09:25 +00:00
|
|
|
#region Window components
|
|
|
|
|
2023-07-19 19:30:39 +00:00
|
|
|
private NSSplitViewController MainContentController
|
|
|
|
{
|
|
|
|
get => (this.ContentViewController as NSSplitViewController)
|
|
|
|
.SplitViewItems[1].ViewController as NSSplitViewController;
|
|
|
|
}
|
|
|
|
|
|
|
|
private NSViewController SidebarController
|
|
|
|
{
|
|
|
|
get => (this.ContentViewController as NSSplitViewController)
|
|
|
|
.SplitViewItems[0].ViewController;
|
|
|
|
}
|
|
|
|
|
|
|
|
private NSTextView ScriptEditorTextBox
|
|
|
|
{
|
|
|
|
get => (this.MainContentController
|
|
|
|
.SplitViewItems[0].ViewController.View as NSScrollView)
|
|
|
|
.ContentView.DocumentView as NSTextView;
|
|
|
|
}
|
|
|
|
|
2023-07-19 22:09:25 +00:00
|
|
|
public NSTextView ScriptOutputTextBox
|
2023-07-19 19:30:39 +00:00
|
|
|
{
|
|
|
|
get => (this.MainContentController
|
|
|
|
.SplitViewItems[1].ViewController.View as NSScrollView)
|
|
|
|
.ContentView.DocumentView as NSTextView;
|
|
|
|
}
|
|
|
|
|
2023-07-19 22:09:25 +00:00
|
|
|
public string ScriptText { get => this.ScriptEditorTextBox.Value; }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Shared properties
|
|
|
|
|
|
|
|
public CancellationTokenSource ScriptCancellationTokenSource { get; set; }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2023-07-19 19:30:39 +00:00
|
|
|
|
2023-07-19 22:09:25 +00:00
|
|
|
public MainWindow (ObjCRuntime.NativeHandle handle) : base (handle) { }
|
2023-07-19 19:30:39 +00:00
|
|
|
|
|
|
|
public override void AwakeFromNib()
|
|
|
|
{
|
|
|
|
base.AwakeFromNib();
|
|
|
|
|
|
|
|
this.RunScriptToolbarButton.Activated += RunScript;
|
|
|
|
|
|
|
|
NSTextView scriptTextBox = this.ScriptEditorTextBox;
|
|
|
|
scriptTextBox.Font = NSFont.MonospacedSystemFont(new nfloat(14), NSFontWeight.Regular);
|
|
|
|
scriptTextBox.AutomaticQuoteSubstitutionEnabled = false;
|
|
|
|
scriptTextBox.AutomaticDashSubstitutionEnabled = false;
|
|
|
|
scriptTextBox.AutomaticDataDetectionEnabled = false;
|
|
|
|
scriptTextBox.AutomaticSpellingCorrectionEnabled = false;
|
|
|
|
scriptTextBox.AutomaticTextCompletionEnabled = false;
|
|
|
|
scriptTextBox.AutomaticTextReplacementEnabled = false;
|
|
|
|
scriptTextBox.AutomaticLinkDetectionEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RunScript(object sender, EventArgs e)
|
|
|
|
{
|
2023-07-19 22:09:25 +00:00
|
|
|
ScriptRunner.RunScript(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CancelScript(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
this.ScriptCancellationTokenSource?.Cancel();
|
|
|
|
}
|
2023-07-19 19:30:39 +00:00
|
|
|
|
2023-07-19 22:09:25 +00:00
|
|
|
public void SetScriptRunState(bool scriptIsRunning)
|
|
|
|
{
|
|
|
|
if (scriptIsRunning)
|
|
|
|
{
|
|
|
|
this.RunScriptToolbarButton.Enabled = false;
|
|
|
|
}
|
|
|
|
else
|
2023-07-19 19:30:39 +00:00
|
|
|
{
|
2023-07-19 22:09:25 +00:00
|
|
|
this.RunScriptToolbarButton.Enabled = true;
|
|
|
|
}
|
2023-07-19 19:30:39 +00:00
|
|
|
}
|
|
|
|
}
|