Added special chars menu to entries in search dialog; made cell renderers in MooCombo use single paragraph, to avoid having multiline items in the popup.

master
Yevgen Muntyan 2006-04-09 17:18:52 -05:00
parent 08f9dc7c11
commit a006678c0d
6 changed files with 153 additions and 31 deletions

View File

@ -286,16 +286,16 @@
</kdevdoctreeview>
<kdevfilecreate>
<filetypes>
<type icon="source" ext="g" name="GAP source" create="template" >
<type icon="source" ext="g" create="template" name="GAP source" >
<descr>A new empty GAP source file</descr>
</type>
<type icon="source_cpp" ext="cpp" name="C++ Source" create="template" >
<type icon="source_cpp" ext="cpp" create="template" name="C++ Source" >
<descr>A new empty C++ file.</descr>
</type>
<type icon="source_h" ext="h" name="C/C++ Header" create="template" >
<type icon="source_h" ext="h" create="template" name="C/C++ Header" >
<descr>A new empty header file for C/C++.</descr>
</type>
<type icon="source_c" ext="c" name="C Source" create="template" >
<type icon="source_c" ext="c" create="template" name="C Source" >
<descr>A new empty C file.</descr>
</type>
</filetypes>

View File

@ -82,6 +82,7 @@ static void
moo_find_init (MooFind *find)
{
GtkWidget *vbox;
MooCombo *search, *replace;
find->xml = moo_glade_xml_new_empty ();
moo_glade_xml_map_id (find->xml, "search_entry", MOO_TYPE_HISTORY_ENTRY);
@ -99,8 +100,14 @@ moo_find_init (MooFind *find)
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(find)->vbox), vbox);
gtk_dialog_set_has_separator (GTK_DIALOG (find), FALSE);
moo_history_entry_set_list (moo_glade_xml_get_widget (find->xml, "search_entry"), search_history);
moo_history_entry_set_list (moo_glade_xml_get_widget (find->xml, "replace_entry"), replace_history);
search = moo_glade_xml_get_widget (find->xml, "search_entry");
replace = moo_glade_xml_get_widget (find->xml, "replace_entry");
moo_entry_set_use_special_chars_menu (MOO_ENTRY (search->entry), TRUE);
moo_entry_set_use_special_chars_menu (MOO_ENTRY (replace->entry), TRUE);
moo_history_entry_set_list (MOO_HISTORY_ENTRY (search), search_history);
moo_history_entry_set_list (MOO_HISTORY_ENTRY (replace), replace_history);
}

View File

