aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/filesystem.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/system/filesystem.js')
-rwxr-xr-x[-rw-r--r--]js/io/system/filesystem.js78
1 files changed, 35 insertions, 43 deletions
diff --git a/js/io/system/filesystem.js b/js/io/system/filesystem.js
index 54c16a05..cd158812 100644..100755
--- a/js/io/system/filesystem.js
+++ b/js/io/system/filesystem.js
@@ -4,31 +4,23 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7var FileIo = require("js/io/system/fileio").FileIo, 7////////////////////////////////////////////////////////////////////////
8 ProjectIo = require("js/io/system/projectio").ProjectIo, 8//
9 ShellApi = require("js/io/system/shellapi").ShellApi, 9var Montage = require("montage/core/core").Montage,
10 ComponentsPanelBase = require("js/panels/Components/ComponentsPanelBase.reel").ComponentsPanelBase; 10 FileIo = require("js/io/system/fileio").FileIo,
11 ProjectIo = require("js/io/system/projectio").ProjectIo,
12 CoreIoApi = require("js/io/system/coreioapi").CoreIoApi;
11//////////////////////////////////////////////////////////////////////// 13////////////////////////////////////////////////////////////////////////
12//Exporting as File System 14//Exporting as File System
13exports.FileSystem = (require("montage/core/core").Montage).create(Object.prototype, { 15exports.FileSystem = Montage.create(Object.prototype, {
14 //////////////////////////////////////////////////////////////////// 16 ////////////////////////////////////////////////////////////////////
15 // 17 //
16 init: { 18
17 enumerable: false,
18 value: function () {
19 //Called by NinjaMain
20
21
22
23 //Calling Shell API to initialize
24 ShellApi.init();
25 }
26 },
27 19
28 shellApiHandler :{ 20 shellApiHandler :{
29 enumerable:true, 21 enumerable:true,
30 writable:false, 22 writable:false,
31 value:ShellApi 23 value:CoreIoApi
32 }, 24 },
33 25
34 26
@@ -78,8 +70,8 @@ exports.FileSystem = (require("montage/core/core").Montage).create(Object.protot
78 //documentManagerModule.DocumentManager.openDocument({"type": "html"}); 70 //documentManagerModule.DocumentManager.openDocument({"type": "html"});
79 } else { 71 } else {
80 // 72 //
81 var file = {uri: ShellApi.openShellDialog({type: 'file', action: 'new'})}, type; 73 var file = {uri: CoreIoApi.openShellDialog({type: 'file', action: 'new'})}, type;
82 var check = ShellApi.fileExists(file); 74 var check = CoreIoApi.fileExists(file);
83 75
84 76
85 77
@@ -117,13 +109,13 @@ exports.FileSystem = (require("montage/core/core").Montage).create(Object.protot
117 109
118 //TODO: Improve logic 110 //TODO: Improve logic
119 //Checking for file to exist in files template folder 111 //Checking for file to exist in files template folder
120 var templateCheck = ShellApi.fileExists({uri: window.NativeShellApp.GetKnownFolder('appsource')+'\\document-templates\\files\\template.'+type}), content; 112 var templateCheck = CoreIoApi.fileExists({uri: window.NativeShellApp.GetKnownFolder('appsource')+'\\document-templates\\files\\template.'+type}), content;
121 // 113 //
122 if (templateCheck.success) { 114 if (templateCheck.success) {
123 switch (check.status) { 115 switch (check.status) {
124 case 204: 116 case 204:
125 //Template exists, so opening and getting contents to be used when creating file 117 //Template exists, so opening and getting contents to be used when creating file
126 content = ShellApi.openFile({uri: 'template.'+type}); 118 content = CoreIoApi.openFile({uri: 'template.'+type});
127 if (content.content) { 119 if (content.content) {
128 file.content = content.content; 120 file.content = content.content;
129 } else { 121 } else {
@@ -169,7 +161,7 @@ switch (type.toLowerCase()) {
169 161
170 162
171 163
172 var create = ShellApi.createFile(file); 164 var create = CoreIoApi.createFile(file);
173 if (create.success) { 165 if (create.success) {
174 switch (create.status) { 166 switch (create.status) {
175 case 201: 167 case 201:
@@ -239,8 +231,8 @@ switch (type.toLowerCase()) {
239 //documentManagerModule.DocumentManager.openDocument({"type": "html"}); 231 //documentManagerModule.DocumentManager.openDocument({"type": "html"});
240 } else { 232 } else {
241 // 233 //
242 var directory = {uri: ShellApi.openShellDialog({type: 'directory', action: 'new'})}; 234 var directory = {uri: CoreIoApi.openShellDialog({type: 'directory', action: 'new'})};
243 var check = ShellApi.directoryExists(directory); 235 var check = CoreIoApi.directoryExists(directory);
244 // 236 //
245 if (check.success) { 237 if (check.success) {
246 switch (check.status) { 238 switch (check.status) {
@@ -249,7 +241,7 @@ switch (type.toLowerCase()) {
249 break; 241 break;
250 case 404: 242 case 404:
251 //Directory does not exists, ready to be created 243 //Directory does not exists, ready to be created
252 var create = ShellApi.createDirectory(directory); 244 var create = CoreIoApi.createDirectory(directory);
253 if (create.success) { 245 if (create.success) {
254 switch (create.status) { 246 switch (create.status) {
255 case 201: 247 case 201:
@@ -294,7 +286,7 @@ switch (type.toLowerCase()) {
294 enumerable: false, 286 enumerable: false,
295 value: function (file) { 287 value: function (file) {
296 //Checking for file to exist 288 //Checking for file to exist
297 var check = ShellApi.fileExists(file), createdFile = null; 289 var check = CoreIoApi.fileExists(file), createdFile = null;
298 // 290 //
299 if (check.success) { 291 if (check.success) {
300 switch (check.status) { 292 switch (check.status) {
@@ -303,7 +295,7 @@ switch (type.toLowerCase()) {
303 break; 295 break;
304 case 404: 296 case 404:
305 //File does not exists, ready to be created 297 //File does not exists, ready to be created
306 var create = ShellApi.createFile(file); 298 var create = CoreIoApi.createFile(file);
307 if (create.success) { 299 if (create.success) {
308 switch (create.status) { 300 switch (create.status) {
309 case 201: 301 case 201:
@@ -357,7 +349,7 @@ switch (type.toLowerCase()) {
357 //TODO: Add cloud integration 349 //TODO: Add cloud integration
358 } else { 350 } else {
359 //Getting file URI from native prompt 351 //Getting file URI from native prompt
360 uri = ShellApi.openShellDialog({type: 'file', action: 'open'}); 352 uri = CoreIoApi.openShellDialog({type: 'file', action: 'open'});
361 } 353 }
362 } 354 }
363 //Checking for a valid URI 355 //Checking for a valid URI
@@ -378,7 +370,7 @@ switch (type.toLowerCase()) {
378 //Opening file via shell 370 //Opening file via shell
379 function shellOpenFile (f) { 371 function shellOpenFile (f) {
380 //Getting string from file 372 //Getting string from file
381 var doc = ShellApi.openFile({uri: f}), type = f.split('.'); 373 var doc = CoreIoApi.openFile({uri: f}), type = f.split('.');
382 //Splitting to get file extension 374 //Splitting to get file extension
383 type = type[type.length-1]; 375 type = type[type.length-1];
384 //TODO: Fix this HACK to generate string 376 //TODO: Fix this HACK to generate string
@@ -387,7 +379,7 @@ switch (type.toLowerCase()) {
387 dir_str += dir[i] + '\\'; 379 dir_str += dir[i] + '\\';
388 } 380 }
389 //Starting an instance of the shell server on directory 381 //Starting an instance of the shell server on directory
390 server = ShellApi.startServer(dir_str); 382 server = CoreIoApi.startServer(dir_str);
391 //Opening file in app 383 //Opening file in app
392 FileIo.open(doc, type, f, server); 384 FileIo.open(doc, type, f, server);
393 } 385 }
@@ -439,7 +431,7 @@ switch (type.toLowerCase()) {
439 value: function (directory) { 431 value: function (directory) {
440 var mjs_dir = {uri: directory.uri}; 432 var mjs_dir = {uri: directory.uri};
441 mjs_dir.uri += '\\m-js'; 433 mjs_dir.uri += '\\m-js';
442 var mjs_check = ShellApi.directoryExists(mjs_dir); 434 var mjs_check = CoreIoApi.directoryExists(mjs_dir);
443 // 435 //
444 if (mjs_check.success) { 436 if (mjs_check.success) {
445 switch (mjs_check.status) { 437 switch (mjs_check.status) {
@@ -455,7 +447,7 @@ switch (type.toLowerCase()) {
455 447
456 448
457 //Creating m-js folder and copying contents 449 //Creating m-js folder and copying contents
458 var mjs_folder = ShellApi.createDirectory(mjs_dir); 450 var mjs_folder = CoreIoApi.createDirectory(mjs_dir);
459 if (mjs_folder.success) { 451 if (mjs_folder.success) {
460 switch (mjs_folder.status) { 452 switch (mjs_folder.status) {
461 case 201: 453 case 201:
@@ -463,12 +455,12 @@ switch (type.toLowerCase()) {
463 455
464 456
465 var temp_dir = window.NativeShellApp.GetKnownFolder('appsource')+'\\user-document-templates\\montage-application\\systemio\\new\\project\\montage'; 457 var temp_dir = window.NativeShellApp.GetKnownFolder('appsource')+'\\user-document-templates\\montage-application\\systemio\\new\\project\\montage';
466 var mjs_deps = ShellApi.createDirectory({uri: mjs_dir.uri+'\\deps'}); 458 var mjs_deps = CoreIoApi.createDirectory({uri: mjs_dir.uri+'\\deps'});
467 459
468 //Folder created, now copying contents 460 //Folder created, now copying contents
469 var copy_lib = ShellApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('frameworksource')+'\\lib', destUri: mjs_dir.uri+'\\lib'}), 461 var copy_lib = CoreIoApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('frameworksource')+'\\lib', destUri: mjs_dir.uri+'\\lib'}),
470 copy_deps = ShellApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('frameworksource')+'\\deps\\require', destUri: mjs_dir.uri+'\\deps\\require'}), 462 copy_deps = CoreIoApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('frameworksource')+'\\deps\\require', destUri: mjs_dir.uri+'\\deps\\require'}),
471 copy_components = ShellApi.copyDirectory({sourceUri: window.NativeShellApp.GetKnownFolder('appsource')+'\\montage-components', destUri: directory.uri+'\\montage-components'});