From 61fd5d04df86cb0786c0f0d2a1a3683f2efc0ae0 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Fri, 25 Jan 2013 14:57:43 +0100 Subject: [PATCH] Position file chooser relative to text view This is instead of placing it relative to the entire window. The main motivation is that with the file browser on the right, I want the file chooser closer to the left edge of the window. --- .../DocumentWindow/src/DocumentController.mm | 12 +++++++++++- Frameworks/OakFilterList/src/FileChooser.h | 3 ++- Frameworks/OakFilterList/src/FileChooser.mm | 16 ---------------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Frameworks/DocumentWindow/src/DocumentController.mm b/Frameworks/DocumentWindow/src/DocumentController.mm index fa4124cc..1a4503ac 100644 --- a/Frameworks/DocumentWindow/src/DocumentController.mm +++ b/Frameworks/DocumentWindow/src/DocumentController.mm @@ -1463,7 +1463,17 @@ namespace fc.filterString = entry.string; } - [fc showWindowRelativeToWindow:self.window]; + if(![fc.window isVisible]) + { + NSRect frame = [fc.window frame]; + NSRect parent = [_window convertRectToScreen:[_textView convertRect:[_textView visibleRect] toView:nil]]; + + frame.origin.x = NSMinX(parent) + round((NSWidth(parent) - NSWidth(frame)) * 1 / 4); + frame.origin.y = NSMinY(parent) + round((NSHeight(parent) - NSHeight(frame)) * 3 / 4); + [fc.window setFrame:frame display:NO]; + } + + [fc showWindow:self]; } - (void)fileChooserDidSelectItems:(FileChooser*)sender diff --git a/Frameworks/OakFilterList/src/FileChooser.h b/Frameworks/OakFilterList/src/FileChooser.h index c53bcfb4..c0ce8f2b 100644 --- a/Frameworks/OakFilterList/src/FileChooser.h +++ b/Frameworks/OakFilterList/src/FileChooser.h @@ -2,6 +2,8 @@ #import PUBLIC @interface FileChooser : NSObject +@property (nonatomic) NSWindow* window; + @property (nonatomic) NSString* path; @property (nonatomic) scm::info_ptr const& scmInfo; @@ -19,6 +21,5 @@ PUBLIC @interface FileChooser : NSObject + (FileChooser*)sharedInstance; - (void)showWindow:(id)sender; -- (void)showWindowRelativeToWindow:(NSWindow*)parentWindow; - (void)close; @end diff --git a/Frameworks/OakFilterList/src/FileChooser.mm b/Frameworks/OakFilterList/src/FileChooser.mm index de52a00f..84614917 100644 --- a/Frameworks/OakFilterList/src/FileChooser.mm +++ b/Frameworks/OakFilterList/src/FileChooser.mm @@ -186,7 +186,6 @@ static path::glob_list_t globs_for_path (std::string const& path) std::vector _records; document::scanner_ptr _scanner; } -@property (nonatomic) NSWindow* window; @property (nonatomic) NSSearchField* searchField; @property (nonatomic) NSButton* allButton; @property (nonatomic) NSButton* openDocumentsButton; @@ -351,21 +350,6 @@ static path::glob_list_t globs_for_path (std::string const& path) [_window makeFirstResponder:_searchField]; } -- (void)showWindowRelativeToWindow:(NSWindow*)parentWindow -{ - if(parentWindow && ![_window isVisible]) - { - NSRect frame = [_window frame]; - NSRect parent = [parentWindow frame]; - - frame.origin.x = round(NSMidX(parent) - 0.5 * NSWidth(frame)); - frame.origin.y = NSMinY(parent) + round((NSHeight(parent) - NSHeight(frame)) * 3 / 4); - [_window setFrame:frame display:NO]; - } - - [self showWindow:self]; -} - - (void)close { [_window performClose:self];