Ejemplo n.º 1
0
/**
 * e_selection_model_do_something
 * @selection: #ESelectionModel to do something to.
 * @row: The row to do something in.
 * @col: The col to do something in.
 * @state: The state in which to do something.
 *
 * This routine does whatever is appropriate as if the user clicked
 * the mouse in the given row and column.
 */
void
e_selection_model_do_something (ESelectionModel *selection,
				guint                 row,
				guint                 col,
				GdkModifierType       state)
{
	gint shift_p = state & GDK_SHIFT_MASK;
	gint ctrl_p = state & GDK_CONTROL_MASK;
	int row_count;

	selection->old_selection = -1;

	if (row == -1 && col != -1)
		row = 0;
	if (col == -1 && row != -1)
		col = 0;

	row_count = e_selection_model_row_count(selection);
	if (row_count >= 0 && row < row_count) {
		switch (selection->mode) {
		case GTK_SELECTION_SINGLE:
			e_selection_model_select_single_row (selection, row);
			break;
		case GTK_SELECTION_BROWSE:
		case GTK_SELECTION_MULTIPLE:
			if (shift_p) {
				e_selection_model_set_selection_end (selection, row);
			} else {
				if (ctrl_p) {
					e_selection_model_toggle_single_row (selection, row);
				} else {
					e_selection_model_select_single_row (selection, row);
				}
			}
			break;
		default:
			g_return_if_reached();
			break;
		}
		e_selection_model_change_cursor(selection, row, col);
		g_signal_emit(selection,
			      e_selection_model_signals[CURSOR_CHANGED], 0,
			      row, col);
		g_signal_emit(selection,
			      e_selection_model_signals[CURSOR_ACTIVATED], 0,
			      row, col);
	}
}
Ejemplo n.º 2
0
/**
 * e_selection_model_maybe_do_something
 * @selection: #ESelectionModel to do something to.
 * @row: The row to do something in.
 * @col: The col to do something in.
 * @state: The state in which to do something.
 *
 * If this row is selected, this routine just moves the cursor row and
 * column.  Otherwise, it does the same thing as
 * e_selection_model_do_something().  This is for being used on
 * right clicks and other events where if the user hit the selection,
 * they don't want it to change.
 */
gboolean
e_selection_model_maybe_do_something      (ESelectionModel *selection,
					   guint            row,
					   guint            col,
					   GdkModifierType  state)
{
	selection->old_selection = -1;

	if (e_selection_model_is_row_selected(selection, row)) {
		e_selection_model_change_cursor(selection, row, col);
		g_signal_emit(selection,
			      e_selection_model_signals[CURSOR_CHANGED], 0,
			      row, col);
		return FALSE;
	} else {
		e_selection_model_do_something(selection, row, col, state);
		return TRUE;
	}
}
Ejemplo n.º 3
0
void
e_selection_model_select_as_key_press (ESelectionModel *selection,
				       guint            row,
				       guint            col,
				       GdkModifierType  state)
{
	int cursor_activated = TRUE;

	gint shift_p = state & GDK_SHIFT_MASK;
	gint ctrl_p = state & GDK_CONTROL_MASK;

	selection->old_selection = -1;

	switch (selection->mode) {
	case GTK_SELECTION_BROWSE:
	case GTK_SELECTION_MULTIPLE:
		if (shift_p) {
			e_selection_model_set_selection_end (selection, row);
		} else if (!ctrl_p) {
			e_selection_model_select_single_row (selection, row);
		} else
			cursor_activated = FALSE;
		break;
	case GTK_SELECTION_SINGLE:
		e_selection_model_select_single_row (selection, row);
		break;
	default:
		g_return_if_reached();
		break;
	}
	if (row != -1) {
		e_selection_model_change_cursor(selection, row, col);
		g_signal_emit(selection,
			      e_selection_model_signals[CURSOR_CHANGED], 0,
			      row, col);
		if (cursor_activated)
			g_signal_emit(selection,
				      e_selection_model_signals[CURSOR_ACTIVATED], 0,
				      row, col);
	}
}
Ejemplo n.º 4
0
static gint
model_changed_idle (ETableSelectionModel *etsm)
{
	ETableModel *etm = etsm->model;

	e_selection_model_clear (E_SELECTION_MODEL (etsm));

	if (etsm->cursor_id && etm && e_table_model_has_save_id (etm)) {
		gint row_count = e_table_model_row_count (etm);
		gint cursor_row = -1;
		gint cursor_col = -1;
		gint i;
		e_selection_model_array_confirm_row_count (E_SELECTION_MODEL_ARRAY (etsm));
		for (i = 0; i < row_count; i++) {
			gchar *save_id = e_table_model_get_save_id (etm, i);
			if (g_hash_table_lookup (etsm->hash, save_id))
				e_selection_model_change_one_row (E_SELECTION_MODEL (etsm), i, TRUE);

			if (etsm->cursor_id && !strcmp (etsm->cursor_id, save_id)) {
				cursor_row = i;
				cursor_col = e_selection_model_cursor_col (E_SELECTION_MODEL (etsm));
				if (cursor_col == -1) {
					if (etsm->eth) {
						cursor_col = e_table_header_prioritized_column (etsm->eth);
					} else
						cursor_col = 0;
				}
				e_selection_model_change_cursor (E_SELECTION_MODEL (etsm), cursor_row, cursor_col);
				g_free (etsm->cursor_id);
				etsm->cursor_id = NULL;
			}
			g_free (save_id);
		}
		free_hash (etsm);
		e_selection_model_cursor_changed (E_SELECTION_MODEL (etsm), cursor_row, cursor_col);
		e_selection_model_selection_changed (E_SELECTION_MODEL (etsm));
	}
	etsm->model_changed_idle_id = 0;
	return FALSE;
}