Skip to content

Added "Sort By" function under Window Menu - #11190

Closed
deebash wants to merge 5 commits into
notepad-plus-plus:masterfrom
deebash:master
Closed

deebash wants to merge 5 commits into
notepad-plus-plus:masterfrom
deebash:master

Conversation

@deebash

@deebash deebash commented Feb 12, 2022

Copy link
Copy Markdown
Contributor

Added sorting function under Window Menu for issue #10393

Added sorting function under Window Menu for issue #10393
@Yaron10

Yaron10 commented Feb 12, 2022

Copy link
Copy Markdown

@deebash,

Thank you for this PR.
I've tested it and it works like a charm. Great work. 👍

Allow me some comments:

  1. Wouldn't it be nicer if the "Sort By" menu appeared after the list of open documents?
    List of open documents.
    Separator.
    Sort By.
    Windows...

  2. Isn't it possible to adapt and use the existing Sort functions?

  3. If this PR is accepted, you'd be asked to provide localization for the new items.

@deebash

deebash commented Feb 12, 2022

Copy link
Copy Markdown
Contributor Author

Thanks @Yaron10

  1. Sure, I'll change that. I placed it on top so that if large number of documents are opened users needs to scroll to bottom all the way down to reach this menu item. If you prefer the way that you mentioned, I'll do the change.

  2. Actually I used the existing sort function code, but removed few lines which is related to list view processing in Windows.... Dialog box.

  3. Sure, I'll do that.

@Yaron10

Yaron10 commented Feb 12, 2022

Copy link
Copy Markdown

@deebash,

I placed it on top so that if large number of documents are opened...

The number of open documents is limited to 10.
If @donho approves, I don't see why it shouldn't be changed to 20.

Thanks again.

Comment thread PowerEditor/src/NppCommands.cpp Outdated

case IDM_WINDOW_SORT_FN_ASC :
{
WindowsDlg _windowsDlg;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
size_t count = (_pTab != NULL) ? _pTab->nbItem() : 0;
auto currrentTabIndex = _pTab->getCurrentTabIndex();
NMWINDLG nmdlg;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to avoid a potential memory leak, you can use a RAII approach. Example:

std::vector<UINT> items(count);
nmdlg.Items = items.data();

@deebash

deebash commented Feb 13, 2022 •

Copy link
Copy Markdown
Contributor Author

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.

@chcg chcg added the enhancement Proposed enhancements of existing features label Feb 13, 2022
@Yaron10

Yaron10 commented Feb 14, 2022

Copy link
Copy Markdown

@deebash,

List of open documents.
Separator.
Sort By.
Windows...

A few months ago I modified some code in WindowsDlg.cpp for my personal use.
Amongst other things, I've added a separator between the list of open documents and the Windows... command.

I did that by adding the following lines in WindowsDlg.cpp after the for ( ; id <= IDM_WINDOW_MRU_LIMIT; ++id) loop.

::RemoveMenu(hMenu, 0, MF_SEPARATOR);
::InsertMenu(hMenu, IDM_WINDOW_WINDOWS, MF_SEPARATOR | MF_BYCOMMAND, 0, NULL);

Could you please let me know if you have a better solution?

Thank you.

@deebash

deebash commented Feb 15, 2022 •

Copy link
Copy Markdown
Contributor Author

Could you please let me know if you have a better solution?

@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

@Yaron10

Yaron10 commented Feb 15, 2022

Copy link
Copy Markdown

@deebash,

I'll wait for your final PR. Thank you.

@deebash

deebash commented Feb 16, 2022

Copy link
Copy Markdown
Contributor Author

Hi @donho, waiting for your approval on the menu position.

@donho donho self-assigned this Feb 16, 2022

@donho donho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider the change according the comments of @mere-human.

3 changes mentioned by @mere-human  done in this commit.
@deebash

deebash commented Feb 17, 2022

Copy link
Copy Markdown
Contributor Author

@donho @mere-human changes has been done and commit added.

@mere-human

Copy link
Copy Markdown
Contributor

Looks good. I haven't tested it locally yet.

Comment thread PowerEditor/src/NppCommands.cpp Outdated
WindowsDlg windowsDlg;
windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab);
windowsDlg.sortFileSizeDSC();
windowsDlg.doSort();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent problem?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usual mixed tabs/spaces

