Fix docked panels appear with "-nosession" cmd line parameters

Fix #8005
This commit is contained in:
Don HO 2020-11-09 04:19:37 +01:00
parent 1961f708c1
commit 7399257f56
4 changed files with 204 additions and 76 deletions

View File

@ -207,7 +207,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
// Menu
_mainMenuHandle = ::GetMenu(hwnd);
int langPos2BeRemoved = MENUINDEX_LANGUAGE+1;
int langPos2BeRemoved = MENUINDEX_LANGUAGE + 1;
if (nppGUI._isLangMenuCompact)
langPos2BeRemoved = MENUINDEX_LANGUAGE;
::RemoveMenu(_mainMenuHandle, langPos2BeRemoved, MF_BYPOSITION);
@ -421,7 +421,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
if (nbMacro >= 1)
::InsertMenu(hMacroMenu, posBase - 1, MF_BYPOSITION, static_cast<UINT>(-1), 0);
for (size_t i = 0 ; i < nbMacro ; ++i)
for (size_t i = 0; i < nbMacro; ++i)
::InsertMenu(hMacroMenu, static_cast<UINT>(posBase + i), MF_BYPOSITION, ID_MACRO + i, macros[i].toMenuItemString().c_str());
if (nbMacro >= 1)
@ -438,7 +438,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
if (nbUserCommand >= 1)
::InsertMenu(hRunMenu, runPosBase - 1, MF_BYPOSITION, static_cast<UINT>(-1), 0);
for (size_t i = 0 ; i < nbUserCommand ; ++i)
for (size_t i = 0; i < nbUserCommand; ++i)
{
::InsertMenu(hRunMenu, static_cast<UINT>(runPosBase + i), MF_BYPOSITION, ID_USER_CMD + i, userCommands[i].toMenuItemString().c_str());
}
@ -465,7 +465,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
HMENU hLangMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_LANGUAGE);
// Add external languages to menu
for (int i = 0 ; i < nppParam.getNbExternalLang() ; ++i)
for (int i = 0; i < nppParam.getNbExternalLang(); ++i)
{
ExternalLangContainer & externalLangContainer = nppParam.getELCFromIndex(i);
@ -479,12 +479,12 @@ LRESULT Notepad_plus::init(HWND hwnd)
::GetMenuString(hLangMenu, x, buffer, bufferSize, MF_BYPOSITION);
}
::InsertMenu(hLangMenu, x-1, MF_BYPOSITION, IDM_LANG_EXTERNAL + i, externalLangContainer._name);
::InsertMenu(hLangMenu, x - 1, MF_BYPOSITION, IDM_LANG_EXTERNAL + i, externalLangContainer._name);
}
if (nppGUI._excludedLangList.size() > 0)
{
for (size_t i = 0, len = nppGUI._excludedLangList.size(); i < len ; ++i)
for (size_t i = 0, len = nppGUI._excludedLangList.size(); i < len; ++i)
{
int cmdID = nppParam.langTypeToCommandID(nppGUI._excludedLangList[i]._langType);
const int itemSize = 256;
@ -500,7 +500,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
// Add User Defined Languages Entry
int udlpos = ::GetMenuItemCount(hLangMenu) - 1;
for (int i = 0, len = nppParam.getNbUserLang(); i < len ; ++i)
for (int i = 0, len = nppParam.getNbUserLang(); i < len; ++i)
{
UserLangContainer & userLangContainer = nppParam.getULCFromIndex(i);
::InsertMenu(hLangMenu, udlpos + i, MF_BYPOSITION, IDM_LANG_USER + i + 1, userLangContainer.getName());
@ -513,7 +513,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
_lastRecentFileList.initMenu(hFileMenu, IDM_FILEMENU_LASTONE + 1, IDM_FILEMENU_EXISTCMDPOSITION, &_accelerator, nppParam.putRecentFileInSubMenu());
_lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding());
for (int i = 0 ; i < nbLRFile ; ++i)
for (int i = 0; i < nbLRFile; ++i)
{
generic_string * stdStr = nppParam.getLRFile(i);
if (!nppGUI._checkHistoryFiles || PathFileExists(stdStr->c_str()))
@ -553,7 +553,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
vector<MenuItemUnit> & tmp = nppParam.getContextMenuItems();
size_t len = tmp.size();
TCHAR menuName[64];
for (size_t i = 0 ; i < len ; ++i)
for (size_t i = 0; i < len; ++i)
{
if (tmp[i]._itemName.empty())
{
@ -597,7 +597,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
scnN.nmhdr.idFrom = 0;
_pluginsManager.notify(&scnN);
_toolBar.init(_pPublicInterface->getHinst(), hwnd, tbStatus, toolBarIcons, sizeof(toolBarIcons)/sizeof(ToolBarButtonUnit));
_toolBar.init(_pPublicInterface->getHinst(), hwnd, tbStatus, toolBarIcons, sizeof(toolBarIcons) / sizeof(ToolBarButtonUnit));
changeToolBarIcons();
@ -651,7 +651,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
_isUDDocked = true;
break;
}
case (UDD_SHOW | UDD_DOCKED) : // show & docked
case (UDD_SHOW | UDD_DOCKED): // show & docked
{
udd->doDialog(true, _nativeLangSpeaker.isRTL());
_nativeLangSpeaker.changeUserDefineLang(udd);
@ -687,14 +687,17 @@ LRESULT Notepad_plus::init(HWND hwnd)
//
// launch the plugin dlg memorized at the last session
//
if (!nppGUI._isCmdlineNosessionActivated)
{
DockingManagerData& dmd = nppGUI._dockingData;
_dockingManager.setDockedContSize(CONT_LEFT , nppGUI._dockingData._leftWidth);
_dockingManager.setDockedContSize(CONT_RIGHT , nppGUI._dockingData._rightWidth);
_dockingManager.setDockedContSize(CONT_TOP , nppGUI._dockingData._topHeight);
_dockingManager.setDockedContSize(CONT_LEFT, nppGUI._dockingData._leftWidth);
_dockingManager.setDockedContSize(CONT_RIGHT, nppGUI._dockingData._rightWidth);
_dockingManager.setDockedContSize(CONT_TOP, nppGUI._dockingData._topHeight);
_dockingManager.setDockedContSize(CONT_BOTTOM, nppGUI._dockingData._bottomHight);
for (size_t i = 0, len = dmd._pluginDockInfo.size(); i < len ; ++i)
for (size_t i = 0, len = dmd._pluginDockInfo.size(); i < len; ++i)
{
PluginDlgDockingInfo& pdi = dmd._pluginDockInfo[i];
if (pdi._isVisible)
@ -711,6 +714,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
ContainerTabInfo & cti = dmd._containerTabInfo[i];
_dockingManager.setActiveTab(cti._cont, cti._activeTab);
}
}
//Load initial docs into doctab
loadBufferIntoView(_mainEditView.getCurrentBufferID(), MAIN_VIEW);

View File

@ -99,6 +99,8 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
if (cmdLineParams->_isNoPlugin)
_notepad_plus_plus_core._pluginsManager.disable();
nppGUI._isCmdlineNosessionActivated = cmdLineParams->_isNoSession;
_hSelf = ::CreateWindowEx(
WS_EX_ACCEPTFILES | (_notepad_plus_plus_core._nativeLangSpeaker.isRTL()?WS_EX_LAYOUTRTL:0),
_className,
@ -168,8 +170,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
if (cmdLineParams->_alwaysOnTop)
::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_ALWAYSONTOP, 0);
nppGUI._isCmdlineNosessionActivated = cmdLineParams->_isNoSession;
if (nppGUI._rememberLastSession && !cmdLineParams->_isNoSession)
if (nppGUI._rememberLastSession && !nppGUI._isCmdlineNosessionActivated)
_notepad_plus_plus_core.loadLastSession();
if (nppParams.doFunctionListExport() || nppParams.doPrintAndExit())

View File

@ -5461,8 +5461,6 @@ void NppParameters::feedDockingManager(TiXmlNode *node)
if (element->Attribute(TEXT("bottomHeight"), &i))
_nppGUI._dockingData._bottomHight = i;
for (TiXmlNode *childNode = node->FirstChildElement(TEXT("FloatingWindow"));
childNode ;
childNode = childNode->NextSibling(TEXT("FloatingWindow")) )
@ -5528,6 +5526,116 @@ void NppParameters::feedDockingManager(TiXmlNode *node)
}
}
TiXmlElement NppParameters::duplicateDockingManager(TiXmlNode *node)
{
TiXmlElement *element = node->ToElement();
TiXmlElement DMNode(TEXT("GUIConfig"));
DMNode.SetAttribute(TEXT("name"), TEXT("DockingManager"));
int i;
if (element->Attribute(TEXT("leftWidth"), &i))
DMNode.SetAttribute(TEXT("leftWidth"), i);
if (element->Attribute(TEXT("rightWidth"), &i))
DMNode.SetAttribute(TEXT("rightWidth"), i);
if (element->Attribute(TEXT("topHeight"), &i))
DMNode.SetAttribute(TEXT("topHeight"), i);
if (element->Attribute(TEXT("bottomHeight"), &i))
DMNode.SetAttribute(TEXT("bottomHeight"), i);
for (TiXmlNode *childNode = node->FirstChildElement(TEXT("FloatingWindow"));
childNode;
childNode = childNode->NextSibling(TEXT("FloatingWindow")))
{
TiXmlElement *floatElement = childNode->ToElement();
int cont;
if (floatElement->Attribute(TEXT("cont"), &cont))
{
TiXmlElement FWNode(TEXT("FloatingWindow"));
FWNode.SetAttribute(TEXT("cont"), cont);
int x = 0;
int y = 0;
int w = 100;
int h = 100;
floatElement->Attribute(TEXT("x"), &x);
FWNode.SetAttribute(TEXT("x"), x);
floatElement->Attribute(TEXT("y"), &y);
FWNode.SetAttribute(TEXT("y"), y);
floatElement->Attribute(TEXT("width"), &w);
FWNode.SetAttribute(TEXT("width"), w);
floatElement->Attribute(TEXT("height"), &h);
FWNode.SetAttribute(TEXT("height"), h);
DMNode.InsertEndChild(FWNode);
}
}
for (TiXmlNode *childNode = node->FirstChildElement(TEXT("PluginDlg"));
childNode;
childNode = childNode->NextSibling(TEXT("PluginDlg")))
{
TiXmlElement *dlgElement = childNode->ToElement();
const TCHAR *name = dlgElement->Attribute(TEXT("pluginName"));
TiXmlElement PDNode(TEXT("PluginDlg"));
int id;
const TCHAR *idStr = dlgElement->Attribute(TEXT("id"), &id);
if (name && idStr)
{
int curr = 0; // on left
int prev = 0; // on left
dlgElement->Attribute(TEXT("curr"), &curr);
dlgElement->Attribute(TEXT("prev"), &prev);
bool isVisible = false;
const TCHAR *val = dlgElement->Attribute(TEXT("isVisible"));
if (val)
{
isVisible = (lstrcmp(val, TEXT("yes")) == 0);
}
PDNode.SetAttribute(TEXT("pluginName"), name);
PDNode.SetAttribute(TEXT("id"), idStr);
PDNode.SetAttribute(TEXT("curr"), curr);
PDNode.SetAttribute(TEXT("prev"), prev);
PDNode.SetAttribute(TEXT("isVisible"), isVisible ? TEXT("yes") : TEXT("no"));
DMNode.InsertEndChild(PDNode);
}
}
for (TiXmlNode *childNode = node->FirstChildElement(TEXT("ActiveTabs"));
childNode;
childNode = childNode->NextSibling(TEXT("ActiveTabs")))
{
TiXmlElement *dlgElement = childNode->ToElement();
TiXmlElement CTNode(TEXT("ActiveTabs"));
int cont;
if (dlgElement->Attribute(TEXT("cont"), &cont))
{
int activeTab = 0;
dlgElement->Attribute(TEXT("activeTab"), &activeTab);
CTNode.SetAttribute(TEXT("cont"), cont);
CTNode.SetAttribute(TEXT("activeTab"), activeTab);
DMNode.InsertEndChild(CTNode);
}
}
return DMNode;
}
bool NppParameters::writeScintillaParams()
{
if (!_pXmlUserDoc) return false;
@ -5594,12 +5702,19 @@ bool NppParameters::writeScintillaParams()
void NppParameters::createXmlTreeFromGUIParams()
{
TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus"));
if (not nppRoot)
if (!nppRoot)
{
nppRoot = _pXmlUserDoc->InsertEndChild(TiXmlElement(TEXT("NotepadPlus")));
}
TiXmlNode *oldGUIRoot = nppRoot->FirstChildElement(TEXT("GUIConfigs"));
TiXmlElement dockMngNode(TEXT(""));
if (_nppGUI._isCmdlineNosessionActivated)
{
// Copy DockingParamNode
dockMngNode = duplicateDockingManager(oldGUIRoot);
}
// Remove the old root nod if it exist
if (oldGUIRoot)
{
@ -6054,7 +6169,14 @@ void NppParameters::createXmlTreeFromGUIParams()
// <GUIConfig name="DockingManager" leftWidth="328" rightWidth="359" topHeight="200" bottomHeight="436">
// ...
if (_nppGUI._isCmdlineNosessionActivated)
{
newGUIRoot->InsertEndChild(dockMngNode);
}
else
{
insertDockingParamNode(newGUIRoot);
}
}
bool NppParameters::writeFindHistory()

View File

@ -1852,6 +1852,7 @@ private:
void feedFileListParameters(TiXmlNode *node);
void feedScintillaParam(TiXmlNode *node);
void feedDockingManager(TiXmlNode *node);
TiXmlElement duplicateDockingManager(TiXmlNode *node);
void feedFindHistoryParameters(TiXmlNode *node);
void feedProjectPanelsParameters(TiXmlNode *node);
void feedFileBrowserParameters(TiXmlNode *node);