Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare current and previous files and place current in the top view #22

Closed
jsleroy opened this issue Jul 23, 2016 · 6 comments
Closed

Comments

@jsleroy
Copy link
Owner

jsleroy commented Jul 23, 2016

From @Yaron10 on March 10, 2016 19:5

When comparing In One-View mode, the current file and the previous file should be compared.
Also, the current file should always get the top (or left) view.

NOTE:
This fix (current at top) does not address "Compare to last Save".
I've never used "Compare to Git".


Replace

    if(!IsWindowVisible(nppData._scintillaMainHandle) || !IsWindowVisible(nppData._scintillaSecondHandle))
    {   
        skipAutoReset = true;
        SendMessage(nppData._nppHandle, WM_COMMAND, IDM_VIEW_GOTO_ANOTHER_VIEW, 0);
        skipAutoReset = false;
        panelsOpened = true;
    }

with

    if(!IsWindowVisible(nppData._scintillaMainHandle) || !IsWindowVisible(nppData._scintillaSecondHandle))  // Yaron - One-View mode.
    {
        skipAutoReset = true;

        // Yaron - In One-View mode, the current view can be 0 or 1.
        // In Two-Views mode, the top (or left) view is ALWAYS 0, and the bottom view is ALWAYS 1.
        int currentView = SendMessage(nppData._nppHandle, NPPM_GETCURRENTVIEW, 0, 0);
        LRESULT bufferID = SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);

        // Yaron - If the current view is 0, we want the prev file to be moved to the bottom; if the current view is 1, we still need to activate it and make sure it's compared to the current file.
        SendMessage(nppData._nppHandle, WM_COMMAND, IDM_VIEW_TAB_PREV, 0);

        if(currentView == 1)
        {
            bufferID = SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
            SendMessage(nppData._nppHandle, WM_COMMAND, IDM_VIEW_TAB_NEXT, 0);      // Yaron - Switch back to current file.
        }

        SendMessage(nppData._nppHandle, WM_COMMAND, IDM_VIEW_GOTO_ANOTHER_VIEW, 0);     // Yaron - Current file is ALWAYS at top, and prev file is ALWAYS at bottom.

        activateBufferID(bufferID, currentView);        // Yaron - If the current view is 0, activate current file at top; if the current view is 1, activate prev file at bottom (possibly multiple files there).

        if (currentView == 1)
            SendMessage(nppData._nppHandle, WM_COMMAND, IDM_VIEW_SWITCHTO_OTHER_VIEW, 0);       // Yaron - Activate current file at top.

        skipAutoReset = false;
        panelsOpened = true;
    }

and add the following function

void activateBufferID(LRESULT bufferID, int view)
{
    LRESULT index = SendMessage(nppData._nppHandle, NPPM_GETPOSFROMBUFFERID, bufferID, view);
    index = index & 0x3FFFFFFF;

    SendMessage(nppData._nppHandle, NPPM_ACTIVATEDOC, view, index);
}

Thank you.

Copied from original issue: pnedev/comparePlus#1

@jsleroy
Copy link
Owner Author

jsleroy commented Jul 23, 2016

From @pnedev on March 13, 2016 0:45

Hi Yaron,

One question regarding

When comparing In One-View mode, the current file and the previous file should be compared.

Why the current file should be compared to the previous and not to the next file? Could you please explain?
I would prefer to compare the current vs. the next file.

BR,
Pavel

@jsleroy
Copy link
Owner Author

jsleroy commented Jul 23, 2016

From @Yaron10 on March 13, 2016 2:16

Hello Pavel,

I was thinking of the following scenarios:

  1. You start NPP and open two files in order to compare them.
    In this case, practically there's no difference between previous and next.
    But it can still give us a logical reference: two files, current is last and you want to compare it to previous.

  2. You already have some files opened and then you want to compare two other files. You open them.
    If we compare "current vs. next", the newly opened file would be compared to the first old one.

Why would you prefer "current vs. next"?
Is it because "next" is activated when a file has been closed?

Best regards.

@jsleroy
Copy link
Owner Author

jsleroy commented Jul 23, 2016

From @pnedev on March 13, 2016 9:19

Hi Yaron,

Why would you prefer "current vs. next"?
Is it because "next" is activated when a file has been closed?

No, no, nothing that "profound", just a "human" logic :) - If you have several files opened and you switch between tabs and later you decide to compare two adjacent files my "feeling" as user would be to switch to the first (left-most in the tabs order) of the files and start the comparison from it. I would assume then that it would be compared to the next file, right after it.

If I'd like to compare two files immediately after I open them in Notepad++ they will be at the end of the tabs list (I've just opened them) and then they will be compared no matter if I've selected the first or the last.

BR,
Pavel

@jsleroy
Copy link
Owner Author

jsleroy commented Jul 23, 2016

From @Yaron10 on March 13, 2016 19:22

Hello Pavel,

Thanks for the explanation.

Your argument makes sense. However, I still think that the "natural" and more common workflow is "current vs. prev".
As a long time Compare user I've often come across the second scenario I've portrayed.

Would you like me to change that? Not recommended. :) :)

BTW - if "next" was always activated when another file was closed, we could shorten the code.
But if the last tab is closed, "prev" is activated.

Best regards.

@jsleroy
Copy link
Owner Author

jsleroy commented Jul 23, 2016

From @pnedev on March 13, 2016 23:24

Hi Yaron,

The change is merged to master, good job!
Thanks.

BR

@jsleroy
Copy link
Owner Author

jsleroy commented Jul 23, 2016

From @Yaron10 on March 14, 2016 0:40

Hello Pavel,

Thank you!
We might get some feedback regarding this point when you announce the new version.

Best regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants