Renaming variables and other minor fixes

1164-fix
melex750 2017-11-21 12:58:12 -05:00 committed by Mateusz Przybył
parent 5cc565439c
commit 50b2afbda8
4 changed files with 57 additions and 54 deletions

View File

@ -98,7 +98,7 @@ void CFileDialog::StartDialog()
if ( m_dialogtype != CFileDialog::Type::None ) if ( m_dialogtype != CFileDialog::Type::None )
{ {
StartFileDialog(m_dialogtype); StartFileDialog();
} }
else else
{ {
@ -197,13 +197,12 @@ std::string CFileDialog::GetFilename()
// Start display of Open or Save dialogue // Start display of Open or Save dialogue
void CFileDialog::StartFileDialog(CFileDialog::Type type) void CFileDialog::StartFileDialog()
{ {
m_dialogtype = type;
m_captureClick = false; m_captureClick = false;
Math::Point pos = m_windowPos; Math::Point pos = m_windowPos;
Math::Point dim = m_windowDim; Math::Point dim = m_windowDim;
int icon = (type == CFileDialog::Type::Open) ? 14 : 13 ; int icon = (m_dialogtype == CFileDialog::Type::Open) ? 14 : 13 ;
CWindow* pw = m_interface->CreateWindows(pos, dim, icon, m_windowEvent); CWindow* pw = m_interface->CreateWindows(pos, dim, icon, m_windowEvent);
if ( pw == nullptr ) return; if ( pw == nullptr ) return;
@ -220,8 +219,11 @@ void CFileDialog::StartFileDialog(CFileDialog::Type type)
if ( m_title.empty() ) if ( m_title.empty() )
{ {
if ( type == CFileDialog::Type::Open ) GetResource(RES_TEXT, RT_IO_OPEN, m_title); if (m_dialogtype == CFileDialog::Type::Open)
if ( type == CFileDialog::Type::Save ) GetResource(RES_TEXT, RT_IO_SAVE, m_title); GetResource(RES_TEXT, RT_IO_OPEN, m_title);
if (m_dialogtype == CFileDialog::Type::Save)
GetResource(RES_TEXT, RT_IO_SAVE, m_title);
} }
pw->SetName(m_title); pw->SetName(m_title);
@ -698,6 +700,7 @@ bool CFileDialog::StopNewFolderMode(bool bCancel)
CEdit* pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT2)); // new folder edit box CEdit* pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT2)); // new folder edit box
if ( pe != nullptr ) if ( pe != nullptr )
{ {
pe->SetText("");
pe->ClearState(STATE_VISIBLE | STATE_ENABLE); pe->ClearState(STATE_VISIBLE | STATE_ENABLE);
} }
@ -766,8 +769,6 @@ bool CFileDialog::EventNewFolder(const Event &event)
void CFileDialog::GetListChoice() void CFileDialog::GetListChoice()
{ {
if ( ListItemIsFolder() ) return; // don't change text if a folder was clicked
CWindow* pw = static_cast< CWindow* >(m_interface->SearchControl(m_windowEvent)); CWindow* pw = static_cast< CWindow* >(m_interface->SearchControl(m_windowEvent));
if ( pw == nullptr ) return; if ( pw == nullptr ) return;
CList* pl = static_cast< CList* >(pw->SearchControl(EVENT_DIALOG_LIST)); CList* pl = static_cast< CList* >(pw->SearchControl(EVENT_DIALOG_LIST));
@ -962,19 +963,19 @@ void CFileDialog::PopulateList()
} }
// list all files // list all files
std::vector<std::string> programs = CResourceManager::ListFiles(SearchDirectory(false), true); std::vector<std::string> files = CResourceManager::ListFiles(SearchDirectory(false), true);
auto it = std::remove_if(programs.begin(), programs.end(), [this](const std::string& name) auto it = std::remove_if(files.begin(), files.end(), [this](const std::string& name)
{ {
return !CheckFilename(name); return !CheckFilename(name);
}); });
programs.erase(it, programs.end()); // remove invalid file names files.erase(it, files.end()); // remove invalid file names
for (auto& prog : programs) for (auto& filename : files)
{ {
std::ostringstream temp; std::ostringstream temp;
time_t now = CResourceManager::GetLastModificationTime(SearchDirectory(false) + prog); time_t now = CResourceManager::GetLastModificationTime(SearchDirectory(false) + filename);
strftime(timestr, 99, "%x %X", localtime(&now)); strftime(timestr, 99, "%x %X", localtime(&now));
temp << prog << '\t' << CResourceManager::GetFileSize(SearchDirectory(false) + prog) << " \t" << timestr; temp << filename << '\t' << CResourceManager::GetFileSize(SearchDirectory(false) + filename) << " \t" << timestr;
pl->SetItemName(i++, temp.str().c_str()); pl->SetItemName(i++, temp.str().c_str());
} }
} }
@ -1117,12 +1118,14 @@ bool CFileDialog::ActionOpen()
if ( !CheckFilename(filename) ) // add default extension ? if ( !CheckFilename(filename) ) // add default extension ?
{ {
if ( !m_extension.empty() ) filename += m_extension; if ( !m_extension.empty() ) filename += m_extension;
if ( !CheckFilename(filename) ) return false; // file name is ok ?
} }
if ( !CheckFilename(filename) ) return false; // file name is ok ?
SearchDirectory(true); SearchDirectory(true);
SetFilename(filename); SetFilename(filename);
SetFilenameField(pe, filename);
pe->SetCursor(999, 0); // select all
pw->SetFocus(pe);
return true; return true;
} }
@ -1140,10 +1143,9 @@ bool CFileDialog::ActionSave(bool checkFileExist)
if ( !CheckFilename(filename) ) // add default extension ? if ( !CheckFilename(filename) ) // add default extension ?
{ {
if ( !m_extension.empty() ) filename += m_extension; if ( !m_extension.empty() ) filename += m_extension;
if ( !CheckFilename(filename) ) return false; // file name is ok ?
} }
if ( !CheckFilename(filename) ) return false; // file name is ok ?
SearchDirectory(true); SearchDirectory(true);
if ( checkFileExist ) if ( checkFileExist )
@ -1156,6 +1158,9 @@ bool CFileDialog::ActionSave(bool checkFileExist)
} }
SetFilename(filename); SetFilename(filename);
SetFilenameField(pe, filename);
pe->SetCursor(999, 0); // select all
pw->SetFocus(pe);
return true; return true;
} }

