return Promise.all(promises).then(function() {
   initPerspectiveSwitcher();
   // Opening last saved location by the start of the application
   var lastLocation = TSCORE.Config.getLastOpenedLocation(); 
   if (TSCORE.Config.getUseDefaultLocation()) {
     lastLocation = TSCORE.Config.getDefaultLocation();
   }
   if (lastLocation && lastLocation.length >= 1) {
     TSCORE.openLocation(lastLocation);
     TSCORE.IO.checkAccessFileURLAllowed ? TSCORE.IO.checkAccessFileURLAllowed() : true;
     var evt = TSCORE.createDocumentEvent("initApp");
     TSCORE.fireDocumentEvent(evt);
     $("#viewContainers").removeClass("appBackgroundTile");
   }
   $('#loading').hide();
   if (isNode || isElectron) {
     TSCORE.IO.showMainWindow();
   }
   return true;
 });
 require([extPath], function(perspective) {
   perspectives.push(perspective);
   try {
     // Creating perspective's toolbar
     $('#viewToolbars').append($('<div>', {
       id: perspective.ID + 'Toolbar',
       class: 'btn-toolbar'
     }).hide());
     // Creating perspective's container
     $('#viewContainers').append($('<div>', {
       id: perspective.ID + 'Container',
       style: 'width: 100%; height: 100%'
     }).hide());
     // Creating perspective's footer
     $('#viewFooters').append($('<div>', {
       id: perspective.ID + 'Footer'
     }).hide());
     perspective.init();
   } catch (e) {
     console.log('Error while executing \'init\' on ' + perspectives[i].ID + ' - ' + e);
   } finally {
     if (perspectives.length === extensions.length) {
       initPerspectiveSwitcher();
       // Opening last saved location by the start of the application (not in firefox)
       var lastLocation = TSCORE.Config.getLastOpenedLocation();
       if (lastLocation !== undefined && lastLocation.length >= 1 && !isFirefox) {
         TSCORE.openLocation(lastLocation);
         TSCORE.IO.checkAccessFileURLAllowed();
         var evt = TSCORE.createDocumentEvent("initApp");
         TSCORE.fireDocumentEvent(evt);
       }
       $('#loading').hide();
       if (isNode) {
         TSCORE.IO.showMainWindow();
       }
     }
   }
 }); // jshint ignore:line
