Skip to content

Commit cf21200

Browse files
Improvements to the statusbar icon/menu
1 parent c90884f commit cf21200

File tree

15 files changed

+149
-184
lines changed

15 files changed

+149
-184
lines changed

AppController.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
@class TitlebarButton;
3030
@class LinearDividerShader;
3131
@class TagEditingManager;
32-
@class StatusItemView;
3332
@class DFView;
3433
@class PreviewController;
3534
@class WordCountToken;
@@ -63,7 +62,6 @@
6362
BOOL wasDeleting;
6463
IBOutlet ETContentView *mainView;
6564
DFView *dualFieldView;
66-
StatusItemView *cView;
6765
NSStatusItem *statusItem;
6866
IBOutlet NSMenu *statBarMenu;
6967
TagEditingManager *tagEditor;
@@ -186,8 +184,6 @@ void outletObjectAwoke(id sender);
186184
//- (void)setIsEditing:(BOOL)inBool inCell:(NSCell *)theCell;
187185
//- (void)focusOnCtrlFld:(id)sender;
188186
- (NSMenu *)statBarMenu;
189-
- (void)toggleAttachedWindow:(NSNotification *)aNotification;
190-
- (void)toggleAttachedMenu:(NSNotification *)aNotification;
191187
- (NSArray *)commonLabelsForNotesAtIndexes:(NSIndexSet *)selDexes;
192188
- (IBAction)multiTag:(id)sender;
193189
- (void)releaseTagEditor:(NSNotification *)note;

AppController.m

