Permalink
Browse files

better handling of note label-previews

  • Loading branch information...
1 parent e4d402c commit f0f341077a9fb1be9cfb2751853bd158bf124673 @scrod scrod committed Jan 19, 2011
View
@@ -632,6 +632,7 @@ - (void)settingChangedForSelectorString:(NSString*)selectorString {
ResetFontRelatedTableAttributes();
[notesTableView updateTitleDereferencorState];
+ [notationController invalidateAllLabelPreviewImages];
[notationController regeneratePreviewsForColumn:[notesTableView noteAttributeColumnForIdentifier:NoteTitleColumnString]
visibleFilteredRows:[notesTableView rowsInRect:[notesTableView visibleRect]] forceUpdate:YES];
View
@@ -125,6 +125,7 @@ - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
[objects[rowIndex] performSelector:columnAttributeMutator((NoteAttributeColumn*)aTableColumn) withObject:anObject];
+ [(NoteAttributeColumn*)aTableColumn editingFinished];
}
View
@@ -0,0 +1,29 @@
+//
+// LabelColumnCell.h
+// Notation
+//
+// Created by Zachary Schneirov on 1/18/11.
+
+/*Copyright (c) 2010, Zachary Schneirov. All rights reserved.
+ Redistribution and use in source and binary forms, with or without modification, are permitted
+ provided that the following conditions are met:
+ - Redistributions of source code must retain the above copyright notice, this list of conditions
+ and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright notice, this list of
+ conditions and the following disclaimer in the documentation and/or other materials provided with
+ the distribution.
+ - Neither the name of Notational Velocity nor the names of its contributors may be used to endorse
+ or promote products derived from this software without specific prior written permission. */
+
+#import <Cocoa/Cocoa.h>
+
+@class NoteObject;
+
+@interface LabelColumnCell : NSTextFieldCell {
+ NoteObject *noteObject;
+}
+
+- (NoteObject*)noteObject;
+- (void)setNoteObject:(NoteObject*)obj;
+
+@end
View
@@ -0,0 +1,72 @@
+//
+// LabelColumnCell.m
+// Notation
+//
+// Created by Zachary Schneirov on 1/18/11.
+
+/*Copyright (c) 2010, Zachary Schneirov. All rights reserved.
+ Redistribution and use in source and binary forms, with or without modification, are permitted
+ provided that the following conditions are met:
+ - Redistributions of source code must retain the above copyright notice, this list of conditions
+ and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright notice, this list of
+ conditions and the following disclaimer in the documentation and/or other materials provided with
+ the distribution.
+ - Neither the name of Notational Velocity nor the names of its contributors may be used to endorse
+ or promote products derived from this software without specific prior written permission. */
+
+#import "LabelColumnCell.h"
+#import "NotesTableView.h"
+#import "NoteObject.h"
+#import "GlobalPrefs.h"
+
+@implementation LabelColumnCell
+
+- (id)init {
+ if ([super init]) {
+ [self setEditable:YES];
+
+ [self setFocusRingType: NSFocusRingTypeExterior];
+ }
+ return self;
+}
+
+- (BOOL)isScrollable {
+ return YES;
+}
+
+
+- (NoteObject*)noteObject {
+ return noteObject;
+}
+
+- (void)setNoteObject:(NoteObject*)obj {
+ [noteObject autorelease];
+ noteObject = [obj retain];
+}
+
+- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
+ NotesTableView *tv = (NotesTableView *)controlView;
+
+ NSInteger col = [tv editedColumn];
+ BOOL isEditing = [self isHighlighted] && [tv currentEditor] &&
+ (col > -1 && [[[[tv tableColumns] objectAtIndex:col] identifier] isEqualToString:NoteLabelsColumnString]);
+
+ if (isEditing) {
+ [super drawWithFrame:cellFrame inView:controlView];
+ }
+
+ if (!isEditing) {
+ NSImage *img = ([self isHighlighted] && [tv isActiveStyle]) ? [noteObject labelsPreviewImageOfColor:[NSColor whiteColor]] : [noteObject labelsPreviewImage];
+ if (img) {
+ [[NSGraphicsContext currentContext] saveGraphicsState];
+ NSRectClip(cellFrame);
+ NSPoint imgSpot = NSMakePoint(NSMinX(cellFrame), NSMaxY(cellFrame) - 1.0);
+ [img compositeToPoint:imgSpot operation:NSCompositeSourceOver];
+ [[NSGraphicsContext currentContext] restoreGraphicsState];
+ }
+ }
+
+}
+
+@end
@@ -126,6 +126,8 @@
21B1C173110764570004A7D0 /* statusInProgress.png in Resources */ = {isa = PBXBuildFile; fileRef = 21B1C170110764570004A7D0 /* statusInProgress.png */; };
21B548FA112F307E00E163A1 /* NotationDirectoryManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 21B548F8112F307E00E163A1 /* NotationDirectoryManager.m */; };
21B54C021134F2E800E163A1 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21B54C011134F2E800E163A1 /* IOKit.framework */; };
+ 21B64A2612E61FA700D87EFC /* LabelColumnCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 21B64A2512E61FA700D87EFC /* LabelColumnCell.m */; };
+ 21B64C4E12E62A5700D87EFC /* UnifiedCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 21B64C4D12E62A5700D87EFC /* UnifiedCell.m */; };
21BD2ED110DAF31500BA3DF6 /* LinearDividerShader.m in Sources */ = {isa = PBXBuildFile; fileRef = 21BD2ECF10DAF31500BA3DF6 /* LinearDividerShader.m */; };
21BD2F3610DAF61700BA3DF6 /* SplitViewDimple.tif in Resources */ = {isa = PBXBuildFile; fileRef = 21BD2F3510DAF61700BA3DF6 /* SplitViewDimple.tif */; };
21C0F8A212C7E7160068693F /* Fonts & Colors.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 21C0F8A112C7E7160068693F /* Fonts & Colors.tiff */; };
@@ -138,7 +140,6 @@
21D6FB4912E104D6005C2DA5 /* NSBezierPath_NV.m in Sources */ = {isa = PBXBuildFile; fileRef = 21D6FB4812E104D6005C2DA5 /* NSBezierPath_NV.m */; };
21DB3D0F12D4FBDD0057F52B /* SecureTextEntryManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 21DB3D0E12D4FBDD0057F52B /* SecureTextEntryManager.m */; };
21DB407E12D5383F0057F52B /* IBeamInverted.png in Resources */ = {isa = PBXBuildFile; fileRef = 21DB407D12D5383F0057F52B /* IBeamInverted.png */; };
- 21DB49BB12DE19480057F52B /* UnifiedCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 21DB49B912DE19480057F52B /* UnifiedCell.m */; };
21DB4BE612DE4E3D0057F52B /* NSString_CustomTruncation.m in Sources */ = {isa = PBXBuildFile; fileRef = 21DB4BE512DE4E3D0057F52B /* NSString_CustomTruncation.m */; };
21DC788F097894B600E59B09 /* NSCollection_utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 21DC788E097894B600E59B09 /* NSCollection_utils.m */; };
21DF19B210D172F600543C35 /* DFCapRightInactive.png in Resources */ = {isa = PBXBuildFile; fileRef = 21DF19AE10D172F600543C35 /* DFCapRightInactive.png */; };
@@ -393,6 +394,9 @@
21B548F8112F307E00E163A1 /* NotationDirectoryManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NotationDirectoryManager.m; sourceTree = "<group>"; };
21B548F9112F307E00E163A1 /* NotationDirectoryManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotationDirectoryManager.h; sourceTree = "<group>"; };
21B54C011134F2E800E163A1 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; };
+ 21B64A2412E61FA700D87EFC /* LabelColumnCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LabelColumnCell.h; sourceTree = "<group>"; };
+ 21B64A2512E61FA700D87EFC /* LabelColumnCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LabelColumnCell.m; sourceTree = "<group>"; };
+ 21B64C4D12E62A5700D87EFC /* UnifiedCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UnifiedCell.m; sourceTree = "<group>"; };
21BD2ECF10DAF31500BA3DF6 /* LinearDividerShader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LinearDividerShader.m; sourceTree = "<group>"; };
21BD2ED010DAF31500BA3DF6 /* LinearDividerShader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinearDividerShader.h; sourceTree = "<group>"; };
21BD2F3510DAF61700BA3DF6 /* SplitViewDimple.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = SplitViewDimple.tif; sourceTree = "<group>"; };
@@ -413,7 +417,6 @@
21DB3D0D12D4FBDD0057F52B /* SecureTextEntryManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecureTextEntryManager.h; sourceTree = "<group>"; };
21DB3D0E12D4FBDD0057F52B /* SecureTextEntryManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecureTextEntryManager.m; sourceTree = "<group>"; };
21DB407D12D5383F0057F52B /* IBeamInverted.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = IBeamInverted.png; path = Images/IBeamInverted.png; sourceTree = "<group>"; };
- 21DB49B912DE19480057F52B /* UnifiedCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UnifiedCell.m; sourceTree = "<group>"; };
21DB49BA12DE19480057F52B /* UnifiedCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnifiedCell.h; sourceTree = "<group>"; };
21DB4BE412DE4E3D0057F52B /* NSString_CustomTruncation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSString_CustomTruncation.h; sourceTree = "<group>"; };
21DB4BE512DE4E3D0057F52B /* NSString_CustomTruncation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSString_CustomTruncation.m; sourceTree = "<group>"; };
@@ -765,7 +768,9 @@
2191930109CFBEBD00586B15 /* NotesTableView.h */,
2191930209CFBEBD00586B15 /* NotesTableView.m */,
21DB49BA12DE19480057F52B /* UnifiedCell.h */,
- 21DB49B912DE19480057F52B /* UnifiedCell.m */,
+ 21B64C4D12E62A5700D87EFC /* UnifiedCell.m */,
+ 21B64A2412E61FA700D87EFC /* LabelColumnCell.h */,
+ 21B64A2512E61FA700D87EFC /* LabelColumnCell.m */,
215DE83609ECC4FE009A710B /* HeaderViewWIthMenu.h */,
215DE83709ECC4FE009A710B /* HeaderViewWIthMenu.m */,
210A10660B66720F005BE981 /* BookmarksTable.h */,
@@ -1172,11 +1177,12 @@
216D987F12CE68AD0004B9CE /* NSFileManager_NV.m in Sources */,
216DA22612D17DB70004B9CE /* AugmentedScrollView.m in Sources */,
21DB3D0F12D4FBDD0057F52B /* SecureTextEntryManager.m in Sources */,
- 21DB49BB12DE19480057F52B /* UnifiedCell.m in Sources */,
21DB4BE612DE4E3D0057F52B /* NSString_CustomTruncation.m in Sources */,
21D6F7EF12E0C751005C2DA5 /* AppController_Importing.m in Sources */,
21D6FB4912E104D6005C2DA5 /* NSBezierPath_NV.m in Sources */,
215309F412E4E92300AF2739 /* DiskUUIDEntry.m in Sources */,
+ 21B64A2612E61FA700D87EFC /* LabelColumnCell.m in Sources */,
+ 21B64C4E12E62A5700D87EFC /* UnifiedCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -180,6 +180,7 @@ typedef struct _NoteCatalogEntry {
- (float)titleColumnWidth;
- (void)regeneratePreviewsForColumn:(NSTableColumn*)col visibleFilteredRows:(NSRange)rows forceUpdate:(BOOL)force;
- (void)regenerateAllPreviews;
+- (void)invalidateAllLabelPreviewImages;
//for setting up the nstableviews
- (id)labelsListDataSource;
View
@@ -1457,6 +1457,10 @@ - (void)regeneratePreviewsForColumn:(NSTableColumn*)col visibleFilteredRows:(NSR
}
}
+- (void)invalidateAllLabelPreviewImages {
+ [allNotes makeObjectsPerformSelector:@selector(invalidateLabelsPreviewImage)];
+}
+
- (void)regenerateAllPreviews {
[allNotes makeObjectsPerformSelector:@selector(updateTablePreviewString)];
}
View
@@ -27,12 +27,13 @@
NSInteger (*sortFunction) (id*, id*);
NSInteger (*reverseSortFunction) (id*, id*);
id (*objectAttribute) (id, id, NSInteger);
- SEL mutateObjectSelector;
+ SEL mutateObjectSelector, originalMutateObjectSelector;
float absoluteMinimumWidth;
}
+ (NSDictionary*)standardDictionary;
SEL columnAttributeMutator(NoteAttributeColumn *col);
+- (void)setMutatingSelectorForNextEdit:(SEL)selector;
- (void)setMutatingSelector:(SEL)selector;
id columnAttributeForObject(NotesTableView *tv, NoteAttributeColumn *col, id object, NSInteger row);
- (void)updateWidthForHighlight;
@@ -41,6 +42,8 @@ id columnAttributeForObject(NotesTableView *tv, NoteAttributeColumn *col, id obj
id (*dereferencingFunction(NoteAttributeColumn *col))(id, id, NSInteger);
- (void)setDereferencingFunction:(id (*)(id, id, NSInteger))attributeFunction;
+- (void)editingFinished;
+
- (void)setSortingFunction:(NSInteger (*)(id*, id*))sortFunction;
- (NSInteger (*)(id*, id*))sortFunction;
- (void)setReverseSortingFunction:(NSInteger (*)(id*, id*))aFunction;
View
@@ -52,6 +52,16 @@ SEL columnAttributeMutator(NoteAttributeColumn *col) {
return col->mutateObjectSelector;
}
+- (void)setMutatingSelectorForNextEdit:(SEL)selector {
+ originalMutateObjectSelector = mutateObjectSelector;
+ [self setMutatingSelector:selector];
+}
+
+- (void)editingFinished {
+ if (originalMutateObjectSelector)
+ [self setMutatingSelector:originalMutateObjectSelector];
+}
+
- (void)setMutatingSelector:(SEL)selector {
mutateObjectSelector = selector;
}
View
@@ -130,6 +130,7 @@ NSInteger compareFileSize(id *a, id *b);
id properlyHighlightingTableTitleOfNote(NotesTableView *tv, NoteObject *note, NSInteger row);
id unifiedCellSingleLineForNote(NotesTableView *tv, NoteObject *note, NSInteger row);
id unifiedCellForNote(NotesTableView *tv, NoteObject *note, NSInteger row);
+ id labelColumnCellForNote(NotesTableView *tv, NoteObject *note, NSInteger row);
id labelsOfNote2(NotesTableView *tv, NoteObject *note, NSInteger row);
id dateCreatedStringOfNote(NotesTableView *tv, NoteObject *note, NSInteger row);
id dateModifiedStringOfNote(NotesTableView *tv, NoteObject *note, NSInteger row);
@@ -152,9 +153,9 @@ NSInteger compareFileSize(id *a, id *b);
- (void)updateLabelConnections;
- (void)setLabelString:(NSString*)newLabels;
- (NSArray*)orderedLabelTitles;
+- (void)invalidateLabelsPreviewImage;
- (NSImage*)labelsPreviewImage;
- (NSImage*)labelsPreviewImageOfColor:(NSColor*)aColor;
-- (void)updateLabelsPreviewImage;
- (void)setSyncObjectAndKeyMD:(NSDictionary*)aDict forService:(NSString*)serviceName;
- (void)removeAllSyncMDForService:(NSString*)serviceName;
View
@@ -265,13 +265,19 @@ NSInteger compareFileSize(id *a, id *b) {
return titleOfNote(note);
}
+force_inline id labelColumnCellForNote(NotesTableView *tv, NoteObject *note, NSInteger row) {
+
+ UnifiedCell *cell = [[tv tableColumnWithIdentifier:NoteLabelsColumnString] dataCellForRow:row];
+ [cell setNoteObject:note];
+
+ return labelsOfNote(note);
+}
force_inline id unifiedCellSingleLineForNote(NotesTableView *tv, NoteObject *note, NSInteger row) {
id obj = note->tableTitleString ? (id)note->tableTitleString : (id)titleOfNote(note);
UnifiedCell *cell = [[[tv tableColumns] objectAtIndex:0] dataCellForRow:row];
- // [cell setObjectValue:obj];
[cell setNoteObject:note];
[cell setPreviewIsHidden:YES];
@@ -282,14 +288,16 @@ NSInteger compareFileSize(id *a, id *b) {
//snow leopard is stricter about applying the default highlight-attributes (e.g., no shadow unless no paragraph formatting)
//so add the shadow here for snow leopard on selected rows
- id obj = note->tableTitleString ? ([tv isRowSelected:row] ? (id)AttributedStringForSelection(note->tableTitleString) :
- (id)note->tableTitleString) : (id)titleOfNote(note);
-
UnifiedCell *cell = [[[tv tableColumns] objectAtIndex:0] dataCellForRow:row];
- // NSLog(@"set obj value %@", [obj isKindOfClass:[NSAttributedString class]] ? [obj string] : obj);
- // [cell setObjectValue:obj];
[cell setNoteObject:note];
[cell setPreviewIsHidden:NO];
+
+ BOOL rowSelected = [tv isRowSelected:row];
+ BOOL drawShadow = IsSnowLeopardOrLater || (IsLeopardOrLater && rowSelected && [tv currentEditor]);
+
+ id obj = note->tableTitleString ? (rowSelected ? (id)AttributedStringForSelection(note->tableTitleString, drawShadow) :
+ (id)note->tableTitleString) : (id)titleOfNote(note);
+
return obj;
}
@@ -695,8 +703,11 @@ - (void)updateTablePreviewString {
if ([prefs tableColumnsShowPreview]) {
if ([prefs horizontalLayout]) {
+ //labelsPreviewImage does work only when the image is explicitly invalidated, and because updateTablePreviewString
+ //is called for visible notes at launch and resize only, generation of images for invisible notes is delayed until after launch
+ NSImage *img = [self labelsPreviewImage];
tableTitleString = [[titleString attributedMultiLinePreviewFromBodyText:contentString upToWidth:[delegate titleColumnWidth]
- intrusionWidth:labelsPreviewImage ? [labelsPreviewImage size].width : 0.0] retain];
+ intrusionWidth:img ? [img size].width : 0.0] retain];
} else {
tableTitleString = [[titleString attributedSingleLinePreviewFromBodyText:contentString upToWidth:[delegate titleColumnWidth]] retain];
}
@@ -906,6 +917,10 @@ - (void)setLabelString:(NSString*)newLabelString {
cLabelsFoundPtr = cLabels = replaceString(cLabels, [labelString lowercaseUTF8String]);
[self updateLabelConnections];
+ [self invalidateLabelsPreviewImage];
+ if ([[GlobalPrefs defaultPrefs] horizontalLayout]) {
+ [self updateTablePreviewString];
+ }
[self makeNoteDirtyUpdateTime:YES updateFile:YES];
//[self registerModificationWithOwnedServices];
@@ -936,9 +951,14 @@ - (NSArray*)orderedLabelTitles {
return titles;
}
+- (void)invalidateLabelsPreviewImage {
+ [labelsPreviewImage release];
+ labelsPreviewImage = nil;
+}
+
- (NSImage*)labelsPreviewImage {
if (!labelsPreviewImage && [labelString length]) {
- [self updateLabelsPreviewImage];
+ labelsPreviewImage = [[self labelsPreviewImageOfColor:[NSColor colorWithCalibratedWhite:0.55 alpha:1.0]] retain];
}
return labelsPreviewImage;
}
@@ -960,6 +980,9 @@ - (NSImage*)labelsPreviewImageOfColor:(NSColor*)aColor {
[textStorage addLayoutManager:layoutManager];
NSArray *words = [self orderedLabelTitles];
+ if (![words count])
+ return nil;
+
NSBezierPath *blocksPath = [NSBezierPath bezierPath];
NSPoint nextBoxPoint = NSZeroPoint;
NSUInteger i;
@@ -1012,12 +1035,6 @@ - (NSImage*)labelsPreviewImageOfColor:(NSColor*)aColor {
return nil;
}
-- (void)updateLabelsPreviewImage {
-
- [labelsPreviewImage release];
- labelsPreviewImage = [[self labelsPreviewImageOfColor:[NSColor colorWithCalibratedWhite:0.55 alpha:1.0]] retain];
-}
-
- (NSURL*)uniqueNoteLink {
View
@@ -27,12 +27,14 @@ typedef struct _ViewLocationContext {
@interface NotesTableView : NSTableView {
IBOutlet NSTextField *controlField;
NSMutableArray *allColumns;
+ NSMutableDictionary *allColsDict;
NSInteger firstRowIndexBeforeSplitResize;
BOOL viewMenusValid;
BOOL hadHighlightInForeground, hadHighlightInBackground;
BOOL shouldUseSecondaryHighlightColor, isActiveStyle;
+ BOOL lastEventActivatedTagEdit;
GlobalPrefs *globalPrefs;
NSMenuItem *dummyItem;
@@ -70,6 +72,8 @@ typedef struct _ViewLocationContext {
- (void)restoreColumns;
- (void)_configureAttributesForCurrentLayout;
- (void)updateHeaderViewForColumns;
+- (BOOL)eventIsTagEdit:(NSEvent*)event forColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex;
+- (BOOL)lastEventActivatedTagEdit;
- (void)editRowAtColumnWithIdentifier:(id)identifier;
- (BOOL)addPermanentTableColumn:(NSTableColumn*)column;
- (IBAction)actionHideShowColumn:(id)sender;
Oops, something went wrong.

0 comments on commit f0f3410

Please sign in to comment.