Skip to content

Commit

Permalink
Merge branch 'CPStepper-nib2cib' of https://github.com/cacaodev/cappu…
Browse files Browse the repository at this point in the history
…ccino into stepper-nib2cib
  • Loading branch information
Antoine Mercadal committed Feb 11, 2012
2 parents fdf672c + 4d3f8c3 commit a0eadc6
Show file tree
Hide file tree
Showing 12 changed files with 1,304 additions and 29 deletions.
86 changes: 57 additions & 29 deletions AppKit/CPStepper.j
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@implementation CPStepper: CPControl
{
BOOL _valueWraps @accessors(property=valueWraps);
BOOL _autorepeat @accessors(getter=autorepeat);
int _increment @accessors(property=increment);
int _maxValue @accessors(property=maxValue);
int _minValue @accessors(property=minValue);
Expand Down Expand Up @@ -88,29 +89,38 @@
_minValue = 0.0;
_increment = 1.0;
_valueWraps = YES;
_autorepeat = YES;

[self setDoubleValue:0.0];

_buttonUp = [[CPButton alloc] initWithFrame:_CGRectMakeZero()];
[_buttonUp setContinuous:YES];
[_buttonUp setTarget:self];
[_buttonUp setAction:@selector(_buttonDidClick:)];
[_buttonUp setAutoresizingMask:CPViewNotSizable];
[self addSubview:_buttonUp];

_buttonDown = [[CPButton alloc] initWithFrame:_CGRectMakeZero()];
[_buttonDown setContinuous:YES];
[_buttonDown setTarget:self];
[_buttonDown setAction:@selector(_buttonDidClick:)];
[_buttonDown setAutoresizingMask:CPViewNotSizable];
[self addSubview:_buttonDown];

[self setNeedsLayout];
[self _init];
}

return self;
}

/*! @ignore */

- (void)_init
{
_buttonUp = [[CPButton alloc] initWithFrame:_CGRectMakeZero()];
[_buttonUp setContinuous:_autorepeat];
[_buttonUp setTarget:self];
[_buttonUp setAction:@selector(_buttonDidClick:)];
[_buttonUp setAutoresizingMask:CPViewNotSizable];
[self addSubview:_buttonUp];

_buttonDown = [[CPButton alloc] initWithFrame:_CGRectMakeZero()];
[_buttonDown setContinuous:_autorepeat];
[_buttonDown setTarget:self];
[_buttonDown setAction:@selector(_buttonDidClick:)];
[_buttonDown setAutoresizingMask:CPViewNotSizable];

[self setContinuous:_autorepeat];
[self addSubview:_buttonDown];

[self setNeedsLayout];
}

#pragma mark -
#pragma mark Superclass overrides

Expand Down Expand Up @@ -164,8 +174,13 @@
*/
- (void)setAutorepeat:(BOOL)shouldAutoRepeat
{
[_buttonUp setContinuous:shouldAutoRepeat];
[_buttonDown setContinuous:shouldAutoRepeat];
if (shouldAutoRepeat !== _autorepeat)
{
[_buttonUp setContinuous:shouldAutoRepeat];
[_buttonDown setContinuous:shouldAutoRepeat];
}

[self setContinuous:shouldAutoRepeat];
}

/*!
Expand Down Expand Up @@ -235,31 +250,44 @@

@end

var CPStepperMinValue = @"CPStepperMinValue",
CPStepperMaxValue = @"CPStepperMaxValue",
CPStepperValueWraps = @"CPStepperValueWraps",
CPStepperAutorepeat = @"CPStepperAutorepeat",
CPStepperIncrement = @"CPStepperIncrement";

@implementation CPStepper (CPCodingCompliance)
@implementation CPStepper (CPCoding)

- (id)initWithCoder:(CPCoder)aCoder
{
if (self = [super initWithCoder:aCoder])
{
_maxValue = [aCoder decodeObjectForKey:@"_maxValue"];
_minValue = [aCoder decodeObjectForKey:@"_minValue"];
_increment = [aCoder decodeObjectForKey:@"_increment"];
_buttonUp = [aCoder decodeObjectForKey:@"_buttonUp"];
_buttonDown = [aCoder decodeObjectForKey:@"_buttonDown"];
_increment = [aCoder decodeIntForKey:CPStepperIncrement];
_minValue = [aCoder decodeIntForKey:CPStepperMinValue] || 0;
_maxValue = [aCoder decodeIntForKey:CPStepperMaxValue] || 0;
_valueWraps = [aCoder decodeBoolForKey:CPStepperValueWraps] || NO;
_autorepeat = [aCoder decodeBoolForKey:CPStepperAutorepeat] || NO;

[self _init];
}

return self;
}

- (void)encodeWithCoder:(CPCoder)aCoder
{
[super encodeWithCoder:aCoder];

[aCoder encodeObject:_maxValue forKey:@"_maxValue"];
[aCoder encodeObject:_minValue forKey:@"_minValue"];
[aCoder encodeObject:_increment forKey:@"_increment"];
[aCoder encodeObject:_buttonUp forKey:@"_buttonUp"];
[aCoder encodeObject:_buttonDown forKey:@"_buttonDown"];
[aCoder encodeInt:_increment forKey:CPStepperIncrement];

if (_minValue)
[aCoder encodeInt:_minValue forKey:CPStepperMinValue];
if (_maxValue)
[aCoder encodeInt:_maxValue forKey:CPStepperMaxValue];
if (_valueWraps)
[aCoder encodeBool:_valueWraps forKey:CPStepperValueWraps];
if (_autorepeat)
[aCoder encodeBool:_autorepeat forKey:CPStepperAutorepeat];
}

@end
67 changes: 67 additions & 0 deletions Tests/Manual/CPStepperNibTest/AppController.j
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* AppController.j
* CPStepperNibTest
*
* Created by cacaodev on February 7, 2012.
* Copyright 2012, Your Company All rights reserved.
*/

