Example #1
0
 function loadSettingsLocalStorage() {
   try {
     var tmpSettings = JSON.parse(localStorage.getItem('tagSpacesSettings'));
     //Cordova try to load saved setting in app storage
     if (isCordova) {
       var appStorageSettings = JSON.parse(TSCORE.IO.loadSettings());
       var appStorageTagGroups = JSON.parse(TSCORE.IO.loadSettingsTags());
       if (appStorageSettings) {
         tmpSettings = appStorageSettings;
       }
       if (appStorageTagGroups) {
         tmpSettings.tagGroups = appStorageTagGroups.tagGroups;
       }
     }
     //console.log("Settings: "+JSON.stringify(tmpSettings));        
     if (tmpSettings !== null) {
       exports.Settings = tmpSettings;
     } else {
       // If no settings found in the local storage,
       // the application runs for the first time.
       firstRun = true;
     }
     console.log('Loaded settings from local storage: '); //+ JSON.stringify(exports.Settings));
   } catch (ex) {
     console.log('Loading settings from local storage failed due exception: ' + ex);
   }
 }
Example #2
0
    TSCORE.metaFileList.forEach(function(element, index) {
      if (element.name.indexOf(name) >= 0) {
        if (newFileName) {
          var pathOld  = TSCORE.Utils.dirName(oldFileName);
          var pathNew = TSCORE.Utils.dirName(newFileName);
          var path = TSCORE.currentPath;

          if (pathNew.lastIndexOf(TSCORE.dirSeparator) === 0) {
            pathOld += TSCORE.dirSeparator;
          }

          if (pathOld != pathNew) {
            path = pathNew;
          }
          var newName = TSCORE.Utils.baseName(newFileName) + "." + element.name.split('.').pop();
          var newFilePath = path + TSCORE.dirSeparator + TSCORE.metaFolder + TSCORE.dirSeparator + newName;
          TSCORE.IO.renameFilePromise(element.path, newFilePath);

          if (pathOld == TSCORE.currentPath) {
            element.name = newName;
            element.path = newFilePath;  
          } else {
            TSCORE.metaFileList.splice(index, 1);
          }
          
        } else {
          TSCORE.IO.deleteFilePromise(element.path).then(function() {
            TSCORE.metaFileList.splice(index, 1);
          });
        }
      }
    });
Example #3
0
        $( '#fileCreateConfirmButton' ).click(function() {
            var fileTags = "";
            var rawTags = $( "#newFileNameTags" ).val().split(",");

            rawTags.forEach(function (value, index) {
                if(index == 0) {
                    fileTags = value;
                } else {
                    fileTags = fileTags + TSCORE.Config.getTagDelimiter() + value;
                }
            });

            if($("#tagWithCurrentDate").prop("checked")) {
                if(fileTags.length < 1) {
                    fileTags = TSCORE.TagUtils.formatDateTime4Tag(new Date());
                } else {
                    fileTags = fileTags + TSCORE.Config.getTagDelimiter() + TSCORE.TagUtils.formatDateTime4Tag(new Date());
                }
            }

            if(fileTags.length > 0) {
                fileTags = TSCORE.TagUtils.beginTagContainer + fileTags + TSCORE.TagUtils.endTagContainer;
            }

            var fileName = TSCORE.currentPath+TSCORE.dirSeparator+$( "#newFileName" ).val()+fileTags+"."+fileType;

            TSCORE.IO.saveTextFile(fileName,fileContent);
            
            // TODO move this functionality to postio
            TSCORE.IO.listDirectory(TSCORE.currentPath);
        });
Example #4
0
 // Save setting
 function saveSettings() {
   // TODO Make a file based json backup
   // Making a backup of the last settings
   localStorage.setItem('tagSpacesSettingsBackup1', localStorage.getItem('tagSpacesSettings'));
   // Storing setting in the local storage of mozilla and chorme
   localStorage.setItem('tagSpacesSettings', JSON.stringify(exports.Settings));
   // Storing settings in firefox native preferences
   if (isFirefox || isChrome || isCordova) {
     TSCORE.IO.saveSettings(JSON.stringify(exports.Settings));
     if (isCordova) {
       TSCORE.IO.saveSettingsTags(JSON.stringify(exports.Settings.tagGroups));
     }
   }
   console.log('Tagspace Settings Saved!');
 }
Example #5
0
  function startSearch() {
    if (TSCORE.IO.stopWatchingDirectories) {
      TSCORE.IO.stopWatchingDirectories();
    }
    if ($('#searchBox').val().length > 0) {
      var origSearchVal = $('#searchBox').val(); 
      origSearchVal = origSearchVal.trim();

      if ($('#searchRecursive').prop('checked')) {
        $('#searchBox').val(origSearchVal);
      } else {
        if (origSearchVal.indexOf(TSCORE.Search.recursiveSymbol) === 0) {
          $('#searchBox').val(origSearchVal);
        } else {
          //origSearchVal = origSearchVal.substring(1, origSearchVal.length);
          $('#searchBox').val(TSCORE.Search.recursiveSymbol + " " + origSearchVal);
        }
      }

      if (TSCORE.PRO && TSCORE.PRO.Search) {
        TSCORE.PRO.Search.addQueryToHistory(origSearchVal);
      }
      TSCORE.Search.nextQuery = $('#searchBox').val();
    }
    $('#searchOptions').hide();
    TSCORE.PerspectiveManager.redrawCurrentPerspective();
  }
Example #6
0
 .click( function() {
     var currentDateTime = TSCORE.TagUtils.formatDateTime4Tag(new Date(), true);
     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);
 });
Example #7
0
  function init(filePath, containerElementID) {
    console.log("Initalization HTML Editor...");

    fileDirectory = TSCORE.TagUtils.extractContainingDirectoryPath(filePath);

    $containerElement = $('#' + containerElementID);

    currentFilePath = filePath;

    $containerElement.empty();
    $containerElement.css("background-color", "white");

    var extPath = extensionDirectory + "/index.html";
    $containerElement.append($('<iframe>', {
      id: "iframeViewer",
      sandbox: "allow-same-origin allow-scripts allow-modals",
      scrolling: "no",
      style: "background-color: white; overflow: hidden;",
      src: extPath + "?cp=" + filePath + "&setLng=" + TSCORE.currentLanguage,
      "nwdisable": "",
      "nwfaketop": ""
    }));

    TSCORE.IO.loadTextFilePromise(filePath).then(function(content) {
      exports.setContent(content);
    },
    function(error) {
      TSCORE.hideLoadingAnimation();
      TSCORE.showAlertDialog("Loading " + filePath + " failed.");
      console.error("Loading file " + filePath + " failed " + error);
    });
  }
Example #8
0
 $('#fileCreateConfirmButton').click(function() {
   var fileTags = '';
   var rawTags = $('#newFileNameTags').val().split(',');
   rawTags.forEach(function(value, index) {
     if (index === 0) {
       fileTags = value;
     } else {
       fileTags = fileTags + TSCORE.Config.getTagDelimiter() + value;
     }
   });
   if ($('#tagWithCurrentDate').prop('checked')) {
     if (fileTags.length < 1) {
       fileTags = TSCORE.TagUtils.formatDateTime4Tag(new Date());
     } else {
       fileTags = fileTags + TSCORE.Config.getTagDelimiter() + TSCORE.TagUtils.formatDateTime4Tag(new Date());
     }
   }
   if (fileTags.length > 0) {
     fileTags = TSCORE.TagUtils.beginTagContainer + fileTags + TSCORE.TagUtils.endTagContainer;
   }
   var filePath = TSCORE.currentPath + TSCORE.dirSeparator + $('#newFileName').val() + fileTags + '.' + fileType;
   TSCORE.IO.saveFilePromise(filePath, fileContent).then(function() {
     TSPOSTIO.saveTextFile(filePath, isNewFile);
   }, function(error) {
     TSCORE.hideLoadingAnimation();
     TSCORE.showAlertDialog("Saving " + filePath + " failed.");
     console.error("Save to file " + filePath + " failed " + error);
   });
 });
Example #9
0
   // 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);
   var tmpTag;
   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) {
         tmpTag = extractedTags[i - 1];
         extractedTags[i - 1] = extractedTags[i];
         extractedTags[i] = tmpTag;
         break;
       } else if (direction === 'next' && i < extractedTags.length - 1) {
         tmpTag = extractedTags[i];
         extractedTags[i] = extractedTags[i + 1];
         extractedTags[i + 1] = tmpTag;
         break;
       } else if (direction === 'first' && i > 0) {
         tmpTag = extractedTags[i];
         extractedTags[i] = extractedTags[0];
         extractedTags[0] = tmpTag;
         break;
       }
     }
   }
   var newFileName = generateFileName(fileName, extractedTags);
   TSCORE.IO.renameFile(filePath, containingDirectoryPath + TSCORE.dirSeparator + newFileName);
 }
 var promise = new Promise(function(resolve, reject) {
   var extensions = [];
   TSCORE.IO.listDirectoryPromise(extFolderPath).then(function(dirList) {
     var readBowerFileWorkers = [];
     for (var i in dirList) {
       var dirItem = dirList[i];
       if (!dirItem.isFile) {
         var filePath = dirItem.path + TSCORE.dirSeparator + bowerFileName;
         readBowerFileWorkers.push(loadBowerData(filePath));
       }
     }
     Promise.all(readBowerFileWorkers).then(function(bowerObjects) {
       bowerObjects.forEach(function(bowerObject) {
         if (bowerObject) {
           extensions.push(bowerObject);
         }
       });
       TSCORE.Config.setExtensions(extensions);
       resolve();
     }).catch(function(err) {
       console.warn("reading of at least one bower.json file failed: " + err);
       resolve();
     });
   }).catch(function(err) {
     console.warn("loadExtensionData failed with error: " + err);
     resolve();
   });
 });
Example #11
0
 var handleStartParameters = function() {
   //Windows "C:\Users\na\Desktop\TagSpaces\tagspaces.exe" --original-process-start-time=13043601900594583 "G:\data\assets\icon16.png"
   //Linux /opt/tagspaces/tagspaces /home/na/Dropbox/TagSpaces/README[README].md
   //OSX /home/na/Dropbox/TagSpaces/README[README].md
   //gui.App.on('open', function(cmdline) {
   //   console.log('Command line arguments on open: ' + cmdline);
   //   TSCORE.FileOpener.openFile(cmdArguments);
   //});
   var cmdArguments = gui.App.argv;
   if (cmdArguments !== undefined && cmdArguments.length > 0) {
     console.log("CMD Arguments: " + cmdArguments + " Process running in " + process.cwd());
     var dataPathIndex;
     cmdArguments.forEach(function(part, index) {
       if (part === "--data-path") {
         dataPathIndex = index;
       }
     });
     if (dataPathIndex >= 0 && cmdArguments.length >= dataPathIndex + 1) {
       cmdArguments.splice(dataPathIndex, 2);
     }
     console.log("CMD Arguments cleaned: " + cmdArguments);
     var filePath = "" + cmdArguments;
     var dirPath = TSCORE.TagUtils.extractContainingDirectoryPath(filePath);
     TSCORE.IO.listDirectory(dirPath);
     TSCORE.FileOpener.openFileOnStartup(filePath);
   }
 };
Example #12
0
  function createZipPrewiew(filePath, elementID) {
    var $parent = $('#' + elementID);
    var $previewElement = $('<div/>').css({'overflow': 'auto', 'padding': '5px', 'fontSize': 12})
      .width($parent.width()).height($parent.height()).appendTo($parent);

    TSCORE.showLoadingAnimation();
    
    TSCORE.IO.getFileContent(filePath, function(content) {
      var zipFile = new JSZip(content);
      $previewElement.append("<p> Contents of file " + filePath + "</p>");
      var ulFiles = $previewElement.append("<ul/>");

      for (var fileName in zipFile.files) {

        if (zipFile.files[fileName].dir === true) {
          continue;
        }
        var linkToFile = $('<a>').attr('href', '#').text(fileName);
        linkToFile.click(function(event) {
          event.preventDefault();
          var containFile = zipFile.files[$(this).text()];
          showContentFilePreviewDialog(containFile);
        });
        var liFile = $('<li/>').css('list-style-type', 'none').append(linkToFile);
        ulFiles.append(liFile);
      }

      TSCORE.hideLoadingAnimation();
    }, 
    function(error) {
      $previewElement.append("<p> Error in getFileContent :" + error + "</p>");
    });
  }
