Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.1.1 working #26

Merged
merged 30 commits into from
Jun 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5236f1a
Added convertNumberToString function
NorthernRealities Mar 20, 2016
d93633e
Merge branch 'master' into 1.1.1-working
NorthernRealities Mar 22, 2016
6e95edc
Added the UUID for Xcode 7.3
NorthernRealities Mar 24, 2016
c97bba4
Replaced deprecated start: end: call
NorthernRealities Mar 24, 2016
72655d8
Code cleanup, bug fix
NorthernRealities Mar 26, 2016
5e11149
Using guard to clean up code
NorthernRealities Mar 26, 2016
954ad7e
Using guard to clean up code, Swift 2.2 changes
NorthernRealities Mar 26, 2016
bcb7d46
Changed constant to use new one for alpha decimal places.
NorthernRealities Mar 26, 2016
596a07c
Making regular expressions easier to maintain.
NorthernRealities Mar 26, 2016
11d5092
Added user state to the ignore list
NorthernRealities Mar 26, 2016
dd2ef81
Using guard to clean up code, Swift 2.2 changes
NorthernRealities Mar 26, 2016
5391216
Added another user state file
NorthernRealities Mar 26, 2016
0224927
Added another file
NorthernRealities Mar 26, 2016
ec104ac
Added another file.
NorthernRealities Mar 26, 2016
0004a3e
Merge remote-tracking branch 'origin/1.1.1-working' into 1.1.1-working
NorthernRealities Mar 26, 2016
0ba36be
Making regular expressions easier to maintain.
NorthernRealities Apr 3, 2016
1103eb0
Update library to Swift 2.2
NorthernRealities Apr 3, 2016
465f2d2
Add support for ".init" to match regex
NorthernRealities Apr 3, 2016
4e359ad
Support for Rainbow Creator function for HSB colour creation
NorthernRealities Apr 5, 2016
cd003c9
Formats the value of the alpha properly now.
NorthernRealities Apr 9, 2016
4703548
Making regular expressions easier to maintain.
NorthernRealities Apr 9, 2016
b2dcf13
Defined a constant in here instead of the superclass
NorthernRealities Apr 14, 2016
62737df
Making regular expressions easier to maintain.
NorthernRealities Apr 14, 2016
37c8146
Using guard, format alpha better
NorthernRealities Apr 14, 2016
a1edf70
Set number of decimal places to proper values
NorthernRealities Apr 21, 2016
2ceb68a
Fix to allow plug-in to work on pre 7.3 Xcode
NorthernRealities Apr 24, 2016
447fc25
Added number formatters to fix the number of decimals printed for alpha
NorthernRealities Apr 24, 2016
99df962
Updated for testing
NorthernRealities Apr 24, 2016
4091217
Fix to allow plug-in to work on pre 7.3 Xcode
NorthernRealities Apr 25, 2016
3f92667
Updated for testing
NorthernRealities Apr 25, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
ColorSenseRainbow.xcodeproj/project.xcworkspace/xcshareddata/ColorSenseRainbow.xccheckout

ColorSenseRainbow.xcodeproj/project.xcworkspace/xcshareddata/ColorSenseRainbow.xccheckout

*.xcuserstate

ColorSenseRainbow.xcodeproj/project.xcworkspace/xcuserdata/rgravell.xcuserdatad/UserInterfaceState.xcuserstate

ColorSenseRainbow.xcodeproj/project.xcworkspace/xcuserdata/rgravell.xcuserdatad/UserInterfaceState.xcuserstate
12 changes: 10 additions & 2 deletions ColorSenseRainbow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
5662361E1AE9420000BABC79 /* Rainbow-Creator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5662361D1AE9420000BABC79 /* Rainbow-Creator.swift */; };
566236201AE97CCB00BABC79 /* RGBFloatSeeker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5662361F1AE97CCB00BABC79 /* RGBFloatSeeker.swift */; };
566236221AE9830800BABC79 /* RGBCalculatedSeeker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566236211AE9830800BABC79 /* RGBCalculatedSeeker.swift */; };
56673E791CB2F49A009CBCB4 /* RainbowHSBSeeker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56673E781CB2F49A009CBCB4 /* RainbowHSBSeeker.swift */; };
56673E7B1CB44401009CBCB4 /* RainbowHSBBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56673E7A1CB44401009CBCB4 /* RainbowHSBBuilder.swift */; };
566FFA7B1B6E9A8900F4EBA6 /* HSBFloatSeeker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566FFA7A1B6E9A8900F4EBA6 /* HSBFloatSeeker.swift */; };
566FFA7D1B6EA02B00F4EBA6 /* DefaultHSBBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 566FFA7C1B6EA02B00F4EBA6 /* DefaultHSBBuilder.swift */; };
56B480E01AE2D6CC00B507E4 /* ColorSenseRainbow.xcscheme in Resources */ = {isa = PBXBuildFile; fileRef = 56B480DF1AE2D6CC00B507E4 /* ColorSenseRainbow.xcscheme */; };
Expand Down Expand Up @@ -57,6 +59,8 @@
5662361D1AE9420000BABC79 /* Rainbow-Creator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Rainbow-Creator.swift"; sourceTree = "<group>"; };
5662361F1AE97CCB00BABC79 /* RGBFloatSeeker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RGBFloatSeeker.swift; sourceTree = "<group>"; };
566236211AE9830800BABC79 /* RGBCalculatedSeeker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RGBCalculatedSeeker.swift; sourceTree = "<group>"; };
56673E781CB2F49A009CBCB4 /* RainbowHSBSeeker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RainbowHSBSeeker.swift; sourceTree = "<group>"; };
56673E7A1CB44401009CBCB4 /* RainbowHSBBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RainbowHSBBuilder.swift; sourceTree = "<group>"; };
566FFA7A1B6E9A8900F4EBA6 /* HSBFloatSeeker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HSBFloatSeeker.swift; sourceTree = "<group>"; };
566FFA7C1B6EA02B00F4EBA6 /* DefaultHSBBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultHSBBuilder.swift; sourceTree = "<group>"; };
56B480DA1AE2D6CC00B507E4 /* ColorSenseRainbow.xcplugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ColorSenseRainbow.xcplugin; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -91,11 +95,12 @@
5609BEE31AE460D000DF2D5B /* PredefinedColorSeeker.swift */,
5662361B1AE940AF00BABC79 /* RainbowHexadecimalIntSeeker.swift */,
566236191AE9391100BABC79 /* RainbowHexadecimalStringSeeker.swift */,
56673E781CB2F49A009CBCB4 /* RainbowHSBSeeker.swift */,
5609BEEA1AE544F500DF2D5B /* RainbowIntSeeker.swift */,
566FFA7A1B6E9A8900F4EBA6 /* HSBFloatSeeker.swift */,
566236211AE9830800BABC79 /* RGBCalculatedSeeker.swift */,
5662361F1AE97CCB00BABC79 /* RGBFloatSeeker.swift */,
56B4D75A1B72919000F59DD6 /* WhiteSeeker.swift */,
566236211AE9830800BABC79 /* RGBCalculatedSeeker.swift */,
5609BEE11AE41A1500DF2D5B /* Seeker.swift */,
);
name = Seekers;
Expand All @@ -110,9 +115,10 @@
566FFA7C1B6EA02B00F4EBA6 /* DefaultHSBBuilder.swift */,
56B4D75C1B72973400F59DD6 /* DefaultWhiteBuilder.swift */,
56D014671AF11C1F005624AF /* PredefinedColorBuilder.swift */,
56D014631AF04131005624AF /* RainbowIntBuilder.swift */,
56F4E9E31B1624210083699A /* RainbowHexIntBuilder.swift */,
564C22FC1AEE833B0098E933 /* RainbowHexStringBuilder.swift */,
56673E7A1CB44401009CBCB4 /* RainbowHSBBuilder.swift */,
56D014631AF04131005624AF /* RainbowIntBuilder.swift */,
);
name = ColorBuilders;
sourceTree = "<group>";
Expand Down Expand Up @@ -246,7 +252,9 @@
5662361C1AE940AF00BABC79 /* RainbowHexadecimalIntSeeker.swift in Sources */,
56F4E9E41B1624210083699A /* RainbowHexIntBuilder.swift in Sources */,
5662361E1AE9420000BABC79 /* Rainbow-Creator.swift in Sources */,
56673E7B1CB44401009CBCB4 /* RainbowHSBBuilder.swift in Sources */,
56B480E91AE2D73500B507E4 /* NSColor+Rainbow.swift in Sources */,
56673E791CB2F49A009CBCB4 /* RainbowHSBSeeker.swift in Sources */,
563133FA1AF3EF58005494E2 /* CalculatedRGBBuilder.swift in Sources */,
5662361A1AE9391100BABC79 /* RainbowHexadecimalStringSeeker.swift in Sources */,
5609BEE21AE41A1500DF2D5B /* Seeker.swift in Sources */,
Expand Down
Binary file not shown.
Binary file modified ColorSenseRainbow.xcplugin.zip
Binary file not shown.
64 changes: 35 additions & 29 deletions ColorSenseRainbow/CalculatedRGBBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,53 +24,59 @@ class CalculatedRGBBuilder: ColorBuilder {

override func stringForColor( color : NSColor, forSearchResult : SearchResult ) -> String? {

var returnString = ""

if let unwrappedString = forSearchResult.capturedStrings.first {
returnString = unwrappedString
} else {
guard var returnString = forSearchResult.capturedStrings.first else {
return nil
}


let numberFormatter = NSNumberFormatter()
numberFormatter.locale = NSLocale(localeIdentifier: "us")
numberFormatter.numberStyle = NSNumberFormatterStyle.DecimalStyle
numberFormatter.maximumFractionDigits = 1 // Don't need as many digits here.
numberFormatter.maximumFractionDigits = ColorBuilder.maximumAlphaFractionDigits
numberFormatter.minimumFractionDigits = 1
numberFormatter.decimalSeparator = "." // Users, with another locales have "," separating decimals

let stringFormatter = NSNumberFormatter()
numberFormatter.locale = NSLocale(localeIdentifier: "us")
stringFormatter.numberStyle = NSNumberFormatterStyle.DecimalStyle
stringFormatter.decimalSeparator = numberFormatter.decimalSeparator


guard let alphaComponent = convertNumberToString( Double ( color.alphaComponent ), numberDesc: "alpha component", numberFormatter: numberFormatter ) else {
return nil
}


if ( forSearchResult.tcr.numberOfRanges == 8 ) {
if let modifiedString = processCaptureGroupInSearchResult( forSearchResult, forRangeAtIndex: 7, inText: returnString, withReplacementText: "\(color.alphaComponent)" ) {
if let modifiedString = processCaptureGroupInSearchResult( forSearchResult, forRangeAtIndex: 7, inText: returnString, withReplacementText: alphaComponent ) {
returnString = modifiedString
} else {
return nil
}
} else if ( color.alphaComponent < 1.0 ) {
// User has changed the alpha so we need to add it to the code.

if let modifiedString = processCaptureGroupInSearchResult( forSearchResult, forRangeAtIndex: 6, inText: returnString, withReplacementText: forSearchResult.capturedStrings[6] + ", alpha: \(color.alphaComponent)" ) {
if let modifiedString = processCaptureGroupInSearchResult( forSearchResult, forRangeAtIndex: 6, inText: returnString, withReplacementText: forSearchResult.capturedStrings[6] + ", alpha: " + alphaComponent ) {
returnString = modifiedString
} else {
return nil
}
}


numberFormatter.maximumFractionDigits = 1 // Don't need as many digits here.


if let denomString = stringFormatter.numberFromString( forSearchResult.capturedStrings[ 6 ] ) {
let denom = denomString.doubleValue
if let component = numberFormatter.stringFromNumber( Double ( color.blueComponent ) * denom ) {
if let modifiedString = processCaptureGroupInSearchResult( forSearchResult, forRangeAtIndex: 5, inText: returnString, withReplacementText: component ) {
returnString = modifiedString
} else {
return nil
}

guard let component = convertNumberToString ( Double ( color.blueComponent ) * denom, numberDesc: "blue component", numberFormatter: numberFormatter ) else {
return nil
}

if let modifiedString = processCaptureGroupInSearchResult( forSearchResult, forRangeAtIndex: 5, inText: returnString, withReplacementText: component ) {
returnString = modifiedString
} else {
print ( "Error converting color blue component of \(color.blueComponent) to a string." )
return nil
}
} else {
Expand All @@ -81,14 +87,14 @@ class CalculatedRGBBuilder: ColorBuilder {

if let denomString = stringFormatter.numberFromString( forSearchResult.capturedStrings[ 4 ] ) {
let denom = denomString.doubleValue
if let component = numberFormatter.stringFromNumber( Double ( color.greenComponent ) * denom ) {
if let modifiedString = processCaptureGroupInSearchResult( forSearchResult, forRangeAtIndex: 3, inText: returnString, withReplacementText: component ) {
returnString = modifiedString
} else {
return nil
}

guard let component = convertNumberToString ( Double ( color.greenComponent ) * denom, numberDesc: "green component", numberFormatter: numberFormatter ) else {
return nil
}

if let modifiedString = processCaptureGroupInSearchResult( forSearchResult, forRangeAtIndex: 3, inText: returnString, withReplacementText: component ) {
returnString = modifiedString
} else {
print ( "Error converting color green component of \(color.greenComponent) to a string." )
return nil
}
} else {
Expand All @@ -99,14 +105,14 @@ class CalculatedRGBBuilder: ColorBuilder {

if let denomString = stringFormatter.numberFromString( forSearchResult.capturedStrings[ 2 ] ) {
let denom = denomString.doubleValue
if let component = numberFormatter.stringFromNumber( Double ( color.redComponent ) * denom ) {
if let modifiedString = processCaptureGroupInSearchResult( forSearchResult, forRangeAtIndex: 1, inText: returnString, withReplacementText: component ) {
returnString = modifiedString
} else {
return nil
}

guard let component = convertNumberToString ( Double ( color.redComponent ) * denom, numberDesc: "red component", numberFormatter: numberFormatter ) else {
return nil
}

if let modifiedString = processCaptureGroupInSearchResult( forSearchResult, forRangeAtIndex: 1, inText: returnString, withReplacementText: component ) {
returnString = modifiedString
} else {
print ( "Error converting color red component of \(color.redComponent) to a string." )
return nil
}
} else {
Expand Down
21 changes: 20 additions & 1 deletion ColorSenseRainbow/ColorBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import AppKit

class ColorBuilder {

static let maximumFractionDigits : Int = 4
static let maximumFractionDigits : Int = 4 // Delete this after everything converted over to ColorFractionsDigits
static let maximumAlphaFractionDigits : Int = 2
static let maximumColorFractionDigits : Int = 4


/**
Expand Down Expand Up @@ -73,4 +75,21 @@ class ColorBuilder {
return nil
}






func convertNumberToString ( numberToConvert : Double, numberDesc : String, numberFormatter : NSNumberFormatter ) -> String?
{
let numberAsString = numberFormatter.stringFromNumber( numberToConvert )

if ( numberAsString == nil ) {
print ( "Error converting \(numberDesc) with value of \(numberToConvert) to a string." )
return nil
}

return numberAsString
}

}
3 changes: 3 additions & 0 deletions ColorSenseRainbow/ColorBuilderFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class ColorBuilderFactory {
case .DefaultHSB:
return DefaultHSBBuilder()

case .RainbowHSB:
return RainbowHSBBuilder()

case .Unknown:
return nil
}
Expand Down
1 change: 1 addition & 0 deletions ColorSenseRainbow/ColorFinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ColorFinder : CustomStringConvertible {
RainbowIntSeeker(),
RainbowHexadecimalStringSeeker(),
RainbowHexadecimalIntSeeker(),
RainbowHSBSeeker(),
HSBFloatSeeker()
]

Expand Down
24 changes: 13 additions & 11 deletions ColorSenseRainbow/ColorSenseRainbow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,20 @@ class ColorSenseRainbow: NSObject {

func createMenuItems() {

let item = NSApp.mainMenu!.itemWithTitle("Edit")
if item != nil {
actionMenuItem = NSMenuItem(title:"Show Colors Under Carat", action:"toggleColorsUnderCarat", keyEquivalent:"")
actionMenuItem.target = self

if enabled == true {
actionMenuItem.state = NSOnState
}

item!.submenu!.addItem(NSMenuItem.separatorItem())
item!.submenu!.addItem(actionMenuItem)
guard let item = NSApp.mainMenu!.itemWithTitle("Edit") else {
return
}

actionMenuItem = NSMenuItem(title:"Show Colors Under Carat", action:"toggleColorsUnderCarat", keyEquivalent:"")
actionMenuItem.target = self

if enabled == true {
actionMenuItem.state = NSOnState
}


item.submenu!.addItem(NSMenuItem.separatorItem())
item.submenu!.addItem(actionMenuItem)
}


Expand Down
Loading