@import <Foundation/CPObject.j>


@implementation AppController : CPObject
{
CPWindow theWindow; //this "outlet" is connected automatically by the Cib
@outlet CPStepper stepper;
}

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// This is called when the application is done loading.
}

- (void)awakeFromCib
{
// This is called when the cib is done loading.
// You can implement this method on any object instantiated from a Cib.
// It's a useful hook for setting up current UI values, and other things.

// In this case, we want the window from Cib to become our full browser window
var contentView = [theWindow contentView];

[[contentView viewWithTag:1000] setIntValue:[stepper increment]];
[[contentView viewWithTag:1001] setIntValue:[stepper minValue]];
[[contentView viewWithTag:1002] setIntValue:[stepper maxValue]];
[[contentView viewWithTag:1003] setState:[stepper valueWraps] ? CPOnState : CPOffState];
[[contentView viewWithTag:1005] setState:[stepper autorepeat] ? CPOnState : CPOffState];
[[contentView viewWithTag:1004] setIntValue:[stepper objectValue]];

[theWindow setFullPlatformWindow:YES];
}

- (IBAction)setWraps:(id)sender
{
[stepper setValueWraps:[sender state]];
}

- (IBAction)setMin:(id)sender
{
[stepper setMinValue:[sender intValue]];
}

- (IBAction)setMax:(id)sender
{
[stepper setMaxValue:[sender intValue]];
}

- (IBAction)setIncrement:(id)sender
{
[stepper setIncrement:[sender intValue]];
}

- (IBAction)setAutorepeat:(id)sender
{
[stepper setAutorepeat:[sender state]];
}

@end
10 changes: 10 additions & 0 deletions Tests/Manual/CPStepperNibTest/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?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>Main cib file base name</key>
<string>MainMenu.cib</string>
<key>CPBundleName</key>
<string>CPStepperNibTest</string>
</dict>
</plist>
94 changes: 94 additions & 0 deletions Tests/Manual/CPStepperNibTest/Jakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Jakefile
* CPStepperNibTest
*
* Created by You on February 7, 2012.
* Copyright 2012, Your Company All rights reserved.
*/

var ENV = require("system").env,
FILE = require("file"),
JAKE = require("jake"),
task = JAKE.task,
FileList = JAKE.FileList,
app = require("cappuccino/jake").app,
configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug",
OS = require("os");

app ("CPStepperNibTest", function(task)
{
task.setBuildIntermediatesPath(FILE.join("Build", "CPStepperNibTest.build", configuration));
task.setBuildPath(FILE.join("Build", configuration));

task.setProductName("CPStepperNibTest");
task.setIdentifier("com.yourcompany.CPStepperNibTest");
task.setVersion("1.0");
task.setAuthor("Your Company");
task.setEmail("feedback @nospam@ yourcompany.com");
task.setSummary("CPStepperNibTest");
task.setSources((new FileList("**/*.j")).exclude(FILE.join("Build", "**")));
task.setResources(new FileList("Resources/**"));
task.setIndexFilePath("index.html");
task.setInfoPlistPath("Info.plist");
task.setNib2CibFlags("-R Resources/");

if (configuration === "Debug")
task.setCompilerFlags("-DDEBUG -g");
else
task.setCompilerFlags("-O");
});

task ("default", ["CPStepperNibTest"], function()
{
printResults(configuration);
});

task ("build", ["default"]);

task ("debug", function()
{
ENV["CONFIGURATION"] = "Debug";
JAKE.subjake(["."], "build", ENV);
});

task ("release", function()
{
ENV["CONFIGURATION"] = "Release";
JAKE.subjake(["."], "build", ENV);
});

task ("run", ["debug"], function()
{
OS.system(["open", FILE.join("Build", "Debug", "CPStepperNibTest", "index.html")]);
});

task ("run-release", ["release"], function()
{
OS.system(["open", FILE.join("Build", "Release", "CPStepperNibTest", "index.html")]);
});

task ("deploy", ["release"], function()
{
FILE.mkdirs(FILE.join("Build", "Deployment", "CPStepperNibTest"));
OS.system(["press", "-f", FILE.join("Build", "Release", "CPStepperNibTest"), FILE.join("Build", "Deployment", "CPStepperNibTest")]);
printResults("Deployment")
});

task ("desktop", ["release"], function()
{
FILE.mkdirs(FILE.join("Build", "Desktop", "CPStepperNibTest"));
require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", "CPStepperNibTest"), FILE.join("Build", "Desktop", "CPStepperNibTest", "CPStepperNibTest.app"));
printResults("Desktop")
});

task ("run-desktop", ["desktop"], function()
{
OS.system([FILE.join("Build", "Desktop", "CPStepperNibTest", "CPStepperNibTest.app", "Contents", "MacOS", "NativeHost"), "-i"]);
});

function printResults(configuration)
{
print("----------------------------");
print(configuration+" app built at path: "+FILE.join("Build", configuration, "CPStepperNibTest"));
print("----------------------------");
}
1 change: 1 addition & 0 deletions Tests/Manual/CPStepperNibTest/Resources/MainMenu.cib

Large diffs are not rendered by default.

0 comments on commit a0eadc6

Please sign in to comment.