Editor: Fix recent scenario display on welcome page if a recent entry was opened via path including Scenario.txt

Always show the name of the enclosing .ocs file.
directional-lights
Sven Eberhardt 2016-10-16 09:52:48 -04:00
parent cd9d6f5c6f
commit 24c386c67f
1 changed files with 13 additions and 2 deletions

View File

@ -1092,12 +1092,23 @@ void C4ConsoleGUIState::InitWelcomeScreen()
const char *filename = ::Config.Developer.RecentlyEditedSzenarios[i];
if (*filename && ::ItemExists(filename))
{
const char *basename = GetFilenameOnly(filename);
StdStrBuf basename(GetFilename(filename), true);
if (basename == C4CFN_ScenarioCore)
{
// If a Scenario.txt was opened, use the enclosing .ocs name
basename.Copy(filename, strlen(filename) - basename.getLength());
int32_t len = basename.getLength();
while (len && (basename.getData()[len - 1] == DirectorySeparator || basename.getData()[len - 1] == AltDirectorySeparator))
basename.SetLength(--len);
StdStrBuf base_folder_name(GetFilename(basename.getData()), true);
basename.Take(base_folder_name);
}
RemoveExtension(&basename);
QLabel *link = new QLabel(ui.welcomeScrollAreaWidgetContents);
ui.welcomeScrollLayout->insertWidget(++recent_idx, link);
link->setIndent(ui.welcomeOpenLabel->indent());
link->setTextInteractionFlags(ui.welcomeOpenLabel->textInteractionFlags());
link->setText(QString("<a href=\"open:%1\">%2</a>").arg(filename).arg(basename)); // let's hope file names never contain "
link->setText(QString("<a href=\"open:%1\">%2</a>").arg(filename).arg(basename.getData())); // let's hope file names never contain "
any_file = true;
window->connect(link, SIGNAL(linkActivated(QString)), window.get(), SLOT(WelcomeLinkActivated(QString)));
}