[gnumeric] Arrows: finish arrow property editor.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Arrows: finish arrow property editor.
- Date: Wed, 11 Feb 2015 20:25:41 +0000 (UTC)
commit 8edf8315f680de78193db2c8bcf80dd1a902486e
Author: Morten Welinder <terra gnome org>
Date: Wed Feb 11 15:24:56 2015 -0500
Arrows: finish arrow property editor.
NEWS | 1 +
src/commands.c | 97 ----------------------------------------
src/commands.h | 3 -
src/dialogs/dialog-so-styled.c | 84 ++++++++++++++++++++--------------
src/dialogs/dialogs.h | 3 +-
src/gnm-so-filled.c | 2 +-
src/gnm-so-line.c | 2 +-
src/gnm-so-path.c | 2 +-
src/gnm-so-polygon.c | 2 +-
9 files changed, 56 insertions(+), 140 deletions(-)
---
diff --git a/NEWS b/NEWS
index e9f8653..45a26f2 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ Morten:
* Initial xlsx export of sheet widgets.
* xlsx import/exports of patterns.
* Plug leaks.
+ * Arrow properties editor. [#158327]
--------------------------------------------------------------------------
Gnumeric 1.12.20
diff --git a/src/commands.c b/src/commands.c
index 317cbe8..ce586db 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -4752,103 +4752,6 @@ cmd_objects_move (WorkbookControl *wbc, GSList *objects, GSList *anchors,
/******************************************************************/
-#define CMD_OBJECT_FORMAT_TYPE (cmd_object_format_get_type ())
-#define CMD_OBJECT_FORMAT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CMD_OBJECT_FORMAT_TYPE, CmdObjectFormat))
-
-typedef struct {
- GnmCommand cmd;
- GObject *so, *style;
- char *text;
- PangoAttrList *attr;
- gboolean first_time;
-} CmdObjectFormat;
-
-MAKE_GNM_COMMAND (CmdObjectFormat, cmd_object_format, NULL)
-
-static gboolean
-cmd_object_format_redo (GnmCommand *cmd, G_GNUC_UNUSED WorkbookControl *wbc)
-{
- CmdObjectFormat *me = CMD_OBJECT_FORMAT (cmd);
- if (me->first_time)
- me->first_time = FALSE;
- else {
- GObject *prev;
-
- g_object_get (me->so, "style", &prev, NULL);
- g_object_set (me->so, "style", me->style, NULL);
- g_object_unref (me->style);
- me->style = prev;
- if (me->text != NULL) {
- char *old_text;
- g_object_get (me->so, "text", &old_text, NULL);
- g_object_set (me->so, "text", me->text, NULL);
- g_free (me->text);
- me->text = old_text;
- }
- if (me->attr != NULL) {
- PangoAttrList *old_attr;
- g_object_get (me->so, "markup", &old_attr, NULL);
- g_object_set (me->so, "markup", me->attr, NULL);
- pango_attr_list_unref (me->attr);
- me->attr = old_attr;
- pango_attr_list_ref (me->attr);
- }
- }
- sheet_mark_dirty (me->cmd.sheet);
- return FALSE;
-}
-
-static gboolean
-cmd_object_format_undo (GnmCommand *cmd, WorkbookControl *wbc)
-{
- return cmd_object_format_redo (cmd, wbc);
-}
-
-static void
-cmd_object_format_finalize (GObject *cmd)
-{
- CmdObjectFormat *me = CMD_OBJECT_FORMAT (cmd);
- g_object_unref (me->style);
- g_object_unref (me->so);
- g_free (me->text);
- if (me->attr)
- pango_attr_list_unref (me->attr);
- gnm_command_finalize (cmd);
-}
-
-/* Pass in the original style, we assume that the dialog was doing
- * instant apply. */
-gboolean
-cmd_object_format (WorkbookControl *wbc, SheetObject *so,
- gpointer orig_style, char *orig_text,
- PangoAttrList *orig_attr)
-{
- CmdObjectFormat *me;
-
- g_return_val_if_fail (IS_WORKBOOK_CONTROL (wbc), TRUE);
- g_return_val_if_fail (IS_SHEET_OBJECT (so), TRUE);
-
- me = g_object_new (CMD_OBJECT_FORMAT_TYPE, NULL);
-
- me->so = g_object_ref (so);
- me->style = g_object_ref (orig_style);
- me->text = g_strdup (orig_text);
- if (orig_attr != NULL) {
- me->attr = orig_attr;
- pango_attr_list_ref (me->attr);
- } else
- me->attr = NULL;
- me->first_time = TRUE;
-
- me->cmd.sheet = sheet_object_get_sheet (so);
- me->cmd.size = 1;
- me->cmd.cmd_descriptor = g_strdup (_("Format Object"));
-
- return gnm_command_push_undo (wbc, G_OBJECT (me));
-}
-
-/******************************************************************/
-
#define CMD_REORGANIZE_SHEETS_TYPE (cmd_reorganize_sheets_get_type ())
#define CMD_REORGANIZE_SHEETS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CMD_REORGANIZE_SHEETS_TYPE,
CmdReorganizeSheets))
diff --git a/src/commands.h b/src/commands.h
index 88e8cd7..85ae076 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -175,9 +175,6 @@ gboolean cmd_objects_delete (WorkbookControl *wbc, GSList *objects,
gboolean cmd_objects_move (WorkbookControl *wbc,
GSList *objects, GSList *anchors,
gboolean objects_created, char const *name);
-gboolean cmd_object_format (WorkbookControl *wbc, SheetObject *so,
- gpointer orig_style, char *orig_text,
- PangoAttrList *orig_attr);
gboolean cmd_so_graph_config (WorkbookControl *wbc, SheetObject *sog,
GObject *n_graph, GObject *o_graph);
diff --git a/src/dialogs/dialog-so-styled.c b/src/dialogs/dialog-so-styled.c
index 8e5b13a..9358aad 100644
--- a/src/dialogs/dialog-so-styled.c
+++ b/src/dialogs/dialog-so-styled.c
@@ -39,47 +39,61 @@
typedef struct {
GObject *so;
WBCGtk *wbcg;
- GOStyle *orig_style;
- char *orig_text;
- PangoAttrList *orig_attributes;
+ GSList *orig_props;
+
so_styled_t extent;
} DialogSOStyled;
#define GNM_SO_STYLED_KEY "gnm-so-styled-key"
static void
-dialog_so_styled_free (DialogSOStyled *pref)
+dialog_so_styled_free (DialogSOStyled *state)
{
- if (pref->orig_style != NULL) {
- g_object_set (G_OBJECT (pref->so), "style", pref->orig_style, NULL);
- g_object_unref (pref->orig_style);
- }
- if (pref->extent & SO_STYLED_TEXT) {
- g_object_set (G_OBJECT (pref->so), "text", pref->orig_text, NULL);
- g_free (pref->orig_text);
- g_object_set (G_OBJECT (pref->so), "markup", pref->orig_attributes, NULL);
- pango_attr_list_unref (pref->orig_attributes);
- }
- g_free (pref);
+ go_object_properties_apply (state->so, state->orig_props, TRUE);
+ go_object_properties_free (state->orig_props);
+ g_free (state);
+}
+
+static void
+force_new_style (GObject *so)
+{
+ GOStyle *style;
+
+ /* Ensure we have a new style object. */
+ g_object_get (so, "style", &style, NULL);
+ g_object_set (so, "style", style, NULL);
+ g_object_unref (style);
+}
+
+static void
+cb_set_props (gpointer a, gpointer b, gpointer data)
+{
+ go_object_properties_apply (a, b, TRUE);
+}
+
+static GOUndo *
+make_undo (GObject *so, GSList *props)
+{
+ return go_undo_binary_new (g_object_ref (so), props,
+ cb_set_props,
+ g_object_unref,
+ (GFreeFunc)go_object_properties_free);
}
static void
cb_dialog_so_styled_response (GtkWidget *dialog,
- gint response_id, DialogSOStyled *pref)
+ gint response_id, DialogSOStyled *state)
{
if (response_id == GTK_RESPONSE_HELP)
return;
if (response_id == GTK_RESPONSE_OK) {
- cmd_object_format (WORKBOOK_CONTROL (pref->wbcg),
- SHEET_OBJECT (pref->so), pref->orig_style,
- pref->orig_text, pref->orig_attributes);
- g_object_unref (pref->orig_style);
- pref->orig_style = NULL;
- g_free (pref->orig_text);
- pref->orig_text = NULL;
- pango_attr_list_unref (pref->orig_attributes);
- pref->orig_attributes = NULL;
- pref->extent = 0;
+ GSList *new_props = go_object_properties_collect (state->so);
+ force_new_style (state->so);
+ cmd_generic (WORKBOOK_CONTROL (state->wbcg),
+ _("Format Object"),
+ make_undo (state->so, state->orig_props),
+ make_undo (state->so, new_props));
+ state->orig_props = NULL;
}
gtk_widget_destroy (dialog);
}
@@ -110,12 +124,11 @@ dialog_so_styled_text_widget (DialogSOStyled *state)
g_object_get (state->so, "text", &strval, NULL);
g_object_set (gtv, "text", (strval == NULL) ? "" : strval, NULL);
- state->orig_text = strval;
+ g_free (strval);
g_object_get (state->so, "markup", &markup, NULL);
- state->orig_attributes = markup;
- pango_attr_list_ref (state->orig_attributes);
g_object_set (gtv, "attributes", markup, NULL);
+ /* unref? */
g_signal_connect (G_OBJECT (gtv), "changed",
G_CALLBACK (cb_dialog_so_styled_text_widget_changed), state);
@@ -155,12 +168,12 @@ dialog_so_styled_line_widget (DialogSOStyled *state, const char *prop)
}
void
-dialog_so_styled (WBCGtk *wbcg,
- GObject *so, GOStyle *orig, GOStyle *default_style,
+dialog_so_styled (WBCGtk *wbcg, GObject *so, GOStyle *default_style,
char const *title, so_styled_t extent)
{
DialogSOStyled *state;
GtkWidget *dialog, *help, *editor;
+ GOStyle *style;
/* Only pop up one copy per workbook */
if (gnumeric_dialog_raise_if_exists (wbcg, GNM_SO_STYLED_KEY)) {
@@ -171,8 +184,9 @@ dialog_so_styled (WBCGtk *wbcg,
state = g_new0 (DialogSOStyled, 1);
state->so = G_OBJECT (so);
state->wbcg = wbcg;
- state->orig_style = go_style_dup (orig);
- state->orig_text = NULL;
+ state->orig_props = go_object_properties_collect (so);
+ force_new_style (state->so);
+
dialog = gtk_dialog_new_with_buttons
(title,
wbcg_toplevel (state->wbcg),
@@ -193,8 +207,10 @@ dialog_so_styled (WBCGtk *wbcg,
GNM_STOCK_OK, GTK_RESPONSE_OK,
NULL);
- editor = go_style_get_editor (orig, default_style,
+ g_object_get (so, "style", &style, NULL);
+ editor = go_style_get_editor (style, default_style,
GO_CMD_CONTEXT (wbcg), G_OBJECT (so));
+ g_object_unref (style);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
editor, TRUE, TRUE, TRUE);
diff --git a/src/dialogs/dialogs.h b/src/dialogs/dialogs.h
index c3c4ad1..6a045f9 100644
--- a/src/dialogs/dialogs.h
+++ b/src/dialogs/dialogs.h
@@ -139,8 +139,7 @@ typedef enum {
SO_STYLED_TEXT = 2,
} so_styled_t;
-void dialog_so_styled (WBCGtk *wbcg, GObject *so,
- GOStyle *orig, GOStyle *default_style,
+void dialog_so_styled (WBCGtk *wbcg, GObject *so, GOStyle *default_style,
char const *title, so_styled_t extent);
void dialog_so_list (WBCGtk *wbcg, GObject *so);
diff --git a/src/gnm-so-filled.c b/src/gnm-so-filled.c
index cbd41e3..c1c09eb 100644
--- a/src/gnm-so-filled.c
+++ b/src/gnm-so-filled.c
@@ -172,7 +172,7 @@ gnm_so_filled_user_config (SheetObject *so, SheetControl *sc)
{
GnmSOFilled *sof = GNM_SO_FILLED (so);
dialog_so_styled (scg_wbcg (SHEET_CONTROL_GUI (sc)), G_OBJECT (so),
- sof->style, sof_default_style (),
+ sof_default_style (),
_("Filled Object Properties"),
SO_STYLED_TEXT);
}
diff --git a/src/gnm-so-line.c b/src/gnm-so-line.c
index 9ad839d..820f3f4 100644
--- a/src/gnm-so-line.c
+++ b/src/gnm-so-line.c
@@ -119,7 +119,7 @@ static void
gnm_so_line_user_config (SheetObject *so, SheetControl *sc)
{
dialog_so_styled (scg_wbcg (SHEET_CONTROL_GUI (sc)), G_OBJECT (so),
- GNM_SO_LINE (so)->style, sol_default_style (),
+ sol_default_style (),
_("Line/Arrow Properties"), SO_STYLED_LINE);
}
diff --git a/src/gnm-so-path.c b/src/gnm-so-path.c
index 38adb67..a6682a3 100644
--- a/src/gnm-so-path.c
+++ b/src/gnm-so-path.c
@@ -195,7 +195,7 @@ gnm_so_path_user_config (SheetObject *so, SheetControl *sc)
{
GnmSOPath *sop = GNM_SO_PATH (so);
dialog_so_styled (scg_wbcg (SHEET_CONTROL_GUI (sc)), G_OBJECT (so),
- sop->style, sop_default_style (),
+ sop_default_style (),
_("Filled Object Properties"),
SO_STYLED_TEXT);
}
diff --git a/src/gnm-so-polygon.c b/src/gnm-so-polygon.c
index f3f4dbc..b65e59c 100644
--- a/src/gnm-so-polygon.c
+++ b/src/gnm-so-polygon.c
@@ -165,7 +165,7 @@ static void
gnm_so_polygon_user_config (SheetObject *so, SheetControl *sc)
{
dialog_so_styled (scg_wbcg (SHEET_CONTROL_GUI (sc)), G_OBJECT (so),
- GNM_SO_POLYGON (so)->style, sop_default_style (),
+ sop_default_style (),
_("Polygon Properties"), SO_STYLED_STYLE_ONLY);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]