From: <sv...@op...> - 2024-11-19 18:23:07
|
Author: sagamusix Date: Tue Nov 19 19:22:58 2024 New Revision: 22245 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22245 Log: [Imp] Tree view: Add option to open modules and instrument library entries in Explorer (https://bugs.openmpt.org/view.php?id=677). Modified: trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/View_tre.cpp Modified: trunk/OpenMPT/mptrack/Mptrack.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp Tue Nov 19 19:15:56 2024 (r22244) +++ trunk/OpenMPT/mptrack/Mptrack.cpp Tue Nov 19 19:22:58 2024 (r22245) @@ -2441,7 +2441,7 @@ return OpenURL(mpt::PathString::FromUnicode(url)); } -bool CTrackApp::OpenURL(const mpt::PathString &lpszURL) +bool CTrackApp::OpenURL(const mpt::PathString &lpszURL, const mpt::tstring ¶m) { if(!lpszURL.empty() && theApp.m_pMainWnd) { @@ -2449,8 +2449,8 @@ theApp.m_pMainWnd->m_hWnd, _T("open"), lpszURL.AsNative().c_str(), - NULL, - NULL, + param.empty() ? nullptr : param.c_str(), + nullptr, SW_SHOW)) >= 32) { return true; @@ -2459,6 +2459,14 @@ return false; } +bool CTrackApp::OpenDirectory(const mpt::PathString &directory) +{ + if(mpt::native_fs{}.is_file(directory)) + return OpenURL(P_("explorer.exe"), MPT_TFORMAT("/select,\"{}\"")(directory.AsNative())); + else + return OpenURL(directory); +} + CString CTrackApp::GetResamplingModeName(ResamplingMode mode, int length, bool addTaps) { Modified: trunk/OpenMPT/mptrack/Mptrack.h ============================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h Tue Nov 19 19:15:56 2024 (r22244) +++ trunk/OpenMPT/mptrack/Mptrack.h Tue Nov 19 19:22:58 2024 (r22245) @@ -204,9 +204,9 @@ static bool OpenURL(const std::string &url); // UTF8 static bool OpenURL(const CString &url); static bool OpenURL(const mpt::ustring &url); - static bool OpenURL(const mpt::PathString &lpszURL); + static bool OpenURL(const mpt::PathString &lpszURL, const mpt::tstring ¶m = {}); static bool OpenFile(const mpt::PathString &file) { return OpenURL(file); }; - static bool OpenDirectory(const mpt::PathString &directory) { return OpenURL(directory); }; + static bool OpenDirectory(const mpt::PathString &directory); // Retrieve the user-supplied MIDI port name for a MIDI input or output port. mpt::ustring GetFriendlyMIDIPortName(const mpt::ustring &deviceName, bool isInputPort, bool addDeviceName = true); Modified: trunk/OpenMPT/mptrack/View_tre.cpp ============================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp Tue Nov 19 19:15:56 2024 (r22244) +++ trunk/OpenMPT/mptrack/View_tre.cpp Tue Nov 19 19:22:58 2024 (r22245) @@ -1825,13 +1825,18 @@ switch(modItem.type) { + case MODITEM_HDR_SONG: + CTrackApp::OpenDirectory(GetDocumentFromItem(hItem)->GetPathNameMpt()); + break; case MODITEM_INSLIB_SONG: theApp.OpenDocumentFile(InsLibGetFullPath(hItem).ToCString()); break; case MODITEM_HDR_INSTRUMENTLIB: - CTrackApp::OpenDirectory(m_InstrLibPath); + CTrackApp::OpenDirectory(m_InstrLibPath + m_SongFileName); break; case MODITEM_INSLIB_FOLDER: + case MODITEM_INSLIB_INSTRUMENT: + case MODITEM_INSLIB_SAMPLE: // Open path in Explorer CTrackApp::OpenDirectory(InsLibGetFullPath(hItem)); break; @@ -3047,6 +3052,7 @@ AppendMenu(hMenu, MF_STRING, defaultID, ih->GetKeyTextFromCommand(kcTreeViewOpen, _T("&View"))); AppendMenu(hMenu, MF_STRING, ID_MODTREE_CLOSE, _T("&Close")); AppendMenu(hMenu, MF_STRING, ID_MODTREE_RENAME, ih->GetKeyTextFromCommand(kcTreeViewRename, _T("Re&name"))); + AppendMenu(hMenu, MF_STRING, ID_MODTREE_OPENITEM, _T("&Open in Explorer")); break; case MODITEM_COMMENTS: @@ -3114,7 +3120,7 @@ AppendMenu(hMenu, MF_STRING, ID_MODTREE_RENAME, ih->GetKeyTextFromCommand(kcTreeViewRename, _T("Re&name Sample"))); if(modDoc && !modDoc->GetNumInstruments()) { - AppendMenu(hMenu, MF_SEPARATOR, NULL, _T("")); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); AppendMenu(hMenu, (modDoc->IsSampleMuted((SAMPLEINDEX)modItemID) ? MF_CHECKED : 0) | MF_STRING, ID_MODTREE_MUTE, _T("&Mute Sample")); AppendMenu(hMenu, MF_STRING, ID_MODTREE_SOLO, _T("S&olo Sample")); AppendMenu(hMenu, MF_STRING, ID_MODTREE_UNMUTEALL, _T("&Unmute all")); @@ -3146,7 +3152,7 @@ if(menuForThisSample || anyPath || anyModified) { - AppendMenu(hMenu, MF_SEPARATOR, NULL, _T("")); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); if(menuForThisSample) AppendMenu(hMenu, MF_STRING | ((sndFile->GetType() == MOD_TYPE_MPT || hasPath) ? 0 : MF_GRAYED), ID_MODTREE_SETPATH, _T("Set P&ath")); if(menuForThisSample) AppendMenu(hMenu, MF_STRING | ((hasPath && sample.HasSampleData() && sample.uFlags[SMP_MODIFIED]) ? 0 : MF_GRAYED), ID_MODTREE_SAVEITEM, _T("&Save")); if(anyModified) AppendMenu(hMenu, MF_STRING, ID_MODTREE_SAVEALL, _T("&Save All")); @@ -3167,7 +3173,7 @@ AppendMenu(hMenu, MF_STRING, ID_MODTREE_RENAME, ih->GetKeyTextFromCommand(kcTreeViewRename, _T("Re&name Instrument"))); if(modDoc) { - AppendMenu(hMenu, MF_SEPARATOR, NULL, _T("")); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); AppendMenu(hMenu, (modDoc->IsInstrumentMuted((INSTRUMENTINDEX)modItemID) ? MF_CHECKED : 0) | MF_STRING, ID_MODTREE_MUTE, _T("&Mute Instrument")); AppendMenu(hMenu, MF_STRING, ID_MODTREE_SOLO, _T("S&olo Instrument")); AppendMenu(hMenu, MF_STRING, ID_MODTREE_UNMUTEALL, _T("&Unmute all")); @@ -3200,7 +3206,7 @@ AppendMenu(hMenu, MF_STRING, defaultID, ih->GetKeyTextFromCommand(kcTreeViewOpen, _T("&Map Instrument"))); AppendMenu(hMenu, MF_STRING, ID_MODTREE_PLAY, ih->GetKeyTextFromCommand(kcTreeViewPlay, _T("&Play Instrument"))); AppendMenu(hMenu, MF_STRING, ID_MODTREE_REMOVE, _T("&Unmap Instrument")); - AppendMenu(hMenu, MF_SEPARATOR, NULL, _T("")); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); [[fallthrough]]; case MODITEM_HDR_MIDILIB: case MODITEM_HDR_MIDIGROUP: @@ -3240,7 +3246,7 @@ AppendMenu(hMenu, MF_STRING, defaultID, ih->GetKeyTextFromCommand(kcTreeViewOpen, _T("&Browse Song..."))); AppendMenu(hMenu, MF_STRING, ID_MODTREE_OPENITEM, _T("&Edit Song")); hSubMenu = AddLibraryFindAndSortMenus(hMenu); - AppendMenu(hMenu, MF_SEPARATOR, NULL, _T("")); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); AppendMenu(hMenu, MF_STRING, ID_MODTREE_REMOVE, ih->GetKeyTextFromCommand(kcTreeViewDelete, _T("&Delete"))); break; @@ -3253,6 +3259,8 @@ } else { AppendMenu(hMenu, MF_STRING, ID_MODTREE_PLAY, ih->GetKeyTextFromCommand(kcTreeViewPlay, _T("&Play File"))); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); + AppendMenu(hMenu, MF_STRING, ID_MODTREE_OPENITEM, _T("&Open in Explorer")); AppendMenu(hMenu, MF_STRING, ID_MODTREE_REMOVE, ih->GetKeyTextFromCommand(kcTreeViewDelete, _T("&Delete"))); } hSubMenu = AddLibraryFindAndSortMenus(hMenu); @@ -3285,7 +3293,7 @@ || (modItem.type == MODITEM_HDR_INSTRUMENTLIB)) { if(addSeparator || defaultID) - AppendMenu(hMenu, MF_SEPARATOR, NULL, _T("")); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); AppendMenu(hMenu, TrackerSettings::Instance().showDirsInSampleBrowser ? (MF_STRING|MF_CHECKED) : MF_STRING, ID_MODTREE_SHOWDIRS, _T("Show &Directories in Sample Browser")); AppendMenu(hMenu, (m_showAllFiles) ? (MF_STRING|MF_CHECKED) : MF_STRING, ID_MODTREE_SHOWALLFILES, _T("Show &All Files")); AppendMenu(hMenu, (m_showAllFiles) ? MF_STRING : (MF_STRING|MF_CHECKED), ID_MODTREE_SOUNDFILESONLY, _T("Show &Sound Files")); @@ -3293,7 +3301,7 @@ } if(addSeparator || defaultID) - AppendMenu(hMenu, MF_SEPARATOR, NULL, _T("")); + AppendMenu(hMenu, MF_SEPARATOR, 0, _T("")); AppendMenu(hMenu, MF_STRING, ID_MODTREE_REFRESH, _T("&Refresh")); TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x + 4, pt.y, 0, m_hWnd, NULL); @@ -3835,7 +3843,7 @@ std::vector<INSTRUMENTINDEX> newOrder = GenerateInsertVector<INSTRUMENTINDEX>(sndFile.GetNumInstruments(), modItemID, static_cast<INSTRUMENTINDEX>(insert ? 0 : modItemID), 1); if(modDoc.ReArrangeInstruments(newOrder) != INSTRUMENTINDEX_INVALID) { - modDoc.UpdateAllViews(NULL, InstrumentHint().Info().Envelope().Names()); + modDoc.UpdateAllViews(nullptr, InstrumentHint().Info().Envelope().Names()); modDoc.UpdateAllViews(nullptr, PatternHint().Data()); modDoc.SetModified(); } else @@ -3904,7 +3912,7 @@ SAMPLEINDEX smpID = static_cast<SAMPLEINDEX>(modItem.val1); pModDoc->SaveSample(smpID); if(pModDoc) - pModDoc->UpdateAllViews(NULL, SampleHint(smpID).Info()); + pModDoc->UpdateAllViews(nullptr, SampleHint(smpID).Info()); OnRefreshTree(); } } @@ -3945,7 +3953,7 @@ { pModDoc->SetModified(); } - pModDoc->UpdateAllViews(NULL, SampleHint(smpID).Info().Data().Names()); + pModDoc->UpdateAllViews(nullptr, SampleHint(smpID).Info().Data().Names()); } OnRefreshTree(); @@ -4086,7 +4094,7 @@ if(stgm.hGlobal == NULL) return FALSE; hDropInfo = (HDROP)stgm.hGlobal; - nFiles = DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); + nFiles = DragQueryFile(hDropInfo, (UINT)-1, nullptr, 0); if(nFiles) { UINT size = ::DragQueryFile(hDropInfo, 0, nullptr, 0) + 1; @@ -4679,7 +4687,7 @@ void CModTree::OnDropFiles(HDROP hDropInfo) { bool refreshDLS = false; - const UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); + const UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, nullptr, 0); CMainFrame::GetMainFrame()->SetForegroundWindow(); for(UINT f = 0; f < nFiles; f++) { |