diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index c19d17ed..202c3a18 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -206,6 +206,8 @@ IDI_PROJECT_FILEINVALID BITMAP "icons/project_file_invalid.bmp" IDI_FB_ROOTOPEN BITMAP "icons/fb_root_open.bmp" IDI_FB_ROOTCLOSE BITMAP "icons/fb_root_close.bmp" +IDI_FB_SELECTCURRENTFILE BITMAP "icons/fb_select_current_file.bmp" + IDI_FUNCLIST_ROOT BITMAP "icons/project_file.bmp" IDI_FUNCLIST_NODE BITMAP "icons/funcList_node.bmp" IDI_FUNCLIST_LEAF BITMAP "icons/funcList_leaf.bmp" @@ -213,7 +215,6 @@ IDI_FUNCLIST_LEAF BITMAP "icons/funcList_leaf.bmp" IDI_FUNCLIST_SORTBUTTON BITMAP "icons/funclstSort.bmp" IDI_FUNCLIST_RELOADBUTTON BITMAP "icons/funclstReload.bmp" - IDI_VIEW_DOC_MAP_ON_ICON ICON "icons/docMap_on.ico" IDI_VIEW_DOC_MAP_OFF_ICON ICON "icons/docMap_off.ico" IDI_VIEW_FUNCLIST_ON_ICON ICON "icons/funcList_on.ico" diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index 01cb477f..5ef8c3ef 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -53,6 +53,7 @@ #define FB_ADDFILE (WM_USER + 1024) #define FB_RMFILE (WM_USER + 1025) #define FB_RNFILE (WM_USER + 1026) +#define FB_CMD_AIMFILE 1 FileBrowser::~FileBrowser() { @@ -79,12 +80,52 @@ vector split(const generic_string & string2split, TCHAR sep) return splitedStrings; }; +bool isRelatedRootFolder(const generic_string & relatedRoot, const generic_string & subFolder) +{ + if (relatedRoot.empty()) + return false; + + if (subFolder.empty()) + return false; + + size_t pos = subFolder.find(relatedRoot); + if (pos != 0) // pos == 0 is the necessary condition, but not enough + return false; + + vector relatedRootArray = split(relatedRoot, '\\'); + vector subFolderArray = split(subFolder, '\\'); + + size_t index2Compare = relatedRootArray.size() - 1; + + return relatedRootArray[index2Compare] == subFolderArray[index2Compare]; +} + INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG : { + NppParameters& nppParam = NppParameters::getInstance(); + int style = WS_CHILD | WS_VISIBLE | CCS_ADJUSTABLE | TBSTYLE_AUTOSIZE | TBSTYLE_FLAT | TBSTYLE_LIST | TBSTYLE_TRANSPARENT | BTNS_AUTOSIZE | BTNS_SEP | TBSTYLE_TOOLTIPS; + _hToolbarMenu = CreateWindowEx(WS_EX_LAYOUTRTL, TOOLBARCLASSNAME, NULL, style, 0, 0, 0, 0, _hSelf, nullptr, _hInst, NULL); + TBBUTTON tbButtons[1]; + // Add the bmap image into toolbar's imagelist + TBADDBITMAP addbmp = { _hInst, 0 }; + addbmp.nID = IDI_FB_SELECTCURRENTFILE; + ::SendMessage(_hToolbarMenu, TB_ADDBITMAP, 1, reinterpret_cast(&addbmp)); + tbButtons[0].idCommand = FB_CMD_AIMFILE; + tbButtons[0].iBitmap = 0; + tbButtons[0].fsState = TBSTATE_ENABLED; + tbButtons[0].fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE; + tbButtons[0].iString = reinterpret_cast(TEXT("")); + ::SendMessage(_hToolbarMenu, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); + ::SendMessage(_hToolbarMenu, TB_SETBUTTONSIZE, 0, MAKELONG(nppParam._dpiManager.scaleX(20), nppParam._dpiManager.scaleY(20))); + ::SendMessage(_hToolbarMenu, TB_SETPADDING, 0, MAKELONG(30, 0)); + ::SendMessage(_hToolbarMenu, TB_ADDBUTTONS, sizeof(tbButtons) / sizeof(TBBUTTON), reinterpret_cast(&tbButtons)); + ::SendMessage(_hToolbarMenu, TB_AUTOSIZE, 0, 0); + ShowWindow(_hToolbarMenu, SW_SHOW); + FileBrowser::initPopupMenus(); _treeView.init(_hInst, _hSelf, ID_FILEBROWSERTREEVIEW); @@ -130,10 +171,16 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP { int width = LOWORD(lParam); int height = HIWORD(lParam); + int extraValue = NppParameters::getInstance()._dpiManager.scaleX(4); + + RECT toolbarMenuRect; + ::GetClientRect(_hToolbarMenu, &toolbarMenuRect); + + ::MoveWindow(_hToolbarMenu, 0, 0, width, toolbarMenuRect.bottom, TRUE); HWND hwnd = _treeView.getHSelf(); if (hwnd) - ::MoveWindow(hwnd, 0, 0, width, height, TRUE); + ::MoveWindow(hwnd, 0, toolbarMenuRect.bottom + extraValue, width, height - toolbarMenuRect.bottom - extraValue, TRUE); break; } @@ -144,12 +191,23 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP case WM_COMMAND: { - popupMenuCmd(LOWORD(wParam)); + switch (LOWORD(wParam)) + { + case FB_CMD_AIMFILE: + { + selectCurrentEditingFile(); + break; + } + + default: + popupMenuCmd(LOWORD(wParam)); + } break; } case WM_DESTROY: { + ::DestroyWindow(_hToolbarMenu); _treeView.destroy(); destroyMenus(); break; @@ -290,6 +348,31 @@ void FileBrowser::initPopupMenus() ::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_FILEBROWSER_CMDHERE, cmdHere.c_str()); } +bool FileBrowser::selectCurrentEditingFile() +{ + TCHAR currentDocPath[MAX_PATH] = { '0' }; + ::SendMessage(_hParent, NPPM_GETFULLCURRENTPATH, MAX_PATH, reinterpret_cast(currentDocPath)); + generic_string rootFolderPath = currentDocPath; + size_t nbFolderUpdaters = _folderUpdaters.size(); + for (size_t i = 0; i < nbFolderUpdaters; ++i) + { + if (isRelatedRootFolder(_folderUpdaters[i]->_rootFolder._rootPath, rootFolderPath)) + { + generic_string rootPath = _folderUpdaters[i]->_rootFolder._rootPath; + generic_string pathSuffix = rootFolderPath.substr(rootPath.size() + 1, rootFolderPath.size() - rootPath.size()); + vector linarPathArray = split(pathSuffix, '\\'); + + HTREEITEM foundItem = findInTree(rootPath, nullptr, linarPathArray); + if (foundItem) + { + _treeView.selectItem(foundItem); + _treeView.getFocus(); + return true; + } + } + } + return false; +} BOOL FileBrowser::setImageList(int root_clean_id, int root_dirty_id, int open_node_id, int closed_node_id, int leaf_id) { @@ -393,12 +476,12 @@ void FileBrowser::openSelectFile() { // Get the selected item HTREEITEM selectedNode = _treeView.getSelection(); - if (not selectedNode) return; + if (!selectedNode) return; generic_string fullPath = getNodePath(selectedNode); // test the path - if it's a file, open it, otherwise just fold or unfold it - if (not ::PathFileExists(fullPath.c_str())) + if (!::PathFileExists(fullPath.c_str())) return; if (::PathIsDirectory(fullPath.c_str())) return; @@ -857,26 +940,6 @@ void FileBrowser::getDirectoryStructure(const TCHAR *dir, const std::vector relatedRootArray = split(relatedRoot, '\\'); - vector subFolderArray = split(subFolder, '\\'); - - size_t index2Compare = relatedRootArray.size() - 1; - - return relatedRootArray[index2Compare] == subFolderArray[index2Compare]; -} - void FileBrowser::addRootFolder(generic_string rootFolderPath) { if (!::PathFileExists(rootFolderPath.c_str())) @@ -1159,7 +1222,7 @@ bool FileBrowser::renameInTree(const generic_string& rootPath, HTREEITEM node, c if (foundItem == nullptr) return false; - // found it, rename it + // found it, rename it _treeView.renameItem(foundItem, renameTo.c_str()); return true; } diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h index 3a38b59f..d0ae862f 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h @@ -157,6 +157,8 @@ public: generic_string getSelectedItemPath() const; protected: + HWND _hToolbarMenu = nullptr; + TreeView _treeView; HIMAGELIST _hImaLst = nullptr; @@ -172,6 +174,7 @@ protected: BrowserNodeType getNodeType(HTREEITEM hItem); void popupMenuCmd(int cmdID); + bool selectCurrentEditingFile(); virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); void notified(LPNMHDR notification); void showContextMenu(int x, int y); diff --git a/PowerEditor/src/icons/fb_select_current_file.bmp b/PowerEditor/src/icons/fb_select_current_file.bmp new file mode 100644 index 00000000..b6025831 Binary files /dev/null and b/PowerEditor/src/icons/fb_select_current_file.bmp differ diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 31b1870f..ebff517a 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -144,6 +144,7 @@ #define IDI_PROJECT_FILEINVALID 607 #define IDI_FB_ROOTOPEN 608 #define IDI_FB_ROOTCLOSE 609 +#define IDI_FB_SELECTCURRENTFILE 610 #define IDI_FUNCLIST_ROOT 620 #define IDI_FUNCLIST_NODE 621