Skip to content

Commit

Permalink
Add action to focus search entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Wootten committed Dec 14, 2023
1 parent e195220 commit 19ab863
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ public class Music.Application : Gtk.Application {
public const string ACTION_PLAY_PAUSE = "action-play-pause";
public const string ACTION_PREVIOUS = "action-previous";
public const string ACTION_SHUFFLE = "action-shuffle";
public const string ACTION_FIND = "action-find";

private const ActionEntry[] ACTION_ENTRIES = {
{ ACTION_PLAY_PAUSE, action_play_pause, null, "false" },
{ ACTION_NEXT, action_next },
{ ACTION_PREVIOUS, action_previous },
{ ACTION_SHUFFLE, action_shuffle }
{ ACTION_SHUFFLE, action_shuffle },
{ ACTION_FIND, action_find }
};

private PlaybackManager? playback_manager = null;
Expand Down Expand Up @@ -47,6 +49,8 @@ public class Music.Application : Gtk.Application {
((SimpleAction) lookup_action (ACTION_PREVIOUS)).set_enabled (false);
((SimpleAction) lookup_action (ACTION_SHUFFLE)).set_enabled (false);

set_accels_for_action (ACTION_PREFIX + ACTION_FIND, {"<Ctrl>F"});

playback_manager = PlaybackManager.get_default ();

var mpris_id = Bus.own_name (
Expand Down Expand Up @@ -175,6 +179,10 @@ public class Music.Application : Gtk.Application {
playback_manager.shuffle ();
}

private void action_find () {
((MainWindow)active_window).start_search ();
}

private void on_bus_acquired (DBusConnection connection, string name) {
try {
connection.register_object ("/org/mpris/MediaPlayer2", new MprisRoot ());
Expand Down
9 changes: 8 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
private Gtk.Button shuffle_button;
private Settings settings;
private Gtk.SearchEntry search_entry;
private Gtk.Revealer search_revealer;

construct {
var playback_manager = PlaybackManager.get_default ();
Expand All @@ -25,7 +26,7 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
placeholder_text = _("Search titles in playlist")
};

var search_revealer = new Gtk.Revealer () {
search_revealer = new Gtk.Revealer () {
child = search_entry
};

Expand Down Expand Up @@ -191,6 +192,12 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
});
}

public void start_search () {
if (search_revealer.child_revealed) {
search_entry.grab_focus ();
}
}

//Array concatenation not permitted for parameters so use a list instead
private void prepend_directory_files (GLib.File dir, ref SList<File> file_list) {
try {
Expand Down

0 comments on commit 19ab863

Please sign in to comment.