diff --git a/aegisub/src/tooltip_manager.cpp b/aegisub/src/tooltip_manager.cpp index c0ff387a4..7fbdee946 100644 --- a/aegisub/src/tooltip_manager.cpp +++ b/aegisub/src/tooltip_manager.cpp @@ -42,19 +42,43 @@ #include +#ifndef AGI_PRE +#include +#endif + +#include + struct ToolTipBinding { - wxWindow *window; + wxWeakRef window; wxString toolTip; const char *command; const char *context; void Update(); + + ToolTipBinding(wxWindow *window, wxString toolTip, const char *command, const char *context) + : window(window) + , toolTip(toolTip) + , command(command) + , context(context) + { + } + + // clang doesn't like wxWeakRef's copy constructor, so use the assignment + // operator instead + ToolTipBinding(ToolTipBinding const& other) + : toolTip(other.toolTip) + , command(other.command) + , context(other.context) + { + window = other.window; + } }; ToolTipManager::ToolTipManager() { } ToolTipManager::~ToolTipManager() { } void ToolTipManager::Bind(wxWindow *window, wxString tooltip, const char *context, const char *command) { - ToolTipBinding tip = { window, tooltip, command, context }; + ToolTipBinding tip(window, tooltip, command, context); tip.Update(); static ToolTipManager instance; @@ -63,6 +87,8 @@ void ToolTipManager::Bind(wxWindow *window, wxString tooltip, const char *contex } void ToolTipBinding::Update() { + if (!window.get()) return; + std::vector hotkeys = hotkey::get_hotkey_strs(context, command); std::string str; diff --git a/aegisub/src/tooltip_manager.h b/aegisub/src/tooltip_manager.h index c5dcd82da..cd47637fd 100644 --- a/aegisub/src/tooltip_manager.h +++ b/aegisub/src/tooltip_manager.h @@ -36,15 +36,13 @@ #ifndef AGI_PRE #include -#include - -#include -#include -#include #endif struct ToolTipBinding; +class wxString; +class wxWindow; + /// DOCME /// @class ToolTipManager /// @brief DOCME