Skip to content

Commit

Permalink
Add some functions for convenience
Browse files Browse the repository at this point in the history
Add and rearange some Npp helper functions, no functional change.
  • Loading branch information
pnedev committed Apr 15, 2016
1 parent e0b9c81 commit 4ea7472
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 68 deletions.
25 changes: 12 additions & 13 deletions src/Compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,15 @@ void jumpChangedLines(bool direction)
lineStart--;
}

if ((direction && (nextLine < prevLine)) ||
(!direction && (nextLine > prevLine)))
if ((direction && (nextLine < prevLine)) || (!direction && (nextLine > prevLine)))
{
FLASHWINFO flashInfo;
flashInfo.cbSize = sizeof(flashInfo);
flashInfo.hwnd = nppData._nppHandle;
flashInfo.uCount = 2;
flashInfo.dwTimeout = 100;
flashInfo.dwFlags = FLASHW_ALL;
FlashWindowEx(&flashInfo);
::FlashWindowEx(&flashInfo);
}

::SendMessage(CurView, SCI_ENSUREVISIBLEENFORCEPOLICY, nextLine, 0);
Expand All @@ -494,7 +493,7 @@ void jumpChangedLines(bool direction)
// ::SendMessage(nppData._nppHandle, NPPM_GETFULLCURRENTPATH, _countof(original), (LPARAM)original);
// HWND originalwindow = getCurrentView();

// LRESULT curBuffer = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
// LRESULT curBuffer = getCurrentBuffId();
// LangType curLang = (LangType)::SendMessage(nppData._nppHandle, NPPM_GETBUFFERLANGTYPE, curBuffer, 0);

// int result = ::SendMessage(nppData._nppHandle, NPPM_SWITCHTOFILE, 0, (LPARAM)compareFilePath);
Expand All @@ -507,7 +506,7 @@ void jumpChangedLines(bool direction)
// ::SendMessage(nppData._nppHandle, NPPM_GETFILENAME, 0, (LPARAM)compareFilePath);
// tempWindow = ::SendMessage(window, SCI_GETDOCPOINTER, 0, 0);

// curBuffer = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
// curBuffer = getCurrentBuffId();
// ::SendMessage(nppData._nppHandle, NPPM_SETBUFFERLANGTYPE, curBuffer, curLang);
// }

Expand Down Expand Up @@ -882,7 +881,7 @@ CompareList_t::iterator createComparePair()
firstFile.reset();

cmpPair.second.originalViewId = getCurrentViewId();
cmpPair.second.buffId = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
cmpPair.second.buffId = getCurrentBuffId();

const bool moveToOtherViewNeeded = (cmpPair.first.originalViewId == cmpPair.second.originalViewId);

Expand Down Expand Up @@ -989,7 +988,7 @@ bool prepareFiles()
if (manualSelectionMode)
{
// Compare to self?
if (firstFile->buffId == ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0))
if (firstFile->buffId == getCurrentBuffId())
{
::MessageBox(nppData._nppHandle, TEXT("Trying to compare file to itself - operation ignored."),
TEXT("Compare Plugin"), MB_OK);
Expand Down Expand Up @@ -1082,7 +1081,7 @@ void SetAsFirst()
{
firstFile.reset(new ComparedFile);

firstFile->buffId = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
firstFile->buffId = getCurrentBuffId();

HWND view = getCurrentView();

Expand All @@ -1102,7 +1101,7 @@ void Compare()
{
ScopedIncrementer incr(notificationsLock);

CompareList_t::iterator cmpPair = getCompare(::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0));
CompareList_t::iterator cmpPair = getCompare(getCurrentBuffId());

// New compare
if (cmpPair == compareList.end())
Expand Down Expand Up @@ -1180,7 +1179,7 @@ void ClearCurrentCompare()
if (!nppSettings.compareMode)
nppSettings.updatePluginMenu();
else
clearComparePair(::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0));
clearComparePair(getCurrentBuffId());
}


Expand All @@ -1193,7 +1192,7 @@ void ClearAllCompares()
else
nppSettings.setNormalMode();

const int buffId = ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
const int buffId = getCurrentBuffId();

ScopedIncrementer incr(notificationsLock);

Expand Down Expand Up @@ -1630,7 +1629,7 @@ void onSciUpdateUI(SCNotification *notifyCode)

void onSciModified(SCNotification *notifyCode)
{
CompareList_t::iterator cmpPair = getCompare(::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0));
CompareList_t::iterator cmpPair = getCompare(getCurrentBuffId());
if (cmpPair == compareList.end())
return;

