Branch: refs/heads/master Author: Matthew Brush matt@geany.org Committer: Thomas Martitz kugel@rockbox.org Date: Sat, 24 May 2014 12:46:49 UTC Commit: 9f587e9c265893e9fa3081c2387a0246d3e3c9c9 https://github.com/geany/geany/commit/9f587e9c265893e9fa3081c2387a0246d3e3c9...
Log Message: ----------- Pack Scintilla widgets into a GtkVBox and use it as the notebook page.
This is to allow stacking widgets such as GtkInfoBar above the Scintilla widget in each tab.
notebook.c need to be changed because the document isn't the direct widget anymore which was assumed for tab closing.
Modified Paths: -------------- src/document.c src/notebook.c
Modified: src/document.c 51 lines changed, 44 insertions(+), 7 deletions(-) =================================================================== @@ -220,10 +220,36 @@ GeanyDocument *document_find_by_sci(ScintillaObject *sci) * @since 0.19 */ gint document_get_notebook_page(GeanyDocument *doc) { + GtkWidget *parent; + g_return_val_if_fail(doc != NULL, -1);
- return gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook), - GTK_WIDGET(doc->editor->sci)); + parent = gtk_widget_get_parent(GTK_WIDGET(doc->editor->sci)); + g_return_val_if_fail(GTK_IS_BOX(parent), -1); + + return gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook), parent); +} + + +static ScintillaObject *locate_sci_in_container(GtkWidget *container) +{ + ScintillaObject *sci = NULL; + GList *children, *iter; + + g_return_val_if_fail(GTK_IS_CONTAINER(container), NULL); + + children = gtk_container_get_children(GTK_CONTAINER(container)); + for (iter = children; iter != NULL; iter = g_list_next(iter)) + { + if (IS_SCINTILLA(iter->data)) + { + sci = SCINTILLA(iter->data); + break; + } + } + g_list_free(children); + + return sci; }
@@ -236,13 +262,17 @@ gint document_get_notebook_page(GeanyDocument *doc) **/ GeanyDocument *document_get_from_page(guint page_num) { + GtkWidget *parent; ScintillaObject *sci;
if (page_num >= documents_array->len) return NULL;
- sci = (ScintillaObject*)gtk_notebook_get_nth_page( - GTK_NOTEBOOK(main_widgets.notebook), page_num); + parent = gtk_notebook_get_nth_page(GTK_NOTEBOOK(main_widgets.notebook), page_num); + g_return_val_if_fail(GTK_IS_BOX(parent), NULL); + + sci = locate_sci_in_container(parent); + g_return_val_if_fail(IS_SCINTILLA(sci), NULL);
return document_find_by_sci(sci); } @@ -255,14 +285,21 @@ GeanyDocument *document_get_from_page(guint page_num) **/ GeanyDocument *document_get_current(void) { - gint cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook)); + gint cur_page; + GtkWidget *parent; + ScintillaObject *sci; + + cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
if (cur_page == -1) return NULL; else { - ScintillaObject *sci = (ScintillaObject*) - gtk_notebook_get_nth_page(GTK_NOTEBOOK(main_widgets.notebook), cur_page); + parent = gtk_notebook_get_nth_page(GTK_NOTEBOOK(main_widgets.notebook), cur_page); + g_return_val_if_fail(GTK_IS_BOX(parent), NULL); + + sci = locate_sci_in_container(parent); + g_return_val_if_fail(IS_SCINTILLA(sci), NULL);
return document_find_by_sci(sci); }
Modified: src/notebook.c 27 lines changed, 15 insertions(+), 12 deletions(-) =================================================================== @@ -608,6 +608,7 @@ static void tab_count_changed(void) static gboolean notebook_tab_click(GtkWidget *widget, GdkEventButton *event, gpointer data) { guint state; + GeanyDocument *doc = (GeanyDocument *) data;
/* toggle additional widgets on double click */ if (event->type == GDK_2BUTTON_PRESS) @@ -620,8 +621,7 @@ static gboolean notebook_tab_click(GtkWidget *widget, GdkEventButton *event, gpo /* close tab on middle click */ if (event->button == 2) { - document_remove_page(gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook), - GTK_WIDGET(data))); + document_close(doc); return TRUE; /* stop other handlers like notebook_tab_bar_click_cb() */ } /* switch last used tab on ctrl-click */ @@ -656,14 +656,18 @@ static void notebook_tab_close_button_style_set(GtkWidget *btn, GtkRcStyle *prev /* Returns page number of notebook page, or -1 on error */ gint notebook_new_tab(GeanyDocument *this) { - GtkWidget *hbox, *ebox; + GtkWidget *hbox, *ebox, *vbox; gint tabnum; GtkWidget *page; gint cur_page;
g_return_val_if_fail(this != NULL, -1);
+ /* page is packed into a vbox so we can stack infobars above it */ + vbox = gtk_vbox_new(FALSE, 0); page = GTK_WIDGET(this->editor->sci); + gtk_box_pack_start(GTK_BOX(vbox), page, TRUE, TRUE, 0); + gtk_widget_show(vbox);
this->priv->tab_label = gtk_label_new(NULL);
@@ -671,7 +675,7 @@ gint notebook_new_tab(GeanyDocument *this) * the close button, if any */ ebox = gtk_event_box_new(); gtk_widget_set_has_window(ebox, FALSE); - g_signal_connect(ebox, "button-press-event", G_CALLBACK(notebook_tab_click), page); + g_signal_connect(ebox, "button-press-event", G_CALLBACK(notebook_tab_click), this); /* focus the current document after clicking on a tab */ g_signal_connect_after(ebox, "button-release-event", G_CALLBACK(focus_sci), NULL); @@ -698,7 +702,7 @@ gint notebook_new_tab(GeanyDocument *this)
g_signal_connect(btn, "clicked", G_CALLBACK(notebook_tab_close_clicked_cb), page); /* button overrides event box, so make middle click on button also close tab */ - g_signal_connect(btn, "button-press-event", G_CALLBACK(notebook_tab_click), page); + g_signal_connect(btn, "button-press-event", G_CALLBACK(notebook_tab_click), this); /* handle style modification to keep button small as possible even when theme change */ g_signal_connect(btn, "style-set", G_CALLBACK(notebook_tab_close_button_style_set), NULL); } @@ -712,28 +716,27 @@ gint notebook_new_tab(GeanyDocument *this) else cur_page = file_prefs.tab_order_ltr ? -2 /* hack: -2 + 1 = -1, last page */ : 0; if (file_prefs.tab_order_ltr) - tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(main_widgets.notebook), page, + tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(main_widgets.notebook), vbox, ebox, NULL, cur_page + 1); else - tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(main_widgets.notebook), page, + tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(main_widgets.notebook), vbox, ebox, NULL, cur_page);
tab_count_changed();
/* enable tab DnD */ - gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(main_widgets.notebook), page, TRUE); + gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(main_widgets.notebook), vbox, TRUE);
return tabnum; }
static void -notebook_tab_close_clicked_cb(GtkButton *button, gpointer user_data) +notebook_tab_close_clicked_cb(GtkButton *button, gpointer data) { - gint cur_page = gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook), - GTK_WIDGET(user_data)); + GeanyDocument *doc = (GeanyDocument *) data;
- document_remove_page(cur_page); + document_close(doc); }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).