Added "Sort By" function under Window Menu#11190
Added "Sort By" function under Window Menu#11190deebash wants to merge 5 commits intonotepad-plus-plus:masterfrom deebash:master
Conversation
Added sorting function under Window Menu for issue #10393
|
Thank you for this PR. Allow me some comments:
|
|
Thanks @Yaron10
|
|
|
||
| case IDM_WINDOW_SORT_FN_ASC : | ||
| { | ||
| WindowsDlg _windowsDlg; |
There was a problem hiding this comment.
Underscore at the beginning is usually used only for member variables.
https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/CONTRIBUTING.md#member-variables
| { | ||
| size_t count = (_pTab != NULL) ? _pTab->nbItem() : 0; | ||
| auto currrentTabIndex = _pTab->getCurrentTabIndex(); | ||
| NMWINDLG nmdlg; |
There was a problem hiding this comment.
You can also use uniform initialization to avoid uninitialized members. Like this: nmdlg = {};
| nmdlg.curSel = currrentTabIndex; | ||
| nmdlg.code = WDN_NOTIFY; | ||
| nmdlg.nItems = static_cast<UINT>(count); | ||
| nmdlg.Items = new UINT[count]; |
There was a problem hiding this comment.
In order to avoid a potential memory leak, you can use a RAII approach. Example:
std::vector<UINT> items(count);
nmdlg.Items = items.data();
|
I did the changes as mentioned by @mere-human. Not given commit yet. @donho, If you accept this PR, I'll add localisation text and change the menu item position based upon your suggestion and I'll add single commit with both changes. |
A few months ago I modified some code in I did that by adding the following lines in Could you please let me know if you have a better solution? Thank you. |
@Yaron10 If you want to add menu item at the bottom, then you can use -1 as position. It'll append to bottom of the menu |
|
I'll wait for your final PR. Thank you. |
|
Hi @donho, waiting for your approval on the menu position. |
donho
left a comment
There was a problem hiding this comment.
Please consider the change according the comments of @mere-human.
3 changes mentioned by @mere-human done in this commit.
|
@donho @mere-human changes has been done and commit added. |
|
Looks good. I haven't tested it locally yet. |
| WindowsDlg windowsDlg; | ||
| windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab); | ||
| windowsDlg.sortFileSizeDSC(); | ||
| windowsDlg.doSort(); |
There was a problem hiding this comment.
The usual mixed tabs/spaces
Indent error fixed in this commit
donho
left a comment
There was a problem hiding this comment.
- code refactoring.
- solve the indent problem (in comment).
| nmdlg.code = WDN_NOTIFY; | ||
| SendMessage(_hParent, WDN_NOTIFY, 0, LPARAM(&nmdlg)); | ||
| } | ||
|
|
There was a problem hiding this comment.
Refactoring: I would add a new method here with the following code in WindowsDlg.cpp:
void WindowsDlg::sort(int columnID, bool reverseSort)
{
refreshMap();
_currentColumn = columnID;
_reverseSort = reverseSort;
stable_sort(_idxMap.begin(), _idxMap.end(), BufferEquivalent(_pTab, _currentColumn, _reverseSort));
}
Then use the sort() method on the following methods, in WindowsDlg.h:
void WindowsDlg::sortFileNameASC() {
sort(0, false);
}
void WindowsDlg::sortFileNameDSC() {
sort(0, true);
}
void WindowsDlg::sortFilePathASC() {
sort(1, false);
}
...
Note that the coding conversion (braces position) should be respected:
in cpp:
void aClass::method1()
{
// codes here
}
in h:
class aClass
{
public:
void method1();
int method2() {
return _x; // only one line code can be placed in *.h
}
private:
int _x;
}
|
|
||
| void doSortToTabs(); | ||
| void doSort(); | ||
| void sortFileNameASC(); |
There was a problem hiding this comment.
Put the one line definition code here, with the new method sort().
| WindowsDlg windowsDlg; | ||
| windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab); | ||
| windowsDlg.sortFileSizeASC(); | ||
| windowsDlg.doSort(); |
| WindowsDlg windowsDlg; | ||
| windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab); | ||
| windowsDlg.sortFileTypeDSC(); | ||
| windowsDlg.doSort(); |
| WindowsDlg windowsDlg; | ||
| windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab); | ||
| windowsDlg.sortFileTypeASC(); | ||
| windowsDlg.doSort(); |
| WindowsDlg windowsDlg; | ||
| windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab); | ||
| windowsDlg.sortFilePathDSC(); | ||
| windowsDlg.doSort(); |
| WindowsDlg windowsDlg; | ||
| windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab); | ||
| windowsDlg.sortFileNameASC(); | ||
| windowsDlg.doSort(); |
| WindowsDlg windowsDlg; | ||
| windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab); | ||
| windowsDlg.sortFileNameDSC(); | ||
| windowsDlg.doSort(); |
| WindowsDlg windowsDlg; | ||
| windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab); | ||
| windowsDlg.sortFilePathASC(); | ||
| windowsDlg.doSort(); |
|
@deebash
You can do them in this PR or in the next PR, it's up to you. Thank you |
|
@donho I'll do in this PR itself, I'll give commit in few hours. And thank you for the brief comments. |
1. Code Refactoring 2. Localization ability 3. Shortcut Mapper
donho
left a comment
There was a problem hiding this comment.
Add "Sort By" before all the entries of MainCommandNames in ShortcutMapper.
| <Item id="11006" name="Type A to Z"/> | ||
| <Item id="11007" name="Type Z to A"/> | ||
| <Item id="11008" name="Size Smaller to Larger"/> | ||
| <Item id="11009" name="Size Larger to Smaller"/> |
There was a problem hiding this comment.
Please add "Sort By" before all the entries. For example:
<Item id="11002" name="Sort By Name A to Z"/>
<Item id="11003" name="Sort By Name Z to A"/>
<Item id="11004" name="Sort By Path A to Z"/>
<Item id="11005" name="Sort By Path Z to A"/>
<Item id="11006" name="Sort By Type A to Z"/>
...because these entries name will appear in the shortcut mapper without "Sort By" menu. With "Sort By" in front of each command, users won't be confused.
Sort By prefix added
|
@donho I added Sort By prefix before each entries. But changes are taking effect only after language change in preferences. Is this the actual behaviour? It's happening for all entries. |
What do you mean by "changes are taking effect only after language change in preferences." ? |
| { VK_NULL, IDM_WINDOW_SORT_FT_DSC, false, false, false, nullptr }, | ||
| { VK_NULL, IDM_WINDOW_SORT_FS_ASC, false, false, false, nullptr }, | ||
| { VK_NULL, IDM_WINDOW_SORT_FS_DSC, false, false, false, nullptr }, | ||
|
|
There was a problem hiding this comment.
changes are taking effect only after language change in preferences.
I guess I do understand what you said now - my bad, I forgot these entries.
I'll do a PR to fix them (and you will understand why this behaviour you describe above).
| sortTrans = nameW; | ||
| ::ModifyMenu(menuHandle, 0, MF_BYPOSITION, 0, sortTrans.c_str()); | ||
| } | ||
|
|
There was a problem hiding this comment.
Normally, it shouldn't be here this block.
Added sorting function under Window Menu for issue #10393