static void peacock_file_load_async_open_cb (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer data) { PeacockFile *file = PEACOCK_FILE (data); #ifdef PEACOCK_FILE_DEBUG g_warning ("peacock_file_load_async_open_cb(): Error opening file to read: %s.\n", gnome_vfs_result_to_string (result)); #endif if (result != GNOME_VFS_OK) { /* * Display UI error dialog. */ gchar *err_msg = g_strdup_printf (_("Error opening file to load.\nReason - %s.\n"), gnome_vfs_result_to_string (result)); peacock_file_util_show_ui_error (err_msg); g_free (err_msg); /* * Cleanup. Destructor peacock_file_finalize handles * PeacockFile related memory. */ g_object_unref (file); return; } else { gchar *buffer = g_malloc (PEACOCK_FILE_READ_WRITE_BUF_SIZE); gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (file)); gnome_vfs_async_read (handle, buffer, PEACOCK_FILE_READ_WRITE_BUF_SIZE, peacock_file_load_async_read_cb, data); } }
static void gb_view_source_set_file (GbViewSource *source, GFile *file) { GbViewSourcePrivate *priv; gchar *contents = NULL; gsize size; g_return_if_fail(GB_IS_VIEW_SOURCE(source)); g_return_if_fail(G_IS_FILE(file)); priv = source->priv; /* * TODO: Do this all aysnc. */ priv->file = g_object_ref(file); gb_view_source_set_file_attribs(source, file); if (g_file_get_contents(g_file_get_path(file), &contents, &size, NULL)) { gtk_source_buffer_begin_not_undoable_action(priv->buffer); gtk_text_buffer_set_text(GTK_TEXT_BUFFER(priv->buffer), contents, size); gtk_source_buffer_end_not_undoable_action(priv->buffer); gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(priv->buffer), FALSE); gb_view_source_goto_start(GTK_TEXT_BUFFER(priv->buffer)); g_free(contents); } }
void set_buffer(){ gtk_source_buffer_begin_not_undoable_action(GTK_SOURCE_BUFFER(mBuff)); gtk_text_buffer_set_text(GTK_TEXT_BUFFER(mBuff),content,-1); g_free(content); gtk_source_buffer_end_not_undoable_action(GTK_SOURCE_BUFFER(mBuff)); gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(mBuff),FALSE); GtkTextIter iter; gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(mBuff),&iter); gtk_text_buffer_place_cursor(GTK_TEXT_BUFFER(mBuff),&iter); }
void new_file(){ //unsigned int u_id //GtkSourceBuffer *tBuff=(GtkSourceBuffer *)tpad_buff_get_buff(u_id); if(save_modified()) { gtk_source_buffer_begin_not_undoable_action(GTK_SOURCE_BUFFER(mBuff)); gtk_text_buffer_set_text(GTK_TEXT_BUFFER(mBuff),"",-1); gtk_source_buffer_end_not_undoable_action(GTK_SOURCE_BUFFER(mBuff)); gtk_text_buffer_set_modified(GTK_TEXT_BUFFER(mBuff),FALSE); gtk_window_set_title(GTK_WINDOW(window),_FALLBACK_SAVE_FILE_NAME); save_locked=FALSE; } }
static void insert_text_in_document(SourceviewIO* sio, const gchar* text, gsize len) { GtkSourceBuffer* document = GTK_SOURCE_BUFFER (sio->sv->priv->document); gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (sio->sv->priv->document)); /* Insert text in the buffer */ gtk_text_buffer_set_text (GTK_TEXT_BUFFER (document), text, len); gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (document), FALSE); gtk_source_buffer_end_not_undoable_action (document); }
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); }
static gssize gedit_document_output_stream_write (GOutputStream *stream, const void *buffer, gsize count, GCancellable *cancellable, GError **error) { GeditDocumentOutputStream *ostream; gchar *text; gsize len; gboolean freetext = FALSE; if (g_cancellable_set_error_if_cancelled (cancellable, error)) { return -1; } ostream = GEDIT_DOCUMENT_OUTPUT_STREAM (stream); if (!ostream->priv->is_initialized) { ostream->priv->charset_conv = guess_encoding (ostream, buffer, count); /* If we still have the previous case is that we didn't guess anything */ if (ostream->priv->charset_conv == NULL && !ostream->priv->is_utf8) { g_set_error_literal (error, GEDIT_DOCUMENT_ERROR, GEDIT_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED, _("It is not possible to detect the encoding automatically")); return -1; } /* Do not initialize iconv if we are not going to convert anything */ if (!ostream->priv->is_utf8) { gchar *from_charset; /* Initialize iconv */ g_object_get (G_OBJECT (ostream->priv->charset_conv), "from-charset", &from_charset, NULL); ostream->priv->iconv = g_iconv_open ("UTF-8", from_charset); if (ostream->priv->iconv == (GIConv)-1) { if (errno == EINVAL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Conversion from character set '%s' to 'UTF-8' is not supported"), from_charset); } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Could not open converter from '%s' to 'UTF-8'"), from_charset); } g_free (from_charset); g_clear_object (&ostream->priv->charset_conv); return -1; } g_free (from_charset); } /* Init the undoable action */ gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (ostream->priv->doc)); gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->priv->doc), &ostream->priv->pos); ostream->priv->is_initialized = TRUE; } if (ostream->priv->buflen > 0) { len = ostream->priv->buflen + count; text = g_malloc (len + 1); memcpy (text, ostream->priv->buffer, ostream->priv->buflen); memcpy (text + ostream->priv->buflen, buffer, count); text[len] = '\0'; g_free (ostream->priv->buffer); ostream->priv->buffer = NULL; ostream->priv->buflen = 0; freetext = TRUE; } else { text = (gchar *) buffer; len = count; } if (!ostream->priv->is_utf8) { gchar *outbuf; gsize outbuf_len; /* check if iconv was correctly initializated, this shouldn't happen but better be safe */ if (ostream->priv->iconv == NULL) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED, _("Invalid object, not initialized")); if (freetext) { g_free (text); } return -1; } /* manage the previous conversion buffer */ if (ostream->priv->iconv_buflen > 0) { gchar *text2; gsize len2; len2 = len + ostream->priv->iconv_buflen; text2 = g_malloc (len2 + 1); memcpy (text2, ostream->priv->iconv_buffer, ostream->priv->iconv_buflen); memcpy (text2 + ostream->priv->iconv_buflen, text, len); text2[len2] = '\0'; if (freetext) { g_free (text); } text = text2; len = len2; g_free (ostream->priv->iconv_buffer); ostream->priv->iconv_buffer = NULL; ostream->priv->iconv_buflen = 0; freetext = TRUE; } if (!convert_text (ostream, text, len, &outbuf, &outbuf_len, error)) { if (freetext) { g_free (text); } return -1; } if (freetext) { g_free (text); } /* set the converted text as the text to validate */ text = outbuf; len = outbuf_len; } validate_and_insert (ostream, text, len); if (freetext) { g_free (text); } return count; }
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"); } }