From 24c386c67f42316c844e3133053eda180b5a051b Mon Sep 17 00:00:00 2001 From: Sven Eberhardt Date: Sun, 16 Oct 2016 09:52:48 -0400 Subject: [PATCH] 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. --- src/editor/C4ConsoleQtState.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/editor/C4ConsoleQtState.cpp b/src/editor/C4ConsoleQtState.cpp index 07109ca70..025c2cde1 100644 --- a/src/editor/C4ConsoleQtState.cpp +++ b/src/editor/C4ConsoleQtState.cpp @@ -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("%2").arg(filename).arg(basename)); // let's hope file names never contain " + link->setText(QString("%2").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))); }