Skip to content

Commit 6952abf

Browse files
author
Jason Burns
committed
Found instances now display image of the instance, page where the
instance reside, and instance name.
1 parent 41f13a4 commit 6952abf

File tree

8 files changed

+94
-54
lines changed

8 files changed

+94
-54
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# Symbol Instance Locator
1+
![Symbol Instance Locator](https://raw.githubusercontent.com/sonburn/symbol-instance-locator/master/logo.png)
22

33
Locate all instances of a selected symbol or instance. Select an instance in the list of results to jump to it's location.
44

5+
![Symbol Instance Locator](https://raw.githubusercontent.com/sonburn/symbol-instance-locator/master/Screenshots/Symbol%20Instance%20Locator.png)
6+
57
<a href="http://bit.ly/SketchRunnerWebsite">
68
<img width="160" height="41" src="http://bit.ly/RunnerBadgeBlue" alt="runner-badge-blue">
79
</a>
@@ -37,6 +39,7 @@ To find your plugins directory...
3739

3840
# Changelog
3941

42+
* **1.0** - Found instances now display image of the instance, page where the instance reside, and instance name.
4043
* **0.3** - Converted list of instances to NSButtons, which when selected, will now navigate user to location of instance.
4144
* **0.2** - Added appcast plugin support for Sketch 45 and later. Significantly improved processing time, and presentation of results.
4245
* **0.1** - Initial commit. Functional, but rudimentary and will be improved upon.
59.9 KB
Loading
1.39 KB
Loading
13.2 KB
Loading

Symbol Instance Locator.sketchplugin/Contents/Sketch/manifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"name" : "Symbol Instance Locator",
66
"shortcut": "cmd option shift l",
77
"identifier" : "instanceLocator",
8+
"description" : "Locate instances of the selected symbol or instance.",
89
"script" : "script.cocoascript",
10+
"icon" : "icon-sr.png"
911
}
1012
],
1113
"menu" : {
@@ -16,7 +18,7 @@
1618
"isRoot" : true
1719
},
1820
"identifier" : "com.sonburn.sketchplugins.symbol-instance-locator",
19-
"version" : "0.3",
21+
"version" : "1.0",
2022
"description" : "Locate all instances of a selected symbol or instance.",
2123
"authorEmail" : "[email protected]",
2224
"name" : "Symbol Instance Locator",

Symbol Instance Locator.sketchplugin/Contents/Sketch/script.cocoascript

