Skip to content

Commit

Permalink
Handle shift and (fixed) ctrl click on tab close buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
realh committed Jun 22, 2017
1 parent e1d116d commit b1f6eb1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ to draw the tabline in text. This is enabled with the `gui-tabs` gsetting.

#### Tab shortcuts

Right-click or ctrl-click a tab close icon to close all other tabs. More useful
shortcuts will be added in the future.
* Right-click or ctrl-click a tab close icon to close all other tabs.

* Shift-click to force close tabs with unsaved buffers.

More useful shortcuts will be added in the future.

#### Tab caveats

Expand Down
20 changes: 15 additions & 5 deletions src/tab-page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,36 @@ TabPage::TabPage(Gtk::Notebook *notebook,
box_.pack_end(close_button_, false, false);
}

// "clicked" signal is much easier than working out whether a press/release
// is a click, but it only works for button 1 and we need to get the modifiers
// from the source event
void TabPage::on_close_button_clicked()
{
send_tab_command("tabclose");
auto event = gtk_get_current_event();
bool force = event && (event->button.state && Gdk::SHIFT_MASK);
auto cmd = (event && (event->button.state && Gdk::CONTROL_MASK))
? "tabonly" : "tabclose";
send_tab_command(cmd, force);
}

bool TabPage::on_close_button_pressed(GdkEventButton *event)
{
if (event->button == 3 || (event->button == 1 &&
(event->state & Gdk::CONTROL_MASK)))
bool force = event->state & Gdk::SHIFT_MASK;
if (event->button == 3)
{
send_tab_command("tabonly");
send_tab_command("tabonly", force);
return true;
}
return false;
}

void TabPage::send_tab_command(const char *cmd)
void TabPage::send_tab_command(const char *cmd, bool force)
{
std::ostringstream s;
// This assumes GUI tab order is in sync with nvim, which is reasonably safe
s << (notebook_->child_property_position(*this).get_value() + 1) << cmd;
if (force)
s << '!';
get_nvim_bridge()->nvim_command(s.str());
}

Expand Down
2 changes: 1 addition & 1 deletion src/tab-page.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TabPage : public NvimGridWidget {

bool on_close_button_pressed(GdkEventButton *);

void send_tab_command(const char *cmd);
void send_tab_command(const char *cmd, bool force = false);

Gtk::Notebook *notebook_;
Gtk::Box box_;
Expand Down

0 comments on commit b1f6eb1

Please sign in to comment.