Skip to content

Commit 5a1632c

Browse files
committed
Initial commit
0 parents  commit 5a1632c

File tree

16 files changed

+607
-0
lines changed

16 files changed

+607
-0
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.repl_history
2+
build
3+
tags
4+
app/pixate_code.rb
5+
resources/*.nib
6+
resources/*.momd
7+
resources/*.storyboardc
8+
vendor/Pods
9+
.DS_Store
10+
nbproject
11+
.redcar
12+
#*#
13+
*~
14+
*.sw[po]
15+
.eprj
16+
.sass-cache
17+
.idea
18+
.dat*.*

Gemfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'rake'
4+
# Add your dependencies here:
5+
6+
gem 'motion_print', '~> 1.2.0'
7+
gem 'motion-cocoapods', '~> 1.8'
8+
gem 'bubble-wrap', '~> 1.9'
9+
gem 'sugarcube', '~> 3.4'
10+
gem 'motion-kit', '~> 1.1'
11+
12+
group :spec do
13+
gem 'bacon-expect'
14+
end
15+

Gemfile.lock

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
CFPropertyList (2.3.5)
5+
activesupport (4.2.9)
6+
i18n (~> 0.7)
7+
minitest (~> 5.1)
8+
thread_safe (~> 0.3, >= 0.3.4)
9+
tzinfo (~> 1.1)
10+
bacon-expect (1.0.3)
11+
bubble-wrap (1.9.6)
12+
claide (1.0.2)
13+
cocoapods (1.3.1)
14+
activesupport (>= 4.0.2, < 5)
15+
claide (>= 1.0.2, < 2.0)
16+
cocoapods-core (= 1.3.1)
17+
cocoapods-deintegrate (>= 1.0.1, < 2.0)
18+
cocoapods-downloader (>= 1.1.3, < 2.0)
19+
cocoapods-plugins (>= 1.0.0, < 2.0)
20+
cocoapods-search (>= 1.0.0, < 2.0)
21+
cocoapods-stats (>= 1.0.0, < 2.0)
22+
cocoapods-trunk (>= 1.2.0, < 2.0)
23+
cocoapods-try (>= 1.1.0, < 2.0)
24+
colored2 (~> 3.1)
25+
escape (~> 0.0.4)
26+
fourflusher (~> 2.0.1)
27+
gh_inspector (~> 1.0)
28+
molinillo (~> 0.5.7)
29+
nap (~> 1.0)
30+
ruby-macho (~> 1.1)
31+
xcodeproj (>= 1.5.1, < 2.0)
32+
cocoapods-core (1.3.1)
33+
activesupport (>= 4.0.2, < 6)
34+
fuzzy_match (~> 2.0.4)
35+
nap (~> 1.0)
36+
cocoapods-deintegrate (1.0.1)
37+
cocoapods-downloader (1.1.3)
38+
cocoapods-plugins (1.0.0)
39+
nap
40+
cocoapods-search (1.0.0)
41+
cocoapods-stats (1.0.0)
42+
cocoapods-trunk (1.2.0)
43+
nap (>= 0.8, < 2.0)
44+
netrc (= 0.7.8)
45+
cocoapods-try (1.1.0)
46+
colored2 (3.1.2)
47+
dbt (1.2.0)
48+
escape (0.0.4)
49+
fourflusher (2.0.1)
50+
fuzzy_match (2.0.4)
51+
gh_inspector (1.0.3)
52+
i18n (0.8.6)
53+
minitest (5.10.3)
54+
molinillo (0.5.7)
55+
motion-cocoapods (1.9.0)
56+
cocoapods (>= 1.0.0)
57+
motion-kit (1.1.1)
58+
dbt (~> 1.1, >= 1.1.5)
59+
motion_print (1.2.0)
60+
nanaimo (0.2.3)
61+
nap (1.1.0)
62+
netrc (0.7.8)
63+
rake (12.0.0)
64+
ruby-macho (1.1.0)
65+
sugarcube (3.4.0)
66+
thread_safe (0.3.6)
67+
tzinfo (1.2.3)
68+
thread_safe (~> 0.1)
69+
xcodeproj (1.5.1)
70+
CFPropertyList (~> 2.3.3)
71+
claide (>= 1.0.2, < 2.0)
72+
colored2 (~> 3.1)
73+
nanaimo (~> 0.2.3)
74+
75+
PLATFORMS
76+
ruby
77+
78+
DEPENDENCIES
79+
bacon-expect
80+
bubble-wrap (~> 1.9)
81+
motion-cocoapods (~> 1.8)
82+
motion-kit (~> 1.1)
83+
motion_print (~> 1.2.0)
84+
rake
85+
sugarcube (~> 3.4)
86+
87+
BUNDLED WITH
88+
1.14.6

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright 2017 digitalMoksha LLC
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## Drag and Drop Tester for macOS
2+
3+
Simple macOS app that allows you to drag and drop anything and inspect the pasteboard types. It was written using [RubyMotion](http://www.rubymotion.com).
4+
5+
### Installation
6+
7+
A built application can be found in the `bin` folder. If you have RubyMotion installed, then you can change to the folder and run `rake` from the command line.
8+
9+
### Using the program
10+
11+
After starting the app, drag anything (a webpage image, text, etc) into the drop rectangle. You will
12+
then be shown the Pasteboard types for that object.
13+
14+
For example, dragging the address bar link `https://www.apple.com` from Safari will generate
15+
the following output:
16+
17+
```
18+
https://www.apple.com/
19+
PB type: dyn.ah62d4rv4gu8yc6durvwwa3xmrvw1gkdusm1044pxqyuha2pxsvw0e55bsmwca7d3sbwu
20+
properties: ["webloc"]
21+
PB type: Apple files promise pasteboard type
22+
properties: ["webloc"]
23+
PB type: com.apple.Safari.bookmarkDictionaryList
24+
properties: [{"URIDictionary"=>{"title"=>"Apple"}, "WebBookmarkType"=>"WebBookmarkTypeLeaf", "WebBookmarkUUID"=>"3BE0B2B3-5574-4885-B4A5-2062C2D4E3EE", "URLString"=>"https://www.apple.com/"}]
25+
PB type: com.apple.Safari.bookmarkStatistics
26+
properties: {"TotalCount"=>1, "FolderCount"=>0}
27+
PB type: dyn.ah62d4rv4gu8zs3pcnzme2641rf4guzdmsv0gn64uqm10c6xenv61a3k
28+
properties: [["https://www.apple.com/"], ["Apple"]]
29+
PB type: WebURLsWithTitlesPboardType
30+
properties: [["https://www.apple.com/"], ["Apple"]]
31+
PB type: public.url
32+
properties: https://www.apple.com/
33+
PB type: CorePasteboardFlavorType 0x75726C20
34+
properties: https://www.apple.com/
35+
PB type: dyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw0e55bsmwca7d3sbwu
36+
properties: ["https://www.apple.com/", ""]
37+
PB type: Apple URL pasteboard type
38+
properties: ["https://www.apple.com/", ""]
39+
PB type: public.utf8-plain-text
40+
properties: https://www.apple.com/
41+
PB type: NSStringPboardType
42+
properties: https://www.apple.com/
43+
PB type: public.url-name
44+
properties: Apple
45+
PB type: CorePasteboardFlavorType 0x75726C6E
46+
properties: Apple
47+
PB type: com.apple.pasteboard.promised-file-content-type
48+
properties: com.apple.web-internet-location
49+
PB type: com.apple.pasteboard.promised-file-url
50+
properties:
51+
PB type: dyn.ah62d4rv4gu8y6y4usm1044pxqzb085xyqz1hk64uqm10c6xenv61a3k
52+
properties:
53+
PB type: NSPromiseContentsPboardType
54+
properties:
55+
```

Rakefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
$:.unshift("/Library/RubyMotion/lib")
3+
require 'motion/project/template/osx'
4+
5+
begin
6+
require 'bundler'
7+
Bundler.require
8+
rescue LoadError
9+
end
10+
11+
require 'sugarcube-repl'
12+
13+
Motion::Project::App.setup do |app|
14+
# Use `rake config' to see complete project settings.
15+
app.name = 'dragdrop-tester'
16+
app.identifier = 'com.digitalmoksha.dragdrop-tester'
17+
app.copyright = "Copyright © 2017 digitalMoksha LLC\nAll Rights Reserved"
18+
app.short_version = '0.1' # CFBundleShortVersionString
19+
app.version = `git rev-list --all | wc -l`.strip.to_i.to_s # the build number
20+
app.sdk_version = '10.12'
21+
app.deployment_target = '10.10'
22+
end

app/app_delegate.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# App for testing different drag/drop scenarios and the information available.
2+
#------------------------------------------------------------------------------
3+
class AppDelegate
4+
#------------------------------------------------------------------------------
5+
def applicationDidFinishLaunching(notification)
6+
buildMenu
7+
buildWindow
8+
end
9+
10+
#------------------------------------------------------------------------------
11+
def buildWindow
12+
@window_controller = WindowController.alloc.init
13+
@window_controller.showWindow(self)
14+
@window_controller.window.orderFrontRegardless
15+
end
16+
end

app/destination_view.rb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Parts based on the tutorial
2+
# https://www.raywenderlich.com/136272/drag-and-drop-tutorial-for-macos
3+
#------------------------------------------------------------------------------
4+
class DestinationView < NSView
5+
6+
attr_accessor :delegate
7+
8+
#------------------------------------------------------------------------------
9+
def initialize_dragging
10+
registerForDraggedTypes([KUTTypeItem])
11+
@isReceivingDrag = false
12+
end
13+
14+
#------------------------------------------------------------------------------
15+
def shouldAllowDrag(draggingInfo) # NSDraggingInfo
16+
canAccept = false
17+
pasteBoard = draggingInfo.draggingPasteboard
18+
# if pasteBoard.canReadObjectForClasses([NSURL], options: {})
19+
canAccept = true
20+
# end
21+
return canAccept
22+
end
23+
24+
#------------------------------------------------------------------------------
25+
def draggingEntered(sender) # NSDraggingInfo -> NSDragOperation
26+
allow = shouldAllowDrag(sender)
27+
@isReceivingDrag = allow
28+
self.needsDisplay = true
29+
return allow ? NSDragOperationGeneric : NSDragOperationNone
30+
end
31+
32+
#------------------------------------------------------------------------------
33+
def draggingExited(sender)
34+
@isReceivingDrag = false
35+
self.needsDisplay = true
36+
end
37+
38+
#------------------------------------------------------------------------------
39+
def draggingEnded(sender)
40+
@isReceivingDrag = false
41+
self.needsDisplay = true
42+
end
43+
44+
#------------------------------------------------------------------------------
45+
def prepareForDragOperation(draggingInfo)
46+
return shouldAllowDrag(draggingInfo)
47+
end
48+
49+
#------------------------------------------------------------------------------
50+
def performDragOperation(draggingInfo)
51+
@isReceivingDrag = false
52+
53+
point = convertPoint(draggingInfo.draggingLocation, fromView: nil)
54+
pasteboard = draggingInfo.draggingPasteboard
55+
56+
urls = pasteboard.readObjectsForClasses([NSURL, ], options: {})
57+
urls.each {|x| @delegate.log_msg x.isFileReferenceURL ? x.path : x.absoluteString}
58+
59+
pasteboard.types.each do |type|
60+
@delegate.log_msg " PB type: #{type}"
61+
@delegate.log_msg " properties: #{pasteboard.propertyListForType(type)}"
62+
end
63+
@delegate.log_msg "------------------------------------------------------"
64+
return true
65+
end
66+
67+
#------------------------------------------------------------------------------
68+
def concludeDragOperation(draggingInfo)
69+
end
70+
71+
#------------------------------------------------------------------------------
72+
def drawRect(dirtyRect) # NSRect
73+
@isReceivingDrag ? NSColor.selectedControlColor.set : NSColor.secondaryLabelColor.set
74+
path = NSBezierPath.bezierPathWithRect(self.bounds)
75+
path.lineWidth = 1
76+
path.stroke
77+
end
78+
end

app/main_controller.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class MainController < NSViewController
2+
3+
#------------------------------------------------------------------------------
4+
def loadView
5+
@layout = MainLayout.new
6+
self.view = @layout.view
7+
8+
@destination_view = @layout.get(:destination_view)
9+
@destination_view.delegate = self
10+
@destination_view.initialize_dragging
11+
12+
@log_field = @layout.get(:log_field)
13+
end
14+
15+
#------------------------------------------------------------------------------
16+
def log_msg(msg)
17+
@log_field.setSelectedRange(NSMakeRange(@log_field.string.length, 0))
18+
@log_field.insertText("#{msg}\n")
19+
@log_field.setSelectedRange(NSMakeRange(@log_field.string.length, 0))
20+
end
21+
22+
end

0 commit comments

Comments
 (0)