Skip to content
Permalink
Browse files

initial window setup and skeleton drag and drop control

  • Loading branch information
ejdraper committed May 18, 2015
0 parents commit 13080b10508ad80c7434acddcd10ff0037b28fde
Showing with 264 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +4 −0 Gemfile
  3. +10 −0 Gemfile.lock
  4. +14 −0 Rakefile
  5. +33 −0 app/app_delegate.rb
  6. +2 −0 app/drag_and_drop_view.rb
  7. +155 −0 app/menu.rb
  8. +29 −0 resources/Credits.rtf
@@ -0,0 +1,17 @@
.repl_history
build
tags
app/pixate_code.rb
resources/*.nib
resources/*.momd
resources/*.storyboardc
.DS_Store
nbproject
.redcar
#*#
*~
*.sw[po]
.eprj
.sass-cache
.idea
.dat*.*
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'rake'
# Add your dependencies here:
@@ -0,0 +1,10 @@
GEM
remote: https://rubygems.org/
specs:
rake (10.4.2)

PLATFORMS
ruby

DEPENDENCIES
rake
@@ -0,0 +1,14 @@
# -*- 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 = 'DragAndDropDemo'
end
@@ -0,0 +1,33 @@
class AppDelegate
def applicationDidFinishLaunching(notification)
buildMenu
buildWindow

@drag_and_drop = DragAndDropView.alloc.initWithFrame(CGRectZero)
self.set_drag_and_drop_frame
@mainWindow.contentView.addSubview(@drag_and_drop)
end

def set_drag_and_drop_frame
window_size = @mainWindow.frame.size
drag_and_drop_size = [200, 200]
@drag_and_drop.frame = [
[(window_size.width / 2.0) - (drag_and_drop_size[0] / 2.0), (window_size.height / 2.0) - (drag_and_drop_size[1] / 2.0)],
drag_and_drop_size
]
end

def buildWindow
@mainWindow = NSWindow.alloc.initWithContentRect([[240, 180], [480, 360]],
styleMask: NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
backing: NSBackingStoreBuffered,
defer: false)
@mainWindow.title = NSBundle.mainBundle.infoDictionary['CFBundleName']
@mainWindow.orderFrontRegardless
@mainWindow.delegate = self
end

def windowDidResize(sender)
self.set_drag_and_drop_frame
end
end
@@ -0,0 +1,2 @@
class DragAndDropView < NSImageView
end
@@ -0,0 +1,155 @@
class AppDelegate
def buildMenu
@mainMenu = NSMenu.new

appName = NSBundle.mainBundle.infoDictionary['CFBundleName']

find_menu = createMenu('Find') do
addItemWithTitle('Find...', action: 'performFindPanelAction:', keyEquivalent: 'f')
addItemWithTitle('Find Next', action: 'performFindPanelAction:', keyEquivalent: 'g')
addItemWithTitle('Find Previous', action: 'performFindPanelAction:', keyEquivalent: 'G')
addItemWithTitle('Use Selection for Find', action: 'performFindPanelAction:', keyEquivalent: 'e')
addItemWithTitle('Jump to Selection', action: 'centerSelectionInVisibleArea:', keyEquivalent: 'j')
end

spelling_and_grammar_menu = createMenu('Spelling and Grammar') do
addItemWithTitle('Show Spelling and Grammar', action: 'showGuessPanel:', keyEquivalent: ':')
addItemWithTitle('Check Document Now', action: 'checkSpelling:', keyEquivalent: ';')
addItem(NSMenuItem.separatorItem)
addItemWithTitle('Check Spelling While Typing', action: 'toggleContinuousSpellChecking:', keyEquivalent: '')
addItemWithTitle('Check Grammar With Spelling', action: 'toggleGrammarChecking:', keyEquivalent: '')
addItemWithTitle('Correct Spelling Automatically', action: 'toggleAutomaticSpellingCorrection:', keyEquivalent: '')
end

substitutions_menu = createMenu('Substitutions') do
addItemWithTitle('Show Substitutions', action: 'orderFrontSubstitutionsPanel:', keyEquivalent: 'f')
addItem(NSMenuItem.separatorItem)
addItemWithTitle('Smart Copy/Paste', action: 'toggleSmartInsertDelete:', keyEquivalent: 'f')
addItemWithTitle('Smart Quotes', action: 'toggleAutomaticQuoteSubstitution:', keyEquivalent: 'g')
addItemWithTitle('Smart Dashes', action: 'toggleAutomaticDashSubstitution:', keyEquivalent: '')
addItemWithTitle('Smart Links', action: 'toggleAutomaticLinkDetection:', keyEquivalent: 'G')
addItemWithTitle('Text Replacement', action: 'toggleAutomaticTextReplacement:', keyEquivalent: '')
end

transformations_menu = createMenu('Transformations') do
addItemWithTitle('Make Upper Case', action: 'uppercaseWord:', keyEquivalent: '')
addItemWithTitle('Make Lower Case', action: 'lowercaseWord:', keyEquivalent: '')
addItemWithTitle('Capitalize', action: 'capitalizeWord:', keyEquivalent: '')
end

speech_menu = createMenu('Speech') do
addItemWithTitle('Start Speaking', action: 'startSpeaking:', keyEquivalent: '')
addItemWithTitle('Stop Speaking', action: 'stopSpeaking:', keyEquivalent: '')
end

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')
addItem(NSMenuItem.separatorItem)
addItem(find_menu)
addItem(spelling_and_grammar_menu)
addItem(substitutions_menu)
addItem(transformations_menu)
addItem(speech_menu)
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
@@ -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\
}

0 comments on commit 13080b1

Please sign in to comment.
You can’t perform that action at this time.