gtkhtml r8729 - branches/mbarnes-composer/components/editor
- From: mbarnes svn gnome org
- To: svn-commits-list gnome org
- Subject: gtkhtml r8729 - branches/mbarnes-composer/components/editor
- Date: Sun, 10 Feb 2008 20:44:34 +0000 (GMT)
Author: mbarnes
Date: Sun Feb 10 20:44:33 2008
New Revision: 8729
URL: http://svn.gnome.org/viewvc/gtkhtml?rev=8729&view=rev
Log:
Add a "html-or-plaintext" option to gtkhtml_editor_save() and adapt the
GtkhtmlEditor test program to use it.
Modified:
branches/mbarnes-composer/components/editor/gtkhtml-editor.c
branches/mbarnes-composer/components/editor/gtkhtml-editor.h
branches/mbarnes-composer/components/editor/main.c
Modified: branches/mbarnes-composer/components/editor/gtkhtml-editor.c
==============================================================================
--- branches/mbarnes-composer/components/editor/gtkhtml-editor.c (original)
+++ branches/mbarnes-composer/components/editor/gtkhtml-editor.c Sun Feb 10 20:44:33 2008
@@ -917,7 +917,7 @@
guint length,
GString *contents)
{
- g_string_assign (contents, data);
+ g_string_append_len (contents, data, length);
return TRUE;
}
@@ -992,6 +992,7 @@
gboolean
gtkhtml_editor_save (GtkhtmlEditor *editor,
const gchar *filename,
+ gboolean as_html,
GError **error)
{
gchar *contents;
@@ -1001,8 +1002,13 @@
g_return_val_if_fail (GTKHTML_IS_EDITOR (editor), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
- contents = gtkhtml_editor_get_text_html (editor, &length);
+ if (as_html)
+ contents = gtkhtml_editor_get_text_html (editor, &length);
+ else
+ contents = gtkhtml_editor_get_text_plain (editor, &length);
+
success = g_file_set_contents (filename, contents, length, error);
+
g_free (contents);
if (success) {
Modified: branches/mbarnes-composer/components/editor/gtkhtml-editor.h
==============================================================================
--- branches/mbarnes-composer/components/editor/gtkhtml-editor.h (original)
+++ branches/mbarnes-composer/components/editor/gtkhtml-editor.h Sun Feb 10 20:44:33 2008
@@ -111,6 +111,7 @@
gssize length);
gboolean gtkhtml_editor_save (GtkhtmlEditor *editor,
const gchar *filename,
+ gboolean as_html,
GError **error);
const gchar * gtkhtml_editor_get_paragraph_data
(GtkhtmlEditor *editor,
Modified: branches/mbarnes-composer/components/editor/main.c
==============================================================================
--- branches/mbarnes-composer/components/editor/main.c (original)
+++ branches/mbarnes-composer/components/editor/main.c Sun Feb 10 20:44:33 2008
@@ -57,8 +57,6 @@
" </menubar>\n"
"</ui>";
-static gchar *save_filename;
-
static void
handle_error (GError **error)
{
@@ -92,6 +90,7 @@
save_dialog (GtkhtmlEditor *editor)
{
GtkWidget *dialog;
+ const gchar *filename;
gint response;
dialog = gtk_file_chooser_dialog_new (
@@ -104,9 +103,11 @@
gtk_file_chooser_set_do_overwrite_confirmation (
GTK_FILE_CHOOSER (dialog), TRUE);
- if (save_filename != NULL)
+ filename = gtkhtml_editor_get_filename (editor);
+
+ if (filename != NULL)
gtk_file_chooser_set_filename (
- GTK_FILE_CHOOSER (dialog), save_filename);
+ GTK_FILE_CHOOSER (dialog), filename);
else {
gtk_file_chooser_set_current_folder (
GTK_FILE_CHOOSER (dialog), g_get_home_dir ());
@@ -117,9 +118,12 @@
response = gtk_dialog_run (GTK_DIALOG (dialog));
if (response == GTK_RESPONSE_ACCEPT) {
- g_free (save_filename);
- save_filename = gtk_file_chooser_get_filename (
+ gchar *new_filename;
+
+ new_filename = gtk_file_chooser_get_filename (
GTK_FILE_CHOOSER (dialog));
+ gtkhtml_editor_set_filename (editor, new_filename);
+ g_free (new_filename);
}
gtk_widget_destroy (dialog);
@@ -228,13 +232,18 @@
action_save_cb (GtkAction *action,
GtkhtmlEditor *editor)
{
+ const gchar *filename;
+ gboolean as_html;
GError *error = NULL;
- if (save_filename == NULL)
+ if (gtkhtml_editor_get_filename (editor) == NULL)
if (save_dialog (editor) == GTK_RESPONSE_CANCEL)
return;
- gtkhtml_editor_save (editor, save_filename, &error);
+ filename = gtkhtml_editor_get_filename (editor);
+ as_html = gtkhtml_editor_get_html_mode (editor);
+
+ gtkhtml_editor_save (editor, filename, as_html, &error);
handle_error (&error);
}
@@ -242,12 +251,17 @@
action_save_as_cb (GtkAction *action,
GtkhtmlEditor *editor)
{
+ const gchar *filename;
+ gboolean as_html;
GError *error = NULL;
if (save_dialog (editor) == GTK_RESPONSE_CANCEL)
return;
- gtkhtml_editor_save (editor, save_filename, &error);
+ filename = gtkhtml_editor_get_filename (editor);
+ as_html = gtkhtml_editor_get_html_mode (editor);
+
+ gtkhtml_editor_save (editor, filename, as_html, &error);
handle_error (&error);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]