From b3d789fcec1061d71eb6c1618f570a41a1c4de7f Mon Sep 17 00:00:00 2001
From: espectador
Date: Sun, 16 Jan 2011 00:32:54 +0000
Subject: [PATCH] Applied changes in menuInWindow.patch
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@31895 72102866-910b-0410-8b05-ffd578937521
---
ChangeLog | 11 +++++++++++
Headers/AppKit/NSApplication.h | 1 +
Source/NSApplication.m | 34 ++++++++++++++++++++++------------
Source/NSMenuView.m | 20 ++++++++++++++++----
Source/NSSavePanel.m | 8 --------
Source/NSWindow.m | 8 --------
6 files changed, 50 insertions(+), 32 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f885b6554..562afe2ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-01-15 German Arias
+
+ * Source/NSWindow.m:
+ * Source/NSSavePanel.m: Reverted latest changes.
+ * Source/NSMenuView.m: Added the appropriate code to close
+ the menu after select an option, but before do the
+ instructions of the selected option.
+ * Headers/AppKit/NSApplication.h:
+ * Source/NSApplication.m: Save the main window when the
+ app is hidden or when is deactivated.
+
2011-01-15 Wolfgang Lux
* Source/NSColorWell.m (-activate:): Deactivate an activate color
diff --git a/Headers/AppKit/NSApplication.h b/Headers/AppKit/NSApplication.h
index 45aae9b6d..120a5192d 100644
--- a/Headers/AppKit/NSApplication.h
+++ b/Headers/AppKit/NSApplication.h
@@ -145,6 +145,7 @@ APPKIT_EXPORT NSString *NSEventTrackingRunLoopMode;
NSMutableArray *_hidden;
NSMutableArray *_inactive;
NSWindow *_hidden_key;
+ NSWindow *_hidden_main;
GSInfoPanel *_infoPanel;
/* This autorelease pool should only be created and used by -run, with
diff --git a/Source/NSApplication.m b/Source/NSApplication.m
index f7f180084..243f1977a 100644
--- a/Source/NSApplication.m
+++ b/Source/NSApplication.m
@@ -1315,18 +1315,17 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
[_hidden_key makeKeyWindow];
_hidden_key = nil;
}
+
+ if ([self mainWindow] == nil && _hidden_main != nil
+ && [[self windows] indexOfObjectIdenticalTo: _hidden_main] != NSNotFound)
+ {
+ [_hidden_main makeMainWindow];
+ _hidden_main = nil;
+ }
if ([self keyWindow] != nil)
{
[[self keyWindow] orderFront: self];
-
- /* If menu is in window, we need a main window, in other way
- the menu can't respond */
- if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self) ==
- NSWindows95InterfaceStyle && [[self keyWindow] canBecomeMainWindow])
- {
- [[self keyWindow] becomeMainWindow];
- }
}
else if ([self mainWindow] != nil)
{
@@ -1376,10 +1375,13 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
_hidden_key = [self keyWindow];
[_hidden_key resignKeyWindow];
}
- // FIXME: main window is not saved for when the app is activated again.
- // This is not a problem if it is also key, and I'm not sure if it
- // is a problem at all. May be annoying in the case of workspace switch.
- [[self mainWindow] resignMainWindow];
+ // The main window is saved for when the app is activated again.
+ // This is necessary for menu in window.
+ if ([self mainWindow] != nil)
+ {
+ _hidden_main = [self mainWindow];
+ [_hidden_main resignMainWindow];
+ }
windows_list = GSOrderedWindows();
iter = [windows_list reverseObjectEnumerator];
@@ -2418,6 +2420,14 @@ image.
See Also: -applicationIconImage
[_hidden_key resignKeyWindow];
}
+ // The main window is saved for when the app is activated again.
+ // This is necessary for menu in window.
+ if ([self mainWindow] != nil)
+ {
+ _hidden_main = [self mainWindow];
+ [_hidden_main resignMainWindow];
+ }
+
windows_list = GSOrderedWindows();
iter = [windows_list reverseObjectEnumerator];
diff --git a/Source/NSMenuView.m b/Source/NSMenuView.m
index 762078d13..faf88a7bd 100644
--- a/Source/NSMenuView.m
+++ b/Source/NSMenuView.m
@@ -1389,14 +1389,21 @@ static NSMapTable *viewInfo = 0;
- (BOOL) _executeItemAtIndex: (int)indexOfActionToExecute
removeSubmenu: (BOOL)subMenusNeedRemoving
{
+ NSInterfaceStyle style =
+ NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self);
+
+ /*If we have menu in window, close the menu after select
+ an option*/
+ if (style == NSWindows95InterfaceStyle)
+ {
+ [[[[NSApp mainWindow] menu] attachedMenu] close];
+ }
+
if (indexOfActionToExecute >= 0
&& [_attachedMenu attachedMenu] != nil && [_attachedMenu attachedMenu] ==
[[_items_link objectAtIndex: indexOfActionToExecute] submenu])
{
- NSInterfaceStyle style =
- NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self);
- if (style == NSMacintoshInterfaceStyle ||
- style == NSWindows95InterfaceStyle)
+ if (style == NSMacintoshInterfaceStyle)
{
// On Macintosh, clicking on or releasing the mouse over a
// submenu item always closes the menu (if it is open) and
@@ -1405,6 +1412,11 @@ static NSMapTable *viewInfo = 0;
return YES;
}
+ if (style == NSWindows95InterfaceStyle)
+ {
+ return YES;
+ }
+
if (subMenusNeedRemoving)
{
[self detachSubmenu];
diff --git a/Source/NSSavePanel.m b/Source/NSSavePanel.m
index 331edd5fe..77a844092 100644
--- a/Source/NSSavePanel.m
+++ b/Source/NSSavePanel.m
@@ -50,7 +50,6 @@
#import "AppKit/NSImage.h"
#import "AppKit/NSImageView.h"
#import "AppKit/NSMatrix.h"
-#import "AppKit/NSMenu.h"
#import "AppKit/NSPasteboard.h"
#import "AppKit/NSDragging.h"
#import "AppKit/NSSavePanel.h"
@@ -183,7 +182,6 @@ setPath(NSBrowser *browser, NSString *path)
NSImage *image;
NSRect r;
id lastKeyView;
- NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil);
// Track window resizing so we can change number of browser columns.
[[NSNotificationCenter defaultCenter] addObserver: self
@@ -375,12 +373,6 @@ setPath(NSBrowser *browser, NSString *path)
[self registerForDraggedTypes: [NSArray arrayWithObjects:
NSFilenamesPboardType, nil]];
-
- if (style == NSWindows95InterfaceStyle)
- {
- [[[[NSApp mainWindow] menu] attachedMenu] close];
- }
-
return self;
}
diff --git a/Source/NSWindow.m b/Source/NSWindow.m
index 949f43061..fc10144dd 100644
--- a/Source/NSWindow.m
+++ b/Source/NSWindow.m
@@ -1818,14 +1818,6 @@ many times.
if (_f.is_main == YES)
{
_f.is_main = NO;
-
- //We close the menu if the app will be hide
- if (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", self) ==
- NSWindows95InterfaceStyle)
- {
- [[[self menu] attachedMenu] close];
- }
-
if (_f.is_key == YES)
{
[_wv setInputState: GSTitleBarKey];