[Planner Dev] Last patch for undo resource dialog: undo calendar selection
- From: Alvaro del Castillo <acs lambdaux com>
- To: Planner Project Manager - Development List <planner-dev lists imendio com>
- Subject: [Planner Dev] Last patch for undo resource dialog: undo calendar selection
- Date: Sat, 01 May 2004 12:54:12 +0000
Hi guys!
Here goes the last patch, if we don't find some prob, to implement the
undo system in the resource dialog. It implements undoing the calendar
selection.
Also I have found a bug that crash planner undoing the note in the
resource note editor and it is solved with this patch also (using a
DialogData when it could be destroyed to store data).
Now, it is time to test a lot this dialog in order to make it as robust
as we can. I have left some code for debugging because normally, we will
find some bugs in the first moments start using the new features.
Cheers
-- Alvaro
Index: src/planner-resource-dialog.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-resource-dialog.c,v
retrieving revision 1.9
diff -u -b -B -p -r1.9 planner-resource-dialog.c
--- src/planner-resource-dialog.c 1 May 2004 08:37:48 -0000 1.9
+++ src/planner-resource-dialog.c 1 May 2004 10:46:15 -0000
@@ -183,13 +183,21 @@ typedef struct {
typedef struct {
PlannerCmd base;
- DialogData *data;
MrpResource *resource;
gchar *property;
gchar *note;
gchar *old_note;
} ResourceCmdEditNote;
+typedef struct {
+ PlannerCmd base;
+
+ MrpResource *resource;
+ MrpCalendar *calendar;
+ MrpCalendar *old_calendar;
+} ResourceCmdCalendar;
+
+
static gboolean
foreach_find_calendar (GtkTreeModel *model,
GtkTreePath *path,
@@ -430,26 +438,98 @@ resource_dialog_resource_removed_cb (Gtk
}
static void
+resource_cmd_calendar_do (PlannerCmd *cmd_base)
+{
+ ResourceCmdCalendar *cmd;
+
+ cmd = (ResourceCmdCalendar*) cmd_base;
+
+ mrp_resource_set_calendar (cmd->resource, cmd->calendar);
+}
+
+static void
+resource_cmd_calendar_undo (PlannerCmd *cmd_base)
+{
+ ResourceCmdCalendar *cmd;
+
+ cmd = (ResourceCmdCalendar*) cmd_base;
+
+ mrp_resource_set_calendar (cmd->resource, cmd->old_calendar);
+
+}
+
+static void
+resource_cmd_calendar_free (PlannerCmd *cmd_base)
+{
+ ResourceCmdCalendar *cmd;
+
+ cmd = (ResourceCmdCalendar *) cmd_base;
+
+ g_free (cmd_base->label);
+ g_object_unref (cmd->resource);
+
+ if (cmd->old_calendar) {
+ g_object_unref (cmd->calendar);
+ }
+ if (cmd->old_calendar) {
+ g_object_unref (cmd->old_calendar);
+ }
+
+ g_free (cmd);
+}
+
+static PlannerCmd *
+resource_cmd_edit_calendar (DialogData *data,
+ MrpCalendar *calendar)
+{
+ PlannerCmd *cmd_base;
+ ResourceCmdCalendar *cmd;
+ MrpCalendar *current_calendar;
+
+ cmd = g_new0 (ResourceCmdCalendar, 1);
+
+ cmd_base = (PlannerCmd*) cmd;
+
+ cmd_base->label = g_strdup (_("Edit resource calendar from dialog"));
+ cmd_base->do_func = resource_cmd_calendar_do;
+ cmd_base->undo_func = resource_cmd_calendar_undo;
+ cmd_base->free_func = resource_cmd_calendar_free;
+
+ cmd->resource = g_object_ref (data->resource);
+
+ current_calendar = mrp_resource_get_calendar (data->resource);
+
+ if (current_calendar) {
+ cmd->old_calendar = g_object_ref (current_calendar);
+ } else {
+ cmd->old_calendar = NULL;
+ }
+
+ if (calendar) {
+ cmd->calendar = g_object_ref (calendar);
+ } else {
+ cmd->calendar = NULL;
+ }
+
+ planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (data->main_window),
+ cmd_base);
+
+ return cmd_base;
+}
+
+static void
resource_cmd_note_do (PlannerCmd *cmd_base)
{
ResourceCmdEditNote *cmd;
cmd = (ResourceCmdEditNote*) cmd_base;
- g_signal_handlers_block_by_func (cmd->resource,
- resource_dialog_resource_note_changed_cb,
- cmd->resource);
-
if (g_getenv ("PLANNER_DEBUG_UNDO_RESOURCE")) {
g_message ("Doing the note change ... focus out: %s, focus in: %s",
cmd->note, cmd->old_note);
}
g_object_set (cmd->resource, "note", cmd->note, NULL);
-
- g_signal_handlers_unblock_by_func (cmd->resource,
- resource_dialog_resource_note_changed_cb,
- cmd->resource);
}
static void
@@ -459,20 +539,12 @@ resource_cmd_note_undo (PlannerCmd *cmd_
cmd = (ResourceCmdEditNote*) cmd_base;
- g_signal_handlers_block_by_func (cmd->data->note_buffer,
- resource_dialog_note_changed_cb,
- cmd->data->dialog);
-
if (g_getenv ("PLANNER_DEBUG_UNDO_RESOURCE")) {
g_message ("Undoing the note change to \"%s\" from the new \"%s\"",
cmd->old_note, cmd->note);
}
g_object_set (cmd->resource, "note", cmd->old_note, NULL);
-
- g_signal_handlers_unblock_by_func (cmd->data->note_buffer,
- resource_dialog_note_changed_cb,
- cmd->data->dialog);
}
static void
@@ -517,7 +589,6 @@ resource_cmd_edit_note (DialogData *dat
cmd_base->undo_func = resource_cmd_note_undo;
cmd_base->free_func = resource_cmd_note_free;
- cmd->data = data;
cmd->property = g_strdup (property);
cmd->resource = g_object_ref (data->resource);
@@ -1329,6 +1400,12 @@ resource_dialog_calendar_toggled_cb (Gtk
GtkTreeIter iter;
gboolean selected;
MrpCalendar *calendar;
+ PlannerCmd *cmd;
+
+ if (g_getenv ("PLANNER_DEBUG_UNDO_RESOURCE")) {
+ g_message ("Changing the calendar for the resource %s",
+ mrp_resource_get_name (data->resource));
+ }
path = gtk_tree_path_new_from_string (path_str);
@@ -1343,7 +1420,7 @@ resource_dialog_calendar_toggled_cb (Gtk
-1);
if (!selected) {
- mrp_resource_set_calendar (data->resource, calendar);
+ cmd = resource_cmd_edit_calendar (data, calendar);
}
gtk_tree_path_free (path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]