diff --git a/po/colobot.pot b/po/colobot.pot index 3851d356..5614aaac 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -209,6 +209,9 @@ msgstr "" msgid "Overwrite existing file?" msgstr "" +msgid "Select Folder" +msgstr "" + msgid "Original game developed by:" msgstr "" diff --git a/po/de.po b/po/de.po index 21fe4e71..383b072a 100644 --- a/po/de.po +++ b/po/de.po @@ -1380,6 +1380,9 @@ msgstr "Speichern\\Aktuelle Mission speichern" msgid "Save\\Saves the current mission" msgstr "Speichern\\Speichert die Mission" +msgid "Select Folder" +msgstr "" + msgid "Select the astronaut\\Selects the astronaut" msgstr "Astronauten auswählen\\Astronauten auswählen" diff --git a/po/fr.po b/po/fr.po index cfef0235..cfd44ace 100644 --- a/po/fr.po +++ b/po/fr.po @@ -1382,6 +1382,9 @@ msgstr "Enregistrer\\Enregistrer la mission en cours" msgid "Save\\Saves the current mission" msgstr "Enregistrer\\Enregistrer la mission en cours" +msgid "Select Folder" +msgstr "" + msgid "Select the astronaut\\Selects the astronaut" msgstr "Sélectionner le cosmonaute\\Sélectionner le cosmonaute" diff --git a/po/pl.po b/po/pl.po index 93319441..b61aa5ff 100644 --- a/po/pl.po +++ b/po/pl.po @@ -1362,6 +1362,9 @@ msgstr "Zapisz\\Zapisuje bieżącą misję" msgid "Save\\Saves the current mission" msgstr "Zapisz\\Zapisuje bieżącą misję" +msgid "Select Folder" +msgstr "" + msgid "Select the astronaut\\Selects the astronaut" msgstr "Zaznacz astronautę\\Zaznacza astronautę" diff --git a/po/ru.po b/po/ru.po index 8143ac37..e4040b5b 100644 --- a/po/ru.po +++ b/po/ru.po @@ -1391,6 +1391,9 @@ msgstr "Сохранить\\Сохранить текущую миссию" msgid "Save\\Saves the current mission" msgstr "Сохранить\\Сохранить текущую миссию" +msgid "Select Folder" +msgstr "" + msgid "Select the astronaut\\Selects the astronaut" msgstr "Выбор астронавта\\Выбор астронавта" diff --git a/src/common/restext.cpp b/src/common/restext.cpp index c54ddb1a..09975f4e 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -125,6 +125,7 @@ void InitializeRestext() stringsText[RT_IO_PRIVATE] = TR("Private\\Private folder"); stringsText[RT_IO_PUBLIC] = TR("Public\\Common folder"); stringsText[RT_IO_REPLACE] = TR("Overwrite existing file?"); + stringsText[RT_IO_SELECT_DIR] = TR("Select Folder"); stringsText[RT_GENERIC_DEV1] = TR("Original game developed by:"); stringsText[RT_GENERIC_DEV2] = TR("epsitec.com"); diff --git a/src/common/restext.h b/src/common/restext.h index 2369d8c0..ff01b538 100644 --- a/src/common/restext.h +++ b/src/common/restext.h @@ -119,6 +119,7 @@ enum ResTextType RT_IO_PRIVATE = 155, RT_IO_PUBLIC = 156, RT_IO_REPLACE = 157, + RT_IO_SELECT_DIR = 158, RT_GENERIC_DEV1 = 170, RT_GENERIC_DEV2 = 171, diff --git a/src/ui/filedialog.cpp b/src/ui/filedialog.cpp index 3bb40be0..16c650ff 100644 --- a/src/ui/filedialog.cpp +++ b/src/ui/filedialog.cpp @@ -224,6 +224,9 @@ void CFileDialog::StartFileDialog() if (m_dialogtype == CFileDialog::Type::Save) GetResource(RES_TEXT, RT_IO_SAVE, m_title); + + if (m_dialogtype == CFileDialog::Type::Folder) + GetResource(RES_TEXT, RT_IO_SELECT_DIR, m_title); } pw->SetName(m_title); @@ -237,8 +240,6 @@ void CFileDialog::StartFileDialog() CButton* pb = pw->CreateButton(pos, dim, -1, EVENT_DIALOG_NEWDIR); // New Folder button pb->SetState(STATE_SHADOW); - GetResource(RES_EVENT, EVENT_DIALOG_NEWDIR, name); - pb->SetName(name); CList* pli = pw->CreateList(pos, dim, 0, EVENT_DIALOG_LIST); // file list pli->SetState(STATE_SHADOW); @@ -246,13 +247,6 @@ void CFileDialog::StartFileDialog() CEdit* pe = pw->CreateEdit(pos, dim, 0, EVENT_DIALOG_EDIT2); // new folder edit box pe->ClearState(STATE_VISIBLE | STATE_ENABLE); - GetResource(RES_TEXT, RT_IO_NAME, name); - pla = pw->CreateLabel(pos, dim, 0, EVENT_DIALOG_LABEL2, name); // "Name:" label - pla->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); - - pe = pw->CreateEdit(pos, dim, 0, EVENT_DIALOG_EDIT); // file name edit box - pe->SetState(STATE_SHADOW); - if ( m_usePublicPrivate ) { GetResource(RES_TEXT, RT_IO_DIR, name); @@ -270,16 +264,33 @@ void CFileDialog::StartFileDialog() pc->SetState(STATE_SHADOW); } + pb = pw->CreateButton(pos, dim, -1, EVENT_DIALOG_CANCEL); // Cancel button + pb->SetState(STATE_SHADOW); + pb = pw->CreateButton(pos, dim, -1, EVENT_DIALOG_OK); // open/save button pb->SetState(STATE_SHADOW); + + if (m_dialogtype == CFileDialog::Type::Folder) + { + m_selectFolderMode = true; + AdjustDialog(); + UpdatePublic(m_public); + PopulateList(); + UpdatePathLabel(); + UpdateSelectFolder(); + return; + } + GetResource(RES_TEXT, RT_IO_OPEN, name); if ( m_dialogtype == CFileDialog::Type::Save ) GetResource(RES_TEXT, RT_IO_SAVE, name); pb->SetName(name); - pb = pw->CreateButton(pos, dim, -1, EVENT_DIALOG_CANCEL); // Cancel button - pb->SetState(STATE_SHADOW); - GetResource(RES_EVENT, EVENT_DIALOG_CANCEL, name); - pb->SetName(name); + GetResource(RES_TEXT, RT_IO_NAME, name); + pla = pw->CreateLabel(pos, dim, 0, EVENT_DIALOG_LABEL2, name); // "Name:" label + pla->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); + + pe = pw->CreateEdit(pos, dim, 0, EVENT_DIALOG_EDIT); // file name edit box + pe->SetState(STATE_SHADOW); // create "Overwrite existing file?" controls CGroup* pg = pw->CreateGroup(pos, dim, 0, EVENT_DIALOG_GROUP1); // box "Overwrite ?" @@ -393,29 +404,32 @@ void CFileDialog::AdjustDialog() } } - ppos.y = wpos.y+30.0f/480.0f; - ddim.x = 50.0f/640.0f; - ddim.y = 20.0f/480.0f; - pla = static_cast< CLabel* >(pw->SearchControl(EVENT_DIALOG_LABEL2)); // "Name:" label - if ( pla != nullptr ) + if (!m_selectFolderMode) { - pla->SetPos(ppos); - pla->SetDim(ddim); - } + ppos.y = wpos.y+30.0f/480.0f; + ddim.x = 50.0f/640.0f; + ddim.y = 20.0f/480.0f; + pla = static_cast< CLabel* >(pw->SearchControl(EVENT_DIALOG_LABEL2)); // "Name:" label + if ( pla != nullptr ) + { + pla->SetPos(ppos); + pla->SetDim(ddim); + } - ppos.x += 50.0f/640.0f; - ppos.y = wpos.y+36.0f/480.0f; - ddim.x = wdim.x-170.0f/640.0f; - CEdit* pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT)); // file name edit box - if ( pe != nullptr ) - { - pe->SetPos(ppos); - pe->SetDim(ddim); + ppos.x += 50.0f/640.0f; + ppos.y = wpos.y+36.0f/480.0f; + ddim.x = wdim.x-170.0f/640.0f; + CEdit* pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT)); // file name edit box + if ( pe != nullptr ) + { + pe->SetPos(ppos); + pe->SetDim(ddim); - int nch = static_cast< int >((ddim.x*640.0f-22.0f)/5.75f); - std::string name = pe->GetText(nch); - pe->SetMaxChar(nch); - pe->SetText(name); + int nch = static_cast< int >((ddim.x*640.0f-22.0f)/5.75f); + std::string name = pe->GetText(nch); + pe->SetMaxChar(nch); + pe->SetText(name); + } } if ( m_usePublicPrivate ) @@ -561,12 +575,19 @@ bool CFileDialog::EventProcess(const Event &event) m_captureClick = true; m_lastTimeClickDir = m_time; } + if (m_selectFolderMode) UpdateSelectFolder(); return true; } // a file name was clicked - if ( !m_newFolderMode ) GetListChoice(); m_captureClick = false; + if (m_selectFolderMode) + { + UpdateSelectFolder(); + return true; + } + + if (!m_newFolderMode) GetListChoice(); return true; } @@ -598,6 +619,7 @@ bool CFileDialog::EventProcess(const Event &event) PopulateList(); UpdatePathLabel(); if (pe != nullptr) SearchList(pe->GetText(999), m_newFolderMode); + if (m_selectFolderMode) UpdateSelectFolder(); } else if ( event.type == EVENT_DIALOG_CHECK2 ) // public? { @@ -606,6 +628,7 @@ bool CFileDialog::EventProcess(const Event &event) PopulateList(); UpdatePathLabel(); if (pe != nullptr) SearchList(pe->GetText(999), m_newFolderMode); + if (m_selectFolderMode) UpdateSelectFolder(); } } @@ -622,6 +645,8 @@ bool CFileDialog::EventProcess(const Event &event) return true; } + if (m_selectFolderMode) return EventSelectFolder(event); + if ( event.type == EVENT_DIALOG_OK || (event.type == EVENT_KEY_DOWN && event.GetData()->key == KEY(RETURN)) ) { @@ -650,9 +675,12 @@ bool CFileDialog::StartNewFolderMode() CWindow* pw = static_cast< CWindow* >(m_interface->SearchControl(m_windowEvent)); // dialog window if ( pw == nullptr ) return false; - CEdit* pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT)); // filename edit box - if ( pe == nullptr ) return false; - pe->SetState(STATE_ENABLE, false); + if (!m_selectFolderMode) + { + CEdit* pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT)); // filename edit box + if ( pe == nullptr ) return false; + pe->SetState(STATE_ENABLE, false); + } CButton* pb = static_cast< CButton* >(pw->SearchControl(EVENT_DIALOG_NEWDIR)); // new folder button if ( pb == nullptr ) return false; @@ -674,7 +702,7 @@ bool CFileDialog::StartNewFolderMode() pos.y += dim.y-3.0f/480.0f; dim.y = 20.0f/480.0f; - 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 ) return false; pe->SetState(STATE_VISIBLE, true); pe->SetState(STATE_ENABLE, true); @@ -704,11 +732,14 @@ bool CFileDialog::StopNewFolderMode(bool bCancel) pe->ClearState(STATE_VISIBLE | STATE_ENABLE); } - pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT)); // filename edit box - if ( pe != nullptr ) + if (!m_selectFolderMode) { - pe->SetState(STATE_ENABLE, true); - pw->SetFocus(pe); + pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT)); // filename edit box + if ( pe != nullptr ) + { + pe->SetState(STATE_ENABLE, true); + pw->SetFocus(pe); + } } CButton* pb = static_cast< CButton* >(pw->SearchControl(EVENT_DIALOG_NEWDIR)); // new folder button @@ -721,6 +752,12 @@ bool CFileDialog::StopNewFolderMode(bool bCancel) AdjustDialog(); + if (m_selectFolderMode) + { + UpdateSelectFolder(); + return true; + } + if ( pe != nullptr ) { pe->SetCursor(999, 0); @@ -765,6 +802,48 @@ bool CFileDialog::EventNewFolder(const Event &event) return true; } +bool CFileDialog::EventSelectFolder(const Event &event) +{ + CWindow* pw = static_cast< CWindow* >(m_interface->SearchControl(m_windowEvent)); + if ( pw == nullptr ) return false; + + if ( event.type == EVENT_DIALOG_OK ) + { + CList* pl = static_cast< CList* >(pw->SearchControl(EVENT_DIALOG_LIST)); + if ( pl == nullptr ) return false; + std::string name = pl->GetItemName(pl->GetSelect()); + name = name.substr(0, name.find_first_of("\t")); + m_subDirPath += m_subDirPath.empty() ? name : "/" + name; + m_eventQueue->AddEvent(Event(EVENT_DIALOG_ACTION)); + } + + if (event.type == EVENT_KEY_DOWN) + { + if (event.GetData()->key == KEY(ESCAPE)) + { + m_eventQueue->AddEvent(Event(EVENT_DIALOG_STOP)); + } + + if (event.GetData()->key == KEY(RETURN)) + { + if ( ListItemIsFolder() ) + { + CList* pl = static_cast< CList* >(pw->SearchControl(EVENT_DIALOG_LIST)); + if ( pl == nullptr ) return false; + std::string name = pl->GetItemName(pl->GetSelect()); + name = name.substr(0, name.find_first_of("\t")); + if ( name != ".." ) + { + m_subDirPath += m_subDirPath.empty() ? name : "/" + name; + m_eventQueue->AddEvent(Event(EVENT_DIALOG_ACTION)); + } + } + } + } + + return true; +} + // Updates the file name edit box after a click in the list. void CFileDialog::GetListChoice() @@ -863,6 +942,28 @@ void CFileDialog::UpdateAction() pb->SetState(STATE_ENABLE, !bError); } +void CFileDialog::UpdateSelectFolder() +{ + CWindow* pw = static_cast< CWindow* >(m_interface->SearchControl(m_windowEvent)); + if ( pw == nullptr ) return; + CButton* pb = static_cast< CButton* >(pw->SearchControl(EVENT_DIALOG_OK)); + if ( pb == nullptr ) return; + + bool bError = true; + if (!m_newFolderMode && ListItemIsFolder()) + { + CList* pl = static_cast< CList* >(pw->SearchControl(EVENT_DIALOG_LIST)); + if ( pl != nullptr ) + { + std::string name = pl->GetItemName(pl->GetSelect()); + name = name.substr(0, name.find_first_of("\t")); + if (name != "..") bError = false; + } + } + + pb->SetState(STATE_ENABLE, !bError); +} + // Updates the New Folder button. void CFileDialog::UpdateNewFolder() diff --git a/src/ui/filedialog.h b/src/ui/filedialog.h index 6d6ca734..a2058798 100644 --- a/src/ui/filedialog.h +++ b/src/ui/filedialog.h @@ -46,11 +46,15 @@ public: void StopDialog(); bool EventProcess(const Event &event); + /** + * \brief Identifies the type of dialog to display. + */ enum class Type { - None, - Open, - Save, + None, //!< Type was not set + Open, //!< Open dialog + Save, //!< Save dialog + Folder, //!< Select Folder dialog }; void SetDialogType(CFileDialog::Type type) { m_dialogtype = type; } @@ -111,6 +115,9 @@ private: void UpdateNewFolder(); void CreateNewFolder(); + bool EventSelectFolder(const Event &event); + void UpdateSelectFolder(); + bool ListItemIsFolder(); bool DirectoryExists(const std::string &name); @@ -157,6 +164,7 @@ private: bool m_captureClick = false; bool m_newFolderMode = false; + bool m_selectFolderMode = false; bool m_askOverwriteMode = false; bool m_confirmOverwrite = false;