mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Fixes crash #504
This commit is contained in:
parent
f5a05543cd
commit
5673cefd1b
6 changed files with 79 additions and 6 deletions
|
@ -381,7 +381,8 @@ HEADERS += \
|
|||
src/util/clamp.hpp \
|
||||
src/widgets/label.hpp \
|
||||
src/util/combine_path.hpp \
|
||||
src/widgets/settingspages/browserextensionpage.hpp
|
||||
src/widgets/settingspages/browserextensionpage.hpp \
|
||||
src/nullableptr.hpp
|
||||
|
||||
RESOURCES += \
|
||||
resources/resources.qrc
|
||||
|
|
59
src/nullableptr.hpp
Normal file
59
src/nullableptr.hpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#pragma once
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename T>
|
||||
class NullablePtr
|
||||
{
|
||||
public:
|
||||
NullablePtr()
|
||||
: element_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
NullablePtr(T *element)
|
||||
: element_(element)
|
||||
{
|
||||
}
|
||||
|
||||
T *operator->() const
|
||||
{
|
||||
assert(this->hasElement());
|
||||
|
||||
return element_;
|
||||
}
|
||||
|
||||
T &operator*() const
|
||||
{
|
||||
assert(this->hasElement());
|
||||
|
||||
return *element_;
|
||||
}
|
||||
|
||||
T *get() const
|
||||
{
|
||||
assert(this->hasElement());
|
||||
|
||||
return this->element_;
|
||||
}
|
||||
|
||||
bool isNull() const
|
||||
{
|
||||
return this->element_ == nullptr;
|
||||
}
|
||||
|
||||
bool hasElement() const
|
||||
{
|
||||
return this->element_ != nullptr;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return this->hasElement();
|
||||
}
|
||||
|
||||
private:
|
||||
T *element_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -16,8 +16,8 @@
|
|||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
SelectChannelDialog::SelectChannelDialog()
|
||||
: BaseWindow((QWidget *)nullptr, BaseWindow::EnableCustomFrame)
|
||||
SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
||||
: BaseWindow(parent, BaseWindow::EnableCustomFrame)
|
||||
, selectedChannel(Channel::getEmpty())
|
||||
{
|
||||
this->setWindowTitle("Select a channel to join");
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace widgets {
|
|||
class SelectChannelDialog : public BaseWindow
|
||||
{
|
||||
public:
|
||||
SelectChannelDialog();
|
||||
SelectChannelDialog(QWidget *parent = nullptr);
|
||||
|
||||
void setSelectedChannel(IndirectChannel selectedChannel);
|
||||
IndirectChannel getSelectedChannel() const;
|
||||
|
|
|
@ -45,7 +45,7 @@ pajlada::Signals::Signal<Qt::KeyboardModifiers> Split::modifierStatusChanged;
|
|||
Qt::KeyboardModifiers Split::modifierStatus = Qt::NoModifier;
|
||||
|
||||
Split::Split(SplitContainer *parent)
|
||||
: Split((QWidget *)parent)
|
||||
: Split(static_cast<QWidget *>(parent))
|
||||
{
|
||||
this->container = parent;
|
||||
}
|
||||
|
@ -232,7 +232,13 @@ bool Split::getModerationMode() const
|
|||
void Split::showChangeChannelPopup(const char *dialogTitle, bool empty,
|
||||
std::function<void(bool)> callback)
|
||||
{
|
||||
SelectChannelDialog *dialog = new SelectChannelDialog();
|
||||
if (this->selectChannelDialog.hasElement()) {
|
||||
this->selectChannelDialog->raise();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SelectChannelDialog *dialog = new SelectChannelDialog(this);
|
||||
if (!empty) {
|
||||
dialog->setSelectedChannel(this->getIndirectChannel());
|
||||
}
|
||||
|
@ -247,7 +253,9 @@ void Split::showChangeChannelPopup(const char *dialogTitle, bool empty,
|
|||
}
|
||||
|
||||
callback(dialog->hasSeletedChannel());
|
||||
this->selectChannelDialog = nullptr;
|
||||
});
|
||||
this->selectChannelDialog = dialog;
|
||||
}
|
||||
|
||||
void Split::layoutMessages()
|
||||
|
@ -362,6 +370,7 @@ void Split::doCloseSplit()
|
|||
void Split::doChangeChannel()
|
||||
{
|
||||
this->showChangeChannelPopup("Change channel", false, [](bool) {});
|
||||
|
||||
auto popup = this->findChildren<QDockWidget *>();
|
||||
if (popup.size() && popup.at(0)->isVisible() && !popup.at(0)->isFloating()) {
|
||||
popup.at(0)->hide();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "messages/layouts/messagelayoutelement.hpp"
|
||||
#include "messages/limitedqueuesnapshot.hpp"
|
||||
#include "messages/messageelement.hpp"
|
||||
#include "nullableptr.hpp"
|
||||
#include "util/serialize-custom.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/helper/channelview.hpp"
|
||||
|
@ -22,6 +23,7 @@ namespace widgets {
|
|||
|
||||
class SplitContainer;
|
||||
class SplitOverlay;
|
||||
class SelectChannelDialog;
|
||||
|
||||
// Each ChatWidget consists of three sub-elements that handle their own part of the chat widget:
|
||||
// ChatWidgetHeader
|
||||
|
@ -96,6 +98,8 @@ private:
|
|||
SplitInput input;
|
||||
SplitOverlay *overlay;
|
||||
|
||||
NullablePtr<SelectChannelDialog> selectChannelDialog;
|
||||
|
||||
bool moderationMode = false;
|
||||
|
||||
bool isMouseOver = false;
|
||||
|
|
Loading…
Reference in a new issue