From d3b96cfb586631d66375e0af2aeb1a922bc99c2e Mon Sep 17 00:00:00 2001 From: Sergey Svistunov Date: Wed, 18 Dec 2024 18:03:02 +0300 Subject: [PATCH] Fixed updating thumbnail after external image editor closes --- Source/Gui/Dialogs/MainDlg.cpp | 30 +++++++++++++++++++----------- Source/Gui/Dialogs/MainDlg.h | 1 + Source/Image Uploader.rc | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Source/Gui/Dialogs/MainDlg.cpp b/Source/Gui/Dialogs/MainDlg.cpp index c66b746e..2216c643 100644 --- a/Source/Gui/Dialogs/MainDlg.cpp +++ b/Source/Gui/Dialogs/MainDlg.cpp @@ -435,17 +435,15 @@ LRESULT CMainDlg::OnEditExternal(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWnd LPCTSTR FileName = ThumbsView.GetFileName(nCurItem); if(!FileName) return FALSE; - WtlGuiSettings& Settings = *ServiceLocator::instance()->settings(); - // TODO: Edit this bullshit - CString EditorCmd = Settings.ImageEditorPath; + auto* settings = ServiceLocator::instance()->settings(); + + 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); @@ -453,12 +451,14 @@ LRESULT CMainDlg::OnEditExternal(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWnd 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; } @@ -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(); @@ -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; } diff --git a/Source/Gui/Dialogs/MainDlg.h b/Source/Gui/Dialogs/MainDlg.h index d7bec88d..e26e04d1 100644 --- a/Source/Gui/Dialogs/MainDlg.h +++ b/Source/Gui/Dialogs/MainDlg.h @@ -141,6 +141,7 @@ class CMainDlg : public CDialogImpl,public CThreadImpl,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); diff --git a/Source/Image Uploader.rc b/Source/Image Uploader.rc index 8a48ee70..3f60f127 100644 --- a/Source/Image Uploader.rc +++ b/Source/Image Uploader.rc @@ -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