Add indent settings to code2

pull/1/head
yflory 7 years ago
parent f54dc7505c
commit 0d008aaa2e

@ -68,21 +68,21 @@ define([
editor.setOption('indentWithTabs', useTabs); editor.setOption('indentWithTabs', useTabs);
}; };
var indentKey = 'cryptpad.indentUnit'; var indentKey = 'indentUnit';
var useTabsKey = 'cryptpad.indentWithTabs'; var useTabsKey = 'indentWithTabs';
var proxy = Cryptpad.getProxy(); var proxy = Cryptpad.getProxy();
var updateIndentSettings = APP.updateIndentSettings = function () { var updateIndentSettings = APP.updateIndentSettings = function () {
var indentUnit = proxy[indentKey]; var indentUnit = proxy.settings[indentKey];
var useTabs = proxy[useTabsKey]; var useTabs = proxy.settings[useTabsKey];
setIndentation( setIndentation(
typeof(indentUnit) === 'number'? indentUnit: 2, typeof(indentUnit) === 'number'? indentUnit: 2,
typeof(useTabs) === 'boolean'? useTabs: false); typeof(useTabs) === 'boolean'? useTabs: false);
}; };
proxy.on('change', [indentKey], updateIndentSettings); proxy.on('change', ['settings', indentKey], updateIndentSettings);
proxy.on('change', [useTabsKey], updateIndentSettings); proxy.on('change', ['settings', useTabsKey], updateIndentSettings);
var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox'); var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox');

