actions: add support for selecting found items
[ncmpcpp.git] / src / help.cpp
blob807fc580b0be05faff76d15f4e9a281a5c323da4
1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "mpdpp.h"
23 #include "bindings.h"
24 #include "global.h"
25 #include "help.h"
26 #include "settings.h"
27 #include "status.h"
28 #include "utility/wide_string.h"
29 #include "title.h"
30 #include "screen_switcher.h"
32 using Global::MainHeight;
33 using Global::MainStartY;
35 Help *myHelp;
37 namespace {
39 std::string display_keys(const Actions::Type at)
41 std::wstring result, skey;
42 for (auto it = Bindings.begin(); it != Bindings.end(); ++it)
44 for (auto j = it->second.begin(); j != it->second.end(); ++j)
46 if (j->isSingle() && j->action()->type() == at)
48 skey = keyToWString(it->first);
49 if (!skey.empty())
51 result += std::move(skey);
52 result += ' ';
57 size_t i = 0, len = 0;
58 const size_t max_len = 20;
59 for (; i < result.size(); ++i)
61 int width = std::max(1, wcwidth(result[i]));
62 if (len+width > max_len)
63 break;
64 else
65 len += width;
67 result.resize(i + max_len - len, ' ');
68 return ToString(result);
71 void section(NC::Scrollpad &w, const char *type_, const char *title_)
73 w << "\n " << NC::Format::Bold;
74 if (type_[0] != '\0')
75 w << type_ << " - ";
76 w << title_ << NC::Format::NoBold << "\n\n";
79 /**********************************************************************/
81 void key_section(NC::Scrollpad &w, const char *title_)
83 section(w, "Keys", title_);
86 void key(NC::Scrollpad &w, const Actions::Type at, const char *desc)
88 w << " " << display_keys(at) << " : " << desc << '\n';
91 void key(NC::Scrollpad &w, const Actions::Type at, const boost::format &desc)
93 w << " " << display_keys(at) << " : " << desc.str() << '\n';
96 /**********************************************************************/
98 void mouse_section(NC::Scrollpad &w, const char *title_)
100 section(w, "Mouse", title_);
103 void mouse(NC::Scrollpad &w, std::string action, const char *desc, bool indent = false)
105 action.resize(31 - (indent ? 2 : 0), ' ');
106 w << " " << (indent ? " " : "") << action;
107 w << ": " << desc << '\n';
110 void mouse_column(NC::Scrollpad &w, const char *column)
112 w << NC::Format::Bold << " " << column << " column:\n" << NC::Format::NoBold;
115 /**********************************************************************/
117 void write_bindings(NC::Scrollpad &w)
119 using Actions::Type;
121 key_section(w, "Movement");
122 key(w, Type::ScrollUp, "Move cursor up");
123 key(w, Type::ScrollDown, "Move cursor down");
124 key(w, Type::ScrollUpAlbum, "Move cursor up one album");
125 key(w, Type::ScrollDownAlbum, "Move cursor down one album");
126 key(w, Type::ScrollUpArtist, "Move cursor up one artist");
127 key(w, Type::ScrollDownArtist, "Move cursor down one artist");
128 key(w, Type::PageUp, "Page up");
129 key(w, Type::PageDown, "Page down");
130 key(w, Type::MoveHome, "Home");
131 key(w, Type::MoveEnd, "End");
132 w << '\n';
133 if (Config.screen_switcher_previous)
135 key(w, Type::NextScreen, "Switch between current and last screen");
136 key(w, Type::PreviousScreen, "Switch between current and last screen");
138 else
140 key(w, Type::NextScreen, "Switch to next screen in sequence");
141 key(w, Type::PreviousScreen, "Switch to previous screen in sequence");
143 key(w, Type::ShowHelp, "Show help");
144 key(w, Type::ShowPlaylist, "Show playlist");
145 key(w, Type::ShowBrowser, "Show browser");
146 key(w, Type::ShowSearchEngine, "Show search engine");
147 key(w, Type::ShowMediaLibrary, "Show media library");
148 key(w, Type::ShowPlaylistEditor, "Show playlist editor");
149 # ifdef HAVE_TAGLIB_H
150 key(w, Type::ShowTagEditor, "Show tag editor");
151 # endif // HAVE_TAGLIB_H
152 # ifdef ENABLE_OUTPUTS
153 key(w, Type::ShowOutputs, "Show outputs");
154 # endif // ENABLE_OUTPUTS
155 # ifdef ENABLE_VISUALIZER
156 key(w, Type::ShowVisualizer, "Show music visualizer");
157 # endif // ENABLE_VISUALIZER
158 # ifdef ENABLE_CLOCK
159 key(w, Type::ShowClock, "Show clock");
160 # endif // ENABLE_CLOCK
161 w << '\n';
162 key(w, Type::ShowServerInfo, "Show server info");
164 key_section(w, "Global");
165 key(w, Type::Stop, "Stop");
166 key(w, Type::Pause, "Pause");
167 key(w, Type::Next, "Next track");
168 key(w, Type::Previous, "Previous track");
169 key(w, Type::ReplaySong, "Replay playing song");
170 key(w, Type::SeekForward, "Seek forward in playing song");
171 key(w, Type::SeekBackward, "Seek backward in playing song");
172 key(w, Type::VolumeDown,
173 boost::format("Decrease volume by %1%%%") % Config.volume_change_step
175 key(w, Type::VolumeUp,
176 boost::format("Increase volume by %1%%%") % Config.volume_change_step
178 w << '\n';
179 key(w, Type::ToggleAddMode, "Toggle add mode (add or remove/always add)");
180 key(w, Type::ToggleMouse, "Toggle mouse support");
181 key(w, Type::SelectRange, "Select range");
182 key(w, Type::ReverseSelection, "Reverse selection");
183 key(w, Type::RemoveSelection, "Remove selection");
184 key(w, Type::SelectItem, "Select current item");
185 key(w, Type::SelectFoundItems, "Select found items");
186 key(w, Type::SelectAlbum, "Select songs of album around the cursor");
187 key(w, Type::AddSelectedItems, "Add selected items to playlist");
188 key(w, Type::AddRandomItems, "Add random items to playlist");
189 w << '\n';
190 key(w, Type::ToggleRepeat, "Toggle repeat mode");
191 key(w, Type::ToggleRandom, "Toggle random mode");
192 key(w, Type::ToggleSingle, "Toggle single mode");
193 key(w, Type::ToggleConsume, "Toggle consume mode");
194 key(w, Type::ToggleReplayGainMode, "Toggle replay gain mode");
195 key(w, Type::ToggleBitrateVisibility, "Toggle bitrate visibility");
196 key(w, Type::ToggleCrossfade, "Toggle crossfade mode");
197 key(w, Type::SetCrossfade, "Set crossfade");
198 key(w, Type::SetVolume, "Set volume");
199 key(w, Type::UpdateDatabase, "Start music database update");
200 w << '\n';
201 key(w, Type::ExecuteCommand, "Execute command");
202 key(w, Type::FindItemForward, "Find item forward");
203 key(w, Type::FindItemBackward, "Find item backward");
204 key(w, Type::PreviousFoundItem, "Jump to previous found item");
205 key(w, Type::NextFoundItem, "Jump to next found item");
206 key(w, Type::ToggleFindMode, "Toggle find mode (normal/wrapped)");
207 key(w, Type::JumpToBrowser, "Locate song in browser");
208 key(w, Type::JumpToMediaLibrary, "Locate song in media library");
209 key(w, Type::ToggleScreenLock, "Lock/unlock current screen");
210 key(w, Type::MasterScreen, "Switch to master screen (left one)");
211 key(w, Type::SlaveScreen, "Switch to slave screen (right one)");
212 # ifdef HAVE_TAGLIB_H
213 key(w, Type::JumpToTagEditor, "Locate song in tag editor");
214 # endif // HAVE_TAGLIB_H
215 key(w, Type::ToggleDisplayMode, "Toggle display mode");
216 key(w, Type::ToggleInterface, "Toggle user interface");
217 key(w, Type::ToggleSeparatorsBetweenAlbums, "Toggle displaying separators between albums");
218 key(w, Type::JumpToPositionInSong, "Jump to given position in playing song (formats: mm:ss, x%)");
219 key(w, Type::ShowSongInfo, "Show song info");
220 # ifdef HAVE_CURL_CURL_H
221 key(w, Type::ShowArtistInfo, "Show artist info");
222 key(w, Type::ToggleLyricsFetcher, "Toggle lyrics fetcher");
223 key(w, Type::ToggleFetchingLyricsInBackground, "Toggle fetching lyrics for playing songs in background");
224 # endif // HAVE_CURL_CURL_H
225 key(w, Type::ShowLyrics, "Show/hide song lyrics");
226 w << '\n';
227 key(w, Type::Quit, "Quit");
229 key_section(w, "Playlist");
230 key(w, Type::PressEnter, "Play selected item");
231 key(w, Type::DeletePlaylistItems, "Delete selected item(s) from playlist");
232 key(w, Type::ClearMainPlaylist, "Clear playlist");
233 key(w, Type::CropMainPlaylist, "Clear playlist except selected item(s)");
234 key(w, Type::SetSelectedItemsPriority, "Set priority of selected items");
235 key(w, Type::MoveSelectedItemsUp, "Move selected item(s) up");
236 key(w, Type::MoveSelectedItemsDown, "Move selected item(s) down");
237 key(w, Type::MoveSelectedItemsTo, "Move selected item(s) to cursor position");
238 key(w, Type::Add, "Add item to playlist");
239 # ifdef HAVE_TAGLIB_H
240 key(w, Type::EditSong, "Edit song");
241 # endif // HAVE_TAGLIB_H
242 key(w, Type::SavePlaylist, "Save playlist");
243 key(w, Type::Shuffle, "Shuffle range");
244 key(w, Type::SortPlaylist, "Sort range");
245 key(w, Type::ReversePlaylist, "Reverse range");
246 key(w, Type::JumpToPlayingSong, "Jump to current song");
247 key(w, Type::TogglePlayingSongCentering, "Toggle playing song centering");
249 key_section(w, "Browser");
250 key(w, Type::PressEnter, "Enter directory/Add item to playlist and play it");
251 key(w, Type::AddItemToPlaylist, "Add item to playlist");
252 # ifdef HAVE_TAGLIB_H
253 key(w, Type::EditSong, "Edit song");
254 # endif // HAVE_TAGLIB_H
255 key(w, Type::EditDirectoryName, "Edit directory name");
256 key(w, Type::EditPlaylistName, "Edit playlist name");
257 key(w, Type::ChangeBrowseMode, "Browse MPD database/local filesystem");
258 key(w, Type::ToggleBrowserSortMode, "Toggle sort mode");
259 key(w, Type::JumpToPlayingSong, "Locate playing song");
260 key(w, Type::JumpToParentDirectory, "Jump to parent directory");
261 key(w, Type::DeleteBrowserItems, "Delete selected items from disk");
262 key(w, Type::JumpToPlaylistEditor, "Jump to playlist editor (playlists only)");
264 key_section(w, "Search engine");
265 key(w, Type::PressEnter, "Add item to playlist and play it/change option");
266 key(w, Type::AddItemToPlaylist, "Add item to playlist");
267 # ifdef HAVE_TAGLIB_H
268 key(w, Type::EditSong, "Edit song");
269 # endif // HAVE_TAGLIB_H
270 key(w, Type::StartSearching, "Start searching");
271 key(w, Type::ResetSearchEngine, "Reset search constraints and clear results");
273 key_section(w, "Media library");
274 key(w, Type::ToggleMediaLibraryColumnsMode, "Switch between two/three columns mode");
275 key(w, Type::PreviousColumn, "Previous column");
276 key(w, Type::NextColumn, "Next column");
277 key(w, Type::PressEnter, "Add item to playlist and play it");
278 key(w, Type::AddItemToPlaylist, "Add item to playlist");
279 # ifdef HAVE_TAGLIB_H
280 key(w, Type::EditSong, "Edit song");
281 # endif // HAVE_TAGLIB_H
282 key(w, Type::EditLibraryTag, "Edit tag (left column)/album (middle/right column)");
283 key(w, Type::ToggleLibraryTagType, "Toggle type of tag used in left column");
284 key(w, Type::ToggleMediaLibrarySortMode, "Toggle sort mode");
286 key_section(w, "Playlist editor");
287 key(w, Type::PreviousColumn, "Previous column");
288 key(w, Type::NextColumn, "Next column");
289 key(w, Type::PressEnter, "Add item to playlist and play it");
290 key(w, Type::AddItemToPlaylist, "Add item to playlist");
291 # ifdef HAVE_TAGLIB_H
292 key(w, Type::EditSong, "Edit song");
293 # endif // HAVE_TAGLIB_H
294 key(w, Type::EditPlaylistName, "Edit playlist name");
295 key(w, Type::MoveSelectedItemsUp, "Move selected item(s) up");
296 key(w, Type::MoveSelectedItemsDown, "Move selected item(s) down");
297 key(w, Type::DeleteStoredPlaylist, "Delete selected playlists (left column)");
298 key(w, Type::DeletePlaylistItems, "Delete selected item(s) from playlist (right column)");
299 key(w, Type::ClearPlaylist, "Clear playlist");
300 key(w, Type::CropPlaylist, "Clear playlist except selected items");
302 key_section(w, "Lyrics");
303 key(w, Type::ToggleLyricsUpdateOnSongChange, "Toggle lyrics update on song change");
304 key(w, Type::EditLyrics, "Open lyrics in external editor");
305 key(w, Type::RefetchLyrics, "Refetch lyrics");
307 # ifdef HAVE_TAGLIB_H
308 key_section(w, "Tiny tag editor");
309 key(w, Type::PressEnter, "Edit tag");
310 key(w, Type::SaveTagChanges, "Save");
312 key_section(w, "Tag editor");
313 key(w, Type::PressEnter, "Edit tag/filename of selected item (left column)");
314 key(w, Type::PressEnter, "Perform operation on all/selected items (middle column)");
315 key(w, Type::PreviousColumn, "Previous column");
316 key(w, Type::NextColumn, "Next column");
317 key(w, Type::JumpToParentDirectory, "Jump to parent directory (left column, directories view)");
318 # endif // HAVE_TAGLIB_H
320 # ifdef ENABLE_OUTPUTS
321 key_section(w, "Outputs");
322 key(w, Type::PressEnter, "Toggle output");
323 # endif // ENABLE_OUTPUTS
325 # if defined(ENABLE_VISUALIZER) && defined(HAVE_FFTW3_H)
326 key_section(w, "Music visualizer");
327 key(w, Type::ToggleVisualizationType, "Toggle visualization type");
328 key(w, Type::SetVisualizerSampleMultiplier, "Set visualizer sample multiplier");
329 # endif // ENABLE_VISUALIZER && HAVE_FFTW3_H
331 mouse_section(w, "Global");
332 mouse(w, "Left click on \"Playing/Paused\"", "Play/pause");
333 mouse(w, "Left click on progressbar", "Jump to pointed position in playing song");
334 w << '\n';
335 mouse(w, "Mouse wheel on \"Volume: xx\"", "Adjust volume");
336 mouse(w, "Mouse wheel on main window", "Scroll");
338 mouse_section(w, "Playlist");
339 mouse(w, "Left click", "Select pointed item");
340 mouse(w, "Right click", "Play");
342 mouse_section(w, "Browser");
343 mouse(w, "Left click on directory", "Enter pointed directory");
344 mouse(w, "Right click on directory", "Add pointed directory to playlist");
345 w << '\n';
346 mouse(w, "Left click on song/playlist", "Add pointed item to playlist");
347 mouse(w, "Right click on song/playlist", "Add pointed item to playlist and play it");
349 mouse_section(w, "Search engine");
350 mouse(w, "Left click", "Highlight/switch value");
351 mouse(w, "Right click", "Change value");
353 mouse_section(w, "Media library");
354 mouse_column(w, "Left/middle");
355 mouse(w, "Left click", "Select pointed item", true);
356 mouse(w, "Right click", "Add item to playlist", true);
357 w << '\n';
358 mouse_column(w, "Right");
359 mouse(w, "Left Click", "Add pointed item to playlist", true);
360 mouse(w, "Right Click", "Add pointed item to playlist and play it", true);
362 mouse_section(w, "Playlist editor");
363 mouse_column(w, "Left");
364 mouse(w, "Left click", "Select pointed item", true);
365 mouse(w, "Right click", "Add item to playlist", true);
366 w << '\n';
367 mouse_column(w, "Right");
368 mouse(w, "Left click", "Add pointed item to playlist", true);
369 mouse(w, "Right click", "Add pointed item to playlist and play it", true);
371 # ifdef HAVE_TAGLIB_H
372 mouse_section(w, "Tiny tag editor");
373 mouse(w, "Left click", "Select option");
374 mouse(w, "Right click", "Set value/execute");
376 mouse_section(w, "Tag editor");
377 mouse_column(w, "Left");
378 mouse(w, "Left click", "Enter pointed directory/select pointed album", true);
379 mouse(w, "Right click", "Toggle view (directories/albums)", true);
380 w << '\n';
381 mouse_column(w, "Middle");
382 mouse(w, "Left click", "Select option", true);
383 mouse(w, "Right click", "Set value/execute", true);
384 w << '\n';
385 mouse_column(w, "Right");
386 mouse(w, "Left click", "Select pointed item", true);
387 mouse(w, "Right click", "Set value", true);
388 # endif // HAVE_TAGLIB_H
390 # ifdef ENABLE_OUTPUTS
391 mouse_section(w, "Outputs");
392 mouse(w, "Left click", "Select pointed output");
393 mouse(w, "Right click", "Toggle output");
394 # endif // ENABLE_OUTPUTS
396 section(w, "", "List of available colors");
397 for (int i = 0; i < COLORS; ++i)
398 w << NC::Color(i, NC::Color::transparent) << i+1 << NC::Color::End << " ";
403 Help::Help()
404 : Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
406 write_bindings(w);
407 w.flush();
410 void Help::resize()
412 size_t x_offset, width;
413 getWindowResizeParams(x_offset, width);
414 w.resize(width, MainHeight);
415 w.moveTo(x_offset, MainStartY);
416 hasToBeResized = 0;
419 void Help::switchTo()
421 SwitchTo::execute(this);
422 drawHeader();
425 std::wstring Help::title()
427 return L"Help";