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.
This commit is contained in:
Allan Odgaard
2013-01-25 14:57:43 +01:00
parent ece57c79b8
commit 61fd5d04df
3 changed files with 13 additions and 18 deletions

View File

@@ -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

View File

@@ -2,6 +2,8 @@
#import <scm/scm.h>
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

View File

@@ -186,7 +186,6 @@ static path::glob_list_t globs_for_path (std::string const& path)
std::vector<document_record_t> _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];