gnustep-dev
[Top][All Lists]
Advanced

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

exception panel userInfo browser


From: Matt Rice
Subject: exception panel userInfo browser
Date: Sat, 21 Oct 2006 14:58:48 -0700 (PDT)

not sure if anyone is opposed to adding something like
this...

it provides a userInfo browser to the exception panel
which gets shown when you click on the icon in the
upper left hand corner.

i find it very useful when doing key value coding
stuff
and you have dictionaries with arrays of dictionaries
and stuff

it isn't the most polished looking but it does the job.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
Index: Source/NSAlert.m
===================================================================
--- Source/NSAlert.m    (revision 23935)
+++ Source/NSAlert.m    (working copy)
@@ -163,10 +163,12 @@
 
 
 @class GSAlertPanel;
address@hidden  GSExceptionPanel;
 
 static GSAlertPanel    *standardAlertPanel = nil;
 static GSAlertPanel    *informationalAlertPanel = nil;
 static GSAlertPanel    *criticalAlertPanel = nil;
+static GSAlertPanel    *nonstandardExceptionPanel = nil;
 
 @interface     GSAlertPanel: NSPanel
 {
@@ -869,6 +871,7 @@
 static GSAlertPanel*
 getSomePanel(
   GSAlertPanel **instance,
+  Class panelClass,
   NSString *defaultTitle,
   NSString *title,
   NSString *message,
@@ -882,7 +885,7 @@
     {
       if ([*instance isActivePanel])
        {                               // c:
-         panel = [[GSAlertPanel alloc] init];
+         panel = [[panelClass alloc] init];
        }
       else
        {                               // b:
@@ -891,7 +894,7 @@
     }
   else
     {                                  // a:
-      panel = [[GSAlertPanel alloc] init];
+      panel = [[panelClass alloc] init];
       *instance = panel;
     }
 
@@ -928,8 +931,8 @@
   message = [NSString stringWithFormat: msg arguments: ap];
   va_end(ap);
 
-  return getSomePanel(&standardAlertPanel, defaultTitle, title, message,
-    defaultButton, alternateButton, otherButton);
+  return getSomePanel(&standardAlertPanel, [GSAlertPanel class], defaultTitle,
+                 title, message, defaultButton, alternateButton, otherButton);
 }
 
 int
@@ -954,8 +957,8 @@
       defaultButton = @"OK";
     }
 
-  panel = getSomePanel(&standardAlertPanel, defaultTitle, title, message,
-    defaultButton, alternateButton, otherButton);
+  panel = getSomePanel(&standardAlertPanel, [GSAlertPanel class], defaultTitle,
+                 title, message, defaultButton, alternateButton, otherButton);
   result = [panel runModal];
   NSReleaseAlertPanel(panel);
   return result;
@@ -1001,8 +1004,8 @@
       defaultButton = @"OK";
     }
 
-  panel = getSomePanel(&standardAlertPanel, @"Alert", title, message,
-                    defaultButton, alternateButton, otherButton);
+  panel = getSomePanel(&standardAlertPanel, [GSAlertPanel class], @"Alert",
+                 title, message, defaultButton, alternateButton, otherButton);
   result = [panel runModal];
   NSReleaseAlertPanel(panel);
   return result;
@@ -1025,8 +1028,8 @@
   message = [NSString stringWithFormat: msg arguments: ap];
   va_end(ap);
 
-  return getSomePanel(&criticalAlertPanel, @"Critical", title, message,
-    defaultButton, alternateButton, otherButton);
+  return getSomePanel(&criticalAlertPanel, [GSAlertPanel class], @"Critical",
+                 title, message, defaultButton, alternateButton, otherButton);
 }
 
 
@@ -1047,8 +1050,8 @@
   message = [NSString stringWithFormat: msg arguments: ap];
   va_end(ap);
 
-  panel = getSomePanel(&criticalAlertPanel, @"Critical", title, message,
-    defaultButton, alternateButton, otherButton);
+  panel = getSomePanel(&criticalAlertPanel, [GSAlertPanel class], @"Critical",
+                 title, message, defaultButton, alternateButton, otherButton);
   result = [panel runModal];
   NSReleaseAlertPanel(panel);
   return result;
@@ -1070,8 +1073,8 @@
   message = [NSString stringWithFormat: msg arguments: ap];
   va_end(ap);
 
-  return getSomePanel(&informationalAlertPanel, @"Information", title, message,
-    defaultButton, alternateButton, otherButton);
+  return getSomePanel(&informationalAlertPanel, [GSAlertPanel class], 
+   @"Information", title, message, defaultButton, alternateButton, 
otherButton);
 }
 
 
@@ -1093,6 +1096,7 @@
   va_end(ap);
 
   panel = getSomePanel(&informationalAlertPanel,
+                     [GSAlertPanel class],
                      @"Information",
                      title, message,
                      defaultButton, alternateButton, otherButton);
