[gnumeric] GUI: Move sheet renaming into a dialog.



commit 427a16fc3698e1579ac76183f8761c9dd73f4afd
Author: Morten Welinder <terra gnome org>
Date:   Wed Apr 3 13:28:44 2013 -0400

    GUI: Move sheet renaming into a dialog.

 NEWS                              |    1 +
 src/dialogs/Makefile.am           |    2 +
 src/dialogs/dialog-sheet-rename.c |  123 ++++++++++++++++++++++++++++++++++
 src/dialogs/dialogs.h             |    1 +
 src/dialogs/sheet-rename.ui       |  133 +++++++++++++++++++++++++++++++++++++
 src/wbc-gtk-actions.c             |    6 +-
 src/wbc-gtk.c                     |   22 +------
 7 files changed, 264 insertions(+), 24 deletions(-)
---
diff --git a/NEWS b/NEWS
index 616df2f..a42c1f0 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ Morten:
        * Fix getting the detachable-toolbars setting.
        * Style most of Gnumeric using css.
        * Fix focus problem in cell comment dialog.  [#696826]
+       * Move sheet renaming into a dialog.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.1
diff --git a/src/dialogs/Makefile.am b/src/dialogs/Makefile.am
index 817b924..ffe3fda 100644
--- a/src/dialogs/Makefile.am
+++ b/src/dialogs/Makefile.am
@@ -65,6 +65,7 @@ libdialogs_la_SOURCES =                                       \
        dialog-search.c                         \
        dialog-search-replace.c                 \
        dialog-sheet-order.c                    \
+       dialog-sheet-rename.c                   \
        dialog-sheet-resize.c                   \
        dialog-sheetobject-size.c               \
        dialog-shuffle.c                        \
@@ -160,6 +161,7 @@ embedded_uis =                      \
        search-replace.ui               \
        search.ui                       \
        sheet-order.ui                  \
+       sheet-rename.ui                 \
        sheet-resize.ui                 \
        sheetobject-size.ui             \
        shuffle.ui                      \
diff --git a/src/dialogs/dialog-sheet-rename.c b/src/dialogs/dialog-sheet-rename.c
new file mode 100644
index 0000000..066fec1
--- /dev/null
+++ b/src/dialogs/dialog-sheet-rename.c
@@ -0,0 +1,123 @@
+/*
+ * dialog-sheet-rename.c: Dialog to rename current sheet.
+ *
+ * Author:
+ *     Morten Welinder <terra gnome org>
+ *
+ * (C) Copyright 2013 Morten Welinder <terra gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gnumeric-config.h>
+#include <glib/gi18n-lib.h>
+#include <gnumeric.h>
+#include "dialogs.h"
+#include "help.h"
+
+#include <gui-util.h>
+#include <wbc-gtk.h>
+#include <workbook-view.h>
+#include <workbook.h>
+#include <sheet.h>
+#include <commands.h>
+
+#define RENAME_DIALOG_KEY "sheet-rename-dialog"
+
+typedef struct {
+       WBCGtk *wbcg;
+       Sheet *sheet;
+       GtkWidget *dialog;
+       GtkWidget *old_name, *new_name;
+       GtkWidget *ok_button, *cancel_button;
+} RenameState;
+
+static void
+cb_name_changed (GtkEntry *e, RenameState *state)
+{
+       const char *name = gtk_entry_get_text (e);
+       gboolean valid;
+       Sheet *sheet2 = workbook_sheet_by_name (state->sheet->workbook, name);
+
+       valid = (*name != 0) && (sheet2 == NULL || sheet2 == state->sheet);
+
+       gtk_widget_set_sensitive (state->ok_button, valid);
+}
+
+static void
+cb_ok_clicked (RenameState *state)
+{
+       const char *name = gtk_entry_get_text (GTK_ENTRY (state->new_name));
+
+       cmd_rename_sheet (WORKBOOK_CONTROL (state->wbcg),
+                         state->sheet,
+                         name);
+
+       gtk_widget_destroy (state->dialog);
+}
+
+void
+dialog_sheet_rename (WBCGtk *wbcg, Sheet *sheet)
+{
+       GtkBuilder *gui;
+       RenameState *state;
+
+       if (gnumeric_dialog_raise_if_exists (wbcg, RENAME_DIALOG_KEY))
+               return;
+       gui = gnm_gtk_builder_load ("sheet-rename.ui", NULL, GO_CMD_CONTEXT (wbcg));
+       if (gui == NULL)
+               return;
+
+       state = g_new (RenameState, 1);
+       state->wbcg   = wbcg;
+       state->dialog = go_gtk_builder_get_widget (gui, "Rename");
+       state->sheet = sheet;
+       g_return_if_fail (state->dialog != NULL);
+
+       state->old_name = go_gtk_builder_get_widget (gui, "old_name");
+       gtk_entry_set_text (GTK_ENTRY (state->old_name), sheet->name_unquoted);
+
+       state->new_name = go_gtk_builder_get_widget (gui, "new_name");
+       gtk_entry_set_text (GTK_ENTRY (state->new_name), sheet->name_unquoted);
+       gtk_editable_select_region (GTK_EDITABLE (state->new_name), 0, -1);
+       gtk_widget_grab_focus (state->new_name);
+       g_signal_connect (state->new_name,
+                         "changed", G_CALLBACK (cb_name_changed),
+                         state);
+       gnumeric_editable_enters (GTK_WINDOW (state->dialog), state->new_name);
+
+       state->ok_button = go_gtk_builder_get_widget (gui, "ok_button");
+       g_signal_connect_swapped (G_OBJECT (state->ok_button),
+                                 "clicked", G_CALLBACK (cb_ok_clicked),
+                                 state);
+
+       state->cancel_button = go_gtk_builder_get_widget (gui, "cancel_button");
+       g_signal_connect_swapped (G_OBJECT (state->cancel_button),
+                                 "clicked", G_CALLBACK (gtk_widget_destroy),
+                                 state->dialog);
+
+       gnm_dialog_setup_destroy_handlers (GTK_DIALOG (state->dialog), wbcg,
+                                          GNM_DIALOG_DESTROY_SHEET_REMOVED);
+
+       gnumeric_keyed_dialog (wbcg, GTK_WINDOW (state->dialog),
+                              RENAME_DIALOG_KEY);
+
+       g_object_set_data_full (G_OBJECT (state->dialog),
+                               "state", state,
+                               (GDestroyNotify) g_free);
+       g_object_unref (gui);
+
+       gtk_widget_show (state->dialog);
+}
diff --git a/src/dialogs/dialogs.h b/src/dialogs/dialogs.h
index 69a46b4..30753ce 100644
--- a/src/dialogs/dialogs.h
+++ b/src/dialogs/dialogs.h
@@ -58,6 +58,7 @@ void     dialog_autoformat    (WBCGtk *wbcg);
 void     dialog_consolidate    (WBCGtk *wbcg);
 void     dialog_sheet_order    (WBCGtk *wbcg);
 void     dialog_sheet_resize    (WBCGtk *wbcg);
+void     dialog_sheet_rename    (WBCGtk *wbcg, Sheet *sheet);
 void     dialog_row_height     (WBCGtk *wbcg, gboolean set_default);
 void    dialog_fill_series     (WBCGtk *wbcg);
 void     dialog_col_width      (WBCGtk *wbcg, gboolean set_default);
diff --git a/src/dialogs/sheet-rename.ui b/src/dialogs/sheet-rename.ui
new file mode 100644
index 0000000..a7ad335
--- /dev/null
+++ b/src/dialogs/sheet-rename.ui
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkDialog" id="Rename">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Rename Sheet</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="ok_button">
+                <property name="label">gtk-ok</property>
+                <property name="use_action_appearance">False</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="cancel_button">
+                <property name="label">gtk-cancel</property>
+                <property name="use_action_appearance">False</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Old Name:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">New Name:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="old_name">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="editable">False</property>
+                <property name="invisible_char">●</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="new_name">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">●</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">ok_button</action-widget>
+      <action-widget response="0">cancel_button</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/src/wbc-gtk-actions.c b/src/wbc-gtk-actions.c
index 20af87c..2579807 100644
--- a/src/wbc-gtk-actions.c
+++ b/src/wbc-gtk-actions.c
@@ -70,7 +70,6 @@
 #include <goffice/goffice.h>
 #include <goffice/component/goffice-component.h>
 
-#include "widgets/widget-editable-label.h"
 #include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
 #include <gsf/gsf-input.h>
@@ -918,8 +917,9 @@ static GNM_ACTION_DEF (cb_insert_comment)
 
 static GNM_ACTION_DEF (cb_sheet_name)
 {
-       SheetControlGUI *scg = wbcg_cur_scg(wbcg);
-       editable_label_start_editing (EDITABLE_LABEL(scg->label));
+       WorkbookControl *wbc = WORKBOOK_CONTROL (wbcg);
+       Sheet *sheet = wb_control_cur_sheet (wbc);
+       dialog_sheet_rename (wbcg, sheet);
 }
 
 static GNM_ACTION_DEF (cb_sheet_order)         { dialog_sheet_order (wbcg); }
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index 7a2bcc1..707a8b6 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -415,23 +415,6 @@ wbcg_update_action_sensitivity (WorkbookControl *wbc)
        }
 }
 
-static gboolean
-cb_sheet_label_edit_finished (EditableLabel *el, char const *new_name,
-                             WBCGtk *wbcg)
-{
-       gboolean reject = FALSE;
-       if (new_name != NULL) {
-               char const *old_name = editable_label_get_text (el);
-               Workbook *wb = wb_control_get_workbook (WORKBOOK_CONTROL (wbcg));
-               Sheet *sheet = workbook_sheet_by_name (wb, old_name);
-               reject = cmd_rename_sheet (WORKBOOK_CONTROL (wbcg),
-                                          sheet,
-                                          new_name);
-       }
-       wbcg_focus_cur_scg (wbcg);
-       return reject;
-}
-
 void
 wbcg_insert_sheet (GtkWidget *unused, WBCGtk *wbcg)
 {
@@ -490,7 +473,7 @@ static void cb_sheets_manage (SheetControlGUI *scg) { dialog_sheet_order (scg->w
 static void cb_sheets_insert (SheetControlGUI *scg) { wbcg_insert_sheet (NULL, scg->wbcg); }
 static void cb_sheets_add    (SheetControlGUI *scg) { wbcg_append_sheet (NULL, scg->wbcg); }
 static void cb_sheets_clone  (SheetControlGUI *scg) { wbcg_clone_sheet  (NULL, scg->wbcg); }
-static void cb_sheets_rename (SheetControlGUI *scg) { editable_label_start_editing 
(EDITABLE_LABEL(scg->label)); }
+static void cb_sheets_rename (SheetControlGUI *scg) { dialog_sheet_rename (scg->wbcg, scg_sheet (scg)); }
 static void cb_sheets_resize (SheetControlGUI *scg) { dialog_sheet_resize (scg->wbcg); }
 
 
@@ -1103,9 +1086,6 @@ wbcg_sheet_add (WorkbookControl *wbc, SheetView *sv)
        g_object_set_data (G_OBJECT (scg->grid), SHEET_CONTROL_KEY, scg);
 
        g_object_set_data (G_OBJECT (scg->label), SHEET_CONTROL_KEY, scg);
-       g_signal_connect_after (G_OBJECT (scg->label),
-                               "edit_finished",
-                               G_CALLBACK (cb_sheet_label_edit_finished), wbcg);
 
        /* do not preempt the editable label handler */
        g_signal_connect_after (G_OBJECT (scg->label),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]