Example #13
0
 function listSubDirectories(dirPath) {
   console.log("Listing sub directories: " + dirPath);
   TSCORE.showLoadingAnimation();
   TSCORE.IO.listDirectoryPromise(dirPath).then(function(entries) {
     var anotatedDirList = [];
     var firstEntry = 0;
     // skiping the first entry pointing to the parent directory
     if (isChrome) {
       firstEntry = 1;
     }
     for (var i = firstEntry; i < entries.length; i++) {
       if (!entries[i].isFile) {
         anotatedDirList.push({
           "name": entries[i].name,
           "path": entries[i].path
         });
       }
     }
     TSPOSTIO.listSubDirectories(anotatedDirList, dirPath);
   }).catch(function(error) {
     TSPOSTIO.errorOpeningPath(dirPath);
     TSCORE.hideLoadingAnimation();
     console.error("Error listDirectory " + dirPath + " error: " + error);
   });
 }
Example #14
0
 function walkDirectory(path, options, fileCallback, dirCallback) {
   return TSCORE.IO.listDirectoryPromise(path, true).then(function(entries) {
     return Promise.all(entries.map(function(entry) {
       if (!options) {
         options = {};
         options.recursive = false;
       }
       if (entry.isFile) {
         if (fileCallback) {
           return fileCallback(entry);
         } else {
           return entry;
         }
       } else {
         if (dirCallback) {
           return dirCallback(entry);
         }
         if (options.recursive) { //  && !stopDirectoryWalking &&
           return walkDirectory(entry.path, options, fileCallback, dirCallback);
         } else {
           return entry;
         }
       }
     }));
   }).catch(function(err) {
     console.warn("Error walking directory " + err);
     return null;
   });
 }
Example #15
0
 function() {
     $("#saveDocument").hide();
     $("#editDocument").show();      
     var content = _tsEditor.getContent();
     TSCORE.IO.saveTextFile(_openedFilePath, content);
     _isEditMode = false;              
 }
Example #16
0
	exports.init = function(filePath, containerElementID) {
	    console.log("Initalization Text Viewer...");
	    containerElID = containerElementID;

        var filePathURI = undefined;
        if(isCordova) {
            filePathURI = filePath;            
        } else {
            filePathURI = "file:///"+filePath;  
        }
        
        var fileExt = TSCORE.TagUtils.extractFileExtension(filePath);

        $('#'+containerElID).empty();        
        
        if((fileExt.indexOf("htm") == 0 || fileExt.indexOf("xhtm") == 0 || fileExt.indexOf("txt") == 0) && !isFirefox) {
	        $("#"+containerElID).append($('<iframe>', {
			    	id: "iframeViewer",
					"nwdisable": "",
					"nwfaketop": "",
	        	})
	        );
	     	TSCORE.IO.loadTextFile(filePath);	    	 
        } else {
        	$("#"+containerElID).append($('<iframe>', {
			    	id: "iframeViewer",
					src: filePathURI,
					"nwdisable": "",
					"nwfaketop": "",
	        	})
	        );
	    }
	};
Example #17
0
    exports.init = function(filePath, containerElementID) {
        console.log("Initalization HTML Editor...");

        $containerElement = $('#'+containerElementID);

        currentFilePath = filePath;

        //var fileExt = TSCORE.TagUtils.extractFileExtension(filePath);

        $containerElement.empty();
        $containerElement.css("background-color","white");

        var extPath = extensionDirectory+"/index.html";
        $containerElement.append($('<iframe>', {
            id: "iframeViewer",
            sandbox: "allow-same-origin allow-scripts",
            scrolling: "no",
            style: "background-color: white; overflow: hidden;",
            src: extPath+"?cp="+filePath,
            "nwdisable": "",
            "nwfaketop": ""
        }));
        TSCORE.IO.loadTextFile(filePath);

//        if (!window.addEventListener) {
//            window.attachEvent('onmessage', function(e) {alert(e.origin);alert(e.data);});
//        } else {
//            window.addEventListener('message', function(e) {alert(e.origin);alert(e.data);}, false);
//        }
    };
