This ensures the memory is freed when the pointers are removed. While
there was an explicit delete loop in the destructor, memory leaks could
occur when links were removed from the menu.
This avoids unnecessary copying.
Removed sectionName argument to addLink(), since its only caller didn't
provide a value for it, meaning it always defaulted.
Keeping it sorted when sections are inserted after startup improves the
user experience and if we have code for that already, we might as well
use it during startup too.
The code cannot deal with there being no sections. After startup,
there will always be sections for the built-in actions. But before
those are added the lack of sections could be fatal.
Under certain conditions, it was possible to get orderLinks() trigger a
segmentation fault or a SIGBUS; even if all the Link* and Linkapp*
pointers where correct, the compare_links() function would eventually
end up receiving an invalid pointer.
Apparently, the std::sort function *requires* that the assertion
compare_links(a, b) != compare_links(b, a) is always true, which was not
the case previously when a link was compared with itself.
Instead, consider the installation location non-deletable and the home
directory deletable. This makes the "deletable" property follow the
purpose of the directory rather than its implementation details.
The check I removed earlier today was redundant for readPackages() but
not so much for the Monitor: it starts a thread and it logs an error,
both of which are better avoided when possible.
Also cleaned up implementation of readPackages() a bit.
This avoids having to store the paths in an intermediate vector. Also
it allows us to do the writability check once per directory instead of
once per file.
Previously, it sorted before Link instances were created. Using
readLinks() ensures consistency and it might be more efficient if
a significant number of link files are rejected.
Also modernized the body of orderLinks() and removed unnecessary
special case for 1-link sections.
Before this change, it was possible to delete for example a link that
is stored on a read-only file system and it would disappear after
deletion but reappear as soon as the menu restarts.
This removes the need for a separate setAction method.
The default action is the empty action, which does nothing. However,
a touch event on a button with the empty action is no longer considered
handled.
Menu::btnContextMenu was changed from a unique_ptr to a plain data
member.
Use emplace_back when a new string is put into a vector.
Removed unused variables.
When searching section names, compare C++ string to C string, so we
don't need to construct a C++ string for the second string just for
the search.
When comparing full strings, operator== will do nicely.
When comparing the first char, "s[0] == c" is more efficient if we know
the string cannot be empty.
The constructor now has zero arguments. showDirectories and showFiles
are now set using setter methods.
FileLister::browse is now the sole way to start a scan for files and
directories, replacing the initial path in the constructor and the
setPath method. It allows merging results from multiple directories
as before.
This is all to make explicit how many times the costly task of browsing
a directory is actually carried out.
All calls to this method are in GMenu2X::initMenu() and they will only
pass valid indices, so the range check was redundant. Also the return
value was never used.
Added an assert to spot any invalid indices from future code.
In well-described fonts, this enables multi-line text (e.g. in manuals) to be
more readable.
The term "height" is also replaced with "line spacing" in Font's code.
Loading dynamically at startup is a very bad idea, as it
confuses the "load state before exiting" feature of GMenu2X:
the file selector will pass the file to a different program,
the cursor will move to select a different app, etc.
This reverts commit 5c631d610eabdf27c78693bdae566053166a791a.
The scroll bar always spans the content area of the screen: the
position and height depend only on the theme and not on who is
drawing it.
Note that the coordinates passed were wrong in most cases, so this
commit fixes the scroll bar positioning for several dialogs.
Previously, the links would scroll when the cursor was about to move
out of screen. By scrolling earlier, the user gets a view of the next
row before it becomes the current row. This allows a longer reaction
time to switch from vertical to horizontal navigation when looking for
a particular link in the grid.
This fixes a bug with the captured background being wrong when using
double buffering. Also it ensures that for example the clock in the
status bar is updated when the context menu is open.
All of the entries in the context menu affect sections and links, so
the context menu should be considered part of the main menu, not of
the global / background context.