Get back Find dialog while you lost it

In the environment of multi-monitor with a laptop + a stantion, it
happens all the time that users have lost Find dialog after detaching
and retatching - the solution: Ctrl-F twice will get back your Find
dialog.
This commit is contained in:
Don Ho 2016-12-18 17:37:43 +01:00
parent 911fd9a7bd
commit ac871cacd4
6 changed files with 58 additions and 22 deletions

View File

@ -2629,10 +2629,16 @@ void Notepad_plus::maintainIndentation(TCHAR ch)
}
}
BOOL Notepad_plus::processFindAccel(MSG *msg) const
{
if (not ::IsChild(_findReplaceDlg.getHSelf(), ::GetFocus()))
return FALSE;
return ::TranslateAccelerator(_findReplaceDlg.getHSelf(), _accelerator.getFindAccTable(), msg);
}
BOOL Notepad_plus::processIncrFindAccel(MSG *msg) const
{
if (!::IsChild(_incrementFindDlg.getHSelf(), ::GetFocus()))
if (not ::IsChild(_incrementFindDlg.getHSelf(), ::GetFocus()))
return FALSE;
return ::TranslateAccelerator(_incrementFindDlg.getHSelf(), _accelerator.getIncrFindAccTable(), msg);
}

View File

@ -514,6 +514,7 @@ private:
enum LangType menuID2LangType(int cmdID);
BOOL processIncrFindAccel(MSG *msg) const;
BOOL processFindAccel(MSG *msg) const;
void checkMenuItem(int itemID, bool willBeChecked) const {
::CheckMenuItem(_mainMenuHandle, itemID, MF_BYCOMMAND | (willBeChecked?MF_CHECKED:MF_UNCHECKED));

View File

@ -308,6 +308,9 @@ bool Notepad_plus_Window::isDlgsMsg(MSG *msg) const
if (_notepad_plus_plus_core.processIncrFindAccel(msg))
return true;
if (_notepad_plus_plus_core.processFindAccel(msg))
return true;
if (::IsDialogMessageW(_notepad_plus_plus_core._hModelessDlgs[i], msg))
return true;
}

View File

