[ENHANCE] Enhance Project Manager.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@816 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2011-09-25 01:33:34 +00:00
parent 2d5cf5ddeb
commit cfa7850d01
9 changed files with 216 additions and 40 deletions

View File

@ -696,6 +696,18 @@ bool Notepad_plus::saveGUIParams()
return (NppParameters::getInstance())->writeGUIParams();
}
bool Notepad_plus::saveProjectPanelsParams()
{
if (_pProjectPanel_1)
(NppParameters::getInstance())->setWorkSpaceFilePath(0, _pProjectPanel_1->getWorkSpaceFilePath());
if (_pProjectPanel_2)
(NppParameters::getInstance())->setWorkSpaceFilePath(1, _pProjectPanel_2->getWorkSpaceFilePath());
if (_pProjectPanel_3)
(NppParameters::getInstance())->setWorkSpaceFilePath(2, _pProjectPanel_3->getWorkSpaceFilePath());
return (NppParameters::getInstance())->writeProjectPanelsSettings();
}
void Notepad_plus::saveDockingParams()
{
NppGUI & nppGUI = (NppGUI &)(NppParameters::getInstance())->getNppGUI();
@ -4671,13 +4683,15 @@ void Notepad_plus::launchAnsiCharPanel()
_pAnsiCharPanel->display();
}
void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel)
void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int panelID)
{
if (!*pProjPanel)
if (!(*pProjPanel))
{
*pProjPanel = new ProjectPanel;
NppParameters *pNppParam = NppParameters::getInstance();
(*pProjPanel) = new ProjectPanel;
(*pProjPanel)->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf());
(*pProjPanel)->setWorkSpaceFilePath(pNppParam->getworkSpaceFilePath(panelID));
tTbData data = {0};
(*pProjPanel)->create(&data);

View File

@ -233,6 +233,7 @@ public:
bool saveScintillaParams();
bool saveGUIParams();
bool saveProjectPanelsParams();
void saveDockingParams();
void saveUserDefineLangs() {
if (ScintillaEditView::getUserDefineDlg()->isDirty())
@ -589,7 +590,7 @@ private:
void launchAnsiCharPanel();
void launchClipboardHistoryPanel();
void launchFileSwitcherPanel();
void launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel);
void launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int panelID);
};

View File

@ -1419,6 +1419,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_lastRecentFileList.saveLRFL();
saveScintillaParams();
saveGUIParams();
saveProjectPanelsParams();
saveUserDefineLangs();
saveShortcuts();
if (nppgui._rememberLastSession && _rememberThisSession)

View File

@ -300,17 +300,17 @@ void Notepad_plus::command(int id)
case IDM_VIEW_PROJECT_PANEL_1:
{
launchProjectPanel(id, &_pProjectPanel_1);
launchProjectPanel(id, &_pProjectPanel_1, 0);
}
break;
case IDM_VIEW_PROJECT_PANEL_2:
{
launchProjectPanel(id, &_pProjectPanel_2);
launchProjectPanel(id, &_pProjectPanel_2, 1);
}
break;
case IDM_VIEW_PROJECT_PANEL_3:
{
launchProjectPanel(id, &_pProjectPanel_3);
launchProjectPanel(id, &_pProjectPanel_3, 2);
}
break;

View File

