Skip to content

Commit

Permalink
Add a menu button
Browse files Browse the repository at this point in the history
Useful for exposing features
  • Loading branch information
sonnyp committed Oct 24, 2021
1 parent f138149 commit 05bad74
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 55 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/Entry.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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", () => {
Expand Down
5 changes: 4 additions & 1 deletion src/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
Expand All @@ -32,7 +34,8 @@ export default function Application({ version }) {
application.add_action(quit);
application.set_accels_for_action("app.quit", ["<Primary>Q"]);

application.set_accels_for_action("win.close", ["<Primary>W", "Escape"]);
application.set_accels_for_action("window.close", ["<Primary>W", "Escape"]);
application.set_accels_for_action("win.copy", ["<Primary>C"]);

const showAboutDialog = new Gio.SimpleAction({
name: "about",
Expand Down
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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}`);
Expand Down
Empty file added src/menu.ui
Empty file.
8 changes: 0 additions & 8 deletions src/setup.js

This file was deleted.

10 changes: 9 additions & 1 deletion src/window.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
22 changes: 6 additions & 16 deletions src/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export default function Window({ application, file }) {
entry: builder.get_object("entry"),
value,
scheme,
copyToClipboard,
});

const applications = getApplications(content_type);
Expand All @@ -68,23 +67,14 @@ export default function Window({ application, file }) {
list.append(button);
});

const shortcut = new Gtk.Shortcut({
trigger: Gtk.ShortcutTrigger.parse_string("<Control>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 };
}
Expand Down
72 changes: 54 additions & 18 deletions src/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,37 @@
</object>
</child>
<child>
<object class="GtkEntry" id="entry">
<property name="input-purpose">url</property>
<property name="xalign">0.5</property>
<!-- TODO: file a bug - does not seem to be working -->
<property name="primary-icon-activatable">False</property>
<!-- TRANSLATORS: You will find this string in https://gitlab.gnome.org/search?search=This+site+has+no+security&project_id=1906 -->
<property
name="primary-icon-tooltip-text"
translatable="yes"
>This site has no security. An attacker could see any information you send, or control the content that you see.</property>
<property name="secondary-icon-name">edit-copy-symbolic</property>
<property
name="secondary-icon-tooltip-text"
translatable="yes"
>Copy to Clipboard</property>
<style>
<class name="uri" />
</style>
<object class="GtkBox">
<child>
<object class="GtkEntry" id="entry">
<property name="hexpand">true</property>
<property name="input-purpose">url</property>
<property name="xalign">0.5</property>
<!-- TODO: file a bug - does not seem to be working -->
<property name="primary-icon-activatable">False</property>
<!-- TRANSLATORS: You will find this string in https://gitlab.gnome.org/search?search=This+site+has+no+security&project_id=1906 -->
<property
name="primary-icon-tooltip-text"
translatable="yes"
>This site has no security. An attacker could see any information you send, or control the content that you see.</property>
<!-- <property
name="secondary-icon-name"
>edit-copy-symbolic</property> -->
<!-- <property
name="secondary-icon-tooltip-text"
translatable="yes"
>Copy to Clipboard</property> -->
<style>
<class name="uri" />
</style>
</object>
</child>
<child type="start">
<object class="GtkMenuButton" id="menu_button">
<property name="popover">menu_popover</property>
<property name="icon-name">open-menu-symbolic</property>
</object>
</child>
</object>
</child>
</object>
Expand All @@ -43,4 +56,27 @@
<class name="main" />
</style>
</object>
<object class="GtkPopoverMenu" id="menu_popover">
<property name="menu-model">menu_model</property>
<property name="halign">end</property>
</object>
<menu id="menu_model">
<item>
<attribute name="label" translatable="yes">Copy to Clipboard</attribute>
<attribute name="action">win.copy</attribute>
</item>
<section>
<item>
<attribute
name="label"
translatable="yes"
>Keyboard Shortcuts</attribute>
<attribute name="action">app.shortcuts</attribute>
</item>
<item>
<attribute name="label" translatable="yes">About Junction</attribute>
<attribute name="action">app.about</attribute>
</item>
</section>
</menu>
</interface>

0 comments on commit 05bad74

Please sign in to comment.