El mié, 25-12-2013 a las 14:32 +0100, Fred Kiefer escribió:
> 
> I must admit I don't quite understand the issue at hand. You say that
> the string type has the value "txt, TXT". This looks wrong to me, why
> would a string that is an array of file extensions ever get used as an
> argument to displayNameForType:? In GNUstep gui the only place I could
> find where we call this method is NSDocument
> _addItemsToSpaButtonFromArray: and this method should get a list of type
> names (plus something called NSExportableAsKey which I don't remember).
> 
> Could you please give more information on the context? Or better point
> to the application that shows this behaviour? And does it show up
> without the WinUXTheme as well? And what about a Unix environment?
> I would be surprised to learn that themes affect the working of
> NSDocumentController, but then I was surprised to see my name in the
> code of WinUXTheme.
> 
> Fred
> 

Right, the type "txt, TXT" is wrong, I put the comma inside the double
quotes. But after fix this I'm facing annoying problems. 


This problem only occurs on Windows (latest installers) with native
open/save panels and when the document type have more than one
extension. With current implementation the function
filter_string_from_types() at WinNSOpenPanel class, build an entry with
all types in the array. For open panels there isn't problem, because
this load all supported types. But for save panels this don't allow
change the type, because there is present only one type (the current
type).

So, in the attached patch, I change the function
filter_string_from_types() to build one entry for each type. The result,
for open panels, is the attached image panel1. As you can see, the "txt"
and "TXT" don't show the corresponding name. The test app is Ink, where
I change the InkInfo.plist to add "TXT" in Text Document.

For save panels I use -writableTypes to pass all the available types. So
the user can change the format. The attached image panel2 show the
result, as you can see the extension for "Text document" is wrong.

Germán.


Index: WinNSOpenPanel.m
===================================================================
--- WinNSOpenPanel.m	(revisión: 37516)
+++ WinNSOpenPanel.m	(copia de trabajo)
@@ -111,28 +111,19 @@
       return L"All (*.*)\0*.*\0";
     }
 
-  NSMutableSet *set = [NSMutableSet set];
   NSEnumerator *en = nil;
   id type = nil;
   NSDocumentController *dc = [NSDocumentController sharedDocumentController];
   NSMutableString *filterString = [NSMutableString string];
-  NSMutableString *typesString = [NSMutableString string];
+  
+  en = [types objectEnumerator];
 
-  [set addObjectsFromArray: types];
-  en = [set objectEnumerator];
-
-  // build the string..
+  // Build the string, adding one entry for each type
   while((type = [en nextObject]) != nil)
     {
-	  [filterString appendFormat:@"%@ (*.%@),", [dc displayNameForType: type],
-        type];
-	  [typesString appendFormat: @"*.%@;",type];
+      [filterString appendFormat:@"%@ (*.%@)+*.%@+", [dc displayNameForType: type],
+       type, type];
     }
-  [filterString replaceCharactersInRange:NSMakeRange([filterString length]-1,1)
-    withString:@"+"];
-  [filterString appendString:typesString];
-  [filterString replaceCharactersInRange:NSMakeRange([filterString length]-1,1) 
-    withString:@"+"];
 
   // Add the nulls...
   unichar *fs = (unichar *)[filterString cStringUsingEncoding: 
@@ -281,8 +272,6 @@
 {
   BOOL flag = YES;
   int result = NSOKButton;
-  NSDocumentController *dc = [NSDocumentController sharedDocumentController];
-  NSArray *extensionsForDefaultType = [dc fileExtensionsFromType: [dc defaultType]];
   NSMutableSet *typeset = [NSMutableSet set];
   NSArray *types = nil; 
 
@@ -317,14 +306,7 @@
   ofn.hwndOwner = (HWND)[window windowNumber];
   ofn.lpstrFilter = (unichar *)filter_string_from_types(types);
   ofn.nFilterIndex = 0;
-  if ([extensionsForDefaultType count] > 0)
-  {
-  	NSUInteger defaultIndex = [types indexOfObject: [extensionsForDefaultType objectAtIndex: 0]];
-  	if (defaultIndex !=  NSNotFound)
-  	{
-  		ofn.nFilterIndex = defaultIndex + 1;
-  	}
-  }
+
 	ofn.lpstrTitle = (unichar *)[[self title] cStringUsingEncoding: NSUnicodeStringEncoding];
 	if ([name length])
   {
@@ -467,25 +449,19 @@
   BOOL flag = YES;
   int result = NSOKButton;
   NSDocumentController *dc = [NSDocumentController sharedDocumentController];
-  NSArray *extensionsForDefaultType = [dc fileExtensionsFromType: [dc defaultType]];
-  NSMutableSet *typeset = [NSMutableSet set];
+  id doc = [dc documentClassForType: [fileTypes objectAtIndex: 0]];
   NSArray *types = nil; 
 
-  [typeset addObjectsFromArray: fileTypes];
-  types = [typeset allObjects];
+  // Get all writable types, not only the current type. FOr the case when
+  // the user wants change the format of the file
+  types = [doc writableTypes];
 
   ofn.hwndOwner = (HWND)[window windowNumber];
   
   ofn.lpstrFilter = (unichar *)filter_string_from_types(types);
-  ofn.nFilterIndex = 0;
-  if ([extensionsForDefaultType count] > 0)
-  {
-  	NSUInteger defaultIndex = [types indexOfObject: [extensionsForDefaultType objectAtIndex: 0]];
-  	if (defaultIndex !=  NSNotFound)
-  	{
-  		ofn.nFilterIndex = defaultIndex + 1;
-  	}
-  }
+  // Select the current type
+  ofn.nFilterIndex = [types indexOfObject: [fileTypes objectAtIndex: 0]];
+
   ofn.lpstrTitle = (unichar *)[[self title] cStringUsingEncoding: NSUnicodeStringEncoding];
   if ([name length]) {
     NSString *file = [name lastPathComponent];

<<attachment: open1.jpg>>

<<attachment: panel2.jpg>>

_______________________________________________
Gnustep-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to