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(); } }