-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define Gtk closure expressions in code when the UI file is NOT a template. #667
Comments
Thanks for filing a clear issue. This is something I've wanted as well. Related, during a Workshop someone was confused about the lack of signal handlers. https://floss.social/@sonny/110816126000858204 The main issues are:
I've been proposing the following for GJS https://gitlab.gnome.org/GNOME/gjs/-/merge_requests/853 Let's move forward, here is a plan:
|
@rolandlo are you able to test / use Workbench devel (branch If you're gonna use it, please do share feedback and thoughts. Thanks! The experimental Blueprint
JavaScriptimport GObject from "gi://GObject";
import Gtk from "gi://Gtk";
import Adw from "gi://Adw";
const { preferences_group } = workbench.build({
onlyOneTwoThree(_self, item) {
const str = item.string;
return str === "One" || str === "Two" || str === "Three";
},
onlyThreeFour(_self, item) {
const str = item.string;
return str === "Three" || str === "Four";
},
msg(_self, active1, active2, item) {
log("msg");
const str = item.string;
if (active1 && active2) {
return `"${str}" was selected, 2 visible`;
} else if (active1 || active2) {
return `"${str}" was selected, 1 visible`;
} else {
return "0 active. Discard selection";
}
},
onButtonClicked(...args) {
console.log(...args);
},
});
workbench.preview(preferences_group); |
Yes, I can test the main branch. It works great in the example. The syntax is nice. However, how would the JS code look for a Blueprint file like this:
With the obvious looking import GObject from "gi://GObject";
import Gtk from "gi://Gtk";
import Adw from "gi://Adw";
const { preferences_window } = workbench.build({
onButtonClicked,
});
function onButtonClicked(...args) {
console.log(...args);
}
workbench.preview(preferences_window); |
You need to press the "Run" button first. Related #643 |
I did, but that doesn't help. Note that when I change |
I'm not sure why that is but |
Right, it does. I will do further tests then. |
Everything works fine now with what I wanted to achieve with this feature request. See the redesigned Xournal++ preferences window code/UI in case you'd like to check it out. |
@rolandlo that's great to hear. I'm glad Workbench is useful to Xournal++ I'll leave this open as there are a couple of things left to do here. |
Suppose we have a .blp-file that defines a template. Then we can use Gtk closure expression defined in the (say javascript) code like this for example:
UI file
main.blp
Code file
main.js
Now suppose I want to have the same behavior in case that the UI file does NOT define a template (remove
from the fourth line of
main.blp
)How can we define the Gtk closure expressions
onlyOneTwoThree
,onlyThreeFour
andmsg
in the code? There doesn't seem to be an easy way to do so. According to @andyholmes (conversation in the matrix channel) these closures should be added to Workbench's builder scope in some way (compare gjs guide), yet apparently Workbench is not set up to use closures at the moment.So I'd like to request Workbench to support closures in a way that it is easy to use and documented (maybe in a Library demo).
The text was updated successfully, but these errors were encountered: