TagSpaces is an offline, open source, document manager with tagging support
Added move tag position in filename functionality.
uggrock191f199d97b5
diff --git a/data/index.html b/data/index.htmlindex 4888b552c..012156ff3 100644--- a/data/index.html+++ b/data/index.html@@ -363,6 +363,8 @@<ul id="tagMenu" class="dropdown-menu has-tip anchor-right"><li><a id="tagMenuAddTagAsFilter" title="Set the extension of this file as a filter"><i class="icon-filter"></i> Set as Filter</a></li><li><a id="tagMenuEditTag" title=""><i class="icon-pencil"></i> Edit Tag</a></li>+ <li><a id="tagMenuMoveTagRight" title=""><i class="icon-arrow-right"></i> Move Tag to Right</a></li>+ <li><a id="tagMenuMoveTagLeft" title=""><i class="icon-arrow-left"></i> Move Tag to Left</a></li><li><a id="tagMenuRemoveTag" title=""><i class="icon-trash"></i> Remove Tag</a></li></ul>diff --git a/data/js/tags.ui.js b/data/js/tags.ui.jsindex 92c734c0b..9e8fd6060 100644--- a/data/js/tags.ui.js+++ b/data/js/tags.ui.js@@ -26,6 +26,13 @@ define(function(require, exports, module) {TSCORE.TagUtils.removeTag(TSCORE.selectedFiles[0],TSCORE.selectedTag);});+ $( "#tagMenuMoveTagRight" ).click( function() {+ TSCORE.TagUtils.moveTagLocation(TSCORE.selectedFiles[0],TSCORE.selectedTag, "next");+ });++ $( "#tagMenuMoveTagLeft" ).click( function() {+ TSCORE.TagUtils.moveTagLocation(TSCORE.selectedFiles[0],TSCORE.selectedTag, "prev");+ });// Context menu for the tags in the tag tree$( "#tagTreeMenuAddTagToFile" ).click( function() {diff --git a/data/js/tagutils.js b/data/js/tagutils.jsindex 5f099a595..7d859771c 100644--- a/data/js/tagutils.js+++ b/data/js/tagutils.js@@ -215,6 +215,9 @@ define(function(require, exports, module) {} else {// File does not have an extensionnewFileName = fileName.substring(0,beginTagContainer)+tagsString+fileName.substring(endTagContainer+1,fileName.length);+ }+ if(newFileName.length < 1) {+ throw "Generated filename is invalid";}return newFileName;}@@ -249,6 +252,40 @@ define(function(require, exports, module) {}}+ // Moves the location of tag in the file name+ // possible directions should be next, prev, last, first+ function moveTagLocation(filePath, tagName, direction) {+ console.log("Moves the location of tag in the file name: "+filePath);++ var fileName = extractFileName(filePath);++ var containingDirectoryPath = extractContainingDirectoryPath(filePath);++ var extractedTags = extractTags(filePath);++ for (var i=0; i < extractedTags.length; i++) {+ // check if tag is already in the tag array+ if(extractedTags[i] == tagName) {+ if((direction == "prev") && (i > 0)) {+ var tmpTag = extractedTags[i-1];+ extractedTags[i-1] = extractedTags[i]+ extractedTags[i] = tmpTag;+ break;+ } else if ((direction == "next") && i < (extractedTags.length-1) ){+ var tmpTag = extractedTags[i];+ extractedTags[i] = extractedTags[i+1]+ extractedTags[i+1] = tmpTag;+ break;+ }+ }+ }++ var newFileName = generateFileName(fileName, extractedTags);++ IOAPI.renameFile(filePath, containingDirectoryPath+DIR_SEPARATOR+newFileName);++ }+// Replaces a tag with a new onefunction renameTag(filePath, oldTag, newTag) {console.log("Rename tag for file: "+filePath);@@ -328,6 +365,7 @@ define(function(require, exports, module) {exports.extractTags = extractTags;exports.suggestTags = suggestTags;exports.writeTagsToFile = writeTagsToFile;+ exports.moveTagLocation = moveTagLocation;exports.renameTag = renameTag;exports.removeTag = removeTag;exports.addTag = addTag;