/* Called when the user clicks the 'New' menu. We need to prompt for save if the file has been modified, and then delete the buffer and clear the modified flag. */ void on_new_menu_item_activate (GtkMenuItem *menuitem, TutorialTextEditor *editor) { GtkTextBuffer *buffer; if (check_for_save (editor) == TRUE) { on_save_menu_item_activate (NULL, editor); } /* clear editor for a new file */ editor->filename = NULL; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->text_view)); gtk_text_buffer_set_text (buffer, "", -1); gtk_text_buffer_set_modified (buffer, FALSE); reset_default_status (editor); }
void iofunctions_save_file (GuIOFunc* io, gchar* filename, gchar *text) { gchar* status = NULL; status = g_strdup_printf (_("Saving %s..."), filename); statusbar_set_message (status); g_free (status); GObject *savecontext = g_object_new(G_TYPE_OBJECT, NULL); g_object_set_data (savecontext, "filename", filename); g_object_set_data (savecontext, "text", text); g_signal_emit_by_name (io->sig_hook, "document-write", savecontext); gtk_text_buffer_set_modified (GTK_TEXT_BUFFER(gummi_get_active_editor()->buffer), FALSE); }
/** runs once per page */ static void set_text (Ebook * ebook, gchar * text, gboolean lines_state, gboolean page_state, gboolean hyphens_state) { GtkTextView * textview; GtkTextBuffer * buffer; GtkTextIter start, end; gssize size, old; GError * err; err = NULL; if (lines_state) text = g_regex_replace (ebook->line, text, -1, 0, " \\1",0 , &err); if (err) g_warning ("line replace: %s", err->message); if (page_state) text = g_regex_replace_literal (ebook->page, text, -1, 0, " ",0 , &err); if (err) g_warning ("page replace: %s", err->message); if (hyphens_state) text = g_regex_replace (ebook->hyphen, text, -1, 0, "\\1",0 , &err); if (err) g_warning ("hyphen replace: %s", err->message); if (!ebook->builder) ebook->builder = load_builder_xml (NULL); if (!ebook->builder) return; old = strlen (text); text = g_utf8_normalize (text, old, G_NORMALIZE_ALL); size = strlen (text); if (size < old) ebook->utf8_count += (old - size); textview = GTK_TEXT_VIEW(gtk_builder_get_object (ebook->builder, "textview")); buffer = GTK_TEXT_BUFFER(gtk_builder_get_object (ebook->builder, "textbuffer1")); gtk_text_buffer_get_bounds (buffer, &start, &end); if ((text != NULL) && (g_utf8_validate (text, size, NULL))) { gtk_text_buffer_insert (buffer, &end, text, size); gtk_text_buffer_set_modified (buffer, TRUE); } gtk_widget_show (GTK_WIDGET(textview)); }
GtkSourceBuffer * init_buffer(FileContainer *file_container) { GtkSourceBuffer *source_buffer = gtk_source_buffer_new(NULL); gtk_source_buffer_set_highlight_matching_brackets(source_buffer, FALSE); GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER(source_buffer); gtk_text_buffer_set_text( text_buffer, file_container->data, file_container->size ); GtkTextIter start_of_buffer; gtk_text_buffer_get_start_iter(text_buffer, &start_of_buffer); gtk_text_buffer_place_cursor(text_buffer, &start_of_buffer); gtk_text_buffer_set_modified(text_buffer, FALSE); return source_buffer; }
void iofunctions_load_default_text (gboolean loopedonce) { GError* readerr = NULL; GError* copyerr = NULL; gchar* text = NULL; GuEditor* ec = gummi_get_active_editor(); if (!g_file_get_contents (C_WELCOMETEXT, &text, NULL, &readerr)) { slog (L_WARNING, "Could not find default welcome text, resetting..\n"); utils_copy_file (C_DEFAULTTEXT, C_WELCOMETEXT, ©err); if (!loopedonce) return iofunctions_load_default_text (TRUE); } if (text) editor_fill_buffer (ec, text); gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (ec->buffer), FALSE); g_free (text); }
void reloading_file(GtkWidget *widget, gpointer user_data) { if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(gui->editor_notebook)) <= 0) { return ; } /** Retrieve the stored filepath: **/ gpointer filepath = g_object_get_data(G_OBJECT(current_editor.current_buffer), "filepath") ; File_Editor *file_editor = g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ; reload_file(GTK_SOURCE_BUFFER(current_editor.current_buffer), filepath, file_editor) ; /** We mark the TextBuffer as not modified. **/ gtk_text_buffer_set_modified(current_editor.current_buffer, FALSE) ; }
static void sp_text_edit_dialog_update_object_text ( SPItem *text ) { GtkTextBuffer *tb; GtkTextIter start, end; gchar *str; tb = (GtkTextBuffer*)g_object_get_data (G_OBJECT (dlg), "text"); /* write text */ if (gtk_text_buffer_get_modified (tb)) { gtk_text_buffer_get_bounds (tb, &start, &end); str = gtk_text_buffer_get_text (tb, &start, &end, TRUE); sp_te_set_repr_text_multiline (text, str); g_free (str); gtk_text_buffer_set_modified (tb, FALSE); } }
void mape_edit_view_clear(MapeEditView* view) { g_free(view->file_path); view->file_path = NULL; /* TODO: Undoable action dingsen */ /* (statische mape_edit_view_set_contents-Call?) */ gtk_text_buffer_set_text( gtk_text_view_get_buffer(GTK_TEXT_VIEW(view->view)), "", 0 ); gtk_text_buffer_set_modified( gtk_text_view_get_buffer(GTK_TEXT_VIEW(view->view)), FALSE ); }
/* We call load_file() when we have a filename and want to load it into the buffer for the GtkTextView. The previous contents are overwritten. */ void load_file (TutorialTextEditor *editor, gchar *filename) { GError *err=NULL; gchar *status; gchar *text; gboolean result; GtkTextBuffer *buffer; /* add Loading message to status bar and ensure GUI is current */ status = g_strdup_printf ("Loading %s...", filename); gtk_statusbar_push (GTK_STATUSBAR (editor->statusbar), editor->statusbar_context_id, status); g_free (status); while (gtk_events_pending()) gtk_main_iteration(); /* get the file contents */ result = g_file_get_contents (filename, &text, NULL, &err); if (result == FALSE) { /* error loading file, show message to user */ error_message (err->message); g_error_free (err); g_free (filename); } /* disable the text view while loading the buffer with the text */ gtk_widget_set_sensitive (editor->text_view, FALSE); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->text_view)); gtk_text_buffer_set_text (buffer, text, -1); gtk_text_buffer_set_modified (buffer, FALSE); gtk_widget_set_sensitive (editor->text_view, TRUE); g_free (text); /* now we can set the current filename since loading was a success */ if (editor->filename != NULL) g_free (editor->filename); editor->filename = filename; /* clear loading status and restore default */ gtk_statusbar_pop (GTK_STATUSBAR (editor->statusbar), editor->statusbar_context_id); reset_default_status (editor); }
//================================================================ int GUI_edi_getModif (MemObj *mo) { //================================================================ /// GUI_edi_getModif get if buffer is modfied /// if buffer is modied: save; this call resets the state. /// returns 1=modified; 0=unmodified. int imod; // set GUI_ed1_view GUI_ed1_buff if(mo) { // for internal call: mo=NULL if(GUI_ed1_decode(mo)) return -1; } imod = gtk_text_buffer_get_modified (GUI_ed1_buff); gtk_text_buffer_set_modified (GUI_ed1_buff, FALSE); return imod; }
void Highlight::highlight() // This does the actual highlighting. // Ensure that applying a tag does not change the modified status of the textbuffer. { bool cursor_set = false; for (unsigned int i = 0; i < highlightwordstarts.size(); i++) { GtkTextIter start, end; gtk_text_buffer_get_iter_at_offset(highlightbuffers[i], &start, highlightwordstarts[i]); gtk_text_buffer_get_iter_at_offset(highlightbuffers[i], &end, highlightwordends[i]); bool modified_status = gtk_text_buffer_get_modified(highlightbuffers[i]); gtk_text_buffer_apply_tag(highlightbuffers[i], mytag, &start, &end); if (!modified_status) gtk_text_buffer_set_modified(highlightbuffers[i], false); if (!cursor_set) { gtk_text_buffer_place_cursor(highlightbuffers[i], &start); screen_scroll_to_iterator(highlightviews[i], &start); cursor_set = true; } } }
void on_save_show (GtkImageMenuItem* test, gpointer user_data) { GtkWidget* save; GUI_* guisex; GtkTextBuffer *txtbuffer; char *filename, *text; (void)test; guisex = (GUI_ *)user_data; /* guisex->textview = gtk_text_view_new (); */ txtbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guisex->textview)); /* create a 'save file' dialog */ save = gtk_file_chooser_dialog_new (NULL, NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER(save),TRUE ); /*if (!gtk_text_buffer_get_modified (txtbuffer)) {*/ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (save), "/" ); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (save), "Untitled" ); gtk_text_buffer_set_modified (txtbuffer, FALSE); if (gtk_dialog_run (GTK_DIALOG (save)) == GTK_RESPONSE_ACCEPT) { GtkTextIter iStart, iEnd; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (save) ); /* on chope le debut et la fin du buffer */ gtk_text_buffer_get_start_iter(txtbuffer, &iStart); gtk_text_buffer_get_end_iter(txtbuffer, &iEnd); text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER(txtbuffer), &iStart, &iEnd, FALSE ); save_as(text, filename); g_free (filename); } gtk_widget_destroy (save); }
static void gedit_document_output_stream_constructed (GObject *object) { GeditDocumentOutputStream *stream = GEDIT_DOCUMENT_OUTPUT_STREAM (object); if (!stream->priv->doc) { g_critical ("This should never happen, a problem happened constructing the Document Output Stream!"); return; } /* Init the undoable action */ gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc)); /* clear the buffer */ gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->priv->doc), "", 0); gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->doc), FALSE); gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (stream->priv->doc)); G_OBJECT_CLASS (gedit_document_output_stream_parent_class)->constructed (object); }
void ori_open (gchar * fn, gboolean replace) { GString *gstr; GFile *fp; GFileInputStream *file_in; char *nullstr = "NULLSTRING"; gssize bytes = 1; if (!fn) fn = nullstr; fp = g_file_new_for_uri (fn); if (fp == NULL) { gchar errmsg[MAX_ERR_MSG_SIZE + 1]; g_snprintf (errmsg, MAX_ERR_MSG_SIZE, _("Failed to open <%s>"), fn); gui_app_show_msg (GTK_MESSAGE_ERROR, errmsg); return; } gstr = g_string_new (""); file_in = g_file_read (fp, NULL, NULL); while (bytes != 0) { gchar buf[100] = { 0 }; bytes = g_input_stream_read (G_INPUT_STREAM (file_in), buf, 100, NULL, NULL); g_string_append_len (gstr, buf, bytes); } g_input_stream_close (G_INPUT_STREAM (file_in), NULL, NULL); gui_editor_set_text (app->editor, gstr->str); gtk_text_buffer_set_modified ((GtkTextBuffer *)app->editor->buffer, FALSE); /* Set breakpoints as instructed in the source */ { gchar *str = gstr->str; gint ln = 0; gchar **lines = NULL; g_assert (str); lines = g_strsplit (str, "\n", -1); g_assert (lines); /* for each line */ while (lines[ln]) { /* check for ;@ */ if (strlen (lines[ln]) > 1) { if (lines[ln][0] == ';' && lines[ln][1] == '@') { /* add breakpoint */ gui_editor_set_mark (app->editor, ln + 1, TRUE); //exit(99); } } ln++; } g_strfreev (lines); } g_string_free (gstr, TRUE); if (replace) _set_file_name (fn); }
void GUI::add_program_file(gchar * filepath){ if (this->is_empty_notebook){ this->is_empty_notebook = false; gtk_notebook_remove_page(GTK_NOTEBOOK(this->programs_notebook), this->empty_notebook_index); } GuiNotebookItem notebook_item; notebook_item.vmachine = NULL; notebook_item.filepath = filepath; // netobook label notebook_item.notebook_label_text = this->extract_file_name(notebook_item.filepath); notebook_item.notebook_label = gtk_label_new (notebook_item.notebook_label_text); // create inner notebook vbox notebook_item.notebook_vbox = gtk_vbox_new(FALSE, 0); // create scrolled_window notebook_item.notebook_scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (notebook_item.notebook_scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (notebook_item.notebook_vbox), notebook_item.notebook_scrolled_window, TRUE, // vbox gives widget all remaining space TRUE, // widget expands to fill given space 0); // pixel of padding around the widget // create notebook_source_view notebook_item.source_buffer = gtk_source_buffer_new (NULL); notebook_item.source_view = gtk_source_view_new_with_buffer(notebook_item.source_buffer); gtk_container_add (GTK_CONTAINER (notebook_item.notebook_scrolled_window), notebook_item.source_view); gtk_source_view_set_auto_indent ( GTK_SOURCE_VIEW (notebook_item.source_view), TRUE); // make a tab be two spaces gtk_source_view_set_indent_width (GTK_SOURCE_VIEW (notebook_item.source_view), 2); gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (notebook_item.source_view), TRUE); gtk_source_view_set_show_line_numbers ( GTK_SOURCE_VIEW (notebook_item.source_view), TRUE); gtk_source_view_set_right_margin_position ( GTK_SOURCE_VIEW (notebook_item.source_view), 80); // default is 70 chars gtk_source_view_set_show_right_margin ( GTK_SOURCE_VIEW (notebook_item.source_view), TRUE); gtk_text_view_set_wrap_mode ( GTK_TEXT_VIEW (notebook_item.source_view), GTK_WRAP_WORD_CHAR); gtk_text_view_set_editable ( GTK_TEXT_VIEW (notebook_item.source_view), FALSE); gtk_text_view_set_cursor_visible ( GTK_TEXT_VIEW (notebook_item.source_view), FALSE); /* setup view */ PangoFontDescription * font_desc = NULL; font_desc = pango_font_description_from_string ("monospace"); if (font_desc != NULL){ gtk_widget_modify_font (notebook_item.source_view, font_desc); pango_font_description_free (font_desc); } // get file content gchar * buffer; GError * error_here = NULL; if (g_file_get_contents (notebook_item.filepath, &buffer, NULL, &error_here)){ gtk_source_buffer_begin_not_undoable_action (notebook_item.source_buffer); gtk_source_buffer_begin_not_undoable_action (notebook_item.source_buffer); gtk_text_buffer_set_text (GTK_TEXT_BUFFER (notebook_item.source_buffer), buffer, -1); gtk_source_buffer_end_not_undoable_action (notebook_item.source_buffer); gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (notebook_item.source_buffer), FALSE); /* move cursor to the beginning */ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (notebook_item.source_buffer), ¬ebook_item.iter); gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (notebook_item.source_buffer), ¬ebook_item.iter); { GtkTextIter start, end; char *text; gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (notebook_item.source_buffer), &start, &end); text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (notebook_item.source_buffer), &start, &end, TRUE); g_assert (!strcmp (text, buffer)); g_free (text); } g_free (buffer); GtkWidget * vm_frame; vm_frame = gtk_frame_new ("VM operations"); // create buttons notebook_item.notebook_button_hbox = gtk_hbox_new (FALSE, 0); notebook_item.run_step_button = gtk_button_new_with_label ("Run Step"); notebook_item.run_button = gtk_button_new_with_label ("Run"); notebook_item.view_vm_mem = gtk_button_new_with_label ("View Vm memory"); // create time out input notebook_item.timeout_field = gtk_entry_new_with_max_length(10); GtkWidget * timeout_label; timeout_label = gtk_label_new("Timeout:"); g_signal_connect (notebook_item.run_step_button, "clicked", G_CALLBACK (GUI::run_step_button_clicked), gpointer(this)); g_signal_connect (notebook_item.run_button, "clicked", G_CALLBACK (GUI::run_button_clicked), gpointer(this)); g_signal_connect (notebook_item.view_vm_mem, "clicked", G_CALLBACK (GUI::view_vm_mem_clicked), gpointer(this)); gtk_box_pack_start (GTK_BOX (notebook_item.notebook_button_hbox), notebook_item.view_vm_mem, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); // pixel of padding around the widget gtk_box_pack_start (GTK_BOX (notebook_item.notebook_button_hbox), notebook_item.run_step_button, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); // pixel of padding around the widget gtk_box_pack_start (GTK_BOX (notebook_item.notebook_button_hbox), timeout_label, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); // pixel of padding around the widget gtk_box_pack_start (GTK_BOX (notebook_item.notebook_button_hbox), notebook_item.timeout_field, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); // pixel of padding around the widget gtk_box_pack_start (GTK_BOX (notebook_item.notebook_button_hbox), notebook_item.run_button, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); // pixel of padding around the widget gtk_container_add(GTK_CONTAINER (vm_frame), notebook_item.notebook_button_hbox); gtk_box_pack_start (GTK_BOX (notebook_item.notebook_vbox), vm_frame, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); gtk_notebook_append_page( GTK_NOTEBOOK(this->programs_notebook), notebook_item.notebook_vbox, notebook_item.notebook_label); this->gui_notebook_item_list.push_back(notebook_item); gtk_widget_show_all(this->programs_notebook); } else { g_print("WRONG \n"); } }
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 ; }
gboolean mape_edit_view_open(MapeEditView* view, const gchar* filename, GError** error) { gboolean result; gchar* contents; gchar* conv; gchar* utf8_file; gsize length; result = g_file_get_contents(filename, &contents, &length, error); if(result == FALSE) return FALSE; /* Assume UTF-8 */ result = g_utf8_validate(contents, length, NULL); if(result == FALSE) { /* No UTF-8, try LATIN1 */ conv = g_convert( contents, -1, "UTF-8", "LATIN1", NULL, NULL, NULL ); g_free(contents); if(conv == NULL) { utf8_file = g_filename_to_utf8( filename, -1, NULL, NULL, NULL ); if(utf8_file == NULL) utf8_file = g_strdup("<unknown file name>"); g_set_error( error, g_quark_from_static_string( "MAPE_EDIT_VIEW_ERROR" ), MAPE_EDIT_VIEW_ERROR_UNKNOWN_ENCODING, "Could not read file %s: Either the encoding " "is unknown or it is a binary file", utf8_file ); g_free(utf8_file); return FALSE; } /* Conversion succeeded */ contents = conv; view->encoding = "LATIN1"; } else { view->encoding = "UTF-8"; } mape_edit_view_set_filename(view, filename); /* TODO: Undoable action dingsen */ /* (statische mape_edit_view_set_contents-Call?) */ gtk_text_buffer_set_text( gtk_text_view_get_buffer(GTK_TEXT_VIEW(view->view)), contents, length ); g_free(contents); gtk_text_buffer_set_modified( gtk_text_view_get_buffer(GTK_TEXT_VIEW(view->view)), FALSE ); return TRUE; }
void ori_open (gchar * fn, gboolean replace) { GString *gstr; FILE *fp; char *nullstr = "NULLSTRING"; char *ret; if (!fn) fn = nullstr; fp = fopen (fn, "r"); if (fp == NULL) { gchar errmsg[MAX_ERR_MSG_SIZE + 1]; g_snprintf (errmsg, MAX_ERR_MSG_SIZE, _("Failed to open <%s>"), fn); gui_app_show_msg (GTK_MESSAGE_ERROR, errmsg); return; } gstr = g_string_new (""); while (!feof (fp)) { gchar buf[300] = { 0 }; // return value stored just to avoid compiler warnings. ret = fgets (buf, 100, fp); g_string_append (gstr, buf); } gui_editor_set_text (app->editor, gstr->str); gtk_text_buffer_set_modified ((GtkTextBuffer *)app->editor->buffer, FALSE); /* Set breakpoints as instructed in the source */ { gchar *str = gstr->str; gint ln = 0; gchar **lines = NULL; g_assert (str); lines = g_strsplit (str, "\n", -1); g_assert (lines); /* for each line */ while (lines[ln]) { /* check for ;@ */ if (strlen (lines[ln]) > 1) { if (lines[ln][0] == ';' && lines[ln][1] == '@') { /* add breakpoint */ gui_editor_set_mark (app->editor, ln + 1, TRUE); //exit(99); } } ln++; } g_strfreev (lines); } g_string_free (gstr, TRUE); if (replace) _set_file_name (fn); }
void load_file (char *fname) { FILE *f; GtkTextIter p; char fbuf[CHAR_BUF]; size_t l; if (!fname) { // Create file selection dialog GtkWidget *dialog = gtk_file_chooser_dialog_new("Open File...", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); // Show the file selection dialog int resp = gtk_dialog_run(GTK_DIALOG(dialog)); if (resp == GTK_RESPONSE_OK) { // fname contains the file selected by the user fname = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog))); gtk_widget_destroy(dialog); } else { // cancel gtk_widget_destroy(dialog); return; } } if (!(f = fopen(fname, "r"))) { // If file cannot be opened g_printerr("%s: %s\n", fname, g_strerror(errno)); return; } if (fname != filename) { gchar *wt = g_strdup_printf("Text Editor (%s)", fname); g_free(filename); filename = fname; // Set titlebar to the file name gtk_window_set_title(GTK_WINDOW(editor_window), wt); g_free(wt); } // Get the ending iterator of buffer into p gtk_text_buffer_get_end_iter(editor_buf, &p); while ((l = fread(fbuf, 1, sizeof(fbuf), f)) > 0) { // Only text files in Utf-8 format can be opened GError *err = NULL; gsize br, bw; gchar *text; if (!(text = g_locale_to_utf8(fbuf, l, &br, &bw, &err))) { g_printerr("File is not in UTF-8 format : %s\n", err->message); g_clear_error(&err); filename = NULL; // if an invalid file is opened enter the file name as NULL gtk_window_set_title(GTK_WINDOW(editor_window), "Text Editor (Insert file name)"); fclose(f); return; } gtk_text_buffer_insert(editor_buf, &p, text, bw); g_free(text); } gtk_text_buffer_set_modified(editor_buf, FALSE); gtk_text_buffer_get_start_iter(editor_buf, &p); gtk_text_buffer_place_cursor(editor_buf, &p); if (ferror(f)) { g_printerr("%s: %s\n", fname, g_strerror(errno)); fclose(f); return; } if (fclose(f) == EOF) g_printerr("%s: %s\n", fname, g_strerror(errno)); }
/* only used in editor */ GtkWidget * org_gnome_exchange_settings(EPlugin *epl, EConfigHookItemFactoryData *data) { EMConfigTargetAccount *target_account; ExchangeAccount *account = NULL; CamelURL *url; const char *source_url; char *message = NULL, *txt = NULL, *oof_message; gboolean oof_state = FALSE; GtkVBox *vbox_settings; /* OOF fields */ GtkFrame *frm_oof; GtkVBox *vbox_oof; GtkLabel *lbl_oof_desc; GtkTable *tbl_oof_status; GtkLabel *lbl_status; GtkRadioButton *radio_iof, *radio_oof; GtkScrolledWindow *scrwnd_oof; GtkTextView *txtview_oof; /* Authentication settings */ GtkFrame *frm_auth; GtkVBox *vbox_auth; GtkTable *tbl_auth; #ifdef HAVE_KRB5 GtkLabel *lbl_chpass; GtkButton *btn_chpass; #endif GtkLabel *lbl_dass; GtkButton *btn_dass; /* Miscelleneous setting */ GtkFrame *frm_misc; GtkVBox *vbox_misc; GtkTable *tbl_misc; GtkLabel *lbl_fsize; GtkButton *btn_fsize; GtkTextBuffer *buffer; GtkTextIter start, end; target_account = (EMConfigTargetAccount *)data->config->target; source_url = e_account_get_string (target_account->account, E_ACCOUNT_SOURCE_URL); url = camel_url_new(source_url, NULL); if (url == NULL || strcmp(url->protocol, "exchange") != 0) { if (url) camel_url_free(url); return NULL; } if (data->old) { camel_url_free(url); return data->old; } if (url) camel_url_free (url); account = exchange_operations_get_exchange_account (); oof_data = g_new0 (OOFData, 1); oof_data->state = FALSE; oof_data->message = NULL; oof_data->text_view = NULL; /* See if oof info found already */ if (account && !exchange_oof_get (account, &oof_state, &message)) { e_error_run (NULL, ERROR_DOMAIN ":state-read-error", NULL); return NULL; } if (message && *message) oof_data->message = g_strdup (message); else oof_data->message = NULL; oof_data->state = oof_state; /* construct page */ vbox_settings = (GtkVBox*) g_object_new (GTK_TYPE_VBOX, "homogeneous", FALSE, "spacing", 6, NULL); gtk_container_set_border_width (GTK_CONTAINER (vbox_settings), 12); frm_oof = (GtkFrame*) g_object_new (GTK_TYPE_FRAME, "label", _("Out Of Office"), NULL); gtk_box_pack_start (GTK_BOX (vbox_settings), GTK_WIDGET (frm_oof), FALSE, FALSE, 0); vbox_oof = (GtkVBox*) g_object_new (GTK_TYPE_VBOX, NULL, "homogeneous", FALSE, "spacing", 12, NULL); gtk_container_set_border_width (GTK_CONTAINER (vbox_oof), 6); gtk_container_add (GTK_CONTAINER (frm_oof), GTK_WIDGET (vbox_oof)); lbl_oof_desc = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("The message specified below will be automatically sent to \neach person who sends mail to you while you are out of the office."), "justify", GTK_JUSTIFY_LEFT, NULL); gtk_misc_set_alignment (GTK_MISC (lbl_oof_desc), 0, 0.5); gtk_box_pack_start (GTK_BOX (vbox_oof), GTK_WIDGET (lbl_oof_desc), FALSE, FALSE, 0); tbl_oof_status = (GtkTable*) g_object_new (GTK_TYPE_TABLE, "n-rows", 2, "n-columns", 2, "homogeneous", FALSE, "row-spacing", 6, "column-spacing", 6, NULL); txt = g_strdup_printf ("<b>%s</b>", _("Status:")); lbl_status = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", txt, "use-markup", TRUE, NULL); g_free (txt); gtk_misc_set_alignment (GTK_MISC (lbl_status), 0, 0.5); gtk_misc_set_padding (GTK_MISC (lbl_status), 0, 0); if (oof_data->state) { radio_oof = (GtkRadioButton*) g_object_new (GTK_TYPE_RADIO_BUTTON, "label", _("I am out of the office"), NULL); radio_iof = (GtkRadioButton*) g_object_new (GTK_TYPE_RADIO_BUTTON, "label", _("I am in the office"), "group", radio_oof, NULL); } else { radio_iof = (GtkRadioButton*) g_object_new (GTK_TYPE_RADIO_BUTTON, "label", _("I am in the office"), NULL); radio_oof = (GtkRadioButton*) g_object_new (GTK_TYPE_RADIO_BUTTON, "label", _("I am out of the office"), "group", radio_iof, NULL); } g_signal_connect (radio_oof, "toggled", G_CALLBACK (toggled_state), NULL); gtk_table_attach (tbl_oof_status, GTK_WIDGET (lbl_status), 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach (tbl_oof_status, GTK_WIDGET (radio_iof), 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach (tbl_oof_status, GTK_WIDGET (radio_oof), 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_box_pack_start (GTK_BOX (vbox_oof), GTK_WIDGET (tbl_oof_status), FALSE, FALSE, 0); scrwnd_oof = (GtkScrolledWindow*) g_object_new (GTK_TYPE_SCROLLED_WINDOW, "hscrollbar-policy", GTK_POLICY_AUTOMATIC, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, "shadow-type", GTK_SHADOW_IN, NULL); gtk_box_pack_start (GTK_BOX (vbox_oof), GTK_WIDGET (scrwnd_oof), FALSE, FALSE, 0); txtview_oof = (GtkTextView*) g_object_new (GTK_TYPE_TEXT_VIEW, "justification", GTK_JUSTIFY_LEFT, "wrap-mode", GTK_WRAP_WORD, "editable", TRUE, NULL); buffer = gtk_text_view_get_buffer (txtview_oof); gtk_text_buffer_get_bounds (buffer, &start, &end); oof_message = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); if (oof_message && *oof_message) { /* Will this ever happen? */ oof_data->message = oof_message; } if (oof_data->message) { /* previuosly set message */ gtk_text_buffer_set_text (buffer, oof_data->message, -1); gtk_text_view_set_buffer (txtview_oof, buffer); } gtk_text_buffer_set_modified (buffer, FALSE); if (!oof_data->state) gtk_widget_set_sensitive (GTK_WIDGET (txtview_oof), FALSE); oof_data->text_view = GTK_WIDGET (txtview_oof); g_signal_connect (buffer, "changed", G_CALLBACK (update_state), NULL); gtk_container_add (GTK_CONTAINER (scrwnd_oof), GTK_WIDGET (txtview_oof)); /* Security settings */ frm_auth = (GtkFrame*) g_object_new (GTK_TYPE_FRAME, "label", _("Security"), NULL); gtk_box_pack_start (GTK_BOX (vbox_settings), GTK_WIDGET (frm_auth), FALSE, FALSE, 0); vbox_auth = (GtkVBox*) g_object_new (GTK_TYPE_VBOX, "homogeneous", FALSE, "spacing", 6, NULL); gtk_container_set_border_width (GTK_CONTAINER (vbox_auth), 6); gtk_container_add (GTK_CONTAINER (frm_auth), GTK_WIDGET (vbox_auth)); tbl_auth = (GtkTable*) g_object_new (GTK_TYPE_TABLE, "n-rows", 2, "n-columns", 2, "homogeneous", FALSE, "row-spacing", 6, "column-spacing", 6, NULL); #ifdef HAVE_KRB5 /* Change Password */ lbl_chpass = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("Change the password for Exchange account"), NULL); gtk_misc_set_alignment (GTK_MISC (lbl_chpass), 0, 0.5); btn_chpass = (GtkButton*) g_object_new (GTK_TYPE_BUTTON, "label", _("Change Password"), NULL); g_signal_connect (GTK_OBJECT (btn_chpass), "clicked", G_CALLBACK (btn_chpass_clicked), NULL); #endif /* Delegation Assistant */ lbl_dass = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("Manage the delegate settings for Exchange account"), NULL); gtk_misc_set_alignment (GTK_MISC (lbl_dass), 0, 0.5); btn_dass = (GtkButton*) g_object_new (GTK_TYPE_BUTTON, "label", _("Delegation Assistant"), NULL); g_signal_connect (btn_dass, "clicked", G_CALLBACK (btn_dass_clicked), NULL); /* Add items to the table */ #ifdef HAVE_KRB5 gtk_table_attach_defaults (tbl_auth, GTK_WIDGET (lbl_chpass), 0, 1, 0, 1); gtk_table_attach (tbl_auth, GTK_WIDGET (btn_chpass), 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0); #endif gtk_table_attach_defaults (tbl_auth, GTK_WIDGET (lbl_dass), 0, 1, 1, 2); gtk_table_attach (tbl_auth, GTK_WIDGET (btn_dass), 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_box_pack_start (GTK_BOX (vbox_auth), GTK_WIDGET (tbl_auth), FALSE, FALSE, 0); /* Miscelleneous settings */ frm_misc = (GtkFrame*) g_object_new (GTK_TYPE_FRAME, "label", _("Miscelleneous"), NULL); gtk_box_pack_start (GTK_BOX (vbox_settings), GTK_WIDGET (frm_misc), FALSE, FALSE, 0); vbox_misc = (GtkVBox*) g_object_new (GTK_TYPE_VBOX, "homogeneous", FALSE, "spacing", 6, NULL); gtk_container_set_border_width (GTK_CONTAINER (vbox_misc), 6); gtk_container_add (GTK_CONTAINER (frm_misc), GTK_WIDGET (vbox_misc)); tbl_misc = (GtkTable*) g_object_new (GTK_TYPE_TABLE, "n-rows", 1, "n-columns", 1, "homogeneous", FALSE, "row-spacing", 6, "column-spacing", 6, NULL); /* Folder Size */ lbl_fsize = (GtkLabel*) g_object_new (GTK_TYPE_LABEL, "label", _("View the size of all Exchange folders"), NULL); gtk_misc_set_alignment (GTK_MISC (lbl_fsize), 0, 0.5); btn_fsize = (GtkButton*) g_object_new (GTK_TYPE_BUTTON, "label", _("Folders Size"), NULL); g_signal_connect (btn_fsize, "clicked", G_CALLBACK (btn_fsize_clicked), NULL); gtk_table_attach_defaults (tbl_misc, GTK_WIDGET (lbl_fsize), 0, 1, 0, 1); gtk_table_attach (tbl_misc, GTK_WIDGET (btn_fsize), 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0); gtk_box_pack_start (GTK_BOX (vbox_misc), GTK_WIDGET (tbl_misc), FALSE, FALSE, 0); gtk_widget_show_all (GTK_WIDGET (vbox_settings)); gtk_notebook_insert_page (GTK_NOTEBOOK (data->parent), GTK_WIDGET (vbox_settings), gtk_label_new(_("Exchange Settings")), 4); return GTK_WIDGET (vbox_settings); }
void Gobby::OperationOpen::read_finish() { // If the last character is a newline character, remove it. GtkTextIter end_iter, test_iter; gtk_text_buffer_get_end_iter(m_content, &end_iter); test_iter = end_iter; if(gtk_text_iter_backward_char(&test_iter)) { if(gtk_text_iter_get_char(&test_iter) == '\n') { gtk_text_buffer_delete( m_content, &test_iter, &end_iter); } } gtk_text_buffer_set_modified(m_content, FALSE); GtkTextIter insert_iter; GtkTextMark* insert = gtk_text_buffer_get_insert(m_content); gtk_text_buffer_get_iter_at_mark(m_content, &insert_iter, insert); InfUser* user = INF_USER(g_object_new( INF_TEXT_TYPE_USER, "id", 1, "flags", INF_USER_LOCAL, "name", m_preferences.user.name.get().c_str(), /* The user is made active when the user * switches to the document. */ "status", INF_USER_INACTIVE, "hue", m_preferences.user.hue.get(), "caret-position", gtk_text_iter_get_offset(&insert_iter), static_cast<void*>(NULL))); InfUserTable* user_table = inf_user_table_new(); inf_user_table_add_user(user_table, user); g_object_unref(user); InfTextGtkBuffer* text_gtk_buffer = inf_text_gtk_buffer_new(m_content, user_table); g_object_unref(user_table); ConnectionManager& connection_manager = get_browser().get_connection_manager(); InfCommunicationManager* communication_manager = connection_manager.get_communication_manager(); InfBrowser* browser = m_parent.get_browser(); InfIo* io; g_object_get(G_OBJECT(browser), "io", &io, NULL); InfTextSession* session = inf_text_session_new_with_user_table( communication_manager, INF_TEXT_BUFFER(text_gtk_buffer), io, user_table, INF_SESSION_RUNNING, NULL, NULL); g_object_unref(io); g_object_unref(text_gtk_buffer); InfRequest* request = inf_browser_add_note( m_parent.get_browser(), m_parent.get_browser_iter(), m_name.c_str(), "InfText", NULL, INF_SESSION(session), TRUE, on_request_finished_static, this); g_object_unref(session); if(request != NULL) { m_request = request; g_object_ref(m_request); // TODO: We can remove the node watch here, but need to have // the browser available in on_request_finished then. Maybe // just disconnect the signal, or bind it. } }
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); }
gint main(gint argc, gchar **argv) { Conf *conf; GtkItemFactory *ifactory; gchar *stdin_data = NULL; bindtextdomain(PACKAGE, LOCALEDIR); //bindtextdomain ?? bind_textdomain_codeset(PACKAGE, "UTF-8"); // ?? textdomain(PACKAGE); // ?? pub = g_malloc(sizeof(PublicData)); pub->fi = g_malloc(sizeof(FileInfo)); pub->fi->filename = NULL; pub->fi->charset = NULL; pub->fi->charset_flag = FALSE; pub->fi->lineend = LF; parse_args(argc, argv, pub->fi); gtk_init(&argc, &argv); //call before using any gtk fuction g_set_application_name(PACKAGE_NAME); g_print("%s\n", PACKAGE_NAME); #if !GTK_CHECK_VERSION(2, 6, 0) add_about_stock(); #endif pub->mw = create_main_window(); //Find create_main_window conf = g_malloc(sizeof(Conf)); //sends default vlues to load and overwrites in the function conf->width = 600; conf->height = 400; conf->fontname = g_strdup("Monospace 12"); conf->wordwrap = FALSE; conf->linenumbers = FALSE; conf->autoindent = FALSE; load_config_file(conf); //gtk options for GUI gtk_window_set_default_size( GTK_WINDOW(pub->mw->window), conf->width, conf->height); set_text_font_by_name(pub->mw->view, conf->fontname); ifactory = gtk_item_factory_from_widget(pub->mw->menubar); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(ifactory, "/Options/Word Wrap")), conf->wordwrap); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(ifactory, "/Options/Line Numbers")), conf->linenumbers); indent_refresh_tab_width(pub->mw->view); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(ifactory, "/Options/Auto Indent")), conf->autoindent); gtk_widget_show_all(pub->mw->window); g_free(conf->fontname); g_free(conf); #ifdef ENABLE_EMACS check_emacs_key_theme(GTK_WINDOW(pub->mw->window), ifactory); #endif hlight_init(pub->mw->buffer); undo_init(pub->mw->view, gtk_item_factory_get_widget(ifactory, "/Edit/Undo"), gtk_item_factory_get_widget(ifactory, "/Edit/Redo")); // hlight_init(pub->mw->buffer); dnd_init(pub->mw->view); if (pub->fi->filename) file_open_real(pub->mw->view, pub->fi); #ifdef G_OS_UNIX else stdin_data = gedit_utils_get_stdin(); #endif if (stdin_data) { gchar *str; GtkTextIter iter; str = g_convert(stdin_data, -1, "UTF-8", get_default_charset(), NULL, NULL, NULL); g_free(stdin_data); // gtk_text_buffer_set_text(buffer, "", 0); gtk_text_buffer_get_start_iter(pub->mw->buffer, &iter); gtk_text_buffer_insert(pub->mw->buffer, &iter, str, strlen(str)); gtk_text_buffer_get_start_iter(pub->mw->buffer, &iter); gtk_text_buffer_place_cursor(pub->mw->buffer, &iter); gtk_text_buffer_set_modified(pub->mw->buffer, FALSE); gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(pub->mw->view), &iter, 0, FALSE, 0, 0); g_free(str); } if (jump_linenum) { GtkTextIter iter; gtk_text_buffer_get_iter_at_line(pub->mw->buffer, &iter, jump_linenum - 1); gtk_text_buffer_place_cursor(pub->mw->buffer, &iter); // gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview), &iter, 0.1, FALSE, 0.5, 0.5); scroll_to_cursor(pub->mw->buffer, 0.25); } set_main_window_title(); // hlight_apply_all(pub->mw->buffer); gtk_main(); return 0; }
void note_save(UserInterface *ui) { time_t time_in_s; gchar* title; gchar* content; GtkTextIter iter, start, end; GtkTextMark *mark; gint cursor_position; AppData *app_data = app_data_get(); GtkTextBuffer *buffer = ui->buffer; ConboyNote *note = ui->note; /* If note is empty, don't save */ gtk_text_buffer_get_bounds(buffer, &start, &end); content = gtk_text_iter_get_text(&start, &end); if (is_empty_str(content)) { gtk_text_buffer_set_modified(buffer, FALSE); g_free(content); return; } g_free(content); /* If buffer is not dirty, don't save */ if (!gtk_text_buffer_get_modified(buffer)) { return; } /* Get time */ time_in_s = time(NULL); /* Get cursor position */ mark = gtk_text_buffer_get_insert(buffer); gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark); cursor_position = gtk_text_iter_get_offset(&iter); /* Get title */ title = note_extract_title_from_buffer(buffer); /* Check for duplicated title */ ConboyNote *existing_note = conboy_note_store_find_by_title(app_data->note_store, title); if (existing_note && (existing_note != note)) { /* Save alternative title if title is already taken */ int num = conboy_note_store_get_length(app_data->note_store) + 1; gchar new_title[100]; g_sprintf(new_title, _("New Note %i"), num); g_free(title); title = g_strdup(new_title); } /* Set meta data */ /* We don't change height, width, x and y because we don't use them */ g_object_set(note, "title", title, "change-date", time_in_s, "metadata-change-date", time_in_s, "cursor-position", cursor_position, "open-on-startup", FALSE, NULL); g_free(title); if (note->create_date == 0) { g_object_set(note, "create-date", time_in_s, NULL); } if (note->height == 0) { g_object_set(note, "height", 300, NULL); } if (note->width == 0) { g_object_set(note, "width", 600, NULL); } if (note->x == 0) { g_object_set(note, "x", 1, NULL); } if (note->y == 0) { g_object_set(note, "y", 1, NULL); } /* Clear note content, then set it with fresh data from the text buffer */ content = conboy_note_buffer_get_xml(CONBOY_NOTE_BUFFER(buffer)); /** DEBUG **/ if (!g_str_has_suffix(content, "</note-content>\n")) { g_printerr("WARN: Problem when saving:\n%s\n", content); g_free(content); content = NULL; /* Get XML again. See wheter is's ok now */ content = conboy_note_buffer_get_xml(CONBOY_NOTE_BUFFER(buffer)); if (!g_str_has_suffix(content, "</note-content>\n")) { g_printerr("ERROR: Second save NOT successful\n"); } else { g_printerr("INFO: Second save successful\n"); } gtk_text_buffer_set_modified(buffer, FALSE); return; } /****/ g_object_set(note, "content", content, NULL); g_free(content); /* Save the complete note */ conboy_storage_note_save(app_data->storage, note); /* If first save, add to list of all notes */ if (!conboy_note_store_find(app_data->note_store, note)) { conboy_note_store_add(app_data->note_store, note, NULL); } else { conboy_note_store_note_changed(app_data->note_store, note); } gtk_text_buffer_set_modified(buffer, FALSE); }
void save_all_file(GtkWidget *button, gpointer user_data) { /** All files saving callback. **/ #ifdef DEBUG DEBUG_FUNC_MARK #endif gint number_of_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(gui->editor_notebook)) ; int c ; for (c=0 ; c < number_of_pages ; c++) { /** We iterate over every notebook page. **/ GtkWidget *notebook_page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui->editor_notebook), c) ; GtkWidget *notebook_tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui->editor_notebook), 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) { if (g_object_get_data(G_OBJECT(tab_compound_list->data), "tab_filename_widget")) { /** We get the filename tab label. **/ const char *tab_label = gtk_label_get_text(GTK_LABEL(tab_compound_list->data)) ; if (tab_label[0] == '*' && g_strcmp0(tab_label,"*New") != 0) { /** Check if the file is modified (marked with an'*') and is not the default "New" named file. **/ GtkWidget *current_textview = gtk_bin_get_child(GTK_BIN(notebook_page)) ; GtkTextBuffer *current_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(current_textview)) ; gpointer filepath = g_object_get_data(G_OBJECT(current_buffer), "filepath") ; if (filepath != NULL) { /** Getting current editor content **/ GtkTextIter iter_start, iter_end ; GError *error=NULL ; gtk_text_buffer_get_start_iter(current_buffer, &iter_start); gtk_text_buffer_get_end_iter(current_buffer, &iter_end); gchar *file_content = gtk_text_buffer_get_text(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) ) { /** The content saving has failed **/ rename(back_up_filepath, filepath) ; /** We must reset the renaming because else we lost the correct filename in this error case. **/ char *msg = g_strdup_printf( _("Failed to save file:\n%s"), (gchar *) filepath) ; display_message_dialog( _("Cannot save file !!!"), msg, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE) ; free(msg) ; } g_free(file_content) ; g_free(back_up_filepath) ; /** setting the base filename in the bottom bar. **/ gtk_label_set_text(GTK_LABEL(tab_compound_list->data), g_path_get_basename(filepath)) ; /** We mark the TextBuffer as not modified since last saving operation. **/ gtk_text_buffer_set_modified(current_buffer, FALSE) ; 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_textview), "file_editor") ; g_stat(filepath, &file_editor->file_info) ; #endif } } break ; } tab_compound_list = tab_compound_list->next ; } } return ; }
static void gb_view_source_save (GbView *view) { GbViewSourcePrivate *priv; GFileOutputStream *stream; GtkTextBuffer *buffer; GbViewSource *source = (GbViewSource *)view; GCancellable *cancellable = NULL; GtkTextIter iter1; GtkTextIter iter2; const gchar *etag = NULL; GtkWidget *widget; gboolean make_backup = FALSE; GError *error = NULL; gchar *text; gsize n_written; ENTRY; g_return_if_fail(GB_IS_VIEW_SOURCE(source)); priv = source->priv; if (!priv->file) { GtkDialog *dialog; widget = gtk_widget_get_toplevel(GTK_WIDGET(view)); dialog = g_object_new(GTK_TYPE_FILE_CHOOSER_DIALOG, "action", GTK_FILE_CHOOSER_ACTION_SAVE, "title", _("Save File"), "transient-for", widget, NULL); gtk_dialog_add_buttons(dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); if (gtk_dialog_run(dialog) != GTK_RESPONSE_OK) { gtk_widget_destroy(GTK_WIDGET(dialog)); EXIT; } priv->file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog)); gtk_widget_destroy(GTK_WIDGET(dialog)); } g_signal_emit(source, gSignals[PRE_SAVE], 0); g_object_set(priv->progress, "fraction", 0.0, "visible", TRUE, NULL); gb_object_animate_full(priv->progress, GB_ANIMATION_EASE_IN_OUT_QUAD, 500, 60, save_animation_done, g_object_ref(priv->progress), "fraction", 1.0, NULL); buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(priv->source1)); /* * TODO: Do this all async. */ if (!(stream = g_file_replace(priv->file, etag, make_backup, G_FILE_CREATE_NONE, cancellable, &error))) { g_printerr("%s\n", error->message); g_error_free(error); EXIT; } gtk_text_buffer_get_start_iter(buffer, &iter1); gtk_text_buffer_get_end_iter(buffer, &iter2); text = gtk_text_buffer_get_text(buffer, &iter1, &iter2, TRUE); if (!g_output_stream_write_all(G_OUTPUT_STREAM(stream), text, strlen(text), &n_written, cancellable, &error)) { g_printerr("%s\n", error->message); g_error_free(error); } else { g_output_stream_flush(G_OUTPUT_STREAM(stream), NULL, NULL); if (!g_output_stream_close(G_OUTPUT_STREAM(stream), cancellable, &error)) { g_printerr("%s\n", error->message); g_error_free(error); } else { gb_view_set_can_save(view, FALSE); } } gtk_text_buffer_set_modified(buffer, FALSE); g_object_unref(stream); g_free(text); gb_view_source_set_file_attribs(source, priv->file); EXIT; }
static void editor_window_new(const gchar *src_path, const gchar *desktop_name) { EditorWindow *ew; GtkWidget *win_vbox; GtkWidget *hbox; GtkWidget *button; GtkWidget *ct_button; GtkWidget *button_hbox; GtkWidget *scrolled; GtkWidget *text_view; gchar *text; gsize size; ew = g_new0(EditorWindow, 1); ew->window = window_new(GTK_WINDOW_TOPLEVEL, "Desktop", PIXBUF_INLINE_ICON_CONFIG, NULL, _("Desktop file")); gtk_window_set_type_hint(GTK_WINDOW(ew->window), GDK_WINDOW_TYPE_HINT_DIALOG); g_signal_connect(G_OBJECT(ew->window), "delete_event", G_CALLBACK(editor_window_delete_cb), ew); gtk_window_set_default_size(GTK_WINDOW(ew->window), CONFIG_WINDOW_DEF_WIDTH, CONFIG_WINDOW_DEF_HEIGHT); gtk_window_set_resizable(GTK_WINDOW(ew->window), TRUE); gtk_container_set_border_width(GTK_CONTAINER(ew->window), PREF_PAD_BORDER); win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE); gtk_container_add(GTK_CONTAINER(ew->window), win_vbox); gtk_widget_show(win_vbox); hbox = gtk_hbox_new(FALSE, PREF_PAD_SPACE); gtk_box_pack_end(GTK_BOX(win_vbox), hbox, FALSE, FALSE, 0); gtk_widget_show(hbox); ew->entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(hbox), ew->entry, TRUE, TRUE, 0); ew->desktop_name = NULL; if (desktop_name) { gtk_entry_set_text(GTK_ENTRY(ew->entry), desktop_name); ew->desktop_name = g_strdup(desktop_name); } gtk_widget_show(ew->entry); g_signal_connect(G_OBJECT(ew->entry), "changed", G_CALLBACK(editor_window_entry_changed_cb), ew); button_hbox = gtk_hbutton_box_new(); gtk_button_box_set_layout(GTK_BUTTON_BOX(button_hbox), GTK_BUTTONBOX_END); gtk_box_set_spacing(GTK_BOX(button_hbox), PREF_PAD_BUTTON_GAP); gtk_box_pack_end(GTK_BOX(hbox), button_hbox, FALSE, FALSE, 0); gtk_widget_show(button_hbox); ew->save_button = pref_button_new(NULL, GTK_STOCK_SAVE, NULL, FALSE, G_CALLBACK(editor_window_save_cb), ew); gtk_container_add(GTK_CONTAINER(button_hbox), ew->save_button); GTK_WIDGET_SET_FLAGS(ew->save_button, GTK_CAN_DEFAULT); gtk_widget_set_sensitive(ew->save_button, FALSE); gtk_widget_show(ew->save_button); ct_button = ew->save_button; button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, G_CALLBACK(editor_window_close_cb), ew); gtk_container_add(GTK_CONTAINER(button_hbox), button); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); gtk_widget_show(button); if (!generic_dialog_get_alternative_button_order(ew->window)) { gtk_box_reorder_child(GTK_BOX(button_hbox), ct_button, -1); } scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start(GTK_BOX(win_vbox), scrolled, TRUE, TRUE, 5); gtk_widget_show(scrolled); text_view = gtk_text_view_new(); gtk_container_add(GTK_CONTAINER(scrolled), text_view); gtk_widget_show(text_view); ew->buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view)); if (g_file_get_contents(src_path, &text, &size, NULL)) { gtk_text_buffer_set_text(ew->buffer, text, size); } gtk_text_buffer_set_modified(ew->buffer, FALSE); g_signal_connect(G_OBJECT(ew->buffer), "modified-changed", G_CALLBACK(editor_window_text_modified_cb), ew); gtk_widget_show(ew->window); }
gboolean save_file (char *fname) { FILE *f; int ok = TRUE; if (!fname) { GtkWidget *dialog = gtk_file_chooser_dialog_new("Save File As...", NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); int resp = gtk_dialog_run(GTK_DIALOG(dialog)); if (resp == GTK_RESPONSE_ACCEPT) { fname = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog))); gtk_widget_destroy(dialog); } else { gtk_widget_destroy(dialog); return FALSE; } } if (!(f = fopen(fname, "w"))) { // Error opening file g_printerr("%s: %s\n", fname, g_strerror(errno)); ok = FALSE; } else { GtkTextIter start, end, p; // Get the starting and ending position gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(editor_buf), &start, &end); p = start; while (!gtk_text_iter_equal(&start, &end)) { gchar *buf, *fbuf; gsize br, bw; GError *err = NULL; gtk_text_iter_forward_chars(&p, CHAR_BUF); buf = gtk_text_iter_get_slice(&start, &p); fbuf = g_locale_from_utf8(buf, -1, &br, &bw, &err); g_free(buf); if (!fbuf) { g_printerr("Failed UTF-8 to locale conversion: %s\n", err->message); g_clear_error(&err); ok = FALSE; break; } fwrite(fbuf, bw, 1, f); g_free(fbuf); if (ferror(f)) { g_printerr("%s: %s\n", fname, g_strerror(errno)); ok = FALSE; break; } start = p; } if (fclose(f) == EOF) { g_printerr("%s: %s\n", fname, g_strerror(errno)); ok = FALSE; } } if (ok) { gtk_text_buffer_set_modified(editor_buf, FALSE); if (fname != filename) { gchar *wt = g_strdup_printf("TextView (%s)", fname); g_free(filename); filename = fname; gtk_window_set_title(GTK_WINDOW(editor_window), wt); g_free(wt); } } return ok; }
void note_show(ConboyNote *note, gboolean modify_history, gboolean scroll, gboolean select_row) { AppData *app_data = app_data_get(); UserInterface *ui = app_data->note_window; GtkTextBuffer *buffer = ui->buffer; GtkWindow *window = GTK_WINDOW(ui->window); /* Before we switch to a new note, we save the last one if it was modified. */ if (gtk_text_buffer_get_modified(buffer)) { note_save(ui); } /* Add to history */ if (modify_history || app_data->current_element == NULL) { add_to_history(note); } /* Toggle forward/backward buttons */ gtk_action_set_sensitive(ui->action_back, (gboolean) app_data->current_element->prev); gtk_action_set_sensitive(ui->action_forward, (gboolean) app_data->current_element->next); /* Block signals on TextBuffer until we are done with initializing the content. This is to prevent saves etc. */ g_signal_handlers_block_matched(buffer, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, ui); conboy_note_window_show_note(ui, note); /* Format note title and update window title */ note_format_title(buffer); note_set_window_title_from_buffer(window, buffer); /* Replace this. And use note->title instead */ /* Show widget and set focus to the text view */ gtk_widget_show(GTK_WIDGET(window)); gtk_widget_grab_focus(GTK_WIDGET(ui->view)); while (gtk_events_pending()) { gtk_main_iteration_do(FALSE); } /* Select first row if wanted */ if (select_row) { GtkTextIter start, end; gtk_text_buffer_get_iter_at_line(buffer, &start, 2); end = start; gtk_text_iter_forward_to_line_end(&end); gtk_text_buffer_select_range(buffer, &start, &end); } /* Scroll to cursor position */ if (scroll && !select_row) { GtkTextIter iter; gtk_text_buffer_get_iter_at_offset(buffer, &iter, note->cursor_position); gtk_text_buffer_place_cursor(buffer, &iter); GtkTextMark *mark = gtk_text_buffer_get_insert(buffer); gtk_text_view_scroll_to_mark(ui->view, mark, 0.1, TRUE, 0, 0.5); } /* Set the buffer to unmodified */ gtk_text_buffer_set_modified(buffer, FALSE); /* unblock signals */ g_signal_handlers_unblock_matched(buffer, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, ui); /* Update active tags */ conboy_note_buffer_update_active_tags(CONBOY_NOTE_BUFFER(buffer)); /* Update the state of the buttons */ conboy_note_window_update_button_states(ui); }
gint main(gint argc, gchar **argv) { Conf *conf; gchar *stdin_data = NULL; bindtextdomain(PACKAGE, LOCALEDIR); bind_textdomain_codeset(PACKAGE, "UTF-8"); textdomain(PACKAGE); pub = g_malloc(sizeof(PublicData)); pub->fi = g_malloc(sizeof(FileInfo)); pub->fi->filename = NULL; pub->fi->charset = NULL; pub->fi->charset_flag = FALSE; pub->fi->lineend = LF; parse_args(argc, argv, pub->fi); #if !ENABLE_XINPUT2 gdk_disable_multidevice(); #endif gtk_init(&argc, &argv); g_set_application_name(PACKAGE_NAME); selection_primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY); pub->mw = create_main_window(); conf = g_malloc(sizeof(Conf)); conf->width = 600; conf->height = 400; conf->fontname = g_strdup("Monospace 12"); conf->wordwrap = FALSE; conf->linenumbers = FALSE; conf->autoindent = FALSE; load_config_file(conf); gtk_window_set_default_size( GTK_WINDOW(pub->mw->window), conf->width, conf->height); set_text_font_by_name(pub->mw->view, conf->fontname); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(pub->mw->menubar, "/M/Options/WordWrap")), conf->wordwrap); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(pub->mw->menubar, "/M/Options/LineNumbers")), conf->linenumbers); indent_refresh_tab_width(pub->mw->view); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(pub->mw->menubar, "/M/Options/AutoIndent")), conf->autoindent); gtk_widget_show_all(pub->mw->window); g_free(conf->fontname); g_free(conf); #if ENABLE_EMACS check_emacs_key_theme(GTK_WINDOW(pub->mw->window), pub->mw->menubar); #endif hlight_init(pub->mw->buffer); undo_init(pub->mw->view, gtk_item_factory_get_widget(pub->mw->menubar, "/M/Edit/Undo"), gtk_item_factory_get_widget(pub->mw->menubar, "/M/Edit/Redo")); // hlight_init(pub->mw->buffer); dnd_init(pub->mw->view); if (pub->fi->filename) file_open_real(pub->mw->view, pub->fi); #ifdef G_OS_UNIX else stdin_data = gedit_utils_get_stdin(); #endif if (stdin_data) { gchar *str; GtkTextIter iter; str = g_convert(stdin_data, -1, "UTF-8", get_default_charset(), NULL, NULL, NULL); g_free(stdin_data); // gtk_text_buffer_set_text(buffer, "", 0); gtk_text_buffer_get_start_iter(pub->mw->buffer, &iter); gtk_text_buffer_insert(pub->mw->buffer, &iter, str, strlen(str)); gtk_text_buffer_get_start_iter(pub->mw->buffer, &iter); gtk_text_buffer_place_cursor(pub->mw->buffer, &iter); gtk_text_buffer_set_modified(pub->mw->buffer, FALSE); gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(pub->mw->view), &iter, 0, FALSE, 0, 0); g_free(str); } if (jump_linenum) { GtkTextIter iter; gtk_text_buffer_get_iter_at_line(pub->mw->buffer, &iter, jump_linenum - 1); gtk_text_buffer_place_cursor(pub->mw->buffer, &iter); // gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview), &iter, 0.1, FALSE, 0.5, 0.5); scroll_to_cursor(pub->mw->buffer, 0.25); } set_main_window_title(); indent_refresh_tab_width(pub->mw->view); // hlight_apply_all(pub->mw->buffer); gtk_main(); return 0; }