Implemented capitalization keybindings.
2002-03-14 Christopher James Lahey <clahey@ximian.com> * e-cell-text.c: Implemented capitalization keybindings. * e-tree.c (item_key_press): Added parentheses to the default case here. svn path=/trunk/; revision=16168
This commit is contained in:

committed by
Chris Lahey

parent
bd3790d66e
commit
eafda9ba48
@ -1861,6 +1861,29 @@ _blink_scroll_timeout (gpointer data)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
next_word (CellEdit *edit, int start)
|
||||||
|
{
|
||||||
|
CurrentCell *cell = CURRENT_CELL(edit);
|
||||||
|
char *p;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
length = strlen (cell->text);
|
||||||
|
if (start >= length)
|
||||||
|
return length;
|
||||||
|
|
||||||
|
p = g_utf8_next_char (cell->text + start);
|
||||||
|
|
||||||
|
while (*p && g_unichar_validate (g_utf8_get_char (p))) {
|
||||||
|
gunichar unival = g_utf8_get_char (p);
|
||||||
|
if (g_unichar_isspace (unival))
|
||||||
|
return p - cell->text;
|
||||||
|
p = g_utf8_next_char (p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return p - cell->text;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_get_position (ECellTextView *text_view, ETextEventProcessorCommand *command)
|
_get_position (ECellTextView *text_view, ETextEventProcessorCommand *command)
|
||||||
{
|
{
|
||||||
@ -1941,19 +1964,7 @@ _get_position (ECellTextView *text_view, ETextEventProcessorCommand *command)
|
|||||||
return p - cell->text;
|
return p - cell->text;
|
||||||
|
|
||||||
case E_TEP_FORWARD_WORD:
|
case E_TEP_FORWARD_WORD:
|
||||||
|
return next_word (edit, edit->selection_end);
|
||||||
length = strlen (cell->text);
|
|
||||||
if (edit->selection_end >= length) return length;
|
|
||||||
|
|
||||||
p = g_utf8_next_char (cell->text + edit->selection_end);
|
|
||||||
|
|
||||||
while (*p && g_unichar_validate (g_utf8_get_char (p))) {
|
|
||||||
unival = g_utf8_get_char (p);
|
|
||||||
if (g_unichar_isspace (unival)) return p - cell->text;
|
|
||||||
p = g_utf8_next_char (p);
|
|
||||||
}
|
|
||||||
|
|
||||||
return p - cell->text;
|
|
||||||
|
|
||||||
case E_TEP_BACKWARD_WORD:
|
case E_TEP_BACKWARD_WORD:
|
||||||
|
|
||||||
@ -2048,6 +2059,58 @@ _insert (ECellTextView *text_view, char *string, int value)
|
|||||||
edit->selection_end = edit->selection_start;
|
edit->selection_end = edit->selection_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
capitalize (CellEdit *edit, int start, int end, ETextEventProcessorCaps type)
|
||||||
|
{
|
||||||
|
CurrentCell *cell = CURRENT_CELL(edit);
|
||||||
|
ECellTextView *text_view = cell->text_view;
|
||||||
|
|
||||||
|
gboolean first = TRUE;
|
||||||
|
int character_length = g_utf8_strlen (cell->text + start, start - end);
|
||||||
|
const char *p = cell->text + start;
|
||||||
|
const char *text_end = cell->text + end;
|
||||||
|
char *new_text = g_new0 (char, character_length * 6 + 1);
|
||||||
|
char *output = new_text;
|
||||||
|
|
||||||
|
while (p && *p && p < text_end && g_unichar_validate (g_utf8_get_char (p))) {
|
||||||
|
gunichar unival = g_utf8_get_char (p);
|
||||||
|
gunichar newval = unival;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case E_TEP_CAPS_UPPER:
|
||||||
|
newval = g_unichar_toupper (unival);
|
||||||
|
break;
|
||||||
|
case E_TEP_CAPS_LOWER:
|
||||||
|
newval = g_unichar_tolower (unival);
|
||||||
|
break;
|
||||||
|
case E_TEP_CAPS_TITLE:
|
||||||
|
if (g_unichar_isalpha (unival)) {
|
||||||
|
if (first)
|
||||||
|
newval = g_unichar_totitle (unival);
|
||||||
|
else
|
||||||
|
newval = g_unichar_tolower (unival);
|
||||||
|
first = FALSE;
|
||||||
|
} else {
|
||||||
|
first = TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
g_unichar_to_utf8 (newval, output);
|
||||||
|
output = g_utf8_next_char (output);
|
||||||
|
|
||||||
|
p = g_utf8_next_char (p);
|
||||||
|
}
|
||||||
|
*output = 0;
|
||||||
|
|
||||||
|
edit->selection_end = end;
|
||||||
|
edit->selection_start = start;
|
||||||
|
_delete_selection (text_view);
|
||||||
|
|
||||||
|
_insert (text_view, new_text, output - new_text);
|
||||||
|
|
||||||
|
g_free (new_text);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
e_cell_text_view_command (ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data)
|
e_cell_text_view_command (ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data)
|
||||||
{
|
{
|
||||||
@ -2153,7 +2216,18 @@ e_cell_text_view_command (ETextEventProcessor *tep, ETextEventProcessorCommand *
|
|||||||
edit->actions = E_CELL_UNGRAB;
|
edit->actions = E_CELL_UNGRAB;
|
||||||
break;
|
break;
|
||||||
case E_TEP_CAPS:
|
case E_TEP_CAPS:
|
||||||
/* FIXME */
|
if (edit->selection_start == edit->selection_end) {
|
||||||
|
capitalize (edit, edit->selection_start, next_word (edit, edit->selection_start), command->value);
|
||||||
|
} else {
|
||||||
|
int selection_start = MIN (edit->selection_start, edit->selection_end);
|
||||||
|
int selection_end = edit->selection_start + edit->selection_end - selection_start; /* Slightly faster than MAX */
|
||||||
|
capitalize (edit, selection_start, selection_end, command->value);
|
||||||
|
}
|
||||||
|
if (edit->timer) {
|
||||||
|
g_timer_reset (edit->timer);
|
||||||
|
}
|
||||||
|
redraw = TRUE;
|
||||||
|
change = TRUE;
|
||||||
break;
|
break;
|
||||||
case E_TEP_NOP:
|
case E_TEP_NOP:
|
||||||
break;
|
break;
|
||||||
|
@ -863,9 +863,9 @@ item_key_press (ETableItem *eti, int row, int col, GdkEvent *event, ETree *et)
|
|||||||
/* Fallthrough */
|
/* Fallthrough */
|
||||||
default:
|
default:
|
||||||
if ((key->state & ~(GDK_SHIFT_MASK | GDK_LOCK_MASK)) == 0
|
if ((key->state & ~(GDK_SHIFT_MASK | GDK_LOCK_MASK)) == 0
|
||||||
&& (key->keyval >= GDK_a && key->keyval <= GDK_z) ||
|
&& ((key->keyval >= GDK_a && key->keyval <= GDK_z) ||
|
||||||
(key->keyval >= GDK_A && key->keyval <= GDK_Z) ||
|
(key->keyval >= GDK_A && key->keyval <= GDK_Z) ||
|
||||||
(key->keyval >= GDK_0 && key->keyval <= GDK_9)) {
|
(key->keyval >= GDK_0 && key->keyval <= GDK_9))) {
|
||||||
e_table_search_input_character (et->priv->search, key->keyval);
|
e_table_search_input_character (et->priv->search, key->keyval);
|
||||||
}
|
}
|
||||||
path = e_tree_table_adapter_node_at_row(et->priv->etta, row);
|
path = e_tree_table_adapter_node_at_row(et->priv->etta, row);
|
||||||
|
Reference in New Issue
Block a user