Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Paulo Queiroz
Black Box
Commits
4db8a0c4
Commit
4db8a0c4
authored
Nov 17, 2022
by
Paulo Queiroz
📦
Browse files
WIP shortcuts
- Add reset_shortcut_for_action function to Keymap - Define and use constants for action names
parent
46602ce2
Pipeline
#462879
passed with stage
in 3 minutes and 2 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/services/Shortcuts.vala
View file @
4db8a0c4
...
...
@@ -18,6 +18,21 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
namespace
Terminal
{
public
const
string
ACTION_FOCUS_NEXT_TAB
=
"app.focus-next-tab"
;
public
const
string
ACTION_FOCUS_PREVIOUS_TAB
=
"app.focus-previous-tab"
;
public
const
string
ACTION_NEW_WINDOW
=
"app.new-window"
;
public
const
string
ACTION_WIN_SWITCH_HEADER_BAR_MODE
=
"win.switch-headerbar-mode"
;
public
const
string
ACTION_WIN_NEW_TAB
=
"win.new_tab"
;
public
const
string
ACTION_WIN_EDIT_PREFERENCES
=
"win.edit_preferences"
;
public
const
string
ACTION_WIN_COPY
=
"win.copy"
;
public
const
string
ACTION_WIN_PASTE
=
"win.paste"
;
public
const
string
ACTION_WIN_SEARCH
=
"win.search"
;
public
const
string
ACTION_WIN_FULLSCREEN
=
"win.fullscreen"
;
public
const
string
ACTION_WIN_SHOW_HELP_OVERLAY
=
"win.show-help-overlay"
;
}
// We load the user's keybindings and use them to override the default keymap.
// This way, if we release a new version with an extra action that isn't present
// in the user's file, we'll just use the default shortcut.
...
...
@@ -31,18 +46,20 @@ public class Terminal.Keymap : Object, Json.Serializable {
construct
{
this
.
default_keymap
=
new
Gee
.
HashMultiMap
<
string
,
string
>
();
this
.
default_keymap
.
set
(
"app.focus-next-tab"
,
"<Control>Tab"
);
this
.
default_keymap
.
set
(
"app.focus-previous-tab"
,
"<Shift><Control>Tab"
);
this
.
default_keymap
.
set
(
"app.new-window"
,
"<Shift><Control>n"
);
this
.
default_keymap
.
set
(
"win.switch-headerbar-mode"
,
"<Shift><Control>h"
);
this
.
default_keymap
.
set
(
"win.new_tab"
,
"<Shift><Control>t"
);
this
.
default_keymap
.
set
(
"win.edit_preferences"
,
"<Control>comma"
);
this
.
default_keymap
.
set
(
"win.copy"
,
"<Shift><Control>c"
);
this
.
default_keymap
.
set
(
"win.paste"
,
"<Shift><Control>v"
);
this
.
default_keymap
.
set
(
"win.search"
,
"<Shift><Control>f"
);
this
.
default_keymap
.
set
(
"win.fullscreen"
,
"F11"
);
this
.
default_keymap
.
set
(
ACTION_FOCUS_NEXT_TAB
,
"<Control>Tab"
);
this
.
default_keymap
.
set
(
ACTION_FOCUS_PREVIOUS_TAB
,
"<Shift><Control>Tab"
);
this
.
default_keymap
.
set
(
ACTION_NEW_WINDOW
,
"<Shift><Control>n"
);
this
.
default_keymap
.
set
(
ACTION_WIN_SWITCH_HEADER_BAR_MODE
,
"<Shift><Control>h"
);
this
.
default_keymap
.
set
(
ACTION_WIN_NEW_TAB
,
"<Shift><Control>t"
);
this
.
default_keymap
.
set
(
ACTION_WIN_EDIT_PREFERENCES
,
"<Control>comma"
);
this
.
default_keymap
.
set
(
ACTION_WIN_COPY
,
"<Shift><Control>c"
);
this
.
default_keymap
.
set
(
ACTION_WIN_PASTE
,
"<Shift><Control>v"
);
this
.
default_keymap
.
set
(
ACTION_WIN_SEARCH
,
"<Shift><Control>f"
);
this
.
default_keymap
.
set
(
ACTION_WIN_FULLSCREEN
,
"F11"
);
this
.
default_keymap
.
set
(
ACTION_WIN_SHOW_HELP_OVERLAY
,
"<Control>question"
);
}
// Private constructor
private
Keymap
()
{}
private
static
Keymap
?
instance
=
null
;
...
...
@@ -73,7 +90,7 @@ public class Terminal.Keymap : Object, Json.Serializable {
return
instance
;
}
public
void
apply
(
unowned
Gtk
.
Application
app
)
{
public
void
apply
(
Gtk
.
Application
app
)
{
foreach
(
string
key
in
this
.
default_keymap
.
get_keys
())
{
// Get accelerators for this action from the user's keybindings or from
// the default map, in case the user hasn't specified one
...
...
@@ -105,6 +122,19 @@ public class Terminal.Keymap : Object, Json.Serializable {
this
.
keymap
.
@set
(
action
,
accel
);
}
public
void
reset_shortcut_for_action
(
string
action
)
{
string
[]?
_default
=
this
.
get_default_shortcut_for_action
(
action
);
if
(
_default
==
null
)
{
this
.
set_shortcut_for_action
(
action
,
null
);
}
else
{
foreach
(
unowned
string
shortcut
in
_default
)
{
this
.
set_shortcut_for_action
(
action
,
shortcut
);
}
}
}
public
override
bool
deserialize_property
(
string
name
,
out
Value
@value
,
...
...
src/widgets/HeaderBar.vala
View file @
4db8a0c4
...
...
@@ -27,8 +27,8 @@ namespace Terminal {
var
section1
=
new
GLib
.
Menu
();
var
section2
=
new
GLib
.
Menu
();
section1
.
append
(
_
(
"Fullscreen"
),
"win.fullscreen"
);
section1
.
append
(
_
(
"Preferences"
),
"win.edit_preferences"
);
section1
.
append
(
_
(
"Fullscreen"
),
ACTION_WIN_FULLSCREEN
);
section1
.
append
(
_
(
"Preferences"
),
ACTION_WIN_EDIT_PREFERENCES
);
section2
.
append
(
_
(
"Keyboard Shortcuts"
),
"win.show-help-overlay"
);
section2
.
append
(
_
(
"About"
),
"app.about"
);
more_menu
.
append_section
(
null
,
section1
);
...
...
src/widgets/ShortcutEditor.vala
View file @
4db8a0c4
...
...
@@ -33,16 +33,17 @@ public class Terminal.ShortcutEditor : Adw.PreferencesPage {
static
construct
{
action_map
=
new
Gee
.
HashMap
<
string
,
string
>
();
action_map
.
@set
(
"app.focus-next-tab"
,
_
(
"Focus Next Tab"
));
action_map
.
@set
(
"app.focus-previous-tab"
,
_
(
"Focus Previous Tab"
));
action_map
.
@set
(
"app.new-window"
,
_
(
"New Window"
));
action_map
.
@set
(
"win.switch-headerbar-mode"
,
_
(
"Toggle Header Bar"
));
action_map
.
@set
(
"win.new_tab"
,
_
(
"New Tab"
));
action_map
.
@set
(
"win.edit_preferences"
,
_
(
"Preferences"
));
action_map
.
@set
(
"win.copy"
,
_
(
"Copy"
));
action_map
.
@set
(
"win.paste"
,
_
(
"Paste"
));
action_map
.
@set
(
"win.search"
,
_
(
"Search"
));
action_map
.
@set
(
"win.fullscreen"
,
_
(
"Fullscreen"
));
action_map
.
@set
(
ACTION_FOCUS_NEXT_TAB
,
_
(
"Focus Next Tab"
));
action_map
.
@set
(
ACTION_FOCUS_PREVIOUS_TAB
,
_
(
"Focus Previous Tab"
));
action_map
.
@set
(
ACTION_NEW_WINDOW
,
_
(
"New Window"
));
action_map
.
@set
(
ACTION_WIN_SWITCH_HEADER_BAR_MODE
,
_
(
"Toggle Header Bar"
));
action_map
.
@set
(
ACTION_WIN_NEW_TAB
,
_
(
"New Tab"
));
action_map
.
@set
(
ACTION_WIN_EDIT_PREFERENCES
,
_
(
"Preferences"
));
action_map
.
@set
(
ACTION_WIN_COPY
,
_
(
"Copy"
));
action_map
.
@set
(
ACTION_WIN_PASTE
,
_
(
"Paste"
));
action_map
.
@set
(
ACTION_WIN_SEARCH
,
_
(
"Search"
));
action_map
.
@set
(
ACTION_WIN_FULLSCREEN
,
_
(
"Fullscreen"
));
action_map
.
@set
(
ACTION_WIN_SHOW_HELP_OVERLAY
,
_
(
"Keyboard Shortcuts"
));
}
construct
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment