/**
 * inf_adopted_operation_apply:
 * @operation: A #InfAdoptedOperation.
 * @by: A #InfAdoptedUser.
 * @buffer: The #InfBuffer to apply the operation to.
 *
 * Applies @operation to @buffer. The operation is considered to be applied by
 * user @by.
 **/
void
inf_adopted_operation_apply(InfAdoptedOperation* operation,
                            InfAdoptedUser* by,
                            InfBuffer* buffer)
{
  InfAdoptedOperationIface* iface;

  g_return_if_fail(INF_ADOPTED_IS_OPERATION(operation));
  g_return_if_fail(INF_ADOPTED_IS_USER(by));
  g_return_if_fail(INF_IS_BUFFER(buffer));

  iface = INF_ADOPTED_OPERATION_GET_IFACE(operation);

  /* apply must be implemented */
  g_assert(iface->apply != NULL);
  (*iface->apply)(operation, by, buffer);
}
Пример #2
0
/**
 * inf_buffer_set_modified:
 * @buffer: A #InfBuffer.
 * @modified: Whether the buffer is considered modified or not.
 *
 * Sets the modification flag of @buffer to @modified. You should normally set
 * the flag to %FALSE every time the document is saved onto disk. The buffer
 * itself will set it to %TRUE when it has been changed.
 *
 * To get notified when the modification flag changes, connect to
 * GObject::notify for the InfBuffer:modified property.
 */
void
inf_buffer_set_modified(InfBuffer* buffer,
                        gboolean modified)
{
  InfBufferInterface* iface;

  g_return_if_fail(INF_IS_BUFFER(buffer));

  iface = INF_BUFFER_GET_IFACE(buffer);
  if(iface->set_modified != NULL)
  {
    iface->set_modified(buffer, modified);
  }
  else
  {
    g_object_set(G_OBJECT(buffer), "modified", modified, NULL);
  }
}
Пример #3
0
/**
 * inf_buffer_get_modified:
 * @buffer: A #InfBuffer.
 *
 * Indicates whether the buffer has been modified since the last call to
 * inf_buffer_set_modified() set the modification flag to %FALSE.
 *
 * Returns: Whether the buffer has been modified.
 */
gboolean
inf_buffer_get_modified(InfBuffer* buffer)
{
  InfBufferInterface* iface;
  gboolean modified;

  g_return_val_if_fail(INF_IS_BUFFER(buffer), FALSE);

  iface = INF_BUFFER_GET_IFACE(buffer);
  if(iface->get_modified != NULL)
  {
    return iface->get_modified(buffer);
  }
  else
  {
    g_object_get(G_OBJECT(buffer), "modified", &modified, NULL);
    return modified;
  }
}
/**
 * inf_adopted_operation_make_reversible:
 * @operation: A #InfAdoptedOperation.
 * @with: Another #InfAdoptedOperation that emerged from @operation by
 * transforming it.
 * @buffer: A #InfBuffer.
 *
 * Some operations may not be reversible, but can be made reversible with
 * some extra information such as another operation that collected
 * enough information while being transformed, and the current buffer.
 *
 * This function can only be called when @operation is not yet reversible
 * and returns a new operation that has the same effect as @operation, but is
 * reversible.
 *
 * For example, an operation that deletes some range of text in a text editor
 * is not reversible if it only stores the position and length of the range,
 * but can be made reversible when it looks up what there is at that position
 * in the buffer.
 *
 * Return Value: A reversible #InfAdoptedOperation, or %NULL if @operation
 * cannot be made reversible with the given transformed operation @with and
 * @buffer.
 **/
InfAdoptedOperation*
inf_adopted_operation_make_reversible(InfAdoptedOperation* operation,
                                      InfAdoptedOperation* with,
                                      InfBuffer* buffer)
{
  InfAdoptedOperationIface* iface;

  g_return_val_if_fail(INF_ADOPTED_IS_OPERATION(operation), NULL);
  g_return_val_if_fail(INF_ADOPTED_IS_OPERATION(with), NULL);
  g_return_val_if_fail(INF_IS_BUFFER(buffer), NULL);

  g_assert(inf_adopted_operation_is_reversible(operation) == FALSE);

  iface = INF_ADOPTED_OPERATION_GET_IFACE(operation);

  if(iface->make_reversible != NULL)
    return (*iface->make_reversible)(operation, with, buffer);
  else
    return NULL;
}