View File

@ -92,7 +92,7 @@ public:
private: private:
void StartFileDialog(CFileDialog::Type type); void StartFileDialog();
void AdjustDialog(); void AdjustDialog();
void PopulateList(); void PopulateList();

View File

@ -94,7 +94,7 @@ CStudio::CStudio()
m_bRealTime = true; m_bRealTime = true;
m_bRunning = false; m_bRunning = false;
m_fixInfoTextTime = 0.0f; m_fixInfoTextTime = 0.0f;
m_dialog = nullptr; m_fileDialog = nullptr;
m_editCamera = Gfx::CAM_TYPE_NULL; m_editCamera = Gfx::CAM_TYPE_NULL;
} }
@ -113,7 +113,7 @@ bool CStudio::EventProcess(const Event &event)
CEdit* edit; CEdit* edit;
CSlider* slider; CSlider* slider;
if ( m_dialog != nullptr ) // dialogue exists? if (m_fileDialog != nullptr) // dialogue exists?
{ {
return EventDialog(event); return EventDialog(event);
} }
@ -151,13 +151,11 @@ bool CStudio::EventProcess(const Event &event)
if ( event.type == EVENT_STUDIO_OPEN ) // open? if ( event.type == EVENT_STUDIO_OPEN ) // open?
{ {
pw->SetFocus(edit); // focus on edit box after dialog is closed
StartDialog(event); StartDialog(event);
return true; return true;
} }
if ( event.type == EVENT_STUDIO_SAVE ) // save? if ( event.type == EVENT_STUDIO_SAVE ) // save?
{ {
pw->SetFocus(edit);
StartDialog(event); StartDialog(event);
return true; return true;
} }
@ -985,34 +983,34 @@ void CStudio::StartDialog(const Event &event)
{ {
if ( event.type == EVENT_STUDIO_OPEN ) if ( event.type == EVENT_STUDIO_OPEN )
{ {
m_dialog = MakeUnique<CFileDialog>(); m_fileDialog = MakeUnique<CFileDialog>();
m_dialog->SetDialogType(CFileDialog::Type::Open); m_fileDialog->SetDialogType(CFileDialog::Type::Open);
} }
if ( event.type == EVENT_STUDIO_SAVE ) if ( event.type == EVENT_STUDIO_SAVE )
{ {
m_dialog = MakeUnique<CFileDialog>(); m_fileDialog = MakeUnique<CFileDialog>();
m_dialog->SetDialogType(CFileDialog::Type::Save); m_fileDialog->SetDialogType(CFileDialog::Type::Save);
} }
if ( m_dialog != nullptr ) // a dialog was created? if (m_fileDialog != nullptr) // a dialog was created?
{ {
m_main->SetSatComLock(true); // impossible to use the SatCom m_main->SetSatComLock(true); // impossible to use the SatCom
m_dialog->SetWindowEvent(EVENT_WINDOW9); m_fileDialog->SetWindowEvent(EVENT_WINDOW9);
m_dialog->SetWindowPos(m_dialogPos); m_fileDialog->SetWindowPos(m_dialogPos);
m_dialog->SetWindowDim(m_dialogDim); m_fileDialog->SetWindowDim(m_dialogDim);
m_dialog->SetAutoExtension(".cbot"); m_fileDialog->SetAutoExtension(".cbot");
m_dialog->AddOptionalExtension(".txt"); m_fileDialog->AddOptionalExtension(".txt");
m_dialog->SetUsePublicPrivate(true); m_fileDialog->SetUsePublicPrivate(true);
m_dialog->SetPublic(m_settings->GetIOPublic()); m_fileDialog->SetPublic(m_settings->GetIOPublic());
m_dialog->SetPublicFolder("program"); m_fileDialog->SetPublicFolder("program");
m_dialog->SetPrivateFolder(m_main->GetPlayerProfile()->GetSaveFile("program")); m_fileDialog->SetPrivateFolder(m_main->GetPlayerProfile()->GetSaveFile("program"));
if ( event.type == EVENT_STUDIO_SAVE ) if ( event.type == EVENT_STUDIO_SAVE )
{ {
m_dialog->SetConfirmOverwrite(true); m_fileDialog->SetConfirmOverwrite(true);
// filename in CScript may include sub-folder // filename in CScript may include sub-folder
std::string filename = m_script->GetFilename(); std::string filename = m_script->GetFilename();
@ -1021,14 +1019,14 @@ void CStudio::StartDialog(const Event &event)
size_t pos = filename.find_last_of("/"); size_t pos = filename.find_last_of("/");
if (pos != std::string::npos) // split subfolder from filename if (pos != std::string::npos) // split subfolder from filename
{ {
m_dialog->SetSubFolderPath(filename.substr(0, pos)); m_fileDialog->SetSubFolderPath(filename.substr(0, pos));
filename = filename.substr(pos+1, filename.length()-pos-1); filename = filename.substr(pos+1, filename.length()-pos-1);
} }
} }
m_dialog->SetFilename(filename); m_fileDialog->SetFilename(filename);
} }
m_dialog->StartDialog(); m_fileDialog->StartDialog();
} }
} }
@ -1036,13 +1034,13 @@ void CStudio::StartDialog(const Event &event)
void CStudio::StopDialog() void CStudio::StopDialog()
{ {
if ( m_dialog != nullptr ) // a dialog exists? if (m_fileDialog != nullptr) // a dialog exists?
{ {
m_settings->SetIOPublic(m_dialog->GetPublic()); m_settings->SetIOPublic(m_fileDialog->GetPublic());
m_dialogPos = m_dialog->GetWindowPos(); m_dialogPos = m_fileDialog->GetWindowPos();
m_dialogDim = m_dialog->GetWindowDim(); m_dialogDim = m_fileDialog->GetWindowDim();
m_dialog->StopDialog(); m_fileDialog->StopDialog();
m_dialog.reset(); m_fileDialog.reset();
} }
m_main->SetSatComLock(false); // possible to use the SatCom m_main->SetSatComLock(false); // possible to use the SatCom
@ -1052,7 +1050,7 @@ void CStudio::StopDialog()
bool CStudio::EventDialog(const Event &event) bool CStudio::EventDialog(const Event &event)
{ {
if ( m_dialog != nullptr ) // a dialog exists? if (m_fileDialog != nullptr) // a dialog exists?
{ {
if ( event.type == EVENT_DIALOG_STOP ) if ( event.type == EVENT_DIALOG_STOP )
{ {
@ -1067,13 +1065,13 @@ bool CStudio::EventDialog(const Event &event)
CEdit* pe = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT)); CEdit* pe = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT));
if ( pe == nullptr ) return false; if ( pe == nullptr ) return false;
std::string path = m_dialog->GetBasePath() + "/"; // public/private folder std::string path = m_fileDialog->GetBasePath() + "/"; // public/private folder
std::string subpath = m_dialog->GetSubFolderPath();// sub-folder std::string subpath = m_fileDialog->GetSubFolderPath();// sub-folder
// filename in CScript may include sub-folder // filename in CScript may include sub-folder
std::string filename = subpath.empty() ? "" : subpath + "/"; std::string filename = subpath.empty() ? "" : subpath + "/";
filename += m_dialog->GetFilename(); filename += m_fileDialog->GetFilename();
CFileDialog::Type type = m_dialog->GetDialogType(); CFileDialog::Type type = m_fileDialog->GetDialogType();
if ( type == CFileDialog::Type::Save ) if ( type == CFileDialog::Type::Save )
{ {
@ -1092,7 +1090,7 @@ bool CStudio::EventDialog(const Event &event)
return true; return true;
} }
return m_dialog->EventProcess(event); return m_fileDialog->EventProcess(event);
} }
return true; return true;

View File

@ -101,7 +101,7 @@ protected:
ActivePause* m_runningPause = nullptr; ActivePause* m_runningPause = nullptr;
std::string m_helpFilename; std::string m_helpFilename;
std::unique_ptr<CFileDialog> m_dialog; std::unique_ptr<CFileDialog> m_fileDialog;
}; };