Пример #1
0
static void
undo_do_something (GObject *object,
                   EUndoDoType todo,
                   void (* insert_func) (GObject *object,
                   const gchar *text,
                   gint position),
                   void (* delete_func) (GObject *object,
                   gint position_start,
                   gint position_end))
{
	EUndoData *data;
	EUndoInfo *info = NULL;

	data = g_object_get_data (object, UNDO_DATA_KEY);
	if (!data)
		return;

	if (todo == E_UNDO_DO_UNDO && data->n_undos > 0) {
		info = data->undo_stack[REAL_INDEX (data->n_undos - 1)];
		data->n_undos--;
		data->n_redos++;
	} else if (todo == E_UNDO_DO_REDO && data->n_redos > 0) {
		info = data->undo_stack[REAL_INDEX (data->n_undos)];
		data->n_undos++;
		data->n_redos--;
	}

	if (!info)
		return;

	g_signal_handler_block (object, data->insert_handler_id);
	g_signal_handler_block (object, data->delete_handler_id);

	if (info->type == E_UNDO_INSERT) {
		if (todo == E_UNDO_DO_UNDO) {
			delete_func (object, info->position_start, info->position_start + g_utf8_strlen (info->text, -1));
			widget_undo_place_cursor_at (object, info->position_start);
		} else {
			insert_func (object, info->text, info->position_start);
			widget_undo_place_cursor_at (object, info->position_start + g_utf8_strlen (info->text, -1));
		}
	} else if (info->type == E_UNDO_DELETE) {
		if (todo == E_UNDO_DO_UNDO) {
			insert_func (object, info->text, info->position_start);
			widget_undo_place_cursor_at (object, info->position_start + g_utf8_strlen (info->text, -1));
		} else {
			delete_func (object, info->position_start, info->position_end);
			widget_undo_place_cursor_at (object, info->position_start);
		}
	}

	data->current_info = NULL;

	g_signal_handler_unblock (object, data->delete_handler_id);
	g_signal_handler_unblock (object, data->insert_handler_id);
}
Пример #2
0
FeriteVariable *ferite_amtarray_get_index( FeriteScript *script, FeriteAMTArray *array, int index )
{    
	unsigned int real_index = index;
	FeriteAMTArrayEntry *entry = NULL;
	
	REAL_INDEX( array, index, real_index );	
	entry = ferite_amt_get( script, array->_array, real_index );
	if( entry ) {
		return entry->variable;
	}
	return NULL;
}
Пример #3
0
static void
reset_redos (EUndoData *data)
{
	gint ii, index;

	for (ii = 0; ii < data->n_redos; ii++) {
		index = REAL_INDEX (data->n_undos + ii);

		free_undo_info (data->undo_stack[index]);
		data->undo_stack[index] = NULL;
	}

	data->n_redos = 0;
}
Пример #4
0
static gboolean
undo_check_redo (GObject *object,
                 gchar **description)
{
	EUndoData *data;

	data = g_object_get_data (object, UNDO_DATA_KEY);
	if (!data)
		return FALSE;

	if (data->n_redos <= 0)
		return FALSE;

	if (description)
		*description = undo_describe_info (data->undo_stack[REAL_INDEX (data->n_undos)], E_UNDO_DO_REDO);

	return TRUE;
}
Пример #5
0
static void
push_undo (EUndoData *data,
           EUndoInfo *info)
{
	gint index;

	reset_redos (data);

	if (data->n_undos == data->undo_len) {
		data->undo_from = (data->undo_from + 1) % data->undo_len;
	} else {
		data->n_undos++;
	}

	index = REAL_INDEX (data->n_undos - 1);
	free_undo_info (data->undo_stack[index]);
	data->undo_stack[index] = info;
}