Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: QuickSwitcherPopup now pops up in the selected window #4819

Merged
merged 7 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Bugfix: Fixed Usercard popup not floating on tiling WMs on Linux when "Automatically close user popup when it loses focus" setting is enabled. (#3511)
- Bugfix: Fixed selection of tabs after closing a tab when using "Live Tabs Only". (#4770)
- Bugfix: Fixed input in reply thread popup losing focus when dragging. (#4815)
- Bugfix: Fixed the Quick Switcher (CTRL+K) from sometimes showing up on the wrong window. (#4819)
- Bugfix: Fixed too much text being copied when copying chat messages. (#4812)
- Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791)
- Dev: Temporarily disable High DPI scaling on Qt6 builds on Windows. (#4767)
Expand Down
5 changes: 2 additions & 3 deletions src/widgets/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,8 @@ void Window::addShortcuts()
return "";
}},
{"openQuickSwitcher",
[](std::vector<QString>) -> QString {
auto quickSwitcher =
new QuickSwitcherPopup(&getApp()->windows->getMainWindow());
[this](std::vector<QString>) -> QString {
pajlada marked this conversation as resolved.
Show resolved Hide resolved
auto *quickSwitcher = new QuickSwitcherPopup(this);
quickSwitcher->show();
return "";
}},
Expand Down
5 changes: 3 additions & 2 deletions src/widgets/dialogs/switcher/NewTabItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

namespace chatterino {

NewTabItem::NewTabItem(const QString &channelName)
NewTabItem::NewTabItem(Window *window_, const QString &channelName)
: AbstractSwitcherItem(QIcon(":/switcher/plus.svg"))
, channelName_(channelName)
, text_(QString(TEXT_FORMAT).arg(channelName))
, window(window_)
{
}

void NewTabItem::action()
{
auto &nb = getApp()->windows->getMainWindow().getNotebook();
auto &nb = this->window->getNotebook();
SplitContainer *container = nb.addPage(true);

Split *split = new Split(container);
Expand Down
5 changes: 4 additions & 1 deletion src/widgets/dialogs/switcher/NewTabItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace chatterino {

class Window;

class NewTabItem : public AbstractSwitcherItem
{
public:
Expand All @@ -13,7 +15,7 @@ class NewTabItem : public AbstractSwitcherItem
*
* @param channelName name of channel to open
*/
NewTabItem(const QString &channelName);
NewTabItem(Window *window_, const QString &channelName);

/**
* @brief Open the channel passed in the constructor in a new tab.
Expand All @@ -27,6 +29,7 @@ class NewTabItem : public AbstractSwitcherItem
static constexpr const char *TEXT_FORMAT = "Open channel \"%1\" in new tab";
QString channelName_;
QString text_;
Window *window{};
};

} // namespace chatterino
33 changes: 18 additions & 15 deletions src/widgets/dialogs/switcher/QuickSwitcherPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,33 @@
#include "widgets/splits/SplitContainer.hpp"
#include "widgets/Window.hpp"

namespace chatterino {

namespace {
QList<SplitContainer *> openPages()
{
QList<SplitContainer *> pages;

auto &nb = getApp()->windows->getMainWindow().getNotebook();
for (int i = 0; i < nb.getPageCount(); ++i)
{
pages.append(static_cast<SplitContainer *>(nb.getPageAt(i)));
}
using namespace chatterino;

QList<SplitContainer *> openPages(Window *window)
{
QList<SplitContainer *> pages;

return pages;
auto &nb = window->getNotebook();
for (int i = 0; i < nb.getPageCount(); ++i)
{
pages.append(static_cast<SplitContainer *>(nb.getPageAt(i)));
pajlada marked this conversation as resolved.
Show resolved Hide resolved
}

return pages;
}

} // namespace

const QSize QuickSwitcherPopup::MINIMUM_SIZE(500, 300);
namespace chatterino {

QuickSwitcherPopup::QuickSwitcherPopup(QWidget *parent)
QuickSwitcherPopup::QuickSwitcherPopup(Window *parent)
: BasePopup({BaseWindow::Flags::Frameless, BaseWindow::Flags::TopMost,
BaseWindow::DisableLayoutSave},
parent)
, switcherModel_(this)
, window(parent)
{
this->setWindowFlag(Qt::Dialog);
this->setActionOnFocusLoss(BaseWindow::ActionOnFocusLoss::Delete);
Expand Down Expand Up @@ -86,7 +89,7 @@ void QuickSwitcherPopup::updateSuggestions(const QString &text)
this->switcherModel_.clear();

// Add items for navigating to different splits
for (auto *sc : openPages())
for (auto *sc : openPages(this->window))
{
const QString &tabTitle = sc->getTab()->getTitle();
const auto splits = sc->getSplits();
Expand Down Expand Up @@ -119,7 +122,7 @@ void QuickSwitcherPopup::updateSuggestions(const QString &text)
// Add item for opening a channel in a new tab or new popup
if (!text.isEmpty())
{
auto newTabItem = std::make_unique<NewTabItem>(text);
auto newTabItem = std::make_unique<NewTabItem>(this->window, text);
this->switcherModel_.addItem(std::move(newTabItem));

auto newPopupItem = std::make_unique<NewPopupItem>(text);
Expand Down
13 changes: 8 additions & 5 deletions src/widgets/dialogs/switcher/QuickSwitcherPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@
namespace chatterino {

class GenericListView;
class Window;

class QuickSwitcherPopup : public BasePopup
{
public:
/**
* @brief Construct a new QuickSwitcherPopup.
*
* @param parent Parent widget of the popup. The popup will be placed
* in the center of the parent widget.
* @param parent Parent window of the popup. The popup will be placed
* in the center of the window.
*/
explicit QuickSwitcherPopup(QWidget *parent = nullptr);
explicit QuickSwitcherPopup(Window *parent);

protected:
virtual void themeChangedEvent() override;
void themeChangedEvent() override;

public slots:
void updateSuggestions(const QString &text);

private:
static const QSize MINIMUM_SIZE;
constexpr static const QSize MINIMUM_SIZE{500, 300};

struct {
QLineEdit *searchEdit{};
Expand All @@ -38,6 +39,8 @@ public slots:

QuickSwitcherModel switcherModel_;

Window *window{};

void initWidgets();
};

Expand Down