@smartface/smartface.openfile
Version:
73 lines (63 loc) • 2.42 kB
JavaScript
define(function(require, exports, module) {
main.consumes = [
"Plugin", "fs", "tabManager", "panels", "commands", "smf.dispatcher",
"smartface.plugin-loader"
];
main.provides = ["smartface.openfile"];
return main;
function main(options, imports, register) {
var Plugin = imports.Plugin;
var plugin = new Plugin("Smartface", main.consumes);
var fs = imports.fs;
var tabManager = imports.tabManager;
var panels = imports.panels;
var commands = imports.commands;
var loaded = false;
var dispatcher = imports["smf.dispatcher"];
var pluginLoader = imports["smartface.plugin-loader"];
plugin.on("load", function() {
if (loaded) return;
loaded = true;
pluginLoader.on("editorLoad", openFile);
});
plugin.on("unload", function() {
plugin = null;
loaded = false;
});
function openFile() {
tabManager.once("ready", function() {
if (window.location.hash.match(/#openfile-(.*)/)) {
var file = "/" + RegExp.$1;
fs.exists(file, function(exists) {
if (!exists) return;
if (/\.pgx/.test(file))
initUIEditorPanels();
dispatcher.ready(function() {
tabManager.open({
path: file,
focus: true,
active: true,
pane: tabManager.getPanes()[0],
},
function(err, page) {
if (err) return console.error(err);
});
});
});
}
});
}
function initUIEditorPanels() {
var bottomPane = tabManager.getPanes()[1];
if (bottomPane) {
commands.exec("toggleconsole");
}
panels.activate("smartface.ui-editor.properties");
panels.activate("smartface.ui-editor.ui-editor-panel");
}
plugin.freezePublicAPI({});
register(null, {
"smartface.openfile": plugin
});
}
});