Skip to content

Commit

Permalink
Add option to create new project (#970)
Browse files Browse the repository at this point in the history
Fixes #951
  • Loading branch information
rolandlo authored Jul 23, 2024
1 parent b66871f commit 2c1dad9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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", ["<Control>N"]);

const action_open_file = new Gio.SimpleAction({
name: "open",
parameter_type: new GLib.VariantType("s"),
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/shortcutsWindow.blp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ ShortcutsWindow window {
title: _("Format");
}

ShortcutsShortcut {
accelerator: "<Control>N";
title: _("New Project");
}

ShortcutsShortcut {
accelerator: "<Control>O";
title: _("Open Project");
Expand Down
5 changes: 5 additions & 0 deletions src/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,11 @@ menu menu_app {
}

section {
item {
label: _("New Project");
action: "app.new";
}

item {
label: _("Open Project…");
action: "app.open";
Expand Down

0 comments on commit 2c1dad9

Please sign in to comment.