[NEW_FEATURE] Add "adding files from folder" for Project Manager.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@833 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2011-10-31 01:25:40 +00:00
parent 46888bb4f3
commit 8daa455c0d
8 changed files with 216 additions and 11 deletions

View File

@ -99,6 +99,44 @@ void folderBrowser(HWND parent, int outputCtrlID, const TCHAR *defaultStr)
}
}
generic_string getFolderName(HWND parent)
{
generic_string folderName(TEXT(""));
LPMALLOC pShellMalloc = 0;
if (::SHGetMalloc(&pShellMalloc) == NO_ERROR)
{
BROWSEINFO info;
memset(&info, 0, sizeof(info));
info.hwndOwner = parent;
info.pidlRoot = NULL;
TCHAR szDisplayName[MAX_PATH];
info.pszDisplayName = szDisplayName;
info.lpszTitle = TEXT("Select a folder");
info.ulFlags = 0;
info.lpfn = BrowseCallbackProc;
// Execute the browsing dialog.
LPITEMIDLIST pidl = ::SHBrowseForFolder(&info);
// pidl will be null if they cancel the browse dialog.
// pidl will be not null when they select a folder.
if (pidl)
{
// Try to convert the pidl to a display generic_string.
// Return is true if success.
TCHAR szDir[MAX_PATH];
if (::SHGetPathFromIDList(pidl, szDir))
// Set edit control to the directory path.
folderName = szDir;
pShellMalloc->Free(pidl);
}
pShellMalloc->Release();
}
return folderName;
}
void ClientRectToScreenRect(HWND hWnd, RECT* rect)
{
POINT pt;

View File

@ -74,6 +74,7 @@ const bool dirDown = false;
typedef std::basic_string<TCHAR> generic_string;
void folderBrowser(HWND parent, int outputCtrlID, const TCHAR *defaultStr = NULL);
generic_string getFolderName(HWND parent);
void printInt(int int2print);
void printStr(const TCHAR *str2print);

View File

@ -1074,7 +1074,7 @@ void Notepad_plus::getMatchedFileNames(const TCHAR *dir, const vector<generic_st
{
if (!isInHiddenDir && (foundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
{
// branles rien
// do nothing
}
else if (isRecursive)
{
@ -1103,7 +1103,7 @@ void Notepad_plus::getMatchedFileNames(const TCHAR *dir, const vector<generic_st
{
if (!isInHiddenDir && (foundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
{
// branles rien
// do nothing
}
else if (isRecursive)
{
@ -4704,6 +4704,7 @@ void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int
tTbData data;
memset(&data, 0, sizeof(data));
(*pProjPanel)->create(&data);
data.pszName = TEXT("ST");
::SendMessage(_pPublicInterface->getHSelf(), NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)(*pProjPanel)->getHSelf());
// define the default docking behaviour

View File

@ -172,23 +172,27 @@ void ProjectPanel::initMenus()
generic_string edit_rename = pNativeSpeaker->getProjectPanelLangMenuStr("ProjectMenu", IDM_PROJECT_RENAME, PM_EDITRENAME);
generic_string edit_addfolder = pNativeSpeaker->getProjectPanelLangMenuStr("ProjectMenu", IDM_PROJECT_NEWFOLDER, PM_EDITNEWFOLDER);
generic_string edit_addfiles = pNativeSpeaker->getProjectPanelLangMenuStr("ProjectMenu", IDM_PROJECT_ADDFILES, PM_EDITADDFILES);
generic_string edit_addfilesRecursive = pNativeSpeaker->getProjectPanelLangMenuStr("ProjectMenu", IDM_PROJECT_ADDFILESRECUSIVELY, PM_EDITADDFILESRECUSIVELY);
generic_string edit_remove = pNativeSpeaker->getProjectPanelLangMenuStr("ProjectMenu", IDM_PROJECT_DELETEFOLDER, PM_EDITREMOVE);
_hProjectMenu = ::CreatePopupMenu();
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, edit_rename.c_str());
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, edit_addfolder.c_str());
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILES, edit_addfiles.c_str());
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILESRECUSIVELY, edit_addfilesRecursive.c_str());
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFOLDER, edit_remove.c_str());
edit_rename = pNativeSpeaker->getProjectPanelLangMenuStr("FolderMenu", IDM_PROJECT_RENAME, PM_EDITRENAME);
edit_addfolder = pNativeSpeaker->getProjectPanelLangMenuStr("FolderMenu", IDM_PROJECT_NEWFOLDER, PM_EDITNEWFOLDER);
edit_addfiles = pNativeSpeaker->getProjectPanelLangMenuStr("FolderMenu", IDM_PROJECT_ADDFILES, PM_EDITADDFILES);
edit_addfilesRecursive = pNativeSpeaker->getProjectPanelLangMenuStr("FolderMenu", IDM_PROJECT_ADDFILESRECUSIVELY, PM_EDITADDFILESRECUSIVELY);
edit_remove = pNativeSpeaker->getProjectPanelLangMenuStr("FolderMenu", IDM_PROJECT_DELETEFOLDER, PM_EDITREMOVE);
_hFolderMenu = ::CreatePopupMenu();
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, edit_rename.c_str());
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, edit_addfolder.c_str());
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILES, edit_addfiles.c_str());
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILESRECUSIVELY, edit_addfilesRecursive.c_str());
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFOLDER, edit_remove.c_str());
edit_rename = pNativeSpeaker->getProjectPanelLangMenuStr("FileMenu", IDM_PROJECT_RENAME, PM_EDITRENAME);
@ -616,6 +620,13 @@ void ProjectPanel::notified(LPNMHDR notification)
}
}
break;
case TVN_BEGINDRAG:
{
//printStr(TEXT("hello"));
}
break;
}
}
}
@ -700,6 +711,18 @@ POINT ProjectPanel::getMenuDisplyPoint(int iButton)
return p;
}
HTREEITEM ProjectPanel::addFolder(HTREEITEM hTreeItem, const TCHAR *folderName)
{
HTREEITEM addedItem = _treeView.addItem(folderName, hTreeItem, INDEX_CLOSED_NODE);
TreeView_Expand(_treeView.getHSelf(), hTreeItem, TVE_EXPAND);
TreeView_EditLabel(_treeView.getHSelf(), addedItem);
if (getNodeType(hTreeItem) == nodeType_folder)
_treeView.setItemImage(hTreeItem, INDEX_OPEN_NODE, INDEX_OPEN_NODE);
return addedItem;
}
void ProjectPanel::popupMenuCmd(int cmdID)
{
// get selected item handle
@ -741,7 +764,10 @@ void ProjectPanel::popupMenuCmd(int cmdID)
case IDM_PROJECT_NEWPROJECT :
{
HTREEITEM root = _treeView.getRoot();
HTREEITEM addedItem = _treeView.addItem(TEXT("Project Name"), root, INDEX_PROJECT);
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
generic_string newProjectLabel = pNativeSpeaker->getProjectPanelLangStr("NewProjectName", PM_NEWPROJECTNAME);
HTREEITEM addedItem = _treeView.addItem(newProjectLabel.c_str(), root, INDEX_PROJECT);
setWorkSpaceDirty(true);
_treeView.expand(hTreeItem);
TreeView_EditLabel(_treeView.getHSelf(), addedItem);
@ -779,12 +805,10 @@ void ProjectPanel::popupMenuCmd(int cmdID)
case IDM_PROJECT_NEWFOLDER :
{
HTREEITEM addedItem = _treeView.addItem(TEXT("Folder Name"), hTreeItem, INDEX_CLOSED_NODE);
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
generic_string newFolderLabel = pNativeSpeaker->getProjectPanelLangStr("NewFolderName", PM_NEWFOLDERNAME);
addFolder(hTreeItem, newFolderLabel.c_str());
setWorkSpaceDirty(true);
TreeView_Expand(_treeView.getHSelf(), hTreeItem, TVE_EXPAND);
TreeView_EditLabel(_treeView.getHSelf(), addedItem);
if (getNodeType(hTreeItem) == nodeType_folder)
_treeView.setItemImage(hTreeItem, INDEX_OPEN_NODE, INDEX_OPEN_NODE);
}
break;
@ -796,6 +820,14 @@ void ProjectPanel::popupMenuCmd(int cmdID)
}
break;
case IDM_PROJECT_ADDFILESRECUSIVELY :
{
addFilesFromDirectory(hTreeItem);
if (getNodeType(hTreeItem) == nodeType_folder)
_treeView.setItemImage(hTreeItem, INDEX_OPEN_NODE, INDEX_OPEN_NODE);
}
break;
case IDM_PROJECT_OPENWS:
{
if (_isDirty)
@ -977,6 +1009,98 @@ void ProjectPanel::addFiles(HTREEITEM hTreeItem)
}
}
void ProjectPanel::recursiveAddFilesFrom(const TCHAR *folderPath, HTREEITEM hTreeItem)
{
bool isRecursive = true;
bool isInHiddenDir = false;
generic_string dirFilter(folderPath);
if (folderPath[lstrlen(folderPath)-1] != '\\')
dirFilter += TEXT("\\");
dirFilter += TEXT("*.*");
WIN32_FIND_DATA foundData;
HANDLE hFile = ::FindFirstFile(dirFilter.c_str(), &foundData);
if (hFile != INVALID_HANDLE_VALUE)
{
if (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!isInHiddenDir && (foundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
{
// do nothing
}
else if (isRecursive)
{
if ((lstrcmp(foundData.cFileName, TEXT("."))) && (lstrcmp(foundData.cFileName, TEXT(".."))))
{
generic_string pathDir(folderPath);
if (folderPath[lstrlen(folderPath)-1] != '\\')
pathDir += TEXT("\\");
pathDir += foundData.cFileName;
pathDir += TEXT("\\");
HTREEITEM addedItem = addFolder(hTreeItem, foundData.cFileName);
recursiveAddFilesFrom(pathDir.c_str(), addedItem);
}
}
}
else
{
generic_string pathFile(folderPath);
if (folderPath[lstrlen(folderPath)-1] != '\\')
pathFile += TEXT("\\");
pathFile += foundData.cFileName;
TCHAR *strValueLabel = ::PathFindFileName(pathFile.c_str());
_treeView.addItem(strValueLabel, hTreeItem, INDEX_LEAF, pathFile.c_str());
}
}
while (::FindNextFile(hFile, &foundData))
{
if (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!isInHiddenDir && (foundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
{
// do nothing
}
else if (isRecursive)
{
if ((lstrcmp(foundData.cFileName, TEXT("."))) && (lstrcmp(foundData.cFileName, TEXT(".."))))
{
generic_string pathDir(folderPath);
if (folderPath[lstrlen(folderPath)-1] != '\\')
pathDir += TEXT("\\");
pathDir += foundData.cFileName;
pathDir += TEXT("\\");
HTREEITEM addedItem = addFolder(hTreeItem, foundData.cFileName);
recursiveAddFilesFrom(pathDir.c_str(), addedItem);
}
}
}
else
{
generic_string pathFile(folderPath);
if (folderPath[lstrlen(folderPath)-1] != '\\')
pathFile += TEXT("\\");
pathFile += foundData.cFileName;
TCHAR *strValueLabel = ::PathFindFileName(pathFile.c_str());
_treeView.addItem(strValueLabel, hTreeItem, INDEX_LEAF, pathFile.c_str());
}
}
::FindClose(hFile);
}
void ProjectPanel::addFilesFromDirectory(HTREEITEM hTreeItem)
{
generic_string folderName = getFolderName(_hSelf);
if (folderName != TEXT(""))
{
recursiveAddFilesFrom(folderName.c_str(), hTreeItem);
_treeView.expand(hTreeItem);
setWorkSpaceDirty(true);
}
}
BOOL CALLBACK FileRelocalizerDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
{
switch (Message)

View File

@ -30,6 +30,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define PM_PROJECTPANELTITLE TEXT("Project")
#define PM_WORKSPACEROOTNAME TEXT("Workspace")
#define PM_NEWFOLDERNAME TEXT("Folder Name")
#define PM_NEWPROJECTNAME TEXT("Project Name")
#define PM_NEWWORKSPACE TEXT("New Workspace")
#define PM_OPENWORKSPACE TEXT("Open Workspace")
#define PM_RELOADWORKSPACE TEXT("Reload Workspace")
@ -41,6 +44,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define PM_EDITRENAME TEXT("Rename")
#define PM_EDITNEWFOLDER TEXT("Add Folder")
#define PM_EDITADDFILES TEXT("Add Files...")
#define PM_EDITADDFILESRECUSIVELY TEXT("Add Files from Directory...")
#define PM_EDITREMOVE TEXT("Remove")
#define PM_EDITMODIFYFILE TEXT("Modify File Path")
@ -98,6 +102,10 @@ protected:
void destroyMenus();
BOOL setImageList(int root_clean_id, int root_dirty_id, int project_id, int open_node_id, int closed_node_id, int leaf_id, int ivalid_leaf_id);
void addFiles(HTREEITEM hTreeItem);
void addFilesFromDirectory(HTREEITEM hTreeItem);
void recursiveAddFilesFrom(const TCHAR *folderPath, HTREEITEM hTreeItem);
HTREEITEM addFolder(HTREEITEM hTreeItem, const TCHAR *folderName);
bool writeWorkSpace(TCHAR *projectFileName = NULL);
generic_string getRelativePath(const generic_string & fn, const TCHAR *workSpaceFileName);
void buildProjectXml(TiXmlNode *root, HTREEITEM hItem, const TCHAR* fn2write);

View File

@ -26,7 +26,7 @@ EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE
CAPTION "Project"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
CONTROL "",ID_PROJECTTREEVIEW,"SysTreeView32", TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_EDITLABELS | TVS_INFOTIP | TVS_HASLINES | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,7,172,93
//CONTROL "",ID_PROJECTTREEVIEW,"SysTreeView32", TVS_HASBUTTONS | TVS_EDITLABELS | TVS_INFOTIP | TVS_HASLINES | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,7,172,93
END
IDD_FILERELOCALIZER_DIALOG DIALOGEX 0, 0, 350, 48

View File

@ -26,7 +26,8 @@
#define IDM_PROJECT_ADDFILES (IDD_PROJECTPANEL_MENU + 3)
#define IDM_PROJECT_DELETEFOLDER (IDD_PROJECTPANEL_MENU + 4)
#define IDM_PROJECT_DELETEFILE (IDD_PROJECTPANEL_MENU + 5)
#define IDM_PROJECT_MODIFYFILEPATH (IDD_PROJECTPANEL_MENU + 6)
#define IDM_PROJECT_MODIFYFILEPATH (IDD_PROJECTPANEL_MENU + 6)
#define IDM_PROJECT_ADDFILESRECUSIVELY (IDD_PROJECTPANEL_MENU + 7)
#define IDD_PROJECTPANEL_MENUWS (IDD_PROJECTPANEL + 20)
#define IDM_PROJECT_NEWPROJECT (IDD_PROJECTPANEL_MENUWS + 1)

View File

@ -24,7 +24,22 @@ void TreeView::init(HINSTANCE hInst, HWND parent, int treeViewID)
{
Window::init(hInst, parent);
_hSelf = ::GetDlgItem(parent, treeViewID);
_hSelf = CreateWindowEx(0,
WC_TREEVIEW,
TEXT("Tree View"),
TVS_HASBUTTONS | WS_CHILD | WS_BORDER | WS_HSCROLL |
TVS_HASLINES | TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_EDITLABELS | TVS_INFOTIP | WS_TABSTOP,
0, 0, 0, 0,
_hParent,
NULL,
_hInst,
(LPVOID)0);
TreeView_SetItemHeight(_hSelf, CY_ITEMHEIGHT);
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this);
_defaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)staticProc));
}
@ -37,7 +52,24 @@ void TreeView::destroy()
}
LRESULT TreeView::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
{/*
switch(Message)
{
case WM_MOUSEMOVE:
//::MessageBoxA(NULL, "WM_MOUSEMOVE", "", MB_OK);
break;
case WM_LBUTTONUP:
//::MessageBoxA(NULL, "WM_LBUTTONUP", "", MB_OK);
//SendMessage to parent
break;
case WM_KEYDOWN:
if (wParam == VK_F2)
::MessageBoxA(NULL, "VK_F2", "", MB_OK);
break;
default:
return ::CallWindowProc(_defaultProc, hwnd, Message, wParam, lParam);
}
*/
return ::CallWindowProc(_defaultProc, hwnd, Message, wParam, lParam);
}