Skip to content

Commit

Permalink
Add CTRL+SHIFT+T and CTRL+SHIFT+W to Open and Close tabs
Browse files Browse the repository at this point in the history
Fixes #21
  • Loading branch information
pajlada committed Jan 6, 2018
1 parent 29046b3 commit 26170e4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/widgets/helper/shortcut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ inline void CreateShortcut(WidgetType *w, const char *key, Func func)
QObject::connect(s, &QShortcut::activated, w, func);
}

template <typename WidgetType, typename Func>
inline void CreateWindowShortcut(WidgetType *w, const char *key, Func func)
{
auto s = new QShortcut(QKeySequence(key), w);
s->setContext(Qt::WindowShortcut);
QObject::connect(s, &QShortcut::activated, w, func);
}

} // namespace widgets
} // namespace chatterino
9 changes: 9 additions & 0 deletions src/widgets/notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ void Notebook::removePage(SplitContainer *page)
this->performLayout();
}

void Notebook::removeCurrentPage()
{
if (this->selectedPage == nullptr) {
return;
}

this->removePage(this->selectedPage);
}

void Notebook::select(SplitContainer *page)
{
if (page == this->selectedPage) {
Expand Down
1 change: 1 addition & 0 deletions src/widgets/notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Notebook : public BaseWidget
SplitContainer *addPage(const std::string &uuid, bool select = false);

void removePage(SplitContainer *page);
void removeCurrentPage();
void select(SplitContainer *page);
void selectIndex(unsigned index);

Expand Down
26 changes: 16 additions & 10 deletions src/widgets/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,26 @@ Window::Window(const QString &windowName, singletons::ThemeManager &_themeManage

/// Initialize program-wide hotkeys
// CTRL+P: Open Settings Dialog
CreateShortcut(this, "CTRL+P", [] {
CreateWindowShortcut(this, "CTRL+P", [] {
SettingsDialog::showDialog(); //
});

// CTRL+Number: Switch to n'th tab
CreateShortcut(this, "CTRL+1", [this] { this->notebook.selectIndex(0); });
CreateShortcut(this, "CTRL+2", [this] { this->notebook.selectIndex(1); });
CreateShortcut(this, "CTRL+3", [this] { this->notebook.selectIndex(2); });
CreateShortcut(this, "CTRL+4", [this] { this->notebook.selectIndex(3); });
CreateShortcut(this, "CTRL+5", [this] { this->notebook.selectIndex(4); });
CreateShortcut(this, "CTRL+6", [this] { this->notebook.selectIndex(5); });
CreateShortcut(this, "CTRL+7", [this] { this->notebook.selectIndex(6); });
CreateShortcut(this, "CTRL+8", [this] { this->notebook.selectIndex(7); });
CreateShortcut(this, "CTRL+9", [this] { this->notebook.selectIndex(8); });
CreateWindowShortcut(this, "CTRL+1", [this] { this->notebook.selectIndex(0); });
CreateWindowShortcut(this, "CTRL+2", [this] { this->notebook.selectIndex(1); });
CreateWindowShortcut(this, "CTRL+3", [this] { this->notebook.selectIndex(2); });
CreateWindowShortcut(this, "CTRL+4", [this] { this->notebook.selectIndex(3); });
CreateWindowShortcut(this, "CTRL+5", [this] { this->notebook.selectIndex(4); });
CreateWindowShortcut(this, "CTRL+6", [this] { this->notebook.selectIndex(5); });
CreateWindowShortcut(this, "CTRL+7", [this] { this->notebook.selectIndex(6); });
CreateWindowShortcut(this, "CTRL+8", [this] { this->notebook.selectIndex(7); });
CreateWindowShortcut(this, "CTRL+9", [this] { this->notebook.selectIndex(8); });

// CTRL+SHIFT+T: New tab
CreateWindowShortcut(this, "CTRL+SHIFT+T", [this] { this->notebook.addNewPage(); });

// CTRL+SHIFT+W: Close current tab
CreateWindowShortcut(this, "CTRL+SHIFT+W", [this] { this->notebook.removeCurrentPage(); });
}

void Window::repaintVisibleChatWidgets(Channel *channel)
Expand Down

0 comments on commit 26170e4

Please sign in to comment.