Lines changed: 77 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#import "TagEditingManager.h"
4444
#import "NotesTableHeaderCell.h"
4545
#import "DFView.h"
46-
#import "StatusItemView.h"
4746
#import "ETContentView.h"
4847
#import "PreviewController.h"
4948
#import "ETClipView.h"
@@ -143,8 +142,6 @@ - (id)init {
143142

144143
NSNotificationCenter *nc=[NSNotificationCenter defaultCenter];
145144
[nc addObserver:previewController selector:@selector(requestPreviewUpdate:) name:@"TextViewHasChangedContents" object:self];
146-
[nc addObserver:self selector:@selector(toggleAttachedWindow:) name:@"NVShouldActivate" object:nil];
147-
[nc addObserver:self selector:@selector(toggleAttachedMenu:) name:@"StatusItemMenuShouldDrop" object:nil];
148145
[nc addObserver:self selector:@selector(togDockIcon:) name:@"AppShouldToggleDockIcon" object:nil];
149146
[nc addObserver:self selector:@selector(toggleStatusItem:) name:@"AppShouldToggleStatusItem" object:nil];
150147

@@ -344,65 +341,54 @@ - (void)runDelayedUIActionsAfterLaunch {
344341
[[prefsController bookmarksController] setAppController:self];
345342
[[prefsController bookmarksController] restoreWindowFromSave];
346343
[[prefsController bookmarksController] updateBookmarksUI];
347-
[self updateNoteMenus];
348-
[textView setupFontMenu];
349-
[prefsController registerAppActivationKeystrokeWithTarget:self selector:@selector(toggleNVActivation:)];
350-
[notationController updateLabelConnectionsAfterDecoding];
351-
[notationController checkIfNotationIsTrashed];
352-
[[SecureTextEntryManager sharedInstance] checkForIncompatibleApps];
353-
354-
//connect sparkle programmatically to avoid loading its framework at nib awake;
355-
356-
if (!NSClassFromString(@"SUUpdater")) {
357-
NSString *frameworkPath = [[[NSBundle bundleForClass:[self class]] privateFrameworksPath] stringByAppendingPathComponent:@"Sparkle.framework"];
358-
if ([[NSBundle bundleWithPath:frameworkPath] load]) {
359-
SUUpdater *updater =[NSClassFromString(@"SUUpdater") performSelector:@selector(sharedUpdater)];
360-
if (IsLionOrLater) {
361-
[updater setFeedURL:[NSURL URLWithString:kSparkleUpdateFeedForLions]];
362-
}else{
363-
[updater setFeedURL:[NSURL URLWithString:kSparkleUpdateFeedForSnowLeopard]];
364-
}
365-
[sparkleUpdateItem setTarget:updater];
366-
[sparkleUpdateItem setAction:@selector(checkForUpdates:)];
367-
NSMenuItem *siSparkle = [statBarMenu itemWithTag:902];
368-
[siSparkle setTarget:updater];
369-
[siSparkle setAction:@selector(checkForUpdates:)];
370-
if (![[prefsController notationPrefs] firstTimeUsed]) {
371-
//don't do anything automatically on the first launch; afterwards, check every 4 days, as specified in Info.plist
372-
// SEL checksSEL = @selector(setAutomaticallyChecksForUpdates:);
373-
[updater setAutomaticallyChecksForUpdates:YES];
374-
// [updater methodForSelector:checksSEL](updater, checksSEL, YES);
375-
}
376-
} else {
377-
NSLog(@"Could not load %@!", frameworkPath);
378-
}
379-
}else{
380-
NSLog(@"su");
381-
}
382-
// add elasticthreads' menuitems
383-
NSMenuItem *theMenuItem = [[[NSMenuItem alloc] init] autorelease];
384-
[theMenuItem setTarget:self];
385-
// NSMenu *notesMenu = [[[NSApp mainMenu] itemWithTag:NOTES_MENU_ID] submenu];
386-
theMenuItem = [theMenuItem copy];
387-
// [statBarMenu insertItem:theMenuItem atIndex:4];
388-
[theMenuItem release];
389-
//theMenuItem = [[viewMenu itemWithTag:801] copy];
390-
//[statBarMenu insertItem:theMenuItem atIndex:11];
391-
//[theMenuItem release];
344+
[self updateNoteMenus];
345+
[textView setupFontMenu];
346+
[prefsController registerAppActivationKeystrokeWithTarget:self selector:@selector(toggleNVActivation:)];
347+
[notationController updateLabelConnectionsAfterDecoding];
348+
[notationController checkIfNotationIsTrashed];
349+
[[SecureTextEntryManager sharedInstance] checkForIncompatibleApps];
350+
351+
//connect sparkle programmatically to avoid loading its framework at nib awake;
352+
// if (!NSClassFromString(@"SUUpdater")) {
353+
// NSLog(@"su:%@ SEL:%@",sparkleUpdateItem.target,sparkleUpdateItem.action);
354+
// }else{
355+
NSString *frameworkPath = [[[NSBundle bundleForClass:[self class]] privateFrameworksPath] stringByAppendingPathComponent:@"Sparkle.framework"];
356+
if ([[NSBundle bundleWithPath:frameworkPath] load]) {
357+
SUUpdater *updater =[SUUpdater sharedUpdater];
358+
if (IsLionOrLater) {
359+
[updater setFeedURL:[NSURL URLWithString:kSparkleUpdateFeedForLions]];
360+
}else{
361+
[updater setFeedURL:[NSURL URLWithString:kSparkleUpdateFeedForSnowLeopard]];
362+
}
363+
[sparkleUpdateItem setTarget:updater];
364+
[sparkleUpdateItem setAction:@selector(checkForUpdates:)];
365+
NSMenuItem *siSparkle = [statBarMenu itemWithTag:902];
366+
[siSparkle setTarget:updater];
367+
[siSparkle setAction:@selector(checkForUpdates:)];
368+
if (![[prefsController notationPrefs] firstTimeUsed]) {
369+
//don't do anything automatically on the first launch; afterwards, check every 4 days, as specified in Info.plist
370+
// SEL checksSEL = @selector(setAutomaticallyChecksForUpdates:);
371+
[updater setAutomaticallyChecksForUpdates:YES];
372+
// [updater methodForSelector:checksSEL](updater, checksSEL, YES);
373+
}
374+
} else {
375+
NSLog(@"Could not load %@!", frameworkPath);
376+
}
377+
// }
378+
// add elasticthreads' menuitems
392379
if(IsLeopardOrLater){
393-
//theMenuItem =[viewMenu itemWithTag:314];
394380
[fsMenuItem setEnabled:YES];
395381
[fsMenuItem setHidden:NO];
396-
382+
397383
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
398384
if (IsLionOrLater) {
399385
// [window setCollectionBehavior:NSWindowCollectionBehaviorTransient|NSWindowCollectionBehaviorMoveToActiveSpace];
400386
//
401387
[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
402388
// [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
403-
// [NSApp setPresentationOptions:[NSApp currentSystemPresentationOptions]|NSApplicationPresentationFullScreen];
404-
405-
389+
// [NSApp setPresentationOptions:[NSApp currentSystemPresentationOptions]|NSApplicationPresentationFullScreen];
390+
391+
406392
}else{
407393
#endif
408394
[fsMenuItem setTarget:self];
@@ -411,7 +397,8 @@ - (void)runDelayedUIActionsAfterLaunch {
411397
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
412398
}
413399
#endif
414-
theMenuItem = [fsMenuItem copy];
400+
401+
NSMenuItem *theMenuItem = [fsMenuItem copy];
415402
[statBarMenu insertItem:theMenuItem atIndex:14];
416403
[theMenuItem release];
417404
}
@@ -2228,7 +2215,6 @@ - (void)dealloc {
22282215
[dividerShader release];
22292216
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
22302217
[statusItem release];
2231-
[cView release];
22322218
[statBarMenu release];
22332219
[self postTextUpdate];
22342220

@@ -2467,15 +2453,7 @@ - (NSMenu *)statBarMenu{
24672453
return statBarMenu;
24682454
}
24692455

2470-
- (void)toggleAttachedWindow:(NSNotification *)aNotification
2471-
{
2472-
[self toggleNVActivation:[aNotification object]];
2473-
}
24742456

2475-
- (void)toggleAttachedMenu:(NSNotification *)aNotification
2476-
{
2477-
[statusItem popUpStatusItemMenu:statBarMenu];
2478-
}
24792457

24802458
#pragma mark multitagging
24812459

@@ -2807,7 +2785,7 @@ - (IBAction)switchFullScreen:(id)sender
28072785
NSResponder *currentResponder = [window firstResponder];
28082786
NSDictionary* options;
28092787
if (([[NSUserDefaults standardUserDefaults] boolForKey:@"ShowDockIcon"])&&(IsSnowLeopardOrLater)) {
2810-
options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:(NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationHideDock)],@"NSFullScreenModeApplicationPresentationOptions", nil];
2788+
options = @{@"NSFullScreenModeApplicationPresentationOptions":@(NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationHideDock)};
28112789
}else {
28122790
options = nil;
28132791
}
@@ -3377,22 +3355,49 @@ - (void)hideDockIconAfterDelay{
33773355

33783356
[self performSelector:@selector(hideDockIcon) withObject:nil afterDelay:0.22];
33793357
}
3380-
3358+
3359+
3360+
3361+
- (IBAction)statusItemAction:(id)sender{
3362+
3363+
NSEvent *curEv=[NSApp currentEvent];
3364+
if ((curEv.type==NSEventTypeRightMouseUp)||((NSEventModifierFlagControl&curEv.modifierFlags)!=0)) {
3365+
[statusItem popUpStatusItemMenu:statBarMenu];
3366+
// NSPoint og=NSMakePoint(statusItem.button.frame.origin.x, 27.f);//NSMaxY(statusItem.button.frame));
3367+
// [self.statusMenu popUpMenuPositioningItem:nil atLocation:og inView:statusItem.button];
3368+
}else{
3369+
[self toggleNVActivation:sender];
3370+
}
3371+
}
3372+
3373+
33813374
- (void)setUpStatusBarItem{
3382-
NSRect viewFrame = NSMakeRect(0.0f, 0.0f, 24.0f,[[NSStatusBar systemStatusBar] thickness]);
3383-
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:24.0f] retain];
3384-
cView = [[[StatusItemView alloc] initWithFrame:viewFrame] autorelease];
3385-
[statusItem setView:cView];
3386-
3387-
[[NSNotificationCenter defaultCenter]postNotificationName:@"StatusBarMenuIsAwake" object:statBarMenu];
3375+
3376+
NSImage *statusIcon=[NSImage imageNamed:@"nvMenuDark"];
3377+
[statusIcon setSize:NSMakeSize(16.0, 16.0)];
3378+
[statusIcon setTemplate:YES];
3379+
statusItem =[[NSStatusBar systemStatusBar] statusItemWithLength:24.f];
3380+
if (!IsYosemiteOrLater) {
3381+
statusItem.button.image=statusIcon;
3382+
statusItem.button.target=self;
3383+
statusItem.button.action=@selector(statusItemAction:);
3384+
[statusItem.button sendActionOn:NSEventMaskLeftMouseUp|NSEventMaskRightMouseUp];
3385+
}else{
3386+
statusItem.image=statusIcon;
3387+
statusItem.target=self;
3388+
statusItem.action=@selector(statusItemAction:);
3389+
[statusItem sendActionOn:NSEventMaskLeftMouseUp|NSEventMaskRightMouseUp];
3390+
statusItem.highlightMode=YES;
3391+
}
3392+
[statusItem retain];
3393+
33883394
}
33893395

33903396
- (void)toggleStatusItem:(NSNotification *)notification{
33913397
if (!statusItem) {
33923398
[self setUpStatusBarItem];
33933399
}else{
33943400
[[NSStatusBar systemStatusBar]removeStatusItem:statusItem];
3395-
cView=nil;
33963401
statusItem=nil;
33973402
}
33983403
}

GlobalPrefs.m

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -663,16 +663,14 @@ - (NSDictionary*)noteBodyAttributes {
663663
NSMutableDictionary *attrs = [[NSMutableDictionary dictionaryWithObjectsAndKeys:bodyFont, NSFontAttributeName, nil] retain];
664664

665665
//not storing the foreground color in each note will make the database smaller, and black is assumed when drawing text
666-
//NSColor *fgColor = [self foregroundTextColor];
667-
NSColor *fgColor = [[NSApp delegate] foregrndColor];
666+
NSColor *fgColor = [(AppController *)[NSApp delegate] foregrndColor];
668667

669668
if (!ColorsEqualWith8BitChannels([NSColor blackColor], fgColor)) {
670669
[attrs setObject:fgColor forKey:NSForegroundColorAttributeName];
671670
}
672671
// background text color is handled directly by the NSTextView subclass and so does not need to be stored here
673-
if ([self _bodyFontIsMonospace]) {
674-
675-
// NSLog(@"notebody att3");
672+
if ([self _bodyFontIsMonospace]) {
673+
// NSLog(@"notebody att3");
676674
NSParagraphStyle *pStyle = [self noteBodyParagraphStyle];
677675
if (pStyle)
678676
[attrs setObject:pStyle forKey:NSParagraphStyleAttributeName];
@@ -683,7 +681,7 @@ - (NSDictionary*)noteBodyAttributes {
683681
}else {
684682
//NSLog(@"notebody att4");
685683
NSMutableDictionary *attrs = [[NSMutableDictionary dictionaryWithObjectsAndKeys:bodyFont, NSFontAttributeName, nil] retain];
686-
NSColor *fgColor = [[NSApp delegate] foregrndColor];
684+
NSColor *fgColor = [(AppController *)[NSApp delegate] foregrndColor];
687685

688686
// if (!ColorsEqualWith8BitChannels([NSColor blackColor], fgColor)) {
689687
[attrs setObject:fgColor forKey:NSForegroundColorAttributeName];
@@ -709,18 +707,16 @@ - (NSParagraphStyle*)noteBodyParagraphStyle {
709707
while (numberOfSpaces--) {
710708
[sizeString appendString:@" "];
711709
}
712-
NSDictionary *sizeAttribute = [[NSDictionary alloc] initWithObjectsAndKeys:bodyFont, NSFontAttributeName, nil];
713-
float sizeOfTab = [sizeString sizeWithAttributes:sizeAttribute].width;
714-
[sizeAttribute release];
710+
711+
float sizeOfTab = [sizeString sizeWithAttributes:@{NSFontAttributeName:bodyFont}].width;
715712
[sizeString release];
716713

717714
noteBodyParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
718-
719-
NSTextTab *textTabToBeRemoved;
720-
NSEnumerator *enumerator = [[noteBodyParagraphStyle tabStops] objectEnumerator];
721-
while ((textTabToBeRemoved = [enumerator nextObject])) {
722-
[noteBodyParagraphStyle removeTabStop:textTabToBeRemoved];
723-
}
715+
716+
717+
for (NSTextTab *textTabToBeRemoved in [noteBodyParagraphStyle tabStops]) {
718+
[noteBodyParagraphStyle removeTabStop:textTabToBeRemoved];
719+
}
724720
//[paragraphStyle setHeadIndent:sizeOfTab]; //for soft-indents, this would probably have to be applied contextually, and heaven help us for soft tabs
725721

726722
[noteBodyParagraphStyle setDefaultTabInterval:sizeOfTab];

LinkingEditor.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ - (BOOL)becomeFirstResponder {
170170
[self performSelector:@selector(indicateRange:) withObject:[NSValue valueWithRange:range] afterDelay:0];
171171
}
172172
}
173-
174173
[self setTypingAttributes:[prefsController noteBodyAttributes]];
175-
174+
// NSLog(@"exist :>%@<",self.defaultParagraphStyle);
175+
// [self.textStorage setAttributes:@{NSParagraphStyleAttributeName:[NSParagraphStyle defaultParagraphStyle]} range:NSMakeRange(0, self.string.length)];
176+
// NSLog(@"exist :>%@<",self.defaultParagraphStyle);
176177
[self performSelector:@selector(_fixCursorForBackgroundUpdatingMouseInside:) withObject:[NSNumber numberWithBool:YES] afterDelay:0.0];
177178

178179
return [super becomeFirstResponder];
@@ -1007,11 +1008,11 @@ - (void)deleteBackward:(id)sender {
10071008
[super deleteBackward:sender];
10081009
} else {
10091010

1010-
unsigned tabWidth = [prefsController numberOfSpacesInTab];
1011-
unsigned indentWidth = 4;
1011+
NSInteger tabWidth = [prefsController numberOfSpacesInTab];
1012+
NSInteger indentWidth = 4;
10121013
BOOL usesTabs = ![prefsController softTabs];
10131014
NSRange leadingSpaceRange = paraRange;
1014-
unsigned leadingSpaces = [string numberOfLeadingSpacesFromRange:&leadingSpaceRange tabWidth:tabWidth];
1015+
NSInteger leadingSpaces = [string numberOfLeadingSpacesFromRange:&leadingSpaceRange tabWidth:tabWidth];
10151016

10161017
if (charRange.location > NSMaxRange(leadingSpaceRange)) {
10171018

@@ -1031,7 +1032,7 @@ - (void)deleteBackward:(id)sender {
10311032
}
10321033

10331034
NSTextStorage *text = [self textStorage];
1034-
unsigned leadingIndents = leadingSpaces / indentWidth;
1035+
NSInteger leadingIndents = leadingSpaces / indentWidth;
10351036
NSString *replaceString;
10361037

10371038
// If we were indented to an fractional level just go back to the last even multiple of indentWidth, if we were exactly on, go back a full level.
@@ -1735,7 +1736,7 @@ - (void)showGeneratedPasswords:(id)sender {
17351736
// display modal overlay, get user selection and insert it
17361737
// Nice to have:
17371738
// keep stats on the user's selection and then use the most frequent choice in [insertGeneratedPassword] (instead of just [strong])
1738-
#lse
1739+
#else
17391740
[self insertGeneratedPassword:nil];
17401741
#endif
17411742
}

NSString_NV.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ CFDateFormatterRef simplenoteDateFormatter(int lowPrecision);
3939
- (NSString*)syntheticTitleAndSeparatorWithContext:(NSString**)sepStr bodyLoc:(NSUInteger*)bodyLoc
4040
oldTitle:(NSString*)oldTitle maxTitleLen:(NSUInteger)maxTitleLen;
4141
- (NSString*)syntheticTitleAndTrimmedBody:(NSString**)newBody;
42-
+ (NSString *)tabbifiedStringWithNumberOfSpaces:(unsigned)origNumSpaces tabWidth:(unsigned)tabWidth usesTabs:(BOOL)usesTabs;
43-
- (unsigned)numberOfLeadingSpacesFromRange:(NSRange*)range tabWidth:(unsigned)tabWidth;
42+
+ (NSString *)tabbifiedStringWithNumberOfSpaces:(NSInteger)origNumSpaces tabWidth:(NSInteger)tabWidth usesTabs:(BOOL)usesTabs;
43+
- (NSInteger)numberOfLeadingSpacesFromRange:(NSRange*)range tabWidth:(NSInteger)tabWidth;
4444

4545
BOOL IsHardLineBreakUnichar(unichar uchar, NSString *str, unsigned charIndex);
4646

0 commit comments

Comments
 (0)