Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Adding default perspective per locaiton

Ilianfa027f0e9c1e
diff --git a/data/js/directories.ui.js b/data/js/directories.ui.js
index efa8c9b4a..e8852ab6e 100644
--- a/data/js/directories.ui.js
+++ b/data/js/directories.ui.js
@@ -12,16 +12,16 @@ define(function(require, exports, module) {
var dir4ContextMenu = null;
- var currentLocationName = undefined;
+// var currentLocationName = undefined;
- function openConnection(path) {
+ function openLocation(path) {
console.log("Opening connection in : "+path);
- currentLocationName = TSCORE.Config.getConnectionName(path);
+ var currentLocation = TSCORE.Config.getLocation(path);
- document.title = currentLocationName + " | " + TSCORE.Config.DefaultSettings.appName;
+ document.title = currentLocation.name + " | " + TSCORE.Config.DefaultSettings.appName;
- $( "#locationName" ).text(currentLocationName);
+ $( "#locationName" ).text(currentLocation.name);
$( "#locationName" ).attr("title",path);
// Open the directory locations panel
@@ -30,6 +30,12 @@ define(function(require, exports, module) {
// Clears the directory history
directoryHistory = new Array();
navigateToDirectory(path);
+
+ // Handle open default perspective for a location
+ var defaultPerspective = currentLocation.perspective;
+ if(defaultPerspective != undefined) {
+ TSCORE.PerspectiveManager.changePerspective(defaultPerspective);
+ }
}
// Updates the directory subtree
@@ -291,14 +297,34 @@ define(function(require, exports, module) {
}
+ function createLocation() {
+ var locationPath = $("#folderLocation").val();
+ TSCORE.Config.createLocation(
+ $("#connectionName").val(),
+ locationPath,
+ $("#locationPerspective").val()
+ );
+
+ // Enable the UI behavior by not empty location list
+ $( "#createNewLocation" ).attr("title", "Connect New Location");
+ $( "#createNewLocation" ).removeClass("createFirstLocation");
+ $( "#createNewLocation" ).tooltip( "destroy" );
+ $( "#locationName" ).prop('disabled', false);
+ $( "#selectLocation" ).prop('disabled', false);
+
+ initConnections();
+ openLocation(locationPath);
+ }
+
function editLocation() {
- TSCORE.Config.editConnection(
+ TSCORE.Config.editLocation(
$("#connectionName2").attr("oldName"),
$("#connectionName2").val(),
- $("#folderLocation2").val()
+ $("#folderLocation2").val(),
+ $("#locationPerspective2").val()
);
initConnections();
- openConnection($("#folderLocation2").val());
+ openLocation($("#folderLocation2").val());
}
function showLocationEditDialog(name,path) {
@@ -313,7 +339,8 @@ define(function(require, exports, module) {
$("#selectLocalDirectory2").on("click",function(e) {
e.preventDefault();
TSCORE.IO.selectDirectory();
- });
+ });
+
$( "#saveLocationButton" ).on("click", function() {
editLocation();
@@ -324,6 +351,18 @@ define(function(require, exports, module) {
showDeleteFolderConnectionDialog();
});
}
+
+ var selectedPerspectiveId = TSCORE.Config.getLocation(path).perspective;
+ $("#locationPerspective2").empty();
+ TSCORE.Config.getActivatedPerspectiveExtensions().forEach( function(value) {
+ if (selectedPerspectiveId == value.id) {
+ $("#locationPerspective2").append($("<option>").attr("selected","selected").text(value.id).val(value.id));
+ } else {
+ $("#locationPerspective2").append($("<option>").text(value.id).val(value.id));
+ }
+ }
+ );
+
$("#connectionName2").val(name);
$("#connectionName2").attr("oldName",name);
$("#folderLocation2").val(path);
@@ -345,19 +384,12 @@ define(function(require, exports, module) {
TSCORE.IO.selectDirectory();
});
- $( "#createFolderConnectionButton" ).on("click", function() {
- var locationPath = $("#folderLocation").val();
- TSCORE.Config.createConnection($("#connectionName").val(), locationPath);
-
- // Disabling the UI behavior by empty location list
- $( "#createNewLocation" ).attr("title", "Connect New Location");
- $( "#createNewLocation" ).removeClass("createFirstLocation");
- $( "#createNewLocation" ).tooltip( "destroy" );
- $( "#locationName" ).prop('disabled', false);
- $( "#selectLocation" ).prop('disabled', false);
-
- initConnections();
- openConnection(locationPath);
+ TSCORE.Config.getActivatedPerspectiveExtensions().forEach( function(value) {
+ $("#locationPerspective").append($("<option>").text(value.id).val(value.id));
+ });
+
+ $( "#createFolderConnectionButton" ).on("click", function() {
+ createLocation();
});
if(isCordova) {
@@ -400,13 +432,13 @@ define(function(require, exports, module) {
function deleteLocation(name) {
console.log("Deleting folder connection..");
- TSCORE.Config.deleteConnection(name);
+ TSCORE.Config.deleteLocation(name);
initConnections();
//Opens the first location in the settings after deleting a location
if(TSCORE.Config.Settings["tagspacesList"].length > 0) {
- openConnection(TSCORE.Config.Settings["tagspacesList"][0].path);
+ openLocation(TSCORE.Config.Settings["tagspacesList"][0].path);
} else {
closeCurrentLocation();
}
@@ -414,18 +446,15 @@ define(function(require, exports, module) {
function closeCurrentLocation() {
console.log("Closing location..");
- currentLocationName = undefined;
$("#locationName").text("Choose Location");
$("#locationName").attr("title","");
- $("#locationContent").empty();
-
+ $("#locationContent").empty();
}
-
function showDeleteFolderConnectionDialog(name) {
TSCORE.showConfirmDialog(
"Delete connection to folder",
- "Do you want to delete this connection to a folder?",
+ "Do you want to delete the connection "+$("#connectionName2").attr("oldName")+"?",
function() {
deleteLocation($("#connectionName2").attr("oldName"));
}
@@ -457,7 +486,7 @@ define(function(require, exports, module) {
class: "btn btn-default"
} )
.click(function() {
- openConnection($(this).attr( "path" ));
+ openLocation($(this).attr( "path" ));
})
.prepend("<i class='fa fa-bookmark'></i>&nbsp;")
)
@@ -483,14 +512,11 @@ define(function(require, exports, module) {
$( "#createNewLocation" ).click(function() {
showLocationCreateDialog();
});
-
- $( "#deleteConnection" ).click(function() {
- showDeleteFolderConnectionDialog();
- });
+
}
// Public API definition
- exports.openConnection = openConnection;
+ exports.openLocation = openLocation;
exports.closeCurrentLocation = closeCurrentLocation;
exports.updateSubDirs = updateSubDirs;
exports.initUI = initUI;
diff --git a/data/js/settings.api.js b/data/js/settings.api.js
index 0b97b2988..0134bd9da 100644
--- a/data/js/settings.api.js
+++ b/data/js/settings.api.js
@@ -31,9 +31,10 @@ define(function(require, exports, module) {
*/
};
- var connectionTemplate = {
+ var locationTemplate = {
"name": undefined,
- "path": undefined
+ "path": undefined,
+ "perspective": undefined
};
var tagGroupTemplate = {
@@ -276,6 +277,13 @@ define(function(require, exports, module) {
return exports.Settings["ootbPerspectives"];
};
+ var getActivatedPerspectiveExtensions = function() {
+ if(exports.Settings["perspectives"] == null) {
+ exports.Settings["perspectives"] = exports.DefaultSettings["perspectives"];
+ }
+ return exports.Settings["perspectives"];
+ };
+
var getViewerExtensions = function() {
if(exports.Settings["ootbViewers"] == null) {
exports.Settings["ootbViewers"] = exports.DefaultSettings["ootbViewers"];
@@ -571,36 +579,37 @@ define(function(require, exports, module) {
saveSettings();
};
- var createConnection = function(name, location) {
- var newConnectionModel = JSON.parse( JSON.stringify(connectionTemplate));
+ var createLocation = function(name, location, perspectiveId) {
+ var newLocationModel = JSON.parse( JSON.stringify(locationTemplate));
name = name.replace("\\", "\\\\");
name = name.replace("\\\\\\", "\\\\");
name = name.replace("\\\\\\\\", "\\\\");
- newConnectionModel.name = name;
- newConnectionModel.path = location;
- var createLocation = true;
+ newLocationModel.name = name;
+ newLocationModel.path = location;
+ newLocationModel.perspective = perspectiveId;
+ var createLoc = true;
exports.Settings["tagspacesList"].forEach(function (value, index) {
- if(value.path == newConnectionModel.path) {
+ if(value.path == newLocationModel.path) {
TSCORE.showAlertDialog("Selected path is already used by a location!","Duplicated Location Path");
- createLocation = false;
+ createLoc = false;
}
- if(value.name == newConnectionModel.name) {
+ if(value.name == newLocationModel.name) {
TSCORE.showAlertDialog("Selected location name is already used by a location!","Duplicated Location Name");
- createLocation = false;
+ createLoc = false;
}
});
- if(createLocation) {
- exports.Settings["tagspacesList"].push(newConnectionModel);
+ if(createLoc) {
+ exports.Settings["tagspacesList"].push(newLocationModel);
saveSettings();
}
};
- var editConnection = function(oldName, newName, newLocation) {
+ var editLocation = function(oldName, newName, newLocation, perspectiveId) {
// name = name.replace("\\", "\\\\");
// name = name.replace("\\\\\\", "\\\\");
// name = name.replace("\\\\\\\\", "\\\\");
console.log("Old Name: "+oldName+" New Name: "+newName+" New Loc: "+newLocation);
- var editLocation = true;
+ var editLoc = true;
exports.Settings["tagspacesList"].forEach(function (value, index) {
/* if(value.path == newLocation) {
TSCORE.showAlertDialog("Selected path is already used by a location!","Duplicated Location Path");
@@ -608,33 +617,32 @@ define(function(require, exports, module) {
} */
if(value.name == newName && value.name != oldName) {
TSCORE.showAlertDialog("Selected location name is already used by a location!","Duplicated Location Name");
- editLocation = false;
+ editLoc = false;
}
});
- if(editLocation) {
+ if(editLoc) {
exports.Settings["tagspacesList"].forEach(function (value, index) {
if(value.name == oldName) {
value.name = newName;
value.path = newLocation;
+ value.perspective = perspectiveId;
}
});
saveSettings();
}
};
- var getConnectionName = function(connectionPath) {
- var connectionName = undefined;
+ var getLocation = function(path) {
+ var location;
exports.Settings["tagspacesList"].forEach(function (value, index) {
- if(value.path == connectionPath) {
- connectionName = value.name;
+ if(value.path == path) {
+ location = value;
}
});
- if(connectionName != undefined) {
- return connectionName;
- }
+ return location;
};
- var deleteConnection = function(name) {
+ var deleteLocation = function(name) {
for(var i=0; i < exports.Settings["tagspacesList"].length; i++) {
console.log("Traversing connections "+exports.Settings["tagspacesList"][i].name+" searching for "+name);
if(exports.Settings["tagspacesList"][i].name == name) {
@@ -713,6 +721,7 @@ define(function(require, exports, module) {
exports.setSupportedFileTypes = setSupportedFileTypes;
exports.getPerspectiveExtensions = getPerspectiveExtensions;
+ exports.getActivatedPerspectiveExtensions = getActivatedPerspectiveExtensions;
exports.getViewerExtensions = getViewerExtensions;
exports.getEditorExtensions = getEditorExtensions;
@@ -736,10 +745,10 @@ define(function(require, exports, module) {
exports.moveTagGroup = moveTagGroup;
exports.createTagGroup = createTagGroup;
exports.duplicateTagGroup = duplicateTagGroup;
- exports.createConnection = createConnection;
- exports.editConnection = editConnection;
- exports.deleteConnection = deleteConnection;
- exports.getConnectionName = getConnectionName;
+ exports.createLocation = createLocation;
+ exports.editLocation = editLocation;
+ exports.deleteLocation = deleteLocation;
+ exports.getLocation = getLocation;
exports.updateSettingMozillaPreferences = updateSettingMozillaPreferences;
exports.loadSettingsLocalStorage = loadSettingsLocalStorage;
exports.loadDefaultSettings = loadDefaultSettings;
diff --git a/data/js/settings.default.js b/data/js/settings.default.js
index a021448a9..3982fc3f9 100644
--- a/data/js/settings.default.js
+++ b/data/js/settings.default.js
@@ -9,7 +9,7 @@ exports.defaultSettings = {
"appVersion": "1.6",
"appBuild": "1685",
"settingsVersion": 2,
- "newTextFileContent": "File created with TagSpaces!",
+ "newTextFileContent": "Text file created with TagSpaces!",
"newHTMLFileContent": "<html><head><title>TagSpaces Note</title></head><body>Your notes here...</body></html>",
"newMDFileContent": '#Markdown file created with TagSpaces!',
"showUnixHiddenEntries": false,
diff --git a/data/templates/LocationCreateDialog.html b/data/templates/LocationCreateDialog.html
index 4cb77305e..056178dd4 100644
--- a/data/templates/LocationCreateDialog.html
+++ b/data/templates/LocationCreateDialog.html
@@ -20,6 +20,10 @@
<label class="control-label" for="connectionName">Location Name</label>
<input class="form-control" type="text" name="connectionName" id="connectionName" placeholder="Example: My Documents" />
</div>
+ <div class="form-group">
+ <label class="control-label" for="locationPerspective">Default Perspective</label>
+ <select class="form-control" name="locationPerspective" id="locationPerspective" ></select>
+ </div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">
diff --git a/data/templates/LocationEditDialog.html b/data/templates/LocationEditDialog.html
index 598b16cbf..ab17e276c 100644
--- a/data/templates/LocationEditDialog.html
+++ b/data/templates/LocationEditDialog.html
@@ -20,6 +20,10 @@
<label class="control-label" for="connectionName2">Location Name</label>
<input class="form-control" type="text" name="connectionName2" id="connectionName2" placeholder="Example: My Documents" />
</div>
+ <div class="form-group">
+ <label class="control-label" for="locationPerspective2">Default Perspective</label>
+ <select class="form-control" name="locationPerspective2" id="locationPerspective2" ></select>
+ </div>
</div>
<div class="modal-footer">
<button id="deleteLocationButton" class="btn pull-left" aria-hidden="true">
diff --git a/default.settings.tmpl.js b/default.settings.tmpl.js
index 3db5d0842..73ab10822 100644
--- a/default.settings.tmpl.js
+++ b/default.settings.tmpl.js
@@ -9,7 +9,7 @@ exports.defaultSettings = {
"appVersion": "@VERSION@",
"appBuild": "@BUILD@",
"settingsVersion": 2,
- "newTextFileContent": "File created with TagSpaces!",
+ "newTextFileContent": "Text file created with TagSpaces!",
"newHTMLFileContent": "<html><head><title>Created with TagSpaces!</title></head><body>Feel free to change this text...</body></html>",
"newMDFileContent": '#Markdown file created with TagSpaces!',
"showUnixHiddenEntries": false,
@@ -98,10 +98,6 @@ exports.defaultSettings = {
{
"title":"paper",
"type":"plain",
- },
- {
- "title":"201XMMDD",
- "type":"plain",
}
]
},