[nautilus-actions] Fix mimetypes and folders selection



commit 8613e0c88738ddfd037c92a8099f5e08e1152981
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Aug 19 23:16:48 2010 +0200

    Fix mimetypes and folders selection

 ChangeLog                          |    7 +++++++
 src/core/na-icontext.c             |   22 ++++++++++++++++++++--
 src/plugin-menu/nautilus-actions.c |    3 ++-
 3 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index dce1b67..b225514 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2010-08-19 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-icontext.c
+	(is_mimetype_of): Take care of wildcard expressions.
+	(is_candidate_for_folders): Only try to g_pattern_match() if has pattern.
+
+	* src/plugin-menu/nautilus-actions.c
+	(build_nautilus_menus): Add debug messages.
+
 	* data/actions/open-terminal-here.desktop:
 	* data/actions/show-na-parameters.desktop: Fix typo.
 
diff --git a/src/core/na-icontext.c b/src/core/na-icontext.c
index e1b0867..91ea4d2 100644
--- a/src/core/na-icontext.c
+++ b/src/core/na-icontext.c
@@ -658,6 +658,8 @@ is_candidate_for_mimetypes( const NAIContext *object, guint target, GList *files
 
 				if( !positive || !match ){
 					if( is_mimetype_of( positive ? imtype : imtype+1, fgroup, fsubgroup )){
+						g_debug( "%s: condition=%s, positive=%s, ftype=%s, fgroup=%s, fsubgroup=%s, matched",
+								thisfn, imtype, positive ? "True":"False", ftype, fgroup, fsubgroup );
 						if( positive ){
 							match = TRUE;
 						} else {
@@ -698,6 +700,10 @@ is_mimetype_of( const gchar *mimetype, const gchar *fgroup, const gchar *fsubgro
 	gboolean is_type_of;
 	gchar *mgroup, *msubgroup;
 
+	if( !strcmp( mimetype, "*" ) || !strcmp( mimetype, "*/*" )){
+		return( TRUE );
+	}
+
 	split_mimetype( mimetype, &mgroup, &msubgroup );
 
 	is_type_of = ( strcmp( fgroup, mgroup ) == 0 );
@@ -932,10 +938,13 @@ is_candidate_for_folders( const NAIContext *object, guint target, GList *files )
 				gchar *dirname = na_selected_info_get_dirname( NA_SELECTED_INFO( files->data ));
 
 				if( na_core_utils_slist_count( distincts, dirname ) == 0 ){
+					g_debug( "%s: distinct dirname=%s", thisfn, dirname );
+
 					GSList *id;
-					gchar *dirname_utf8;
+					gchar *dirname_utf8, *pattern_utf8;
 					const gchar *pattern;
 					gboolean match, positive;
+					gboolean has_pattern;
 
 					distincts = g_slist_prepend( distincts, g_strdup( dirname ));
 					dirname_utf8 = g_filename_to_utf8( dirname, -1, NULL, NULL, NULL );
@@ -944,16 +953,25 @@ is_candidate_for_folders( const NAIContext *object, guint target, GList *files )
 					for( id = folders ; id && ok ; id = id->next ){
 						pattern = ( const gchar * ) id->data;
 						positive = is_positive_assertion( pattern );
+						pattern_utf8 = g_filename_to_utf8( positive ? pattern : pattern+1, -1, NULL, NULL, NULL );
+						has_pattern = ( g_strstr_len( pattern_utf8, -1, "*" ) != NULL );
 
 						if( !positive || !match ){
-							if( g_pattern_match_simple( positive ? pattern : pattern+1, dirname_utf8 )){
+							if(( has_pattern && g_pattern_match_simple( pattern_utf8, dirname_utf8 )) || g_str_has_prefix( dirname_utf8, pattern_utf8 )){
+								g_debug( "%s: condition=%s, positive=%s: matched",
+										thisfn, pattern, positive ? "True":"False" );
 								if( positive ){
 									match = TRUE;
 								} else {
 									ok = FALSE;
 								}
+							/*} else {
+								g_debug( "%s: condition=%s, positive=%s: not matched",
+										thisfn, pattern_utf8, positive ? "True":"False" );*/
 							}
 						}
+
+						g_free( pattern_utf8 );
 					}
 
 					ok &= match;
diff --git a/src/plugin-menu/nautilus-actions.c b/src/plugin-menu/nautilus-actions.c
index a294261..722f488 100644
--- a/src/plugin-menu/nautilus-actions.c
+++ b/src/plugin-menu/nautilus-actions.c
@@ -756,8 +756,9 @@ build_nautilus_menus( NautilusActions *plugin, GList *tree, guint target, GList
 		 */
 		if( NA_IS_OBJECT_MENU( it->data )){
 			subitems = na_object_get_items( it->data );
+			g_debug( "%s: menu has %d items", thisfn, g_list_length( subitems ));
 			submenu = build_nautilus_menus( plugin, subitems, target, files, tokens );
-			/*g_debug( "%s: submenu has %d items", thisfn, g_list_length( submenu ));*/
+			g_debug( "%s: submenu has %d items", thisfn, g_list_length( submenu ));
 
 			if( submenu ){
 				if( target == ITEM_TARGET_TOOLBAR ){



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]