/* Changes the menu label of child. Nothing happens if child is not in notebook. */ int clip_GTK_NOTEBOOKSETMENULABEL(ClipMachine * cm) { C_widget *cntb = _fetch_cw_arg(cm); C_widget *cchild = _fetch_cwidget(cm,_clip_spar(cm,2)); C_widget *clabel; CHECKCWID(cntb,GTK_IS_NOTEBOOK); CHECKARG2(2,MAP_t,NUMERIC_t); CHECKCWID(cchild,GTK_IS_WIDGET); CHECKARG3(3,MAP_t,NUMERIC_t,CHARACTER_t); if (_clip_parinfo(cm,3)==CHARACTER_t) { char * menu_text = _clip_parc(cm,3); LOCALE_TO_UTF(menu_text); gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(cntb->widget), cchild->widget, menu_text); FREE_TEXT(menu_text); } else { clabel = _fetch_cwidget(cm,_clip_spar(cm,3)); CHECKCWID(clabel,GTK_IS_WIDGET); if (clabel) gtk_notebook_set_menu_label(GTK_NOTEBOOK(cntb->widget), cchild->widget, clabel->widget); } return 0; err: return 1; }
/****************************************************************************** * Name * notebook_main_add_page * * Synopsis * #include "tabbed_browser.h" * * void notebook_main_add_page(PASSAGE_TAB_INFO *tbinf) * * Description * adds a new page and label to the main notebook for a new scripture passage * * Return value * void */ void notebook_main_add_page(PASSAGE_TAB_INFO *tbinf) { GtkWidget *tab_widget; GtkWidget *menu_label; GString *str; str = pick_tab_label(tbinf); UI_VBOX(tbinf->page_widget, FALSE, 0); if (tbinf->showparallel) widgets.parallel_tab = tbinf->page_widget; gtk_widget_show(tbinf->page_widget); tab_widget = tab_widget_new(tbinf, str->str); /*gtk_notebook_insert_page(GTK_NOTEBOOK(widgets.notebook_main), tbinf->page_widget, tab_widget, tbinf->showparallel ? 1 : -1); */ gtk_notebook_append_page(GTK_NOTEBOOK(widgets.notebook_main), tbinf->page_widget, tab_widget); gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(widgets.notebook_main), tbinf->page_widget, str->str); menu_label = gtk_label_new(str->str); gtk_notebook_set_menu_label(GTK_NOTEBOOK(widgets.notebook_main), tbinf->page_widget, menu_label); g_string_free(str, TRUE); }
static VALUE rg_set_menu_label_text(VALUE self, VALUE child, VALUE text) { gtk_notebook_set_menu_label_text(_SELF(self), RVAL2WIDGET(child), RVAL2CSTR(text)); return self; }
static int gtkTabsSetTabTitleAttrib(Ihandle* ih, int pos, const char* value) { if (value) { Ihandle* child = IupGetChild(ih, pos); GtkWidget* tab_label = (GtkWidget*)iupAttribGet(child, "_IUPGTK_TABLABEL"); if (tab_label) { GtkWidget* tab_page = (GtkWidget*)iupAttribGet(child, "_IUPTAB_PAGE"); iupgtkSetMnemonicTitle(ih, (GtkLabel*)tab_label, value); gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label)); } } return 1; }
static int gtkTabsSetTabTitleAttrib(Ihandle* ih, const char* name_id, const char* value) { int pos; if (value && iupStrToInt(name_id, &pos)==1) { Ihandle* child = IupGetChild(ih, pos); GtkWidget* tab_label = (GtkWidget*)iupAttribGet(child, "_IUPGTK_TABLABEL"); if (tab_label) { GtkWidget* tab_page = (GtkWidget*)iupAttribGet(child, "_IUPTAB_CONTAINER"); gtk_label_set_text((GtkLabel*)tab_label, iupgtkStrConvertToUTF8(value)); gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label)); } } return 1; }
void gui_set_named_tab_label(const gchar *key, PASSAGE_TAB_INFO *pt, gboolean update) { GString *str; if (stop_refresh) return; gui_reassign_strdup(&pt->text_commentary_key, (char *)key); str = pick_tab_label(pt); gtk_label_set_text(pt->tab_label, str->str); gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(widgets.notebook_main), pt->page_widget, str->str); if (update) main_add_tab_history_item((PASSAGE_TAB_INFO *)pt); g_string_free(str, TRUE); }
static void gtkTabsChildAddedMethod(Ihandle* ih, Ihandle* child) { if (IupGetName(child) == NULL) iupAttribSetHandleName(child); if (ih->handle) { GtkWidget* tab_page; GtkWidget *tab_label = NULL, *tab_image = NULL; char *tabtitle, *tabimage; int pos; unsigned char r, g, b; pos = IupGetChildPos(ih, child); tab_page = gtk_fixed_new(); gtk_widget_show(tab_page); tabtitle = iupAttribGet(child, "TABTITLE"); if (!tabtitle) tabtitle = iupTabsAttribGetStrId(ih, "TABTITLE", pos); tabimage = iupAttribGet(child, "TABIMAGE"); if (!tabimage) tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos); if (!tabtitle && !tabimage) tabtitle = " "; if (tabtitle) { tab_label = gtk_label_new(iupgtkStrConvertToUTF8(tabtitle)); #if GTK_CHECK_VERSION(2, 6, 0) if (ih->data->orientation == ITABS_VERTICAL) gtk_label_set_angle((GtkLabel*)tab_label, 90); #endif } if (tabimage) { GdkPixbuf* pixbuf = iupImageGetImage(tabimage, ih, 0, "TABIMAGE"); tab_image = gtk_image_new(); if (pixbuf) gtk_image_set_from_pixbuf((GtkImage*)tab_image, pixbuf); } iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", "1"); if (tabimage && tabtitle) { GtkWidget* box; if (ih->data->orientation == ITABS_VERTICAL) box = gtk_vbox_new(FALSE, 2); else box = gtk_hbox_new(FALSE, 2); gtk_widget_show(box); gtk_container_add((GtkContainer*)box, tab_image); gtk_container_add((GtkContainer*)box, tab_label); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, box, pos); gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label)); } else if (tabimage) gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_image, pos); else gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_label, pos); gtk_widget_realize(tab_page); iupAttribSetStr(child, "_IUPGTK_TABIMAGE", (char*)tab_image); /* store it even if its NULL */ iupAttribSetStr(child, "_IUPGTK_TABLABEL", (char*)tab_label); iupAttribSetStr(child, "_IUPTAB_CONTAINER", (char*)tab_page); iupStrToRGB(IupGetAttribute(ih, "BGCOLOR"), &r, &g, &b); iupgtkBaseSetBgColor(tab_page, r, g, b); if (tabtitle) { PangoFontDescription* fontdesc = (PangoFontDescription*)iupgtkGetPangoFontDescAttrib(ih); gtk_widget_modify_font(tab_label, fontdesc); iupgtkFontUpdatePangoLayout(ih, gtk_label_get_layout((GtkLabel*)tab_label)); iupgtkBaseSetBgColor(tab_label, r, g, b); iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b); iupgtkBaseSetFgColor(tab_label, r, g, b); gtk_widget_show(tab_label); gtk_widget_realize(tab_label); } if (tabimage) { gtk_widget_show(tab_image); gtk_widget_realize(tab_image); } iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", NULL); } }
/* ------------------------------------------------------------------------- */ static void gtkTabsChildAddedMethod(Ihandle* ih, Ihandle* child) { /* make sure it has at least one name */ if (!iupAttribGetHandleName(child)) iupAttribSetHandleName(child); if (ih->handle) { GtkWidget *evtBox, *tab_page, *tab_container, *box = NULL; GtkWidget *tab_label = NULL, *tab_image = NULL, *tab_close = NULL; char *tabtitle, *tabimage; int pos; unsigned char r, g, b; pos = IupGetChildPos(ih, child); /* Can not hide the tab_page, or the tab will be automatically hidden. So create a secondary container to hide its child instead. */ #if GTK_CHECK_VERSION(3, 0, 0) tab_page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); #else tab_page = gtk_vbox_new(FALSE, 0); #endif gtk_widget_show(tab_page); tab_container = gtk_fixed_new(); /* can not use iupgtkNativeContainerNew in GTK3 */ gtk_widget_show(tab_container); gtk_container_add((GtkContainer*)tab_page, tab_container); tabtitle = iupAttribGet(child, "TABTITLE"); if (!tabtitle) { tabtitle = iupAttribGetId(ih, "TABTITLE", pos); if (tabtitle) iupAttribSetStr(child, "TABTITLE", tabtitle); } tabimage = iupAttribGet(child, "TABIMAGE"); if (!tabimage) { tabimage = iupAttribGetId(ih, "TABIMAGE", pos); if (tabimage) iupAttribSetStr(child, "TABIMAGE", tabimage); } if (!tabtitle && !tabimage) tabtitle = " "; if (tabtitle) { tab_label = gtk_label_new(NULL); iupgtkSetMnemonicTitle(ih, (GtkLabel*)tab_label, tabtitle); #if GTK_CHECK_VERSION(2, 6, 0) if (ih->data->orientation == ITABS_VERTICAL) gtk_label_set_angle((GtkLabel*)tab_label, 90); #endif } if (tabimage) { GdkPixbuf* pixbuf = iupImageGetImage(tabimage, ih, 0); tab_image = gtk_image_new(); if (pixbuf) gtk_image_set_from_pixbuf((GtkImage*)tab_image, pixbuf); } if(ih->data->show_close) { #if GTK_CHECK_VERSION(3, 10, 0) GtkWidget* image = gtk_image_new_from_icon_name("window-close", GTK_ICON_SIZE_MENU); #else GtkWidget* image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); #endif tab_close = gtk_button_new(); gtk_button_set_image((GtkButton*)tab_close, image); gtk_button_set_relief((GtkButton*)tab_close, GTK_RELIEF_NONE); gtk_button_set_focus_on_click((GtkButton*)tab_close, FALSE); iupgtkSetCanFocus(tab_close, FALSE); g_signal_connect(G_OBJECT(tab_close), "clicked", G_CALLBACK(gtkTabsCloseButtonClicked), child); } iupAttribSet(ih, "_IUPGTK_IGNORE_CHANGE", "1"); if ((tabimage && tabtitle) || ih->data->show_close) { #if GTK_CHECK_VERSION(3, 0, 0) if (ih->data->orientation == ITABS_VERTICAL) box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); else box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2); #else if (ih->data->orientation == ITABS_VERTICAL) box = gtk_vbox_new(FALSE, 2); else box = gtk_hbox_new(FALSE, 2); #endif gtk_widget_show(box); } /* RIGHTCLICK_CB will not work without the eventbox */ evtBox = gtk_event_box_new(); gtk_widget_add_events(evtBox, GDK_BUTTON_PRESS_MASK); g_signal_connect(G_OBJECT(evtBox), "button-press-event", G_CALLBACK(gtkTabsButtonPressEvent), child); if (tabimage && tabtitle) { gtk_container_add((GtkContainer*)box, tab_image); gtk_container_add((GtkContainer*)box, tab_label); if(ih->data->show_close) gtk_container_add((GtkContainer*)box, tab_close); gtk_container_add((GtkContainer*)evtBox, box); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos); gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label)); } else if(tabimage && ih->data->show_close) { gtk_container_add((GtkContainer*)box, tab_image); gtk_container_add((GtkContainer*)box, tab_close); gtk_container_add((GtkContainer*)evtBox, box); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos); } else if(tabtitle && ih->data->show_close) { gtk_container_add((GtkContainer*)box, tab_label); gtk_container_add((GtkContainer*)box, tab_close); gtk_container_add((GtkContainer*)evtBox, box); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos); gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label)); } else if (tabimage) { gtk_container_add((GtkContainer*)evtBox, tab_image); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos); } else { gtk_container_add((GtkContainer*)evtBox, tab_label); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, evtBox, pos); } gtk_widget_realize(tab_page); iupAttribSet(child, "_IUPGTK_TABCLOSE", (char*)tab_close); iupAttribSet(child, "_IUPGTK_TABIMAGE", (char*)tab_image); /* store it even if its NULL */ iupAttribSet(child, "_IUPGTK_TABLABEL", (char*)tab_label); iupAttribSet(child, "_IUPTAB_CONTAINER", (char*)tab_container); iupAttribSet(child, "_IUPTAB_PAGE", (char*)tab_page); iupStrToRGB(IupGetAttribute(ih, "BGCOLOR"), &r, &g, &b); iupgtkSetBgColor(tab_container, r, g, b); if (tabtitle) { iupgtkUpdateWidgetFont(ih, tab_label); iupgtkSetBgColor(tab_label, r, g, b); iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b); iupgtkSetFgColor(tab_label, r, g, b); gtk_widget_show(tab_label); gtk_widget_realize(tab_label); } if (tabimage) { gtk_widget_show(tab_image); gtk_widget_realize(tab_image); } if (ih->data->show_close) { gtk_widget_show(tab_close); gtk_widget_realize(tab_close); } iupAttribSet(ih, "_IUPGTK_IGNORE_CHANGE", NULL); if (pos != iupdrvTabsGetCurrentTab(ih)) gtk_widget_hide(tab_container); } }
void save_file(GtkButton *button) { /** Save editor content as the stored filename. **/ #ifdef DEBUG DEBUG_FUNC_MARK #endif /** Retrieve the stored filepath: **/ gpointer filepath = g_object_get_data(G_OBJECT(current_editor.current_buffer), "filepath") ; char *cmp_filepath = g_strdup_printf("%s/New", (char *) g_get_home_dir()) ; if ( g_strcmp0(filepath,cmp_filepath) == 0) { /** File is the start file **/ free(cmp_filepath) ; save_as_file(NULL) ; return ; } free(cmp_filepath) ; /** Getting current editor content **/ GtkTextIter iter_start, iter_end ; GError *error=NULL ; gtk_text_buffer_get_start_iter(current_editor.current_buffer,&iter_start); gtk_text_buffer_get_end_iter(current_editor.current_buffer,&iter_end); gchar *file_content = gtk_text_buffer_get_text(current_editor.current_buffer, &iter_start, &iter_end, FALSE); char *back_up_filepath = NULL ; if (settings.backup_file) { /** backup creation by renaming the ancient (last saved) file (content) by adding an '~' the backup files suffix. **/ back_up_filepath = g_strdup_printf("%s~",(char *) filepath) ; rename(filepath,back_up_filepath) ; } if ( ! g_file_set_contents(filepath, file_content, -1, &error) ) { /** Failed to save editor content as file, display an error message and return. **/ rename(back_up_filepath, filepath) ; /** We must reset the renaming because else we lost the correct filename in this error case. **/ free(back_up_filepath) ; char *msg = g_strdup_printf(_("Failed to save file:\n%s"), (char *) filepath) ; display_message_dialog(_("Cannot save file !!!"), msg, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE) ; free(msg) ; return ; } free(back_up_filepath) ; /** Update the notebook label tab **/ GtkWidget *notebook_tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui->editor_notebook), current_editor.current_notebook_page); /** The tab contains an mimetype icon, the filename and the page closing button. **/ GList *tab_compound_list = gtk_container_get_children(GTK_CONTAINER(notebook_tab)) ; tab_compound_list = g_list_first(tab_compound_list) ; while (tab_compound_list->data != NULL) { /** We iterate over the notebook tab component to find the filename label.**/ if (g_object_get_data(G_OBJECT(tab_compound_list->data), "tab_filename_widget")) { /** We reset the filename without the asterix ('*'). **/ gtk_label_set_text(GTK_LABEL(tab_compound_list->data), g_path_get_basename(filepath)) ; break ; } tab_compound_list = tab_compound_list->next ; } /** We mark the TextBuffer as not modified since last saving operation. **/ gtk_text_buffer_set_modified(current_editor.current_buffer, FALSE) ; /** setting the base filename in the bottom bar. **/ gtk_label_set_text(GTK_LABEL(gui->bottom_bar->filename_label), g_path_get_basename(filepath)) ; File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ; gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(gui->editor_notebook), file_editor->scrolled_window, g_path_get_basename(filepath) ) ; g_free(file_content) ; if (settings.rm_trailing_spaces) { /** Deleting trailing spaces. **/ char *trailing_spaces_deleting ; trailing_spaces_deleting = g_strdup_printf("sed -i 's/[[:space:]]$//' '%s'", (char *) filepath) ; int ret ; if ((ret = system(trailing_spaces_deleting)) == -1) { g_warning( _("Removing trailing space failure:\n%s\n"), trailing_spaces_deleting) ; } free(trailing_spaces_deleting) ; } #ifdef RELOADING_FUNC /** Update Last modification timestamp. **/ File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ; g_stat(filepath, &file_editor->file_info) ; #endif return ; }
void save_as_file(GtkButton *button) { /** Save the current editor content as the choosen file. **/ #ifdef DEBUG DEBUG_FUNC_MARK #endif GtkWidget *file_chooser = gtk_file_chooser_dialog_new( _("Save as file"), GTK_WINDOW(gui->main_window), GTK_FILE_CHOOSER_ACTION_SAVE, _("Cancel"), GTK_RESPONSE_CANCEL, _("Save as"), GTK_RESPONSE_ACCEPT, NULL) ; /** Retrieve the stored filepath: **/ gpointer stored_filepath = g_object_get_data(G_OBJECT(current_editor.current_buffer), "filepath") ; /** Storing last opened file folder. **/ if (open_file_dirname != NULL) { g_free(open_file_dirname) ; } open_file_dirname = g_strdup(g_path_get_dirname(stored_filepath)) ; gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_chooser), open_file_dirname ); gint res; GtkFileChooser *chooser; chooser = GTK_FILE_CHOOSER(file_chooser); gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE); res = gtk_dialog_run(GTK_DIALOG(file_chooser)) ; if (res == GTK_RESPONSE_ACCEPT) { char *filepath ; filepath = gtk_file_chooser_get_filename(chooser); /** Getting current editor content **/ GtkTextIter iter_start, iter_end ; GError *error = NULL ; gtk_text_buffer_get_start_iter(current_editor.current_buffer, &iter_start); gtk_text_buffer_get_end_iter(current_editor.current_buffer, &iter_end); gchar *file_content = gtk_text_buffer_get_text(current_editor.current_buffer, &iter_start, &iter_end, FALSE) ; if (! g_file_set_contents(filepath, file_content, -1, &error) ) { /** Failed to save editor content as file, display an error message and return. **/ char *msg = g_strdup_printf(_("Failed to save file:\n%s"), filepath) ; display_message_dialog(_("Cannot save file !!!"), msg, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE) ; free(msg) ; return ; } /** Mark the TextBuffer as not modfied. **/ gtk_text_buffer_set_modified(current_editor.current_buffer, FALSE) ; /** Only useful if the content type has changed like a new file saved as a *.c file. **/ GtkSourceLanguage *source_language = NULL ; GtkSourceLanguageManager *source_language_manager = gtk_source_language_manager_get_default(); gboolean result_uncertain ; gchar *content_type ; content_type = g_content_type_guess( g_path_get_basename(filepath), (const guchar *) file_content, strlen(file_content), &result_uncertain) ; if (content_type && source_language_manager) { source_language = gtk_source_language_manager_guess_language(source_language_manager, g_path_get_basename(filepath), content_type); if (source_language) { set_syntax_highlight_radio(gtk_source_language_get_id(source_language)) ; gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(current_editor.current_buffer), source_language) ; g_object_set_data(G_OBJECT(current_editor.current_textview), "lang_id", (char *) gtk_source_language_get_id(source_language)) ; } g_free(content_type) ; } /** Update the notebook label tab **/ GtkWidget *notebook_tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui->editor_notebook), current_editor.current_notebook_page); /** The tab contains an mimetype icon, the filename and the page closing button. **/ GList *tab_compound_list = gtk_container_get_children(GTK_CONTAINER(notebook_tab)) ; tab_compound_list = g_list_first(tab_compound_list) ; while (tab_compound_list->data != NULL) { /** We iterate over the notebook tab component **/ if (g_object_get_data(G_OBJECT(tab_compound_list->data), "tab_filename_widget")) { /** Set the new filename in the tab. **/ gtk_label_set_text(GTK_LABEL(tab_compound_list->data), g_path_get_basename(filepath)) ; } if (g_object_get_data(G_OBJECT(tab_compound_list->data), "tab_icon") && source_language) { uint8_t c ; for ( c=0 ; ; c++) { if (gtk_source_language_get_mime_types(source_language) == NULL) { break ; } char *mimetype = gtk_source_language_get_mime_types(source_language)[c] ; if (mimetype == NULL) { /** don't find an specific mimetype for this new file extension use default icon. **/ g_object_set(G_OBJECT(tab_compound_list->data),"file", PATH_TO_MIMETYPE_ICON "unknown.png", NULL) ; break ; } /** We search for an image filename ending with the corresponding mimetype: **/ char *ptr = strchr(mimetype, '/') ; if (ptr != NULL) { /** Simply pointer arithmetic to exchange the '/' (used in mimetypes) and the '-' (used in the images names) character **/ mimetype[ptr - mimetype] = '-' ; gchar *filepath = g_strdup_printf("%s%s.png", PATH_TO_MIMETYPE_ICON, mimetype) ; if ( g_file_test(filepath, G_FILE_TEST_EXISTS) ) { /** We found an corresponding image for this mimetype. **/ g_object_set(G_OBJECT(tab_compound_list->data),"file", filepath, NULL) ; free(filepath) ; break ; } free(filepath) ; } } } if (tab_compound_list->next == NULL) { break ; } tab_compound_list = tab_compound_list->next ; } g_free(file_content) ; /** Storing filepath for further saving operations. **/ g_object_set_data(G_OBJECT(current_editor.current_buffer), "filepath", filepath) ; /** setting the base filename in the bottom bar. **/ gtk_label_set_text(GTK_LABEL(gui->bottom_bar->filename_label), g_path_get_basename(filepath)) ; if (settings.rm_trailing_spaces) { /** Deleting trailing spaces. **/ char *trailing_spaces_deleting ; trailing_spaces_deleting = g_strdup_printf("sed -i 's/[[:space:]]$//' '%s'", (char *) filepath) ; int ret ; if ((ret = system(trailing_spaces_deleting)) == -1) { g_warning( _("Removing trailing space failure:\n%s\n"), trailing_spaces_deleting) ; } free(trailing_spaces_deleting) ; } File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ; gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(gui->editor_notebook), file_editor->scrolled_window, g_path_get_basename(filepath) ) ; #ifdef RELOADING_FUNC /** Update Last modification timestamp. **/ File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ; g_stat(filepath, &file_editor->file_info) ; #endif } /** @NOTE: the filepath must not be free because it is set as data from the file_editor->buffer for further use. **/ gtk_widget_destroy(file_chooser); }
static void gtkTabsChildAddedMethod(Ihandle* ih, Ihandle* child) { if (IupGetName(child) == NULL) iupAttribSetHandleName(child); if (ih->handle) { GtkWidget *tab_page, *tab_container; GtkWidget *tab_label = NULL, *tab_image = NULL; char *tabtitle, *tabimage; int pos; unsigned char r, g, b; pos = IupGetChildPos(ih, child); /* Can not hide the tab_page, or the tab will be automatically hidden. So create a secondary container to hide its child instead. */ #if GTK_CHECK_VERSION(3, 0, 0) tab_page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); #else tab_page = gtk_vbox_new(FALSE, 0); #endif gtk_widget_show(tab_page); tab_container = gtk_fixed_new(); /* can not use iupgtkNativeContainerNew in GTK3 */ gtk_widget_show(tab_container); gtk_container_add((GtkContainer*)tab_page, tab_container); tabtitle = iupTabsAttribGetStrId(ih, "TABTITLE", pos); if (!tabtitle) { tabtitle = iupAttribGet(child, "TABTITLE"); if (tabtitle) iupTabsAttribSetStrId(ih, "TABTITLE", pos, tabtitle); } tabimage = iupTabsAttribGetStrId(ih, "TABIMAGE", pos); if (!tabimage) { tabimage = iupAttribGet(child, "TABIMAGE"); if (tabimage) iupTabsAttribSetStrId(ih, "TABIMAGE", pos, tabimage); } if (!tabtitle && !tabimage) tabtitle = " "; if (tabtitle) { tab_label = gtk_label_new(NULL); iupgtkSetMnemonicTitle(ih, (GtkLabel*)tab_label, tabtitle); #if GTK_CHECK_VERSION(2, 6, 0) if (ih->data->orientation == ITABS_VERTICAL) gtk_label_set_angle((GtkLabel*)tab_label, 90); #endif } if (tabimage) { GdkPixbuf* pixbuf = iupImageGetImage(tabimage, ih, 0); tab_image = gtk_image_new(); if (pixbuf) gtk_image_set_from_pixbuf((GtkImage*)tab_image, pixbuf); } iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", "1"); if (tabimage && tabtitle) { GtkWidget* box; #if GTK_CHECK_VERSION(3, 0, 0) if (ih->data->orientation == ITABS_VERTICAL) box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); else box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2); #else if (ih->data->orientation == ITABS_VERTICAL) box = gtk_vbox_new(FALSE, 2); else box = gtk_hbox_new(FALSE, 2); #endif gtk_widget_show(box); gtk_container_add((GtkContainer*)box, tab_image); gtk_container_add((GtkContainer*)box, tab_label); gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, box, pos); gtk_notebook_set_menu_label_text((GtkNotebook*)ih->handle, tab_page, gtk_label_get_text((GtkLabel*)tab_label)); } else if (tabimage) gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_image, pos); else gtk_notebook_insert_page((GtkNotebook*)ih->handle, tab_page, tab_label, pos); gtk_widget_realize(tab_page); iupAttribSetStr(child, "_IUPGTK_TABIMAGE", (char*)tab_image); /* store it even if its NULL */ iupAttribSetStr(child, "_IUPGTK_TABLABEL", (char*)tab_label); iupAttribSetStr(child, "_IUPTAB_CONTAINER", (char*)tab_container); iupAttribSetStr(child, "_IUPTAB_PAGE", (char*)tab_page); iupStrToRGB(IupGetAttribute(ih, "BGCOLOR"), &r, &g, &b); iupgtkSetBgColor(tab_container, r, g, b); if (tabtitle) { PangoFontDescription* fontdesc = (PangoFontDescription*)iupgtkGetPangoFontDescAttrib(ih); #if GTK_CHECK_VERSION(3, 0, 0) gtk_widget_override_font(tab_label, fontdesc); #else gtk_widget_modify_font(tab_label, fontdesc); #endif iupgtkFontUpdatePangoLayout(ih, gtk_label_get_layout((GtkLabel*)tab_label)); iupgtkSetBgColor(tab_label, r, g, b); iupStrToRGB(IupGetAttribute(ih, "FGCOLOR"), &r, &g, &b); iupgtkSetFgColor(tab_label, r, g, b); gtk_widget_show(tab_label); gtk_widget_realize(tab_label); } if (tabimage) { gtk_widget_show(tab_image); gtk_widget_realize(tab_image); } iupAttribSetStr(ih, "_IUPGTK_IGNORE_CHANGE", NULL); if (pos != iupdrvTabsGetCurrentTab(ih)) gtk_widget_hide(tab_container); } }
void set_label (GtkNotebook *Notebook, gint CurrentPage) { gchar BaseTitle[MAX_TAB_LABEL_LENGTH]; gint i = 0, j = 0; while (FPROPS(CurrentPage, BaseName[i]) != '\0') { if (i < MAX_TAB_LABEL_LENGTH) BaseTitle[j++] = FPROPS(CurrentPage, BaseName[i++]); else { for (i = -3; i <= -1; i++) BaseTitle[i+j] = '.'; break; } } BaseTitle[j] = '\0'; if (FPROPS(CurrentPage, Changed[0])) { if (!FPROPS(CurrentPage, ReadOnly)) { gchar *Title; Title = g_strconcat ("*", BaseTitle, NULL); gtk_notebook_set_tab_label_text (Notebook, gtk_notebook_get_nth_page (Notebook, CurrentPage), Title); gtk_notebook_set_menu_label_text (Notebook, gtk_notebook_get_nth_page (Notebook, CurrentPage), Title); g_free (Title); } else { gchar *Title; Title = g_strconcat ("RO *", BaseTitle, NULL); gtk_notebook_set_tab_label_text (Notebook, gtk_notebook_get_nth_page (Notebook, CurrentPage), Title); gtk_notebook_set_menu_label_text (Notebook, gtk_notebook_get_nth_page (Notebook, CurrentPage), Title); g_free (Title); } } else { if (FPROPS(CurrentPage, ReadOnly)) { gchar *Title; Title = g_strconcat ("RO ", BaseTitle, NULL); gtk_notebook_set_tab_label_text (Notebook, gtk_notebook_get_nth_page (Notebook, CurrentPage), Title); gtk_notebook_set_menu_label_text (Notebook, gtk_notebook_get_nth_page (Notebook, CurrentPage), Title); g_free (Title); } else { gtk_notebook_set_tab_label_text (Notebook, gtk_notebook_get_nth_page (Notebook, CurrentPage), BaseTitle); gtk_notebook_set_menu_label_text (Notebook, gtk_notebook_get_nth_page (Notebook, CurrentPage), BaseTitle); } } }