Fix "Import plugins" not working issue.
This commit is contained in:
parent
3465cac7ce
commit
f03ce289d3
@ -5447,6 +5447,52 @@ vector<generic_string> Notepad_plus::addNppComponents(const TCHAR *destDir, cons
|
||||
return copiedFiles;
|
||||
}
|
||||
|
||||
vector<generic_string> Notepad_plus::addNppPlugins(const TCHAR *extFilterName, const TCHAR *extFilter)
|
||||
{
|
||||
FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst());
|
||||
fDlg.setExtFilter(extFilterName, extFilter, NULL);
|
||||
|
||||
vector<generic_string> copiedFiles;
|
||||
|
||||
if (stringVector *pfns = fDlg.doOpenMultiFilesDlg())
|
||||
{
|
||||
// Get plugins dir
|
||||
generic_string destDirName = (NppParameters::getInstance())->getPluginRootDir();
|
||||
|
||||
if (!::PathFileExists(destDirName.c_str()))
|
||||
{
|
||||
::CreateDirectory(destDirName.c_str(), NULL);
|
||||
}
|
||||
|
||||
size_t sz = pfns->size();
|
||||
for (size_t i = 0 ; i < sz ; ++i)
|
||||
{
|
||||
if (::PathFileExists(pfns->at(i).c_str()))
|
||||
{
|
||||
// copy to plugins directory
|
||||
generic_string destName = destDirName;
|
||||
|
||||
generic_string nameExt = ::PathFindFileName(pfns->at(i).c_str());
|
||||
auto pos = nameExt.find_last_of(TEXT("."));
|
||||
if (pos == generic_string::npos)
|
||||
continue;
|
||||
|
||||
generic_string name = nameExt.substr(0, pos);
|
||||
PathAppend(destName, name);
|
||||
if (!::PathFileExists(destName.c_str()))
|
||||
{
|
||||
::CreateDirectory(destName.c_str(), NULL);
|
||||
}
|
||||
PathAppend(destName, nameExt);
|
||||
|
||||
if (::CopyFile(pfns->at(i).c_str(), destName.c_str(), FALSE))
|
||||
copiedFiles.push_back(destName.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return copiedFiles;
|
||||
}
|
||||
|
||||
void Notepad_plus::setWorkingDir(const TCHAR *dir)
|
||||
{
|
||||
NppParameters * params = NppParameters::getInstance();
|
||||
|
@ -240,6 +240,7 @@ public:
|
||||
bool replaceInFiles();
|
||||
void setFindReplaceFolderFilter(const TCHAR *dir, const TCHAR *filters);
|
||||
std::vector<generic_string> addNppComponents(const TCHAR *destDir, const TCHAR *extFilterName, const TCHAR *extFilter);
|
||||
std::vector<generic_string> addNppPlugins(const TCHAR *extFilterName, const TCHAR *extFilter);
|
||||
int getHtmlXmlEncoding(const TCHAR *fileName) const;
|
||||
HACCEL getAccTable() const{
|
||||
return _accelerator.getAccTable();
|
||||
|
@ -2429,23 +2429,21 @@ void Notepad_plus::command(int id)
|
||||
|
||||
case IDM_SETTING_IMPORTPLUGIN :
|
||||
{
|
||||
// get plugin source path
|
||||
// Copy plugins to Plugins Home
|
||||
const TCHAR *extFilterName = TEXT("Notepad++ plugin");
|
||||
const TCHAR *extFilter = TEXT(".dll");
|
||||
const TCHAR *destDir = TEXT("plugins");
|
||||
vector<generic_string> copiedFiles = addNppPlugins(extFilterName, extFilter);
|
||||
|
||||
vector<generic_string> copiedFiles = addNppComponents(destDir, extFilterName, extFilter);
|
||||
|
||||
// load plugin
|
||||
for (size_t i = 0, len = copiedFiles.size() ; i < len ; ++i)
|
||||
{
|
||||
int index = _pluginsManager.loadPlugin(copiedFiles[i].c_str());
|
||||
if (_pluginsManager.getMenuHandle())
|
||||
_pluginsManager.addInMenuFromPMIndex(index);
|
||||
}
|
||||
if (!_pluginsManager.getMenuHandle())
|
||||
_pluginsManager.setMenu(_mainMenuHandle, NULL);
|
||||
::DrawMenuBar(_pPublicInterface->getHSelf());
|
||||
// Tell users to restart Notepad++ to load plugin
|
||||
if (copiedFiles.size())
|
||||
{
|
||||
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
|
||||
pNativeSpeaker->messageBox("NeedToRestartToLoadPlugins",
|
||||
NULL,
|
||||
TEXT("You have to restart Notepad++ to load plugins you installed."),
|
||||
TEXT("Notepad++ need to be relaunched"),
|
||||
MB_OK | MB_APPLMODAL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user