Expand All @@ -1652,7 +1651,7 @@ void onSciModified(SCNotification *notifyCode)

void onSciZoom()
{
CompareList_t::iterator cmpPair = getCompare(::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0));
CompareList_t::iterator cmpPair = getCompare(getCurrentBuffId());
if (cmpPair == compareList.end())
return;

Expand Down
3 changes: 3 additions & 0 deletions src/Compare.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@ struct sUserSettings
};


extern NppData nppData;


void ViewNavigationBar();
48 changes: 0 additions & 48 deletions src/NPPHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
#define INDIC_HIGHLIGHT INDIC_CONTAINER + 7


extern NppData nppData;


static const char strEOL[3][3] =
{
"\r\n",
Expand All @@ -44,51 +41,6 @@ static const char strEOL[3][3] =
static const unsigned short lenEOL[3] = { 2, 1, 1 };


bool isSingleView()
{
return (!IsWindowVisible(nppData._scintillaSecondHandle) || !IsWindowVisible(nppData._scintillaMainHandle));
}


HWND getView(int viewId)
{
return (viewId == MAIN_VIEW) ? nppData._scintillaMainHandle : nppData._scintillaSecondHandle;
}


int getCurrentViewId()
{
return ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTVIEW, 0, 0);
}


HWND getCurrentView()
{
return (::SendMessage(nppData._nppHandle, NPPM_GETCURRENTVIEW, 0, 0) == MAIN_VIEW) ?
nppData._scintillaMainHandle : nppData._scintillaSecondHandle;
}


int getOtherViewId()
{
return (::SendMessage(nppData._nppHandle, NPPM_GETCURRENTVIEW, 0, 0) == MAIN_VIEW) ? SUB_VIEW : MAIN_VIEW;
}


HWND getOtherView()
{
return (::SendMessage(nppData._nppHandle, NPPM_GETCURRENTVIEW, 0, 0) == MAIN_VIEW) ?
nppData._scintillaSecondHandle : nppData._scintillaMainHandle;
}


int viewIdFromBuffId(int buffId)
{
LRESULT index = ::SendMessage(nppData._nppHandle, NPPM_GETPOSFROMBUFFERID, buffId, 0);
return (index >> 30);
}


void activateBufferID(int buffId)
{
LRESULT index = ::SendMessage(nppData._nppHandle, NPPM_GETPOSFROMBUFFERID, buffId, 0);
Expand Down
56 changes: 49 additions & 7 deletions src/NPPHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,57 @@ using BlankSections_t = std::vector<BlankSection>;
using DocLines_t = std::vector<std::vector<char>>;


bool isSingleView();
inline bool isSingleView()
{
return (!::IsWindowVisible(nppData._scintillaSecondHandle) || !::IsWindowVisible(nppData._scintillaMainHandle));
}


inline HWND getView(int viewId)
{
return (viewId == MAIN_VIEW) ? nppData._scintillaMainHandle : nppData._scintillaSecondHandle;
}


inline int getCurrentViewId()
{
return ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTVIEW, 0, 0);
}


inline HWND getCurrentView()
{
return (::SendMessage(nppData._nppHandle, NPPM_GETCURRENTVIEW, 0, 0) == MAIN_VIEW) ?
nppData._scintillaMainHandle : nppData._scintillaSecondHandle;
}


inline int getOtherViewId()
{
return (::SendMessage(nppData._nppHandle, NPPM_GETCURRENTVIEW, 0, 0) == MAIN_VIEW) ? SUB_VIEW : MAIN_VIEW;
}


inline HWND getOtherView()
{
return (::SendMessage(nppData._nppHandle, NPPM_GETCURRENTVIEW, 0, 0) == MAIN_VIEW) ?
nppData._scintillaSecondHandle : nppData._scintillaMainHandle;
}


inline int viewIdFromBuffId(int buffId)
{
LRESULT index = ::SendMessage(nppData._nppHandle, NPPM_GETPOSFROMBUFFERID, buffId, 0);
return (index >> 30);
}


inline int getCurrentBuffId()
{
return ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTBUFFERID, 0, 0);
}

HWND getView(int viewId);
int getCurrentViewId();
HWND getCurrentView();
int getOtherViewId();
HWND getOtherView();

int viewIdFromBuffId(int buffId);
void activateBufferID(int buffId);

void markTextAsChanged(HWND window, int start, int length);
Expand Down

0 comments on commit 4ea7472

Please sign in to comment.