@ -295,7 +295,8 @@ void Notepad_plus::doClose(BufferID id, int whichOne) {
// So we turn Wow64 off
bool isWow64Off = false;
NppParameters *pNppParam = NppParameters::getInstance();
if (!PathFileExists(buf->getFullPathName()))
const TCHAR *fn = buf->getFullPathName();
if (!PathFileExists(fn))
{
pNppParam->safeWow64EnableWow64FsRedirection(FALSE);
isWow64Off = true;

View File

@ -1214,24 +1214,26 @@ bool NppParameters::getUserParametersFromXmlTree()
TiXmlNode *root = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus"));
if (!root) return false;
// GUI
// Get GUI parameters
feedGUIParameters(root);
//History
// Get History parameters
feedFileListParameters(root);
// Raser tout
// Erase the History root
TiXmlNode *node = root->FirstChildElement(TEXT("History"));
root->RemoveChild(node);
// Repartir de zero
// Add a new empty History root
TiXmlElement HistoryNode(TEXT("History"));
root->InsertEndChild(HistoryNode);
//Find history
//Get Find history parameters
feedFindHistoryParameters(root);
//Get Project Panel parameters
feedProjectPanelsParameters(root);
return true;
}
@ -1691,6 +1693,7 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p
return true;
}
void NppParameters::feedFileListParameters(TiXmlNode *node)
{
TiXmlNode *historyRoot = node->FirstChildElement(TEXT("History"));
@ -1726,6 +1729,28 @@ void NppParameters::feedFileListParameters(TiXmlNode *node)
}
}
void NppParameters::feedProjectPanelsParameters(TiXmlNode *node)
{
TiXmlNode *projPanelRoot = node->FirstChildElement(TEXT("ProjectPanels"));
if (!projPanelRoot) return;
for (TiXmlNode *childNode = projPanelRoot->FirstChildElement(TEXT("ProjectPanel"));
childNode;
childNode = childNode->NextSibling(TEXT("ProjectPanel")) )
{
int index = 0;
const TCHAR *idStr = (childNode->ToElement())->Attribute(TEXT("id"), &index);
if (idStr && (index >= 0 && index <= 2))
{
const TCHAR *filePath = (childNode->ToElement())->Attribute(TEXT("workSpaceFile"));
if (filePath)
{
_workSpaceFilePathes[index] = filePath;
}
}
}
}
void NppParameters::feedFindHistoryParameters(TiXmlNode *node)
{
TiXmlNode *findHistoryRoot = node->FirstChildElement(TEXT("FindHistory"));
@ -2741,6 +2766,38 @@ bool NppParameters::writeRecentFileHistorySettings(int nbMaxFile) const
return true;
}
bool NppParameters::writeProjectPanelsSettings() const
{
if (!_pXmlUserDoc) return false;
TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus"));
if (!nppRoot) return false;
TiXmlNode *projPanelRootNode = nppRoot->FirstChildElement(TEXT("ProjectPanels"));
if (projPanelRootNode)
{
// Erase the Project Panel root
nppRoot->RemoveChild(projPanelRootNode);
}
// Create the Project Panel root
projPanelRootNode = new TiXmlElement(TEXT("ProjectPanels"));
// Add 3 Project Panel parameters
for (int i = 0 ; i < 3 ; i++)
{
TiXmlElement projPanelNode(TEXT("ProjectPanel"));
(projPanelNode.ToElement())->SetAttribute(TEXT("id"), i);
(projPanelNode.ToElement())->SetAttribute(TEXT("workSpaceFile"), _workSpaceFilePathes[i]);
(projPanelRootNode->ToElement())->InsertEndChild(projPanelNode);
}
// (Re)Insert the Project Panel root
(nppRoot->ToElement())->InsertEndChild(*projPanelRootNode);
return true;
}
bool NppParameters::writeHistory(const TCHAR *fullpath)
{
TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus"));

View File

@ -1190,6 +1190,8 @@ public:
bool writeRecentFileHistorySettings(int nbMaxFile = -1) const;
bool writeHistory(const TCHAR *fullpath);
bool writeProjectPanelsSettings() const;
TiXmlNode * getChildElementByAttribut(TiXmlNode *pere, const TCHAR *childName,\
const TCHAR *attributName, const TCHAR *attributVal) const;
@ -1353,6 +1355,16 @@ public:
generic_string getContextMenuPath() const {return _contextMenuPath;};
const TCHAR * getAppDataNppDir() const {return _appdataNppDir.c_str();};
const TCHAR * getWorkingDir() const {return _currentDirectory.c_str();};
const TCHAR * getworkSpaceFilePath(int i) const {
if (i < 0 || i > 2) return NULL;
return _workSpaceFilePathes[i].c_str();
};
void setWorkSpaceFilePath(int i, const TCHAR *wsFile) {
if (i < 0 || i > 2 || !wsFile) return;
_workSpaceFilePathes[i] = wsFile;
};
void setWorkingDir(const TCHAR * newPath);
bool loadSession(Session & session, const TCHAR *sessionFileName);
@ -1495,6 +1507,7 @@ private:
generic_string _stylerPath;
generic_string _appdataNppDir; // sentinel of the absence of "doLocalConf.xml" : (_appdataNppDir == TEXT(""))?"doLocalConf.xml present":"doLocalConf.xml absent"
generic_string _currentDirectory;
generic_string _workSpaceFilePathes[3];
Accelerator *_pAccelerator;
ScintillaAccelerator * _pScintAccelerator;
@ -1545,6 +1558,7 @@ private:
void feedScintillaParam(TiXmlNode *node);
void feedDockingManager(TiXmlNode *node);
void feedFindHistoryParameters(TiXmlNode *node);
void feedProjectPanelsParameters(TiXmlNode *node);
bool feedStylerArray(TiXmlNode *node);
void getAllWordStyles(TCHAR *lexerName, TiXmlNode *lexerNode);

View File

@ -75,7 +75,8 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
setImageList(IDI_PROJECT_WORKSPACE, IDI_PROJECT_WORKSPACEDIRTY, IDI_PROJECT_PROJECT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE, IDI_PROJECT_FILEINVALID);
_treeView.display();
openWorkSpace(TEXT("D:\\source\\notepad++\\trunk\\PowerEditor\\src\\WinControls\\ProjectPanel\\demo.xml"));
if (!openWorkSpace(_workSpaceFilePath.c_str()))
newWorkSpace();
return TRUE;
}
@ -267,6 +268,21 @@ void ProjectPanel::newWorkSpace()
_workSpaceFilePath = TEXT("");
}
bool ProjectPanel::saveWorkSpace()
{
if (_workSpaceFilePath == TEXT(""))
{
return saveWorkSpaceAs(false);
}
else
{
writeWorkSpace();
setWorkSpaceDirty(false);
_isDirty = false;
return true;
}
}
bool ProjectPanel::writeWorkSpace(TCHAR *projectFileName)
{
//write <NotepadPlus>: use the default file name if new file name is not given
@ -399,6 +415,8 @@ void ProjectPanel::notified(LPNMHDR notification)
LPNMTVDISPINFO tvnotif = (LPNMTVDISPINFO)notification;
if (!tvnotif->item.pszText)
return;
if (getNodeType(tvnotif->item.hItem) == nodeType_root)
return;
// Processing for only File case
if (tvnotif->item.lParam)
@ -588,9 +606,10 @@ void ProjectPanel::popupMenuCmd(int cmdID)
hMenu = _hProjectMenu;
else if (nodeType == nodeType_folder)
hMenu = _hFolderMenu;
else //nodeType_file
else if (nodeType == nodeType_file)
hMenu = _hFileMenu;
TrackPopupMenu(hMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL);
if (hMenu)
TrackPopupMenu(hMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL);
}
break;
@ -602,13 +621,34 @@ void ProjectPanel::popupMenuCmd(int cmdID)
HTREEITEM root = _treeView.getRoot();
HTREEITEM addedItem = _treeView.addItem(TEXT("Project Name"), root, INDEX_PROJECT);
setWorkSpaceDirty(true);
_treeView.expand(hTreeItem);
TreeView_EditLabel(_treeView.getHSelf(), addedItem);
}
break;
case IDM_PROJECT_NEWWS :
{
if (_isDirty)
{
int res = ::MessageBox(_hSelf, TEXT("The current work space was modified. Do you want to save the current project?"), TEXT(""), MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL);
if (res == IDYES)
{
if (!saveWorkSpace())
return;
}
else if (res == IDNO)
{
// Don't save so do nothing here
}
else if (res == IDCANCEL)
{
// User cancels action "New WorkSpace" so we interrupt here
return;
}
}
_treeView.removeAllItems();
newWorkSpace();
}
break;
case IDM_PROJECT_RENAME :
@ -635,6 +675,25 @@ void ProjectPanel::popupMenuCmd(int cmdID)
case IDM_PROJECT_OPENWS:
{
if (_isDirty)
{
int res = ::MessageBox(_hSelf, TEXT("The current work space was modified. Do you want to save the current project?"), TEXT(""), MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL);
if (res == IDYES)
{
if (!saveWorkSpace())
return;
}
else if (res == IDNO)
{
// Don't save so do nothing here
}
else if (res == IDCANCEL)
{
// User cancels action "New WorkSpace" so we interrupt here
return;
}
}
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
if (TCHAR *fn = fDlg.doOpenSingleFileDlg())
@ -648,35 +707,39 @@ void ProjectPanel::popupMenuCmd(int cmdID)
case IDM_PROJECT_RELOADWS:
{
if (_isDirty)
{
int res = ::MessageBox(_hSelf, TEXT("The current work space was modified. Reload will discard all modification.\rDo you want to continue?"), TEXT(""), MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL);
if (res == IDYES)
{
// Do nothing
}
else if (res == IDNO)
{
return;
}
}
if (::PathFileExists(_workSpaceFilePath.c_str()))
{
_treeView.removeAllItems();
openWorkSpace(_workSpaceFilePath.c_str());
}
else
{
::MessageBox(_hSelf, TEXT("Can not find file to reload"), TEXT(""), MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
}
}
break;
case IDM_PROJECT_SAVEWS:
writeWorkSpace();
setWorkSpaceDirty(false);
_isDirty = false;
saveWorkSpace();
break;
case IDM_PROJECT_SAVEACOPYASWS:
case IDM_PROJECT_SAVEASWS:
{
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
if (TCHAR *fn = fDlg.doSaveDlg())
{
writeWorkSpace(fn);
if (cmdID == IDM_PROJECT_SAVEASWS)
{
_workSpaceFilePath = fn;
setWorkSpaceDirty(false);
}
}
saveWorkSpaceAs(cmdID == IDM_PROJECT_SAVEACOPYASWS);
}
break;
@ -720,6 +783,24 @@ void ProjectPanel::popupMenuCmd(int cmdID)
}
}
bool ProjectPanel::saveWorkSpaceAs(bool saveCopyAs)
{
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
if (TCHAR *fn = fDlg.doSaveDlg())
{
writeWorkSpace(fn);
if (!saveCopyAs)
{
_workSpaceFilePath = fn;
setWorkSpaceDirty(false);
}
return true;
}
return false;
}
void ProjectPanel::addFiles(HTREEITEM hTreeItem)
{
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
@ -733,7 +814,7 @@ void ProjectPanel::addFiles(HTREEITEM hTreeItem)
TCHAR *strValueLabel = ::PathFindFileName(pfns->at(i).c_str());
_treeView.addItem(strValueLabel, hTreeItem, INDEX_LEAF, pfns->at(i).c_str());
}
TreeView_Expand(_treeView.getHSelf(), hTreeItem, TVE_EXPAND);
_treeView.expand(hTreeItem);
setWorkSpaceDirty(true);
}
}