Indent error fixed in this commit

@donho donho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. code refactoring.
  2. solve the indent problem (in comment).

nmdlg.code = WDN_NOTIFY;
SendMessage(_hParent, WDN_NOTIFY, 0, LPARAM(&nmdlg));
}

@donho donho Feb 17, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the one line definition code here, with the new method sort().

Comment thread PowerEditor/src/NppCommands.cpp Outdated
WindowsDlg windowsDlg;
windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab);
windowsDlg.sortFileSizeASC();
windowsDlg.doSort();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent problem

Comment thread PowerEditor/src/NppCommands.cpp Outdated
WindowsDlg windowsDlg;
windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab);
windowsDlg.sortFileTypeDSC();
windowsDlg.doSort();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent problem

Comment thread PowerEditor/src/NppCommands.cpp Outdated
WindowsDlg windowsDlg;
windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab);
windowsDlg.sortFileTypeASC();
windowsDlg.doSort();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent problem

Comment thread PowerEditor/src/NppCommands.cpp Outdated
WindowsDlg windowsDlg;
windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab);
windowsDlg.sortFilePathDSC();
windowsDlg.doSort();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent problem

Comment thread PowerEditor/src/NppCommands.cpp Outdated
WindowsDlg windowsDlg;
windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab);
windowsDlg.sortFileNameASC();
windowsDlg.doSort();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent problem

Comment thread PowerEditor/src/NppCommands.cpp Outdated
WindowsDlg windowsDlg;
windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab);
windowsDlg.sortFileNameDSC();
windowsDlg.doSort();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent problem

Comment thread PowerEditor/src/NppCommands.cpp Outdated
WindowsDlg windowsDlg;
windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab);
windowsDlg.sortFilePathASC();
windowsDlg.doSort();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent problem

@donho

donho commented Feb 17, 2022

Copy link
Copy Markdown
Member

@Yaron10

The number of open documents is limited to 10.
If @donho approves, I don't see why it shouldn't be changed to 20.

I will consider it - could you create an issue for that please?

@donho

donho commented Feb 17, 2022 •

Copy link
Copy Markdown
Member

@deebash
There are 2 missing stuffs:

  1. Localization ability (that you have mentioned) + english.xml .
  2. The possibility to add/change the shortcut of these command: https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/PowerEditor/src/Parameters.cpp#L65

You can do them in this PR or in the next PR, it's up to you.
If you do them in the next PR, please create a new branch for each PR:
Create a new branch for each PR. Make sure your branch name wasn't used before - you can add date (for example patch3_20200528) to ensure its uniqueness.
Ref: https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/CONTRIBUTING.md#guidelines-for-pull-requests

Thank you

@deebash

deebash commented Feb 17, 2022

Copy link
Copy Markdown
Contributor Author

@donho I'll do in this PR itself, I'll give commit in few hours. And thank you for the brief comments.

@Yaron10

Yaron10 commented Feb 17, 2022

Copy link
Copy Markdown

@donho,

could you create an issue for that please?

#11229.

Refactoring: I would add a new method here with the following code in WindowsDlg.cpp

👍

Thank you.

1. Code Refactoring
2. Localization ability
3. Shortcut Mapper
@deebash
deebash requested a review from donho February 20, 2022 02:49

@donho donho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"/>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@deebash

deebash commented Feb 20, 2022

Copy link
Copy Markdown
Contributor Author

@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.

@donho

donho commented Feb 20, 2022

Copy link
Copy Markdown
Member

@deebash

I added Sort By prefix before each entries. But changes are taking effect only after language change in preferences. Is this the actual behaviour?

What do you mean by "changes are taking effect only after language change in preferences." ?

@donho donho added the accepted label Feb 20, 2022
@donho donho closed this in 1c8b867 Feb 20, 2022
{ 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 },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

sortTrans = nameW;
::ModifyMenu(menuHandle, 0, MF_BYPOSITION, 0, sortTrans.c_str());
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, it shouldn't be here this block.

@Yaron10

Yaron10 commented Feb 20, 2022

Copy link
Copy Markdown

@deebash & @donho,

👍
Great work. Thank you.

@Yaron10

Yaron10 commented Feb 23, 2022

Copy link
Copy Markdown

#11271.
#11272.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted enhancement Proposed enhancements of existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants