Permalink
Browse files

Fixing print styles, no longer writing custom css and template to dis…

…k, moved support folder to nvALT, cleaned up code for finding support directory
  • Loading branch information...
1 parent 4f54d28 commit c79f6cca6757e4669a2b7061d8c9b994ba7a3bf9 @ttscoff committed Feb 29, 2012
View
@@ -49,6 +49,7 @@
#import "PreviewController.h"
#import "ETClipView.h"
#import "ETScrollView.h"
+#import "NSFileManager+DirectoryLocations.h"
#define NSApplicationPresentationAutoHideMenuBar (1 << 2)
#define NSApplicationPresentationHideMenuBar (1 << 3)
@@ -79,30 +80,42 @@ + (void)initialize
- (id)init {
- if ([super init]) {
- splitViewAwoke = NO;
- windowUndoManager = [[NSUndoManager alloc] init];
-
- previewController = [[PreviewController alloc] init];
-
- NSNotificationCenter *nc=[NSNotificationCenter defaultCenter];
- [nc addObserver:previewController selector:@selector(requestPreviewUpdate:) name:@"TextView has changed contents" object:self];
- [nc addObserver:self selector:@selector(toggleAttachedWindow:) name:@"NVShouldActivate" object:nil];
- [nc addObserver:self selector:@selector(toggleAttachedMenu:) name:@"StatusItemMenuShouldDrop" object:nil];
- [nc addObserver:self selector:@selector(togDockIcon:) name:@"AppShouldToggleDockIcon" object:nil];
- [nc addObserver:self selector:@selector(resetModTimers:) name:@"ModTimersShouldReset" object:nil];
-
- // Setup URL Handling
- NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
- [appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
-
- // dividerShader = [[LinearDividerShader alloc] initWithStartColor:[NSColor colorWithCalibratedWhite:0.988 alpha:1.0]
- // endColor:[NSColor colorWithCalibratedWhite:0.875 alpha:1.0]];
- dividerShader = [[[LinearDividerShader alloc] initWithBaseColors:self] retain];
- isCreatingANote = isFilteringFromTyping = typedStringIsCached = NO;
- typedString = @"";
- }
- return self;
+ self = [super init];
+ if (self) {
+ splitViewAwoke = NO;
+ windowUndoManager = [[NSUndoManager alloc] init];
+
+ previewController = [[PreviewController alloc] init];
+
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+
+
+ NSString *folder = [[NSFileManager defaultManager] applicationSupportDirectory];
+
+ if ([fileManager fileExistsAtPath: folder] == NO)
+ {
+ [fileManager createDirectoryAtPath: folder attributes: nil];
+
+ }
+
+ NSNotificationCenter *nc=[NSNotificationCenter defaultCenter];
+ [nc addObserver:previewController selector:@selector(requestPreviewUpdate:) name:@"TextView has changed contents" object:self];
+ [nc addObserver:self selector:@selector(toggleAttachedWindow:) name:@"NVShouldActivate" object:nil];
+ [nc addObserver:self selector:@selector(toggleAttachedMenu:) name:@"StatusItemMenuShouldDrop" object:nil];
+ [nc addObserver:self selector:@selector(togDockIcon:) name:@"AppShouldToggleDockIcon" object:nil];
+ [nc addObserver:self selector:@selector(resetModTimers:) name:@"ModTimersShouldReset" object:nil];
+
+ // Setup URL Handling
+ NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
+ [appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
+
+ // dividerShader = [[LinearDividerShader alloc] initWithStartColor:[NSColor colorWithCalibratedWhite:0.988 alpha:1.0]
+ // endColor:[NSColor colorWithCalibratedWhite:0.875 alpha:1.0]];
+ dividerShader = [[[LinearDividerShader alloc] initWithBaseColors:self] retain];
+ isCreatingANote = isFilteringFromTyping = typedStringIsCached = NO;
+ typedString = @"";
+ }
+ return self;
}
- (void)awakeFromNib {
@@ -0,0 +1,36 @@
+//
+// NSFileManager+DirectoryLocations.h
+//
+// Created by Matt Gallagher on 06 May 2010
+//
+// This software is provided 'as-is', without any express or implied
+// warranty. In no event will the authors be held liable for any damages
+// arising from the use of this software. Permission is granted to anyone to
+// use this software for any purpose, including commercial applications, and to
+// alter it and redistribute it freely, subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented; you must not
+// claim that you wrote the original software. If you use this software
+// in a product, an acknowledgment in the product documentation would be
+// appreciated but is not required.
+// 2. Altered source versions must be plainly marked as such, and must not be
+// misrepresented as being the original software.
+// 3. This notice may not be removed or altered from any source
+// distribution.
+//
+
+#import <Foundation/Foundation.h>
+
+//
+// DirectoryLocations is a set of global methods for finding the fixed location
+// directoriess.
+//
+@interface NSFileManager (DirectoryLocations)
+
+- (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory
+ inDomain:(NSSearchPathDomainMask)domainMask
+ appendPathComponent:(NSString *)appendComponent
+ error:(NSError **)errorOut;
+- (NSString *)applicationSupportDirectory;
+
+@end
@@ -0,0 +1,155 @@
+//
+// NSFileManager+DirectoryLocations.m
+//
+// Created by Matt Gallagher on 06 May 2010
+//
+// This software is provided 'as-is', without any express or implied
+// warranty. In no event will the authors be held liable for any damages
+// arising from the use of this software. Permission is granted to anyone to
+// use this software for any purpose, including commercial applications, and to
+// alter it and redistribute it freely, subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented; you must not
+// claim that you wrote the original software. If you use this software
+// in a product, an acknowledgment in the product documentation would be
+// appreciated but is not required.
+// 2. Altered source versions must be plainly marked as such, and must not be
+// misrepresented as being the original software.
+// 3. This notice may not be removed or altered from any source
+// distribution.
+//
+
+#import "NSFileManager+DirectoryLocations.h"
+
+enum
+{
+ DirectoryLocationErrorNoPathFound,
+ DirectoryLocationErrorFileExistsAtLocation
+};
+
+NSString * const DirectoryLocationDomain = @"DirectoryLocationDomain";
+
+@implementation NSFileManager (DirectoryLocations)
+
+//
+// findOrCreateDirectory:inDomain:appendPathComponent:error:
+//
+// Method to tie together the steps of:
+// 1) Locate a standard directory by search path and domain mask
+// 2) Select the first path in the results
+// 3) Append a subdirectory to that path
+// 4) Create the directory and intermediate directories if needed
+// 5) Handle errors by emitting a proper NSError object
+//
+// Parameters:
+// searchPathDirectory - the search path passed to NSSearchPathForDirectoriesInDomains
+// domainMask - the domain mask passed to NSSearchPathForDirectoriesInDomains
+// appendComponent - the subdirectory appended
+// errorOut - any error from file operations
+//
+// returns the path to the directory (if path found and exists), nil otherwise
+//
+- (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory
+ inDomain:(NSSearchPathDomainMask)domainMask
+ appendPathComponent:(NSString *)appendComponent
+ error:(NSError **)errorOut
+{
+ //
+ // Search for the path
+ //
+ NSArray* paths = NSSearchPathForDirectoriesInDomains(
+ searchPathDirectory,
+ domainMask,
+ YES);
+ if ([paths count] == 0)
+ {
+ if (errorOut)
+ {
+ NSDictionary *userInfo =
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ NSLocalizedStringFromTable(
+ @"No path found for directory in domain.",
+ @"Errors",
+ nil),
+ NSLocalizedDescriptionKey,
+ [NSNumber numberWithInteger:searchPathDirectory],
+ @"NSSearchPathDirectory",
+ [NSNumber numberWithInteger:domainMask],
+ @"NSSearchPathDomainMask",
+ nil];
+ *errorOut =
+ [NSError
+ errorWithDomain:DirectoryLocationDomain
+ code:DirectoryLocationErrorNoPathFound
+ userInfo:userInfo];
+ }
+ return nil;
+ }
+
+ //
+ // Normally only need the first path returned
+ //
+ NSString *resolvedPath = [paths objectAtIndex:0];
+
+ //
+ // Append the extra path component
+ //
+ if (appendComponent)
+ {
+ resolvedPath = [resolvedPath
+ stringByAppendingPathComponent:appendComponent];
+ }
+
+ //
+ // Create the path if it doesn't exist
+ //
+ NSError *error = nil;
+ BOOL success = [self
+ createDirectoryAtPath:resolvedPath
+ withIntermediateDirectories:YES
+ attributes:nil
+ error:&error];
+ if (!success)
+ {
+ if (errorOut)
+ {
+ *errorOut = error;
+ }
+ return nil;
+ }
+
+ //
+ // If we've made it this far, we have a success
+ //
+ if (errorOut)
+ {
+ *errorOut = nil;
+ }
+ return resolvedPath;
+}
+
+//
+// applicationSupportDirectory
+//
+// Returns the path to the applicationSupportDirectory (creating it if it doesn't
+// exist).
+//
+- (NSString *)applicationSupportDirectory
+{
+ NSString *executableName =
+ [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
+ NSError *error;
+ NSString *result =
+ [self
+ findOrCreateDirectory:NSApplicationSupportDirectory
+ inDomain:NSUserDomainMask
+ appendPathComponent:executableName
+ error:&error];
+ if (!result)
+ {
+ NSLog(@"Unable to find or create application support directory:\n%@", error);
+ }
+ return result;
+}
+
+@end
View
@@ -76,7 +76,7 @@ +(NSString*)processMultiMarkdown:(NSString*)inputString
inputString = [self processTaskPaper:inputString];
}
NSString* mdScriptPath = [[self class] mmdDirectory];
- NSString* tpScriptPath = [[self class] tp2mdDirectory];
+// NSString* tpScriptPath = [[self class] tp2mdDirectory];
NSTask* task = [[[NSTask alloc] init] autorelease];
NSMutableArray* args = [NSMutableArray array];
@@ -109,14 +109,13 @@ +(NSString*)processMultiMarkdown:(NSString*)inputString
+(NSString*)documentWithProcessedMultiMarkdown:(NSString*)inputString
{
AppController *app = [[NSApplication sharedApplication] delegate];
- if (![[[self class] mmdDirectory] hasPrefix:@"/usr/local/bin"])
- inputString = [@"Format: Snippet\n\n" stringByAppendingString:inputString];
NSString *processedString = [self processMultiMarkdown:inputString];
NSString *htmlString = [[PreviewController class] html];
NSString *cssString = [[PreviewController class] css];
NSMutableString *outputString = [NSMutableString stringWithString:(NSString *)htmlString];
NSString *noteTitle = ([app selectedNoteObject]) ? [NSString stringWithFormat:@"%@",titleOfNote([app selectedNoteObject])] : @"";
- NSString *nvSupportPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Notational Velocity"];
+ NSString *nvSupportPath = [[NSFileManager defaultManager] applicationSupportDirectory];
+
[outputString replaceOccurrencesOfString:@"{%support%}" withString:nvSupportPath options:0 range:NSMakeRange(0, [outputString length])];
[outputString replaceOccurrencesOfString:@"{%title%}" withString:noteTitle options:0 range:NSMakeRange(0, [outputString length])];
[outputString replaceOccurrencesOfString:@"{%content%}" withString:processedString options:0 range:NSMakeRange(0, [outputString length])];
@@ -126,19 +125,11 @@ +(NSString*)documentWithProcessedMultiMarkdown:(NSString*)inputString
+(NSString*)xhtmlWithProcessedMultiMarkdown:(NSString*)inputString
{
- AppController *app = [[NSApplication sharedApplication] delegate];
- NSString *noteTitle = ([app selectedNoteObject]) ? [NSString stringWithFormat:@"%@",titleOfNote([app selectedNoteObject])] : @"";
- if (![[[self class] mmdDirectory] hasPrefix:@"/usr/local/bin"]) {
- inputString = [@"Format: Snippet\n\n" stringByAppendingString:inputString];
-// inputString = [[NSString stringWithFormat:@"Title: %@\n\n",noteTitle] stringByAppendingString:inputString];
- }
return [self processMultiMarkdown:inputString];
}
+(NSString*)stringWithProcessedMultiMarkdown:(NSString*)inputString
{
- if (![[[self class] mmdDirectory] hasPrefix:@"/usr/local/bin"])
- inputString = [@"Format: Snippet\n\n" stringByAppendingString:inputString];
return [self processMultiMarkdown:inputString];
} // stringWithProcessedMultiMarkdown:
View
@@ -39,7 +39,7 @@ +(NSString*)processTextile:(NSString*)inputString
[stdoutFileHandle closeFile];
[task waitUntilExit];
-
+
return outputString;
}
@@ -51,8 +51,9 @@ +(NSString*)documentWithProcessedTextile:(NSString*)inputString
NSString *cssString = [[PreviewController class] css];
NSMutableString *outputString = [NSMutableString stringWithString:(NSString *)htmlString];
NSString *noteTitle = ([app selectedNoteObject]) ? [NSString stringWithFormat:@"%@",titleOfNote([app selectedNoteObject])] : @"";
-
- NSString *nvSupportPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Notational Velocity"];
+
+ NSString *nvSupportPath = [[NSFileManager defaultManager] applicationSupportDirectory];
+
[outputString replaceOccurrencesOfString:@"{%support%}" withString:nvSupportPath options:0 range:NSMakeRange(0, [outputString length])];
[outputString replaceOccurrencesOfString:@"{%title%}" withString:noteTitle options:0 range:NSMakeRange(0, [outputString length])];
[outputString replaceOccurrencesOfString:@"{%content%}" withString:processedString options:0 range:NSMakeRange(0, [outputString length])];
@@ -254,6 +254,11 @@
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
93099628138BD61000368C45 /* tp2md.rb in Resources */ = {isa = PBXBuildFile; fileRef = 93099627138BD61000368C45 /* tp2md.rb */; };
9335C40D148EC7AC009CE623 /* multimarkdown in Resources */ = {isa = PBXBuildFile; fileRef = 9335C40C148EC7AC009CE623 /* multimarkdown */; };
+ 934C3FB214FDA069000D14BA /* custom.css in Resources */ = {isa = PBXBuildFile; fileRef = 934C3FAE14FDA069000D14BA /* custom.css */; };
+ 934C3FB314FDA06A000D14BA /* customclean.css in Resources */ = {isa = PBXBuildFile; fileRef = 934C3FAF14FDA069000D14BA /* customclean.css */; };
+ 934C3FB414FDA06A000D14BA /* template.html in Resources */ = {isa = PBXBuildFile; fileRef = 934C3FB014FDA069000D14BA /* template.html */; };
+ 934C3FB514FDA06A000D14BA /* templateclean.html in Resources */ = {isa = PBXBuildFile; fileRef = 934C3FB114FDA069000D14BA /* templateclean.html */; };
+ 934C3FB914FDA74F000D14BA /* NSFileManager+DirectoryLocations.m in Sources */ = {isa = PBXBuildFile; fileRef = 934C3FB814FDA74F000D14BA /* NSFileManager+DirectoryLocations.m */; };
937E6783138C250E0099DF47 /* AutoHyperlinks.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 937E6781138C24980099DF47 /* AutoHyperlinks.framework */; };
93A158BC133C304D00E1E7DA /* Markdownify.nvhelp in Resources */ = {isa = PBXBuildFile; fileRef = 93A158BB133C304D00E1E7DA /* Markdownify.nvhelp */; };
93A158BE133C497400E1E7DA /* Notality.icns in Resources */ = {isa = PBXBuildFile; fileRef = 93A158BD133C497400E1E7DA /* Notality.icns */; };
@@ -755,6 +760,12 @@
8D1107320486CEB800E47090 /* nvALT.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = nvALT.app; sourceTree = BUILT_PRODUCTS_DIR; };
93099627138BD61000368C45 /* tp2md.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = tp2md.rb; sourceTree = "<group>"; };
9335C40C148EC7AC009CE623 /* multimarkdown */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = multimarkdown; sourceTree = "<group>"; };
+ 934C3FAE14FDA069000D14BA /* custom.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = custom.css; sourceTree = "<group>"; };
+ 934C3FAF14FDA069000D14BA /* customclean.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = customclean.css; sourceTree = "<group>"; };
+ 934C3FB014FDA069000D14BA /* template.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = template.html; sourceTree = "<group>"; };
+ 934C3FB114FDA069000D14BA /* templateclean.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = templateclean.html; sourceTree = "<group>"; };
+ 934C3FB714FDA74F000D14BA /* NSFileManager+DirectoryLocations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+DirectoryLocations.h"; sourceTree = "<group>"; };
+ 934C3FB814FDA74F000D14BA /* NSFileManager+DirectoryLocations.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+DirectoryLocations.m"; sourceTree = "<group>"; };
937E6781138C24980099DF47 /* AutoHyperlinks.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = AutoHyperlinks.framework; sourceTree = "<group>"; };
93A158BB133C304D00E1E7DA /* Markdownify.nvhelp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Markdownify.nvhelp; sourceTree = "<group>"; };
93A158BD133C497400E1E7DA /* Notality.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Notality.icns; sourceTree = "<group>"; };
@@ -802,6 +813,8 @@
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
+ 934C3FB714FDA74F000D14BA /* NSFileManager+DirectoryLocations.h */,
+ 934C3FB814FDA74F000D14BA /* NSFileManager+DirectoryLocations.m */,
93B90E901386072E00BEC5FB /* TemporaryFileCachePreparer.h */,
93B90E911386072E00BEC5FB /* TemporaryFileCachePreparer.m */,
5C96F713131C4A1B00A2E4AC /* UIElement Subclasses */,
@@ -1227,6 +1240,10 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
+ 934C3FAE14FDA069000D14BA /* custom.css */,
+ 934C3FAF14FDA069000D14BA /* customclean.css */,
+ 934C3FB014FDA069000D14BA /* template.html */,
+ 934C3FB114FDA069000D14BA /* templateclean.html */,
5C49E553131C72FD00696B68 /* dsa_pub.pem */,
21813561105AF27400A0AE18 /* Acknowledgments.txt */,
217DB1810B7CE5B9008CD564 /* Help Notes */,
@@ -1547,6 +1564,10 @@
5CE5B0081422795300FB554C /* PTKeyComboPanel.xib in Resources */,
9335C40D148EC7AC009CE623 /* multimarkdown in Resources */,
5CD1B00714F4593900AC948E /* Add.tiff in Resources */,
+ 934C3FB214FDA069000D14BA /* custom.css in Resources */,
+ 934C3FB314FDA06A000D14BA /* customclean.css in Resources */,
+ 934C3FB414FDA06A000D14BA /* template.html in Resources */,
+ 934C3FB514FDA06A000D14BA /* templateclean.html in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1661,6 +1682,7 @@
93B90E921386072E00BEC5FB /* TemporaryFileCachePreparer.m in Sources */,
5C177AE7141EF95200BC0C0A /* ETClipView.m in Sources */,
5C38E2C414223D6900131682 /* ETOverlayScroller.m in Sources */,
+ 934C3FB914FDA74F000D14BA /* NSFileManager+DirectoryLocations.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Oops, something went wrong.

0 comments on commit c79f6cc

Please sign in to comment.