-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a0867c
commit 357f901
Showing
8 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.repl_history | ||
build | ||
tags | ||
app/pixate_code.rb | ||
resources/*.nib | ||
resources/*.momd | ||
resources/*.storyboardc | ||
.DS_Store | ||
nbproject | ||
.redcar | ||
#*# | ||
*~ | ||
*.sw[po] | ||
.eprj | ||
.sass-cache | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rake' | ||
# Add your dependencies here: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Calc.app | ||
|
||
This sample demonstrates the following concepts: #eval for OSX | ||
(http://blog.rubymotion.com/post/65685097257/new-in-rubymotion-mavericks-eval-for-os-x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- coding: utf-8 -*- | ||
$:.unshift("/Library/RubyMotion/lib") | ||
require 'motion/project/template/osx' | ||
|
||
begin | ||
require 'bundler' | ||
Bundler.require | ||
rescue LoadError | ||
end | ||
|
||
Motion::Project::App.setup do |app| | ||
# Use `rake config' to see complete project settings. | ||
app.name = 'Calc' | ||
app.eval_support = true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class AppDelegate | ||
def applicationDidFinishLaunching(notification) | ||
buildMenu | ||
buildWindow | ||
end | ||
|
||
def buildWindow | ||
@mainWindow = NSWindow.alloc.initWithContentRect([[240, 180], [300, 150]], | ||
styleMask: NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask, | ||
backing: NSBackingStoreBuffered, | ||
defer: false) | ||
@mainWindow.title = NSBundle.mainBundle.infoDictionary['CFBundleName'] | ||
@mainWindow.orderFrontRegardless | ||
|
||
@text = NSTextField.alloc.initWithFrame([[20, 90], [200, 22]]) | ||
@text.autoresizingMask = NSViewMinXMargin|NSViewMinYMargin|NSViewWidthSizable | ||
@mainWindow.contentView.addSubview(@text) | ||
|
||
button = NSButton.alloc.initWithFrame([[220, 83], [62, 32]]) | ||
button.title = "Calc" | ||
button.action = :"calc:" | ||
button.target = self | ||
button.bezelStyle = NSRoundedBezelStyle | ||
button.autoresizingMask = NSViewMinXMargin|NSViewMinYMargin | ||
@mainWindow.contentView.addSubview(button) | ||
|
||
@label = NSTextField.alloc.initWithFrame([[20, 40], [260, 22]]) | ||
@label.autoresizingMask = NSViewMinXMargin|NSViewMinYMargin|NSViewWidthSizable | ||
@label.editable = false | ||
@mainWindow.contentView.addSubview(@label) | ||
end | ||
|
||
def calc(sender) | ||
string = @text.stringValue | ||
if string =~ /^[\d\s\.\+\-\*\/]*$/ | ||
result = eval(string) | ||
else | ||
result = "ERROR" | ||
end | ||
@label.stringValue = result.to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
class AppDelegate | ||
def buildMenu | ||
@mainMenu = NSMenu.new | ||
|
||
appName = NSBundle.mainBundle.infoDictionary['CFBundleName'] | ||
addMenu(appName) do | ||
addItemWithTitle("About #{appName}", action: 'orderFrontStandardAboutPanel:', keyEquivalent: '') | ||
addItem(NSMenuItem.separatorItem) | ||
addItemWithTitle('Preferences', action: 'openPreferences:', keyEquivalent: ',') | ||
addItem(NSMenuItem.separatorItem) | ||
servicesItem = addItemWithTitle('Services', action: nil, keyEquivalent: '') | ||
NSApp.servicesMenu = servicesItem.submenu = NSMenu.new | ||
addItem(NSMenuItem.separatorItem) | ||
addItemWithTitle("Hide #{appName}", action: 'hide:', keyEquivalent: 'h') | ||
item = addItemWithTitle('Hide Others', action: 'hideOtherApplications:', keyEquivalent: 'H') | ||
item.keyEquivalentModifierMask = NSCommandKeyMask|NSAlternateKeyMask | ||
addItemWithTitle('Show All', action: 'unhideAllApplications:', keyEquivalent: '') | ||
addItem(NSMenuItem.separatorItem) | ||
addItemWithTitle("Quit #{appName}", action: 'terminate:', keyEquivalent: 'q') | ||
end | ||
|
||
addMenu('File') do | ||
addItemWithTitle('New', action: 'newDocument:', keyEquivalent: 'n') | ||
addItemWithTitle('Open…', action: 'openDocument:', keyEquivalent: 'o') | ||
addItem(NSMenuItem.separatorItem) | ||
addItemWithTitle('Close', action: 'performClose:', keyEquivalent: 'w') | ||
addItemWithTitle('Save…', action: 'saveDocument:', keyEquivalent: 's') | ||
addItemWithTitle('Revert to Saved', action: 'revertDocumentToSaved:', keyEquivalent: '') | ||
addItem(NSMenuItem.separatorItem) | ||
addItemWithTitle('Page Setup…', action: 'runPageLayout:', keyEquivalent: 'P') | ||
addItemWithTitle('Print…', action: 'printDocument:', keyEquivalent: 'p') | ||
end | ||
|
||
addMenu('Edit') do | ||
addItemWithTitle('Undo', action: 'undo:', keyEquivalent: 'z') | ||
addItemWithTitle('Redo', action: 'redo:', keyEquivalent: 'Z') | ||
addItem(NSMenuItem.separatorItem) | ||
addItemWithTitle('Cut', action: 'cut:', keyEquivalent: 'x') | ||
addItemWithTitle('Copy', action: 'copy:', keyEquivalent: 'c') | ||
addItemWithTitle('Paste', action: 'paste:', keyEquivalent: 'v') | ||
item = addItemWithTitle('Paste and Match Style', action: 'pasteAsPlainText:', keyEquivalent: 'V') | ||
item.keyEquivalentModifierMask = NSCommandKeyMask|NSAlternateKeyMask | ||
addItemWithTitle('Delete', action: 'delete:', keyEquivalent: '') | ||
addItemWithTitle('Select All', action: 'selectAll:', keyEquivalent: 'a') | ||
end | ||
|
||
fontMenu = createMenu('Font') do | ||
addItemWithTitle('Show Fonts', action: 'orderFrontFontPanel:', keyEquivalent: 't') | ||
addItemWithTitle('Bold', action: 'addFontTrait:', keyEquivalent: 'b') | ||
addItemWithTitle('Italic', action: 'addFontTrait:', keyEquivalent: 'i') | ||
addItemWithTitle('Underline', action: 'underline:', keyEquivalent: 'u') | ||
addItem(NSMenuItem.separatorItem) | ||
addItemWithTitle('Bigger', action: 'modifyFont:', keyEquivalent: '+') | ||
addItemWithTitle('Smaller', action: 'modifyFont:', keyEquivalent: '-') | ||
end | ||
|
||
textMenu = createMenu('Text') do | ||
addItemWithTitle('Align Left', action: 'alignLeft:', keyEquivalent: '{') | ||
addItemWithTitle('Center', action: 'alignCenter:', keyEquivalent: '|') | ||
addItemWithTitle('Justify', action: 'alignJustified:', keyEquivalent: '') | ||
addItemWithTitle('Align Right', action: 'alignRight:', keyEquivalent: '}') | ||
addItem(NSMenuItem.separatorItem) | ||
addItemWithTitle('Show Ruler', action: 'toggleRuler:', keyEquivalent: '') | ||
item = addItemWithTitle('Copy Ruler', action: 'copyRuler:', keyEquivalent: 'c') | ||
item.keyEquivalentModifierMask = NSCommandKeyMask|NSControlKeyMask | ||
item = addItemWithTitle('Paste Ruler', action: 'pasteRuler:', keyEquivalent: 'v') | ||
item.keyEquivalentModifierMask = NSCommandKeyMask|NSControlKeyMask | ||
end | ||
|
||
addMenu('Format') do | ||
addItem fontMenu | ||
addItem textMenu | ||
end | ||
|
||
addMenu('View') do | ||
item = addItemWithTitle('Show Toolbar', action: 'toggleToolbarShown:', keyEquivalent: 't') | ||
item.keyEquivalentModifierMask = NSCommandKeyMask|NSAlternateKeyMask | ||
addItemWithTitle('Customize Toolbar…', action: 'runToolbarCustomizationPalette:', keyEquivalent: '') | ||
end | ||
|
||
NSApp.windowsMenu = addMenu('Window') do | ||
addItemWithTitle('Minimize', action: 'performMiniaturize:', keyEquivalent: 'm') | ||
addItemWithTitle('Zoom', action: 'performZoom:', keyEquivalent: '') | ||
addItem(NSMenuItem.separatorItem) | ||
addItemWithTitle('Bring All To Front', action: 'arrangeInFront:', keyEquivalent: '') | ||
end.menu | ||
|
||
NSApp.helpMenu = addMenu('Help') do | ||
addItemWithTitle("#{appName} Help", action: 'showHelp:', keyEquivalent: '?') | ||
end.menu | ||
|
||
NSApp.mainMenu = @mainMenu | ||
end | ||
|
||
private | ||
|
||
def addMenu(title, &b) | ||
item = createMenu(title, &b) | ||
@mainMenu.addItem item | ||
item | ||
end | ||
|
||
def createMenu(title, &b) | ||
menu = NSMenu.alloc.initWithTitle(title) | ||
menu.instance_eval(&b) if b | ||
item = NSMenuItem.alloc.initWithTitle(title, action: nil, keyEquivalent: '') | ||
item.submenu = menu | ||
item | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} | ||
{\colortbl;\red255\green255\blue255;} | ||
\paperw9840\paperh8400 | ||
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural | ||
|
||
\f0\b\fs24 \cf0 Engineering: | ||
\b0 \ | ||
Some people\ | ||
\ | ||
|
||
\b Human Interface Design: | ||
\b0 \ | ||
Some other people\ | ||
\ | ||
|
||
\b Testing: | ||
\b0 \ | ||
Hopefully not nobody\ | ||
\ | ||
|
||
\b Documentation: | ||
\b0 \ | ||
Whoever\ | ||
\ | ||
|
||
\b With special thanks to: | ||
\b0 \ | ||
Mom\ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe "Application 'Calc'" do | ||
before do | ||
@app = NSApplication.sharedApplication | ||
end | ||
|
||
it "has one window" do | ||
@app.windows.size.should == 1 | ||
end | ||
end |