Skip to content

Commit

Permalink
Track List: Add shortcut Ctrl-Return to the searchbar (#4141)
Browse files Browse the repository at this point in the history
* Track List: Add shortcut Ctrl-Return to the searchbar

Ctrl-Return in the searchbar enqueues the complete songlist

* Add config variable: browsers.searchbar_enqueue_limit

Update the track list and the paned browser to use this variable.

The actual confirmation request is implemented in QuodLibetWindow, and
the advanced_preferences plugin allows the user to configure the
limit, which defaults to 50.
  • Loading branch information
nemethf committed Oct 8, 2022
1 parent db3f9ba commit 9131401
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion quodlibet/browsers/paned/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def __sb_key_pressed(self, entry, event):
if (is_accel(event, "<Primary>Return") or
is_accel(event, "<Primary>KP_Enter")):
songs = app.window.songlist.get_songs()
app.window.playlist.enqueue(songs)
limit = config.getint("browsers", "searchbar_enqueue_limit")
app.window.enqueue(songs, limit)
return True
return False

Expand Down
12 changes: 12 additions & 0 deletions quodlibet/browsers/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

from gi.repository import Gtk, GLib

from quodlibet import app
from quodlibet import config
from quodlibet import qltk
from quodlibet import _
from quodlibet.browsers import Browser
from quodlibet.qltk import is_accel
from quodlibet.qltk.ccb import ConfigCheckMenuItem
from quodlibet.qltk.completion import LibraryTagCompletion
from quodlibet.qltk.menubutton import MenuButton
Expand Down Expand Up @@ -81,6 +83,7 @@ def __init__(self, library):

sbb.connect('query-changed', self.__text_parse)
sbb.connect('focus-out', self.__focus)
sbb.connect('key-press-event', self.__sb_key_pressed)
self._sb_box = sbb

prefs = PreferencesButton(sbb)
Expand Down Expand Up @@ -116,6 +119,15 @@ def activate(self):
def __text_parse(self, bar, text):
self.activate()

def __sb_key_pressed(self, entry, event):
if (is_accel(event, "<Primary>Return") or
is_accel(event, "<Primary>KP_Enter")):
songs = app.window.songlist.get_songs()
limit = config.getint("browsers", "searchbar_enqueue_limit")
app.window.enqueue(songs, limit)
return True
return False

def save(self):
config.settext("browsers", "query_text", self._get_text())
self._sb_box.save()
Expand Down
3 changes: 3 additions & 0 deletions quodlibet/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
# number of history entries in the search bar
"searchbar_historic_entries": "8",

# confirmation limit on enqueuing songs from the search bar
"searchbar_enqueue_limit": "50",

# panes in paned browser
"panes":
"~people\t<~year|[b][i]<~year>[/i][/b] - ><album>",
Expand Down
5 changes: 5 additions & 0 deletions quodlibet/ext/events/advanced_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ def changed(entry, name, section="settings"):
"browsers", "searchbar_historic_entries",
"Number of history entries in the search bar:",
"8 by default (restart advised)"),
int_config(
"browsers", "searchbar_enqueue_limit",
"Search bar confirmation limit for enqueue:",
("Maximal size of the song list that can be enqueued from "
"the search bar without confirmation.")),
slider_config(
"player", "playcount_minimum_length_proportion",
"Minimum length proportion to consider a track as played:",
Expand Down
30 changes: 30 additions & 0 deletions quodlibet/qltk/quodlibetwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from quodlibet import qltk
from quodlibet import util
from quodlibet import app
from quodlibet import ngettext
from quodlibet import _
from quodlibet.qltk.paned import ConfigRHPaned

Expand Down Expand Up @@ -756,6 +757,19 @@ def open_file(self, filename):
else:
return False

def enqueue(self, songs, limit=0):
"""Append `songs` to the queue
Ask for confimation if the number of songs exceeds `limit`.
"""

if len(songs) > limit:
dialog = ConfirmEnqueue(self, len(songs))
if dialog.run() != Gtk.ResponseType.YES:
return

self.playlist.enqueue(songs)

def __player_error(self, player, song, player_error):
# it's modal, but mmkeys etc. can still trigger new ones
if self._playback_error_dialog:
Expand Down Expand Up @@ -1386,3 +1400,19 @@ def __set_totals(self, info, songs):
t = self.browser.status_text(count=len(songs),
time=util.format_time_preferred(length))
self.statusbar.set_default_text(t)


class ConfirmEnqueue(qltk.Message):
def __init__(self, parent, count):
title = ngettext("Are you sure you want to enqueue %d song?",
"Are you sure you want to enqueue %d songs?",
count) % count
description = ""

super().__init__(
Gtk.MessageType.WARNING, parent, title, description,
Gtk.ButtonsType.NONE)

self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
self.add_icon_button(_("_Enqueue"), Icons.LIST_ADD,
Gtk.ResponseType.YES)

0 comments on commit 9131401

Please sign in to comment.