@ -813,7 +813,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
bool isMacroRecording = (::SendMessage(_hParent, WM_GETCURRENTMACROSTATUS,0,0) == MACRO_RECORDING_IN_PROGRESS);
NppParameters *nppParamInst = NppParameters::getInstance();
FindHistory & findHistory = nppParamInst->getFindHistory();
switch (wParam)
switch (LOWORD(wParam))
{
//Single actions
case IDCANCEL:
@ -844,6 +844,10 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
}
return TRUE;
case IDM_SEARCH_FIND:
goToCenter();
return TRUE;
case IDREPLACE :
{
LongRunningOperation op;

View File

@ -483,10 +483,10 @@ INT_PTR CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
// return true if one of CommandShortcuts is deleted. Otherwise false.
void Accelerator::updateShortcuts()
{
vector<int> IFAccIds;
IFAccIds.push_back(IDM_SEARCH_FINDNEXT);
IFAccIds.push_back(IDM_SEARCH_FINDPREV);
IFAccIds.push_back(IDM_SEARCH_FINDINCREMENT);
vector<int> incrFindAccIds;
incrFindAccIds.push_back(IDM_SEARCH_FINDNEXT);
incrFindAccIds.push_back(IDM_SEARCH_FINDPREV);
incrFindAccIds.push_back(IDM_SEARCH_FINDINCREMENT);
NppParameters *pNppParam = NppParameters::getInstance();
@ -503,8 +503,9 @@ void Accelerator::updateShortcuts()
if (_pAccelArray)
delete [] _pAccelArray;
_pAccelArray = new ACCEL[nbMenu+nbMacro+nbUserCmd+nbPluginCmd];
vector<ACCEL> IFAcc;
vector<ACCEL> incrFindAcc;
ACCEL *pSearchFindAccel = nullptr;
int offset = 0;
size_t i = 0;
//no validation performed, it might be that invalid shortcuts are being used by default. Allows user to 'hack', might be a good thing
@ -512,13 +513,16 @@ void Accelerator::updateShortcuts()
{
if (shortcuts[i].isEnabled())
{
_pAccelArray[offset].cmd = (WORD)(shortcuts[i].getID());
_pAccelArray[offset].cmd = static_cast<WORD>(shortcuts[i].getID());
_pAccelArray[offset].fVirt = shortcuts[i].getAcceleratorModifiers();
_pAccelArray[offset].key = shortcuts[i].getKeyCombo()._key;
// Special extra handling for shortcuts shared by Incremental Find dialog
if (std::find(IFAccIds.begin(), IFAccIds.end(), shortcuts[i].getID()) != IFAccIds.end())
IFAcc.push_back(_pAccelArray[offset]);
if (std::find(incrFindAccIds.begin(), incrFindAccIds.end(), shortcuts[i].getID()) != incrFindAccIds.end())
incrFindAcc.push_back(_pAccelArray[offset]);
if (shortcuts[i].getID() == IDM_SEARCH_FIND)
pSearchFindAccel = &_pAccelArray[offset];
++offset;
}
@ -569,14 +573,28 @@ void Accelerator::updateShortcuts()
if (_hIncFindAccTab)
::DestroyAcceleratorTable(_hIncFindAccTab);
size_t nb = IFAcc.size();
ACCEL *tmpAccelArray = new ACCEL[nb];
size_t nb = incrFindAcc.size();
ACCEL *tmpIncrFindAccelArray = new ACCEL[nb];
for (i = 0; i < nb; ++i)
{
tmpAccelArray[i] = IFAcc[i];
tmpIncrFindAccelArray[i] = incrFindAcc[i];
}
_hIncFindAccTab = ::CreateAcceleratorTable(tmpIncrFindAccelArray, static_cast<int32_t>(nb));
delete [] tmpIncrFindAccelArray;
if (_hIncFindAccTab)
::DestroyAcceleratorTable(_hIncFindAccTab);
if (_hFindAccTab)
::DestroyAcceleratorTable(_hFindAccTab);
ACCEL *tmpFindAccelArray = new ACCEL[1];
if (pSearchFindAccel != nullptr)
{
tmpFindAccelArray[0] = *pSearchFindAccel;
_hFindAccTab = ::CreateAcceleratorTable(tmpFindAccelArray, 1);
delete[] tmpFindAccelArray;
}
_hIncFindAccTab = ::CreateAcceleratorTable(tmpAccelArray, static_cast<int32_t>(nb));
delete [] tmpAccelArray;
return;
}

View File

@ -340,12 +340,14 @@ private :
class Accelerator { //Handles accelerator keys for Notepad++ menu, including custom commands
friend class ShortcutMapper;
public:
Accelerator() :_hAccelMenu(NULL), _hMenuParent(NULL), _hAccTable(NULL), _hIncFindAccTab(NULL), _pAccelArray(NULL), _nbAccelItems(0){};
Accelerator() {};
~Accelerator() {
if (_hAccTable)
::DestroyAcceleratorTable(_hAccTable);
if (_hIncFindAccTab)
::DestroyAcceleratorTable(_hIncFindAccTab);
if (_hFindAccTab)
::DestroyAcceleratorTable(_hFindAccTab);
if (_pAccelArray)
delete [] _pAccelArray;
};
@ -356,17 +358,19 @@ public:
};
HACCEL getAccTable() const {return _hAccTable;};
HACCEL getIncrFindAccTable() const { return _hIncFindAccTab; };
HACCEL getFindAccTable() const { return _hFindAccTab; };
void updateShortcuts();
void updateFullMenu();
private:
HMENU _hAccelMenu;
HWND _hMenuParent;
HACCEL _hAccTable;
HACCEL _hIncFindAccTab;
ACCEL *_pAccelArray;
int _nbAccelItems;
HMENU _hAccelMenu = nullptr;
HWND _hMenuParent = nullptr;
HACCEL _hAccTable = nullptr;
HACCEL _hIncFindAccTab = nullptr;
HACCEL _hFindAccTab = nullptr;
ACCEL *_pAccelArray = nullptr;
int _nbAccelItems = 0;
void updateMenuItemByCommand(CommandShortcut csc);
};