Skip to content

Commit

Permalink
Merge pull request #26 from NorthernRealities/1.1.1-working
Browse files Browse the repository at this point in the history
1.1.1 working
  • Loading branch information
NorthernRealities authored Jun 12, 2016
2 parents 34a9f95 + 3f92667 commit 6f94568
Show file tree
Hide file tree
Showing 30 changed files with 734 additions and 293 deletions.
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

0 comments on commit 6f94568

Please sign in to comment.