diff options
author | bamse16 <marius@marius.me.uk> | 2012-10-05 08:49:47 +0000 |
---|---|---|
committer | bamse16 <marius@marius.me.uk> | 2012-10-05 08:49:47 +0000 |
commit | 76d7e65ef0447fe421a77ed2f16c19a83afb17f6 (patch) | |
tree | c399ad255c4bac8045376eb528e86e7c5ea00c26 | |
parent | 01ac565ab319b022c0d6e7877f9446c9c8c21f88 (diff) | |
download | sequelpro-76d7e65ef0447fe421a77ed2f16c19a83afb17f6.tar.gz sequelpro-76d7e65ef0447fe421a77ed2f16c19a83afb17f6.tar.bz2 sequelpro-76d7e65ef0447fe421a77ed2f16c19a83afb17f6.zip |
Issue 1470: [REQ] Support for bundling default Themes
Themes will be copied from Default Themes to ~/Library/Application Support/Sequel Pro/Themes, only if a theme with the same name does not exist in that folder.
-rwxr-xr-x | Scripts/build.sh | 8 | ||||
-rw-r--r-- | SharedSupport/Default Themes/Blue Dark.spTheme | 78 | ||||
-rw-r--r-- | Source/SPAppController.m | 53 |
3 files changed, 139 insertions, 0 deletions
diff --git a/Scripts/build.sh b/Scripts/build.sh index 9783d9b4..bc5a9d14 100755 --- a/Scripts/build.sh +++ b/Scripts/build.sh @@ -73,6 +73,14 @@ mkdir -p "${BUILD_PRODUCT}/Contents/SharedSupport/Default Bundles" cp -R "${SRCROOT}/SharedSupport/Default Bundles" "${BUILD_PRODUCT}/Contents/SharedSupport" +# Copy all Default Themes to build product +rm -rf "${BUILD_PRODUCT}/Contents/SharedSupport/Default Themes" + +mkdir -p "${BUILD_PRODUCT}/Contents/SharedSupport/Default Themes" + +cp -R "${SRCROOT}/SharedSupport/Default Themes" "${BUILD_PRODUCT}/Contents/SharedSupport" + + # Perform distribution specific tasks if this is a 'Distribution' build if [ "$CONFIGURATION" == 'Distribution' ] then diff --git a/SharedSupport/Default Themes/Blue Dark.spTheme b/SharedSupport/Default Themes/Blue Dark.spTheme new file mode 100644 index 00000000..c7aa2adc --- /dev/null +++ b/SharedSupport/Default Themes/Blue Dark.spTheme @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>settings</key> + <array> + <dict> + <key>settings</key> + <dict> + <key>background</key> + <string>#111D41</string> + <key>caret</key> + <string>#82E661</string> + <key>foreground</key> + <string>#A0E0EE</string> + <key>lineHighlight</key> + <string>#92FFC93A</string> + <key>selection</key> + <string>#EA33545E</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Comment</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#A6B6D0</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>String</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#83C657</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Keyword</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#9451BD</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>User-defined constant</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#DCB838</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Number</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#DC5E14</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Variable</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#4FADEC</string> + </dict> + </dict> + </array> +</dict> +</plist> diff --git a/Source/SPAppController.m b/Source/SPAppController.m index c993749a..7885e339 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -146,6 +146,7 @@ YY_BUFFER_STATE yy_scan_string (const char *); [[FRFeedbackReporter sharedReporter] reportIfCrash]; [self reloadBundles:self]; + [self copyDefaultThemes]; // If no documents are open, open one if (![self frontDocument]) { @@ -183,6 +184,58 @@ YY_BUFFER_STATE yy_scan_string (const char *); return YES; } +/** + * Copy default themes, when we start the app. + */ + +- (void)copyDefaultThemes +{ + NSFileManager *fm = [NSFileManager defaultManager]; + NSError *appPathError = nil; + + NSString *defaultThemesPath = [NSString stringWithFormat:@"%@/Contents/SharedSupport/Default Themes", [[NSBundle mainBundle] bundlePath]]; + NSString *appSupportThemesPath = [fm applicationSupportDirectoryForSubDirectory:SPThemesSupportFolder createIfNotExists:YES error:&appPathError]; + + // If ~/Library/Application Path/Sequel Pro/Themes couldn't be created bail + if(appPathError != nil) { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Themes Installation Error", @"themes installation error") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"Couldn't create Application Support Theme folder!\nError: %@", @"Couldn't create Application Support Theme folder!\nError: %@"), [appPathError localizedDescription]]]; + + [alert runModal]; + return; + } + + NSError *error = nil; + NSError *copyError = nil; + NSArray *defaultThemes = [fm contentsOfDirectoryAtPath:defaultThemesPath error:&error]; + if (defaultThemes && [defaultThemes count] && error == nil) { + for(NSString* defaultTheme in defaultThemes) { + if(![[[defaultTheme pathExtension] lowercaseString] isEqualToString:[SPColorThemeFileExtension lowercaseString]]) continue; + + NSString *defaultThemeFullPath = [NSString stringWithFormat:@"%@/%@", defaultThemesPath, defaultTheme]; + NSString *appSupportThemeFullPath = [NSString stringWithFormat:@"%@/%@", appSupportThemesPath, defaultTheme]; + + if([fm fileExistsAtPath:appSupportThemeFullPath]) continue; + [fm copyItemAtPath:defaultThemeFullPath toPath:appSupportThemeFullPath error:©Error]; + } + } + + // If Themes could not be copied, show error message + if(copyError != nil) { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Themes Installation Error", @"themes installation error") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"Couldn't copy default themes to Application Support Theme folder!\nError: %@", @"Couldn't copy default themes to Application Support Theme folder!\nError: %@"), [copyError localizedDescription]]]; + + [alert runModal]; + return; + } +} + #pragma mark - #pragma mark Open methods |