[evolution] Improve and fix various dialogs.
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Improve and fix various dialogs.
- Date: Thu, 2 Oct 2014 08:56:13 +0000 (UTC)
commit 8df9d94f9a9722829ca8ae3ef1ea2335cc711708
Author: Tomas Popela <tpopela redhat com>
Date: Thu Oct 2 10:47:51 2014 +0200
Improve and fix various dialogs.
In EHTMLEditorCellDialog and EHTMLEditorTableDialog encode the
background images for elements into the base64 format to prevent
from deleting them when sending the HTML message. Also set the default
background color in these dialogs to transparent. In dialogs previously
mentioned and as well as in EHTMLEditorPageDialog add the button to
remove the previously set background image.
e-util/e-html-editor-cell-dialog.c | 91 ++++++++++++++++++++++++---------
e-util/e-html-editor-page-dialog.c | 50 +++++++++++++++++--
e-util/e-html-editor-table-dialog.c | 96 ++++++++++++++++++++++++++---------
3 files changed, 184 insertions(+), 53 deletions(-)
---
diff --git a/e-util/e-html-editor-cell-dialog.c b/e-util/e-html-editor-cell-dialog.c
index 0a93645..2c9680b 100644
--- a/e-util/e-html-editor-cell-dialog.c
+++ b/e-util/e-html-editor-cell-dialog.c
@@ -28,9 +28,11 @@
#include <stdlib.h>
#include "e-color-combo.h"
+#include "e-dialog-widgets.h"
#include "e-html-editor-utils.h"
#include "e-image-chooser-dialog.h"
#include "e-misc-utils.h"
+#include "e-misc-utils.h"
#define E_HTML_EDITOR_CELL_DIALOG_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
@@ -58,6 +60,8 @@ struct _EHTMLEditorCellDialogPrivate {
GtkWidget *background_color_picker;
GtkWidget *background_image_chooser;
+ GtkWidget *remove_image_button;
+
WebKitDOMElement *cell;
guint scope;
};
@@ -69,7 +73,7 @@ enum {
SCOPE_TABLE
} DialogScope;
-static GdkRGBA white = { 1, 1, 1, 1 };
+static GdkRGBA transparent = { 0, 0, 0, 0 };
typedef void (*DOMStrFunc) (WebKitDOMHTMLTableCellElement *cell, const gchar *val, gpointer user_data);
typedef void (*DOMUlongFunc) (WebKitDOMHTMLTableCellElement *cell, gulong val, gpointer user_data);
@@ -414,13 +418,16 @@ html_editor_cell_dialog_set_row_span (EHTMLEditorCellDialog *dialog)
static void
html_editor_cell_dialog_set_background_color (EHTMLEditorCellDialog *dialog)
{
- gchar *color;
+ gchar *color = NULL;
GdkRGBA rgba;
GValue val = { 0 };
e_color_combo_get_current_color (
E_COLOR_COMBO (dialog->priv->background_color_picker), &rgba);
- color = g_strdup_printf ("#%06x", e_rgba_to_value (&rgba));
+ if (rgba.alpha != 0.0)
+ color = g_strdup_printf ("#%06x", e_rgba_to_value (&rgba));
+ else
+ color = g_strdup ("");
g_value_init (&val, G_TYPE_STRING);
g_value_take_string (&val, color);
@@ -434,31 +441,51 @@ html_editor_cell_dialog_set_background_color (EHTMLEditorCellDialog *dialog)
static void
cell_set_background_image (WebKitDOMHTMLTableCellElement *cell,
const gchar *uri,
- gpointer user_data)
+ EHTMLEditorCellDialog *dialog)
{
- if (!uri || !*uri) {
- webkit_dom_element_remove_attribute (
- WEBKIT_DOM_ELEMENT (cell), "background");
- } else {
- webkit_dom_element_set_attribute (
- WEBKIT_DOM_ELEMENT (cell), "background", uri, NULL);
- }
+ EHTMLEditor *editor;
+ EHTMLEditorView *view;
+
+ editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+ view = e_html_editor_get_view (editor);
+
+ if (uri && *uri) {
+ e_html_editor_selection_replace_image_src (
+ e_html_editor_view_get_selection (view),
+ WEBKIT_DOM_ELEMENT (cell),
+ uri);
+ } else
+ remove_image_attributes_from_element (WEBKIT_DOM_ELEMENT (cell));
+
+ gtk_widget_set_sensitive (dialog->priv->remove_image_button, uri && *uri);
}
static void
html_editor_cell_dialog_set_background_image (EHTMLEditorCellDialog *dialog)
{
- const gchar *uri;
+ gchar *uri;
GValue val = { 0 };
uri = gtk_file_chooser_get_uri (
GTK_FILE_CHOOSER (dialog->priv->background_image_chooser));
g_value_init (&val, G_TYPE_STRING);
- g_value_take_string (&val, (gchar *) uri);
+ g_value_take_string (&val, uri);
html_editor_cell_dialog_set_attribute (
- dialog, cell_set_background_image, &val, NULL);
+ dialog, cell_set_background_image, &val, dialog);
+}
+
+static void
+html_editor_cell_dialog_remove_image (EHTMLEditorCellDialog *dialog)
+{
+ remove_image_attributes_from_element (
+ WEBKIT_DOM_ELEMENT (dialog->priv->cell));
+
+ gtk_file_chooser_unselect_all (
+ GTK_FILE_CHOOSER (dialog->priv->background_image_chooser));
+
+ gtk_widget_set_sensitive (dialog->priv->remove_image_button, FALSE);
}
static void
@@ -529,7 +556,7 @@ html_editor_cell_dialog_show (GtkWidget *widget)
if (webkit_dom_element_has_attribute (
WEBKIT_DOM_ELEMENT (dialog->priv->cell), "background")) {
tmp = webkit_dom_element_get_attribute (
- WEBKIT_DOM_ELEMENT (dialog->priv->cell), "background");
+ WEBKIT_DOM_ELEMENT (dialog->priv->cell), "data-uri");
gtk_file_chooser_set_uri (
GTK_FILE_CHOOSER (dialog->priv->background_image_chooser),
@@ -543,17 +570,20 @@ html_editor_cell_dialog_show (GtkWidget *widget)
tmp = webkit_dom_html_table_cell_element_get_bg_color (
WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (dialog->priv->cell));
- if (!tmp || *tmp) {
- color = white;
- }
- if (gdk_rgba_parse (&color, tmp)) {
- e_color_combo_set_current_color (
- E_COLOR_COMBO (dialog->priv->background_color_picker),
- &color);
+ if (tmp && *tmp) {
+ if (gdk_rgba_parse (&color, tmp)) {
+ e_color_combo_set_current_color (
+ E_COLOR_COMBO (dialog->priv->background_color_picker),
+ &color);
+ } else {
+ e_color_combo_set_current_color (
+ E_COLOR_COMBO (dialog->priv->background_color_picker),
+ &transparent);
+ }
} else {
e_color_combo_set_current_color (
E_COLOR_COMBO (dialog->priv->background_color_picker),
- &white);
+ &transparent);
}
g_free (tmp);
@@ -574,6 +604,7 @@ e_html_editor_cell_dialog_class_init (EHTMLEditorCellDialogClass *class)
static void
e_html_editor_cell_dialog_init (EHTMLEditorCellDialog *dialog)
{
+ GtkBox *box;
GtkGrid *main_layout, *grid;
GtkWidget *widget;
GtkFileFilter *file_filter;
@@ -799,7 +830,8 @@ e_html_editor_cell_dialog_init (EHTMLEditorCellDialog *dialog)
/* Color */
widget = e_color_combo_new ();
- e_color_combo_set_default_color (E_COLOR_COMBO (widget), &white);
+ e_color_combo_set_default_color (E_COLOR_COMBO (widget), &transparent);
+ e_color_combo_set_default_label (E_COLOR_COMBO (widget), _("Transparent"));
gtk_widget_set_hexpand (widget, TRUE);
gtk_grid_attach (grid, widget, 1, 0, 1, 1);
g_signal_connect_swapped (
@@ -839,6 +871,17 @@ e_html_editor_cell_dialog_init (EHTMLEditorCellDialog *dialog)
GTK_LABEL (widget), dialog->priv->background_image_chooser);
gtk_grid_attach (grid, widget, 0, 1, 1, 1);
+ box = e_html_editor_dialog_get_button_box (E_HTML_EDITOR_DIALOG (dialog));
+ widget = e_dialog_button_new_with_icon (NULL, _("_Remove image"));
+ g_signal_connect_swapped (
+ widget, "clicked",
+ G_CALLBACK (html_editor_cell_dialog_remove_image), dialog);
+ dialog->priv->remove_image_button = widget;
+
+ gtk_widget_set_sensitive (dialog->priv->remove_image_button, FALSE);
+ gtk_box_pack_start (box, widget, FALSE, FALSE, 5);
+ gtk_box_reorder_child (box, widget, 0);
+
gtk_widget_show_all (GTK_WIDGET (main_layout));
}
diff --git a/e-util/e-html-editor-page-dialog.c b/e-util/e-html-editor-page-dialog.c
index b01e15b..8dd8997 100644
--- a/e-util/e-html-editor-page-dialog.c
+++ b/e-util/e-html-editor-page-dialog.c
@@ -28,6 +28,7 @@
#include "e-color-combo.h"
#include "e-misc-utils.h"
+#include "e-dialog-widgets.h"
#define E_HTML_EDITOR_PAGE_DIALOG_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
@@ -40,6 +41,8 @@ struct _EHTMLEditorPageDialogPrivate {
GtkWidget *background_template_combo;
GtkWidget *background_image_filechooser;
+
+ GtkWidget *remove_image_button;
};
typedef struct _Template {
@@ -207,8 +210,10 @@ html_editor_page_dialog_set_background_color (EHTMLEditorPageDialog *dialog)
e_color_combo_get_current_color (
E_COLOR_COMBO (dialog->priv->background_color_picker), &rgba);
-
- color = g_strdup_printf ("#%06x", e_rgba_to_value (&rgba));
+ if (rgba.alpha != 0.0)
+ color = g_strdup_printf ("#%06x", e_rgba_to_value (&rgba));
+ else
+ color = g_strdup ("");
webkit_dom_html_body_element_set_bg_color (
WEBKIT_DOM_HTML_BODY_ELEMENT (body), color);
@@ -270,17 +275,42 @@ html_editor_page_dialog_set_background_image (EHTMLEditorPageDialog *dialog)
GTK_FILE_CHOOSER (
dialog->priv->background_image_filechooser));
- if (uri && *uri) {
+ if (uri && *uri)
e_html_editor_selection_replace_image_src (
e_html_editor_view_get_selection (view),
WEBKIT_DOM_ELEMENT (body),
uri);
- }
+ else
+ remove_image_attributes_from_element (
+ WEBKIT_DOM_ELEMENT (body));
+
+ gtk_widget_set_sensitive (dialog->priv->remove_image_button, uri && *uri);
g_free (uri);
}
static void
+html_editor_page_dialog_remove_image (EHTMLEditorPageDialog *dialog)
+{
+ EHTMLEditor *editor;
+ EHTMLEditorView *view;
+ WebKitDOMDocument *document;
+ WebKitDOMHTMLElement *body;
+
+ editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+ view = e_html_editor_get_view (editor);
+ document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
+ body = webkit_dom_document_get_body (document);
+
+ remove_image_attributes_from_element (WEBKIT_DOM_ELEMENT (body));
+
+ gtk_file_chooser_unselect_all (
+ GTK_FILE_CHOOSER (dialog->priv->background_image_filechooser));
+
+ gtk_widget_set_sensitive (dialog->priv->remove_image_button, FALSE);
+}
+
+static void
html_editor_page_dialog_show (GtkWidget *widget)
{
EHTMLEditor *editor;
@@ -371,6 +401,7 @@ e_html_editor_page_dialog_class_init (EHTMLEditorPageDialogClass *class)
static void
e_html_editor_page_dialog_init (EHTMLEditorPageDialog *dialog)
{
+ GtkBox *box;
GtkGrid *grid, *main_layout;
GtkWidget *widget;
gint ii;
@@ -481,6 +512,17 @@ e_html_editor_page_dialog_init (EHTMLEditorPageDialog *dialog)
GTK_LABEL (widget), dialog->priv->background_image_filechooser);
gtk_grid_attach (grid, widget, 0, 1, 1, 1);
+ box = e_html_editor_dialog_get_button_box (E_HTML_EDITOR_DIALOG (dialog));
+ widget = e_dialog_button_new_with_icon (NULL, _("_Remove image"));
+ g_signal_connect_swapped (
+ widget, "clicked",
+ G_CALLBACK (html_editor_page_dialog_remove_image), dialog);
+ dialog->priv->remove_image_button = widget;
+
+ gtk_widget_set_sensitive (dialog->priv->remove_image_button, FALSE);
+ gtk_box_pack_start (box, widget, FALSE, FALSE, 5);
+ gtk_box_reorder_child (box, widget, 0);
+
gtk_widget_show_all (GTK_WIDGET (main_layout));
}
diff --git a/e-util/e-html-editor-table-dialog.c b/e-util/e-html-editor-table-dialog.c
index 467d2a6..bd434a2 100644
--- a/e-util/e-html-editor-table-dialog.c
+++ b/e-util/e-html-editor-table-dialog.c
@@ -27,6 +27,7 @@
#include <glib/gi18n-lib.h>
#include "e-color-combo.h"
+#include "e-dialog-widgets.h"
#include "e-html-editor-utils.h"
#include "e-image-chooser-dialog.h"
#include "e-misc-utils.h"
@@ -53,10 +54,12 @@ struct _EHTMLEditorTableDialogPrivate {
GtkWidget *background_image_button;
GtkWidget *image_chooser_dialog;
+ GtkWidget *remove_image_button;
+
WebKitDOMHTMLTableElement *table_element;
};
-static GdkRGBA white = { 1, 1, 1, 1 };
+static GdkRGBA transparent = { 0, 0, 0, 0 };
G_DEFINE_TYPE (
EHTMLEditorTableDialog,
@@ -443,8 +446,11 @@ html_editor_table_dialog_set_background_color (EHTMLEditorTableDialog *dialog)
e_color_combo_get_current_color (
E_COLOR_COMBO (dialog->priv->background_color_button), &rgba);
- color = g_strdup_printf (
- "#%06x", e_rgba_to_value (&rgba));
+
+ if (rgba.alpha != 0.0)
+ color = g_strdup_printf ("#%06x", e_rgba_to_value (&rgba));
+ else
+ color = g_strdup ("");
webkit_dom_html_table_element_set_bg_color (
dialog->priv->table_element, color);
@@ -463,10 +469,15 @@ html_editor_table_dialog_get_background_color (EHTMLEditorTableDialog *dialog)
color = webkit_dom_html_table_element_get_bg_color (
dialog->priv->table_element);
- gdk_rgba_parse (&rgba, color);
+ if (color && *color) {
+ gdk_rgba_parse (&rgba, color);
- e_color_combo_set_current_color (
- E_COLOR_COMBO (dialog->priv->background_color_button), &rgba);
+ e_color_combo_set_current_color (
+ E_COLOR_COMBO (dialog->priv->background_color_button), &rgba);
+ } else {
+ e_color_combo_set_current_color (
+ E_COLOR_COMBO (dialog->priv->background_color_button), &transparent);
+ }
g_free (color);
}
@@ -474,22 +485,30 @@ html_editor_table_dialog_get_background_color (EHTMLEditorTableDialog *dialog)
static void
html_editor_table_dialog_set_background_image (EHTMLEditorTableDialog *dialog)
{
- const gchar *filename;
+ EHTMLEditor *editor;
+ EHTMLEditorView *view;
+ gchar *uri;
g_return_if_fail (dialog->priv->table_element);
- filename = gtk_file_chooser_get_filename (
- GTK_FILE_CHOOSER (dialog->priv->background_image_button));
+ editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+ view = e_html_editor_get_view (editor);
- if (filename) {
- webkit_dom_element_set_attribute (
- WEBKIT_DOM_ELEMENT (dialog->priv->table_element),
- "background", filename, NULL);
- } else {
- webkit_dom_element_remove_attribute (
+ uri = gtk_file_chooser_get_uri (
+ GTK_FILE_CHOOSER (dialog->priv->background_image_button));
+
+ if (uri && *uri)
+ e_html_editor_selection_replace_image_src (
+ e_html_editor_view_get_selection (view),
WEBKIT_DOM_ELEMENT (dialog->priv->table_element),
- "background");
- }
+ uri);
+ else
+ remove_image_attributes_from_element (
+ WEBKIT_DOM_ELEMENT (dialog->priv->table_element));
+
+ gtk_widget_set_sensitive (dialog->priv->remove_image_button, uri && *uri);
+
+ g_free (uri);
}
static void
@@ -497,6 +516,7 @@ html_editor_table_dialog_get_background_image (EHTMLEditorTableDialog *dialog)
{
g_return_if_fail (dialog->priv->table_element);
+
if (!webkit_dom_element_has_attribute (
WEBKIT_DOM_ELEMENT (dialog->priv->table_element), "background")) {
@@ -504,16 +524,16 @@ html_editor_table_dialog_get_background_image (EHTMLEditorTableDialog *dialog)
GTK_FILE_CHOOSER (dialog->priv->background_image_button));
return;
} else {
- gchar *background;
+ gchar *value;
- background = webkit_dom_element_get_attribute (
- WEBKIT_DOM_ELEMENT (dialog->priv->table_element), "background");
+ value = webkit_dom_element_get_attribute (
+ WEBKIT_DOM_ELEMENT (dialog->priv->table_element), "data-uri");
- gtk_file_chooser_set_filename (
+ gtk_file_chooser_set_uri (
GTK_FILE_CHOOSER (dialog->priv->background_image_button),
- background);
+ value);
- g_free (background);
+ g_free (value);
}
}
@@ -556,7 +576,8 @@ html_editor_table_dialog_reset_values (EHTMLEditorTableDialog *dialog)
GTK_SPIN_BUTTON (dialog->priv->border_edit), 1);
e_color_combo_set_current_color (
- E_COLOR_COMBO (dialog->priv->background_color_button), &white);
+ E_COLOR_COMBO (dialog->priv->background_color_button), &transparent);
+
gtk_file_chooser_unselect_all (
GTK_FILE_CHOOSER (dialog->priv->background_image_button));
@@ -612,6 +633,18 @@ html_editor_table_dialog_show (GtkWidget *widget)
}
static void
+html_editor_table_dialog_remove_image (EHTMLEditorTableDialog *dialog)
+{
+ remove_image_attributes_from_element (
+ WEBKIT_DOM_ELEMENT (dialog->priv->table_element));
+
+ gtk_file_chooser_unselect_all (
+ GTK_FILE_CHOOSER (dialog->priv->background_image_button));
+
+ gtk_widget_set_sensitive (dialog->priv->remove_image_button, FALSE);
+}
+
+static void
html_editor_table_dialog_hide (GtkWidget *widget)
{
EHTMLEditorTableDialogPrivate *priv;
@@ -638,6 +671,7 @@ e_html_editor_table_dialog_class_init (EHTMLEditorTableDialogClass *class)
static void
e_html_editor_table_dialog_init (EHTMLEditorTableDialog *dialog)
{
+ GtkBox *box;
GtkGrid *main_layout, *grid;
GtkWidget *widget;
GtkFileFilter *file_filter;
@@ -810,7 +844,8 @@ e_html_editor_table_dialog_init (EHTMLEditorTableDialog *dialog)
/* Color */
widget = e_color_combo_new ();
- e_color_combo_set_default_color (E_COLOR_COMBO (widget), &white);
+ e_color_combo_set_default_color (E_COLOR_COMBO (widget), &transparent);
+ e_color_combo_set_default_label (E_COLOR_COMBO (widget), _("Transparent"));
gtk_widget_set_hexpand (widget, TRUE);
gtk_grid_attach (grid, widget, 1, 0, 1, 1);
g_signal_connect_swapped (
@@ -850,6 +885,17 @@ e_html_editor_table_dialog_init (EHTMLEditorTableDialog *dialog)
GTK_LABEL (widget), dialog->priv->background_image_button);
gtk_grid_attach (grid, widget, 0, 1, 1, 1);
+ box = e_html_editor_dialog_get_button_box (E_HTML_EDITOR_DIALOG (dialog));
+ widget = e_dialog_button_new_with_icon (NULL, _("_Remove image"));
+ g_signal_connect_swapped (
+ widget, "clicked",
+ G_CALLBACK (html_editor_table_dialog_remove_image), dialog);
+ dialog->priv->remove_image_button = widget;
+
+ gtk_widget_set_sensitive (dialog->priv->remove_image_button, FALSE);
+ gtk_box_pack_start (box, widget, FALSE, FALSE, 5);
+ gtk_box_reorder_child (box, widget, 0);
+
gtk_widget_show_all (GTK_WIDGET (main_layout));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]