Skip to content

Commit

Permalink
fix #12: allow pages/tabs to be switched with mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Dec 18, 2014
1 parent 5e2802f commit 1b78409
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
47 changes: 31 additions & 16 deletions src/main_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ namespace Astroid {
sigc::mem_fun (this, &MainWindow::on_my_focus_in_event));
signal_focus_out_event ().connect (
sigc::mem_fun (this, &MainWindow::on_my_focus_out_event));

/* change page */
notebook.signal_switch_page ().connect (
sigc::mem_fun (this, &MainWindow::on_my_switch_page));
}

void MainWindow::set_title (ustring t) {
Expand All @@ -77,7 +81,7 @@ namespace Astroid {
}

void MainWindow::enable_command (CommandBar::CommandMode m, ustring cmd, function<void(ustring)> f) {
unset_active ();
ungrab_active ();
command.enable_command (m, cmd, f);
is_command = true;
command.add_modal_grab ();
Expand Down Expand Up @@ -266,7 +270,7 @@ namespace Astroid {
}
}

void MainWindow::unset_active () {
void MainWindow::ungrab_active () {
if (current >= 0) {
if (notebook.get_n_pages() > current) {
//log << debug << "mw: release modal, from: " << current << endl;
Expand All @@ -276,6 +280,30 @@ namespace Astroid {
}
}

void MainWindow::on_my_switch_page (Gtk::Widget * w, guint no) {
grab_active (no);
}

void MainWindow::grab_active (int n) {
//log << debug << "mw: set active: " << n << ", current: " << current << endl;

ungrab_active ();

//log << debug << "mw: grab modal to: " << n << endl;

if (has_focus() || (get_focus() && get_focus()->has_focus())) {
/* we have focus */
((Mode*) notebook.get_nth_page (n))->grab_modal();
} else {
log << debug << "mw: does not have focus, will not grab modal." << endl;
}

current = n;
active = true;

set_title (((Mode*) notebook.get_nth_page(n))->get_label());
}

void MainWindow::set_active (int n) {
//log << debug << "mw: set active: " << n << ", current: " << current << endl;

Expand All @@ -285,21 +313,8 @@ namespace Astroid {
notebook.set_current_page (n);
}

unset_active ();

//log << debug << "mw: grab modal to: " << n << endl;

if (has_focus() || (get_focus() && get_focus()->has_focus())) {
/* we have focus */
((Mode*) notebook.get_nth_page (n))->grab_modal();
} else {
log << debug << "mw: does not have focus, will not grab modal." << endl;
}

current = n;
active = true;
grab_active (n);

set_title (((Mode*) notebook.get_nth_page(n))->get_label());
} else {
// log << debug << "mw: set active: page is out of range: " << n << endl;
set_title ("");
Expand Down
4 changes: 3 additions & 1 deletion src/main_window.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ namespace Astroid {
void remove_all_modes ();
void close_page ();

void unset_active ();
void ungrab_active ();
void grab_active (int);
void set_active (int);
void set_title (ustring);

Expand All @@ -56,6 +57,7 @@ namespace Astroid {
private:
bool on_my_focus_in_event (GdkEventFocus *);
bool on_my_focus_out_event (GdkEventFocus *);
void on_my_switch_page (Gtk::Widget *, guint);

static atomic<uint> nextid;
};
Expand Down

0 comments on commit 1b78409

Please sign in to comment.