Example #3
0
    function openFile(filePath, editMode) {
        console.log("Opening file: "+filePath);

        if(filePath === undefined) {
            return false;
        }

        if(TSCORE.FileOpener.isFileChanged()) {
            // TODO use closeFile method
            if(confirm($.i18n.t("ns.dialogs:closingEditedFileConfirm"))) {
                 $("#saveDocument").hide();
                 _isEditMode = false;
            } else {
                return false;   
            }
        }

        _isEditMode = false;
        _isFileChanged = false;

        _openedFilePath = filePath;
        //$("#selectedFilePath").val(_openedFilePath.replace("\\\\","\\"));

        if(isWeb) {
            var downloadLink;
            if(location.port === "") {
                downloadLink = location.protocol+"//"+location.hostname+_openedFilePath;
            } else {
                downloadLink = location.protocol+"//"+location.hostname+":"+location.port+_openedFilePath;
            }
            $( "#downloadFile").attr("href",downloadLink).attr("download",TSCORE.TagUtils.extractFileName(_openedFilePath));
        } else {
            $( "#downloadFile").attr("href","file:///"+_openedFilePath).attr("download",TSCORE.TagUtils.extractFileName(_openedFilePath));
        }

        var fileExt = TSCORE.TagUtils.extractFileExtension(filePath);

        // Getting the viewer for the file extension/type
        var viewerExt = TSCORE.Config.getFileTypeViewer(fileExt);
        var editorExt = TSCORE.Config.getFileTypeEditor(fileExt);  
        console.log("File Viewer: "+viewerExt+" File Editor: "+editorExt);

        // Handling the edit button depending on existense of an editor
        if(editorExt == false || editorExt == "false" || editorExt === "") {
            $( "#editDocument" ).hide();        
        } else {
            $( "#editDocument" ).show();                
        }

        var $viewer = $( "#viewer" );
        $viewer.find("*").off();
        $viewer.find("*").unbind();
        $viewer.find("*").remove();

        TSCORE.IO.checkAccessFileURLAllowed();

        TSCORE.IO.getFileProperties(filePath.replace("\\\\","\\"));

        updateUI();

        if(editMode) {
            // opening file for editing
            editFile(filePath);
        } else {
            // opening file for viewing
            if(!viewerExt) {
                require([TSCORE.Config.getExtensionPath()+"/viewerText/extension.js"], function(viewer) {
                    _tsEditor = viewer;
                    _tsEditor.init(filePath, "viewer", true);
                });
            } else {
                require([TSCORE.Config.getExtensionPath()+"/"+viewerExt+"/extension.js"], function(viewer) {
                    _tsEditor = viewer;
                    _tsEditor.init(filePath, "viewer", true);
                });
            }
        }

        initTagSuggestionMenu(filePath);

        // Clearing file selection on file load and adding the current file path to the selection
        TSCORE.PerspectiveManager.clearSelectedFiles();
        TSCORE.selectedFiles.push(filePath);

        _isFileOpened = true;
        TSCORE.openFileViewer();

        // Handling the keybindings
        Mousetrap.unbind(TSCORE.Config.getSaveDocumentKeyBinding());
        Mousetrap.bind(TSCORE.Config.getSaveDocumentKeyBinding(), function() {
            saveFile();
            return false;
        });

        Mousetrap.unbind(TSCORE.Config.getCloseViewerKeyBinding());
        Mousetrap.bind(TSCORE.Config.getCloseViewerKeyBinding(), function() {
            closeFile();
            return false;
        });

        Mousetrap.unbind(TSCORE.Config.getReloadDocumentKeyBinding());
        Mousetrap.bind(TSCORE.Config.getReloadDocumentKeyBinding(), function() {
            reloadFile();
            return false;
        });

        /*Mousetrap.unbind(TSCORE.Config.getDeleteDocumentKeyBinding());
        Mousetrap.bind(TSCORE.Config.getDeleteDocumentKeyBinding(), function() {
            TSCORE.showFileDeleteDialog(_openedFilePath);
            return false;
        });*/

        Mousetrap.unbind(TSCORE.Config.getPropertiesDocumentKeyBinding());
        Mousetrap.bind(TSCORE.Config.getPropertiesDocumentKeyBinding(), function() {
            showFilePropertiesDialog();
            return false;
        });

        Mousetrap.unbind(TSCORE.Config.getPrevDocumentKeyBinding());
        Mousetrap.bind(TSCORE.Config.getPrevDocumentKeyBinding(), function() {
            TSCORE.FileOpener.openFile(TSCORE.PerspectiveManager.getPrevFile(_openedFilePath));
            return false;
        });

        Mousetrap.unbind(TSCORE.Config.getNextDocumentKeyBinding());
        Mousetrap.bind(TSCORE.Config.getNextDocumentKeyBinding(), function() {
            TSCORE.FileOpener.openFile(TSCORE.PerspectiveManager.getNextFile(_openedFilePath));
            return false;
        });

        Mousetrap.unbind(TSCORE.Config.getEditDocumentKeyBinding());
        Mousetrap.bind(TSCORE.Config.getEditDocumentKeyBinding(), function() {
            editFile(_openedFilePath);
            return false;
        });

    }
Example #4
0
	function openFile(filePath) {
	    console.log("Opening file: "+filePath);
		
		if(filePath == undefined) {
		    return false;
		}
		
		if(TSCORE.FileOpener.isFileEdited()) {
		    // TODO use closeFile method
            if(confirm("Any unsaved changes will be lost! Do you want to continue?")) {
                 $("#saveDocument").hide();
                _isEditMode = false;               
            } else {
                return false;   
            }
		}
                 		
	    _isEditMode = false;
	
	    _openedFilePath = filePath;    
	    $("#selectedFilePath").val(_openedFilePath.replace("\\\\","\\")); 
	    
	    var fileExt = TSCORE.TagUtils.extractFileExtension(filePath);       
	
	    // Getting the viewer for the file extension/type
	    var viewerExt = TSCORE.Config.getFileTypeViewer(fileExt);  
        var editorExt = TSCORE.Config.getFileTypeEditor(fileExt);  
	    console.log("File Viewer: "+viewerExt+" File Editor: "+editorExt);

        // Handling the edit button depending on existense of an editor
        if(editorExt == false || editorExt == "false" || editorExt == "") {
            $( "#editDocument" ).hide();        
        } else {
            $( "#editDocument" ).show();                
        }
     
	    $( "#viewer" ).empty();
	    
	    TSCORE.IO.checkAccessFileURLAllowed();
	    
	    TSCORE.IO.getFileProperties(filePath.replace("\\\\","\\"));
        
        if(!viewerExt) {
            require([TSCORE.Config.getExtensionPath()+"/viewerText/extension.js"], function(viewer) {
                _tsEditor = viewer;
                _tsEditor.init(filePath, "viewer", true);
            });
	        //$( "#viewer" ).html("<div class='alert alert-info'><strong>Info</strong> File type not supported for viewing.</div>");        
	    } else if (viewerExt == "viewerBrowser") {
            var filePathURI = undefined;
            if(isCordova) {
                filePathURI = filePath;            
            } else {
                filePathURI = "file:///"+filePath;  
            }
            
		    $('#viewer').append($('<iframe>', {
		    	id: "iframeViewer",
				src: filePathURI
		    })); 
	    } else {
	        require([TSCORE.Config.getExtensionPath()+"/"+viewerExt+"/extension.js"], function(viewer) {
	            _tsEditor = viewer;
	            _tsEditor.init(filePath, "viewer", true);
	        });
	    }

        updateUI();  
        initTagSuggestionMenu(filePath);
	    
        // Clearing file selection on file load and adding the current file path to the selection
        TSCORE.PerspectiveManager.clearSelectedFiles();
        TSCORE.selectedFiles.push(filePath); 	     
	    
	    TSCORE.FileOpener.setFileOpened(true); 
		TSCORE.openFileViewer();
	} 
