From: <sag...@us...> - 2009-12-18 21:51:51
|
Revision: 444 http://modplug.svn.sourceforge.net/modplug/?rev=444&view=rev Author: saga-games Date: 2009-12-18 21:51:37 +0000 (Fri, 18 Dec 2009) Log Message: ----------- [Fix] When using a Load/Save dialog, MPT's key handler will be disabled so that common shortcuts like F2, Ctrl+C, Ctrl+V, Esc. etc. can still be used. [Fix] General tab: VST Preset Load/save buttons didn't use default directories. [Ref] Built a nice abstraction of the CFileDialog to realize the first fix. Now CFileDialog is used in only on place, and using Load/Save dialogs should be a lot easier now - especially when dealing with multiple file selections. Modified Paths: -------------- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/KeyConfigDlg.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Moptions.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/TuningDialog.cpp trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/mptrack/Vstplug.cpp Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.cpp =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -110,48 +110,35 @@ VOID CAbstractVstEditor::OnLoadPreset() //------------------------------------- { - if (m_pVstPlugin) - { - CFileDialog dlg(TRUE, "fxp", NULL, - OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_NOREADONLYRETURN, - "VST Program (*.fxp)|*.fxp||", theApp.m_pMainWnd); - const LPCTSTR pszWdir = CMainFrame::GetWorkingDirectory(DIR_PLUGINPRESETS); - if(pszWdir[0]) - dlg.m_ofn.lpstrInitialDir = pszWdir; + if(!m_pVstPlugin) return; + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "fxp", "", + "VST Program (*.fxp)|*.fxp||", + CMainFrame::GetWorkingDirectory(DIR_PLUGINPRESETS)); + if(files.abort) return; - if (!(dlg.DoModal() == IDOK)) return; + CMainFrame::SetWorkingDirectory(files.workingDirectory.c_str(), DIR_PLUGINPRESETS, true); - CString sFile = dlg.GetPathName(); - CMainFrame::SetWorkingDirectory(sFile, DIR_PLUGINPRESETS, true); - - //TODO: exception handling to distinguish errors at this level. - if (!(m_pVstPlugin->LoadProgram(sFile))) - ::AfxMessageBox("Error loading preset. Are you sure it is for this plugin?"); - } + //TODO: exception handling to distinguish errors at this level. + if (!(m_pVstPlugin->LoadProgram(files.first_file.c_str()))) + ::AfxMessageBox("Error loading preset. Are you sure it is for this plugin?"); } VOID CAbstractVstEditor::OnSavePreset() //------------------------------------- { - if (m_pVstPlugin) - { - CFileDialog dlg(FALSE, "fxp", NULL, - OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_NOREADONLYRETURN, - "VST Program (*.fxp)|*.fxp||", theApp.m_pMainWnd); - const LPCTSTR pszWdir = CMainFrame::GetWorkingDirectory(DIR_PLUGINPRESETS); - if(pszWdir[0]) - dlg.m_ofn.lpstrInitialDir = pszWdir; - if (!(dlg.DoModal() == IDOK)) return; + if(!m_pVstPlugin) return; - CString sFile = dlg.GetPathName(); - CMainFrame::SetWorkingDirectory(sFile, DIR_PLUGINPRESETS, true); + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "fxp", "", + "VST Program (*.fxp)|*.fxp||", + CMainFrame::GetWorkingDirectory(DIR_PLUGINPRESETS)); + if(files.abort) return; - //TODO: exception handling - if (!(m_pVstPlugin->SaveProgram(sFile))) - ::AfxMessageBox("Error saving preset."); - } - return; + CMainFrame::SetWorkingDirectory(files.workingDirectory.c_str(), DIR_PLUGINPRESETS, true); + + //TODO: exception handling + if (!(m_pVstPlugin->SaveProgram(files.first_file.c_str()))) + ::AfxMessageBox("Error saving preset."); } VOID CAbstractVstEditor::OnRandomizePreset() Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -1529,31 +1529,22 @@ void CCtrlInstruments::OnInstrumentOpen() //--------------------------------------- { - CFileDialog dlg(TRUE, - NULL, - NULL, - OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT, - "All Instruments|*.xi;*.pat;*.iti;*.wav;*.aif;*.aiff|" - "FastTracker II Instruments (*.xi)|*.xi|" - "GF1 Patches (*.pat)|*.pat|" - "Impulse Tracker Instruments (*.iti)|*.iti|" - "All Files (*.*)|*.*||", - this); + static int nLastIndex = 0; - const LPCTSTR pszWdir = CMainFrame::GetWorkingDirectory(DIR_INSTRUMENTS); - if(pszWdir[0]) - dlg.m_ofn.lpstrInitialDir = pszWdir; + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "", "", + "All Instruments|*.xi;*.pat;*.iti;*.wav;*.aif;*.aiff|" + "FastTracker II Instruments (*.xi)|*.xi|" + "GF1 Patches (*.pat)|*.pat|" + "Impulse Tracker Instruments (*.iti)|*.iti|" + "All Files (*.*)|*.*||", + CMainFrame::GetWorkingDirectory(DIR_INSTRUMENTS), + true, + &nLastIndex); + if(files.abort) return; - const size_t bufferSize = 2048; //Note: This is possibly the maximum buffer size. - vector<char> filenameBuffer(bufferSize, 0); - dlg.GetOFN().lpstrFile = &filenameBuffer[0]; - dlg.GetOFN().nMaxFile = bufferSize; + CMainFrame::SetWorkingDirectory(files.workingDirectory.c_str(), DIR_INSTRUMENTS, true); - if (dlg.DoModal() != IDOK) return; - - POSITION pos = dlg.GetStartPosition(); - size_t counter = 0; - while(pos != NULL) + for(size_t counter = 0; counter < files.filenames.size(); counter++) { //If loading multiple instruments, advancing to next instrument and creating //new instrument if necessary. @@ -1568,12 +1559,10 @@ OnInstrumentNew(); } - if(!OpenInstrument(dlg.GetNextPathName(pos))) + if(!OpenInstrument(files.filenames[counter].c_str())) ErrorBox(IDS_ERR_FILEOPEN, this); - - counter++; } - filenameBuffer.clear(); + if (m_pParent) m_pParent->InstrumentChanged(m_nInstrument); SwitchToView(); } @@ -1597,43 +1586,29 @@ } SanitizeFilename(szFileName); -// -> CODE#0019 -// -> DESC="correctly load ITI & XI instruments sample note map" -// CFileDialog dlg(FALSE, (m_pSndFile->m_nType & MOD_TYPE_IT) ? "iti" : "xi", -// szFileName, -// OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, -// "FastTracker II Instruments (*.xi)|*.xi|" -// "Impulse Tracker Instruments (*.iti)|*.iti||", -// this); - CFileDialog dlg(FALSE, (m_pSndFile->m_nType & (MOD_TYPE_IT | MOD_TYPE_MPT)) ? "iti" : "xi", - szFileName, - OFN_HIDEREADONLY| OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - ( m_pSndFile->m_nType & (MOD_TYPE_IT | MOD_TYPE_MPT) ? "Impulse Tracker Instruments (*.iti)|*.iti|" - "FastTracker II Instruments (*.xi)|*.xi||" - : "FastTracker II Instruments (*.xi)|*.xi|" - "Impulse Tracker Instruments (*.iti)|*.iti||" ), - this); -// -! BUG_FIX#0019 - + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, (m_pSndFile->GetType() == MOD_TYPE_XM) ? "xi" : "iti", szFileName, + (m_pSndFile->GetType() == MOD_TYPE_XM) ? + "FastTracker II Instruments (*.xi)|*.xi|" + "Impulse Tracker Instruments (*.iti)|*.iti||" : + "Impulse Tracker Instruments (*.iti)|*.iti|" + "FastTracker II Instruments (*.xi)|*.xi||", + CMainFrame::GetWorkingDirectory(DIR_INSTRUMENTS)); + if(files.abort) return; - const LPCTSTR pszWdir = CMainFrame::GetWorkingDirectory(DIR_INSTRUMENTS); - if(pszWdir[0]) - dlg.m_ofn.lpstrInitialDir = pszWdir; - - if (dlg.DoModal() != IDOK) return; BeginWaitCursor(); - _splitpath(dlg.GetPathName(), drive, path, NULL, ext); + + _splitpath(files.first_file.c_str(), drive, path, NULL, ext); BOOL bOk = FALSE; if (!lstrcmpi(ext, ".iti")) - bOk = m_pSndFile->SaveITIInstrument(m_nInstrument, dlg.GetPathName()); + bOk = m_pSndFile->SaveITIInstrument(m_nInstrument, files.first_file.c_str()); else - bOk = m_pSndFile->SaveXIInstrument(m_nInstrument, dlg.GetPathName()); + bOk = m_pSndFile->SaveXIInstrument(m_nInstrument, files.first_file.c_str()); // -> CODE#0023 // -> DESC="IT project files (.itp)" - int n = strlen(dlg.GetPathName()); + int n = strlen(files.first_file.c_str()); if(n > _MAX_PATH) n = _MAX_PATH; - strncpy(m_pSndFile->m_szInstrumentPath[m_nInstrument-1],dlg.GetPathName(),n); + strncpy(m_pSndFile->m_szInstrumentPath[m_nInstrument-1], files.first_file.c_str(),n); m_pSndFile->instrumentModified[m_nInstrument-1] = FALSE; // -! NEW_FEATURE#0023 @@ -1643,7 +1618,7 @@ strcpy(szFileName, drive); strcat(szFileName, path); - CMainFrame::SetWorkingDirectory(szFileName, DIR_INSTRUMENTS); + CMainFrame::SetWorkingDirectory(files.workingDirectory.c_str(), DIR_INSTRUMENTS); // -> CODE#0023 // -> DESC="IT project files (.itp)" Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -902,38 +902,25 @@ //------------------------------- { static int nLastIndex = 0; - CFileDialog dlg(TRUE, - NULL, - NULL, - OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT, - "All Samples|*.wav;*.pat;*.s3i;*.smp;*.snd;*.raw;*.xi;*.aif;*.aiff;*.its;*.8sv;*.8svx;*.svx;*.pcm|" - "Wave Files (*.wav)|*.wav|" - "XI Samples (*.xi)|*.xi|" - "Impulse Tracker Samples (*.its)|*.its|" - "ScreamTracker Samples (*.s3i,*.smp)|*.s3i;*.smp|" - "GF1 Patches (*.pat)|*.pat|" - "AIFF Files (*.aiff;*.8svx)|*.aif;*.aiff;*.8sv;*.8svx;*.svx|" - "Raw Samples (*.raw,*.snd,*.pcm)|*.raw;*.snd;*.pcm|" - "All Files (*.*)|*.*||", - this); + + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "", "", + "All Samples|*.wav;*.pat;*.s3i;*.smp;*.snd;*.raw;*.xi;*.aif;*.aiff;*.its;*.8sv;*.8svx;*.svx;*.pcm|" + "Wave Files (*.wav)|*.wav|" + "XI Samples (*.xi)|*.xi|" + "Impulse Tracker Samples (*.its)|*.its|" + "ScreamTracker Samples (*.s3i,*.smp)|*.s3i;*.smp|" + "GF1 Patches (*.pat)|*.pat|" + "AIFF Files (*.aiff;*.8svx)|*.aif;*.aiff;*.8sv;*.8svx;*.svx|" + "Raw Samples (*.raw,*.snd,*.pcm)|*.raw;*.snd;*.pcm|" + "All Files (*.*)|*.*||", + CMainFrame::GetWorkingDirectory(DIR_SAMPLES), + true, + &nLastIndex); + if(files.abort) return; - const LPCTSTR pszWdir = CMainFrame::GetWorkingDirectory(DIR_SAMPLES); - if(pszWdir[0]) - dlg.m_ofn.lpstrInitialDir = pszWdir; + CMainFrame::SetWorkingDirectory(files.workingDirectory.c_str(), DIR_SAMPLES, true); - dlg.m_ofn.nFilterIndex = nLastIndex; - const size_t bufferSize = 2048; //Note: This is possibly the maximum buffer size in MFC 7(this note was written November 2006). - vector<char> filenameBuffer(bufferSize, 0); - dlg.GetOFN().lpstrFile = &filenameBuffer[0]; - dlg.GetOFN().nMaxFile = bufferSize; - - if (dlg.DoModal() != IDOK) return; - - nLastIndex = dlg.m_ofn.nFilterIndex; - - POSITION pos = dlg.GetStartPosition(); - size_t counter = 0; - while(pos != NULL) + for(size_t counter = 0; counter < files.filenames.size(); counter++) { //If loading multiple samples, advancing to next sample and creating //new one if necessary. @@ -944,16 +931,13 @@ else m_nSample++; - if(m_nSample > m_pSndFile->GetNumSamples()) + if(m_nSample > m_pSndFile->GetNumSamples()) OnSampleNew(); } - if(!OpenSample(dlg.GetNextPathName(pos))) + if(!OpenSample(files.filenames[counter].c_str())) ErrorBox(IDS_ERR_FILEOPEN, this); - - counter++; } - filenameBuffer.clear(); SwitchToView(); } @@ -1000,24 +984,20 @@ } SanitizeFilename(szFileName); - CFileDialog dlg(FALSE, "wav", - szFileName, - OFN_HIDEREADONLY| OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - "Wave File (*.wav)|*.wav|" - "RAW Audio (*.raw)|*.raw||", - this); - const LPCTSTR pszWdir = CMainFrame::GetWorkingDirectory(DIR_SAMPLES); - if(pszWdir[0]) - dlg.m_ofn.lpstrInitialDir = pszWdir; - if (dlg.DoModal() != IDOK) return; + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "wav", szFileName, + "Wave File (*.wav)|*.wav|" + "RAW Audio (*.raw)|*.raw||", + CMainFrame::GetWorkingDirectory(DIR_SAMPLES)); + if(files.abort) return; + BeginWaitCursor(); TCHAR ext[_MAX_EXT]; - _splitpath(dlg.GetPathName(), NULL, NULL, NULL, ext); + _splitpath(files.first_file.c_str(), NULL, NULL, NULL, ext); bool bOk = false; UINT iMinSmp = m_nSample, iMaxSmp = m_nSample; - CString sFilename = dlg.GetPathName(), sNumberFormat; + CString sFilename = files.first_file.c_str(), sNumberFormat; if(bBatchSave) { iMinSmp = 1; @@ -1040,7 +1020,7 @@ SanitizeFilename(sSampleName); SanitizeFilename(sSampleFilename); - sFilename = dlg.GetPathName(); + sFilename = files.first_file.c_str(); sFilename.Replace("%sample_number%", sSampleNumber); sFilename.Replace("%sample_filename%", sSampleFilename); sFilename.Replace("%sample_name%", sSampleName); @@ -1058,7 +1038,7 @@ ErrorBox(IDS_ERR_SAVESMP, this); } else { - CMainFrame::SetWorkingDirectory(dlg.GetPathName(), DIR_SAMPLES, true); + CMainFrame::SetWorkingDirectory(files.workingDirectory.c_str(), DIR_SAMPLES, true); } SwitchToView(); } Modified: trunk/OpenMPT/mptrack/KeyConfigDlg.cpp =================================================================== --- trunk/OpenMPT/mptrack/KeyConfigDlg.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/KeyConfigDlg.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -646,37 +646,29 @@ void COptionsKeyboard::OnLoad() { - CFileDialog dlg(TRUE, "mkb", m_sFullPathName, - OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_NOREADONLYRETURN, - "OpenMPT Key Bindings (*.mkb)|*.mkb||", theApp.m_pMainWnd); - if (CMainFrame::m_szKbdFile[0]) - dlg.m_ofn.lpstrInitialDir = CMainFrame::m_szKbdFile; + std::string filename = m_sFullPathName; + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "mkb", filename, + "OpenMPT Key Bindings (*.mkb)|*.mkb||", + CMainFrame::m_szKbdFile); + if(files.abort) return; - if (dlg.DoModal() == IDOK) - { - m_sFullPathName=dlg.GetPathName(); - plocalCmdSet->LoadFile(m_sFullPathName); - ForceUpdateGUI(); - TentativeSetToDefaultFile(m_sFullPathName); - } - + m_sFullPathName = files.first_file.c_str(); + plocalCmdSet->LoadFile(m_sFullPathName); + ForceUpdateGUI(); + TentativeSetToDefaultFile(m_sFullPathName); } void COptionsKeyboard::OnSave() { - CFileDialog dlg(FALSE, "mkb", m_sFullPathName, - OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_NOREADONLYRETURN, - "OpenMPT Key Bindings (*.mkb)|*.mkb||", theApp.m_pMainWnd); - if (CMainFrame::m_szKbdFile[0]) - dlg.m_ofn.lpstrInitialDir = CMainFrame::m_szKbdFile; - - if (dlg.DoModal() == IDOK) - { - m_sFullPathName=dlg.GetPathName(); - plocalCmdSet->SaveFile(m_sFullPathName, m_bDebugSave.GetCheck()); - TentativeSetToDefaultFile(m_sFullPathName); - } - + std::string filename = m_sFullPathName; + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "mkb", filename, + "OpenMPT Key Bindings (*.mkb)|*.mkb||", + CMainFrame::m_szKbdFile); + if(files.abort) return; + + m_sFullPathName = files.first_file.c_str(); + plocalCmdSet->SaveFile(m_sFullPathName, m_bDebugSave.GetCheck()); + TentativeSetToDefaultFile(m_sFullPathName); } bool COptionsKeyboard::TentativeSetToDefaultFile(CString m_sFullPathName) Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -132,7 +132,6 @@ BOOL CMainFrame::gbPatternVUMeters = FALSE; BOOL CMainFrame::gbPatternPluginNames = TRUE; DWORD CMainFrame::gdwNotificationType = MPTNOTIFY_DEFAULT; -UINT CMainFrame::m_nFilterIndex = 0; UINT CMainFrame::m_nLastOptionsPage = 0; BOOL CMainFrame::gbMdiMaximize = FALSE; bool CMainFrame::gbShowHackControls = false; @@ -2418,45 +2417,40 @@ void CMainFrame::OnAddDlsBank() //----------------------------- { - CFileDialog dlg(TRUE, - ".dls", - NULL, - OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, - "All Sound Banks|*.dls;*.sbk;*.sf2;*.mss|" - "Downloadable Sounds Banks (*.dls)|*.dls;*.mss|" - "SoundFont 2.0 Banks (*.sf2)|*.sbk;*.sf2|" - "All Files (*.*)|*.*||", - this); - if (dlg.DoModal() == IDOK) + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "dls", "", + "All Sound Banks|*.dls;*.sbk;*.sf2;*.mss|" + "Downloadable Sounds Banks (*.dls)|*.dls;*.mss|" + "SoundFont 2.0 Banks (*.sf2)|*.sbk;*.sf2|" + "All Files (*.*)|*.*||", + "", + true); + if(files.abort) return; + + BeginWaitCursor(); + for(size_t counter = 0; counter < files.filenames.size(); counter++) { - BeginWaitCursor(); - CTrackApp::AddDLSBank(dlg.GetPathName()); - m_wndTree.RefreshDlsBanks(); - EndWaitCursor(); + CTrackApp::AddDLSBank(files.filenames[counter].c_str()); } + m_wndTree.RefreshDlsBanks(); + EndWaitCursor(); } void CMainFrame::OnImportMidiLib() //-------------------------------- { - CFileDialog dlg(TRUE, - NULL, - NULL, - OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, - "Text and INI files (*.txt,*.ini)|*.txt;*.ini;*.dls;*.sf2;*.sbk|" - "Downloadable Sound Banks (*.dls)|*.dls;*.mss|" - "SoundFont 2.0 banks (*.sf2)|*.sbk;*.sf2|" - "Gravis UltraSound (ultrasnd.ini)|ultrasnd.ini|" - "All Files (*.*)|*.*||", - this); - if (dlg.DoModal() == IDOK) - { - BeginWaitCursor(); - CTrackApp::ImportMidiConfig(dlg.GetPathName()); - m_wndTree.RefreshMidiLibrary(); - EndWaitCursor(); - } + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "", "", + "Text and INI files (*.txt,*.ini)|*.txt;*.ini;*.dls;*.sf2;*.sbk|" + "Downloadable Sound Banks (*.dls)|*.dls;*.mss|" + "SoundFont 2.0 banks (*.sf2)|*.sbk;*.sf2|" + "Gravis UltraSound (ultrasnd.ini)|ultrasnd.ini|" + "All Files (*.*)|*.*||"); + if(files.abort) return; + + BeginWaitCursor(); + CTrackApp::ImportMidiConfig(files.first_file.c_str()); + m_wndTree.RefreshMidiLibrary(); + EndWaitCursor(); } Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2009-12-18 21:51:37 UTC (rev 444) @@ -368,7 +368,7 @@ CString m_csRegSettings; CString m_csRegWindow; // Globals - static UINT m_nLastOptionsPage, m_nFilterIndex; + static UINT m_nLastOptionsPage; static BOOL gbMdiMaximize; static bool gbShowHackControls; static LONG glCtrlWindowHeight, glTreeWindowWidth, glTreeSplitRatio; Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -22,12 +22,12 @@ static char THIS_FILE[] = __FILE__; #endif -const TCHAR* const FileFilterMOD = TEXT("ProTracker Modules (*.mod)|*.mod||"); -const TCHAR* const FileFilterXM = TEXT("FastTracker Modules (*.xm)|*.xm||"); -const TCHAR* const FileFilterS3M = TEXT("ScreamTracker Modules (*.s3m)|*.s3m||"); -const TCHAR* const FileFilterIT = TEXT("Impulse Tracker Modules (*.it)|*.it||"); -const TCHAR* const FileFilterITP = TEXT("Impulse Tracker Projects (*.itp)|*.itp||"); -const TCHAR* const FileFilterMPT = TEXT("OpenMPT Modules (*.mptm)|*.mptm||"); +const std::string FileFilterMOD = _T("ProTracker Modules (*.mod)|*.mod||"); +const std::string FileFilterXM = _T("FastTracker Modules (*.xm)|*.xm||"); +const std::string FileFilterS3M = _T("ScreamTracker Modules (*.s3m)|*.s3m||"); +const std::string FileFilterIT = _T("Impulse Tracker Modules (*.it)|*.it||"); +const std::string FileFilterITP = _T("Impulse Tracker Projects (*.itp)|*.itp||"); +const std::string FileFilterMPT = _T("OpenMPT Modules (*.mptm)|*.mptm||"); ///////////////////////////////////////////////////////////////////////////// // CModDoc @@ -489,25 +489,25 @@ CHAR s[_MAX_PATH] = ""; CHAR path[_MAX_PATH]="", drive[_MAX_DRIVE]=""; CHAR fname[_MAX_FNAME]="", fext[_MAX_EXT]=""; - LPCSTR lpszFilter = NULL, lpszDefExt = NULL; + std::string extFilter = "", defaultExtension = ""; switch(m_SndFile.GetType()) { case MOD_TYPE_MOD: MsgBoxHidable(ModCompatibilityExportTip); - lpszDefExt = "mod"; - lpszFilter = FileFilterMOD; + defaultExtension = "mod"; + extFilter = FileFilterMOD; strcpy(fext, ".mod"); break; case MOD_TYPE_S3M: - lpszDefExt = "s3m"; - lpszFilter = FileFilterS3M; + defaultExtension = "s3m"; + extFilter = FileFilterS3M; strcpy(fext, ".s3m"); break; case MOD_TYPE_XM: MsgBoxHidable(XMCompatibilityExportTip); - lpszDefExt = "xm"; - lpszFilter = FileFilterXM; + defaultExtension = "xm"; + extFilter = FileFilterXM; strcpy(fext, ".xm"); break; case MOD_TYPE_IT: @@ -517,22 +517,22 @@ // lpszFilter = "Impulse Tracker Modules (*.it)|*.it||"; // strcpy(fext, ".it"); if(m_SndFile.m_dwSongFlags & SONG_ITPROJECT){ - lpszDefExt = "itp"; - lpszFilter = FileFilterITP; + defaultExtension = "itp"; + extFilter = FileFilterITP; strcpy(fext, ".itp"); } else { MsgBoxHidable(ItCompatibilityExportTip); - lpszDefExt = "it"; - lpszFilter = FileFilterIT; + defaultExtension = "it"; + extFilter = FileFilterIT; strcpy(fext, ".it"); } // -! NEW_FEATURE#0023 break; case MOD_TYPE_MPT: - lpszDefExt = "mptm"; - lpszFilter = FileFilterMPT; + defaultExtension = "mptm"; + extFilter = FileFilterMPT; strcpy(fext, ".mptm"); break; default: @@ -547,18 +547,15 @@ strcat(s, path); strcat(s, fname); strcat(s, fext); - CFileDialog dlg(FALSE, lpszDefExt, s, - OFN_HIDEREADONLY| OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - lpszFilter, - theApp.m_pMainWnd); + + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, defaultExtension, s, + extFilter, + CMainFrame::GetWorkingDirectory(DIR_MODS)); + if(files.abort) return FALSE; - const LPCTSTR pszWdir = CMainFrame::GetWorkingDirectory(DIR_MODS); - if(pszWdir[0]) - dlg.m_ofn.lpstrInitialDir = pszWdir; + CMainFrame::SetWorkingDirectory(files.workingDirectory.c_str(), DIR_MODS, true); - if (dlg.DoModal() != IDOK) return FALSE; - strcpy(s, dlg.GetPathName()); - CMainFrame::SetWorkingDirectory(s, DIR_MODS, true); + strcpy(s, files.first_file.c_str()); _splitpath(s, drive, path, fname, fext); } else { @@ -1415,20 +1412,20 @@ if ((!pMainFrm) || (!m_SndFile.GetType())) return; _splitpath(GetPathName(), NULL, NULL, fname, NULL); - CFileDialog dlg(FALSE, "wav", fname, - OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - "Wave Files (*.wav)|*.wav||", pMainFrm); - dlg.m_ofn.lpstrInitialDir = CMainFrame::GetWorkingDirectory(DIR_EXPORT); CWaveConvert wsdlg(pMainFrm, nMinOrder, nMaxOrder); if (wsdlg.DoModal() != IDOK) return; - if (dlg.DoModal() != IDOK) return; //rewbs: made filename dialog appear after wav settings dialog + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "wav", fname, + "Wave Files (*.wav)|*.wav||", + CMainFrame::GetWorkingDirectory(DIR_EXPORT)); + if(files.abort) return; + // will set default dir here because there's no setup option for export dir yet (feel free to add one...) - pMainFrm->SetDefaultDirectory(dlg.GetPathName(), DIR_EXPORT, true); + CMainFrame::SetDefaultDirectory(files.workingDirectory.c_str(), DIR_EXPORT, true); TCHAR s[_MAX_PATH]; - strcpy(s, dlg.GetPathName()); + strcpy(s, files.first_file.c_str()); // Saving as wave file UINT p = 0, n = 1; @@ -1508,59 +1505,58 @@ void CModDoc::OnFileMP3Convert() //------------------------------ { + int nFilterIndex = 0; TCHAR sFName[_MAX_FNAME] = ""; CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); if ((!pMainFrm) || (!m_SndFile.GetType())) return; _splitpath(GetPathName(), NULL, NULL, sFName, NULL); - CFileDialog dlg(FALSE, "mp3", sFName, - OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - "MPEG Layer III Files (*.mp3)|*.mp3|Layer3 Wave Files (*.wav)|*.wav||", pMainFrm); - dlg.m_ofn.nFilterIndex = 0; - - dlg.m_ofn.lpstrInitialDir = CMainFrame::GetWorkingDirectory(DIR_EXPORT); - if (dlg.DoModal() == IDOK) - { - MPEGLAYER3WAVEFORMAT wfx; - HACMDRIVERID hadid; + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "mp3", sFName, + "MPEG Layer III Files (*.mp3)|*.mp3|Layer3 Wave Files (*.wav)|*.wav||", + CMainFrame::GetWorkingDirectory(DIR_EXPORT), + false, + &nFilterIndex); + if(files.abort) return; - // will set default dir here because there's no setup option for export dir yet (feel free to add one...) - pMainFrm->SetDefaultDirectory(dlg.GetPathName(), DIR_EXPORT, true); + MPEGLAYER3WAVEFORMAT wfx; + HACMDRIVERID hadid; - TCHAR s[_MAX_PATH], fext[_MAX_EXT]; - strcpy(s, dlg.GetPathName()); - _splitpath(s, NULL, NULL, NULL, fext); - if (strlen(fext) <= 1) - { - int l = strlen(s) - 1; - if ((l >= 0) && (s[l] == '.')) s[l] = 0; - strcpy(fext, (dlg.m_ofn.nFilterIndex == 2) ? ".wav" : ".mp3"); - strcat(s, fext); - } - CLayer3Convert wsdlg(&m_SndFile, pMainFrm); - if (m_SndFile.m_szNames[0][0]) wsdlg.m_bSaveInfoField = TRUE; - if (wsdlg.DoModal() != IDOK) return; - wsdlg.GetFormat(&wfx, &hadid); - // Saving as mpeg file - BOOL bplaying = FALSE; - UINT pos = m_SndFile.GetCurrentPos(); - bplaying = TRUE; - pMainFrm->PauseMod(); - m_SndFile.SetCurrentPos(0); + // will set default dir here because there's no setup option for export dir yet (feel free to add one...) + pMainFrm->SetDefaultDirectory(files.workingDirectory.c_str(), DIR_EXPORT, true); - m_SndFile.m_dwSongFlags &= ~SONG_PATTERNLOOP; - - // Saving file - CFileTagging *pTag = (wsdlg.m_bSaveInfoField) ? &wsdlg.m_FileTags : NULL; - CDoAcmConvert dwcdlg(&m_SndFile, s, &wfx.wfx, hadid, pTag, pMainFrm); - dwcdlg.m_dwFileLimit = wsdlg.m_dwFileLimit; - dwcdlg.m_dwSongLimit = wsdlg.m_dwSongLimit; - dwcdlg.DoModal(); - m_SndFile.SetCurrentPos(pos); - m_SndFile.GetLength(TRUE); - CMainFrame::UpdateAudioParameters(TRUE); + TCHAR s[_MAX_PATH], fext[_MAX_EXT]; + strcpy(s, files.first_file.c_str()); + _splitpath(s, NULL, NULL, NULL, fext); + if (strlen(fext) <= 1) + { + int l = strlen(s) - 1; + if ((l >= 0) && (s[l] == '.')) s[l] = 0; + strcpy(fext, (nFilterIndex == 2) ? ".wav" : ".mp3"); + strcat(s, fext); } + CLayer3Convert wsdlg(&m_SndFile, pMainFrm); + if (m_SndFile.m_szNames[0][0]) wsdlg.m_bSaveInfoField = TRUE; + if (wsdlg.DoModal() != IDOK) return; + wsdlg.GetFormat(&wfx, &hadid); + // Saving as mpeg file + BOOL bplaying = FALSE; + UINT pos = m_SndFile.GetCurrentPos(); + bplaying = TRUE; + pMainFrm->PauseMod(); + m_SndFile.SetCurrentPos(0); + + m_SndFile.m_dwSongFlags &= ~SONG_PATTERNLOOP; + + // Saving file + CFileTagging *pTag = (wsdlg.m_bSaveInfoField) ? &wsdlg.m_FileTags : NULL; + CDoAcmConvert dwcdlg(&m_SndFile, s, &wfx.wfx, hadid, pTag, pMainFrm); + dwcdlg.m_dwFileLimit = wsdlg.m_dwFileLimit; + dwcdlg.m_dwSongLimit = wsdlg.m_dwSongLimit; + dwcdlg.DoModal(); + m_SndFile.SetCurrentPos(pos); + m_SndFile.GetLength(TRUE); + CMainFrame::UpdateAudioParameters(TRUE); } @@ -1577,19 +1573,17 @@ strcat(s, path); strcat(s, fname); strcat(s, ".mid"); - CFileDialog dlg(FALSE, "mid", s, - OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - "Midi Files (*.mid,*.rmi)|*.mid;*.rmi||", pMainFrm); - dlg.m_ofn.nFilterIndex = 0; - if (dlg.DoModal() == IDOK) + + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "mid", s, + "Midi Files (*.mid,*.rmi)|*.mid;*.rmi||"); + if(files.abort) return; + + CModToMidi mididlg(files.first_file.c_str(), &m_SndFile, pMainFrm); + if (mididlg.DoModal() == IDOK) { - CModToMidi mididlg(dlg.GetPathName(), &m_SndFile, pMainFrm); - if (mididlg.DoModal() == IDOK) - { - BeginWaitCursor(); - mididlg.DoConvert(); - EndWaitCursor(); - } + BeginWaitCursor(); + mididlg.DoConvert(); + EndWaitCursor(); } } @@ -1598,9 +1592,9 @@ //------------------------------------- { CHAR path[_MAX_PATH]="", drive[_MAX_DRIVE]=""; - CHAR s[_MAX_PATH], fname[_MAX_FNAME]=""; + CHAR fname[_MAX_FNAME]=""; CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); - CString ext, pattern; + std::string ext, pattern, filename; UINT type = m_SndFile.GetType(); @@ -1639,35 +1633,30 @@ } _splitpath(GetPathName(), drive, path, fname, NULL); - strcpy(s, drive); - strcat(s, path); - strcat(s, fname); - if (!strstr(fname, "compat")) { - strcat(s, ".compat."); - } else { - strcat(s, "."); - } - strcat(s, ext); - CFileDialog dlg(FALSE, ext, s, - OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - pattern, pMainFrm); - dlg.m_ofn.lpstrInitialDir = CMainFrame::GetWorkingDirectory(DIR_MODS); + filename = drive; + filename += path; + filename += fname; + if (!strstr(fname, "compat")) + filename += ".compat."; + else + filename += "."; + filename += ext; - if (dlg.DoModal() != IDOK){ - return; - } + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, ext, filename, pattern, CMainFrame::GetWorkingDirectory(DIR_MODS)); + if(files.abort) return; + switch (type) { case MOD_TYPE_MOD: - m_SndFile.SaveMod(dlg.GetPathName(), 0, true); + m_SndFile.SaveMod(files.first_file.c_str(), 0, true); SetModified(); // Compatibility save may adjust samples so set modified... m_ShowSavedialog = true; // ...and force save dialog to appear when saving. break; case MOD_TYPE_XM: - m_SndFile.SaveXM(dlg.GetPathName(), 0, true); + m_SndFile.SaveXM(files.first_file.c_str(), 0, true); break; case MOD_TYPE_IT: - m_SndFile.SaveCompatIT(dlg.GetPathName()); + m_SndFile.SaveCompatIT(files.first_file.c_str()); break; } } Modified: trunk/OpenMPT/mptrack/Moptions.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moptions.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/Moptions.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -514,16 +514,10 @@ void COptionsColors::OnLoadColorScheme() //-------------------------------------- { - CFileDialog dlg(TRUE, NULL, NULL, - OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, - "OpenMPT Color Schemes|*.mptcolor|" - "All Files (*.*)|*.*||", - this); - dlg.m_ofn.lpstrInitialDir = theApp.GetConfigPath(); - if (dlg.DoModal() != IDOK) return; - - TCHAR sFilename[MAX_PATH]; - strcpy(sFilename, dlg.GetPathName()); + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "mptcolor", "", + "OpenMPT Color Schemes|*.mptcolor||", + theApp.GetConfigPath()); + if(files.abort) return; // Ensure that all colours are reset (for outdated colour schemes) OnPresetMPT(); @@ -531,7 +525,7 @@ { TCHAR sKeyName[16]; wsprintf(sKeyName, "Color%02d", i); - CustomColors[i] = CMainFrame::GetPrivateProfileLong("Colors", sKeyName, CustomColors[i], sFilename); + CustomColors[i] = CMainFrame::GetPrivateProfileLong("Colors", sKeyName, CustomColors[i], files.first_file.c_str()); } OnPreviewChanged(); } @@ -539,21 +533,16 @@ void COptionsColors::OnSaveColorScheme() //-------------------------------------- { - CFileDialog dlg(FALSE, "mptcolor", NULL, - OFN_HIDEREADONLY| OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - "OpenMPT Color Schemes|*.mptcolor|", - this); - dlg.m_ofn.lpstrInitialDir = theApp.GetConfigPath(); - if (dlg.DoModal() != IDOK) return; + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "mptcolor", "", + "OpenMPT Color Schemes|*.mptcolor||", + theApp.GetConfigPath()); + if(files.abort) return; - TCHAR sFilename[MAX_PATH]; - strcpy(sFilename, dlg.GetPathName()); - for(int i = 0; i < MAX_MODCOLORS; i++) { TCHAR sKeyName[16]; wsprintf(sKeyName, "Color%02d", i); - CMainFrame::WritePrivateProfileLong("Colors", sKeyName, CustomColors[i], sFilename); + CMainFrame::WritePrivateProfileLong("Colors", sKeyName, CustomColors[i], files.first_file.c_str()); } } Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -1430,63 +1430,47 @@ void CTrackApp::OnFileOpen() //-------------------------- { - CFileDialog dlg(TRUE, - NULL, - NULL, - OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_FORCESHOWHIDDEN | OFN_ALLOWMULTISELECT, -// -> CODE#0023 -// -> DESC="IT project files (.itp)" - "All Modules|*.mod;*.nst;*.wow;*.s3m;*.stm;*.669;*.mtm;*.xm;*.it;*.itp;*.mptm;*.ult;*.mdz;*.s3z;*.xmz;*.itz;mod.*;*.far;*.mdl;*.okt;*.dmf;*.ptm;*.mdr;*.med;*.ams;*.dbm;*.dsm;*.mid;*.rmi;*.smf;*.umx;*.amf;*.psm;*.mt2;*.gdm;*.imf;*.j2b" - #ifndef NO_MO3_SUPPORT - ";*.mo3" - #endif - "|" - "Compressed Modules (*.mdz;*.s3z;*.xmz;*.itz" - #ifndef NO_MO3_SUPPORT - ";*.mo3" - #endif - ")|*.mdz;*.s3z;*.xmz;*.itz;*.mdr;*.zip;*.rar;*.lha" - #ifndef NO_MO3_SUPPORT - ";*.mo3" - #endif - "|" -// -! NEW_FEATURE#0023 - "ProTracker Modules (*.mod,*.nst)|*.mod;mod.*;*.mdz;*.nst;*.m15|" - "ScreamTracker Modules (*.s3m,*.stm)|*.s3m;*.stm;*.s3z|" - "FastTracker Modules (*.xm)|*.xm;*.xmz|" - "Impulse Tracker Modules (*.it)|*.it;*.itz|" -// -> CODE#0023 -// -> DESC="IT project files (.itp)" - "Impulse Tracker Projects (*.itp)|*.itp;*.itpz|" -// -! NEW_FEATURE#0023 - "OpenMPT Modules (*.mptm)|*.mptm;*.mptmz|" - "Other Modules (mtm,okt,mdl,669,far,...)|*.mtm;*.669;*.ult;*.wow;*.far;*.mdl;*.okt;*.dmf;*.ptm;*.med;*.ams;*.dbm;*.dsm;*.umx;*.amf;*.psm;*.mt2;*.gdm;*.imf;*.j2b|" - "Wave Files (*.wav)|*.wav|" - "Midi Files (*.mid,*.rmi)|*.mid;*.rmi;*.smf|" - "All Files (*.*)|*.*||", - NULL); - dlg.m_ofn.nFilterIndex = CMainFrame::m_nFilterIndex; + static int nFilterIndex = 0; + FileDlgResult files = ShowOpenSaveFileDialog(true, "", "", + "All Modules|*.mod;*.nst;*.wow;*.s3m;*.stm;*.669;*.mtm;*.xm;*.it;*.itp;*.mptm;*.ult;*.mdz;*.s3z;*.xmz;*.itz;mod.*;*.far;*.mdl;*.okt;*.dmf;*.ptm;*.mdr;*.med;*.ams;*.dbm;*.dsm;*.mid;*.rmi;*.smf;*.umx;*.amf;*.psm;*.mt2;*.gdm;*.imf;*.j2b" +#ifndef NO_MO3_SUPPORT + ";*.mo3" +#endif + "|" + "Compressed Modules (*.mdz;*.s3z;*.xmz;*.itz" +#ifndef NO_MO3_SUPPORT + ";*.mo3" +#endif + ")|*.mdz;*.s3z;*.xmz;*.itz;*.mdr;*.zip;*.rar;*.lha" +#ifndef NO_MO3_SUPPORT + ";*.mo3" +#endif + "|" + // -! NEW_FEATURE#0023 + "ProTracker Modules (*.mod,*.nst)|*.mod;mod.*;*.mdz;*.nst;*.m15|" + "ScreamTracker Modules (*.s3m,*.stm)|*.s3m;*.stm;*.s3z|" + "FastTracker Modules (*.xm)|*.xm;*.xmz|" + "Impulse Tracker Modules (*.it)|*.it;*.itz|" + // -> CODE#0023 + // -> DESC="IT project files (.itp)" + "Impulse Tracker Projects (*.itp)|*.itp;*.itpz|" + // -! NEW_FEATURE#0023 + "OpenMPT Modules (*.mptm)|*.mptm;*.mptmz|" + "Other Modules (mtm,okt,mdl,669,far,...)|*.mtm;*.669;*.ult;*.wow;*.far;*.mdl;*.okt;*.dmf;*.ptm;*.med;*.ams;*.dbm;*.dsm;*.umx;*.amf;*.psm;*.mt2;*.gdm;*.imf;*.j2b|" + "Wave Files (*.wav)|*.wav|" + "Midi Files (*.mid,*.rmi)|*.mid;*.rmi;*.smf|" + "All Files (*.*)|*.*||", + CMainFrame::GetWorkingDirectory(DIR_MODS), + true, + &nFilterIndex); + if(files.abort) return; - const LPCTSTR pszWdir = CMainFrame::GetWorkingDirectory(DIR_MODS); - if(pszWdir[0]) - dlg.m_ofn.lpstrInitialDir = pszWdir; + CMainFrame::SetWorkingDirectory(files.workingDirectory.c_str(), DIR_MODS, true); - const size_t bufferSize = 2048; //Note: This is possibly the maximum buffer size in MFC 7(this note was written November 2006). - vector<char> filenameBuffer(bufferSize, 0); - dlg.GetOFN().lpstrFile = &filenameBuffer[0]; - dlg.GetOFN().nMaxFile = bufferSize; - if (dlg.DoModal() == IDOK) + for(size_t counter = 0; counter < files.filenames.size(); counter++) { - POSITION pos = dlg.GetStartPosition(); - while(pos != NULL) - { - CString pathName = dlg.GetNextPathName(pos); - CMainFrame::SetWorkingDirectory(pathName, DIR_MODS, true); - CMainFrame::m_nFilterIndex = dlg.m_ofn.nFilterIndex; - OpenDocumentFile(pathName); - } + OpenDocumentFile(files.filenames[counter].c_str()); } - filenameBuffer.clear(); } @@ -3282,3 +3266,92 @@ return CWinApp::ProcessWndProcException(e, pMsg); } //end rewbs.crashHandler + + +/* Open or save one or multiple files using the system's file dialog + * Parameter list: + * - load: true: load dialog. false: save dialog. + * - defaultExtension: dialog should use this as the default extension for the file(s) + * - defaultFilename: dialog should use this as the default filename + * - extFilter: list of possible extensions. format: "description|extensions|description|extensions|..." + * - workingDirectory: default directory of the dialog + * - allowMultiSelect: allow the user to select multiple files? (will be ignored if load == false) + * - filterIndex: pointer to a variable holding the index of the last extension filter used. + */ +FileDlgResult CTrackApp::ShowOpenSaveFileDialog(bool load, std::string defaultExtension, std::string defaultFilename, std::string extFilter, std::string workingDirectory, bool allowMultiSelect, int *filterIndex) +//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +{ + FileDlgResult result; + result.workingDirectory = workingDirectory; + result.first_file = ""; + result.filenames.clear(); + result.extension = defaultExtension; + result.abort = true; + + // we can't save multiple files. + if(!load) + { + allowMultiSelect = false; + } + + // First, set up the dialog... + CFileDialog dlg(load ? TRUE : FALSE, + defaultExtension.empty() ? NULL : defaultExtension.c_str(), + defaultFilename.empty() ? NULL : defaultFilename.c_str(), + load ? (OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | (allowMultiSelect ? OFN_ALLOWMULTISELECT : 0)) + : (OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN), + extFilter.empty() ? NULL : extFilter.c_str(), + theApp.m_pMainWnd); + if(!workingDirectory.empty()) + dlg.m_ofn.lpstrInitialDir = workingDirectory.c_str(); + if(filterIndex != nullptr) + dlg.m_ofn.nFilterIndex = (DWORD)(*filterIndex); + + // TODO is this necessary? Apparently not! + /*const size_t bufferSize = 2048; //Note: This is possibly the maximum buffer size in MFC 7(this note was written November 2006). + vector<char> filenameBuffer(bufferSize, 0); + dlg.GetOFN().lpstrFile = &filenameBuffer[0]; + dlg.GetOFN().nMaxFile = bufferSize;*/ + + // Do it! + CMainFrame::GetInputHandler()->Bypass(true); + if(dlg.DoModal() != IDOK) + { + CMainFrame::GetInputHandler()->Bypass(false); + return result; + } + CMainFrame::GetInputHandler()->Bypass(false); + + // Retrieve variables + if(filterIndex != nullptr) + *filterIndex = dlg.m_ofn.nFilterIndex; + + if(allowMultiSelect) + { + // multiple files might have been selected + POSITION pos = dlg.GetStartPosition(); + while(pos != NULL) + { + std::string filename = dlg.GetNextPathName(pos); + result.filenames.push_back(filename); + } + + } else + { + // only one file + std::string filename = dlg.GetPathName(); + result.filenames.push_back(filename); + } + + if(!result.filenames.empty()) + { + // some file has been selected. + result.workingDirectory = result.filenames.back(); + result.first_file = result.filenames.front(); + result.abort = false; + } + + result.extension = dlg.GetFileExt(); + + return result; +} Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/Mptrack.h 2009-12-18 21:51:37 UTC (rev 444) @@ -112,7 +112,20 @@ } REQUEST_CONTEXT; #endif + ///////////////////////////////////////////////////////////////////////////// +// File dialog (open/save) results +struct FileDlgResult +{ + std::string workingDirectory; // working directory. will include filename, so beware. + std::string first_file; // for some convenience, this will keep the first filename of the filenames vector. + std::vector <std::string> filenames; // all selected filenames in one vector. + std::string extension; // extension used. beware of this when multiple files can be selected! + bool abort; // no selection has been made. +}; + + +///////////////////////////////////////////////////////////////////////////// // CTrackApp: // See mptrack.cpp for the implementation of this class // @@ -175,6 +188,8 @@ static BOOL AddDLSBank(LPCSTR); static BOOL OpenURL(LPCSTR lpszURL); + static FileDlgResult ShowOpenSaveFileDialog(bool load, std::string defaultExtension, std::string defaultFilename, std::string extFilter, std::string workingDirectory = "", bool allowMultiSelect = false, int *filterIndex = nullptr); + public: CDocTemplate *GetModDocTemplate() const { return m_pModTemplate; } CVstPluginManager *GetPluginManager() const { return m_pPluginManager; } Modified: trunk/OpenMPT/mptrack/TuningDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/TuningDialog.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/TuningDialog.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -619,24 +619,23 @@ return; } - string filter; + std::string filter; if(pT != NULL) filter = string("Tuning files (*") + CTuning::s_FileExtension + string(")|*") + CTuning::s_FileExtension + string("|"); if(pTC != NULL) filter += string("Tuning collection files (") + CTuningCollection::s_FileExtension + string(")|*") + CTuningCollection::s_FileExtension + string("|"); - CFileDialog dlg(FALSE, CTuning::s_FileExtension.c_str(), - NULL, - OFN_HIDEREADONLY| OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - filter.c_str(), this); - dlg.m_ofn.lpstrInitialDir = theApp.GetTuningsPath(); + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, CTuning::s_FileExtension, "", + filter, + theApp.GetTuningsPath()); + if(files.abort) return; + BeginWaitCursor(); + bool failure = true; - if (dlg.DoModal() != IDOK) return; - BeginWaitCursor(); - ofstream fout(dlg.GetPathName(), ios::binary); - const string ext = "." + dlg.GetFileExt(); + ofstream fout(files.first_file.c_str(), ios::binary); + const string ext = "." + files.extension; if(ext == CTuning::s_FileExtension) { @@ -663,23 +662,18 @@ string filter = string("Tuning files (*") + CTuning::s_FileExtension + string(", *") + CTuningCollection::s_FileExtension + string(")|*") + CTuning::s_FileExtension + string(";*") + CTuningCollection::s_FileExtension + string("|"); - CFileDialog dlg(TRUE, - NULL, - NULL, - OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, - filter.c_str(), - this); - dlg.m_ofn.lpstrInitialDir = theApp.GetTuningsPath(); + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "", "", + filter, + theApp.GetTuningsPath()); + if(files.abort) return; - if (dlg.DoModal() != IDOK) return; + const string ext = string(".") + files.extension; - const string ext = string(".") + string(dlg.GetFileExt()); - bool failure = true; if(ext == CTuning::s_FileExtension) { - ifstream fin(dlg.GetPathName(), ios::binary); + ifstream fin(files.first_file.c_str(), ios::binary); CTuning* pT = CTuningRTI::DeserializeOLD(fin); if(pT == 0) {fin.clear(); fin.seekg(0); pT = CTuningRTI::Deserialize(fin);} fin.close(); @@ -701,7 +695,7 @@ //a separate collection - no possibility to //directly replace some collection. CTuningCollection* pNewTCol = new CTuningCollection; - pNewTCol->SetSavefilePath(static_cast<LPCTSTR>(dlg.GetPathName())); + pNewTCol->SetSavefilePath(static_cast<LPCTSTR>(files.first_file.c_str())); failure = pNewTCol->Deserialize(); if(failure) { Modified: trunk/OpenMPT/mptrack/View_gen.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/View_gen.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -1019,13 +1019,13 @@ //rewbs.fxpPresets: changed Eric's code to use fxp load/save if(pVstPlugin == NULL) return; - CFileDialog dlg(TRUE, "fxp", NULL, - OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_NOREADONLYRETURN, - "VST FX Program (*.fxp)|*.fxp||", theApp.m_pMainWnd); - if (!(dlg.DoModal() == IDOK)) return; + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "fxp", "", + "VST FX Program (*.fxp)|*.fxp||", + CMainFrame::GetDefaultDirectory(DIR_PLUGINPRESETS)); + if(files.abort) return; //TODO: exception handling - if (!(pVstPlugin->LoadProgram(dlg.GetFileName()))) { + if (!(pVstPlugin->LoadProgram(files.first_file.c_str()))) { ::AfxMessageBox("Error loading preset.Are you sure it is for this plugin?"); } else { if (pSndFile->m_nType & (MOD_TYPE_XM|MOD_TYPE_IT|MOD_TYPE_MPT)) pModDoc->SetModified(); @@ -1045,13 +1045,13 @@ if(pVstPlugin == NULL) return; //rewbs.fxpPresets: changed Eric's code to use fxp load/save - CFileDialog dlg(FALSE, "fxp", NULL, - OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_NOREADONLYRETURN, - "VST Program (*.fxp)|*.fxp||", theApp.m_pMainWnd); - if (!(dlg.DoModal() == IDOK)) return; + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "fxp", "", + "VST Program (*.fxp)|*.fxp||", + CMainFrame::GetDefaultDirectory(DIR_PLUGINPRESETS)); + if(files.abort) return; //TODO: exception handling - if (!(pVstPlugin->SaveProgram(dlg.GetFileName()))) + if (!(pVstPlugin->SaveProgram(files.first_file.c_str()))) ::AfxMessageBox("Error saving preset."); //end rewbs.fxpPresets Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -1492,24 +1492,21 @@ BOOL CModTree::OpenMidiInstrument(DWORD dwItem) //--------------------------------------------- { - CFileDialog dlg(TRUE, - NULL, - NULL, - OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, - "All Instruments and Banks|*.xi;*.pat;*.iti;*.wav;*.aif;*.aiff;*.sf2;*.sbk;*.dls|" - "FastTracker II Instruments (*.xi)|*.xi|" - "GF1 Patches (*.pat)|*.pat|" - "Wave Files (*.wav)|*.wav|" - "Impulse Tracker Instruments (*.iti)|*.iti;*.its|" - "SoundFont 2.0 Banks (*.sf2)|*.sf2;*.sbk|" - "DLS Sound Banks (*.dls)|*.dls|" - "All Files (*.*)|*.*||", - this); - if (dlg.DoModal() != IDOK) return FALSE; + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "", "", + "All Instruments and Banks|*.xi;*.pat;*.iti;*.wav;*.aif;*.aiff;*.sf2;*.sbk;*.dls|" + "FastTracker II Instruments (*.xi)|*.xi|" + "GF1 Patches (*.pat)|*.pat|" + "Wave Files (*.wav)|*.wav|" + "Impulse Tracker Instruments (*.iti)|*.iti;*.its|" + "SoundFont 2.0 Banks (*.sf2)|*.sf2;*.sbk|" + "DLS Sound Banks (*.dls)|*.dls|" + "All Files (*.*)|*.*||"); + if(files.abort) return FALSE; + if (dwItem & 0x80) - return SetMidiPercussion(dwItem & 0x7F, dlg.GetPathName()); + return SetMidiPercussion(dwItem & 0x7F, files.first_file.c_str()); else - return SetMidiInstrument(dwItem, dlg.GetPathName()); + return SetMidiInstrument(dwItem, files.first_file.c_str()); } @@ -2914,24 +2911,12 @@ if(pSndFile && modItemID){ - CHAR pszFileNames[_MAX_PATH]; - CFileDialog dlg(TRUE, NULL, NULL, - OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_FORCESHOWHIDDEN, - "All files(*.*)|*.*||", - this); + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "", "", + "All files(*.*)|*.*||"); + if(files.abort) return; - pszFileNames[0] = 0; - pszFileNames[1] = 0; - dlg.m_ofn.lpstrFile = pszFileNames; - dlg.m_ofn.nMaxFile = _MAX_PATH; - - if(dlg.DoModal() == IDOK){ - strcpy(pSndFile->m_szInstrumentPath[modItemID - 1], pszFileNames); - OnRefreshTree(); - } - - dlg.m_ofn.lpstrFile = NULL; - dlg.m_ofn.nMaxFile = 0; + strcpy(pSndFile->m_szInstrumentPath[modItemID - 1], files.first_file.c_str()); + OnRefreshTree(); } } @@ -2948,26 +2933,17 @@ if(pSndFile && modItemID){ - if(pSndFile->m_szInstrumentPath[modItemID - 1][0] == '\0'){ - CHAR pszFileNames[_MAX_PATH]; + if(pSndFile->m_szInstrumentPath[modItemID - 1][0] == '\0') + { + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, (pSndFile->GetType() == MOD_TYPE_XM) ? "xi" : "iti", "", + (pSndFile->GetType() == MOD_TYPE_XM) ? + "FastTracker II Instruments (*.xi)|*.xi|" + "Impulse Tracker Instruments (*.iti)|*.iti||" : + "Impulse Tracker Instruments (*.iti)|*.iti|" + "FastTracker II Instruments (*.xi)|*.xi||"); + if(files.abort) return; - CFileDialog dlg(FALSE, (pSndFile->m_nType & (MOD_TYPE_IT|MOD_TYPE_MPT)) ? "iti" : "xi", NULL, - OFN_HIDEREADONLY| OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - ( pSndFile->m_nType & (MOD_TYPE_IT|MOD_TYPE_MPT) ? "Impulse Tracker Instruments (*.iti)|*.iti|" - "FastTracker II Instruments (*.xi)|*.xi||" - : "FastTracker II Instruments (*.xi)|*.xi|" - "Impulse Tracker Instruments (*.iti)|*.iti||" ), - this); - - pszFileNames[0] = 0; - pszFileNames[1] = 0; - dlg.m_ofn.lpstrFile = pszFileNames; - dlg.m_ofn.nMaxFile = _MAX_PATH; - - if(dlg.DoModal() == IDOK) strcpy(pSndFile->m_szInstrumentPath[modItemID - 1], pszFileNames); - - dlg.m_ofn.lpstrFile = NULL; - dlg.m_ofn.nMaxFile = 0; + strcpy(pSndFile->m_szInstrumentPath[modItemID - 1], files.first_file.c_str()); } if(pSndFile->m_szInstrumentPath[modItemID - 1][0] != '\0'){ @@ -3009,18 +2985,12 @@ void CModTree::OnExportMidiLib() //------------------------------ { - CHAR szFileName[_MAX_PATH] = "mptrack.ini"; - CFileDialog dlg(FALSE, - "ini", - szFileName, - OFN_HIDEREADONLY| OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN, - "Text and INI files (*.txt,*.ini)|*.txt;*.ini|" - "All Files (*.*)|*.*||", - this); - if (dlg.DoModal() == IDOK) - { - CTrackApp::ExportMidiConfig(dlg.GetPathName()); - } + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(false, "ini", "mptrack.ini", + "Text and INI files (*.txt,*.ini)|*.txt;*.ini|" + "All Files (*.*)|*.*||"); + if(files.abort) return; + + CTrackApp::ExportMidiConfig(files.first_file.c_str()); } Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2009-12-17 21:42:45 UTC (rev 443) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2009-12-18 21:51:37 UTC (rev 444) @@ -1411,54 +1411,34 @@ //---------------------------------- { CHAR *pszFileNames; - CFileDialog dlg(TRUE, ".dll", NULL, - OFN_FILEMUSTEXIST|OFN_ENABLESIZING |OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_FORCESHOWHIDDEN|OFN_ALLOWMULTISELECT, - "VST Plugins (*.dll)|*.dll||", - this); - - const LPCTSTR pszWdir = CMainFrame::GetWorkingDirectory(DIR_PLUGINS); - if(pszWdir[0]) - dlg.m_ofn.lpstrInitialDir = pszWdir; - pszFileNames = new CHAR[MAX_FILEOPEN_BUFSIZE]; - if (!pszFileNames) return; - pszFileNames[0] = 0; - pszFileNames[1] = 0; - dlg.m_ofn.lpstrFile = pszFileNames; - dlg.m_ofn.nMaxFile = MAX_FILEOPEN_BUFSIZE; - if (dlg.DoModal() == IDOK) + FileDlgResult files = CTrackApp::ShowOpenSaveFileDialog(true, "dll", "", + "VST Plugins (*.dll)|*.dll||", + CMainFrame::GetWorkingDirectory(DIR_PLUGINS), + true); + if(files.abort) return; + + CMainFrame::SetWorkingDirectory(files.workingDirectory.c_str(), DIR_PLUGINS, true); + + CVstPluginManager *pManager = theApp.GetPluginManager(); + bool bOk = false; + + PVSTPLUGINLIB plugLib = NULL; + for(size_t counter = 0; counter < files.filenames.size(); counter++) { - CVstPluginManager *pManager = theApp.GetPluginManager(); - pszFileNames[MAX_FILEOPEN_BUFSIZE-1] = 0; - POSITION pos = dlg.GetStartPosition(); - BOOL bOk = FALSE; - - int n = 0; - PVSTPLUGINLIB plugLib = NULL; - while (pos != NULL) { - CString sFilename = dlg.GetNextPathName(pos); - if (!n) { - CMainFrame::SetWorkingDirectory(sFilename, DIR_PLUGINS, true); - } - n++; + CString sFilename = files.filenames[counter].c_str(); - if (pManager) { - plugLib = pManager->AddPlugin(sFilename, FALSE); - if (plugLib) { - bOk = TRUE; - } - } + if (pManager) { + plugLib = pManager->AddPlugin(sFilename, FALSE); + if (plugLib) bOk = true; } - if (bOk) { - UpdatePluginsList(plugLib->dwPluginId2); //force selection to last added plug. - } else { - MessageBox("At least one selected file was not a valid VST-Plugin", NULL, MB_ICONERROR|MB_OK); - } } - dlg.m_ofn.lpstrFile = NULL; - dlg.m_ofn.nMaxFile = 0; - delete[] pszFileNames; + if (bOk) { + UpdatePluginsList(plugLib->dwPluginId2); //force selection to last added plug. + } else { + MessageBox("At least one selected file was not a valid VST-Plugin", NULL, MB_ICONERROR|MB_OK); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |