Skip to content

Commit

Permalink
提供一个直接界面预览的能力。
Browse files Browse the repository at this point in the history
  • Loading branch information
bugluo committed Sep 17, 2017
1 parent 761303d commit 8560823
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
7 changes: 5 additions & 2 deletions WeSketch.sketchplugin/Contents/Sketch/commonPreviewJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@import "commonPreview.js";


var commonPreviewJson = function (context, filePath) {
var commonPreviewJson = function (context, filePath, show) {
var i18 = _(context).commonPreview;

var BorderPositions = ["center", "inside", "outside"],
Expand Down Expand Up @@ -201,8 +201,11 @@ var commonPreviewJson = function (context, filePath) {
settingsWindow.addAccessoryView(fx);
return settingsWindow.runModal();
}
if (chooseDialog() != '1000') {
if (show || chooseDialog() != '1000') {
fxstyle = 'default';
if(show){
fxlocal = '20';
}
} else {
fx = fx.selectedCell();
var index = [fx tag];
Expand Down
9 changes: 9 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
"shortcut": "",
"handler" : "hidePreview"
},
{
"name" : "Show Preview",
"identifier" : "showPreview",
"script" : "showPreview.js",
"shortcut": "",
"istool":"",
"handler" : "onRun"
},
{
"name" : "Local Preview",
"identifier" : "localPreview",
Expand Down Expand Up @@ -363,6 +371,7 @@
"setNoBuild",
"previewClear",
"previewHide",
"showPreview",
"localPreview",
"webPreview",
"-",
Expand Down
68 changes: 68 additions & 0 deletions WeSketch.sketchplugin/Contents/Sketch/showPreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@import "common.js"
@import "link.js"
@import "commonPreviewJson.js"

function showPreview(context) {
var i18 = _(context).webPreview;
context.document.showMessage(i18.m5);

function chooseFilePath() {
var save = NSSavePanel.savePanel();
save.setAllowsOtherFileTypes(true);
save.setExtensionHidden(false);
return save.URL().path() + '/' + (Math.random());
}
var filePath = chooseFilePath();
var flag = commonPreviewJson(context, filePath, true);
if (!flag) {
return;
}
var fx;
var width = 414;
var height = 716;
function chooseDialog() {
var settingsWindow = COSAlertWindow.new();
settingsWindow.addButtonWithTitle('确定');
settingsWindow.addButtonWithTitle('取消');

settingsWindow.setMessageText('请选择预览尺寸');

var ButtonList = ['iPhone 6P', 'iPhone 6'];

fx = createRadioButtons(ButtonList, 0);
settingsWindow.addAccessoryView(fx);
return settingsWindow.runModal();
}
if(chooseDialog() == '1000'){
fx = fx.selectedCell();
var index = [fx tag];
if (index == 1) {
width = 375;
height = 647;
}


var pluginSketch = context.plugin.url().URLByAppendingPathComponent("Contents").URLByAppendingPathComponent("Sketch").URLByAppendingPathComponent("library").path();
SMPanel({
url: filePath+'/index.html',
width: width,
height: height,
hiddenClose: false,
floatWindow: false,
identifier: "preview",
callback: function (data) {
},
closeCallback: function () {
var fm = [NSFileManager defaultManager];
fm.removeItemAtPath_error(filePath, nil);
}
});
}
var ga = new Analytics(context);
if (ga) ga.sendEvent('showPreview', 'preview');

}

var onRun = function (context) {
showPreview(context);
}

0 comments on commit 8560823

Please sign in to comment.