@@ -140,7 +140,23 @@ bool Sky::init()
140140
141141 skyList = new ui::SelectionList (skyGroup, " Sky" );
142142 skyList->setCallback ([this ](int selection)
143- { setSky (skyList->items ()[selection]); });
143+ {
144+ if (selection >= skyListNameStart)
145+ {
146+ setSkyEntry (m_skies[selection - skyListNameStart]);
147+ }
148+ else if (selection == 0 )
149+ {
150+ setSkyDisabled ();
151+ }
152+ else if (selection == 1 )
153+ {
154+ setSkyAuto ();
155+ }
156+ else if (selection == 2 )
157+ {
158+ setSkyEphemeris ();
159+ } });
144160
145161 skyPath = configString (" sky" , " skyDir" , " /data/Geodata/sky" )->value ();
146162 loadSkies ();
@@ -259,7 +275,6 @@ std::optional<std::reference_wrapper<SkyEntry>> Sky::addSkyFile(std::filesystem:
259275
260276 auto relative = std::filesystem::relative (path, std::filesystem::path (skyPath)).string ();
261277 std::string name = relative.substr (0 , relative.length () - extension.length ());
262- name = std::regex_replace (name, std::regex (" /" ), " → " );
263278
264279 // Transform extension to lower case
265280 std::transform (extension.begin (), extension.end (), extension.begin (),
@@ -283,6 +298,7 @@ std::optional<std::reference_wrapper<SkyEntry>> Sky::addSkyFile(std::filesystem:
283298
284299 return m_skies.emplace_back (SkyEntry {
285300 .name = name,
301+ .displayName = std::regex_replace (name, std::regex (" /" ), " → " ),
286302 .fileName = path.string (),
287303 .longitude = longitude,
288304 .latitude = latitude,
@@ -308,9 +324,10 @@ void Sky::updateSkyMenu()
308324 " Ephemeris" ,
309325#endif
310326 };
327+ skyListNameStart = skyNames.size ();
311328 for (const auto &sky : m_skies)
312329 {
313- skyNames.push_back (sky.name );
330+ skyNames.push_back (sky.displayName );
314331 }
315332 skyList->setList (skyNames);
316333}
@@ -383,37 +400,32 @@ void Sky::setSkyTexture(std::string_view nameOrFile)
383400{
384401 removeExistingSky ();
385402
386- SkyEntry *sky_ptr = nullptr ;
387-
388403 for (auto &it : m_skies)
389404 {
390- if (it.fileName == nameOrFile || it.name == nameOrFile) // already have this file in the list
405+ if (it.fileName == nameOrFile || it.name == nameOrFile || it. displayName == nameOrFile ) // already have this file in the list
391406 {
392- sky_ptr = ⁢
407+ setSkyEntry (it);
408+ return ;
393409 }
394410 }
395411
396412 // If we did not find a sky with this name (or filename), try to add it
397- if (!sky_ptr)
413+ auto addedSky = addSkyFile (nameOrFile);
414+ if (addedSky)
398415 {
399- auto addedSky = addSkyFile (nameOrFile);
400- if (addedSky)
401- {
402- updateSkyMenu ();
403- sky_ptr = &(addedSky->get ());
404- }
416+ updateSkyMenu ();
417+ setSkyEntry (addedSky->get ());
405418 }
419+ }
406420
407- // Still no sky (adding was unsuccessful) -- do nothing.
408- if (!sky_ptr)
409- return ;
410-
411- SkyEntry &sky = *sky_ptr;
421+ void Sky::setSkyEntry (SkyEntry &sky)
422+ {
423+ removeExistingSky ();
412424
413425 // Choose the corresponding item in the menu
414- auto l = skyList->items ();
426+ const auto & l = skyList->items ();
415427 skyList->select (std::find_if (l.begin (), l.end (), [sky](const auto &it)
416- { return it == sky.name ; })
428+ { return it == sky.name || it == sky. displayName ; })
417429 - l.begin ());
418430
419431 if (sky.texture == nullptr )
0 commit comments