Example #18
0
 var createTXTFile = function() {
     var filePath = TSCORE.currentPath+
                    TSCORE.dirSeparator+
                    TSCORE.TagUtils.beginTagContainer+
                    TSCORE.TagUtils.formatDateTime4Tag(new Date(), true)+
                    TSCORE.TagUtils.endTagContainer+".txt";
     TSCORE.IO.saveTextFile(filePath,TSCORE.Config.getNewTextFileContent());
 };
Example #19
0
 $( '#renameFileButton' ).click(function() {
     var initialFilePath = $( "#renamedFileName" ).attr("filepath");
     var containingDir = TSCORE.TagUtils.extractContainingDirectoryPath(initialFilePath);
     TSCORE.IO.renameFile(
         initialFilePath,
         containingDir+TSCORE.dirSeparator+$( "#renamedFileName" ).val()
     );
 });
Example #20
0
 function cancelSearch() {
   clearSearchFilter();
   $('#searchBox').popover('hide');
   $('#searchToolbar').hide();
   $('#showSearchButton').show();
   // Restoring initial dir listing without subdirectories
   TSCORE.IO.listDirectory(TSCORE.currentPath);
 }
Example #21
0
 drop: function( event, ui ) {
         var filePath = ui.draggable.attr("filepath");
         var fileName = TSCORE.TagUtils.extractFileName(filePath);
         var targetDir = $(this).attr("key");
         console.log("Moving file: "+filePath+" to "+targetDir);
         TSCORE.IO.renameFile(filePath, targetDir+TSCORE.dirSeparator+fileName);
         $(ui.helper).remove();                                 
 }                  
Example #22
0
    ], function(uiTPL) {
      var uiTemplate = Handlebars.compile(uiTPL);
      viewerToolbar = uiTemplate({
        id: extensionID
      });

      TSCORE.IO.loadTextFile(filePath);
    });
Example #23
0
 function navigateToDirectory(directoryPath) {
     console.log("Navigating to directory: "+directoryPath);
 
     // Cleaning the directory path from \\ \ and / 
     if( (directoryPath.lastIndexOf('/')+1 === directoryPath.length) || (directoryPath.lastIndexOf('\\')+1 === directoryPath.length)) {
         directoryPath = directoryPath.substring(0,directoryPath.length-1);
     }
     if( (directoryPath.lastIndexOf('\\\\')+1 === directoryPath.length)) {
         directoryPath = directoryPath.substring(0,directoryPath.length-2);
     }
 
     var directoryFoundOn = -1;    
     for(var i=0; i < directoryHistory.length; i++) {
         if(directoryHistory[i].path === directoryPath) {
             directoryHistory[i].collapsed = false;
             directoryFoundOn = i;
         } else {
             directoryHistory[i].collapsed = true;            
         }
     }
     
     // Removes the history only if it is a completely new path
     if(directoryFoundOn >= 0) { 
         var diff1 = directoryHistory.length - (directoryFoundOn+1);
         if(diff1 > 0) {
             directoryHistory.splice(directoryFoundOn+1, diff1);
         }    
     }       
     
     // If directory path not in history then add it to the history
     if(directoryFoundOn < 0) {      
         // var parentLocation = directoryPath.substring(0, directoryPath.lastIndexOf(TSCORE.dirSeparator));
         var parentLocation = TSCORE.TagUtils.extractParentDirectoryPath(directoryPath);
         var parentFound = -1;
         for(var j=0; j < directoryHistory.length; j++) {
             if(directoryHistory[j].path === parentLocation) {
                 parentFound = j;
             } 
         }       
         if(parentFound >= 0) { 
             var diff2 = directoryHistory.length - (parentFound+1);
             if(diff2 > 0) {
                 directoryHistory.splice(parentFound+1, diff2);
             }    
         }  
                 
         var locationTitle = directoryPath.substring(directoryPath.lastIndexOf(TSCORE.dirSeparator)+1,directoryPath.length);
         directoryHistory.push({
             "name": locationTitle,
             "path": directoryPath,
             "collapsed": false
         });
     }
     console.log("Dir History: "+JSON.stringify(directoryHistory));
     TSCORE.currentPath = directoryPath;
     TSCORE.IO.listDirectory(directoryPath);    
 } 
