Skip to content

Commit

Permalink
Make notebook tabs scrollable
Browse files Browse the repository at this point in the history
  • Loading branch information
likorisd authored and raveit65 committed Mar 25, 2018
1 parent fb76daa commit 4212ffa
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
14 changes: 14 additions & 0 deletions pluma/pluma-notebook.c
Expand Up @@ -838,6 +838,16 @@ close_button_clicked_cb (PlumaTabLabel *tab_label, PlumaNotebook *notebook)
g_signal_emit (notebook, signals[TAB_CLOSE_REQUEST], 0, tab);
}

static gboolean
tab_label_scroll_cb (PlumaTabLabel *tab_label,
GdkEventScroll *event,
PlumaNotebook *notebook)
{
g_signal_emit_by_name (notebook, "scroll-event", &event);

return FALSE;
}

static GtkWidget *
create_tab_label (PlumaNotebook *nb,
PlumaTab *tab)
Expand All @@ -850,6 +860,10 @@ create_tab_label (PlumaNotebook *nb,
"close-clicked",
G_CALLBACK (close_button_clicked_cb),
nb);
g_signal_connect (tab_label,
"scroll-event",
G_CALLBACK (tab_label_scroll_cb),
nb);

g_object_set_data (G_OBJECT (tab), "tab-label", tab_label);

Expand Down
22 changes: 22 additions & 0 deletions pluma/pluma-tab-label.c
Expand Up @@ -114,6 +114,16 @@ close_button_clicked_cb (GtkWidget *widget,
g_signal_emit (tab_label, signals[CLOSE_CLICKED], 0, NULL);
}

static gboolean
scroll_event_cb(GtkWidget *widget,
GdkEventScroll *event,
PlumaTabLabel *tab_label)
{
g_signal_emit_by_name(tab_label, "scroll-event", &event);

return FALSE;
}

static void
sync_tip (PlumaTab *tab, PlumaTabLabel *tab_label)
{
Expand Down Expand Up @@ -265,6 +275,7 @@ pluma_tab_label_init (PlumaTabLabel *tab_label)
GTK_ORIENTATION_HORIZONTAL);

ebox = gtk_event_box_new ();
gtk_widget_add_events (ebox, GDK_SCROLL_MASK);
gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
gtk_box_pack_start (GTK_BOX (tab_label), ebox, TRUE, TRUE, 0);
tab_label->priv->ebox = ebox;
Expand All @@ -273,6 +284,7 @@ pluma_tab_label_init (PlumaTabLabel *tab_label)
gtk_container_add (GTK_CONTAINER (ebox), hbox);

close_button = pluma_close_button_new ();
gtk_widget_add_events (close_button, GDK_SCROLL_MASK);
gtk_widget_set_tooltip_text (close_button, _("Close document"));
gtk_box_pack_start (GTK_BOX (tab_label), close_button, FALSE, FALSE, 0);
tab_label->priv->close_button = close_button;
Expand All @@ -281,6 +293,16 @@ pluma_tab_label_init (PlumaTabLabel *tab_label)
"clicked",
G_CALLBACK (close_button_clicked_cb),
tab_label);

g_signal_connect (close_button,
"scroll-event",
G_CALLBACK (scroll_event_cb),
tab_label);

g_signal_connect (ebox,
"scroll-event",
G_CALLBACK (scroll_event_cb),
tab_label);

spinner = gtk_spinner_new ();
gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
Expand Down
25 changes: 24 additions & 1 deletion pluma/pluma-window.c
Expand Up @@ -36,6 +36,7 @@
#include <sys/types.h>
#include <string.h>

#include <gdk/gdk.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
Expand Down Expand Up @@ -3488,6 +3489,23 @@ notebook_button_press_event (GtkNotebook *notebook,
return FALSE;
}

static gboolean
notebook_scroll_event (GtkNotebook *notebook,
GdkEventScroll *event,
PlumaWindow *window)
{
if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_LEFT)
{
gtk_notebook_prev_page (notebook);
}
else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_RIGHT)
{
gtk_notebook_next_page (notebook);
}

return FALSE;
}

static gboolean
notebook_popup_menu (GtkNotebook *notebook,
PlumaWindow *window)
Expand Down Expand Up @@ -3854,6 +3872,10 @@ connect_notebook_signals (PlumaWindow *window,
"popup-menu",
G_CALLBACK (notebook_popup_menu),
window);
g_signal_connect (notebook,
"scroll-event",
G_CALLBACK (notebook_scroll_event),
window);
}

static void
Expand All @@ -3866,7 +3888,8 @@ add_notebook (PlumaWindow *window,
TRUE);

gtk_widget_show (notebook);


gtk_widget_add_events (notebook, GDK_SCROLL_MASK);
connect_notebook_signals (window, notebook);
}

Expand Down

0 comments on commit 4212ffa

Please sign in to comment.