[ENHANCEMENT] Enhance sort feature in function list.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1134 f5eea248-9336-0410-98b8-ebc06183d4e3remotes/trunk
parent
d3afa41a9f
commit
7e6e8f6fba
|
@ -187,6 +187,39 @@ TreeParams* FunctionListPanel::getFromStateArray(generic_string fullFilePath)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void FunctionListPanel::sortOrUnsort()
|
||||
{
|
||||
bool doSort = shouldSort();
|
||||
if (doSort)
|
||||
_pTreeView->sort(_pTreeView->getRoot());
|
||||
else
|
||||
{
|
||||
TCHAR text2search[MAX_PATH] ;
|
||||
::SendMessage(_hSearchEdit, WM_GETTEXT, MAX_PATH, (LPARAM)text2search);
|
||||
|
||||
if (text2search[0] == '\0') // main view
|
||||
{
|
||||
reload();
|
||||
}
|
||||
else // aux view
|
||||
{
|
||||
reload();
|
||||
|
||||
if (_treeView.getRoot() == NULL)
|
||||
return;
|
||||
|
||||
_treeViewSearchResult.removeAllItems();
|
||||
const TCHAR *fn = ((*_ppEditView)->getCurrentBuffer())->getFileName();
|
||||
_treeViewSearchResult.addItem(fn, NULL, INDEX_ROOT, TEXT("-1"));
|
||||
_treeView.searchLeafAndBuildTree(_treeViewSearchResult, text2search, INDEX_LEAF);
|
||||
_treeViewSearchResult.display(true);
|
||||
_treeViewSearchResult.expand(_treeViewSearchResult.getRoot());
|
||||
_treeView.display(false);
|
||||
_pTreeView = &_treeViewSearchResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionListPanel::reload()
|
||||
{
|
||||
// clean up
|
||||
|
@ -407,6 +440,8 @@ void FunctionListPanel::searchFuncAndSwitchView()
|
|||
{
|
||||
TCHAR text2search[MAX_PATH] ;
|
||||
::SendMessage(_hSearchEdit, WM_GETTEXT, MAX_PATH, (LPARAM)text2search);
|
||||
bool doSort = shouldSort();
|
||||
|
||||
if (text2search[0] == '\0')
|
||||
{
|
||||
_treeViewSearchResult.display(false);
|
||||
|
@ -430,6 +465,9 @@ void FunctionListPanel::searchFuncAndSwitchView()
|
|||
// invalidate the editor rect
|
||||
::InvalidateRect(_hSearchEdit, NULL, TRUE);
|
||||
}
|
||||
|
||||
if (doSort)
|
||||
_pTreeView->sort(_pTreeView->getRoot());
|
||||
}
|
||||
|
||||
static WNDPROC oldFunclstToolbarProc = NULL;
|
||||
|
@ -445,6 +483,17 @@ static BOOL CALLBACK funclstToolbarProc(HWND hwnd, UINT message, WPARAM wParam,
|
|||
return oldFunclstToolbarProc(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool FunctionListPanel::shouldSort()
|
||||
{
|
||||
TBBUTTONINFO tbbuttonInfo;
|
||||
tbbuttonInfo.cbSize = sizeof(TBBUTTONINFO);
|
||||
tbbuttonInfo.dwMask = TBIF_STATE;
|
||||
|
||||
::SendMessage(_hToolbarMenu, TB_GETBUTTONINFO, IDC_SORTBUTTON_FUNCLIST, (LPARAM)&tbbuttonInfo);
|
||||
|
||||
return (tbbuttonInfo.fsState & TBSTATE_CHECKED) != 0;
|
||||
}
|
||||
|
||||
BOOL CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
|
@ -496,8 +545,8 @@ BOOL CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
|||
|
||||
tbButtons[1].idCommand = IDC_SORTBUTTON_FUNCLIST;
|
||||
tbButtons[1].iBitmap = I_IMAGENONE;
|
||||
tbButtons[1].fsState = TBSTATE_ENABLED;
|
||||
tbButtons[1].fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE;
|
||||
tbButtons[1].fsState = TBSTATE_ENABLED;
|
||||
tbButtons[1].fsStyle = BTNS_CHECK | BTNS_AUTOSIZE;
|
||||
tbButtons[1].iString = (INT_PTR)TEXT("Sort");
|
||||
|
||||
tbButtons[2].idCommand = IDC_RELOADBUTTON_FUNCLIST;
|
||||
|
@ -552,7 +601,7 @@ BOOL CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
|||
{
|
||||
case IDC_SORTBUTTON_FUNCLIST:
|
||||
{
|
||||
::SendMessage(_pTreeView->getHSelf(), TVM_SORTCHILDREN, TRUE, (LPARAM)_pTreeView->getRoot());
|
||||
sortOrUnsort();
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@ public:
|
|||
};
|
||||
|
||||
// functionalities
|
||||
void sortOrUnsort();
|
||||
void reload();
|
||||
void addEntry(const TCHAR *node, const TCHAR *displayText, size_t pos);
|
||||
void removeAllEntries();
|
||||
|
@ -130,5 +131,6 @@ private:
|
|||
TreeParams* getFromStateArray(generic_string fullFilePath);
|
||||
BOOL setImageList(int root_id, int node_id, int leaf_id);
|
||||
bool openSelection(const TreeView &treeView);
|
||||
bool shouldSort();
|
||||
};
|
||||
#endif // FUNCLISTPANEL_H
|
||||
|
|
|
@ -618,3 +618,11 @@ bool TreeView::restoreFoldingStateFrom(const TreeStateNode & treeState2Compare,
|
|||
}
|
||||
return isOk;
|
||||
}
|
||||
|
||||
void TreeView::sort(HTREEITEM hTreeItem)
|
||||
{
|
||||
::SendMessage(_hSelf, TVM_SORTCHILDREN, TRUE, (LPARAM)hTreeItem);
|
||||
|
||||
for (HTREEITEM hItem = getChildFrom(hTreeItem); hItem != NULL; hItem = getNextSibling(hItem))
|
||||
sort(hItem);
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ public:
|
|||
bool restoreFoldingStateFrom(const TreeStateNode & treeState2Compare, HTREEITEM treeviewNode);
|
||||
bool retrieveFoldingStateTo(TreeStateNode & treeState2Construct, HTREEITEM treeviewNode);
|
||||
bool searchLeafAndBuildTree(TreeView & tree2Build, const generic_string & text2Search, int index2Search);
|
||||
void sort(HTREEITEM hTreeItem);
|
||||
|
||||
protected:
|
||||
WNDPROC _defaultProc;
|
||||
|
|
Loading…
Reference in New Issue