From 11fbf1a9288bf68457c243f311b1e4a86968bcec Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Sat, 25 Jan 2025 16:54:33 +0100 Subject: [PATCH] feat: Various command palette improvements --- CHANGELOG.md | 1 + src/Core/Themes/Sunrise/Alfred/View.elm | 4 +- src/Core/UI/Adjunct.elm | 14 +++ src/Core/UI/Alfred/State.elm | 20 ++- src/Core/UI/Commands/Alfred.elm | 156 ++++++++++++++++-------- 5 files changed, 139 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b5ca629..19a744cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - **Basic setup for themes**. - No longer resets shuffle history when the collection or search changes. - WebDAV improvements. +- Command palette improvements. - Directory playlists now work correctly with sources that specify a sub directory. - Fixed issue with missing extensions when downloading playlists. - Removed Fission/Webnative user layer (discontinued). diff --git a/src/Core/Themes/Sunrise/Alfred/View.elm b/src/Core/Themes/Sunrise/Alfred/View.elm index afddc1cb..bf799c0f 100644 --- a/src/Core/Themes/Sunrise/Alfred/View.elm +++ b/src/Core/Themes/Sunrise/Alfred/View.elm @@ -7,7 +7,7 @@ import Conditional exposing (ifThenElse) import Html exposing (Html, text) import Html.Attributes exposing (attribute, autofocus, id, placeholder, style, type_) import Html.Events exposing (onInput) -import Html.Ext exposing (onTapPreventDefault) +import Html.Ext exposing (onTapPreventDefault, onTapStopPropagation) import Json.Decode import Material.Icons.Round as Icons import Material.Icons.Types exposing (Coloring(..)) @@ -205,7 +205,7 @@ groupView bgColor instance group indexBase = itemView bgColor instance idx item = brick - [ onTapPreventDefault (UI.SelectAlfredItem idx) + [ onTapStopPropagation (UI.SelectAlfredItem idx) -- , if idx == instance.focus then diff --git a/src/Core/UI/Adjunct.elm b/src/Core/UI/Adjunct.elm index 69faf3a2..46e2ffdb 100644 --- a/src/Core/UI/Adjunct.elm +++ b/src/Core/UI/Adjunct.elm @@ -52,6 +52,19 @@ keyboardInput msg model = [ Keyboard.Escape ] -> hideOverlay m + -- Meta key + -- + [ Keyboard.Character "K", Keyboard.Meta ] -> + Commands.showPalette m + + -- Ctrl key + -- + [ Keyboard.Character "K", Keyboard.Control ] -> + Commands.showPalette m + + [ Keyboard.Character "L", Keyboard.Control ] -> + Playlists.assistWithSelectingPlaylist m + _ -> skip @@ -69,6 +82,7 @@ keyboardInput msg model = -- -- [ Keyboard.Character "}", Keyboard.Shift, Keyboard.Control ] -> -- Audio.seek ((m.audioPosition + 10) / m.audioDuration) m + -- -- Meta key -- [ Keyboard.Character "K", Keyboard.Meta ] -> diff --git a/src/Core/UI/Alfred/State.elm b/src/Core/UI/Alfred/State.elm index b9eacb44..0e646ebd 100644 --- a/src/Core/UI/Alfred/State.elm +++ b/src/Core/UI/Alfred/State.elm @@ -2,6 +2,7 @@ module UI.Alfred.State exposing (..) import Alfred exposing (Alfred) import Browser.Dom as Dom +import Keyboard import Process import Return exposing (return) import Return.Ext as Return @@ -15,14 +16,31 @@ import UI.Types as UI exposing (Manager) assign : Alfred UI.Msg -> Manager assign instance model = + let + pressedKeys = + List.filter + (\k -> + case k of + Keyboard.Meta -> + True + + Keyboard.Control -> + True + + _ -> + False + ) + model.pressedKeys + in 250 |> Process.sleep |> Task.andThen (\_ -> Dom.focus "diffuse__alfred") + |> Task.andThen (\_ -> Dom.setViewportOf "alfred__results" 0 0) |> Task.attempt (\_ -> UI.Bypass) -- The "K" key seems to stick when using CMD + K, -- aka. Meta key + K, to show the command palette. -- https://github.com/ohanhi/keyboard/issues/14 - |> return { model | alfred = Just instance, pressedKeys = [] } + |> return { model | alfred = Just instance, pressedKeys = pressedKeys } gotInput : String -> Manager diff --git a/src/Core/UI/Commands/Alfred.elm b/src/Core/UI/Commands/Alfred.elm index 83693de4..a117ea00 100644 --- a/src/Core/UI/Commands/Alfred.elm +++ b/src/Core/UI/Commands/Alfred.elm @@ -31,6 +31,8 @@ commands : UI.Model -> List (Alfred.Group UI.Msg) commands model = [ { name = Just "Currently playing", items = nowPlayingCommands model } , { name = Just "Track selection", items = selectionCommands model } + , { name = Just "Collection / Playlist", items = playlistCommands model } + , { name = Just "Tracks", items = tracksCommands model } , { name = Just "View", items = viewCommands model } , { name = Just "Playback", items = playbackCommands model } , { name = Just "Sources", items = sourcesCommands model } @@ -49,11 +51,11 @@ dataCommands model = , value = Command (UI.TracksMsg Tracks.ClearCache) } , { icon = Just (Icons.save 16) - , title = "Export data" + , title = "Download data snapshot" , value = Command UI.Export } , { icon = Just (Icons.save 16) - , title = "Import data (⚠️ will override current data)" + , title = "Import data snapshot (⚠️ will override current data)" , value = Command UI.RequestImport } ] @@ -154,6 +156,29 @@ playbackCommands model = ] +playlistCommands model = + let + selection = + case model.selectedPlaylist of + Just playlist -> + [ -- DeselectPlaylist + { icon = Just (Icons.waves 16) + , title = "Deactivate " ++ ifThenElse playlist.collection "collection" "playlist" + , value = Command UI.DeselectPlaylist + } + ] + + Nothing -> + [] + in + selection + ++ [ { icon = Just (Icons.waves 16) + , title = "Select collection or playlist" + , value = Command UI.AssistWithSelectingPlaylist + } + ] + + selectionCommands model = let ( selection, _, amountOfFavs ) = @@ -229,45 +254,8 @@ sourcesCommands model = ] -viewCommands model = +tracksCommands model = let - sortCommands = - (case Maybe.andThen .autoGenerated model.selectedPlaylist of - Nothing -> - [] - - _ -> - case model.scene of - Tracks.Covers -> - [ Album, Artist ] - - Tracks.List -> - [ Album, Artist, Title ] - ) - |> List.remove - model.sortBy - |> List.map - (\sortBy -> - { icon = - Just (Icons.sort 16) - , title = - case sortBy of - Artist -> - "Sort tracks by artist" - - Album -> - "Sort tracks by album" - - PlaylistIndex -> - "Sort tracks by playlist index" - - Title -> - "Sort tracks by title" - , value = - Command (UI.TracksMsg <| Tracks.SortBy sortBy) - } - ) - groupCommands = [ AddedOn, Directory, FirstAlphaCharacter, TrackYear ] |> (case model.grouping of @@ -311,17 +299,81 @@ viewCommands model = list ) in - [ { icon = Just (Icons.brush 14) - , title = "Change application theme" - , value = Command UI.AssistWithChangingTheme - } - , { icon = Just (Icons.favorite 14) + [ { icon = Just (Icons.favorite 14) , title = toggle model.favouritesOnly "favourites-only mode" , value = Command (UI.TracksMsg Tracks.ToggleFavouritesOnly) } -- - , case model.scene of + , { icon = Just (Icons.filter_list 16) + , title = toggle model.cachedTracksOnly "cached-tracks-only mode" + , value = Command (UI.TracksMsg Tracks.ToggleCachedOnly) + } + ] + ++ groupCommands + ++ [ { icon = Just (Icons.filter_list 16) + , title = + if model.hideDuplicates then + "Allow duplicates" + + else + "Remove duplicates" + , value = Command (UI.TracksMsg Tracks.ToggleHideDuplicates) + } + + -- + , { icon = Just (Icons.photo 16) + , title = + if model.coverSelectionReducesPool then + "Track pool is limited to selected cover (Select to disable)" + + else + "Track pool is not restricted by selected cover (Select to enable)" + , value = Command (UI.TracksMsg Tracks.ToggleCoverSelectionReducesPool) + } + ] + + +viewCommands model = + let + sortCommands = + (case Maybe.andThen .autoGenerated model.selectedPlaylist of + Nothing -> + [] + + _ -> + case model.scene of + Tracks.Covers -> + [ Album, Artist ] + + Tracks.List -> + [ Album, Artist, Title ] + ) + |> List.remove + model.sortBy + |> List.map + (\sortBy -> + { icon = + Just (Icons.sort 16) + , title = + case sortBy of + Artist -> + "Sort tracks by artist" + + Album -> + "Sort tracks by album" + + PlaylistIndex -> + "Sort tracks by playlist index" + + Title -> + "Sort tracks by title" + , value = + Command (UI.TracksMsg <| Tracks.SortBy sortBy) + } + ) + in + [ case model.scene of Tracks.Covers -> { icon = Just (Icons.notes 16) , title = "Switch to list view" @@ -334,12 +386,6 @@ viewCommands model = , value = Command (UI.TracksMsg <| Tracks.ChangeScene Tracks.Covers) } - -- - , { icon = Just (Icons.filter_list 16) - , title = ifThenElse model.cachedTracksOnly "Disable cached-tracks-only mode" "Only show cached tracks" - , value = Command (UI.TracksMsg Tracks.ToggleCachedOnly) - } - -- , { icon = Just (Icons.sort 16) , title = "Change sort direction" @@ -347,7 +393,11 @@ viewCommands model = } ] ++ sortCommands - ++ groupCommands + ++ [ { icon = Just (Icons.brush 14) + , title = "Change application theme" + , value = Command UI.AssistWithChangingTheme + } + ] -- 2.51.2