Skip to content
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

Keyboard Shortcut Improvements #2683

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions bottles/frontend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def __init__(self):
self.__create_action('import', self.__show_importer_view, ['<primary>i'])
self.__create_action('preferences', self.__show_preferences, ['<primary>comma'])
self.__create_action('help', self.__help, ['F1'])
self.__create_action('new', self.__new_bottle, ['<primary>n'])
self.__create_action('switch_to_bottles_page', self.__show_bottles_view, ['<alt>1'])
self.__create_action('switch_to_library_page', self.__show_library_view, ['<alt>2'])
self.__create_action('go_back', self.__go_back, ['<alt>Left'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding Escape would help.

Suggested change
self.__create_action('go_back', self.__go_back, ['<alt>Left'])
self.__create_action('go_back', self.__go_back, ['<alt>Left', 'Escape'])


self.__register_arguments()

Expand Down Expand Up @@ -265,6 +269,9 @@ def __show_preferences(self, *args):
preferences_window = PreferencesWindow(self.win)
preferences_window.present()

def __new_bottle(self, *args):
self.win.show_add_view()

def __show_importer_view(self, widget=False, *args):
self.win.main_leaf.set_visible_child(self.win.page_importer)

Expand Down Expand Up @@ -336,6 +343,15 @@ def __show_about_window(self, *_args):
about_window.set_transient_for(self.win)
about_window.present()

def __show_library_view(self, *_args):
self.win.stack_main.set_visible_child_name("page_library")

def __show_bottles_view(self, *_args):
self.win.stack_main.set_visible_child_name("page_list")

def __go_back(self, *_args):
self.win.main_leaf.navigate(Adw.NavigationDirection.BACK)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it locally and it doesn't work well in practice. Instead of going back a page, it goes to the main page when I press Alt+Left:

2023-06-24.08-39-24.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noted this too, thats why i didn't add this once to the keyboard shortcuts window, the reason for this being we have two separate leaflets, this should be fixed automatically when we switch to AdwNavigationView.


def __create_action(self, name, callback, shortcuts=None, param=None):
"""Add an application action.

Expand Down
2 changes: 1 addition & 1 deletion bottles/frontend/ui/bottles.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<file>dialog-vmtouch.ui</file>
<file>onboard.ui</file>
<file>about.ui</file>

<file alias="gtk/help-overlay.ui">help-overlay.ui</file>
</gresource>
<gresource prefix="/com/usebottles/bottles/icons/scalable/actions">
<file alias="bottles-steam-symbolic.svg">../../../data/icons/symbolic/scalable/apps/bottles-steam-symbolic.svg</file>
Expand Down
54 changes: 54 additions & 0 deletions bottles/frontend/ui/help-overlay.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Gtk 4.0;

ShortcutsWindow help_overlay {
modal: true;

ShortcutsSection {
section-name: "shortcuts";
max-height: 10;

ShortcutsGroup {
title: C_("shortcut window", "General");

ShortcutsShortcut {
title: C_("shortcut window", "New Bottle");
action-name: "app.new";
}

ShortcutsShortcut {
title: C_("shortcut window", "Import Bottle");
action-name: "app.import";
}

ShortcutsShortcut {
title: C_("shortcut window", "Preferences");
action-name: "app.preferences";
}

ShortcutsShortcut {
title: C_("shortcut window", "Documentation");
action-name: "app.help";
}

ShortcutsShortcut {
title: C_("shortcut window", "Show Shortcuts");
action-name: "win.show-help-overlay";
}

ShortcutsShortcut {
title: C_("shortcut window", "Quit");
action-name: "app.quit";
}

ShortcutsShortcut {
title: C_("shortcut window", "Switch to Bottles view");
action-name: "app.switch_to_bottles_page";
}

ShortcutsShortcut {
title: C_("shortcut window", "Switch to Library view");
action-name: "app.switch_to_library_page";
}
}
}
}
1 change: 1 addition & 0 deletions bottles/frontend/ui/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ blueprints = custom_target('blueprints',
'task-entry.blp',
'window.blp',
'details-preferences.blp',
'help-overlay.blp',
),
output: '.',
command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],)
Expand Down
5 changes: 5 additions & 0 deletions bottles/frontend/ui/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ menu primary_menu {
action: "app.help";
}

item {
label: _("_Keyboard Shortcuts");
action: "win.show-help-overlay";
}

item {
label: _("About Bottles");
action: "app.about";
Expand Down
10 changes: 9 additions & 1 deletion bottles/frontend/views/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,25 @@ def __init__(self, window, **kwargs):
# focus on the entry_name
self.entry_name.grab_focus()

# Create bottle when pressing enter
self.entry_name.connect("entry-activated", self.create_bottle)

def __set_group(self, *_args) -> None:
""" Checks the state of combo_environment and updates group_custom accordingly. """
self.group_custom.set_sensitive(self.check_custom.get_active())

def __check_entry_name(self, *_args) -> None:
def __check_entry_name(self, *_args) -> bool:
is_duplicate = self.entry_name.get_text() in self.manager.local_bottles
is_invalid = is_duplicate or self.entry_name.get_text() == ""
self.btn_create.set_sensitive(not is_invalid)
self.menu_duplicate.set_visible(is_duplicate)

if is_invalid:
self.entry_name.add_css_class("error")
return False
else:
self.entry_name.remove_css_class("error")
return True

def __choose_env_recipe(self, *_args) -> None:
"""
Expand Down Expand Up @@ -164,6 +169,9 @@ def set_path(_dialog, response: Gtk.ResponseType) -> None:
dialog.show()

def create_bottle(self, *_args) -> None:
if not self.__check_entry_name():
return

""" Starts creating the bottle. """
# set widgets states
self.is_closable = False
Expand Down