Example #24
0
 drop: function(event, ui) {
   ui.draggable.detach();
   var filePath = ui.draggable.attr('filepath');
   var fileName = TSCORE.TagUtils.extractFileName(filePath);
   var targetDir = $(this).attr('key');
   console.log('Moving file: ' + filePath + ' to ' + targetDir);
   TSCORE.IO.renameFile(filePath, targetDir + TSCORE.dirSeparator + fileName);
   $(ui.helper).remove();
 }
Example #25
0
 function createNewTextFile(filePath, content) {
   TSCORE.IO.saveFilePromise(filePath, content).then(function(isNewFile) {
     TSPOSTIO.saveTextFile(filePath, isNewFile);
   }, function(error) {
     TSCORE.hideLoadingAnimation();
     console.error("Save to file " + filePath + " failed " + error);
     TSCORE.showAlertDialog("Saving " + filePath + " failed.");
   });
 }
Example #26
0
			        $( "#createNewDirectoryButton" ).on("click", function() {			
                        // TODO validate folder name
			            var bValid = true;
			            //bValid = bValid && checkLength( newDirName, "directory name", 3, 100 );
			            //bValid = bValid && checkRegexp( newDirName, /^[a-z]([0-9a-z_])+$/i, "Directory name may consist of a-z, 0-9, underscores, begin with a letter." );
			            if ( bValid ) {
			                TSCORE.IO.createDirectory($( "#createNewDirectoryButton" ).attr("path")+TSCORE.dirSeparator+$( "#newDirectoryName" ).val());
			            }
			        });   			     	            
Example #27
0
 $( "#copyFilesButton" ).click(function(e) {
     e.preventDefault();
     TSCORE.showWaitingDialog("Files are being copied");
     var newFilePath;
     for (var i = 0; i < TSCORE.selectedFiles.length; i++) {
         newFilePath = $("#moveCopyDirectoryPath").val()+TSCORE.dirSeparator+TSCORE.TagUtils.extractFileName(TSCORE.selectedFiles[i]);
         TSCORE.IO.copyFile(TSCORE.selectedFiles[i],newFilePath);
     }
 });
Example #28
0
     ], function(uiTPL, controller) {
         TSCORE.directoryBrowser = controller;
         if($("#directoryBrowserDialog").length < 1) {                
             var uiTemplate = Handlebars.compile( uiTPL );
             $('body').append(uiTemplate());   
             TSCORE.directoryBrowser.initUI();                        
         }
         TSCORE.IO.listSubDirectories(path);                     
 });         
 var refreshFileListContainer = function() {
   // TODO consider search view
   TSCORE.IO.listDirectoryPromise(TSCORE.currentPath).then(function(entries) {
     TSPOSTIO.listDirectory(entries);
   }).catch(function(err) {
     TSPOSTIO.errorOpeningPath(TSCORE.currentPath);
     console.warn("Error listing directory" + err);
   });
 };
Example #30
0
 function cleanFileFromTags(filePath) {
     console.log("Cleaning file from tags: " + filePath);
     var fileTitle = extractTitle(filePath);
     var fileExt = extractFileExtension(filePath);
     var containingDirectoryPath = extractContainingDirectoryPath(filePath);
     if(fileExt.length > 0) {
         fileExt = "."+fileExt;
     }
     TSCORE.IO.renameFile(filePath, containingDirectoryPath+TSCORE.dirSeparator+fileTitle+fileExt);
 }