Skip to content

Commit

Permalink
Fixed crash in CHistoryTreeControl
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Jun 22, 2024
1 parent 66d746e commit 1030010
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Source/Gui/Controls/CustomTreeControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ class TreeItem
m_callback = c;
}

bool IsExpanded() {
bool IsExpanded() const {
return m_isExpanded;
}

int level() {
int level() const {
return nLevel;
}

int ItemCount() {
int ItemCount() const {
return m_subItems.size();
}

Expand All @@ -110,7 +110,7 @@ class TreeItem
m_Text = text;
}

CString text() {
CString text() const {
return m_Text;
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Gui/Controls/HistoryTreeControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ DWORD CHistoryTreeControl::OnSubItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lp

HistoryItem* CHistoryTreeControl::getItemData(const TreeItem* res)
{
if (!res || res->level() != 1) {
return nullptr;
}
auto* item = static_cast<HistoryTreeItem*> (res->userData());
return item ? item->hi : nullptr;
}
Expand Down
25 changes: 21 additions & 4 deletions Source/Gui/Dialogs/HistoryWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ SYSTEMTIME GregorianDateToSystemTime(const boost::gregorian::date& d) {
CHistoryWindow::CHistoryWindow(CWizardDlg* wizardDlg) :
m_treeView(ServiceLocator::instance()->networkClientFactory())
{
delayed_closing_ = false;
delayedClosing_ = false;
wizardDlg_ = wizardDlg;
delayedLoad_ = false;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ BOOL CHistoryWindow::PreTranslateMessage(MSG* pMsg)
LRESULT CHistoryWindow::OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
auto* settings = ServiceLocator::instance()->settings<WtlGuiSettings>();
delayed_closing_ = true;
delayedClosing_ = true;
if(!m_treeView.isRunning())
{
settings->HistorySettings.EnableDownloading = SendDlgItemMessage(IDC_DOWNLOADTHUMBS, BM_GETCHECK) == BST_CHECKED;
Expand Down Expand Up @@ -286,6 +286,9 @@ LRESULT CHistoryWindow::OnCopyToClipboard(WORD wNotifyCode, WORD wID, HWND hWndC
TreeItem* item = m_treeView.selectedItem();
if(!item) return 0;
HistoryItem* historyItem = CHistoryTreeControl::getItemData(item);
if (!historyItem) {
return 0;
}
std::string url = historyItem->directUrl.length()?historyItem->directUrl:historyItem->viewUrl;
WinUtils::CopyTextToClipboard(Utf8ToWCstring(url));
return 0;
Expand Down Expand Up @@ -323,6 +326,9 @@ LRESULT CHistoryWindow::OnViewBBCode(WORD wNotifyCode, WORD wID, HWND hWndCtl, B
else
{
HistoryItem* hit = CHistoryTreeControl::getItemData(item);
if (!hit) {
return 0;
}
CUrlListItem it = fromHistoryItem(*hit);
items.push_back(it);
}
Expand All @@ -336,6 +342,9 @@ LRESULT CHistoryWindow::OnOpenFolder(WORD wNotifyCode, WORD wID, HWND hWndCtl, B
TreeItem* item = m_treeView.selectedItem();
if(!item) return 0;
HistoryItem* historyItem = CHistoryTreeControl::getItemData(item);
if (!historyItem) {
return 0;
}
std::string fileName = historyItem->localFilePath;
if(fileName.empty()) return 0;
std::string directory = IuCoreUtils::ExtractFilePath(fileName);
Expand All @@ -355,6 +364,9 @@ LRESULT CHistoryWindow::OnEditFileOnServer(WORD wNotifyCode, WORD wID, HWND hWnd
TreeItem* item = m_treeView.selectedItem();
if (!item) return 0;
HistoryItem* historyItem = CHistoryTreeControl::getItemData(item);
if (historyItem) {
return 0;
}
WinUtils::ShellOpenFileOrUrl(U2W(historyItem->editUrl), m_hWnd);
return 0;
}
Expand All @@ -365,7 +377,9 @@ LRESULT CHistoryWindow::OnDeleteFileOnServer(WORD wNotifyCode, WORD wID, HWND hW
if (!item) return 0;
if (LocalizedMessageBox(TR("Are you sure?"), APPNAME, MB_ICONQUESTION|MB_YESNO) == IDYES) {
HistoryItem* historyItem = CHistoryTreeControl::getItemData(item);
DesktopUtils::ShellOpenUrl(historyItem->deleteUrl);
if (historyItem) {
DesktopUtils::ShellOpenUrl(historyItem->deleteUrl);
}
}

return 0;
Expand Down Expand Up @@ -420,6 +434,9 @@ void CHistoryWindow::LoadHistory()

void CHistoryWindow::OpenInBrowser(const TreeItem* item) const {
HistoryItem* historyItem = CHistoryTreeControl::getItemData(item);
if (!historyItem) {
return;
}
std::string url = historyItem->directUrl.length() ? historyItem->directUrl : historyItem->viewUrl;
WinUtils::ShellOpenFileOrUrl(U2W(url), m_hWnd);
}
Expand All @@ -431,7 +448,7 @@ void CHistoryWindow::threadsFinished()
if (delayedLoad_) {
SendMessage(WM_MY_OPENHISTORYFILE);
}
else if(delayed_closing_)
else if(delayedClosing_)
{
EndDialog(0);
return;
Expand Down
2 changes: 1 addition & 1 deletion Source/Gui/Dialogs/HistoryWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class CHistoryWindow : public CCustomDialogIndirectImpl<CHistoryWindow>,
void onItemDblClick(TreeItem* item);
bool delayedLoad_;
std::vector<CString> m_HistoryFiles;
bool delayed_closing_;
bool delayedClosing_;
CString historyFolder;
CWizardDlg* wizardDlg_;
void LoadHistory();
Expand Down

0 comments on commit 1030010

Please sign in to comment.