Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fileopener.js - new promise api

Borislav Sapundzhiev275705ac2663
diff --git a/data/js/fileopener.js b/data/js/fileopener.js
index ccfea4437..65e58e7d4 100644
--- a/data/js/fileopener.js
+++ b/data/js/fileopener.js
@@ -7,6 +7,7 @@ define(function(require, exports, module) {
'use strict';
console.log('Loading fileopener...');
var TSCORE = require('tscore');
+ var TSPOSTIO = require("tspostioapi");
var _openedFilePath;
var _openedFileProperties;
var _isFileOpened = false;
@@ -109,7 +110,13 @@ define(function(require, exports, module) {
var fileNameWithOutExt = TSCORE.TagUtils.extractFileNameWithoutExt(_openedFilePath);
var fileExt = TSCORE.TagUtils.extractFileExtension(_openedFilePath);
var newFilePath = TSCORE.currentPath + TSCORE.dirSeparator + fileNameWithOutExt + '_' + currentDateTime + '.' + fileExt;
- TSCORE.IO.copyFile(_openedFilePath, newFilePath);
+ TSCORE.IO.copyFilePromise(_openedFilePath, newFilePath).then(function(success) {
+ TSCORE.hideWaitingDialog();
+ TSPOSTIO.copyFile(_openedFilePath, newFilePath);
+ }, function(err) {
+ TSCORE.hideWaitingDialog();
+ TSCORE.showAlertDialog(err);
+ });
});
$('#toggleFullWidthButton').on("click", TSCORE.toggleFullWidth);
$('#fullscreenFile').on("click", switchToFullScreen);
@@ -245,7 +252,15 @@ define(function(require, exports, module) {
$viewer.find('*').unbind();
$viewer.find('*').remove();
TSCORE.IO.checkAccessFileURLAllowed ? TSCORE.IO.checkAccessFileURLAllowed() : true;
- TSCORE.IO.getFileProperties(filePath.replace('\\\\', '\\'));
+ 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
@@ -370,7 +385,13 @@ define(function(require, exports, module) {
title = title.substring(0,99);
}
}*/
- TSCORE.IO.saveTextFile(_openedFilePath, content);
+ TSCORE.IO.saveTextFilePromise(_openedFilePath, content).then(function(isNewFile) {
+ TSPOSTIO.saveTextFile(_openedFilePath, isNewFile);
+ }, function(error) {
+ TSCORE.hideLoadingAnimation();
+ console.error("Save to file " + _openedFilePath + " failed " + error);
+ TSCORE.showAlertDialog("Saving " + _openedFilePath + " failed.");
+ });
}
function updateUI() {
diff --git a/data/node-webkit/node-webkit.api.js b/data/node-webkit/node-webkit.api.js
index c1831b7d9..6315c9fc3 100644
--- a/data/node-webkit/node-webkit.api.js
+++ b/data/node-webkit/node-webkit.api.js
@@ -656,20 +656,20 @@ define(function(require, exports, module) {
function saveFilePromise(filePath, content, overwrite) {
return new Promise(function(resolve, reject) {
- function saveFile(filePath, content) {
+ function saveFile(filePath, content, isNewFile) {
fs.writeFile(filePath, content, 'utf8', function(error) {
if (error) {
reject(error);
}
- resolve();
+ resolve(isNewFile);
});
}
getPropertiesPromise(filePath).then(function(entry) {
if (entry && entry.isFile && overwrite) {
- saveFile(filePath, content);
+ saveFile(filePath, content, false);
} else if (!entry) {
- saveFile(filePath, content);
+ saveFile(filePath, content, true);
} else {
resolve();
}