Example #5
0
  function openFile(filePath, editMode) {
    console.log('Opening file: ' + filePath);
    if (filePath === undefined) {
      return false;
    }
    if (TSCORE.FileOpener.isFileChanged()) {
      // TODO use closeFile method
      if (confirm($.i18n.t('ns.dialogs:closingEditedFileConfirm'))) {
        $('#saveDocument').hide();
        _isEditMode = false;
      } else {
        return false;
      }
    }

    $('#fileTags').find('button').prop('disabled', false);
    $('#addTagFileViewer').prop('disabled', false);

    _isEditMode = false;
    _isFileChanged = false;
    _openedFilePath = filePath;
    //$("#selectedFilePath").val(_openedFilePath.replace("\\\\","\\"));
    if (isWeb) {
      var startupParameter = "";
      if (filePath) {
        startupParameter = "?open=" + encodeURIComponent(filePath);
        window.history.pushState("", "TagSpaces", "/index.html" + startupParameter);
      }
      console.log("Link to file for sharing: " + window.location.href);
      var downloadLink;
      if (location.port === '') {
        downloadLink = location.protocol + '//' + location.hostname + _openedFilePath;
      } else {
        downloadLink = location.protocol + '//' + location.hostname + ':' + location.port + _openedFilePath;
      }
      $('#downloadFile').attr('href', downloadLink).attr('download', TSCORE.TagUtils.extractFileName(_openedFilePath));
    } else {
      $('#downloadFile').attr('href', 'file:///' + _openedFilePath).attr('download', TSCORE.TagUtils.extractFileName(_openedFilePath));
    }
    var fileExt = TSCORE.TagUtils.extractFileExtension(filePath);
    // Getting the viewer for the file extension/type
    var viewerExt = TSCORE.Config.getFileTypeViewer(fileExt);
    var editorExt = TSCORE.Config.getFileTypeEditor(fileExt);
    console.log('File Viewer: ' + viewerExt + ' File Editor: ' + editorExt);
    // Handling the edit button depending on existense of an editor
    if (editorExt === false || editorExt === 'false' || editorExt === '') {
      $('#editDocument').hide();
    } else {
      $('#editDocument').show();
    }
    var $viewer = $('#viewer');
    $viewer.find('*').off();
    $viewer.find('*').unbind();
    $viewer.find('*').remove();
    TSCORE.IO.checkAccessFileURLAllowed ? TSCORE.IO.checkAccessFileURLAllowed() : true;
    TSCORE.IO.getPropertiesPromise(filePath).then(function(fileProperties) {
      if (fileProperties) {
        TSPOSTIO.getFileProperties(fileProperties);
      }
    }).catch(function(error) {
      TSCORE.hideLoadingAnimation();
      TSCORE.showAlertDialog("Error getting properties for " + filePath);
    });

    updateUI();
    if (editMode) {
      // opening file for editing
      editFile(filePath);
    } else {
      // opening file for viewing
      if (!viewerExt) {
        require([TSCORE.Config.getExtensionPath() + '/viewerText/extension.js'], function(viewer) {
          _tsEditor = viewer;
          _tsEditor.init(filePath, 'viewer', true);
        });
      } else {
        require([TSCORE.Config.getExtensionPath() + '/' + viewerExt + '/extension.js'], function(viewer) {
          _tsEditor = viewer;
          _tsEditor.init(filePath, 'viewer', true);
        });
      }
    }
    initTagSuggestionMenu(filePath);
    // Clearing file selection on file load and adding the current file path to the selection
    TSCORE.PerspectiveManager.clearSelectedFiles();
    TSCORE.selectedFiles.push(filePath);
    _isFileOpened = true;
    TSCORE.openFileViewer();
    // Handling the keybindings
    Mousetrap.unbind(TSCORE.Config.getSaveDocumentKeyBinding());
    Mousetrap.bindGlobal(TSCORE.Config.getSaveDocumentKeyBinding(), function() {
      saveFile();
      return false;
    });
    Mousetrap.unbind(TSCORE.Config.getCloseViewerKeyBinding());
    Mousetrap.bindGlobal(TSCORE.Config.getCloseViewerKeyBinding(), function() {
      closeFile();
      return false;
    });
    Mousetrap.unbind(TSCORE.Config.getReloadDocumentKeyBinding());
    Mousetrap.bindGlobal(TSCORE.Config.getReloadDocumentKeyBinding(), function() {
      reloadFile();
      return false;
    });
    /*Mousetrap.unbind(TSCORE.Config.getDeleteDocumentKeyBinding());
        Mousetrap.bind(TSCORE.Config.getDeleteDocumentKeyBinding(), function() {
            TSCORE.showFileDeleteDialog(_openedFilePath);
            return false;
        });*/
    Mousetrap.unbind(TSCORE.Config.getPropertiesDocumentKeyBinding());
    Mousetrap.bindGlobal(TSCORE.Config.getPropertiesDocumentKeyBinding(), function() {
      showFilePropertiesDialog();
      return false;
    });
    Mousetrap.unbind(TSCORE.Config.getPrevDocumentKeyBinding());
    Mousetrap.bind(TSCORE.Config.getPrevDocumentKeyBinding(), function() {
      TSCORE.FileOpener.openFile(TSCORE.PerspectiveManager.getPrevFile(_openedFilePath));
      return false;
    });
    Mousetrap.unbind(TSCORE.Config.getNextDocumentKeyBinding());
    Mousetrap.bind(TSCORE.Config.getNextDocumentKeyBinding(), function() {
      TSCORE.FileOpener.openFile(TSCORE.PerspectiveManager.getNextFile(_openedFilePath));
      return false;
    });
    Mousetrap.unbind(TSCORE.Config.getEditDocumentKeyBinding());
    Mousetrap.bindGlobal(TSCORE.Config.getEditDocumentKeyBinding(), function() {
      editFile(_openedFilePath);
      return false;
    });

    Mousetrap.bindGlobal("esc", leaveFullScreen);

    if (isFullScreen()) {
      switchToFullScreen();
    }
  }