On 2014-02-10 02:11:34 -0600 Fred Kiefer <[email protected]> wrote:
[...]
> 
> What you describe here seems about the correct thing to do. I really would be 
> interested in understanding what goes wrong here. As I understand your mails 
> this only happens with the extended WinUX open panel, not with the standard 
> one from GNUstep gui, is this correct?
> 
> Fred

The problem is only with Open/Save panels in WinUXTheme. The GNUstep panels 
works in a different way, and don't use +readable/writableTypes. Attached is a 
patch for WinNSOpenPanel.m in WinUXTheme. This contains the changes I'm testing 
currently. There are two changes. First in function filter_string_from_types() 
I put one entry for each extension (I will improve this later). Second change 
is at method -runModalForDirectory:file:.... in WinNSSavePanel implementation. 
Here I get all the extensions for all writable types, preventing add 
duplications since -fileExtensionsFromType: return all extension 
(NSUnixExtensions and NSDOSExtensions). With these changes Ink works perfectly. 
But Gorm (Save panel) not.

I don't have a Windows machine. But I will try tomorrow with GDB or adding some 
NSLog. However, if I remember correctly, NSLog don't works in a theme (almost 
on Windows).

Germán.

<changes.patch>
Index: WinNSOpenPanel.m
===================================================================
--- WinNSOpenPanel.m	(revisión: 37516)
+++ WinNSOpenPanel.m	(copia de trabajo)
@@ -111,28 +111,20 @@
       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];
 
-  [set addObjectsFromArray: types];
-  en = [set objectEnumerator];
+  en = [types objectEnumerator];
 
   // build the string..
   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: 
@@ -464,28 +456,38 @@
 		       types: (NSArray *)fileTypes
 	    relativeToWindow: (NSWindow*)window
 {
+  NSUInteger i, j;
   BOOL flag = YES;
   int result = NSOKButton;
   NSDocumentController *dc = [NSDocumentController sharedDocumentController];
-  NSArray *extensionsForDefaultType = [dc fileExtensionsFromType: [dc defaultType]];
-  NSMutableSet *typeset = [NSMutableSet set];
-  NSArray *types = nil; 
+  Class doc = [dc documentClassForType: [fileTypes objectAtIndex: 0]];
+  NSArray *types = nil, *names, *exts; 
+  NSMutableArray *tps= [NSMutableArray array];
 
-  [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
+  names = [doc writableTypes];
 
+  for (i = 0; i < [names count]; i++)
+    {
+      exts = [dc fileExtensionsFromType: [names objectAtIndex: i]];
+
+      for (j = 0; j < [exts count]; j++)
+        {
+          if (![tps containsObject: [exts objectAtIndex: j]])
+            {
+              [tps addObject: [exts objectAtIndex: j]];
+            }
+        }
+    }
+  types = [NSArray arrayWithArray: tps];
+
   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];
_______________________________________________
Gnustep-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to