Default editors

This commit is contained in:
Mo Bitar
2017-11-14 18:57:28 -06:00
parent 9db343a634
commit 483ffab6bf
5 changed files with 53 additions and 7 deletions

View File

@@ -58,7 +58,7 @@ angular.module('app.frontend')
// Activate new editor if it's different from the one currently activated
if(associatedEditor && associatedEditor != this.editorComponent) {
componentManager.activateComponent(associatedEditor);
this.enableComponent(associatedEditor);
}
this.editorComponent = associatedEditor;
@@ -85,6 +85,11 @@ angular.module('app.frontend')
return editor;
}
}
// No editor found for note. Use default editor, if note does not prefer system editor
if(!note.getAppDataItem("prefersPlainEditor")) {
return editors.filter((e) => {return e.isDefaultEditor()})[0];
}
}
this.selectedEditor = function(editorComponent) {
@@ -98,7 +103,15 @@ angular.module('app.frontend')
}
if(editorComponent) {
this.enableComponentForCurrentItem(editorComponent);
this.note.setAppDataItem("prefersPlainEditor", false);
this.note.setDirty(true);
this.enableComponent(editorComponent);
this.associateComponentWithCurrentItem(editorComponent);
} else {
// Note prefers plain editor
this.note.setAppDataItem("prefersPlainEditor", true);
this.note.setDirty(true);
syncManager.sync();
}
this.editorComponent = editorComponent;
@@ -410,12 +423,15 @@ angular.module('app.frontend')
componentManager.contextItemDidChangeInArea("editor-editor");
}
this.enableComponentForCurrentItem = function(component) {
this.enableComponent = function(component) {
componentManager.activateComponent(component);
componentManager.associateComponentWithItem(component, this.note);
componentManager.setEventFlowForComponent(component, 1);
}
this.associateComponentWithCurrentItem = function(component) {
componentManager.associateComponentWithItem(component, this.note);
}
let alertKey = "displayed-component-disable-alert";
this.disableComponentForCurrentItem = function(component, showAlert) {
componentManager.disassociateComponentWithItem(component, this.note);

View File

@@ -61,6 +61,14 @@ class Component extends Item {
return "SN|Component";
}
isEditor() {
return this.area == "editor-editor";
}
isDefaultEditor() {
return this.getAppDataItem("defaultEditor") == true;
}
/*
An associative component depends on being explicitly activated for a given item, compared to a dissaciative component,

View File

@@ -133,6 +133,23 @@ class GlobalExtensionsMenu {
}
}
$scope.makeEditorDefault = function(component) {
var currentDefault = componentManager.componentsForArea("editor-editor").filter((e) => {return e.isDefaultEditor()})[0];
if(currentDefault) {
currentDefault.setAppDataItem("defaultEditor", false);
currentDefault.setDirty(true);
}
component.setAppDataItem("defaultEditor", true);
component.setDirty(true);
syncManager.sync();
}
$scope.removeEditorDefault = function(component) {
component.setAppDataItem("defaultEditor", false);
component.setDirty(true);
syncManager.sync();
}
// Installation
$scope.submitInstallLink = function() {