summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2013-02-15 21:03:33 +0000
committertavmjong-free <tavmjong@free.fr>2013-02-15 21:03:33 +0000
commit595f1268ac8ccc9b102679112559d0ee9e5274f5 (patch)
tree3b607de20a66e066ce5be4e8891c2e04cf9bf52d /src
parentBug #561503: fix typo in earlier fix (r11133) (diff)
downloadinkscape-595f1268ac8ccc9b102679112559d0ee9e5274f5.tar.gz
inkscape-595f1268ac8ccc9b102679112559d0ee9e5274f5.zip
Selection based on font-family via icon in text-toolbar font-family entry box.
(bzr r12129)
Diffstat (limited to 'src')
-rw-r--r--src/ink-comboboxentry-action.cpp127
-rw-r--r--src/ink-comboboxentry-action.h16
-rw-r--r--src/widgets/text-toolbar.cpp47
3 files changed, 167 insertions, 23 deletions
diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp
index fd146926f..48be6be1b 100644
--- a/src/ink-comboboxentry-action.cpp
+++ b/src/ink-comboboxentry-action.cpp
@@ -307,7 +307,14 @@ static void ink_comboboxentry_action_init (Ink_ComboBoxEntry_Action *action)
action->entry_completion = NULL;
action->indicator = NULL;
action->popup = false;
+ action->info = NULL;
+ action->info_cb = NULL;
+ action->info_cb_id = 0;
+ action->info_cb_blocked = false;
action->warning = NULL;
+ action->warning_cb = NULL;
+ action->warning_cb_id = 0;
+ action->warning_cb_blocked = false;
action->altx_name = NULL;
action->focusWidget = NULL;
}
@@ -432,7 +439,6 @@ GtkWidget* create_tool_item( GtkAction* action )
// Add signal for GtkEntry to check if finished typing.
g_signal_connect( G_OBJECT(child), "activate", G_CALLBACK(entry_activate_cb), action );
g_signal_connect( G_OBJECT(child), "key-press-event", G_CALLBACK(keypress_cb), action );
-
}
gtk_activatable_set_related_action( GTK_ACTIVATABLE (item), GTK_ACTION( action ) );
@@ -496,35 +502,95 @@ gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink
gtk_entry_set_text( ink_comboboxentry_action->entry, text );
// Show or hide warning -- this might be better moved to text-toolbox.cpp
- bool clear = true;
+ if( ink_comboboxentry_action->info_cb_id != 0 &&
+ !ink_comboboxentry_action->info_cb_blocked ) {
+ g_signal_handler_block (G_OBJECT(ink_comboboxentry_action->entry),
+ ink_comboboxentry_action->info_cb_id );
+ ink_comboboxentry_action->info_cb_blocked = true;
+ }
+ if( ink_comboboxentry_action->warning_cb_id != 0 &&
+ !ink_comboboxentry_action->warning_cb_blocked ) {
+ g_signal_handler_block (G_OBJECT(ink_comboboxentry_action->entry),
+ ink_comboboxentry_action->warning_cb_id );
+ ink_comboboxentry_action->warning_cb_blocked = true;
+ }
+ bool set = false;
if( ink_comboboxentry_action->warning != NULL ) {
Glib::ustring missing = check_comma_separated_text( ink_comboboxentry_action );
if( !missing.empty() ) {
- GtkStockItem item;
- gboolean isStock = gtk_stock_lookup( GTK_STOCK_DIALOG_WARNING, &item );
- if (isStock) {
- gtk_entry_set_icon_from_stock( ink_comboboxentry_action->entry,
+ GtkStockItem item;
+ gboolean isStock = gtk_stock_lookup( GTK_STOCK_DIALOG_WARNING, &item );
+ if (isStock) {
+ gtk_entry_set_icon_from_stock( ink_comboboxentry_action->entry,
+ GTK_ENTRY_ICON_SECONDARY,
+ GTK_STOCK_DIALOG_WARNING );
+ } else {
+ gtk_entry_set_icon_from_icon_name( ink_comboboxentry_action->entry,
GTK_ENTRY_ICON_SECONDARY,
GTK_STOCK_DIALOG_WARNING );
- } else {
- gtk_entry_set_icon_from_icon_name( ink_comboboxentry_action->entry,
- GTK_ENTRY_ICON_SECONDARY,
- GTK_STOCK_DIALOG_WARNING );
+ }
+ // Can't add tooltip until icon set
+ Glib::ustring warning = ink_comboboxentry_action->warning;
+ warning += ": ";
+ warning += missing;
+ gtk_entry_set_icon_tooltip_text( ink_comboboxentry_action->entry,
+ GTK_ENTRY_ICON_SECONDARY,
+ warning.c_str() );
+
+ if( ink_comboboxentry_action->warning_cb ) {
+
+ // Add callback if we haven't already
+ if( ink_comboboxentry_action->warning_cb_id == 0 ) {
+ ink_comboboxentry_action->warning_cb_id =
+ g_signal_connect( G_OBJECT(ink_comboboxentry_action->entry),
+ "icon-press",
+ G_CALLBACK(ink_comboboxentry_action->warning_cb),
+ ink_comboboxentry_action);
+ }
+ // Unblock signal
+ if( ink_comboboxentry_action->warning_cb_blocked ) {
+ g_signal_handler_unblock (G_OBJECT(ink_comboboxentry_action->entry),
+ ink_comboboxentry_action->warning_cb_id );
+ ink_comboboxentry_action->warning_cb_blocked = false;
}
- // Can't add tooltip until icon set
- Glib::ustring warning = ink_comboboxentry_action->warning;
- warning += ": ";
- warning += missing;
- gtk_entry_set_icon_tooltip_text( ink_comboboxentry_action->entry,
- GTK_ENTRY_ICON_SECONDARY,
- warning.c_str() );
- clear = false;
+ }
+ set = true;
}
}
- if( clear ) {
+ if( !set && ink_comboboxentry_action->info != NULL ) {
+ gtk_entry_set_icon_from_icon_name( GTK_ENTRY(ink_comboboxentry_action->entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ GTK_STOCK_SELECT_ALL );
+ gtk_entry_set_icon_from_stock( GTK_ENTRY(ink_comboboxentry_action->entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ GTK_STOCK_SELECT_ALL );
+ gtk_entry_set_icon_tooltip_text( ink_comboboxentry_action->entry,
+ GTK_ENTRY_ICON_SECONDARY,
+ ink_comboboxentry_action->info );
+
+ if( ink_comboboxentry_action->info_cb ) {
+ // Add callback if we haven't already
+ if( ink_comboboxentry_action->info_cb_id == 0 ) {
+ ink_comboboxentry_action->info_cb_id =
+ g_signal_connect( G_OBJECT(ink_comboboxentry_action->entry),
+ "icon-press",
+ G_CALLBACK(ink_comboboxentry_action->info_cb),
+ ink_comboboxentry_action);
+ }
+ // Unblock signal
+ if( ink_comboboxentry_action->info_cb_blocked ) {
+ g_signal_handler_unblock (G_OBJECT(ink_comboboxentry_action->entry),
+ ink_comboboxentry_action->info_cb_id );
+ ink_comboboxentry_action->info_cb_blocked = false;
+ }
+ }
+ set = true;
+ }
+
+ if( !set ) {
gtk_entry_set_icon_from_icon_name( GTK_ENTRY(ink_comboboxentry_action->entry),
GTK_ENTRY_ICON_SECONDARY,
NULL );
@@ -611,6 +677,24 @@ void ink_comboboxentry_action_set_tooltip( Ink_ComboBoxEntry_Action* action,
}
+void ink_comboboxentry_action_set_info( Ink_ComboBoxEntry_Action* action, const gchar* info ) {
+
+ g_free( action->info );
+ action->info = g_strdup( info );
+
+ // Widget may not have been created....
+ if( action->entry ) {
+ gtk_entry_set_icon_tooltip_text( GTK_ENTRY(action->entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ action->info );
+ }
+}
+
+void ink_comboboxentry_action_set_info_cb( Ink_ComboBoxEntry_Action* action, gpointer info_cb ) {
+
+ action->info_cb = info_cb;
+}
+
void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, const gchar* warning ) {
g_free( action->warning );
@@ -624,6 +708,11 @@ void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action,
}
}
+void ink_comboboxentry_action_set_warning_cb( Ink_ComboBoxEntry_Action* action, gpointer warning_cb ) {
+
+ action->warning_cb = warning_cb;
+}
+
void ink_comboboxentry_action_set_altx_name( Ink_ComboBoxEntry_Action* action, const gchar* altx_name ) {
g_free( action->altx_name );
diff --git a/src/ink-comboboxentry-action.h b/src/ink-comboboxentry-action.h
index f0dc0ee7e..6368dcb6c 100644
--- a/src/ink-comboboxentry-action.h
+++ b/src/ink-comboboxentry-action.h
@@ -58,7 +58,14 @@ struct _Ink_ComboBoxEntry_Action {
gint entry_width;// Width of GtkEntry in characters.
gint extra_width;// Extra Width of GtkComboBox.. to widen drop-down list in list mode.
gboolean popup; // Do we pop-up an entry-completion dialog?
- gchar *warning; // Text for warning that entry isn't in list.
+ gchar *info; // Text for tooltip info about entry.
+ gpointer info_cb; // Callback for clicking info icon.
+ gint info_cb_id;
+ gboolean info_cb_blocked;
+ gchar *warning; // Text for tooltip warning that entry isn't in list.
+ gpointer warning_cb; // Callback for clicking warning icon.
+ gint warning_cb_id;
+ gboolean warning_cb_blocked;
gchar *altx_name; // Target for Alt-X keyboard shortcut.
GtkWidget *focusWidget;
};
@@ -92,8 +99,11 @@ void ink_comboboxentry_action_set_extra_width( Ink_ComboBoxEntry_Action* act
void ink_comboboxentry_action_popup_enable( Ink_ComboBoxEntry_Action* action );
void ink_comboboxentry_action_popup_disable( Ink_ComboBoxEntry_Action* action );
-void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, const gchar* warning );
-void ink_comboboxentry_action_set_tooltip( Ink_ComboBoxEntry_Action* action, const gchar* tooltip );
+void ink_comboboxentry_action_set_info( Ink_ComboBoxEntry_Action* action, const gchar* info );
+void ink_comboboxentry_action_set_info_cb( Ink_ComboBoxEntry_Action* action, gpointer info_cb );
+void ink_comboboxentry_action_set_warning( Ink_ComboBoxEntry_Action* action, const gchar* warning_cb );
+void ink_comboboxentry_action_set_warning_cb(Ink_ComboBoxEntry_Action* action, gpointer warning );
+void ink_comboboxentry_action_set_tooltip( Ink_ComboBoxEntry_Action* action, const gchar* tooltip );
void ink_comboboxentry_action_set_altx_name( Ink_ComboBoxEntry_Action* action, const gchar* altx_name );
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index a01f950a6..45c9ef120 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -1494,6 +1494,44 @@ sp_text_toolbox_get_font_list_in_doc_recursive (SPObject *r, std::list<Glib::ust
}
}
+// Select all occurances of the font-family displayed in the Entry box.
+// TODO: possibly share with font-selector by moving most code to font-lister (passing family name)
+static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*position*/, GdkEvent /*event*/, gpointer /*data*/ ) {
+
+ Glib::ustring family = gtk_entry_get_text ( entry );
+
+ // Get all items with matching font-family set (not inherited!).
+ GSList *selectList = NULL;
+
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ SPDocument *document = sp_desktop_document( desktop );
+ GSList *allList = get_all_items(NULL, document->getRoot(), desktop, false, false, true, NULL);
+ for (GSList *i = allList; i != NULL; i = i->next) {
+
+ SPItem *item = SP_ITEM(i->data);
+ SPStyle *style = item->style;
+
+ if (style && style->text) {
+
+ Glib::ustring family_style;
+ if (style->text->font_family.set) {
+ family_style = style->text->font_family.value;
+ }
+ else if (style->text->font_specification.set) {
+ family_style = style->text->font_specification.value;
+ }
+
+ if (family_style.compare( family ) == 0 ) {
+ selectList = g_slist_prepend (selectList, item);
+ }
+ }
+ }
+
+ // Update selection
+ Inkscape::Selection *selection = sp_desktop_selection (desktop );
+ selection->clear();
+ selection->setList(selectList);
+}
// Define all the "widgets" in the toolbar.
void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
@@ -1526,8 +1564,15 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
(gpointer)font_lister_separator_func,
GTK_WIDGET(desktop->canvas)); // Focus widget
ink_comboboxentry_action_popup_enable( act ); // Enable entry completion
+
+ gchar *const info = _("Select all text with this font-family");
+ ink_comboboxentry_action_set_info( act, info ); // Show selection icon
+ ink_comboboxentry_action_set_info_cb( act, (gpointer)sp_text_toolbox_select_cb );
+
gchar *const warning = _("Font not found on system");
- ink_comboboxentry_action_set_warning( act, warning ); // Show icon with tooltip if missing font
+ ink_comboboxentry_action_set_warning( act, warning ); // Show icon if missing font
+ ink_comboboxentry_action_set_warning_cb( act, (gpointer)sp_text_toolbox_select_cb );
+
ink_comboboxentry_action_set_altx_name( act, "altx-text" ); // Set Alt-X keyboard shortcut
g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontfamily_value_changed), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );