Example #1
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 #2
0
  function showDeleteFilesDialog() {
    console.log('Deleting files...');
    var selFiles = " ";

    TSCORE.Utils.getUniqueSelectedFiles().forEach(function(file) {
      selFiles += " " + TSCORE.Utils.baseName(file) + " ,";
    });

    selFiles = selFiles.substring(0, selFiles.length - 1);
    var dlgConfirmMsgId = 'ns.dialogs:selectedFilesDeleteContentConfirm';

    if (TSCORE.PRO && TSCORE.Config.getUseTrashCan()) {
      dlgConfirmMsgId = 'ns.pro:trashFilesDeleteContentConfirm';
    }

    TSCORE.showConfirmDialog(
            $.i18n.t('ns.dialogs:fileDeleteTitleConfirm'),
            $.i18n.t(dlgConfirmMsgId, {selectedFiles: selFiles}),
            function() {
              if (TSCORE.IO.stopWatchingDirectories) {
                TSCORE.IO.stopWatchingDirectories();
              }
              TSCORE.IOUtils.deleteFiles(TSCORE.Utils.getUniqueSelectedFiles());
            }
    );
  }
Example #3
0
 function handleStartParameters() {
   var filePath = TSCORE.Utils.getURLParameter("open");
   if (filePath && (filePath.length > 0)) {
     filePath = decodeURIComponent(filePath);
     console.log("Opening file in browser: " + filePath);
     TSCORE.FileOpener.openFileOnStartup(filePath);
   }
 }
Example #4
0
 function createTagGroup(tagData, tagGroupName) {
   var newTagGroupModel = JSON.parse(JSON.stringify(tagGroupTemplate));
   newTagGroupModel.title = tagGroupName;
   //newTagGroupModel.children = [];
   newTagGroupModel.key = '' + TSCORE.Utils.getRandomInt(10000, 99999);
   console.log('Creating taggroup: ' + JSON.stringify(newTagGroupModel) + ' with key: ' + newTagGroupModel.key);
   exports.Settings.tagGroups.push(newTagGroupModel);
   saveSettings();
 }
 function loadThumbnail(fileName) {
   var name = TSCORE.Utils.baseName(fileName);
   var res = null;
   TSCORE.metaFileList.forEach(function(element) {
     if (element.name.indexOf(name) >= 0) {
       res = element.path;
     }
   });
   return res;
 }
