Skip to content

Commit

Permalink
improve MItemSearchDlg
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Feb 9, 2025
1 parent a554b86 commit 8f37251
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/MItemSearchDlg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,34 @@ class MItemSearchDlg : public MDialogBase
DestroyIcon(m_hIconSm);
}

typedef std::unordered_set<MItemSearchDlg *> dialogs_type;
typedef std::unordered_set<std::shared_ptr<MItemSearchDlg>> dialogs_type;

static dialogs_type& Dialogs()
{
static dialogs_type s_dialogs;
return s_dialogs;
}

virtual void PostNcDestroy()
{
Dialogs().erase(this);
MDialogBase::PostNcDestroy();
delete this;
}

void Done()
{
m_search.bRunning = FALSE;
EnableWindow(GetDlgItem(m_hwnd, IDOK), TRUE);
}

BOOL OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
void OnDestroy(HWND hwnd)
{
Dialogs().insert(this);
for (auto pItem : Dialogs())
{
if (pItem->m_hwnd == hwnd)
{
pItem->m_hwnd = NULL;
break;
}
}
}

BOOL OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
SetDlgItemText(hwnd, edt1, m_search.strText.c_str());

if (m_search.bDownward)
Expand Down Expand Up @@ -163,6 +166,7 @@ class MItemSearchDlg : public MDialogBase
{
HANDLE_MSG(hwnd, WM_INITDIALOG, OnInitDialog);
HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
}
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/RisohEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4466,8 +4466,9 @@ void MMainWnd::OnItemSearch(HWND hwnd)
}

// create dialog
MItemSearchDlg *pDialog = new MItemSearchDlg(m_search);
auto pDialog = std::make_shared<MItemSearchDlg>(m_search);
pDialog->CreateDialogDx(hwnd);
MItemSearchDlg::Dialogs().insert(pDialog);

// set the window handles to m_search.res2text
m_search.res2text.m_hwnd = hwnd;
Expand Down

0 comments on commit 8f37251

Please sign in to comment.