actions: add support for range selection and make a few actions work on ranges
[ncmpcpp.git] / src / help.cpp
blob98e40558c3cdbe8df5f99e8233c34b103486128c
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::SelectAlbum, "Select songs of album around the cursor");
186 key(w, Type::AddSelectedItems, "Add selected items to playlist");
187 key(w, Type::AddRandomItems, "Add random items to playlist");
188 w << '\n';
189 key(w, Type::ToggleRepeat, "Toggle repeat mode");
190 key(w, Type::ToggleRandom, "Toggle random mode");
191 key(w, Type::ToggleSingle, "Toggle single mode");
192 key(w, Type::ToggleConsume, "Toggle consume mode");
193 key(w, Type::ToggleReplayGainMode, "Toggle replay gain mode");
194 key(w, Type::ToggleBitrateVisibility, "Toggle bitrate visibility");
195 key(w, Type::ToggleCrossfade, "Toggle crossfade mode");
196 key(w, Type::SetCrossfade, "Set crossfade");
197 key(w, Type::SetVolume, "Set volume");
198 key(w, Type::UpdateDatabase, "Start music database update");
199 w << '\n';
200 key(w, Type::ExecuteCommand, "Execute command");
201 key(w, Type::FindItemForward, "Find item forward");
202 key(w, Type::FindItemBackward, "Find item backward");
203 key(w, Type::PreviousFoundItem, "Jump to previous found item");
204 key(w, Type::NextFoundItem, "Jump to next found item");
205 key(w, Type::ToggleFindMode, "Toggle find mode (normal/wrapped)");
206 key(w, Type::JumpToBrowser, "Locate song in browser");
207 key(w, Type::JumpToMediaLibrary, "Locate song in media library");
208 key(w, Type::ToggleScreenLock, "Lock/unlock current screen");
209 key(w, Type::MasterScreen, "Switch to master screen (left one)");
210 key(w, Type::SlaveScreen, "Switch to slave screen (right one)");
211 # ifdef HAVE_TAGLIB_H
212 key(w, Type::JumpToTagEditor, "Locate song in tag editor");
213 # endif // HAVE_TAGLIB_H
214 key(w, Type::ToggleDisplayMode, "Toggle display mode");
215 key(w, Type::ToggleInterface, "Toggle user interface");
216 key(w, Type::ToggleSeparatorsBetweenAlbums, "Toggle displaying separators between albums");
217 key(w, Type::JumpToPositionInSong, "Jump to given position in playing song (formats: mm:ss, x%)");
218 key(w, Type::ShowSongInfo, "Show song info");
219 # ifdef HAVE_CURL_CURL_H
220 key(w, Type::ShowArtistInfo, "Show artist info");
221 key(w, Type::ToggleLyricsFetcher, "Toggle lyrics fetcher");
222 key(w, Type::ToggleFetchingLyricsInBackground, "Toggle fetching lyrics for playing songs in background");
223 # endif // HAVE_CURL_CURL_H
224 key(w, Type::ShowLyrics, "Show/hide song lyrics");
225 w << '\n';
226 key(w, Type::Quit, "Quit");
228 key_section(w, "Playlist");
229 key(w, Type::PressEnter, "Play selected item");
230 key(w, Type::DeletePlaylistItems, "Delete selected item(s) from playlist");
231 key(w, Type::ClearMainPlaylist, "Clear playlist");
232 key(w, Type::CropMainPlaylist, "Clear playlist except selected item(s)");
233 key(w, Type::SetSelectedItemsPriority, "Set priority of selected items");
234 key(w, Type::MoveSelectedItemsUp, "Move selected item(s) up");
235 key(w, Type::MoveSelectedItemsDown, "Move selected item(s) down");
236 key(w, Type::MoveSelectedItemsTo, "Move selected item(s) to cursor position");
237 key(w, Type::Add, "Add item to playlist");
238 # ifdef HAVE_TAGLIB_H
239 key(w, Type::EditSong, "Edit song");
240 # endif // HAVE_TAGLIB_H
241 key(w, Type::SavePlaylist, "Save playlist");
242 key(w, Type::Shuffle, "Shuffle range");
243 key(w, Type::SortPlaylist, "Sort range");
244 key(w, Type::ReversePlaylist, "Reverse range");
245 key(w, Type::JumpToPlayingSong, "Jump to current song");
246 key(w, Type::TogglePlayingSongCentering, "Toggle playing song centering");
248 key_section(w, "Browser");
249 key(w, Type::PressEnter, "Enter directory/Add item to playlist and play it");
250 key(w, Type::AddItemToPlaylist, "Add item to playlist");
251 # ifdef HAVE_TAGLIB_H
252 key(w, Type::EditSong, "Edit song");
253 # endif // HAVE_TAGLIB_H
254 key(w, Type::EditDirectoryName, "Edit directory name");
255 key(w, Type::EditPlaylistName, "Edit playlist name");
256 key(w, Type::ChangeBrowseMode, "Browse MPD database/local filesystem");
257 key(w, Type::ToggleBrowserSortMode, "Toggle sort mode");
258 key(w, Type::JumpToPlayingSong, "Locate playing song");
259 key(w, Type::JumpToParentDirectory, "Jump to parent directory");
260 key(w, Type::DeleteBrowserItems, "Delete selected items from disk");
261 key(w, Type::JumpToPlaylistEditor, "Jump to playlist editor (playlists only)");
263 key_section(w, "Search engine");
264 key(w, Type::PressEnter, "Add item to playlist and play it/change option");
265 key(w, Type::AddItemToPlaylist, "Add item to playlist");
266 # ifdef HAVE_TAGLIB_H
267 key(w, Type::EditSong, "Edit song");
268 # endif // HAVE_TAGLIB_H
269 key(w, Type::StartSearching, "Start searching");
270 key(w, Type::ResetSearchEngine, "Reset search constraints and clear results");
272 key_section(w, "Media library");
273 key(w, Type::ToggleMediaLibraryColumnsMode, "Switch between two/three columns mode");
274 key(w, Type::PreviousColumn, "Previous column");
275 key(w, Type::NextColumn, "Next column");
276 key(w, Type::PressEnter, "Add item to playlist and play it");
277 key(w, Type::AddItemToPlaylist, "Add item to playlist");
278 # ifdef HAVE_TAGLIB_H
279 key(w, Type::EditSong, "Edit song");
280 # endif // HAVE_TAGLIB_H
281 key(w, Type::EditLibraryTag, "Edit tag (left column)/album (middle/right column)");
282 key(w, Type::ToggleLibraryTagType, "Toggle type of tag used in left column");
283 key(w, Type::ToggleMediaLibrarySortMode, "Toggle sort mode");
285 key_section(w, "Playlist editor");
286 key(w, Type::PreviousColumn, "Previous column");
287 key(w, Type::NextColumn, "Next column");
288 key(w, Type::PressEnter, "Add item to playlist and play it");
289 key(w, Type::AddItemToPlaylist, "Add item to playlist");
290 # ifdef HAVE_TAGLIB_H
291 key(w, Type::EditSong, "Edit song");
292 # endif // HAVE_TAGLIB_H
293 key(w, Type::EditPlaylistName, "Edit playlist name");
294 key(w, Type::MoveSelectedItemsUp, "Move selected item(s) up");
295 key(w, Type::MoveSelectedItemsDown, "Move selected item(s) down");
296 key(w, Type::DeleteStoredPlaylist, "Delete selected playlists (left column)");
297 key(w, Type::DeletePlaylistItems, "Delete selected item(s) from playlist (right column)");
298 key(w, Type::ClearPlaylist, "Clear playlist");
299 key(w, Type::CropPlaylist, "Clear playlist except selected items");
301 key_section(w, "Lyrics");
302 key(w, Type::ToggleLyricsUpdateOnSongChange, "Toggle lyrics update on song change");
303 key(w, Type::EditLyrics, "Open lyrics in external editor");
304 key(w, Type::RefetchLyrics, "Refetch lyrics");
306 # ifdef HAVE_TAGLIB_H
307 key_section(w, "Tiny tag editor");
308 key(w, Type::PressEnter, "Edit tag");
309 key(w, Type::SaveTagChanges, "Save");
311 key_section(w, "Tag editor");
312 key(w, Type::PressEnter, "Edit tag/filename of selected item (left column)");
313 key(w, Type::PressEnter, "Perform operation on all/selected items (middle column)");
314 key(w, Type::PreviousColumn, "Previous column");
315 key(w, Type::NextColumn, "Next column");
316 key(w, Type::JumpToParentDirectory, "Jump to parent directory (left column, directories view)");
317 # endif // HAVE_TAGLIB_H
319 # ifdef ENABLE_OUTPUTS
320 key_section(w, "Outputs");
321 key(w, Type::PressEnter, "Toggle output");
322 # endif // ENABLE_OUTPUTS
324 # if defined(ENABLE_VISUALIZER) && defined(HAVE_FFTW3_H)
325 key_section(w, "Music visualizer");
326 key(w, Type::ToggleVisualizationType, "Toggle visualization type");
327 key(w, Type::SetVisualizerSampleMultiplier, "Set visualizer sample multiplier");
328 # endif // ENABLE_VISUALIZER && HAVE_FFTW3_H
330 mouse_section(w, "Global");
331 mouse(w, "Left click on \"Playing/Paused\"", "Play/pause");
332 mouse(w, "Left click on progressbar", "Jump to pointed position in playing song");
333 w << '\n';
334 mouse(w, "Mouse wheel on \"Volume: xx\"", "Adjust volume");
335 mouse(w, "Mouse wheel on main window", "Scroll");
337 mouse_section(w, "Playlist");
338 mouse(w, "Left click", "Select pointed item");
339 mouse(w, "Right click", "Play");
341 mouse_section(w, "Browser");
342 mouse(w, "Left click on directory", "Enter pointed directory");
343 mouse(w, "Right click on directory", "Add pointed directory to playlist");
344 w << '\n';
345 mouse(w, "Left click on song/playlist", "Add pointed item to playlist");
346 mouse(w, "Right click on song/playlist", "Add pointed item to playlist and play it");
348 mouse_section(w, "Search engine");
349 mouse(w, "Left click", "Highlight/switch value");
350 mouse(w, "Right click", "Change value");
352 mouse_section(w, "Media library");
353 mouse_column(w, "Left/middle");
354 mouse(w, "Left click", "Select pointed item", true);
355 mouse(w, "Right click", "Add item to playlist", true);
356 w << '\n';
357 mouse_column(w, "Right");
358 mouse(w, "Left Click", "Add pointed item to playlist", true);
359 mouse(w, "Right Click", "Add pointed item to playlist and play it", true);
361 mouse_section(w, "Playlist editor");
362 mouse_column(w, "Left");
363 mouse(w, "Left click", "Select pointed item", true);
364 mouse(w, "Right click", "Add item to playlist", true);
365 w << '\n';
366 mouse_column(w, "Right");
367 mouse(w, "Left click", "Add pointed item to playlist", true);
368 mouse(w, "Right click", "Add pointed item to playlist and play it", true);
370 # ifdef HAVE_TAGLIB_H
371 mouse_section(w, "Tiny tag editor");
372 mouse(w, "Left click", "Select option");
373 mouse(w, "Right click", "Set value/execute");
375 mouse_section(w, "Tag editor");
376 mouse_column(w, "Left");
377 mouse(w, "Left click", "Enter pointed directory/select pointed album", true);
378 mouse(w, "Right click", "Toggle view (directories/albums)", true);
379 w << '\n';
380 mouse_column(w, "Middle");
381 mouse(w, "Left click", "Select option", true);
382 mouse(w, "Right click", "Set value/execute", true);
383 w << '\n';
384 mouse_column(w, "Right");
385 mouse(w, "Left click", "Select pointed item", true);
386 mouse(w, "Right click", "Set value", true);
387 # endif // HAVE_TAGLIB_H
389 # ifdef ENABLE_OUTPUTS
390 mouse_section(w, "Outputs");
391 mouse(w, "Left click", "Select pointed output");
392 mouse(w, "Right click", "Toggle output");
393 # endif // ENABLE_OUTPUTS
395 section(w, "", "List of available colors");
396 for (int i = 0; i < COLORS; ++i)
397 w << NC::Color(i, NC::Color::transparent) << i+1 << NC::Color::End << " ";
402 Help::Help()
403 : Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
405 write_bindings(w);
406 w.flush();
409 void Help::resize()
411 size_t x_offset, width;
412 getWindowResizeParams(x_offset, width);
413 w.resize(width, MainHeight);
414 w.moveTo(x_offset, MainStartY);
415 hasToBeResized = 0;
418 void Help::switchTo()
420 SwitchTo::execute(this);
421 drawHeader();
424 std::wstring Help::title()
426 return L"Help";