Example #6
0
  function getContent() {
    $("#iframeViewer").contents().find(".note-editable .tsCheckBox").each(function() {
      $(this).attr("disabled", "disabled");
    });

    var content = $("#iframeViewer").contents().find(".note-editable").html();

    $("#iframeViewer").contents().find(".note-editable .tsCheckBox").each(function() {
      $(this).removeAttr("disabled");
    });

    // removing all scripts from the document
    var cleanedContent = content.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "");

    // saving all images as png in base64 format
    var match;
    var urls = [];
    var imgUrl = "";
    var rex = /<img.*?src="([^">]*\/([^">]*?))".*?>/g;

    while (match = rex.exec(cleanedContent)) {
      imgUrl = match[1];
      console.log("URLs: " + imgUrl);
      if (imgUrl.indexOf('data:image') === 0) {
        // Ignore data url
      } else {
        urls.push([imgUrl, TSCORE.Utils.getBase64Image(imgUrl)]);
      }

    }

    urls.forEach(function(dataURLObject) {
      if (dataURLObject[1].length > 7) {
        cleanedContent = cleanedContent.split(dataURLObject[0]).join(dataURLObject[1]);
      }
      //console.log(dataURLObject[0]+" - "+dataURLObject[1]);
    });
    // end saving all images

    cleanedContent = "<body data-sourceurl='" + sourceURL + "' data-scrappedon='" + scrappedOn + "' >" + cleanedContent + "</body>";

    var indexOfBody = currentContent.indexOf("<body");
    var htmlContent = "";
    if (indexOfBody >= 0 && currentContent.indexOf("</body>") > indexOfBody) {
      htmlContent = currentContent.replace(/\<body[^>]*\>([^]*)\<\/body>/m, cleanedContent); // jshint ignore:line
    } else {
      htmlContent = cleanedContent;
    }
    return htmlContent;
  }
 $('.my-gallery').find("figure").each(function() {
   if (TSCORE.Utils.isVisibleOnScreen(this)) {
     var $img = $(this).find('img');
     if ($img.attr("src").indexOf(defaultThumnailPath) === 0) {
       var filePath = $(this).find("a").attr("href");
       if (isChrome) {
         var indexOfFile = filePath.indexOf("file://");
         if (indexOfFile === 0) {
           filePath = filePath.substring(7, filePath.length);
         }
       }
       TSCORE.Meta.loadThumbnailPromise(filePath).then(function(url) {
         $img.attr("src", url);
       });
     }
   }
 });
Example #8
0
  function saveMetaData(filePath, metaData) {
    var metaFilePath = findMetaFilebyPath(filePath, TSCORE.metaFileExt);
    var currentVersion = TSCORE.Config.DefaultSettings.appVersion + "." + TSCORE.Config.DefaultSettings.appBuild;
    if (!metaFilePath) {
      var name = TSCORE.Utils.baseName(filePath) + TSCORE.metaFileExt;
      metaFilePath = TSCORE.currentPath + TSCORE.dirSeparator + TSCORE.metaFolder + TSCORE.dirSeparator + name;
      var entry = {
        "name": name,
        "isFile": true,
        "path": metaFilePath,
      };
      TSCORE.metaFileList.push(entry);
      metaData.appVersionCreated = currentVersion;
    }

    metaData.appName = TSCORE.Config.DefaultSettings.appName;
    metaData.appVersionUpdated = currentVersion;
    metaData.lastUpdated = new Date();

    var content = JSON.stringify(metaData);
    TSCORE.IO.saveTextFilePromise(metaFilePath, content, true);
  }
Example #9
0
 $('#fileMenuOpenDirectory').click(function() {
   var dirPath = TSCORE.Utils.dirName(TSCORE.selectedFiles[0]);
   TSCORE.IO.openDirectory(dirPath);
 });
Example #10
0
 $('#tagTreeMenuAddTagToFile').click(function() {
   TSCORE.TagUtils.addTag(TSCORE.Utils.getUniqueSelectedFiles(), [TSCORE.selectedTag]);
 });
Example #11
0
 }).on('dblclick', function() {
   TSCORE.hideAllDropDownMenus();
   TSCORE.selectedTagData = TSCORE.Config.getTagData($(this).attr('tag'), $(this).attr('parentKey'));
   TSCORE.selectedTag = generateTagValue(TSCORE.selectedTagData);
   TSCORE.TagUtils.addTag(TSCORE.Utils.getUniqueSelectedFiles(), [TSCORE.selectedTag]);
 });
Example #12
0
 return function(e) {
   TSCORE.TagUtils.addTag(TSCORE.Utils.getUniqueSelectedFiles(), [innerTag]);
 };
Example #13
0
 $('#removeTagsButton').click(function() {
   var tags = $('#tags').val().split(',');
   TSCORE.TagUtils.removeTags(TSCORE.Utils.getUniqueSelectedFiles(), tags);
 });
Example #14
0
 TSCORE.showConfirmDialog($.i18n.t('ns.dialogs:cleanFilesTitleConfirm'), $.i18n.t('ns.dialogs:cleanFilesContentConfirm'), function() {
   TSCORE.TagUtils.cleanFilesFromTags(TSCORE.Utils.getUniqueSelectedFiles());
 });
 /**
  * Persists a given binary content to a specified filepath
  * @name saveBinaryFilePromise
  * @method
  * @memberof IOAPI.NWJS
  * @param {string} filePath - the full path of the file which will be saved
  * @param {string} content - content that will be saved
  * @param {string} overwrite - if true existing file path will be overwritten
  * @returns {Promise.<Success, Error>}
  */
 function saveBinaryFilePromise(filePath, content, overwrite) {
   console.log("Saving binary file: " + filePath);
   var buff = TSCORE.Utils.arrayBufferToBuffer(content);
   return saveFilePromise(filePath, buff, overwrite);
 }
Example #16
0
 TSCORE.Utils.getUniqueSelectedFiles().forEach(function(file) {
   selFiles += " " + TSCORE.Utils.baseName(file) + " ,";
 });
Example #17
0
 .done(function(mdData) {
   var modalBody = $("#aboutExtensionModalGraph .modal-body");
   TSCORE.Utils.setMarkDownContent(modalBody, mdData);
 })
Example #18
0
 TSCORE.IO.getFileContent(file, function(buf) {
   var text = TSCORE.Utils.arrayBufferToStr(buf);
   var matched = text.match(/<body[^>]*>([\w|\W]*)<\/body>/im);
   result($(matched[1]).text());
 }, function(err) {
Example #19
0
 function() {
   if (TSCORE.IO.stopWatchingDirectories) {
     TSCORE.IO.stopWatchingDirectories();
   }
   TSCORE.IOUtils.deleteFiles(TSCORE.Utils.getUniqueSelectedFiles());
 }