Example #1
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 #2
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();
	}