Skip to content

Commit

Permalink
Add guide action
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 30, 2023
1 parent 351e5a3 commit 428c870
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
8 changes: 4 additions & 4 deletions hyperplane/gtk/guide.blp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ template $HypGuide : Adw.Window {
Adw.StatusPage page_1 {
title: _("Welcome to Hyperplane");
description: _("This guide will help you learn it's features");
Button {
Button button_1 {
halign: center;
label: _("Start");

Expand Down Expand Up @@ -47,7 +47,7 @@ template $HypGuide : Adw.Window {
title: _("Organize by Categories");
description: _("Categories allow you to organize your files and folders however you like,\nan item can be in any category and you can access your categories in any order");

Button {
Button button_2 {
halign: center;
label: _("Next");

Expand Down Expand Up @@ -77,7 +77,7 @@ template $HypGuide : Adw.Window {
title: _("You Own Your Files");
description: _("Categories are simply stored as folders on disk\nso you can easily access them even outside Hyperplane");

Button {
Button button_3 {
halign: center;
label: _("Next");

Expand Down Expand Up @@ -132,7 +132,7 @@ template $HypGuide : Adw.Window {
title: _("You're in Control");
description: _("Hyperplane will not move files automatically when editing categories\nso all file operations are transparent");

Button {
Button button_4 {
halign: center;
label: _("Open Hyperplane");

Expand Down
5 changes: 5 additions & 0 deletions hyperplane/gtk/help-overlay.blp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ ShortcutsWindow help_overlay {
action-name: "win.show-help-overlay";
}

ShortcutsShortcut {
title: _("Guide");
action-name: "app.show-guide";
}

ShortcutsShortcut {
title: _("Undo");
accelerator: "<primary>z";
Expand Down
5 changes: 2 additions & 3 deletions hyperplane/gtk/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ menu primary_menu {
}
section {
item (_("Show _Hidden Files"), "app.show-hidden")
item (_("Edit Locations"), "win.edit-sidebar")
}
section {
item (_("_Preferences"), "app.preferences")
item (_("_Keyboard Shortcuts"), "win.show-help-overlay")
item (_("_Guide"), "app.show-guide")
item (_("_About Hyperplane"), "app.about")
}
section {
item (_("Edit Locations"), "win.edit-sidebar")
}
}

template $HypWindow : Adw.ApplicationWindow {
Expand Down
8 changes: 7 additions & 1 deletion hyperplane/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class HypGuide(Adw.Window):
folders_picture: Gtk.Picture = Gtk.Template.Child()
folder_picture: Gtk.Picture = Gtk.Template.Child()

button_1: Gtk.Button = Gtk.Template.Child()
button_2: Gtk.Button = Gtk.Template.Child()
button_3: Gtk.Button = Gtk.Template.Child()
button_4: Gtk.Button = Gtk.Template.Child()

def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)

Expand All @@ -46,5 +51,6 @@ def __init__(self, **kwargs) -> None:
@Gtk.Template.Callback()
def _next_page(self, _widget: Gtk.Widget) -> None:
self.carousel.scroll_to(
self.carousel.get_nth_page(self.carousel.get_position() + 1), True
self.carousel.get_nth_page(pos := self.carousel.get_position() + 1), True
)
self.set_focus(getattr(self, f"button_{int(pos) + 1}"))
18 changes: 17 additions & 1 deletion hyperplane/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

# pylint: disable=wrong-import-position

from gi.repository import Adw, Gio, GLib
from gi.repository import Adw, Gio, GLib, Gtk

from hyperplane import shared
from hyperplane.file_manager_dbus import FileManagerDBusServer
Expand Down Expand Up @@ -72,6 +72,7 @@ def __init__(self) -> None:
self.set_option_context_parameter_string("[DIRECTORIES]")

self.create_action("quit", lambda *_: self.quit(), ("<primary>q",))
self.create_action("show-guide", self.__guide, ("F1",))
self.create_action("about", self.__about)
self.create_action("preferences", self.__preferences, ("<primary>comma",))

Expand Down Expand Up @@ -167,6 +168,21 @@ def create_action(
if shortcuts:
self.set_accels_for_action(f"app.{name}", shortcuts)

def __guide(self, *_args: Any) -> None:
guide = HypGuide()

guide.set_modal(True)
guide.set_transient_for(self.get_active_window())
guide.add_controller(shortcut_controller := Gtk.ShortcutController())
shortcut_controller.add_shortcut(
Gtk.Shortcut.new(
Gtk.ShortcutTrigger.parse_string("Escape"),
Gtk.NamedAction.new("window.close"),
),
)

guide.present()

def __about(self, *_args: Any) -> None:
about = Adw.AboutWindow.new_from_appdata(
shared.PREFIX + "/" + shared.APP_ID + ".metainfo.xml", shared.VERSION
Expand Down

0 comments on commit 428c870

Please sign in to comment.