undocommand: Add a timestamp property
This commit is contained in:
@@ -105,13 +105,16 @@ gtk_entry_undo_command_redo (GtkUndoCommand *command)
|
||||
|
||||
static GtkUndoCommand *
|
||||
gtk_entry_undo_command_new_from_snapshots (GtkEntry *entry,
|
||||
gint64 timestamp,
|
||||
const GtkEntrySnapshot *before,
|
||||
const GtkEntrySnapshot *after)
|
||||
{
|
||||
GtkEntryUndoCommand *command;
|
||||
GtkEntryUndoCommandPrivate *priv;
|
||||
|
||||
command = g_object_new (GTK_TYPE_ENTRY_UNDO_COMMAND, NULL);
|
||||
command = g_object_new (GTK_TYPE_ENTRY_UNDO_COMMAND,
|
||||
"timestamp", timestamp,
|
||||
NULL);
|
||||
priv = gtk_entry_undo_command_get_instance_private (command);
|
||||
|
||||
priv->entry = entry;
|
||||
@@ -134,7 +137,10 @@ gtk_entry_undo_command_merge (GtkUndoCommand *command,
|
||||
if (command_priv->entry != followup_priv->entry)
|
||||
return NULL;
|
||||
|
||||
return gtk_entry_undo_command_new_from_snapshots (command_priv->entry, &command_priv->before, &followup_priv->after);
|
||||
return gtk_entry_undo_command_new_from_snapshots (command_priv->entry,
|
||||
gtk_undo_command_get_timestamp (followup),
|
||||
&command_priv->before,
|
||||
&followup_priv->after);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@@ -262,7 +268,7 @@ gtk_entry_undo_command_new (GtkEntry *entry,
|
||||
|
||||
gtk_entry_snapshot_init_from_entry (&after, entry);
|
||||
|
||||
result = gtk_entry_undo_command_new_from_snapshots (entry, before, &after);
|
||||
result = gtk_entry_undo_command_new_from_snapshots (entry, 0, before, &after);
|
||||
|
||||
gtk_entry_snapshot_clear (&after);
|
||||
|
||||
|
||||
@@ -28,9 +28,58 @@ struct _GtkUndoCommandPrivate {
|
||||
gint64 timestamp;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_TIMESTAMP,
|
||||
/* add more */
|
||||
NUM_PROPERTIES
|
||||
};
|
||||
|
||||
static GParamSpec *properties[NUM_PROPERTIES];
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkUndoCommand, gtk_undo_command, G_TYPE_OBJECT,
|
||||
G_ADD_PRIVATE (GtkUndoCommand))
|
||||
|
||||
static void
|
||||
gtk_undo_command_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkUndoCommandPrivate *priv = gtk_undo_command_get_instance_private (GTK_UNDO_COMMAND (object));
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_TIMESTAMP:
|
||||
g_value_set_int64 (value, priv->timestamp);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_undo_command_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkUndoCommandPrivate *priv = gtk_undo_command_get_instance_private (GTK_UNDO_COMMAND (object));
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_TIMESTAMP:
|
||||
priv->timestamp = g_value_get_int64 (value);
|
||||
if (priv->timestamp == 0)
|
||||
priv->timestamp = g_get_real_time ();
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_undo_command_real_undo (GtkUndoCommand *command)
|
||||
{
|
||||
@@ -75,19 +124,35 @@ gtk_undo_command_real_describe (GtkUndoCommand *command)
|
||||
static void
|
||||
gtk_undo_command_class_init (GtkUndoCommandClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->set_property = gtk_undo_command_set_property;
|
||||
object_class->get_property = gtk_undo_command_get_property;
|
||||
|
||||
klass->undo = gtk_undo_command_real_undo;
|
||||
klass->redo = gtk_undo_command_real_redo;
|
||||
klass->merge = gtk_undo_command_real_merge;
|
||||
klass->should_merge = gtk_undo_command_real_should_merge;
|
||||
klass->describe = gtk_undo_command_real_describe;
|
||||
|
||||
/*
|
||||
* GtkUndoCommand:timestamp:
|
||||
*
|
||||
* Timestamp this command was recorded at. See
|
||||
* gtk_undo_command_get_timestamp() for details.
|
||||
*/
|
||||
properties[PROP_TIMESTAMP] = g_param_spec_int64 ("timestamp", "Timestamp",
|
||||
"Time at which this command was recorded",
|
||||
0, G_MAXINT64, 0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_undo_command_init (GtkUndoCommand *command)
|
||||
{
|
||||
GtkUndoCommandPrivate *priv = gtk_undo_command_get_instance_private (command);
|
||||
|
||||
priv->timestamp = g_get_real_time ();
|
||||
}
|
||||
|
||||
gboolean
|
||||
@@ -145,3 +210,23 @@ gtk_undo_command_describe (GtkUndoCommand *command)
|
||||
|
||||
return GTK_UNDO_COMMAND_GET_CLASS (command)->describe (command);
|
||||
}
|
||||
|
||||
/*
|
||||
* gtk_undo_command_get_timestamp:
|
||||
* @command: The command
|
||||
*
|
||||
* Returns the timestamp when this command was recorded. If multiple
|
||||
* commands get combined into one, the timestamp will be the timestamp
|
||||
* of the newest command.
|
||||
*
|
||||
* Returns: Timestamp as returned by g_get_real_time()
|
||||
**/
|
||||
gint64
|
||||
gtk_undo_command_get_timestamp (GtkUndoCommand *command)
|
||||
{
|
||||
GtkUndoCommandPrivate *priv = gtk_undo_command_get_instance_private (command);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_UNDO_COMMAND (command), 0);
|
||||
|
||||
return priv->timestamp;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ struct _GtkUndoCommandClass
|
||||
|
||||
GType gtk_undo_command_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gint64 gtk_undo_command_get_timestamp (GtkUndoCommand *command);
|
||||
|
||||
gboolean gtk_undo_command_undo (GtkUndoCommand *command);
|
||||
gboolean gtk_undo_command_redo (GtkUndoCommand *command);
|
||||
GtkUndoCommand * gtk_undo_command_merge (GtkUndoCommand *command,
|
||||
|
||||
Reference in New Issue
Block a user