/** * @file gui-tabmanager.c * @brief * * Copyright (C) 2010-2011 Gummi-Dev Team * All Rights reserved. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ #include "gui-tabmanager.h" #include "gui-main.h" #include "environment.h" extern Gummi* gummi; extern GummiGui* gui; GuTabmanagerGui* tabmanagergui_init (GtkBuilder* builder) { g_return_val_if_fail (GTK_IS_BUILDER (builder), NULL); GuTabmanagerGui* tm = g_new0 (GuTabmanagerGui, 1); tm->notebook = GTK_NOTEBOOK (gtk_builder_get_object (builder, "tab_notebook")); g_object_set (tm->notebook, "tab-border", 0, NULL); tm->unsavednr = 0; return tm; } int tabmanagergui_create_page (GuTabContext* tc, GuEditor* editor) { GuTabPage* tp = g_new0(GuTabPage, 1); tc->page = tp; int pos; tp->scroll = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(tp->scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gchar* labeltext = tabmanager_get_tabname (tc); tabmanagergui_create_label (tp, labeltext); g_signal_connect (tp->button, "clicked", G_CALLBACK (on_menu_close_activate), tc); gtk_container_add (GTK_CONTAINER (tp->scroll), GTK_WIDGET (editor->view)); pos = gtk_notebook_append_page (GTK_NOTEBOOK (g_tabnotebook), tp->scroll, GTK_WIDGET (tp->labelbox)); gtk_widget_show (tp->scroll); gtk_widget_show (GTK_WIDGET(editor->view)); return pos; } void tabmanagergui_create_label (GuTabPage* tp, gchar* labeltext) { static unsigned count = 0; GtkRcStyle* rcstyle = NULL; GtkWidget* image = NULL; GtkHBox* hbox; tp->labelbox = gtk_event_box_new (); hbox = GTK_HBOX (gtk_hbox_new (FALSE, 0)); tp->unsavednr = ++count; gtk_event_box_set_visible_window (GTK_EVENT_BOX (tp->labelbox), FALSE); gtk_container_add (GTK_CONTAINER(tp->labelbox), GTK_WIDGET (hbox)); tp->label = GTK_LABEL (gtk_label_new (labeltext)); gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (tp->label), TRUE, TRUE, 5); tp->button = GTK_BUTTON (gtk_button_new()); image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); gtk_button_set_image (tp->button, image); g_object_set (tp->button, "relief", GTK_RELIEF_NONE, "focus-on-click", FALSE, NULL); gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (tp->button), FALSE,FALSE,0); rcstyle = gtk_rc_style_new (); rcstyle->xthickness = rcstyle->ythickness = 0; gtk_widget_modify_style (GTK_WIDGET (tp->button), rcstyle); g_object_unref (rcstyle); gtk_widget_show_all (GTK_WIDGET (hbox)); } gchar* tabmanagergui_get_labeltext (GuTabPage* tp) { const gchar* text = gtk_label_get_text (GTK_LABEL(tp->label)); return (gchar*)text; } gint tabmanagergui_replace_page (GuTabContext* tc, GuEditor* newec) { gummi->tabmanager->active_tab->editor = newec; editor_destroy (g_active_editor); gtk_container_remove (GTK_CONTAINER (tc->page->scroll), GTK_WIDGET (gummi->tabmanager->active_editor->view)); gtk_container_add (GTK_CONTAINER (tc->page->scroll), GTK_WIDGET (newec->view)); gtk_widget_show (GTK_WIDGET(newec->view)); int pos = gtk_notebook_page_num (g_tabnotebook, gummi->tabmanager->active_tab->page->scroll); return pos; } void tabmanagergui_set_current_page (gint position) { gtk_notebook_set_current_page (g_tabnotebook, position); } gint tabmanagergui_get_current_page (void) { return gtk_notebook_get_current_page (g_tabnotebook); } gint tabmanagergui_get_n_pages (void) { return gtk_notebook_get_n_pages (g_tabnotebook); } void tabmanagergui_update_label (GuTabPage* tp, const gchar* text) { g_return_if_fail (tp != NULL); gtk_label_set_text (tp->label, text); if (tp->bold) tablabel_set_bold_text (tp); } void tablabel_set_bold_text (GuTabPage* tp) { gchar* markup; const gchar* cur = gtk_label_get_text (tp->label); markup = g_markup_printf_escaped ("%s", cur); gtk_label_set_markup (GTK_LABEL (tp->label), markup); g_free (markup); if (!tp->bold) tp->bold = TRUE; }