Ejemplo n.º 1
0
LRESULT SendMsg(UINT Msg, WPARAM wParam, LPARAM lParam, int count)
{
	int currentEdit;
	::SendMessage(g_nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM) &currentEdit);
	LRESULT res = 0;
	for (int i = 0; i < count; i++)
		res = ::SendMessage(getCurrentHScintilla(currentEdit), Msg, wParam, lParam);
	return res;
}
Ejemplo n.º 2
0
void FindReplaceDlg::getSelText(tComboInfo* info)
{
	if (info == NULL)
		return;

	UINT	posBeg	= 0;
	UINT	posEnd	= 0;

	/* get selection and set find text */
	::SendMessage(_hParentHandle, HEXM_GETSEL, (WPARAM)&posBeg, (LPARAM)&posEnd);

	INT	offset	= (INT)(posBeg < posEnd ? posBeg : posEnd);
	INT	length	= (abs(static_cast<int>(posEnd)-static_cast<int>(posBeg)) > COMBO_STR_MAX ? COMBO_STR_MAX : abs(static_cast<int>(posEnd)-static_cast<int>(posBeg)));
	info->length = length;

	if (info->length != 0)
	{
		PSTR text_temp = new(std::nothrow)CHAR[info->length+1];
		if ( text_temp == NULL ) {
			return;
			}

		std::unique_ptr<_Null_terminated_ CHAR[ ]> text( text_temp );
		text_temp = nullptr;


		/* convert and select and get the text */
		if (LittleEndianChange(_hSCI, getCurrentHScintilla(), &offset, &length) == TRUE)
		{
			ScintillaMsg(_hSCI, SCI_SETSELECTIONSTART, posBeg - offset, 0);
			ScintillaMsg(_hSCI, SCI_SETSELECTIONEND, posEnd - offset, 0);
			ScintillaMsg(_hSCI, SCI_TARGETFROMSELECTION, 0, 0);
			ScintillaMsg(_hSCI, SCI_GETSELTEXT, 0, (LPARAM)text.get());

			/* encode the text in dependency of selected data type */
			memcpy_s(info->text, sizeof( info->text ), text.get(), info->length);

			CleanScintillaBuf(_hSCI);
		}
	}
}
Ejemplo n.º 3
0
void FindReplaceDlg::getSelText(tComboInfo* info)
{
	if (info == NULL)
		return;

	UINT	posBeg	= 0;
	UINT	posEnd	= 0;

	/* get selection and set find text */
	::SendMessage(_hParentHandle, HEXM_GETSEL, (WPARAM)&posBeg, (LPARAM)&posEnd);

	INT	offset	= (INT)(posBeg < posEnd ? posBeg : posEnd);
	INT	length	= (abs((INT)(posEnd-posBeg)) > COMBO_STR_MAX ? COMBO_STR_MAX : abs((INT)(posEnd-posBeg)));
	info->length = length;

	if (info->length != 0)
	{
		CHAR	*text	= (CHAR*)new CHAR[info->length+1];
		if (text != NULL)
		{
			/* convert and select and get the text */
			if (LittleEndianChange(_hSCI, getCurrentHScintilla(), &offset, &length) == TRUE)
			{
				ScintillaMsg(_hSCI, SCI_SETSELECTIONSTART, posBeg - offset, 0);
				ScintillaMsg(_hSCI, SCI_SETSELECTIONEND, posEnd - offset, 0);
				ScintillaMsg(_hSCI, SCI_TARGETFROMSELECTION, 0, 0);
				ScintillaMsg(_hSCI, SCI_GETSELTEXT, 0, (LPARAM)text);

				/* encode the text in dependency of selected data type */
				memcpy(info->text, text, info->length);

				CleanScintillaBuf(_hSCI);
			}
			delete [] text;
		}
	}
}
Ejemplo n.º 4
0
static void SetFocusOnEditor()
{
	int currentEdit;
	::SendMessage(g_nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM) &currentEdit);
	SetFocus(getCurrentHScintilla(currentEdit));	
}
Ejemplo n.º 5
0
INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
	switch (Message) 
	{
        case WM_INITDIALOG :
		{
			initDialog();
			goToCenter();
			return TRUE;
		}
		case WM_ACTIVATE :
        {
			UINT	posBeg;
			UINT	posEnd;

			::SendMessage(_hParentHandle, HEXM_GETSEL, (WPARAM)&posBeg, (LPARAM)&posEnd);
			::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_IN_SEL), ((posBeg == posEnd)?FALSE:TRUE));

			/* change language */
			NLChangeDialog(_hInst, _nppData._nppHandle, _hSelf, _T("FindReplace"));

            break;
        }
		case WM_COMMAND : 
		{
			switch (LOWORD(wParam))
			{
				case IDOK :
                {
					onFind(FALSE);
					return TRUE;
                }
				case IDC_REPLACE:
                {
					onReplace();
					break;
                }
				case IDC_COUNT :
				{
					processAll(COUNT);
					break;
                }
				case IDC_REPLACEALL :
                {
					HWND	hSci = getCurrentHScintilla();
					ScintillaMsg(hSci, SCI_BEGINUNDOACTION);
					processAll(REPLACE_ALL);
					ScintillaMsg(hSci, SCI_ENDUNDOACTION);
					return TRUE;
                }
				case IDC_COMBO_DATATYPE:
				{
					if (HIWORD(wParam) == CBN_SELCHANGE)
						changeCoding();
					break;
				}
				case IDC_CHECK_TRANSPARENT :
				{
					setTrans();
					break;
				}
				case IDC_RADIO_DIRUP :
				case IDC_RADIO_DIRDOWN :
				{
					_whichDirection = isChecked(IDC_RADIO_DIRDOWN);
					return TRUE;
				}
				case IDC_CHECK_MATCHCASE :
				{
					_isMatchCase = isChecked(IDC_CHECK_MATCHCASE);
					return TRUE;
				}
				case IDC_CHECK_WRAP :
				{
					_isWrap = isChecked(IDC_CHECK_WRAP);
					return TRUE;
				}
				case IDC_CHECK_IN_SEL :
				{
					_isInSel = isChecked(IDC_CHECK_IN_SEL);
					return TRUE;
				}
				case IDCANCEL :
				{
					display(FALSE);
					::SetFocus(_hParentHandle);
					break;
				}
				default :
					break;
			}
			break;
		}
		case WM_NOTIFY:
		{
			NMHDR	nmhdr = *((LPNMHDR)lParam);

			if ((nmhdr.idFrom == IDC_SWITCH) && (nmhdr.code == TCN_SELCHANGE))
			{
				_findReplace = TabCtrl_GetCurSel(::GetDlgItem(_hSelf, IDC_SWITCH));
				updateDialog();
			}
			break;
		}
		case WM_HSCROLL :
		{
			if ((HWND)lParam == ::GetDlgItem(_hSelf, IDC_SLIDER_PERCENTAGE))
			{
				setTrans();
			}
			return TRUE;
		}
	}
	return FALSE;
}
Ejemplo n.º 6
0
void FindReplaceDlg::processAll(UINT process)
{
	HWND	hSciSrc		= getCurrentHScintilla();
	INT		lenSrc		= ScintillaMsg(hSciSrc, SCI_GETLENGTH);
	INT		cnt			= 0;
	INT		cntError	= 0;
	INT		offset		= 0;
	INT		length		= 0;
	INT		posBeg		= 0;
	INT		posEnd		= 0;
	BOOL	loopEnd		= FALSE;
	eError	isRep		= E_OK;

	/* get strings */
	_pFindCombo->getText(&_find);
	_pReplaceCombo->getText(&_replace);

	if (_find.length != 0)
	{
		/* selection dependent start position */
		if ((_isInSel == TRUE) && (process == REPLACE_ALL))
		{
			::SendMessage(_hParentHandle, HEXM_GETSEL, (WPARAM)&posBeg, (LPARAM)&lenSrc);
		}

		/* settings */
		ScintillaMsg(_hSCI, SCI_SETSEARCHFLAGS, _isMatchCase ? SCFIND_MATCHCASE : 0, 0);

		/* keep sure that end and begin at the same position */
		posEnd = posBeg;

		do {
			/* copy data into scintilla handle (encoded if necessary) and select string */
			offset = posBeg;
			length = FIND_BLOCK;
			if (LittleEndianChange(_hSCI, hSciSrc, &offset, &length) == TRUE)
			{
				ScintillaMsg(_hSCI, SCI_SETTARGETSTART, posBeg - offset);
				ScintillaMsg(_hSCI, SCI_SETTARGETEND, length);

				/* search */
				while (ScintillaMsg(_hSCI, SCI_SEARCHINTARGET, _find.length, (LPARAM)&_find.text) != -1)
				{
					switch (process)
					{
						case COUNT:
							cnt++;
							break;
						
						case REPLACE_ALL:
							ScintillaMsg(_hSCI, SCI_REPLACETARGET, _replace.length, (LPARAM)&_replace.text);
							isRep = replaceLittleToBig(	hSciSrc, _hSCI, 
														ScintillaMsg(_hSCI, SCI_GETTARGETSTART, 0, 0),
														ScintillaMsg(_hSCI, SCI_GETTARGETSTART, 0, 0) + offset,
														_find.length, 
														_replace.length );
							if (isRep == E_STRIDE)
							{
								LITTLE_REPLACE_ERROR;
								CleanScintillaBuf(_hSCI);
								return;
							}
							else if (isRep == E_OK)
							{
								cnt++;
							}
							else if (isRep == E_START)
							{
								cntError++;
							}

							/* calc offset */
							lenSrc += (_replace.length - _find.length);
							break;

						default:
							break;
					}
					ScintillaMsg(_hSCI, SCI_SETTARGETSTART, ScintillaMsg(_hSCI, SCI_GETTARGETEND));
					ScintillaMsg(_hSCI, SCI_SETTARGETEND, length);
				}

				/* calculate offset or end loop */
				posBeg = offset + length;
				if (posBeg < lenSrc) {
					posBeg -= (_find.length - 1);
				} else {
					loopEnd = TRUE;
				}
			}
		} while (loopEnd == FALSE);
	}

	TCHAR	TEMP[128];
	TCHAR	text[128];

	/* display result */
	if (cnt == 0)
	{
		if (NLGetText(_hInst, _hParent, _T("CantFind"), TEMP, 128)) {
			_tcscpy(text, TEMP);
			if (NLGetText(_hInst, _hParent, _T("Find"), TEMP, 128)) {
				::MessageBox(_hParent, text, TEMP, MB_OK);
			} else {
				::MessageBox(_hParent, text, _T("Find"), MB_OK);
			}
		} else {
			::MessageBox(_hSelf, _T("Can't find"), _T("Find"), MB_OK);
		}
	}
	else
	{
		switch (process)
		{
			case COUNT:
			{
				if (NLGetText(_hInst, _hParent, _T("Tokens Found"), TEMP, 128)) {
					_stprintf(text, TEMP, cnt);
				} else {
					_stprintf(text, _T("%i tokens are found."), cnt);
				}

				if (NLGetText(_hInst, _hParent, _T("Count"), TEMP, 128)) {
					::MessageBox(_hParent, text, TEMP, MB_OK);
				} else {
					::MessageBox(_hParent, text, _T("Count"), MB_OK);
				}

				_pFindCombo->addText(_find);
				break;
			}
			case REPLACE_ALL:
			{
				UINT	pos;
				::SendMessage(_hParentHandle, HEXM_GETPOS, 0, (LPARAM)&pos);
				::SendMessage(_hParentHandle, HEXM_SETPOS, 0, (LPARAM)pos);

				if (NLGetText(_hInst, _hParent, _T("Tokens Replaced"), TEMP, 128)) {
					_stprintf(text, TEMP, cnt);
				} else {
					_stprintf(text, _T("%i tokens are replaced.\n"), cnt);
				}

				if (cntError != 0)
				{
					if (NLGetText(_hInst, _hParent, _T("Tokens Skipped"), TEMP, 128)) {
						_stprintf(text, TEMP, text, cntError);
					} else {
						_stprintf(text, _T("%s%i tokens are skipped, because of alignment error.\n"), text, cntError);
					}
				}

				if (NLGetText(_hInst, _hParent, _T("Replace"), TEMP, 128)) {
					::MessageBox(_hParent, text, TEMP, MB_OK);
				} else {
					::MessageBox(_hParent, text, _T("Replace"), MB_OK);
				}

				_pFindCombo->addText(_find);
				_pReplaceCombo->addText(_replace);
				break;
			}
			default:
				break;
		}
		_pFindCombo->addText(_find);
	}
}
Ejemplo n.º 7
0
void FindReplaceDlg::onReplace(void)
{
	HWND	hSciSrc	= getCurrentHScintilla();
	INT		lenSrc  = ScintillaMsg(hSciSrc, SCI_GETLENGTH);
	lenSrc; //avoid compiler warning  C4189
	INT		lenStr	= 0;
	INT		offset	= 0;
	INT		length  = 0;
	INT		posBeg  = 0;
	INT		posEnd  = 0;
	eError	isRep	= E_OK;

	_pFindCombo->getText(&_find);
	_pReplaceCombo->getText(&_replace);

	/* get selection and correct anchor and cursor position */
	::SendMessage(_hParentHandle, HEXM_GETSEL, (WPARAM)&posBeg, (LPARAM)&posEnd);
	if (posEnd < posBeg) {
		UINT posTmp = posBeg;
		posBeg = posEnd;
		posEnd = posTmp;
	}

	/* copy data into scintilla handle (encoded if necessary) and select string */
	offset = posBeg;
	length = posEnd - posBeg;
	lenStr = length;
	if (LittleEndianChange(_hSCI, hSciSrc, &offset, &length) == TRUE)
	{
		LPSTR	text	= (LPSTR)new CHAR[lenStr+1];

		if (text != NULL)
		{
			/* get selection and compare if it is equal to expected text */
			ScintillaMsg(_hSCI, SCI_SETSELECTIONSTART, posBeg - offset, 0);
			ScintillaMsg(_hSCI, SCI_SETSELECTIONEND, posEnd - offset, 0);
    		ScintillaMsg(_hSCI, SCI_GETSELTEXT, 0, (LPARAM)text);

			/* make difference between match case modes */
    		if (((_isMatchCase == TRUE) && (memcmp(text, _find.text, lenStr) == 0)) ||
				((_isMatchCase == FALSE) && (_stricmp(text, _find.text) == 0)))
    		{
    			ScintillaMsg(_hSCI, SCI_TARGETFROMSELECTION);
    			ScintillaMsg(_hSCI, SCI_REPLACETARGET, _replace.length, (LPARAM)&_replace.text);
    			isRep = replaceLittleToBig(hSciSrc, _hSCI, posBeg - offset, posBeg, lenStr, _replace.length);
    			if (isRep == E_OK)
    			{
    				::SendMessage(_hParentHandle, HEXM_SETPOS, 0, posBeg + _replace.length);
    				_pFindCombo->addText(_find);
    				_pReplaceCombo->addText(_replace);
    			}
    		}

    		if (isRep == E_OK) {
    			onFind(FALSE);
    		} else {
    			LITTLE_REPLACE_ERROR;
    		}

    		delete [] text;
		}
   		CleanScintillaBuf(_hSCI);
	}
}
Ejemplo n.º 8
0
void FindReplaceDlg::onFind(BOOL isVolatile)
{
	/* get current scintilla */
	HWND		hSciSrc		= getCurrentHScintilla();
	INT			lenSrc		= ScintillaMsg(hSciSrc, SCI_GETLENGTH);
	INT			offset		= 0;
	INT			length		= 0;
	INT			posBeg		= 0;
	INT			posEnd		= 0;
	INT			wrapPos		= 0;
	BOOL		loopEnd		= FALSE;
	BOOL		doWrap		= FALSE;
	BOOL		wrapDone	= FALSE;
	tComboInfo	info		= {0};

	if (_hSCI == NULL)
	{
		/* create new scintilla handle */
		_hSCI = (HWND)::SendMessage(_nppData._nppHandle, NPPM_CREATESCINTILLAHANDLE, 0, (LPARAM)_hSelf);
	}

	/* in dependency of find type get search information from combo or directly from source */
	if (isVolatile == FALSE)
	{
		_pFindCombo->getText(&_find);
		info = _find;
		if (info.length == 0)
			return;
	}
	else
	{
		getSelText(&info);
		if (info.length == 0) {
			if (NLMessageBox(_hInst, _hParent, _T("MsgBox SelectSomething"), MB_OK) == FALSE)
				::MessageBox(_hParent, _T("Select something in the text!"), _T("Hex-Editor"), MB_OK);
			return;
		}
	}

	/* set match case */
	ScintillaMsg(_hSCI, SCI_SETSEARCHFLAGS, _isMatchCase ? SCFIND_MATCHCASE : 0, 0);

	/* get selection and correct anchor and cursor position */
	::SendMessage(_hParentHandle, HEXM_GETSEL, (WPARAM)&posBeg, (LPARAM)&posEnd);
	if (posEnd < posBeg) {
		UINT posTmp = posBeg;
		posBeg = posEnd;
		posEnd = posTmp;
	}
	wrapPos = posBeg;

	do {
		BOOL	isConverted = FALSE;

		/* copy data into scintilla handle (encoded if necessary) and select string */

		if ((wrapDone == TRUE) && (lenSrc < FIND_BLOCK)) {
			if (_whichDirection == DIR_DOWN) {
				length = wrapPos + info.length + 1;
			} else {
				length = FIND_BLOCK;
			}
		} else {
			length = FIND_BLOCK;
		}

		if (_whichDirection == DIR_DOWN)
		{
			offset = posBeg;
			if (LittleEndianChange(_hSCI, hSciSrc, &offset, &length) == TRUE)
			{
				ScintillaMsg(_hSCI, SCI_SETTARGETSTART, posEnd - offset);
				ScintillaMsg(_hSCI, SCI_SETTARGETEND, length);
				isConverted = TRUE;
			}
		}
		else
		{
			posEnd -= FIND_BLOCK;
			offset = posEnd;
			if (LittleEndianChange(_hSCI, hSciSrc, &offset, &length) == TRUE)
			{
				ScintillaMsg(_hSCI, SCI_SETTARGETSTART, posBeg);
				ScintillaMsg(_hSCI, SCI_SETTARGETEND, posEnd - offset);
				isConverted = TRUE;
			}
		}

		if (isConverted == TRUE)
		{
			/* find string */
			INT posFind = ScintillaMsg(_hSCI, SCI_SEARCHINTARGET, info.length, (LPARAM)info.text);
			if (posFind != -1)
			{
				/* found */
				posFind += offset;
				::SendMessage(_hParentHandle, HEXM_SETSEL, posFind, posFind + info.length);
				if (isVolatile == FALSE) {
					_pFindCombo->addText(info);
				}
				loopEnd = TRUE;
			}
			else
			{
				/* calculate new start find position */
				if (_whichDirection == DIR_DOWN)
				{
					posBeg = offset + length;

					/* test if out of bound */
					if ((posBeg >= lenSrc) && (wrapDone == FALSE)) {
						posBeg = 0;
						/* notify wrap is done */
						doWrap = TRUE;
					} else if (posBeg != lenSrc) {
						/* calculate new start find position */
						posBeg -= (info.length + 1);
					}

					/* indicate that wrap is still done */
					wrapDone = doWrap;

				} 
				else
				{
					/* indicate wrap done next time */
					wrapDone = doWrap;

					posBeg = offset;

					/* test if out of bound */
					if ((posBeg <= 0) && (wrapDone == FALSE)) {
						posBeg = lenSrc;
						/* notify wrap is done */
						doWrap = TRUE;
					} else if (posBeg != 0) {
						/* calculate new start find position */
						posBeg += (info.length + 1);
					}
				}

				/* if wrap was done and posBeg is jump over the wrapPos (start pos on function call)... */
				if ((wrapDone == TRUE) &&
					(((_whichDirection == DIR_DOWN) && (posBeg >= wrapPos)) ||
					 ((_whichDirection == DIR_UP  ) && (posEnd <= wrapPos))))
				{
					/* ... leave the function */
					TCHAR	text[128];
					TCHAR	TEMP[128];

					if (NLGetText(_hInst, _hParent, _T("CantFind"), TEMP, 128)) {
						_tcscpy(text, TEMP);
						if (NLGetText(_hInst, _hParent, (_findReplace == TRUE)?_T("Replace"):_T("Find"), TEMP, 128)) {
							::MessageBox(_hParent, text, TEMP, MB_OK);
						} else {
							::MessageBox(_hParent, text, (_findReplace == TRUE)?_T("Replace"):_T("Find"), MB_OK);
						}
					} else {
						::MessageBox(_hSelf, _T("Can't find"),(_findReplace == TRUE)?_T("Replace"):_T("Find"), MB_OK);
					}

					loopEnd = TRUE;
				}

				/* for further calculation */
				posEnd = posBeg;
			}
			CleanScintillaBuf(_hSCI);
		}
		else
		{
			loopEnd = TRUE;
		}
	} while (loopEnd == FALSE);
}
Ejemplo n.º 9
0
// Exit compare session
// - Clear results
// - Delete objects
// - Restore previous NP++ appearance (markers, highlight, ...)
void reset()
{
    if (active == true)
    {
		LRESULT RODoc1;
		LRESULT RODoc2;

		// Remove read-only attribute
		if ((RODoc1 = SendMessage(nppData._scintillaMainHandle, SCI_GETREADONLY, 0, 0)) == 1)
			SendMessage(nppData._scintillaMainHandle, SCI_SETREADONLY, false, 0);

		if ((RODoc2 = SendMessage(nppData._scintillaSecondHandle, SCI_GETREADONLY, 0, 0)) == 1)
			SendMessage(nppData._scintillaSecondHandle, SCI_SETREADONLY, false, 0);

        int doc1 = SendMessageA(nppData._scintillaMainHandle, SCI_GETDOCPOINTER, 0, 0);
        int doc2 = SendMessageA(nppData._scintillaSecondHandle, SCI_GETDOCPOINTER, 0, 0);

        int doc1Index = getCompare(doc1);
        int doc2Index = getCompare(doc2);
        int win = 3;

        ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&win);
        HWND window = getCurrentHScintilla(win);

        if(doc1Index != -1)
        {
            clearWindow(nppData._scintillaMainHandle, true);
        }
        if(doc2Index != -1)
        {
            clearWindow(nppData._scintillaSecondHandle, true);
        }

        ::SendMessageA(window, SCI_GRABFOCUS, 0, (LPARAM)1);

        ::SendMessage(nppData._nppHandle, WM_COMMAND, MAKELONG(IDM_VIEW_SYNSCROLLV, 0), 0);
        ::SendMessage(nppData._nppHandle, WM_COMMAND, MAKELONG(IDM_VIEW_SYNSCROLLH, 0), 0);	

        if(panelsOpened)
        {
            ::SendMessageA(nppData._scintillaSecondHandle, SCI_GRABFOCUS, 0, (LPARAM)0);
            SendMessage(nppData._nppHandle, WM_COMMAND, IDM_VIEW_GOTO_ANOTHER_VIEW, 0);
        }

        if(tempWindow!=-1)
        {
            ::SendMessage(nppData._nppHandle, NPPM_SWITCHTOFILE, 0, (LPARAM)compareFilePath);
            window = getCurrentWindow();	
            int tempPointer = SendMessageA(window, SCI_GETDOCPOINTER, 0, 0);
            
            if(tempPointer == tempWindow)
            {
                SendMessageA(window,SCI_EMPTYUNDOBUFFER,0,0);
                SendMessage(nppData._nppHandle, WM_COMMAND, IDM_FILE_CLOSE, 0);
            }
            tempWindow = -1;
			LRESULT ROTemp = RODoc1; RODoc1 = RODoc2; RODoc2 = ROTemp;
        }

        // Remove margin mask
        ::SendMessage(nppData._scintillaMainHandle, SCI_SETMARGINMASKN, (WPARAM)4, (LPARAM)0);
        ::SendMessage(nppData._scintillaSecondHandle, SCI_SETMARGINMASKN, (WPARAM)4, (LPARAM)0);

        // Remove margin
        ::SendMessage(nppData._scintillaMainHandle, SCI_SETMARGINWIDTHN, (WPARAM)4, (LPARAM)0);
        ::SendMessage(nppData._scintillaSecondHandle, SCI_SETMARGINWIDTHN, (WPARAM)4, (LPARAM)0);

        removeCompare(doc1);
        removeCompare(doc2);

        panelsOpened = false;
        active = false;

        // Close NavBar
        NavDlg.doDialog(false);

        // Disable Prev/Next menu entry
        HMENU hMenu = ::GetMenu(nppData._nppHandle);
        ::EnableMenuItem(hMenu, funcItem[CMD_PREV]._cmdID, MF_BYCOMMAND | MF_GRAYED);
        ::EnableMenuItem(hMenu, funcItem[CMD_NEXT]._cmdID, MF_BYCOMMAND | MF_GRAYED);
        ::EnableMenuItem(hMenu, funcItem[CMD_FIRST]._cmdID, MF_BYCOMMAND | MF_GRAYED);
        ::EnableMenuItem(hMenu, funcItem[CMD_LAST]._cmdID, MF_BYCOMMAND | MF_GRAYED);

        // Restore side bar item entry state (because tick has been removed by the docked window)
        CheckMenuItem(hMenu, funcItem[CMD_USE_NAV_BAR]._cmdID, MF_BYCOMMAND | (Settings.UseNavBar ? MF_CHECKED : MF_UNCHECKED));

		// Restore previous read-only attribute
		if (RODoc1 == 1) SendMessage(nppData._scintillaMainHandle, SCI_SETREADONLY, true, 0);
		if (RODoc2 == 1) SendMessage(nppData._scintillaSecondHandle, SCI_SETREADONLY, true, 0);
    }
}
Ejemplo n.º 10
0
bool startCompare()
{
	LRESULT RODoc1;
	LRESULT RODoc2;
    int win = 3;

    ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&win);
    HWND window = getCurrentHScintilla(win);

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

    if(!IsWindowVisible(nppData._scintillaMainHandle) || !IsWindowVisible(nppData._scintillaSecondHandle))
    {	
        panelsOpened = false;
        ::MessageBox(nppData._nppHandle, TEXT("Nothing to compare!"), TEXT("Error"), MB_OK);
        return true;
    }

    if(!notepadVersionOk)
    {
        int version = ::SendMessage(nppData._nppHandle,NPPM_GETNPPVERSION, 0, 0);
        if(version > 0)
        {
            notepadVersionOk = true;
        }
    }

    if(Settings.AddLine && !notepadVersionOk)
    {
        ::MessageBox(nppData._nppHandle, TEXT("Notepad v4.5 or higher is required to line up matches. This feature will be turned off"), TEXT("Incorrect Version"), MB_OK);
        Settings.AddLine = false;
        ::SendMessage(nppData._nppHandle, NPPM_SETMENUITEMCHECK, funcItem[CMD_ALIGN_MATCHES]._cmdID, (LPARAM)Settings.AddLine);
    }

	// Remove read-only attribute
	if ((RODoc1 = SendMessage(nppData._scintillaMainHandle, SCI_GETREADONLY, 0, 0)) == 1)
		SendMessage(nppData._scintillaMainHandle, SCI_SETREADONLY, false, 0);

	if ((RODoc2 = SendMessage(nppData._scintillaSecondHandle, SCI_GETREADONLY, 0, 0)) == 1)
		SendMessage(nppData._scintillaSecondHandle, SCI_SETREADONLY, false, 0);

    SendMessageA(nppData._scintillaMainHandle, SCI_SETWRAPMODE, SC_WRAP_NONE, 0);
    SendMessageA(nppData._scintillaSecondHandle, SCI_SETWRAPMODE, SC_WRAP_NONE, 0);

    setStyles(Settings);

    int doc1 = SendMessageA(nppData._scintillaMainHandle, SCI_GETDOCPOINTER, 0, 0);
    int doc2 = SendMessageA(nppData._scintillaSecondHandle, SCI_GETDOCPOINTER, 0, 0);

    setCompare(doc1);
    setCompare(doc2);

    /* sync pannels */
    HMENU hMenu = ::GetMenu(nppData._nppHandle);

    if ((::GetMenuState(hMenu, IDM_VIEW_SYNSCROLLV, MF_BYCOMMAND) & MF_CHECKED) != 0)
    {
        ::SendMessage(nppData._nppHandle, WM_COMMAND, MAKELONG(IDM_VIEW_SYNSCROLLV, 0), 0);
    }

    if ((::GetMenuState(hMenu, IDM_VIEW_SYNSCROLLH, MF_BYCOMMAND) & MF_CHECKED) != 0)
    {
        ::SendMessage(nppData._nppHandle, WM_COMMAND, MAKELONG(IDM_VIEW_SYNSCROLLH, 0), 0);
    }

    ::SendMessageA(nppData._scintillaMainHandle, SCI_GOTOPOS, 1, 0);
    ::SendMessageA(nppData._scintillaSecondHandle, SCI_GOTOPOS, 1, 0);
    ::SendMessage(nppData._nppHandle, WM_COMMAND, MAKELONG(IDM_VIEW_SYNSCROLLV, 0), 0);
    ::SendMessage(nppData._nppHandle, WM_COMMAND, MAKELONG(IDM_VIEW_SYNSCROLLH, 0), 0);
    ::SendMessageA(nppData._scintillaMainHandle, SCI_SETUNDOCOLLECTION, FALSE, 0);
    ::SendMessageA(nppData._scintillaSecondHandle, SCI_SETUNDOCOLLECTION, FALSE, 0);

    bool result = compareNew();

    ::SendMessageA(nppData._scintillaMainHandle, SCI_SETUNDOCOLLECTION, TRUE, 0);
    ::SendMessageA(nppData._scintillaSecondHandle, SCI_SETUNDOCOLLECTION, TRUE, 0);
    ::SendMessageA(nppData._scintillaSecondHandle/*window*/, SCI_GRABFOCUS, 0, (LPARAM)1);

	// Restore previous read-only attribute
	if (RODoc1 == 1) SendMessage(nppData._scintillaMainHandle, SCI_SETREADONLY, true, 0);
	if (RODoc2 == 1) SendMessage(nppData._scintillaSecondHandle, SCI_SETREADONLY, true, 0);

    if (!result)
	{
        if(Settings.UseNavBar)
		{
			// Save current N++ focus
			HWND hwnd = GetFocus();

			// Configure NavBar
			NavDlg.SetColor(
				Settings.ColorSettings.added, 
				Settings.ColorSettings.deleted, 
				Settings.ColorSettings.changed, 
				Settings.ColorSettings.moved, 
				Settings.ColorSettings.blank);

			// Display Navbar
			NavDlg.doDialog(true);
			start_old = -1;

			// Restore N++ focus
			SetFocus(hwnd);

		}
		// Enable Prev/Next menu entry
		::EnableMenuItem(hMenu, funcItem[CMD_NEXT]._cmdID, MF_BYCOMMAND | MF_ENABLED);
		::EnableMenuItem(hMenu, funcItem[CMD_PREV]._cmdID, MF_BYCOMMAND | MF_ENABLED);
		::EnableMenuItem(hMenu, funcItem[CMD_FIRST]._cmdID, MF_BYCOMMAND | MF_ENABLED);
		::EnableMenuItem(hMenu, funcItem[CMD_LAST]._cmdID, MF_BYCOMMAND | MF_ENABLED);
	}

	return result;
}