diff --git a/src/actions.js b/src/actions.js index db65a5e6d..2d14b9898 100644 --- a/src/actions.js +++ b/src/actions.js @@ -5,7 +5,9 @@ import Xdp from "gi://Xdp"; import XdpGtk from "gi://XdpGtk4"; import About from "./about.js"; +import Window from "./window.js"; import { portal, settings } from "./util.js"; +import { createSession } from "./sessions.js"; export default function Actions({ application }) { const quit = new Gio.SimpleAction({ @@ -65,6 +67,15 @@ export default function Actions({ application }) { // application.add_action(settings.create_action("safe-mode")); // application.add_action(settings.create_action("auto-preview")); + const action_new_project = new Gio.SimpleAction({ + name: "new", + }); + action_new_project.connect("activate", (_self, _target) => { + newProject({ application }).catch(console.error); + }); + application.add_action(action_new_project); + application.set_accels_for_action("app.new", ["N"]); + const action_open_file = new Gio.SimpleAction({ name: "open", parameter_type: new GLib.VariantType("s"), @@ -97,6 +108,12 @@ async function showScreenshot({ application, uri }) { ); } +async function newProject({ application }) { + const session = createSession(); + const { load } = Window({ application, session }); + await load(); +} + async function open({ application, hint }) { const file_dialog = new Gtk.FileDialog(); diff --git a/src/sessions.js b/src/sessions.js index a3b90c0d6..96327aef4 100644 --- a/src/sessions.js +++ b/src/sessions.js @@ -56,7 +56,7 @@ export async function getSessions() { return [...files.values()].map((file) => new Session(file)); } -function createSession() { +export function createSession() { const id = getNowForFilename(); const file = sessions_dir.get_child(id); ensureDir(file); diff --git a/src/shortcutsWindow.blp b/src/shortcutsWindow.blp index d10929b30..e8a09edd5 100644 --- a/src/shortcutsWindow.blp +++ b/src/shortcutsWindow.blp @@ -17,6 +17,11 @@ ShortcutsWindow window { title: _("Format"); } + ShortcutsShortcut { + accelerator: "N"; + title: _("New Project"); + } + ShortcutsShortcut { accelerator: "O"; title: _("Open Project"); diff --git a/src/window.blp b/src/window.blp index 7dad45993..ab3ac0de6 100644 --- a/src/window.blp +++ b/src/window.blp @@ -595,6 +595,11 @@ menu menu_app { } section { + item { + label: _("New Project"); + action: "app.new"; + } + item { label: _("Open Project…"); action: "app.open";