From 05bad7463a08884a027eaa897775deb02bd4e109 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Sun, 24 Oct 2021 04:29:21 +0200 Subject: [PATCH] Add a menu button Useful for exposing features --- README.md | 4 ++- notes.md | 3 +- src/Entry.js | 8 +----- src/application.js | 5 +++- src/main.js | 4 +-- src/menu.ui | 0 src/setup.js | 8 ------ src/window.css | 10 ++++++- src/window.js | 22 ++++---------- src/window.ui | 72 ++++++++++++++++++++++++++++++++++------------ 10 files changed, 81 insertions(+), 55 deletions(-) create mode 100644 src/menu.ui delete mode 100644 src/setup.js diff --git a/README.md b/README.md index b00d13b..dfd8002 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,9 @@ cd Junction ./re.sonny.Junction https://www.gnome.org/ ``` -Press `Ctrl+Shift+Q` on the Junction window to restart it. +Make changes and press `Ctrl+Shift+Q` on the Junction window to restart it. + +Use `Ctrl+Shift+I` to open the inspector. To setup development version as default application first install the desktop file with diff --git a/notes.md b/notes.md index cee5ada..ffad13a 100644 --- a/notes.md +++ b/notes.md @@ -16,6 +16,7 @@ https://github.com/flathub/com.github.donadigo.appeditor/issues/18 - https://github.com/flathub/com.github.donadigo.appeditor/blob/master/com.github.donadigo.appeditor.json - https://github.com/flatpak/flatpak/issues/1286 - https://news.ycombinator.com/item?id=28576147 +- https://edoceo.com/sys/xfce-custom-uri-handler # portal app chooser @@ -41,7 +42,7 @@ Help welcome! Feel free to open an issue and I'd be happy to assist. - Remember application for file type - Replace home dir path with ~ - Replace `file:///` with `/` - - Open file read only + - Open file read only (or copy) - For URLs - HTTPS Everywhere / hsts support - Removes tracking elements from URLs diff --git a/src/Entry.js b/src/Entry.js index 8025462..ce69897 100644 --- a/src/Entry.js +++ b/src/Entry.js @@ -1,11 +1,10 @@ import Gtk from "gi://Gtk"; import GLib from "gi://GLib"; -export default function Entry({ entry, value, scheme, copyToClipboard }) { +export default function Entry({ entry, value, scheme }) { // const entry = builder.get_object("entry"); entry.set_text(value); - entry.set_tooltip_text(value); // Maybe an elipsis in the middle in "view" mode // would be best @@ -27,11 +26,6 @@ export default function Entry({ entry, value, scheme, copyToClipboard }) { entry.set_editable(false); } - entry.connect("icon-release", (position) => { - if (!position === Gtk.EntryIconPosition.SECONDARY) return; - copyToClipboard(); - }); - const eventController = new Gtk.EventControllerFocus(); entry.add_controller(eventController); eventController.connect("enter", () => { diff --git a/src/application.js b/src/application.js index feb37b8..d818988 100644 --- a/src/application.js +++ b/src/application.js @@ -12,6 +12,8 @@ export default function Application({ version }) { flags: Gio.ApplicationFlags.HANDLES_OPEN, }); + Gtk.Settings.get_default()["gtk-application-prefer-dark-theme"] = true; + application.connect("open", (self, [file]) => { Window({ application, file }); }); @@ -32,7 +34,8 @@ export default function Application({ version }) { application.add_action(quit); application.set_accels_for_action("app.quit", ["Q"]); - application.set_accels_for_action("win.close", ["W", "Escape"]); + application.set_accels_for_action("window.close", ["W", "Escape"]); + application.set_accels_for_action("win.copy", ["C"]); const showAboutDialog = new Gio.SimpleAction({ name: "about", diff --git a/src/main.js b/src/main.js index b858857..1018a14 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ -import "./setup.js"; - +import Gtk from "gi://Gtk?version=4.0"; import Gio from "gi://Gio"; import GLib from "gi://GLib"; import { programInvocationName } from "system"; @@ -9,6 +8,7 @@ import Application from "./application.js"; GLib.set_prgname("re.sonny.Junction"); GLib.set_application_name("Junction"); +Gtk.init(); export default function main(argv, { version, datadir }) { log(`datadir: ${datadir}`); diff --git a/src/menu.ui b/src/menu.ui new file mode 100644 index 0000000..e69de29 diff --git a/src/setup.js b/src/setup.js deleted file mode 100644 index 7960b79..0000000 --- a/src/setup.js +++ /dev/null @@ -1,8 +0,0 @@ -// GLib, GObject, and Gio are required by GJS so no version is necessary. -// https://gitlab.gnome.org/GNOME/gjs/-/blob/master/doc/ESModules.md -// import "gi://Gio"; -// import "gi://GLib"; -import Gtk from "gi://Gtk?version=4.0"; -import "gi://Gdk?version=4.0"; - -Gtk.init(); diff --git a/src/window.css b/src/window.css index b387a4b..60a3580 100644 --- a/src/window.css +++ b/src/window.css @@ -33,9 +33,17 @@ entry.uri { border-radius: 18px; margin-top: 6px; margin-left: 12px; - margin-right: 12px; margin-bottom: 6px; /* Non dark theme */ color: white; border: solid 1px black; } + +menubutton button { + background: none; + border: none; +} + +menubutton { + margin-right: 6px; +} diff --git a/src/window.js b/src/window.js index eb0fd3e..3b48638 100644 --- a/src/window.js +++ b/src/window.js @@ -51,7 +51,6 @@ export default function Window({ application, file }) { entry: builder.get_object("entry"), value, scheme, - copyToClipboard, }); const applications = getApplications(content_type); @@ -68,23 +67,14 @@ export default function Window({ application, file }) { list.append(button); }); - const shortcut = new Gtk.Shortcut({ - trigger: Gtk.ShortcutTrigger.parse_string("C"), - action: Gtk.CallbackAction.new(copyToClipboard), - }); - const shortcutController = new Gtk.ShortcutController(); - shortcutController.add_shortcut(shortcut); - window.add_controller(shortcutController); - window.present(); - - const close = new Gio.SimpleAction({ - name: "close", + const copy = new Gio.SimpleAction({ + name: "copy", parameter_type: null, }); - close.connect("activate", () => { - application.get_active_window()?.close(); - }); - window.add_action(close); + copy.connect("activate", copyToClipboard); + window.add_action(copy); + + window.present(); return { window }; } diff --git a/src/window.ui b/src/window.ui index 090e803..6814415 100644 --- a/src/window.ui +++ b/src/window.ui @@ -17,24 +17,37 @@ - - url - 0.5 - - False - - This site has no security. An attacker could see any information you send, or control the content that you see. - edit-copy-symbolic - Copy to Clipboard - + + + + true + url + 0.5 + + False + + This site has no security. An attacker could see any information you send, or control the content that you see. + + + + + + + + menu_popover + open-menu-symbolic + + @@ -43,4 +56,27 @@ + + menu_model + end + + + + Copy to Clipboard + win.copy + +
+ + Keyboard Shortcuts + app.shortcuts + + + About Junction + app.about + +
+