Skip to content

Commit 5730710

Browse files
authored
Do not exit if Library is the only window open (#721)
1 parent 835c00f commit 5730710

File tree

6 files changed

+25
-29
lines changed

6 files changed

+25
-29
lines changed

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"mesonbuild.mesonbuild",
99
"prince781.vala",
1010
"bodil.blueprint-gtk",
11-
"dbaeumer.vscode-eslint"
11+
"dbaeumer.vscode-eslint",
12+
"ms-python.black-formatter"
1213
]
1314
}

src/IconLibrary/main.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Gtk from "gi://Gtk?version=4.0";
22
import Gdk from "gi://Gdk";
3-
43
import Adw from "gi://Adw";
54
import Gio from "gi://Gio";
65

6+
import { build } from "../../troll/src/builder.js";
7+
78
import IconWidget from "./IconWidget.js";
8-
import resource from "./main.blp";
9+
import resource from "./main.blp" with { type: "uri" };
910

1011
const toasts = new Set();
1112

@@ -21,10 +22,8 @@ export default function IconLibrary() {
2122
dev_kit_icons,
2223
);
2324

24-
const builder = Gtk.Builder.new_from_resource(resource);
25-
26-
const overlay = builder.get_object("overlay");
27-
const search_entry = builder.get_object("search_entry");
25+
const { window, overlay, search_entry, flow_box_devkit, flow_box_platform } =
26+
build(resource);
2827

2928
function selectIcon(icon_name) {
3029
clipboard.set(icon_name);
@@ -41,9 +40,6 @@ export default function IconLibrary() {
4140
overlay.add_toast(toast);
4241
}
4342

44-
const flow_box_devkit = builder.get_object("flow_box_devkit");
45-
const flow_box_platform = builder.get_object("flow_box_platform");
46-
4743
function filter_func({ icon_name }) {
4844
return icons[icon_name]?.some((tag) => tag.includes(search_entry.text));
4945
}
@@ -84,7 +80,6 @@ export default function IconLibrary() {
8480
populateIconDevKit();
8581
populatePlatformIcons();
8682

87-
const window = builder.get_object("window");
8883
return window;
8984
}
9085

src/Library/Library.blp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Gtk 4.0;
22
using Adw 1;
33

4-
Adw.PreferencesWindow library {
4+
Adw.PreferencesWindow window {
55
hide-on-close: true;
66
modal: false;
77
title: _("Library");

src/Library/Library.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Gio from "gi://Gio";
2-
import Gtk from "gi://Gtk";
32

43
import {
54
decode,
@@ -9,17 +8,18 @@ import {
98
} from "../util.js";
109
import Window from "../window.js";
1110

12-
import resource from "./Library.blp";
11+
import resource from "./Library.blp" with { type: "uri" };
1312
import { createSessionFromDemo } from "../sessions.js";
1413
import EntryRow from "./EntryRow.js";
1514

1615
import illustration from "./library.svg";
1716

18-
export default function Library({ application }) {
19-
const builder = Gtk.Builder.new_from_resource(resource);
20-
const window = builder.get_object("library");
17+
import { build } from "../../troll/src/builder.js";
2118

22-
const picture_illustration = builder.get_object("picture_illustration");
19+
export default function Library({ application }) {
20+
const objects = build(resource);
21+
const { window, picture_illustration } = objects;
22+
window.application = application;
2323
picture_illustration.set_resource(illustration);
2424

2525
let last_selected;
@@ -39,7 +39,7 @@ export default function Library({ application }) {
3939
}).catch(console.error);
4040
});
4141

42-
builder.get_object(`library_${demo.category}`).add(widget);
42+
objects[`library_${demo.category}`].add(widget);
4343
});
4444

4545
const action_library = new Gio.SimpleAction({

src/shortcutsWindow.blp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Gtk 4.0;
22

3-
ShortcutsWindow window_shortcuts {
3+
ShortcutsWindow window {
44
hide-on-close: true;
55

66
ShortcutsSection {

src/shortcutsWindow.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import Gtk from "gi://Gtk";
21
import Gio from "gi://Gio";
32

4-
import resource from "./shortcutsWindow.blp";
3+
import resource from "./shortcutsWindow.blp" with { type: "uri" };
4+
5+
import { build } from "../troll/src/builder.js";
56

67
export default function ShortcutsWindow({ application }) {
7-
let window_shortcuts;
8+
let window;
89

910
const action_shortcuts = new Gio.SimpleAction({
1011
name: "shortcuts",
1112
parameter_type: null,
1213
});
1314
action_shortcuts.connect("activate", () => {
14-
if (!window_shortcuts) {
15-
const builder = Gtk.Builder.new_from_resource(resource);
16-
window_shortcuts = builder.get_object("window_shortcuts");
17-
window_shortcuts.set_transient_for(application.get_active_window());
18-
window_shortcuts.set_application(application);
15+
if (!window) {
16+
({ window } = build(resource));
17+
window.set_transient_for(application.get_active_window());
18+
window.set_application(application);
1919
}
20-
window_shortcuts.present();
20+
window.present();
2121
});
2222
application.add_action(action_shortcuts);
2323
application.set_accels_for_action("app.shortcuts", ["<Control>question"]);

0 commit comments

Comments
 (0)