@@ -758,7 +758,7 @@ bool TreeNode::IsNetworkLocation() const
758758
759759
760760FileDialog::FileDialog (DialogMode mode, const tSystem::tFileTypes& fileTypes) :
761- PopupJustOpened (false ),
761+ DoPopulate (false ),
762762 Mode(mode),
763763 FileTypes(fileTypes),
764764 RootTreeNode(nullptr ),
@@ -810,7 +810,7 @@ void FileDialog::OpenPopup(const tString& openDir, const tString& saveFileBaseNa
810810 break ;
811811 }
812812
813- PopupJustOpened = true ;
813+ DoPopulate = true ;
814814}
815815
816816
@@ -1097,6 +1097,28 @@ void FileDialog::DoSelectable(ContentItem* item)
10971097}
10981098
10991099
1100+ void FileDialog::DoSelect (const tString& filename)
1101+ {
1102+ // Only allowed one selected max. Clear the others.
1103+ for (ContentItem* i = SelectedNode->Contents .First (); i; i = i->Next ())
1104+ {
1105+ if (i->Name == filename)
1106+ {
1107+ i->Selected = true ;
1108+
1109+ // If item just selected and we're in SaveFile mode we need to update the Edit widget.
1110+ // This widget uses the SaveFileResult string, so we update that.
1111+ if (Mode == DialogMode::SaveFile)
1112+ SaveFileResult = tGetFileBaseName (filename).Chr ();
1113+ }
1114+ else
1115+ {
1116+ i->Selected = false ;
1117+ }
1118+ }
1119+ }
1120+
1121+
11001122tStringItem* FileDialog::BookmarksLoop ()
11011123{
11021124 int flags =
@@ -1245,24 +1267,41 @@ void FileDialog::DoRefresh(tStringItem*& destPathItemName, bool& setYScrollToSel
12451267}
12461268
12471269
1248- bool FileDialog::SetPath (const tString& dirPath )
1270+ bool FileDialog::SetPath (const tString& path )
12491271{
12501272 if (!IsPopupOpen ())
12511273 return false ;
1252- tString normDirPath = dirPath;
1253- tPathStdDir (normDirPath);
1254- if (!tDirExists (normDirPath))
1274+ tString normPath = path;
1275+
1276+ tPathStd (normPath);
1277+
1278+ // Is the path a file or just a directory?
1279+ tString dir;
1280+ tString file;
1281+ if (tFileExists (normPath))
1282+ {
1283+ dir = tGetDir (normPath);
1284+ file = tGetFileName (normPath);
1285+ }
1286+ else if (tDirExists (normPath))
1287+ {
1288+ dir = normPath;
1289+ }
1290+ if (dir.IsEmpty ())
12551291 return false ;
12561292
1293+ // "C:\GitHub\tacent\UnitTests\TestData\Images\Bmp_Lambda.bmp"
1294+
12571295 switch (Mode)
12581296 {
1259- case DialogMode::OpenFile: DirToPath (ConfigOpenFilePath, normDirPath ); break ;
1260- case DialogMode::OpenDir: DirToPath (ConfigOpenDirPath, normDirPath ); break ;
1261- case DialogMode::SaveFile: DirToPath (ConfigSaveFilePath, normDirPath ); break ;
1297+ case DialogMode::OpenFile: DirToPath (ConfigOpenFilePath, dir ); break ;
1298+ case DialogMode::OpenDir: DirToPath (ConfigOpenDirPath, dir ); break ;
1299+ case DialogMode::SaveFile: DirToPath (ConfigSaveFilePath, dir ); break ;
12621300 }
12631301
1264- // @wip This seems like a bit of a workaround that needs more thought.
1265- PopupJustOpened = true ;
1302+ DoPopulate = true ;
1303+ if (file.IsValid ())
1304+ SelectFile = file;
12661305 return true ;
12671306}
12681307
@@ -1291,10 +1330,10 @@ FileDialog::DialogState FileDialog::DoPopup()
12911330
12921331 tStringItem* selectPathItemName = nullptr ;
12931332 bool setYScrollToSel = false ;
1294- if (PopupJustOpened )
1333+ if (DoPopulate )
12951334 {
12961335 selectPathItemName = (!configPath || configPath->IsEmpty ()) ? nullptr : configPath->Head ();
1297- PopupJustOpened = false ;
1336+ DoPopulate = false ;
12981337 if (selectPathItemName)
12991338 setYScrollToSel = true ;
13001339 }
@@ -1588,7 +1627,15 @@ FileDialog::DialogState FileDialog::DoPopup()
15881627
15891628 // The name column selectable spans all columns.
15901629 ImGui::TableNextColumn ();
1591- DoSelectable (item);
1630+ if (SelectFile.IsValid ())
1631+ {
1632+ DoSelect (SelectFile);
1633+ SelectFile.Clear ();
1634+ }
1635+ else
1636+ {
1637+ DoSelectable (item);
1638+ }
15921639
15931640 ImGui::TableNextColumn ();
15941641 if (!item->IsDir )
0 commit comments