Skip to content

Commit 853ad4a

Browse files
author
Jason Burns
committed
Code optimizations and dialog frame will now be smaller if a small set
of results are returned.
1 parent 6952abf commit 853ad4a

File tree

4 files changed

+77
-66
lines changed

4 files changed

+77
-66
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ To find your plugins directory...
3939

4040
# Changelog
4141

42+
* **1.1** - Code optimizations and dialog frame will now be smaller if a small set of results are returned.
4243
* **1.0** - Found instances now display image of the instance, page where the instance reside, and instance name.
4344
* **0.3** - Converted list of instances to NSButtons, which when selected, will now navigate user to location of instance.
4445
* **0.2** - Added appcast plugin support for Sketch 45 and later. Significantly improved processing time, and presentation of results.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"isRoot" : true
1919
},
2020
"identifier" : "com.sonburn.sketchplugins.symbol-instance-locator",
21-
"version" : "1.0",
21+
"version" : "1.1",
2222
"description" : "Locate all instances of a selected symbol or instance.",
2323
"authorEmail" : "[email protected]",
2424
"name" : "Symbol Instance Locator",

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

Lines changed: 72 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ var onRun = function(context) {
3535

3636
var instanceItemHeight = 60,
3737
instanceItemWidth = 286,
38-
instanceFrameHeight = instanceItemHeight * (symbolInstances.length),
39-
instanceFrame = NSScrollView.alloc().initWithFrame(NSMakeRect(0,0,300,300)),
38+
instanceFrameInnerHeight = instanceItemHeight * (symbolInstances.length),
39+
instanceFrameMaxHeight = 300,
40+
instanceFrameHeight = (instanceFrameInnerHeight < instanceFrameMaxHeight) ? instanceFrameInnerHeight : instanceFrameMaxHeight,
41+
instanceFrame = NSScrollView.alloc().initWithFrame(NSMakeRect(0,0,300,instanceFrameHeight)),
4042
instanceFrameSize = instanceFrame.contentSize(),
41-
instanceFrameInner = NSView.alloc().initWithFrame(NSMakeRect(0,0,instanceFrameSize.width,instanceFrameHeight)),
43+
instanceFrameInner = NSView.alloc().initWithFrame(NSMakeRect(0,0,instanceFrameSize.width,instanceFrameInnerHeight)),
4244
count = 0;
4345

44-
instanceFrame.setHasVerticalScroller(true);
4546
instanceFrameInner.setFlipped(true);
47+
instanceFrame.setHasVerticalScroller(true);
4648
instanceFrame.setDocumentView(instanceFrameInner);
4749

4850
for (var i = 0; i < symbolInstances.length; i++) {
49-
instanceFrameInner.addSubview(createbutton(context,symbolInstances[i],NSMakeRect(0,instanceItemHeight*count,instanceItemWidth,instanceItemHeight)));
51+
instanceFrameInner.addSubview(createListItem(symbolInstances[i],NSMakeRect(0,instanceItemHeight*count,instanceItemWidth,instanceItemHeight)));
5052
count++;
5153
}
5254

53-
instanceFrameInner.scrollPoint(NSMakePoint(0,0));
54-
5555
alertWindow.addAccessoryView(instanceFrame);
5656

5757
alertWindow.addButtonWithTitle("Close");
@@ -69,50 +69,62 @@ function displayDialog(message,title) {
6969
NSApplication.sharedApplication().displayDialog_withTitle(message,title);
7070
}
7171

72-
function createbutton(context,instance,frame) {
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));
72+
function createListItem(instance,frame) {
73+
var listItem = NSView.alloc().initWithFrame(frame),
74+
rightColWidth = 120,
75+
leftColWidth = frame.size.width-rightColWidth;
76+
77+
listItem.setFlipped(1);
78+
listItem.addSubview(createTextLabel("Page Name",NSMakeRect(4,2,leftColWidth,14)));
79+
listItem.addSubview(createTextField(instance.parentPage().name(),NSMakeRect(4,15,leftColWidth,18)));
80+
listItem.addSubview(createTextLabel("Instance Name",NSMakeRect(4,29,leftColWidth,14)));
81+
listItem.addSubview(createTextField(instance.name(),NSMakeRect(4,42,leftColWidth,18)));
82+
listItem.addSubview(createImageArea(instance,NSMakeRect(leftColWidth,0,rightColWidth,frame.size.height)));
83+
listItem.addSubview(createDivider(NSMakeRect(0,59,frame.size.width,1)));
84+
listItem.addSubview(createTargetArea(instance,NSMakeRect(0,0,frame.size.width,frame.size.height)));
85+
86+
return listItem;
87+
}
88+
89+
function createTextLabel(string,frame) {
90+
var textLabel = NSTextField.alloc().initWithFrame(frame);
91+
92+
textLabel.setStringValue(string);
93+
textLabel.setFont(NSFont.boldSystemFontOfSize(10));
94+
textLabel.setTextColor(NSColor.colorWithCalibratedRed_green_blue_alpha(0/255,0/255,0/255,0.4));
95+
textLabel.setBezeled(0);
96+
textLabel.setEditable(0);
97+
98+
return textLabel;
99+
}
100+
101+
function createTextField(string,frame) {
102+
var textField = NSTextField.alloc().initWithFrame(frame);
103+
104+
textField.setStringValue(string);
105+
textField.setFont(NSFont.systemFontOfSize(11));
106+
textField.setBezeled(0);
107+
textField.setEditable(0);
108+
109+
return textField;
110+
}
111+
112+
function createDivider(frame) {
113+
var divider = NSView.alloc().initWithFrame(frame);
114+
115+
divider.setWantsLayer(1);
116+
divider.layer().setBackgroundColor(CGColorCreateGenericRGB(204/255,204/255,204/255,1.0));
117+
118+
return divider;
119+
}
120+
121+
function createImageArea(instance,frame) {
122+
var imageArea = NSButton.alloc().initWithFrame(frame);
123+
111124
imageArea.setTitle("");
112125
imageArea.setBordered(0);
113126
imageArea.setWantsLayer(1);
114127
imageArea.layer().setBackgroundColor(CGColorCreateGenericRGB(241/255,241/255,241/255,1.0));
115-
view.addSubview(imageArea);
116128

117129
var exportRequest = MSExportRequest.exportRequestsFromExportableLayer_inRect_useIDForName_(
118130
instance,
@@ -122,8 +134,8 @@ function createbutton(context,instance,frame) {
122134

123135
exportRequest.format = "png";
124136

125-
var scaleX = (rightColWidth-colPad*2) / exportRequest.rect().size.width;
126-
var scaleY = (60-colPad*2) / exportRequest.rect().size.height;
137+
var scaleX = (frame.size.width-4*2) / exportRequest.rect().size.width;
138+
var scaleY = (frame.size.height-4*2) / exportRequest.rect().size.height;
127139

128140
exportRequest.scale = (scaleX < scaleY) ? scaleX : scaleY;
129141

@@ -136,26 +148,24 @@ function createbutton(context,instance,frame) {
136148

137149
imageArea.setImage(instanceImage);
138150

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);
151+
return imageArea;
152+
}
143153

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) {
154+
function createTargetArea(instance,frame) {
155+
var targetArea = NSButton.alloc().initWithFrame(frame);
156+
157+
targetArea.setTransparent(1);
158+
targetArea.setAction("callAction:");
159+
targetArea.setCOSJSTargetFunction(function(sender) {
148160
NSApp.stopModalWithCode(NSOKButton);
149161

150162
var rect = (instance.parentArtboard()) ? instance.parentArtboard().rect() : instance.absoluteRect().rect();
151163

152-
context.document.setCurrentPage(instance.parentPage());
153-
context.document.currentView().zoomToFitRect(rect);
164+
MSDocument.currentDocument().setCurrentPage(instance.parentPage());
165+
MSDocument.currentDocument().currentView().zoomToFitRect(rect);
154166

155167
instance.select_byExpandingSelection(true,false);
156168
});
157169

158-
view.addSubview(hitbox);
159-
160-
return view;
170+
return targetArea;
161171
}

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 1.0</title>
9+
<title>Version 1.1</title>
1010
<description>
1111
<![CDATA[
1212
<ul>
13-
<li>Found instances now display image of the instance, page where the instance reside, and instance name.</li>
13+
<li>Code optimizations and dialog frame will now be smaller if a small set of results are returned.</li>
1414
</ul>
1515
]]>
1616
</description>
17-
<enclosure url="https://github.com/sonburn/symbol-instance-locator/archive/master.zip" sparkle:version="1.0" />
17+
<enclosure url="https://github.com/sonburn/symbol-instance-locator/archive/master.zip" sparkle:version="1.1" />
1818
</item>
1919
</channel>
2020
</rss>

0 commit comments

Comments
 (0)