desktop: Add "New Notebook" to system tray menu (#2247)

This commit is contained in:
Wojtek Mach 2023-10-04 11:46:42 +02:00 committed by GitHub
parent 100d88041b
commit ed6ae02ada
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View file

@ -370,6 +370,10 @@ defmodule Livebook.Utils do
LivebookWeb.Endpoint.access_url()
end
def expand_desktop_url("/new") do
to_string(%{LivebookWeb.Endpoint.access_struct_url() | path: "/new"})
end
def expand_desktop_url("/settings") do
to_string(%{LivebookWeb.Endpoint.access_struct_url() | path: "/settings"})
end

View file

@ -72,9 +72,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.items = [
NSMenuItem(title: "Open", action: #selector(open), keyEquivalent: "o"),
NSMenuItem(title: "New Notebook", action: #selector(openNewNotebook), keyEquivalent: "n"),
.separator(),
copyURLItem,
NSMenuItem(title: "View Logs", action: #selector(viewLogs), keyEquivalent: "l"),
NSMenuItem(title: "Open .livebookdesktop.sh", action: #selector(openBootScript), keyEquivalent: ""),
.separator(),
NSMenuItem(title: "Settings", action: #selector(openSettings), keyEquivalent: ","),
NSMenuItem(title: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
]
@ -116,6 +119,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
ElixirKit.API.publish("open", "")
}
@objc
func openNewNotebook() {
ElixirKit.API.publish("open", "/new")
}
@objc
func copyURL() {
let pasteboard = NSPasteboard.general

View file

@ -68,12 +68,15 @@ class LivebookApp : ApplicationContext
ContextMenuStrip menu = new ContextMenuStrip();
menu.Items.Add("Open", null, openClicked);
menu.Items.Add("New Notebook", null, openNewNotebookClicked);
menu.Items.Add(new ToolStripSeparator());
var copyURLButton = menu.Items.Add("Copy URL", null, copyURLClicked);
copyURLButton.Enabled = false;
menu.Items.Add("View Logs", null, viewLogsClicked);
menu.Items.Add("Open .livebookdesktop.bat", null, openBootScriptClicked);
menu.Items.Add(new ToolStripSeparator());
menu.Items.Add("Settings", null, openSettingsClicked);
menu.Items.Add("Quit", null, quitClicked);
notifyIcon = new NotifyIcon()
@ -134,6 +137,11 @@ class LivebookApp : ApplicationContext
ElixirKit.API.Publish("open", "");
}
private void openNewNotebookClicked(object? sender, EventArgs e)
{
ElixirKit.API.Publish("open", "/new");
}
private void copyURLClicked(object? sender, EventArgs e)
{
System.Windows.Forms.Clipboard.SetText(url!);