TagSpaces is an offline, open source, document manager with tagging support
added node trash
Borislav Sapundzhiev6cec8a615cd0
diff --git a/data/js/settings.api.js b/data/js/settings.api.jsindex 137f35877..3cbaf01ea 100644--- a/data/js/settings.api.js+++ b/data/js/settings.api.js@@ -644,6 +644,15 @@ define(function(require, exports, module) {var getNewMDFileContent = function() {return exports.DefaultSettings.newMDFileContent;};+ var getUseTrashCan = function() {+ if (exports.Settings.useTrashCan === undefined) {+ exports.Settings.useTrashCan = exports.DefaultSettings.useTrashCan;+ }+ return exports.Settings.useTrashCan;+ };+ var setUseTrashCan = function(value) {+ exports.Settings.useTrashCan = value;+ };//////////////////// API methods ///////////////////var getFileTypeEditor = function(fileTypeExt) {for (var i = 0; i < exports.Settings.supportedFileTypes.length; i++) {@@ -1085,7 +1094,9 @@ define(function(require, exports, module) {exports.getActivatedPerspectiveExtensions = getActivatedPerspectiveExtensions;exports.getViewerExtensions = getViewerExtensions;exports.getEditorExtensions = getEditorExtensions;-+ exports.getUseTrashCan = getUseTrashCan;+ exports.setUseTrashCan = setUseTrashCan;+exports.getNewTextFileContent = getNewTextFileContent;exports.getNewHTMLFileContent = getNewHTMLFileContent;exports.getNewMDFileContent = getNewMDFileContent;diff --git a/data/js/settings.default.js b/data/js/settings.default.jsindex fd793aad6..289a30a5a 100644--- a/data/js/settings.default.js+++ b/data/js/settings.default.js@@ -38,6 +38,7 @@ define(function (require, exports, module) {"perspectives": [{ 'id': 'perspectiveList' }, { 'id': 'perspectiveGrid' }, { 'id': 'perspectiveGraph' }],"interfaceLanguage": "en_US","writeTagsToFile": false,+ "useTrashCan": false,"supportedLanguages": [{ "iso": "en_US", "title": "English" },{ "iso": "de_DE", "title": "Deutsch (German)" },diff --git a/data/locales/en_US/ns.dialogs.json b/data/locales/en_US/ns.dialogs.jsonindex 119dc137e..733239556 100644--- a/data/locales/en_US/ns.dialogs.json+++ b/data/locales/en_US/ns.dialogs.json@@ -150,6 +150,7 @@"useDefaultLocation": "Use default location as a startup location","enablingUsingMetaFolder": "Enable the use of a hidden folder(.ts) for storing meta data and thumbnails","writeMetaToSidecarFile": "Use sidecar files in the hidden folders for saving meta data (e.g. tags)",+ "useTrashCan": "Move deleted files or folders to trash bin","invalidImportFile": "The imported file has invalid format","importGroupTagsTitle": "Import tags from file","confirmSaveButton": "Save",diff --git a/data/node-webkit/node-webkit.api.js b/data/node-webkit/node-webkit.api.jsindex 1b74fd212..822ba1e41 100644--- a/data/node-webkit/node-webkit.api.js+++ b/data/node-webkit/node-webkit.api.js@@ -6,7 +6,7 @@var fs = require('fs-extra'); // jshint ignore:linevar pathUtils = require('path'); // jshint ignore:linevar gui = require('nw.gui'); // jshint ignore:line-+var trash = require('trash');define(function(require, exports, module) {"use strict";@@ -558,28 +558,47 @@ define(function(require, exports, module) {var deleteElement = function(path) {console.log("Deleting: " + path);- fs.unlink(path, function(error) {- if (error) {+ if (TSCORE.PRO && TSCORE.Config.getUseTrashCan()) {+ trash([path]) .then(function() {+ TSPOSTIO.deleteElement(path);+ }).catch(function(){TSCORE.hideLoadingAnimation();TSCORE.showAlertDialog("Deleting file " + path + " failed.");console.error("Deleting file " + path + " failed " + error);- return;- }- TSPOSTIO.deleteElement(path);- });+ });+ } else {+ fs.unlink(path, function(error) {+ if (error) {+ TSCORE.hideLoadingAnimation();+ TSCORE.showAlertDialog("Deleting file " + path + " failed.");+ console.error("Deleting file " + path + " failed " + error);+ return;+ }+ TSPOSTIO.deleteElement(path);+ });+ }};var deleteDirectory = function(path) {console.log("Deleting directory: " + path);- fs.rmdir(path, function(error) {- if (error) {- TSCORE.hideLoadingAnimation();+ if (TSCORE.PRO && TSCORE.Config.getUseTrashCan()) {+ trash([path]).then(function() {+ TSPOSTIO.deleteDirectory(path);+ }).catch(function(){console.error("Deleting directory " + path + " failed " + error);TSPOSTIO.deleteDirectoryFailed(path);- return;- }- TSPOSTIO.deleteDirectory(path);- });+ });+ } else {+ fs.rmdir(path, function(error) {+ if (error) {+ TSCORE.hideLoadingAnimation();+ console.error("Deleting directory " + path + " failed " + error);+ TSPOSTIO.deleteDirectoryFailed(path);+ return;+ }+ TSPOSTIO.deleteDirectory(path);+ });+ }};var checkAccessFileURLAllowed = function() {diff --git a/data/templates/OptionsDialog.html b/data/templates/OptionsDialog.htmlindex 9aab1459d..2bc2b98be 100644--- a/data/templates/OptionsDialog.html+++ b/data/templates/OptionsDialog.html@@ -103,6 +103,14 @@<p class="help-block">Location metadata file "tsm.json" should be placed in the ".ts "subfolder of the current location. The file format should be the same as the exported tag groups file from the tab 'general'.</p></div></div>+ <div class="form-group">+ <div class="col-sm-12 checkbox">+ <label for="useTrashCan" >+ <input type="checkbox" id="useTrashCan" />+ <span data-i18n="ns.dialogs:useTrashCan"></span>+ </label>+ </div>+ </div><!--div class='form-group col-sm-12'><label for='tagsDelimiterInput' data-i18n="ns.dialogs:tagDelimiter"></label><input type='text' class='form-control' id='tagsDelimiterInput' />diff --git a/default.settings.tmpl.js b/default.settings.tmpl.jsindex 63d7d21be..58592e191 100644--- a/default.settings.tmpl.js+++ b/default.settings.tmpl.js@@ -38,6 +38,7 @@ define(function (require, exports, module) {"perspectives": [@@ACTIVATEDPERSPECTIVES],"interfaceLanguage": "en_US","writeTagsToFile": false,+ "useTrashCan": false,"supportedLanguages": [{ "iso": "en_US", "title": "English" },{ "iso": "de_DE", "title": "Deutsch (German)" },