Lines changed: 84 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ var onRun = function(context) {
2525

2626
if (symbolInstances.length > 0) {
2727
var alertWindow = COSAlertWindow.new();
28+
29+
alertWindow.setIcon(NSImage.alloc().initByReferencingFile(context.plugin.urlForResourceNamed("icon.png").path()));
2830
alertWindow.setMessageText(strPluginName);
2931

3032
alertWindow.addTextLabelWithValue(symbolMaster.name() + " has " + symbolInstances.length + " instance(s).");
3133

3234
alertWindow.addTextLabelWithValue("Select an instance to navigate to it's location.");
3335

34-
var instanceItemHeight = 24,
36+
var instanceItemHeight = 60,
37+
instanceItemWidth = 286,
3538
instanceFrameHeight = instanceItemHeight * (symbolInstances.length),
36-
instanceFrame = NSScrollView.alloc().initWithFrame(NSMakeRect(0,0,300,200)),
39+
instanceFrame = NSScrollView.alloc().initWithFrame(NSMakeRect(0,0,300,300)),
3740
instanceFrameSize = instanceFrame.contentSize(),
3841
instanceFrameInner = NSView.alloc().initWithFrame(NSMakeRect(0,0,instanceFrameSize.width,instanceFrameHeight)),
3942
count = 0;
@@ -43,7 +46,7 @@ var onRun = function(context) {
4346
instanceFrame.setDocumentView(instanceFrameInner);
4447

4548
for (var i = 0; i < symbolInstances.length; i++) {
46-
instanceFrameInner.addSubview(createbutton(context,symbolInstances[i],NSMakeRect(0,instanceItemHeight*count,284,instanceItemHeight)));
49+
instanceFrameInner.addSubview(createbutton(context,symbolInstances[i],NSMakeRect(0,instanceItemHeight*count,instanceItemWidth,instanceItemHeight)));
4750
count++;
4851
}
4952

@@ -62,33 +65,86 @@ var onRun = function(context) {
6265
}
6366
}
6467

65-
function getInstancePath(layer,path) {
66-
var parentPath = (!path) ? layer.name() : path,
67-
parentGroup = layer.parentGroup(),
68-
separator = "/";
69-
70-
if (parentGroup) {
71-
parentPath = parentGroup.name() + separator + parentPath;
72-
73-
if (parentGroup.parentGroup()) {
74-
parentPath = getInstancePath(parentGroup,parentPath);
75-
}
76-
}
77-
78-
return parentPath;
79-
}
80-
8168
function displayDialog(message,title) {
8269
NSApplication.sharedApplication().displayDialog_withTitle(message,title);
8370
}
8471

8572
function createbutton(context,instance,frame) {
86-
var button = NSButton.alloc().initWithFrame(frame);
87-
button.setTitle(getInstancePath(instance));
88-
button.setAlignment(NSLeftTextAlignment);
89-
button.setBordered(0);
90-
button.setAction("callAction:");
91-
button.setCOSJSTargetFunction(function(sender) {
73+
var rightColWidth = 120,
74+
leftColWidth = frame.size.width-rightColWidth,
75+
colPad = 4;
76+
77+
var view = NSView.alloc().initWithFrame(frame);
78+
view.setFlipped(1);
79+
80+
var pageLabel = NSTextField.alloc().initWithFrame(NSMakeRect(colPad,2,leftColWidth,14));
81+
pageLabel.setStringValue("Page Name");
82+
pageLabel.setFont(NSFont.boldSystemFontOfSize(10));
83+
pageLabel.setTextColor(NSColor.colorWithCalibratedRed_green_blue_alpha(0/255,0/255,0/255,0.4));
84+
pageLabel.setBezeled(0);
85+
pageLabel.setEditable(0);
86+
view.addSubview(pageLabel);
87+
88+
var pageText = NSTextField.alloc().initWithFrame(NSMakeRect(colPad,15,leftColWidth,18));
89+
pageText.setStringValue(instance.parentPage().name());
90+
pageText.setFont(NSFont.systemFontOfSize(11));
91+
pageText.setBezeled(0);
92+
pageText.setEditable(0);
93+
view.addSubview(pageText);
94+
95+
var nameLabel = NSTextField.alloc().initWithFrame(NSMakeRect(colPad,29,leftColWidth,14));
96+
nameLabel.setStringValue("Instance Name");
97+
nameLabel.setFont(NSFont.boldSystemFontOfSize(10));
98+
nameLabel.setTextColor(NSColor.colorWithCalibratedRed_green_blue_alpha(0/255,0/255,0/255,0.4));
99+
nameLabel.setBezeled(0);
100+
nameLabel.setEditable(0);
101+
view.addSubview(nameLabel);
102+
103+
var nameText = NSTextField.alloc().initWithFrame(NSMakeRect(colPad,42,leftColWidth,18));
104+
nameText.setStringValue(instance.name());
105+
nameText.setFont(NSFont.systemFontOfSize(11));
106+
nameText.setBezeled(0);
107+
nameText.setEditable(0);
108+
view.addSubview(nameText);
109+
110+
var imageArea = NSButton.alloc().initWithFrame(NSMakeRect(leftColWidth,0,rightColWidth,60));
111+
imageArea.setTitle("");
112+
imageArea.setBordered(0);
113+
imageArea.setWantsLayer(1);
114+
imageArea.layer().setBackgroundColor(CGColorCreateGenericRGB(241/255,241/255,241/255,1.0));
115+
view.addSubview(imageArea);
116+
117+
var exportRequest = MSExportRequest.exportRequestsFromExportableLayer_inRect_useIDForName_(
118+
instance,
119+
instance.absoluteInfluenceRect(),
120+
false
121+
).firstObject();
122+
123+
exportRequest.format = "png";
124+
125+
var scaleX = (rightColWidth-colPad*2) / exportRequest.rect().size.width;
126+
var scaleY = (60-colPad*2) / exportRequest.rect().size.height;
127+
128+
exportRequest.scale = (scaleX < scaleY) ? scaleX : scaleY;
129+
130+
var colorSpace = NSColorSpace.sRGBColorSpace(),
131+
exporter = MSExporter.exporterForRequest_colorSpace_(exportRequest,colorSpace),
132+
imageRep = exporter.bitmapImageRep(),
133+
instanceImage = NSImage.alloc().init().autorelease();
134+
135+
instanceImage.addRepresentation(imageRep);
136+
137+
imageArea.setImage(instanceImage);
138+
139+
var line = NSView.alloc().initWithFrame(NSMakeRect(0,59,286,1));
140+
line.setWantsLayer(1);
141+
line.layer().setBackgroundColor(CGColorCreateGenericRGB(204/255,204/255,204/255,1.0));
142+
view.addSubview(line);
143+
144+
var hitbox = NSButton.alloc().initWithFrame(NSMakeRect(0,0,frame.size.width,frame.size.height));
145+
hitbox.setTransparent(1);
146+
hitbox.setAction("callAction:");
147+
hitbox.setCOSJSTargetFunction(function(sender) {
92148
NSApp.stopModalWithCode(NSOKButton);
93149

94150
var rect = (instance.parentArtboard()) ? instance.parentArtboard().rect() : instance.absoluteRect().rect();
@@ -99,28 +155,7 @@ function createbutton(context,instance,frame) {
99155
instance.select_byExpandingSelection(true,false);
100156
});
101157

102-
// var exportRequest = MSExportRequest.exportRequestsFromExportableLayer_inRect_useIDForName_(
103-
// instance,
104-
// instance.absoluteInfluenceRect(),
105-
// false
106-
// ).firstObject();
107-
//
108-
// exportRequest.format = "png";
109-
//
110-
// var scaleX = 150 / exportRequest.rect().size.width;
111-
// var scaleY = 40 / exportRequest.rect().size.height;
112-
//
113-
// exportRequest.scale = (scaleX < scaleY) ? scaleX : scaleY;
114-
//
115-
// var colorSpace = NSColorSpace.sRGBColorSpace(),
116-
// exporter = MSExporter.exporterForRequest_colorSpace_(exportRequest,colorSpace),
117-
// imageRep = exporter.bitmapImageRep(),
118-
// instanceImage = NSImage.alloc().init().autorelease();
119-
//
120-
// instanceImage.addRepresentation(imageRep);
121-
//
122-
// button.setImage(instanceImage);
123-
// button.setImagePosition(NSImageRight);
124-
125-
return button;
158+
view.addSubview(hitbox);
159+
160+
return view;
126161
}

appcast.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
<description>Locate all instances of a selected symbol or instance.</description>
77
<language>en</language>
88
<item>
9-
<title>Version 0.3</title>
9+
<title>Version 1.0</title>
1010
<description>
1111
<![CDATA[
1212
<ul>
13-
<li>Converted list of instances to NSButtons, which when selected, will now navigate user to location of instance.</li>
13+
<li>Found instances now display image of the instance, page where the instance reside, and instance name.</li>
1414
</ul>
1515
]]>
1616
</description>
17-
<enclosure url="https://github.com/sonburn/symbol-instance-locator/archive/master.zip" sparkle:version="0.3" />
17+
<enclosure url="https://github.com/sonburn/symbol-instance-locator/archive/master.zip" sparkle:version="1.0" />
1818
</item>
1919
</channel>
2020
</rss>

logo.png

11.7 KB
Loading

0 commit comments

Comments
 (0)