@ -1059,6 +1059,7 @@ moo_combo_set_text_column (MooCombo *combo,
else
{
combo->priv->text_cell = gtk_cell_renderer_text_new ();
g_object_set (combo->priv->text_cell, "single-paragraph-mode", TRUE, NULL);
gtk_tree_view_column_pack_start (combo->priv->column, combo->priv->text_cell, TRUE);
}

View File

@ -30,6 +30,7 @@ struct _MooEntryPrivate {
guint grab_selection : 1;
guint fool_entry : 1;
guint empty : 1;
guint special_chars_menu : 1;
};
static guint INSERT_ACTION_TYPE;
@ -131,7 +132,8 @@ enum {
PROP_ENABLE_UNDO,
PROP_ENABLE_UNDO_MENU,
PROP_GRAB_SELECTION,
PROP_EMPTY
PROP_EMPTY,
PROP_USE_SPECIAL_CHARS_MENU
};
enum {
@ -214,6 +216,14 @@ moo_entry_class_init (MooEntryClass *klass)
TRUE,
G_PARAM_READABLE));
g_object_class_install_property (gobject_class,
PROP_USE_SPECIAL_CHARS_MENU,
g_param_spec_boolean ("use-special-chars-menu",
"use-special-chars-menu",
"use-special-chars-menu",
FALSE,
G_PARAM_READWRITE));
signals[UNDO] = g_signal_lookup ("undo", GTK_TYPE_ENTRY);
if (!signals[UNDO])
@ -306,6 +316,10 @@ moo_entry_set_property (GObject *object,
g_object_notify (object, "grab-selection");
break;
case PROP_USE_SPECIAL_CHARS_MENU:
moo_entry_set_use_special_chars_menu (entry, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -343,6 +357,10 @@ moo_entry_get_property (GObject *object,
g_value_set_boolean (value, GTK_ENTRY(entry)->text_length == 0);
break;
case PROP_USE_SPECIAL_CHARS_MENU:
g_value_set_boolean (value, entry->priv->special_chars_menu != 0);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -438,6 +456,68 @@ moo_entry_new (void)
}
static void
moo_entry_insert_at_cursor (GtkEntry *entry,
const char *text,
int len)
{
int start, end, pos;
if (MOO_IS_ENTRY (entry))
moo_entry_begin_undo_group (MOO_ENTRY (entry));
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
pos = gtk_editable_get_position (GTK_EDITABLE (entry));
gtk_editable_insert_text (GTK_EDITABLE (entry), text, len, &pos);
gtk_editable_set_position (GTK_EDITABLE (entry), pos);
if (MOO_IS_ENTRY (entry))
moo_entry_end_undo_group (MOO_ENTRY (entry));
}
static void
special_char_item_activated (GtkWidget *item,
GtkEntry *entry)
{
const char *text;
text = g_object_get_data (G_OBJECT (item), "moo-entry-special-char");
g_return_if_fail (text != NULL);
moo_entry_insert_at_cursor (entry, text, -1);
}
static void
create_special_char_item (MooEntry *entry,
GtkWidget *menu,
const char *label,
const char *text)
{
GtkWidget *item;
item = gtk_menu_item_new_with_label (label);
g_object_set_data (G_OBJECT (item), "moo-entry-special-char", (char*) text);
g_signal_connect (item, "activate",
G_CALLBACK (special_char_item_activated),
entry);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
static GtkWidget *
create_special_chars_menu (MooEntry *entry)
{
GtkWidget *menu = gtk_menu_new ();
create_special_char_item (entry, menu, "Line End", "\n");
create_special_char_item (entry, menu, "Tab", "\t");
gtk_widget_show_all (menu);
return menu;
}
static void
moo_entry_populate_popup (GtkEntry *gtkentry,
GtkMenu *menu)
@ -445,26 +525,56 @@ moo_entry_populate_popup (GtkEntry *gtkentry,
GtkWidget *item;
MooEntry *entry = MOO_ENTRY (gtkentry);
if (!entry->priv->enable_undo_menu)
if (entry->priv->enable_undo_menu)
{
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_REDO, NULL);
gtk_widget_show (item);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
gtk_widget_set_sensitive (item, entry->priv->enable_undo &&
moo_undo_mgr_can_redo (entry->priv->undo_mgr));
g_signal_connect_swapped (item, "activate", G_CALLBACK (moo_entry_redo), entry);
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_UNDO, NULL);
gtk_widget_show (item);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
gtk_widget_set_sensitive (item, entry->priv->enable_undo &&
moo_undo_mgr_can_undo (entry->priv->undo_mgr));
g_signal_connect_swapped (item, "activate", G_CALLBACK (moo_entry_undo), entry);
}
if (entry->priv->special_chars_menu)
{
GtkWidget *submenu;
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
item = gtk_menu_item_new_with_label ("Insert Special Character");
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
submenu = create_special_chars_menu (entry);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
}
}
void
moo_entry_set_use_special_chars_menu (MooEntry *entry,
gboolean use)
{
g_return_if_fail (MOO_IS_ENTRY (entry));
if ((entry->priv->special_chars_menu != 0) == (use != 0))
return;
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_REDO, NULL);
gtk_widget_show (item);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
gtk_widget_set_sensitive (item, entry->priv->enable_undo &&
moo_undo_mgr_can_redo (entry->priv->undo_mgr));
g_signal_connect_swapped (item, "activate", G_CALLBACK (moo_entry_redo), entry);
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_UNDO, NULL);
gtk_widget_show (item);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
gtk_widget_set_sensitive (item, entry->priv->enable_undo &&
moo_undo_mgr_can_undo (entry->priv->undo_mgr));
g_signal_connect_swapped (item, "activate", G_CALLBACK (moo_entry_undo), entry);
entry->priv->special_chars_menu = use != 0;
g_object_notify (G_OBJECT (entry), "use-special-chars-menu");
}

View File

@ -59,6 +59,9 @@ void moo_entry_end_undo_group (MooEntry *entry);
void moo_entry_clear_undo (MooEntry *entry);
MooUndoMgr *moo_entry_get_undo_mgr (MooEntry *entry);
void moo_entry_set_use_special_chars_menu(MooEntry *entry,
gboolean use);
G_END_DECLS

View File

@ -148,6 +148,7 @@ moo_history_entry_init (MooHistoryEntry *entry)
gtk_cell_layout_clear (GTK_CELL_LAYOUT (entry));
cell = gtk_cell_renderer_text_new ();
g_object_set (cell, "single-paragraph-mode", TRUE, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (entry), cell, TRUE);
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (entry), cell,
(GtkCellLayoutDataFunc) cell_data_func,
@ -167,9 +168,9 @@ moo_history_entry_init (MooHistoryEntry *entry)
static void
moo_history_entry_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MooHistoryEntry *entry = MOO_HISTORY_ENTRY (object);
@ -198,9 +199,9 @@ moo_history_entry_set_property (GObject *object,
static void
moo_history_entry_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MooHistoryEntry *entry = MOO_HISTORY_ENTRY (object);