TagSpaces is an offline, open source, document manager with tagging support
Refactoring
uggrock5f9bd1cbfd60
diff --git a/data/ext/viewThumb/extension.js b/data/ext/viewThumb/extension.jsindex 75d458808..40ae9b574 100644--- a/data/ext/viewThumb/extension.js+++ b/data/ext/viewThumb/extension.js@@ -56,7 +56,7 @@ exports.init = function init() {// On selecting only one file opens it in the viewerif(UIAPI.selectedFiles.length == 1) {- FileViewer.openFile(UIAPI.selectedFiles[0]);+ UIAPI.openFile(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);}}});diff --git a/data/js/core.api.js b/data/js/core.api.jsindex 24a5807eb..e4f8965aa 100644--- a/data/js/core.api.js+++ b/data/js/core.api.js@@ -34,19 +34,11 @@ UIAPI.isFileOpened = false;// Current directory list of filesUIAPI.fileList = [];-UIAPI.fileSortCriteria = "name";-// Last clicked button for removing a tagUIAPI.selectedTag = "";UIAPI.selectedTagData = "";-UIAPI.favIDPrefix = "fav";--UIAPI.fileTable = undefined;--UIAPI.htmlEditor = undefined;-UIAPI.ViewManager = undefined;UIAPI.getDirSeparator = function() {@@ -88,13 +80,6 @@ UIAPI.fileExists = function(fileName) {return false;}-// TODO Remove hideAllContextMenus-UIAPI.hideAllContextMenus = function() {- $('.contextMenu').each(function() {- $(this).hide();- });-}-UIAPI.updateFileBrowserData = function(dirList) {console.debug("Updating the file browser data...");@@ -134,24 +119,6 @@ UIAPI.updateFileBrowserData = function(dirList) {UIAPI.ViewManager.changeView(UIAPI.currentView);}-UIAPI.setFileSortCriteria = function(sortBy) {- console.debug("Setting sort criteris: "+sortBy);- UIAPI.fileSortCriteria = sortBy;-}--/*-UIAPI.updateFileSelection = function() {- console.debug("Updating file selection...");- UIAPI.selectedFiles = [];- UIAPI.fileTable.$('tr.selectedRow').each(function() {- var data = UIAPI.fileTable.fnGetData( this );-// console.debug( "Selected #:" + data[0] );- UIAPI.selectedFiles.push(data[0]);- });- UIAPI.handleElementActivation();-}-*/-UIAPI.changeDirectory = function(newDir) {console.debug("Change direcotory to: "+newDir);var newPath = UIAPI.currentPath;@@ -191,12 +158,29 @@ UIAPI.reloadUI = function() {location.reload();}-UIAPI.layoutContainer = undefined;+UIAPI.openFile = function(filePath) {+// console.debug("Opening file...");+ FileViewer.openFile(filePath);+}++UIAPI.openFileViewer = function() {+ UIAPI.isFileOpened = true;+ layoutContainer.open("east");+}++UIAPI.closeFileViewer = function() {+ UIAPI.isFileOpened = false;+ layoutContainer.close("east");+}++UIAPI.toggleLeftPanel = function() {+ layoutContainer.toggle("west");+}UIAPI.initLayout = function(){console.debug("Initializing Layout...");- UIAPI.layoutContainer = $('#container').layout(+ layoutContainer = $('#container').layout({fxName: "none"@@ -287,12 +271,20 @@ UIAPI.initLayout = function(){});// Closes the viewer area by init- UIAPI.layoutContainer.close("east");+ layoutContainer.close("east");}//return UIAPI;//});+/*+UIAPI.hideAllContextMenus = function() {+ $('.contextMenu').each(function() {+ $(this).hide();+ });+}+*/+/*** Sortingswitch (UIAPI.fileSortCriteria) {diff --git a/data/js/settings.ui.js b/data/js/core.ui.jssimilarity index 94%rename from data/js/settings.ui.jsrename to data/js/core.ui.jsindex 9fe7b6718..d8c2f1eef 100644--- a/data/js/settings.ui.js+++ b/data/js/core.ui.js@@ -1,379 +1,379 @@-/* Copyright (c) 2012 The Tagspaces Authors. All rights reserved.- * Use of this source code is governed by a AGPL3 license that- * can be found in the LICENSE file. */-/*-define([- 'require',- 'exports',- 'module',- 'jsoneditor',-// 'css!jsoneditorcss'-],function(require, exports, module) {-//"use strict";-*/-console.debug("Loading SettingsUI...");--var SettingsUI = (typeof SettingsUI == 'object' && SettingsUI != null) ? SettingsUI : {};--// Init JSON Editor-// TODO variable editor is hardcoded due a bug in the JSONEditor lib-SettingsUI.initJSONEditor = function() {- var edEl = document.getElementById("settingsEditor");- editor = new JSONEditor(edEl);- formatter = new JSONFormatter(document.getElementById("settingsPlainJSON"));-}--SettingsUI.initButtons = function() {- $( "#openSettings" ).button({- text: true,- icons: {- primary: "ui-icon-wrench"- }- })- .click(function() {- SettingsUI.initJSONEditor();- $( "#dialogSetting" ).dialog( "open" );- });-- $( "#openAboutBox" ).button({- text: true,- icons: {- primary: "ui-icon-lightbulb"- }- })- .click(function() {- $( "#dialogAbout" ).dialog( "open" );- });-- $( "#toggleLeftPanel" ).button({- text: false,- icons: {- primary: "ui-icon-bookmark"- }- })- .click(function() {- UIAPI.layoutContainer.toggle("west");- });-}--SettingsUI.initDialogs = function() {- var newDirName = $( "#dirname" );- var newFileName = $( "#newFileName" );- var renamedFileName = $( "#renamedFileName" );-- // TODO evtl add smarttag and the others...- var allFields = $( [] ).add( newDirName );-- var tips = $( ".validateTips" );-- function updateTips( t ) {- tips- .text( t )- .addClass( "ui-state-highlight" );- setTimeout(function() {- tips.removeClass( "ui-state-highlight", 1500 );- }, 500 );- }-- function checkLength( o, n, min, max ) {- if ( o.val().length > max || o.val().length < min ) {- o.addClass( "ui-state-error" );- updateTips( "Length of " + n + " must be between " +- min + " and " + max + "." );- return false;- } else {- return true;- }- }-- function checkRegexp( o, regexp, n ) {- if ( !( regexp.test( o.val() ) ) ) {- o.addClass( "ui-state-error" );- updateTips( n );- return false;- } else {- return true;- }- }-- $( "#fileTypeRadio" ).buttonset();-- var fileContent = undefined;-- $( "#txtFileTypeButton" ).click(function() {- // TODO Add to config options- fileContent = TSSETTINGS.getNewTextFileContent();- //Leave the filename as it is by no extension- if(newFileName.val().lastIndexOf(".")>=0) {- newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".txt");- }- });-- $( "#htmlFileTypeButton" ).click(function() {- // TODO Add to config options- fileContent = TSSETTINGS.getNewHTMLFileContent();- //Leave the filename as it is by no extension- if(newFileName.val().lastIndexOf(".")>=0) {- newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".html");- }- });-- $( "#mdFileTypeButton" ).click(function() {- // TODO Add to config options- fileContent = TSSETTINGS.getNewMDFileContent();- //Leave the filename as it is by no extension- if(newFileName.val().lastIndexOf(".")>=0) {- newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".md");- }- });-- $( "#dialog-filecreate" ).dialog({- autoOpen: false,- height: 250,- width: 450,- modal: true,- buttons: {- "Create": function() {- var bValid = true;- allFields.removeClass( "ui-state-error" );-- bValid = bValid && checkLength( newFileName, "filename", 4, 200 );- // bValid = bValid && checkRegexp( renamedFileName, /^[a-z]([0-9a-z_.])+$/i, "Filename may consist of a-z, 0-9, underscores, begin with a letter." );- if(UIAPI.fileExists(newFileName.val())) {- updateTips("File already exists.");- bValid = false;- }- if ( bValid ) {- IOAPI.saveTextFile(UIAPI.currentPath+UIAPI.getDirSeparator()+$( "#newFileName" ).val(),fileContent);- $( this ).dialog( "close" );- IOAPI.listDirectory(UIAPI.currentPath);- }- },- Cancel: function() {- $( this ).dialog( "close" );- }- },- close: function() {- allFields.val( "" ).removeClass( "ui-state-error" );- },- open: function() {- fileContent = TSSETTINGS.getNewTextFileContent(); // Default new file in text file- $( "#newFileName" ).val(".txt");- }- });-- $( "#dialog-filerename" ).dialog({- autoOpen: false,- height: 220,- width: 450,- modal: true,- buttons: {- "Rename": function() {- var bValid = true;- allFields.removeClass( "ui-state-error" );-- bValid = bValid && checkLength( renamedFileName, "filename", 3, 200 );- // bValid = bValid && checkRegexp( renamedFileName, /^[a-z]([0-9a-z_.])+$/i, "Filename may consist of a-z, 0-9, underscores, begin with a letter." );- if ( bValid ) {- IOAPI.renameFile(- UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0],- UIAPI.currentPath+UIAPI.getDirSeparator()+renamedFileName.val()- );- $( this ).dialog( "close" );- IOAPI.listDirectory(UIAPI.currentPath);- }- },- Cancel: function() {- $( this ).dialog( "close" );- }- },- close: function() {- allFields.val( "" ).removeClass( "ui-state-error" );- },- open: function() {- $( "#renamedFileName" ).val(UIAPI.selectedFiles[0]);- }- });-- $( "#dialog-confirmdelete" ).dialog({- autoOpen: false,- resizable: false,- height:140,- modal: true,- buttons: {- "Delete all items": function() {- IOAPI.deleteElement(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);- $( this ).dialog( "close" );- IOAPI.listDirectory(UIAPI.currentPath);- },- Cancel: function() {- $( this ).dialog( "close" );- }- }- });-- $( "#dialogAddTags" ).dialog({- autoOpen: false,- resizable: false,- height:240,- modal: true,- buttons: {- "Add tags": function() {- var tags = $("#tags").val().split(",");- TSAPI.writeTagsToFile(UIAPI.selectedFiles[0], tags);- IOAPI.listDirectory(UIAPI.currentPath);- $( this ).dialog( "close" );- },- Cancel: function() {- $( this ).dialog( "close" );- }- },- open: function() {-- function split( val ) {- return val.split( /,\s*/ );- }- function extractLast( term ) {- return split( term ).pop();- }-- $( "#tags" )- // don't navigate away from the field on tab when selecting an item- .bind( "keydown", function( event ) {- if ( event.keyCode === $.ui.keyCode.TAB &&- $( this ).data( "autocomplete" ).menu.active ) {- event.preventDefault();- }- })- .autocomplete({- minLength: 0,- source: function( request, response ) {- // delegate back to autocomplete, but extract the last term- response( $.ui.autocomplete.filter(- TSSETTINGS.getAllTags(), extractLast( request.term ) ) );- },- focus: function() {- // prevent value inserted on focus- return false;- },- select: function( event, ui ) {- var terms = split( this.value );- // remove the current input- terms.pop();- // add the selected item- terms.push( ui.item.value );- // add placeholder to get the comma-and-space at the end- terms.push( "" );- this.value = terms.join( ", " );- return false;- }- });- }- });-- $( "#tagTypeRadio" ).buttonset();-- $( "#plainTagTypeButton" ).click(function() {- UIAPI.selectedTag, $( "#newTag" ).datepicker( "destroy" ).val("");- });-- $( "#dateTagTypeButton" ).click(function() {- UIAPI.selectedTag, $( "#newTag" ).datepicker({- showWeek: true,- firstDay: 1,- dateFormat: "yymmdd"- });- });-- $( "#currencyTagTypeButton" ).click(function() {- UIAPI.selectedTag, $( "#newTag" ).datepicker( "destroy" ).val("XEUR")- });-- $( "#dialogEditTag" ).dialog({- autoOpen: false,- resizable: false,- height:240,- modal: true,- buttons: {- "Edit tag": function() {- TSAPI.renameTag(UIAPI.selectedFiles[0], UIAPI.selectedTag, $( "#newTag" ).val());- IOAPI.listDirectory(UIAPI.currentPath);- $( this ).dialog( "close" );- },- Cancel: function() {- $( this ).dialog( "close" );- }- }- });-- $( "#dialogAbout" ).dialog({- autoOpen: false,- resizable: true,- height: 370,- width: 600,- modal: true,- buttons: {- "Back": function() {- $("#aboutIframe").attr("src","about.html");- },- "Close": function() {- $( this ).dialog( "close" );- }- },- open: function() {-- }- });-- $( "#dialogSetting" ).dialog({- autoOpen: false,- resizable: true,- height: 370,- width: 600,- modal: true,- buttons: {-// "Ext. Folder": function() {-// IOAPI.openExtensionsDirectory()-// },- "Editor": function() {- if($("#settingsEditor").is(":hidden") ) {- $("#settingsPlainJSON").hide();- $("#settingsEditor").show();- editor.set(formatter.get());- }- },- "Import/Export": function() {- if($("#settingsPlainJSON").is(":hidden") ) {- formatter.set(editor.get());- $("#settingsPlainJSON").show();- $("#settingsEditor").hide();- }- },- "Default Settings": function() {- if(confirm("Are you sure you want to restore the default application settings?\nAll manually made changes such as tags and taggroups will be lost.")) {- TSSETTINGS.Settings = TSSETTINGS.DefaultSettings;- TSSETTINGS.saveSettings();- UIAPI.reloadUI();- console.debug("Default settings loaded.");- }- },- "Save": function() {- TSSETTINGS.Settings = editor.get();- TSSETTINGS.saveSettings();- UIAPI.reloadUI();- console.debug("Settings saved and UI reloaded.");- $( this ).dialog( "close" );- },- "Cancel": function() {- $( this ).dialog( "close" );- }- },- open: function() {- $("#settingsPlainJSON").hide();- editor.set(TSSETTINGS.Settings);- }- });-}--//return SettingsUI;-//});\ No newline at end of file+/* Copyright (c) 2012 The Tagspaces Authors. All rights reserved.+ * Use of this source code is governed by a AGPL3 license that+ * can be found in the LICENSE file. */+define([+ 'require',+ 'exports',+ 'module',+ 'jsoneditor',+// 'css!jsoneditorcss'+],function(require, exports, module) {+//"use strict";++console.debug("Loading core.ui.js ...");++// Init JSON Editor+// TODO variable editor is hardcoded due a bug in the JSONEditor lib+var initJSONEditor = function() {+ var edEl = document.getElementById("settingsEditor");+ editor = new JSONEditor(edEl);+ formatter = new JSONFormatter(document.getElementById("settingsPlainJSON"));+}++var initButtons = function() {+ $( "#openSettings" ).button({+ text: true,+ icons: {+ primary: "ui-icon-wrench"+ }+ })+ .click(function() {+ initJSONEditor();+ $( "#dialogSetting" ).dialog( "open" );+ });++ $( "#openAboutBox" ).button({+ text: true,+ icons: {+ primary: "ui-icon-lightbulb"+ }+ })+ .click(function() {+ $( "#dialogAbout" ).dialog( "open" );+ });++ $( "#toggleLeftPanel" ).button({+ text: false,+ icons: {+ primary: "ui-icon-bookmark"+ }+ })+ .click(function() {+ UIAPI.toggleLeftPanel();+ });+}++var initDialogs = function() {+ var newDirName = $( "#dirname" );+ var newFileName = $( "#newFileName" );+ var renamedFileName = $( "#renamedFileName" );++ // TODO evtl add smarttag and the others...+ var allFields = $( [] ).add( newDirName );++ var tips = $( ".validateTips" );++ function updateTips( t ) {+ tips+ .text( t )+ .addClass( "ui-state-highlight" );+ setTimeout(function() {+ tips.removeClass( "ui-state-highlight", 1500 );+ }, 500 );+ }++ function checkLength( o, n, min, max ) {+ if ( o.val().length > max || o.val().length < min ) {+ o.addClass( "ui-state-error" );+ updateTips( "Length of " + n + " must be between " ++ min + " and " + max + "." );+ return false;+ } else {+ return true;+ }+ }++ function checkRegexp( o, regexp, n ) {+ if ( !( regexp.test( o.val() ) ) ) {+ o.addClass( "ui-state-error" );+ updateTips( n );+ return false;+ } else {+ return true;+ }+ }++ $( "#fileTypeRadio" ).buttonset();++ var fileContent = undefined;++ $( "#txtFileTypeButton" ).click(function() {+ // TODO Add to config options+ fileContent = TSSETTINGS.getNewTextFileContent();+ //Leave the filename as it is by no extension+ if(newFileName.val().lastIndexOf(".")>=0) {+ newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".txt");+ }+ });++ $( "#htmlFileTypeButton" ).click(function() {+ // TODO Add to config options+ fileContent = TSSETTINGS.getNewHTMLFileContent();+ //Leave the filename as it is by no extension+ if(newFileName.val().lastIndexOf(".")>=0) {+ newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".html");+ }+ });++ $( "#mdFileTypeButton" ).click(function() {+ // TODO Add to config options+ fileContent = TSSETTINGS.getNewMDFileContent();+ //Leave the filename as it is by no extension+ if(newFileName.val().lastIndexOf(".")>=0) {+ newFileName.val(newFileName.val().substring(0,newFileName.val().lastIndexOf("."))+".md");+ }+ });++ $( "#dialog-filecreate" ).dialog({+ autoOpen: false,+ height: 250,+ width: 450,+ modal: true,+ buttons: {+ "Create": function() {+ var bValid = true;+ allFields.removeClass( "ui-state-error" );++ bValid = bValid && checkLength( newFileName, "filename", 4, 200 );+ // bValid = bValid && checkRegexp( renamedFileName, /^[a-z]([0-9a-z_.])+$/i, "Filename may consist of a-z, 0-9, underscores, begin with a letter." );+ if(UIAPI.fileExists(newFileName.val())) {+ updateTips("File already exists.");+ bValid = false;+ }+ if ( bValid ) {+ IOAPI.saveTextFile(UIAPI.currentPath+UIAPI.getDirSeparator()+$( "#newFileName" ).val(),fileContent);+ $( this ).dialog( "close" );+ IOAPI.listDirectory(UIAPI.currentPath);+ }+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ },+ close: function() {+ allFields.val( "" ).removeClass( "ui-state-error" );+ },+ open: function() {+ fileContent = TSSETTINGS.getNewTextFileContent(); // Default new file in text file+ $( "#newFileName" ).val(".txt");+ }+ });++ $( "#dialog-filerename" ).dialog({+ autoOpen: false,+ height: 220,+ width: 450,+ modal: true,+ buttons: {+ "Rename": function() {+ var bValid = true;+ allFields.removeClass( "ui-state-error" );++ bValid = bValid && checkLength( renamedFileName, "filename", 3, 200 );+ // bValid = bValid && checkRegexp( renamedFileName, /^[a-z]([0-9a-z_.])+$/i, "Filename may consist of a-z, 0-9, underscores, begin with a letter." );+ if ( bValid ) {+ IOAPI.renameFile(+ UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0],+ UIAPI.currentPath+UIAPI.getDirSeparator()+renamedFileName.val()+ );+ $( this ).dialog( "close" );+ IOAPI.listDirectory(UIAPI.currentPath);+ }+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ },+ close: function() {+ allFields.val( "" ).removeClass( "ui-state-error" );+ },+ open: function() {+ $( "#renamedFileName" ).val(UIAPI.selectedFiles[0]);+ }+ });++ $( "#dialog-confirmdelete" ).dialog({+ autoOpen: false,+ resizable: false,+ height:140,+ modal: true,+ buttons: {+ "Delete all items": function() {+ IOAPI.deleteElement(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);+ $( this ).dialog( "close" );+ IOAPI.listDirectory(UIAPI.currentPath);+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ }+ });++ $( "#dialogAddTags" ).dialog({+ autoOpen: false,+ resizable: false,+ height:240,+ modal: true,+ buttons: {+ "Add tags": function() {+ var tags = $("#tags").val().split(",");+ TSAPI.writeTagsToFile(UIAPI.selectedFiles[0], tags);+ IOAPI.listDirectory(UIAPI.currentPath);+ $( this ).dialog( "close" );+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ },+ open: function() {++ function split( val ) {+ return val.split( /,\s*/ );+ }+ function extractLast( term ) {+ return split( term ).pop();+ }++ $( "#tags" )+ // don't navigate away from the field on tab when selecting an item+ .bind( "keydown", function( event ) {+ if ( event.keyCode === $.ui.keyCode.TAB &&+ $( this ).data( "autocomplete" ).menu.active ) {+ event.preventDefault();+ }+ })+ .autocomplete({+ minLength: 0,+ source: function( request, response ) {+ // delegate back to autocomplete, but extract the last term+ response( $.ui.autocomplete.filter(+ TSSETTINGS.getAllTags(), extractLast( request.term ) ) );+ },+ focus: function() {+ // prevent value inserted on focus+ return false;+ },+ select: function( event, ui ) {+ var terms = split( this.value );+ // remove the current input+ terms.pop();+ // add the selected item+ terms.push( ui.item.value );+ // add placeholder to get the comma-and-space at the end+ terms.push( "" );+ this.value = terms.join( ", " );+ return false;+ }+ });+ }+ });++ $( "#tagTypeRadio" ).buttonset();++ $( "#plainTagTypeButton" ).click(function() {+ UIAPI.selectedTag, $( "#newTag" ).datepicker( "destroy" ).val("");+ });++ $( "#dateTagTypeButton" ).click(function() {+ UIAPI.selectedTag, $( "#newTag" ).datepicker({+ showWeek: true,+ firstDay: 1,+ dateFormat: "yymmdd"+ });+ });++ $( "#currencyTagTypeButton" ).click(function() {+ UIAPI.selectedTag, $( "#newTag" ).datepicker( "destroy" ).val("XEUR")+ });++ $( "#dialogEditTag" ).dialog({+ autoOpen: false,+ resizable: false,+ height:240,+ modal: true,+ buttons: {+ "Edit tag": function() {+ TSAPI.renameTag(UIAPI.selectedFiles[0], UIAPI.selectedTag, $( "#newTag" ).val());+ IOAPI.listDirectory(UIAPI.currentPath);+ $( this ).dialog( "close" );+ },+ Cancel: function() {+ $( this ).dialog( "close" );+ }+ }+ });++ $( "#dialogAbout" ).dialog({+ autoOpen: false,+ resizable: true,+ height: 370,+ width: 600,+ modal: true,+ buttons: {+ "Back": function() {+ $("#aboutIframe").attr("src","about.html");+ },+ "Close": function() {+ $( this ).dialog( "close" );+ }+ },+ open: function() {++ }+ });++ $( "#dialogSetting" ).dialog({+ autoOpen: false,+ resizable: true,+ height: 370,+ width: 600,+ modal: true,+ buttons: {+// "Ext. Folder": function() {+// IOAPI.openExtensionsDirectory()+// },+ "Editor": function() {+ if($("#settingsEditor").is(":hidden") ) {+ $("#settingsPlainJSON").hide();+ $("#settingsEditor").show();+ editor.set(formatter.get());+ }+ },+ "Import/Export": function() {+ if($("#settingsPlainJSON").is(":hidden") ) {+ formatter.set(editor.get());+ $("#settingsPlainJSON").show();+ $("#settingsEditor").hide();+ }+ },+ "Default Settings": function() {+ if(confirm("Are you sure you want to restore the default application settings?\nAll manually made changes such as tags and taggroups will be lost.")) {+ TSSETTINGS.Settings = TSSETTINGS.DefaultSettings;+ TSSETTINGS.saveSettings();+ UIAPI.reloadUI();+ console.debug("Default settings loaded.");+ }+ },+ "Save": function() {+ TSSETTINGS.Settings = editor.get();+ TSSETTINGS.saveSettings();+ UIAPI.reloadUI();+ console.debug("Settings saved and UI reloaded.");+ $( this ).dialog( "close" );+ },+ "Cancel": function() {+ $( this ).dialog( "close" );+ }+ },+ open: function() {+ $("#settingsPlainJSON").hide();+ editor.set(TSSETTINGS.Settings);+ }+ });+}++// Autoinitialization+initButtons();+initDialogs();++});\ No newline at end of filediff --git a/data/js/fileviewer.ui.js b/data/js/fileviewer.ui.jsindex 98cc58307..4b02f326a 100644--- a/data/js/fileviewer.ui.js+++ b/data/js/fileviewer.ui.js@@ -10,18 +10,20 @@ console.debug("Loading FileViewer...");var FileViewer = (typeof FileViewer == 'object' && FileViewer != null) ? FileViewer : {};-FileViewer.openFile = function(fileName) {- console.debug("Opening file: "+fileName);+FileViewer.openFile = function(filePath) {+ console.debug("Opening file: "+filePath);FileViewer.isEditMode = false;+ var fileName = filePath.substring(filePath.lastIndexOf(UIAPI.getDirSeparator())+1,filePath.length);+var openedFilePath = UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;// TODO replace \\ to \ in filenamesopenedFilePath.replace("\\\\","\\");$("#selectedFilePath").val(openedFilePath);var fileExt = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length).toLowerCase();- var filePath = UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;+// var filePath = UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;this.constructFileViewerUI(fileName, filePath);@@ -29,11 +31,7 @@ FileViewer.openFile = function(fileName) {var viewerExt = TSSETTINGS.getFileTypeViewer(fileExt);console.debug("File Viewer: "+viewerExt);- // TODO Consider page width by opening, e.g. responsive design- UIAPI.layoutContainer.open("east");- // UIAPI.layoutContainer.close("west");-- UIAPI.isFileOpened = true;+ UIAPI.openFileViewer();$( "#viewer" ).empty();if(!viewerExt) {@@ -219,7 +217,7 @@ FileViewer.addEditButton = function(container, fileName) {}};FileViewer.saveFile(fileName);- FileViewer.openFile(fileName);+ UIAPI.openFile(UIAPI.currentPath+UIAPI.getDirSeparator()+fileName);}}$( this ).button( "option", options );@@ -254,17 +252,14 @@ FileViewer.addCloseButton = function(container) {if(confirm("If you confirm, all made changes will be lost.")){// Cleaning the viewer/editordocument.getElementById("viewer").innerHTML = "";- UIAPI.isFileOpened = false;- UIAPI.layoutContainer.open("west");- UIAPI.layoutContainer.close("east");+ UIAPI.closeFileViewer();FileViewer.isEditMode = false;}} else {// Cleaning the viewer/editordocument.getElementById("viewer").innerHTML = "";UIAPI.isFileOpened = false;- UIAPI.layoutContainer.open("west");- UIAPI.layoutContainer.close("east");+ UIAPI.closeFileViewer();FileViewer.isEditMode = false;}});diff --git a/data/js/ioapi.chrome.js b/data/js/ioapi.chrome.jsindex 3ad2bb4e9..7978d7150 100644--- a/data/js/ioapi.chrome.js+++ b/data/js/ioapi.chrome.js@@ -159,4 +159,10 @@ IOAPI.openExtensionsDirectory = function() {// TODO implement openExtensionsDirectoryconsole.debug("Open extensions directory functionality not implemented on chrome yet!");alert("Open extensions directory functionality not implemented on chrome yet!");+}++IOAPI.createDirectoryIndex = function(dirPath) {+ // TODO implement createDirectoryIndex+ console.debug("Directory indexing functionality not implemented on chrome yet!");+ alert("Directory indexing functionality not implemented on chrome yet!");}\ No newline at end of filediff --git a/data/js/main.js b/data/js/main.jsindex 6c3cc2837..6134584ca 100644--- a/data/js/main.js+++ b/data/js/main.js@@ -30,16 +30,18 @@ var initApp = function(){require(["js/ioapi.cordova"]);- }+ }++ var layoutContainer = undefined;// TODO refactor all libs for integration of backbone.jsrequire([- "js/viewmanager",+ "js/view.manager","js/settings.api","js/fileviewer.ui",+ "js/core.ui","js/tags.ui",- "js/settings.ui",- "js/misc.ui",+ "js/core.api","js/tagspace.api","js/directories.ui",],@@ -52,9 +54,6 @@ var initApp = function(){DirectoriesUI.initDialogs();DirectoriesUI.initButtons();DirectoriesUI.initContextMenus();-- SettingsUI.initButtons();- SettingsUI.initDialogs();TSSETTINGS.loadSettingsLocalStorage();diff --git a/data/js/messaging.mozilla.js b/data/js/messaging.mozilla.jsindex 39673c693..b8b531b0c 100644--- a/data/js/messaging.mozilla.js+++ b/data/js/messaging.mozilla.js@@ -45,7 +45,7 @@ document.documentElement.addEventListener("addon-message1", function(event) {// message.content contains the name of the file after the renameUIAPI.selectedFiles[0] = message.content;if(UIAPI.isFileOpened) {- FileViewer.openFile(UIAPI.selectedFiles[0]);+ UIAPI.openFile(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);}} else {UIAPI.updateLogger("Rename failed");@@ -83,7 +83,7 @@ document.documentElement.addEventListener("addon-message1", function(event) {case "indexDirectory":if(message.success){console.debug("Directory Index: "+JSON.stringify(message.content));- // UIAPI.updateFileBrowserData(message.content);+ UIAPI.ViewManager.updateIndexData(message.content);} else {UIAPI.updateLogger("Indexing directory failed");}diff --git a/data/js/viewBasic.js b/data/js/view.basic.jssimilarity index 90%rename from data/js/viewBasic.jsrename to data/js/view.basic.jsindex 179a90923..db6a4d969 100644--- a/data/js/viewBasic.js+++ b/data/js/view.basic.js@@ -163,7 +163,6 @@ exports.init = function init() {filter: 'tr',start: function() {console.debug("Start selecting");- //UIAPI.hideAllContextMenus();UIAPI.selectedFiles = [];$('#'+exports.ID+"FileTable tbody tr").each(function(){$(this).removeClass('selectedRow');@@ -174,7 +173,7 @@ exports.init = function init() {var index = $("#fileTable tr").index(this) - 1;$('#fileTable tbody tr:eq('+index+')').toggleClass('selectedRow');$('#fileTable tbody tr:eq('+index+')').toggleClass('ui-selected');- var rowData = UIAPI.fileTable.fnGetData( this );+ var rowData = fileTable.fnGetData( this );// Add the filename which is located in the first column to the list of selected filenamesUIAPI.selectedFiles.push(rowData[0]);});@@ -218,12 +217,7 @@ exports.load = function load() {console.debug("Opening file...");var rowData = fileTable.fnGetData( this );- // TODO use central API- $("#selectedFilePath").val(UIAPI.currentPath+UIAPI.getDirSeparator()+rowData[0]);-- // TODO use central API not fileView- FileViewer.openFile(rowData[0]);-+ UIAPI.openFile(UIAPI.currentPath+UIAPI.getDirSeparator()+rowData[0]);} );fileTable.$('.fileButton')@@ -358,14 +352,6 @@ var initButtons = function() {$( "#dialog-filecreate" ).dialog( "open" );});-/* $( "#openFileButton" ).button({- text: true,- disabled: true- })- .click(function() {- FileViewer.openFile(UIAPI.selectedFiles[0]);- }); */-$( "#clearFilterButton" ).button({text: false,disabled: false,@@ -375,7 +361,7 @@ var initButtons = function() {}).click(function() {$( "#filterBox" ).val( "" );- UIAPI.fileTable.fnFilter( "" );+ fileTable.fnFilter( "" );});}@@ -385,38 +371,29 @@ var initContextMenus = function() {var commandName = ui.item.attr( "action" );switch (commandName) {case "addTag":- $( this ).hide();console.debug("Adding tag...");$("#tags").val("");$( "#dialogAddTags" ).dialog( "open" );break;case "openFile":- $( this ).hide();console.debug("Opening file...");- FileViewer.openFile(UIAPI.selectedFiles[0]);+ UIAPI.openFile(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);break;case "openDirectory":- $( this ).hide();console.debug("Opening parent directory...");IOAPI.openDirectory(UIAPI.currentPath);break;case "renameFile":- $( this ).hide();console.debug("Renaming file...");$( "#dialog-filerename" ).dialog( "open" );break;case "deleteFile":- $( this ).hide();console.debug("Deleting file...");$( "#dialog-confirmdelete" ).dialog( "open" );break;- case "closeMenu":- $( this ).hide();- break;default:break;}- $( this ).hide();}});@@ -425,24 +402,13 @@ var initContextMenus = function() {var commandName = ui.item.attr( "action" );switch (commandName) {case "openFile":- $( this ).hide();- console.debug("Opening file...");- FileViewer.openFile(UIAPI.selectedFiles[0]);- break;- case "editFile":- $( this ).hide();- console.debug("Editing file...");- UIAPI.editFile(UIAPI.selectedFiles[0]);+ UIAPI.openFile(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);break;case "addTag":- $( this ).hide();console.debug("Adding tag...");$("#tags").val("");$( "#dialogAddTags" ).dialog( "open" );break;- case "closeMenu":- $( this ).hide();- break;default:break;}diff --git a/data/js/view.manager.js b/data/js/view.manager.jsindex fd8a7869f..639bebf25 100644--- a/data/js/view.manager.js+++ b/data/js/view.manager.js@@ -8,10 +8,12 @@ define([],function(require, exports, module) {"use strict";-console.debug("Loading viewmanager.js");+console.debug("Loading view.manager.js");var views = undefined;+var searchViewer = undefined;+exports.initViews = function initViews() {views = [];@@ -22,7 +24,7 @@ exports.initViews = function initViews() {var defaultViewLoaded = false;- require(["js/viewBasic"], function(viewer) {+ require(["js/view.basic"], function(viewer) {views.push(viewer);initViewsUI(viewer);viewer.init();@@ -34,7 +36,13 @@ exports.initViews = function initViews() {$( "#"+viewer.ID+"Container" ).show();$( "#"+viewer.ID+"Toolbar" ).show();+ });+ require(["js/view.search"], function(viewer) {+ views.push(viewer);+ initViewsUI(viewer);+ viewer.init();+ searchViewer = viewer;});for (var i=0; i < TSSETTINGS.Settings["extensions"].length; i++) {@@ -46,18 +54,46 @@ exports.initViews = function initViews() {viewer.init();});}- }-- require(["js/viewSearch"], function(viewer) {- views.push(viewer);- initViewsUI(viewer);- viewer.init();- });+ }$( "#viewSwitcher" ).buttonset();}-function initViewsUI(viewer) {+exports.updateIndexData = function updateIndexData(index) {+ console.debug("Enhancing directory index...");+ var enhancedIndex = [];+ var tags = undefined;+ var ext = undefined;+ var title = undefined;+ var fileSize = undefined;+ var fileLMDT = undefined;+ var path = undefined;+ for (var i=0; i < index.length; i++) {+ if (index[i].type == "file"){+ // Considering Unix HiddenEntries (. in the beginning of the filename)+ if (TSSETTINGS.Settings["showUnixHiddenEntries"] ||+ (!TSSETTINGS.Settings["showUnixHiddenEntries"] && (index[i].name.indexOf(".") != 0))) {+ tags = TSAPI.extractTags(index[i].name);+ title = TSAPI.extractTitle(index[i].name);+ if(index[i].name.lastIndexOf(".") > 0) {+ ext = index[i].name.substring(index[i].name.lastIndexOf(".")+1,index[i].name.length);+ } else {+ ext = "";+ }+ fileSize = index[i].size;+ fileLMDT = index[i].lmdt;+ path = index[i].path;+ if(fileSize == undefined) fileSize = "";+ if(fileLMDT == undefined) fileLMDT = "";+ var entry = [index[i].name,fileSize,fileLMDT,title,tags,ext,path];+ enhancedIndex.push(entry);+ }+ }+ }+ searchViewer.updateIndexData(enhancedIndex);+}++var initViewsUI = function(viewer) {console.debug("Init UI for "+viewer.ID);//var radioChecked = true;diff --git a/data/js/view.search.js b/data/js/view.search.jsindex 887955550..88c4d6638 100644--- a/data/js/view.search.js+++ b/data/js/view.search.js@@ -37,13 +37,13 @@ exports.init = function init() {viewFooter.empty();viewToolbar.append($("<button>", {- text: "New",+ text: "Reindex",disabled: true,- title: "Create new file",- id: exports.ID+"CreateFileButton",+ title: "Reindex current favorite folder.",+ id: exports.ID+"ReIndexButton",}));- viewToolbar.append($("<span>", {+/* viewToolbar.append($("<span>", {id: exports.ID+"ModeSwitcher",}));@@ -95,7 +95,7 @@ exports.init = function init() {.click(function() {viewMode = "files"exports.load();- })+ }) */viewToolbar.append($("<span>", {@@ -130,7 +130,7 @@ exports.init = function init() {{ "sTitle": "Title" },{ "sTitle": "Tags" },{ "sTitle": "Ext" },- // { "sTitle": "Selection", "mData": null }+ { "sTitle": "Path" },],"aoColumnDefs": [{ // Filename column@@ -163,7 +163,6 @@ exports.init = function init() {filter: 'tr',start: function() {console.debug("Start selecting");- //UIAPI.hideAllContextMenus();UIAPI.selectedFiles = [];$('#'+exports.ID+"FileTable tbody tr").each(function(){$(this).removeClass('selectedRow');@@ -174,7 +173,7 @@ exports.init = function init() {var index = $("#fileTable tr").index(this) - 1;$('#fileTable tbody tr:eq('+index+')').toggleClass('selectedRow');$('#fileTable tbody tr:eq('+index+')').toggleClass('ui-selected');- var rowData = UIAPI.fileTable.fnGetData( this );+ var rowData = fileTable.fnGetData( this );// Add the filename which is located in the first column to the list of selected filenamesUIAPI.selectedFiles.push(rowData[0]);});@@ -205,25 +204,24 @@ exports.load = function load() {// Purging file tablefileTable.fnClearTable();++ $( "#"+exports.ID+"ReIndexButton" ).button( "enable" );+ UIAPI.hideLoadingAnimation();+// $( "#"+exports.ID+"ReIndexButton" ).button( "disable" );+// IOAPI.createDirectoryIndex(UIAPI.currentPath);+}- fileTable.fnAddData( UIAPI.fileList );-- fileTable.fnSetColumnVis(0, true);- fileTable.fnSetColumnVis(1, true);- fileTable.fnSetColumnVis(2, true);- fileTable.fnSetColumnVis(3, true);- fileTable.fnSetColumnVis(4, true);+exports.updateIndexData = function updateIndexData(index) {+ console.debug("Updating index data.");+ fileTable.fnAddData( index );++// fileTable.fnSetColumnVis(0, true);fileTable.$('tr').dblclick( function() {console.debug("Opening file...");var rowData = fileTable.fnGetData( this );- // TODO use central API- $("#selectedFilePath").val(UIAPI.currentPath+UIAPI.getDirSeparator()+rowData[0]);-- // TODO use central API not fileView- FileViewer.openFile(rowData[0]);-+ UIAPI.openFile(rowData[6]);} );fileTable.$('.fileButton')@@ -250,27 +248,11 @@ exports.load = function load() {} ).dropdown( 'attach' , '#tagMenu' );- if(viewMode == "files") {- console.debug("Change to FileView");- fileTable.fnSetColumnVis(0, true);- fileTable.fnSetColumnVis(1, true);- fileTable.fnSetColumnVis(2, true);- fileTable.fnSetColumnVis(3, false);- fileTable.fnSetColumnVis(4, false);- } else if (viewMode == "tags") {- console.debug("Change to TagView");- fileTable.fnSetColumnVis(0, false);- fileTable.fnSetColumnVis(1, false);- fileTable.fnSetColumnVis(2, false);- fileTable.fnSetColumnVis(3, true);- fileTable.fnSetColumnVis(4, true);- }-$('#'+exports.ID+"FileTable_wrapper").show();- $( "#"+exports.ID+"CreateFileButton" ).button( "enable" );+ $( "#"+exports.ID+"ReIndexButton" ).button( "enable" );- UIAPI.hideLoadingAnimation();+ UIAPI.hideLoadingAnimation();}exports.setFileFilter = function setFileFilter(filter) {@@ -348,24 +330,17 @@ var openFileMenu = function(tagButton, fileName) {var initButtons = function() {// Initialize file buttons- $( "#"+exports.ID+"CreateFileButton" ).button({+ $( "#"+exports.ID+"ReIndexButton" ).button({text: true,icons: {- primary: "ui-icon-document"+ primary: "ui-icon-refresh"}}).click(function() {- $( "#dialog-filecreate" ).dialog( "open" );+ $( "#"+exports.ID+"ReIndexButton" ).button( "disable" );+ IOAPI.createDirectoryIndex(UIAPI.currentPath);});--/* $( "#openFileButton" ).button({- text: true,- disabled: true- })- .click(function() {- FileViewer.openFile(UIAPI.selectedFiles[0]);- }); */-+$( "#clearFilterButton" ).button({text: false,disabled: false,@@ -375,7 +350,7 @@ var initButtons = function() {}).click(function() {$( "#filterBox" ).val( "" );- UIAPI.fileTable.fnFilter( "" );+ fileTable.fnFilter( "" );});}@@ -385,38 +360,28 @@ var initContextMenus = function() {var commandName = ui.item.attr( "action" );switch (commandName) {case "addTag":- $( this ).hide();console.debug("Adding tag...");$("#tags").val("");$( "#dialogAddTags" ).dialog( "open" );break;case "openFile":- $( this ).hide();- console.debug("Opening file...");- FileViewer.openFile(UIAPI.selectedFiles[0]);+ UIAPI.openFile(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);break;case "openDirectory":- $( this ).hide();console.debug("Opening parent directory...");IOAPI.openDirectory(UIAPI.currentPath);break;case "renameFile":- $( this ).hide();console.debug("Renaming file...");$( "#dialog-filerename" ).dialog( "open" );break;case "deleteFile":- $( this ).hide();console.debug("Deleting file...");$( "#dialog-confirmdelete" ).dialog( "open" );break;- case "closeMenu":- $( this ).hide();- break;default:break;}- $( this ).hide();}});@@ -425,24 +390,13 @@ var initContextMenus = function() {var commandName = ui.item.attr( "action" );switch (commandName) {case "openFile":- $( this ).hide();- console.debug("Opening file...");- FileViewer.openFile(UIAPI.selectedFiles[0]);- break;- case "editFile":- $( this ).hide();- console.debug("Editing file...");- UIAPI.editFile(UIAPI.selectedFiles[0]);+ UIAPI.openFile(UIAPI.currentPath+UIAPI.getDirSeparator()+UIAPI.selectedFiles[0]);break;case "addTag":- $( this ).hide();console.debug("Adding tag...");$("#tags").val("");$( "#dialogAddTags" ).dialog( "open" );break;- case "closeMenu":- $( this ).hide();- break;default:break;}diff --git a/lib/ioutils.js b/lib/ioutils.jsindex 1b41da177..0a592b437 100644--- a/lib/ioutils.js+++ b/lib/ioutils.js@@ -67,12 +67,14 @@ function scanDirectory(dirPath, index) {path = filesIO.join(dirPath,dirList[i]);var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsIFile);- file.initWithPath(filesIO.join(dirPath,dirList[i]));+ var currentPath = filesIO.join(dirPath,dirList[i])+ file.initWithPath(currentPath);index.push({"name": file.leafName,"type": file.isFile()?"file":"directory","size": file.fileSize,- "lmdt": file.lastModifiedTime+ "lmdt": file.lastModifiedTime,+ "path": currentPath});if(!file.isFile()) {