@@ -1140,8 +1144,8 @@
       defaultButton = @"OK";
     }
 
-  panel = getSomePanel(&standardAlertPanel, defaultTitle, title, message,
-    defaultButton, alternateButton, otherButton);
+  panel = getSomePanel(&standardAlertPanel, [GSAlertPanel class], 
defaultTitle, 
+                 title, message, defaultButton, alternateButton, otherButton);
   
   // FIXME: We should also change the button action to call endSheet:
   [NSApp beginSheet: panel
@@ -1172,8 +1176,8 @@
   message = [NSString stringWithFormat: msg arguments: ap];
   va_end(ap);
 
-  panel = getSomePanel(&criticalAlertPanel, @"Critical", title, message,
-    defaultButton, alternateButton, otherButton);
+  panel = getSomePanel(&criticalAlertPanel, [GSAlertPanel class], @"Critical",
+                 title, message, defaultButton, alternateButton, otherButton);
 
   // FIXME: We should also change the button action to call endSheet:
   [NSApp beginSheet: panel
@@ -1205,6 +1209,7 @@
   va_end(ap);
 
   panel = getSomePanel(&informationalAlertPanel,
+                     [GSAlertPanel class],
                      @"Information",
                      title, message,
                      defaultButton, alternateButton, otherButton);
@@ -1468,3 +1473,221 @@
 }
 
 @end
+
address@hidden GSExceptionPanel : GSAlertPanel
+{
+  NSBrowser *_browser;
+  NSDictionary *_userInfo;
+}
+- (void) setUserInfo:(NSDictionary *)userInfo;
address@hidden
+
+int GSRunExceptionPanel(
+  NSString *title,
+  NSException *exception,
+  NSString *defaultButton,
+  NSString *alternateButton,
+  NSString *otherButton)
+{
+  NSString      *message;
+  GSExceptionPanel  *panel;
+  int           result;
+
+  message = [NSString stringWithFormat:@"%@: %@",
+                               [exception name],
+                               [exception reason]];
+  if (defaultButton == nil)
+    {
+      defaultButton = @"OK";
+    }
+
+  panel = (GSExceptionPanel *)getSomePanel(&nonstandardExceptionPanel,
+                       [GSExceptionPanel class],
+                       defaultTitle, title, message,
+                       defaultButton, alternateButton, otherButton);
+  [panel setUserInfo: [exception userInfo]];
+  result = [panel runModal];
+  [panel setUserInfo: nil];
+  NSReleaseAlertPanel(panel);
+  return result;
+}
+
address@hidden GSExceptionPanel
+- (id) init
+{
+  if ((self = [super init]))
+    {
+      [icoButton setEnabled:YES];
+      [icoButton setTarget:self];
+      [icoButton setAction:@selector(_icoAction:)];
+    }
+
+  return self;
+}
+- (void) setUserInfo:(NSDictionary *)userInfo;
+{
+  ASSIGN(_userInfo, userInfo);
+  [_browser reloadColumn:0];
+}
+
+- (void) _icoAction:(id)sender
+{
+  if (!_browser)
+    {
+      NSRect fr = [[self contentView] bounds];
+      NSBox *box;
+      
+      fr = NSMakeRect(0, 108, fr.size.width, fr.size.height);
+      box = [[NSBox alloc] initWithFrame:fr];
+      
+      [box setTitlePosition:NSNoTitle];
+      [box setBorderType:NSNoBorder];
+
+      [box addSubview:defButton];
+      [box addSubview:altButton];
+      [box addSubview:othButton];
+      [box addSubview:icoButton];
+      [box addSubview:titleField];
+      [box addSubview:messageField];
+      [box addSubview:scroll];
+      
+      [[self contentView] addSubview:box];
+
+      _browser = [[NSBrowser alloc]
+             initWithFrame:NSMakeRect(8, 8, _frame.size.width - 16, 100)];
+      [_browser setDelegate:self];
+      fr = NSMakeRect(_frame.origin.x, _frame.origin.y, 
+                     _frame.size.width + 8, _frame.size.height + 116);
+      [[self contentView] addSubview:_browser];
+      [self setMaxSize:fr.size];
+      [self setFrame:fr display:YES];
+    }
+  [_browser reloadColumn:0];
+}
+
+- (int) browser:(id)browser
+numberOfRowsInColumn:(int)col
+{
+  if (col == 0)
+    return [[_userInfo allKeys] count];
+  else
+    {
+      id val = [[(NSCell *)[browser selectedCellInColumn:col - 1] 
representedObject] description];
+      volatile id foo = nil;
+      NS_DURING
+         foo = [val propertyList];
+         val = foo;
+      NS_HANDLER
+      NS_ENDHANDLER
+      
+      if ([val isKindOfClass:[NSArray class]])
+       return [val count];
+      else if ([val isKindOfClass:[NSDictionary class]])
+        return [[val allKeys] count];
+      else return val != nil;
+    }
+  return 0;
+}
+
+- (void) browser:(NSBrowser *)browser willDisplayCell:(NSBrowserCell *)cell 
atRow:(int)row
+column:(int)column
+{
+  if (column == 0)
+    {
+      id key = [[_userInfo allKeys] objectAtIndex:row]; 
+      id val = [_userInfo objectForKey:key]; 
+      BOOL flag;
+
+      flag = [val isKindOfClass:[NSArray class]]
+             || [val isKindOfClass:[NSDictionary class]];
+      
+      [cell setLeaf:NO];
+      [cell setStringValue:[key description]];
+      [cell setRepresentedObject: val];
+    }
+  else
+    {
+      volatile id val = [(NSCell *)[browser selectedCellInColumn:column - 1] 
representedObject];
+      BOOL flag;
+     
+      if (!([val isKindOfClass:[NSArray class]] || [val isKindOfClass:[NSArray 
class]]))
+        {
+          volatile id foo = nil;
+         val = [val description];
+         NS_DURING 
+           foo = [val propertyList];
+           val = foo;
+         NS_HANDLER
+         NS_ENDHANDLER
+       }    
+      flag = (!([val isKindOfClass:[NSArray class]]
+             || [val isKindOfClass:[NSDictionary class]]));
+     
+      
+      
+      [cell setLeaf:flag];
+      
+      if ([val isKindOfClass:[NSArray class]])
+        {
+         volatile id obj = [val objectAtIndex:row];
+         if (!([obj isKindOfClass:[NSArray class]] || [obj 
isKindOfClass:[NSArray class]]))
+           {
+             volatile id foo;
+             obj = [[obj description] propertyList]; 
+             NS_DURING
+               foo = [obj propertyList]; 
+               obj = foo;
+             NS_HANDLER
+             NS_ENDHANDLER
+           }
+
+         if ([obj isKindOfClass:[NSArray class]])
+           {
+              [cell setRepresentedObject:obj];
+             [cell setLeaf:NO];
+              [cell setStringValue:[NSString stringWithFormat:@"%@ %p", [obj 
class], obj]];
+           }
+         else if ([obj isKindOfClass:[NSDictionary class]])
+           {
+             [cell setRepresentedObject:obj];
+             [cell setLeaf:NO];
+              [cell setStringValue:[NSString stringWithFormat:@"%@ %p", [obj 
class], obj]];
+           }
+         else
+           {
+             [cell setLeaf:YES];
+             [cell setStringValue:[obj description]];
+             [cell setRepresentedObject:nil];
+           }
+       }
+      else if ([val isKindOfClass:[NSDictionary class]])
+        {
+         id key = [[val allKeys] objectAtIndex:row];
+          volatile id it = [(NSDictionary *)val objectForKey: key];
+         volatile id foo;
+         foo = [it description];
+         NS_DURING
+           foo = [it propertyList];
+           it = foo;
+         NS_HANDLER
+         NS_ENDHANDLER
+         [cell setStringValue:[key description]];
+         [cell setRepresentedObject:it];
+        } 
+      else
+        {
+         [cell setLeaf:YES];
+         [cell setStringValue:[val description]];
+        }
+      
+    }
+}
+- (id) browser:(NSBrowser *)browser titleOfColumn:(int)column
+{
+  if (column == 0) return @"userInfo";
+  id val = [(NSCell *)[browser selectedCellInColumn:column - 1] 
representedObject];
+  NSString *title = [NSString stringWithFormat:@"%@ %p", [val class], val];
+  return title;
+}
address@hidden
+
Index: Source/NSApplication.m
===================================================================
--- Source/NSApplication.m      (revision 23936)
+++ Source/NSApplication.m      (working copy)
@@ -113,19 +113,17 @@
       [exception raise];
     }
 
-  retVal = NSRunCriticalAlertPanel 
+  retVal = GSRunExceptionPanel 
     ([NSString stringWithFormat: _(@"Critical Error in %@"),
               [[NSProcessInfo processInfo] processName]],
-     @"%@: %@", 
+     exception,
      _(@"Abort"), 
      nil,
 #ifdef DEBUG
-     _(@"Debug"),
+     _(@"Debug"));
 #else
-     nil,
+     nil);
 #endif
-     [exception name], 
-     [exception reason]);
 
   /* The user wants to abort */
   if (retVal == NSAlertDefault)
Index: Headers/AppKit/NSPanel.h
===================================================================
--- Headers/AppKit/NSPanel.h    (revision 23935)
+++ Headers/AppKit/NSPanel.h    (working copy)
@@ -174,6 +174,12 @@
                                                   void *contextInfo, 
                                                   NSString *msg, ...);
 
+APPKIT_EXPORT int GSRunExceptionPanel(NSString *title,
+                                      NSException *exception,
+                                      NSString *defaultButton,
+                                      NSString *alternateButton,
+                                      NSString *otherButton);
+
 #endif
 
 //

PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]