@ -84,7 +84,6 @@ define([
var readOnly = false; var readOnly = false;
var cpNfInner; var cpNfInner;
var metadataMgr; var metadataMgr;
var onLocal;
var $bar = $('#cme_toolbox'); var $bar = $('#cme_toolbox');
var isHistoryMode = false; var isHistoryMode = false;
@ -110,30 +109,24 @@ define([
editor.setOption('indentWithTabs', useTabs); editor.setOption('indentWithTabs', useTabs);
}; };
var indentKey = 'cryptpad.indentUnit'; var indentKey = 'indentUnit';
var useTabsKey = 'cryptpad.indentWithTabs'; var useTabsKey = 'indentWithTabs';
var updateIndentSettings = function () { var updateIndentSettings = function () {
var indentUnit = proxy[indentKey]; if (!metadataMgr) { return; }
var useTabs = proxy[useTabsKey]; var data = metadataMgr.getPrivateData().settings;
var indentUnit = data[indentKey];
var useTabs = data[useTabsKey];
setIndentation( setIndentation(
typeof(indentUnit) === 'number'? indentUnit: 2, typeof(indentUnit) === 'number'? indentUnit: 2,
typeof(useTabs) === 'boolean'? useTabs: false); typeof(useTabs) === 'boolean'? useTabs: false);
}; };
//proxy.on('change', [indentKey], updateIndentSettings); TODO RPC
//proxy.on('change', [useTabsKey], updateIndentSettings); TODO RPC
var setEditable = APP.setEditable = function (bool) { var setEditable = APP.setEditable = function (bool) {
if (readOnly && bool) { return; } if (readOnly && bool) { return; }
editor.setOption('readOnly', !bool); editor.setOption('readOnly', !bool);
}; };
var Title; var Title;
var UserList;
var Metadata;
var config = { var config = {
readOnly: readOnly, readOnly: readOnly,
@ -260,6 +253,9 @@ define([
}; };
config.onInit = function (info) { config.onInit = function (info) {
metadataMgr.onChangeLazy(updateIndentSettings);
updateIndentSettings();
readOnly = metadataMgr.getPrivateData().readOnly; readOnly = metadataMgr.getPrivateData().readOnly;
var titleCfg = { getHeadingText: CodeMirror.getHeadingText }; var titleCfg = { getHeadingText: CodeMirror.getHeadingText };

@ -9,15 +9,6 @@ define([
var requireConfig = RequireConfig(); var requireConfig = RequireConfig();
// Loaded in load #2 // Loaded in load #2
var CpNfOuter;
var Cryptpad;
var Crypto;
var Cryptget;
var sframeChan;
var secret;
var hashes;
nThen(function (waitFor) { nThen(function (waitFor) {
$(waitFor()); $(waitFor());
}).nThen(function (waitFor) { }).nThen(function (waitFor) {

@ -18,7 +18,7 @@ define([], function () {
var key = parsed.hash + '.' + attr; var key = parsed.hash + '.' + attr;
var key2 = parsed.hash.slice(0,-1) + '.' + attr;// old pads not ending with / var key2 = parsed.hash.slice(0,-1) + '.' + attr;// old pads not ending with /
if (typeof(files[key]) !== "undefined" || typeof(files[key2]) !== "undefined") { if (typeof(files[key]) !== "undefined" || typeof(files[key2]) !== "undefined") {
debug("Migrating pad attribute", attr, "for pad", id); console.log("Migrating pad attribute", attr, "for pad", id);
el[attr] = files[key] || files[key2]; el[attr] = files[key] || files[key2];
delete files[key]; delete files[key];
delete files[key2]; delete files[key2];
@ -28,7 +28,7 @@ define([], function () {
var filesData = files.filesData; var filesData = files.filesData;
if (!filesData) { return; } if (!filesData) { return; }
var el, id, parsed; var el, parsed;
for (var id in filesData) { for (var id in filesData) {
id = Number(id); id = Number(id);
el = filesData[id]; el = filesData[id];

@ -46,6 +46,7 @@ define([
var parsed = Cryptpad.parsePadUrl(window.location.href); var parsed = Cryptpad.parsePadUrl(window.location.href);
if (!parsed.type) { throw new Error(); } if (!parsed.type) { throw new Error(); }
var defaultTitle = Cryptpad.getDefaultName(parsed); var defaultTitle = Cryptpad.getDefaultName(parsed);
var proxy = Cryptpad.getProxy();
var updateMeta = function () { var updateMeta = function () {
//console.log('EV_METADATA_UPDATE'); //console.log('EV_METADATA_UPDATE');
var name; var name;
@ -65,7 +66,7 @@ define([
uid: Cryptpad.getUid(), uid: Cryptpad.getUid(),
avatar: Cryptpad.getAvatarUrl(), avatar: Cryptpad.getAvatarUrl(),
profile: Cryptpad.getProfileUrl(), profile: Cryptpad.getProfileUrl(),
curvePublic: Cryptpad.getProxy().curvePublic, curvePublic: proxy.curvePublic,
netfluxId: Cryptpad.getNetwork().webChannels[0].myID, netfluxId: Cryptpad.getNetwork().webChannels[0].myID,
}, },
priv: { priv: {
@ -76,13 +77,15 @@ define([
availableHashes: hashes, availableHashes: hashes,
isTemplate: Cryptpad.isTemplate(window.location.href), isTemplate: Cryptpad.isTemplate(window.location.href),
feedbackAllowed: Cryptpad.isFeedbackAllowed(), feedbackAllowed: Cryptpad.isFeedbackAllowed(),
friends: Cryptpad.getProxy().friends || {} friends: proxy.friends || {},
settings: proxy.settings || {}
} }
}); });
}); });
}; };
Cryptpad.onDisplayNameChanged(updateMeta); Cryptpad.onDisplayNameChanged(updateMeta);
sframeChan.onReg('EV_METADATA_UPDATE', updateMeta); sframeChan.onReg('EV_METADATA_UPDATE', updateMeta);
proxy.on('change', 'settings', updateMeta);
Cryptpad.onError(function (info) { Cryptpad.onError(function (info) {
console.log('error'); console.log('error');

@ -286,8 +286,8 @@ define([
button.addClass('rightside-button'); button.addClass('rightside-button');
} }
return button; return button;
}; };
/* funcs.storeLinkToClipboard = function (readOnly, cb) { /* funcs.storeLinkToClipboard = function (readOnly, cb) {
ctx.sframeChan.query('Q_STORE_LINK_TO_CLIPBOARD', readOnly, function (err) { ctx.sframeChan.query('Q_STORE_LINK_TO_CLIPBOARD', readOnly, function (err) {
if (cb) { cb(err); } if (cb) { cb(err); }

@ -82,4 +82,6 @@ define({
// Set the tab notification when the content of the pad changes // Set the tab notification when the content of the pad changes
'EV_NOTIFY': true, 'EV_NOTIFY': true,
// Send the new settings to the inner iframe when they are changed in the proxy
'EV_SETTINGS_UPDATE': true,
}); });

@ -9,15 +9,6 @@ define([
var requireConfig = RequireConfig(); var requireConfig = RequireConfig();
// Loaded in load #2 // Loaded in load #2
var CpNfOuter;
var Cryptpad;
var Crypto;
var Cryptget;
var sframeChan;
var secret;
var hashes;
nThen(function (waitFor) { nThen(function (waitFor) {
$(waitFor()); $(waitFor());
}).nThen(function (waitFor) { }).nThen(function (waitFor) {

@ -131,6 +131,7 @@ define([
}; };
var createIndentUnitSelector = function (obj) { var createIndentUnitSelector = function (obj) {
var proxy = obj.proxy; var proxy = obj.proxy;
proxy.settings = proxy.settings || {};
var $div = $('<div>', { var $div = $('<div>', {
'class': 'indentUnit element' 'class': 'indentUnit element'
@ -148,26 +149,28 @@ define([
}).on('change', function () { }).on('change', function () {
var val = parseInt($input.val()); var val = parseInt($input.val());
if (typeof(val) !== 'number') { return; } if (typeof(val) !== 'number') { return; }
proxy['cryptpad.indentUnit'] = val; proxy.settings.indentUnit = val;
}).appendTo($inputBlock); }).appendTo($inputBlock);
proxy.on('change', [ 'cryptpad.indentUnit', ], function (o, n) { $input.val(n); }); proxy.on('change', [ 'settings', 'indentUnit', ], function (o, n) { $input.val(n); });
Cryptpad.getAttribute('indentUnit', function (e, val) { //Cryptpad.getAttribute('indentUnit', function (e, val) {
if (e) { return void console.error(e); } //if (e) { return void console.error(e); }
var val = proxy.settings.indentUnit;
if (typeof(val) !== 'number') { if (typeof(val) !== 'number') {
$input.val(2); $input.val(2);
} else { } else {
$input.val(val); $input.val(val);
} }
}); //});
return $div; return $div;
}; };
var createIndentTypeSelector = function (obj) { var createIndentTypeSelector = function (obj) {
var proxy = obj.proxy; var proxy = obj.proxy;
proxy.settings = proxy.settings || {};
var key = 'cryptpad.indentWithTabs'; var key = 'indentWithTabs';
var $div = $('<div>', { var $div = $('<div>', {
'class': 'indentType element' 'class': 'indentType element'
@ -184,11 +187,11 @@ define([
}).on('change', function () { }).on('change', function () {
var val = $input.is(':checked'); var val = $input.is(':checked');
if (typeof(val) !== 'boolean') { return; } if (typeof(val) !== 'boolean') { return; }
proxy[key] = val; proxy.settings[key] = val;
}).appendTo($inputBlock); }).appendTo($inputBlock);
$input[0].checked = !!proxy[key]; $input[0].checked = !!proxy.settings[key];
proxy.on('change', [key], function (o, n) { $input[0].checked = !!n; }); proxy.on('change', ['settings', key], function (o, n) { $input[0].checked = !!n; });
return $div; return $div;
}; };

Loading…
Cancel
Save