Skip to content

Commit 2c1dad9

Browse files
authored
Add option to create new project (#970)
Fixes #951
1 parent b66871f commit 2c1dad9

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/actions.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import Xdp from "gi://Xdp";
55
import XdpGtk from "gi://XdpGtk4";
66

77
import About from "./about.js";
8+
import Window from "./window.js";
89
import { portal, settings } from "./util.js";
10+
import { createSession } from "./sessions.js";
911

1012
export default function Actions({ application }) {
1113
const quit = new Gio.SimpleAction({
@@ -65,6 +67,15 @@ export default function Actions({ application }) {
6567
// application.add_action(settings.create_action("safe-mode"));
6668
// application.add_action(settings.create_action("auto-preview"));
6769

70+
const action_new_project = new Gio.SimpleAction({
71+
name: "new",
72+
});
73+
action_new_project.connect("activate", (_self, _target) => {
74+
newProject({ application }).catch(console.error);
75+
});
76+
application.add_action(action_new_project);
77+
application.set_accels_for_action("app.new", ["<Control>N"]);
78+
6879
const action_open_file = new Gio.SimpleAction({
6980
name: "open",
7081
parameter_type: new GLib.VariantType("s"),
@@ -97,6 +108,12 @@ async function showScreenshot({ application, uri }) {
97108
);
98109
}
99110

111+
async function newProject({ application }) {
112+
const session = createSession();
113+
const { load } = Window({ application, session });
114+
await load();
115+
}
116+
100117
async function open({ application, hint }) {
101118
const file_dialog = new Gtk.FileDialog();
102119

src/sessions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export async function getSessions() {
5656
return [...files.values()].map((file) => new Session(file));
5757
}
5858

59-
function createSession() {
59+
export function createSession() {
6060
const id = getNowForFilename();
6161
const file = sessions_dir.get_child(id);
6262
ensureDir(file);

src/shortcutsWindow.blp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ ShortcutsWindow window {
1717
title: _("Format");
1818
}
1919

20+
ShortcutsShortcut {
21+
accelerator: "<Control>N";
22+
title: _("New Project");
23+
}
24+
2025
ShortcutsShortcut {
2126
accelerator: "<Control>O";
2227
title: _("Open Project");

src/window.blp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,11 @@ menu menu_app {
595595
}
596596

597597
section {
598+
item {
599+
label: _("New Project");
600+
action: "app.new";
601+
}
602+
598603
item {
599604
label: _("Open Project…");
600605
action: "app.open";

0 commit comments

Comments
 (0)