Skip to content

Commit 4873eb8

Browse files
fourplusonemonkeydom
authored andcommitted
[FIX #142] Truncate text in titlebar at head position (#149)
* [FIX #142] Truncate text in titlebar at head position * fix indentation adjustments by @monkeydom: * Adjusted the mode of opertation for this fix slightly. * Configuring the NSTextField and then just removing the preset attributes vs updating the ParagraphAttributes of the title each time. (might be worse if the AttributedTitle is needed for something else) * Went to fetch the NSTextField of the window a little bit differently with less hierarchy traversal. (might break differently if Apple ever changes it, but feels a little bit better) * Fixed issue where the window title synchronization did load the window earlier than it needs to be loaded in terms of the default lifecycle of the NSWindowController
1 parent e797fb5 commit 4873eb8

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

SubEthaEdit-Mac/Source/PlainTextWindowController.m

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,19 @@ - (void)windowWillLoad {
7272
}
7373

7474
- (void)windowDidLoad {
75-
NSWindow *window = self.window;
75+
NSWindow *window = self.window;
7676
[[window contentView] setAutoresizesSubviews:YES];
77-
[self updateWindowMinSize];
77+
78+
NSTextField *titleBarTextField = [self SEE_titlebarTextField];
79+
80+
// Configure the truncation here
81+
if (titleBarTextField) {
82+
titleBarTextField.allowsDefaultTighteningForTruncation = YES;
83+
titleBarTextField.lineBreakMode = NSLineBreakByTruncatingHead;
84+
titleBarTextField.maximumNumberOfLines = 1;
85+
}
86+
87+
[self updateWindowMinSize];
7888
}
7989

8090

@@ -453,9 +463,9 @@ - (void)updateLock {
453463

454464
- (void)synchronizeWindowTitleWithDocumentName {
455465
[super synchronizeWindowTitleWithDocumentName];
456-
457-
NSWindowTab *tab = self.window.tab;
458-
tab.title = self.plainTextDocument.displayName;
466+
if (self.windowLoaded) { // Don't trigger load of window prematurely
467+
[self SEE_postprocessUpdateOfWindowTitle];
468+
}
459469

460470
[self updateLock];
461471
}
@@ -573,6 +583,29 @@ - (void)updateWindowMinSize {
573583
}
574584
}
575585

586+
- (NSTextField *)SEE_titlebarTextField {
587+
NSButton *closeButton = [self.window standardWindowButton:NSWindowCloseButton];
588+
if ([closeButton.superview isKindOfClass:NSClassFromString(@"NSTitlebarView")]) {
589+
// return first NSTextField of that
590+
for (id view in closeButton.superview.subviews) {
591+
if ([view isKindOfClass:[NSTextField class]]) {
592+
return view;
593+
}
594+
}
595+
}
596+
return nil;
597+
}
598+
599+
- (void)SEE_postprocessUpdateOfWindowTitle {
600+
NSWindowTab *tab = self.window.tab;
601+
tab.title = self.plainTextDocument.displayName;
602+
603+
// clean out the attributed title and use the configuraiton of the textfield -
604+
// if that is too radical we could just adjust the linebreakmode
605+
// of the read attributed string and set it again on the text field
606+
NSTextField *titlebarTextField = [self SEE_titlebarTextField];
607+
titlebarTextField.stringValue = titlebarTextField.attributedStringValue.string;
608+
}
576609

577610
#pragma mark - Dialog Split
578611

0 commit comments

Comments
 (0)