Skip to content

Commit

Permalink
Fixed updating thumbnail after external image editor closes
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Dec 18, 2024
1 parent 3a173c0 commit d3b96cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
30 changes: 19 additions & 11 deletions Source/Gui/Dialogs/MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,30 +435,30 @@ LRESULT CMainDlg::OnEditExternal(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWnd
LPCTSTR FileName = ThumbsView.GetFileName(nCurItem);
if(!FileName) return FALSE;

WtlGuiSettings& Settings = *ServiceLocator::instance()->settings<WtlGuiSettings>();
// TODO: Edit this bullshit
CString EditorCmd = Settings.ImageEditorPath;
auto* settings = ServiceLocator::instance()->settings<WtlGuiSettings>();

CString EditorCmd = settings->ImageEditorPath;
EditorCmd.Replace(_T("%1"), FileName);
CString EditorCmdLine = WinUtils::ExpandEnvironmentStrings(EditorCmd);

TCHAR FilePathBuffer[256];
WinUtils::ExtractFilePath(FileName, FilePathBuffer, ARRAY_SIZE(FilePathBuffer));

CCmdLine EditorLine(EditorCmdLine);

CString moduleName = EditorLine.ModuleName();
CString params = EditorLine.OnlyParams();
SHELLEXECUTEINFO Sei;
ZeroMemory(&Sei, sizeof(Sei));
Sei.cbSize = sizeof(Sei);
Sei.fMask = SEE_MASK_NOCLOSEPROCESS;
Sei.hwnd = m_hWnd;
Sei.lpVerb = _T("open");

Sei.lpFile = EditorLine.ModuleName();
Sei.lpParameters = EditorLine.OnlyParams();
Sei.lpFile = moduleName;
Sei.lpParameters = params;
Sei.nShow = SW_SHOW;

if (!::ShellExecuteEx(&Sei)) {
LOG(ERROR) << "Opening external editor failed." << std::endl << "Reason: " << WinUtils::ErrorCodeToString(GetLastError());
DWORD lastError = GetLastError();
LOG(ERROR) << "Opening external editor failed." << std::endl
<< "Reason: " << WinUtils::ErrorCodeToString(lastError);
return 0;
}

Expand All @@ -469,7 +469,7 @@ LRESULT CMainDlg::OnEditExternal(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWnd
WaitThreadStop.SetEvent();
WaitForThread(9999);
}
ThumbsView.OutDateThumb(nCurItem);
itemIndexThumbToBeUpdated_ = nCurItem;
m_EditorProcess = Sei.hProcess;
Release();
Start();
Expand Down Expand Up @@ -508,6 +508,14 @@ DWORD CMainDlg::Run()
Events[0] = m_EditorProcess;
Events[1] = WaitThreadStop.m_hEvent;
WaitForMultipleObjects(2, Events, FALSE, INFINITE);
ServiceLocator::instance()->taskRunner()->runInGuiThread([this] {
if (itemIndexThumbToBeUpdated_ < 0) {
return;
}
ThumbsView.OutDateThumb(itemIndexThumbToBeUpdated_);
itemIndexThumbToBeUpdated_ = -1;
}, true);

WaitThreadStop.ResetEvent();
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions Source/Gui/Dialogs/MainDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class CMainDlg : public CDialogImpl<CMainDlg>,public CThreadImpl<CMainDlg>,publi
CThumbsView ThumbsView;
CEvent WaitThreadStop;
HANDLE m_EditorProcess;
int itemIndexThumbToBeUpdated_ = -1;
CFont dialogFont_;
LRESULT OnBnClickedDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnAddFiles(WORD wNotifyCode, WORD wID, HWND hWndCtl);
Expand Down
2 changes: 1 addition & 1 deletion Source/Image Uploader.rc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ BEGIN
DEFPUSHBUTTON "�������",IDC_GRAB,12,34,60,15
EDITTEXT IDC_NUMOFFRAMESEDIT,158,35,40,13,ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",IDC_UPDOWN,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_HOTTRACK,190,34,11,14
CONTROL "�����������",IDC_DEINTERLACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,208,37,69,10
CONTROL "�����������",IDC_DEINTERLACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,208,37,102,10
PUSHBUTTON "����������",IDCANCEL,317,34,55,14
RTEXT "���-�� ������:",IDC_FRAMELABEL,74,37,79,8
CONTROL "",IDC_THUMBLIST,"SysListView32",LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,5,67,375,180
Expand Down

0 comments on commit d3b96cf

Please sign in to comment.