View File

@ -40,9 +40,9 @@ public:
_hToolbarMenu(NULL), _hWorkSpaceMenu(NULL), _hProjectMenu(NULL), _hFolderMenu(NULL), _hFileMenu(NULL){};
void init(HINSTANCE hInst, HWND hPere) {
DockingDlgInterface::init(hInst, hPere);
}
void init(HINSTANCE hInst, HWND hPere) {
DockingDlgInterface::init(hInst, hPere);
}
virtual void display(bool toShow = true) const {
DockingDlgInterface::display(toShow);
@ -52,10 +52,16 @@ public:
_hParent = parent2set;
};
void newWorkSpace();
bool openWorkSpace(const TCHAR *projectFileName);
void newWorkSpace();
bool saveWorkSpace();
bool saveWorkSpaceAs(bool saveCopyAs);
void setWorkSpaceFilePath(const TCHAR *projectFileName){
_workSpaceFilePath = projectFileName;
};
const TCHAR * getWorkSpaceFilePath() const {
return _workSpaceFilePath.c_str();
};
protected:
TreeView _treeView;
HIMAGELIST _hImaLst;
@ -78,5 +84,6 @@ protected:
bool buildTreeFrom(TiXmlNode *projectRoot, HTREEITEM hParentItem);
void notified(LPNMHDR notification);
void showContextMenu(int x, int y);
};
#endif // PROJECTPANEL_H