Setup key view loop manually for main window

The auto-calculated key view loop includes everything, which means dynamically added elements such as the close buttons for tab view items, but worse, the subviews of a view-based table view. So this change is required before switching to a view-based file browser.
This commit is contained in:
Allan Odgaard
2015-07-20 11:40:59 +02:00
parent 2f30d7d368
commit b3ec7b4c05
7 changed files with 24 additions and 6 deletions

View File

@@ -287,16 +287,17 @@ namespace
NSUInteger windowStyle = (NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask|NSTexturedBackgroundWindowMask);
self.window = [[NSWindow alloc] initWithContentRect:[NSWindow contentRectForFrameRect:[self frameRectForNewWindow] styleMask:windowStyle] styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO];
self.window.autorecalculatesKeyViewLoop = YES;
self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary;
self.window.delegate = self;
self.window.releasedWhenClosed = NO;
self.window.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary;
self.window.delegate = self;
self.window.releasedWhenClosed = NO;
[self.window setContentBorderThickness:0 forEdge:NSMaxYEdge]; // top border
[self.window setContentBorderThickness:0 forEdge:NSMinYEdge]; // bottom border
[self.window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
[self.window setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
OakAddAutoLayoutViewsToSuperview(@[ self.layoutView ], self.window.contentView);
OakSetupKeyViewLoop(@[ self.layoutView ], NO);
self.window.initialFirstResponder = self.textView;
[self.window.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:@{ @"view" : self.layoutView }]];
[self.window.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:@{ @"view" : self.layoutView }]];

View File

@@ -64,19 +64,31 @@ NSString* const kUserDefaultsHTMLOutputSizeKey = @"htmlOutputSize";
return newView;
}
- (void)setTabBarView:(OakTabBarView*)aTabBarView { _tabBarView = (OakTabBarView*)[self replaceView:_tabBarView withView:aTabBarView]; }
- (void)setDocumentView:(NSView*)aDocumentView { _documentView = [self replaceView:_documentView withView:aDocumentView]; }
- (void)updateKeyViewLoop
{
OakSetupKeyViewLoop(@[
_tabBarView ?: [NSNull null],
_documentView ?: [NSNull null],
_htmlOutputView ?: [NSNull null],
_fileBrowserView ?: [NSNull null],
], NO);
}
- (void)setTabBarView:(OakTabBarView*)aTabBarView { _tabBarView = (OakTabBarView*)[self replaceView:_tabBarView withView:aTabBarView]; [self updateKeyViewLoop]; }
- (void)setDocumentView:(NSView*)aDocumentView { _documentView = [self replaceView:_documentView withView:aDocumentView]; [self updateKeyViewLoop]; }
- (void)setHtmlOutputView:(NSView*)aHtmlOutputView
{
_htmlOutputDivider = [self replaceView:_htmlOutputDivider withView:(aHtmlOutputView ? (_htmlOutputOnRight ? OakCreateVerticalLine([NSColor controlShadowColor]) : OakCreateHorizontalLine([NSColor colorWithCalibratedWhite:0.500 alpha:1])) : nil)];
_htmlOutputView = [self replaceView:_htmlOutputView withView:aHtmlOutputView];
[self updateKeyViewLoop];
}
- (void)setFileBrowserView:(NSView*)aFileBrowserView
{
_fileBrowserDivider = [self replaceView:_fileBrowserDivider withView:aFileBrowserView ? OakCreateVerticalLine([NSColor controlShadowColor]) : nil];
_fileBrowserView = [self replaceView:_fileBrowserView withView:aFileBrowserView];
[self updateKeyViewLoop];
}
- (void)setFileBrowserOnRight:(BOOL)flag

View File

@@ -259,6 +259,7 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
};
OakAddAutoLayoutViewsToSuperview([views allValues], _view);
OakSetupKeyViewLoop(@[ _view, _headerView, _outlineView, _actionsView ], NO);
[_view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[browser(==header,==actionsDivider,==actions)]|" options:0 metrics:nil views:views]];
[_view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[header][browser][actionsDivider][actions]|" options:NSLayoutFormatAlignAllLeft metrics:nil views:views]];

View File

@@ -58,6 +58,7 @@ static NSButton* OakCreateImageButton (NSImage* image)
};
OakAddAutoLayoutViewsToSuperview([views allValues], self);
OakSetupKeyViewLoop(@[ self, _createButton, _actionsPopUpButton, _reloadButton, _searchButton, _favoritesButton, _scmButton ], NO);
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-3-[create(==24)]-1-[divider]-5-[actions(==30)]-(>=8)-[reload(==22,==search,==favorites,==scm)][search]-1-[favorites]-2-[scm]-(12)-|" options:0 metrics:nil views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[create(==divider,==actions,==reload,==search,==favorites,==scm)]|" options:0 metrics:nil views:views]];

View File

@@ -130,6 +130,7 @@ static NSPopUpButton* OakCreateFolderPopUpButton ()
};
OakAddAutoLayoutViewsToSuperview([views allValues], self);
OakSetupKeyViewLoop(@[ self, _folderPopUpButton, _goBackButton, _goForwardButton ], NO);
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(-3)-[folder(>=75)]-(3)-[divider]-(2)-[back(==22)]-(2)-[forward(==back)]-(3)-|" options:0 metrics:nil views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[bottomDivider]|" options:0 metrics:nil views:views]];

View File

@@ -110,6 +110,7 @@ static NSMenuItem* OakCreateIndentMenuItem (NSString* title, SEL action, id targ
};
OakAddAutoLayoutViewsToSuperview([views allValues], self);
OakSetupKeyViewLoop(@[ self, _grammarPopUp, _tabSizePopUp, _bundleItemsPopUp, _symbolPopUp, _macroRecordingButton ], NO);
[self.selectionField setContentHuggingPriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationHorizontal];
[self.selectionField setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow+2 forOrientation:NSLayoutConstraintOrientationHorizontal];

View File

@@ -138,6 +138,7 @@ private:
statusBar.target = self;
OakAddAutoLayoutViewsToSuperview(@[ gutterScrollView, gutterDividerView, textScrollView, statusDividerView, statusBar ], self);
OakSetupKeyViewLoop(@[ self, textView, statusBar ], NO);
document::document_ptr doc = document::from_content("", "text.plain"); // file type is only to avoid potential “no grammar” warnings in console
doc->set_custom_name("null document"); // without a name it grabs an untitled token