Add indent settings to code2
This commit is contained in:
parent
f54dc7505c
commit
0d008aaa2e
9 changed files with 38 additions and 52 deletions
|
@ -68,21 +68,21 @@ define([
|
|||
editor.setOption('indentWithTabs', useTabs);
|
||||
};
|
||||
|
||||
var indentKey = 'cryptpad.indentUnit';
|
||||
var useTabsKey = 'cryptpad.indentWithTabs';
|
||||
var indentKey = 'indentUnit';
|
||||
var useTabsKey = 'indentWithTabs';
|
||||
|
||||
var proxy = Cryptpad.getProxy();
|
||||
|
||||
var updateIndentSettings = APP.updateIndentSettings = function () {
|
||||
var indentUnit = proxy[indentKey];
|
||||
var useTabs = proxy[useTabsKey];
|
||||
var indentUnit = proxy.settings[indentKey];
|
||||
var useTabs = proxy.settings[useTabsKey];
|
||||
setIndentation(
|
||||
typeof(indentUnit) === 'number'? indentUnit: 2,
|
||||
typeof(useTabs) === 'boolean'? useTabs: false);
|
||||
};
|
||||
|
||||
proxy.on('change', [indentKey], updateIndentSettings);
|
||||
proxy.on('change', [useTabsKey], updateIndentSettings);
|
||||
proxy.on('change', ['settings', indentKey], updateIndentSettings);
|
||||
proxy.on('change', ['settings', useTabsKey], updateIndentSettings);
|
||||
|
||||
var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox');
|
||||
|
||||
|
|
|
@ -84,7 +84,6 @@ define([
|
|||
var readOnly = false;
|
||||
var cpNfInner;
|
||||
var metadataMgr;
|
||||
var onLocal;
|
||||
var $bar = $('#cme_toolbox');
|
||||
|
||||
var isHistoryMode = false;
|
||||
|
@ -110,30 +109,24 @@ define([
|
|||
editor.setOption('indentWithTabs', useTabs);
|
||||
};
|
||||
|
||||
var indentKey = 'cryptpad.indentUnit';
|
||||
var useTabsKey = 'cryptpad.indentWithTabs';
|
||||
|
||||
var indentKey = 'indentUnit';
|
||||
var useTabsKey = 'indentWithTabs';
|
||||
var updateIndentSettings = function () {
|
||||
var indentUnit = proxy[indentKey];
|
||||
var useTabs = proxy[useTabsKey];
|
||||
if (!metadataMgr) { return; }
|
||||
var data = metadataMgr.getPrivateData().settings;
|
||||
var indentUnit = data[indentKey];
|
||||
var useTabs = data[useTabsKey];
|
||||
setIndentation(
|
||||
typeof(indentUnit) === 'number'? indentUnit: 2,
|
||||
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) {
|
||||
if (readOnly && bool) { return; }
|
||||
editor.setOption('readOnly', !bool);
|
||||
};
|
||||
|
||||
var Title;
|
||||
var UserList;
|
||||
var Metadata;
|
||||
|
||||
var config = {
|
||||
readOnly: readOnly,
|
||||
|
@ -260,6 +253,9 @@ define([
|
|||
};
|
||||
|
||||
config.onInit = function (info) {
|
||||
metadataMgr.onChangeLazy(updateIndentSettings);
|
||||
updateIndentSettings();
|
||||
|
||||
readOnly = metadataMgr.getPrivateData().readOnly;
|
||||
|
||||
var titleCfg = { getHeadingText: CodeMirror.getHeadingText };
|
||||
|
|
|
@ -9,15 +9,6 @@ define([
|
|||
var requireConfig = RequireConfig();
|
||||
|
||||
// Loaded in load #2
|
||||
var CpNfOuter;
|
||||
var Cryptpad;
|
||||
var Crypto;
|
||||
var Cryptget;
|
||||
|
||||
var sframeChan;
|
||||
var secret;
|
||||
var hashes;
|
||||
|
||||
nThen(function (waitFor) {
|
||||
$(waitFor());
|
||||
}).nThen(function (waitFor) {
|
||||
|
|
|
@ -18,7 +18,7 @@ define([], function () {
|
|||
var key = parsed.hash + '.' + attr;
|
||||
var key2 = parsed.hash.slice(0,-1) + '.' + attr;// old pads not ending with /
|
||||
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];
|
||||
delete files[key];
|
||||
delete files[key2];
|
||||
|
@ -28,7 +28,7 @@ define([], function () {
|
|||
var filesData = files.filesData;
|
||||
if (!filesData) { return; }
|
||||
|
||||
var el, id, parsed;
|
||||
var el, parsed;
|
||||
for (var id in filesData) {
|
||||
id = Number(id);
|
||||
el = filesData[id];
|
||||
|
|
|
@ -46,6 +46,7 @@ define([
|
|||
var parsed = Cryptpad.parsePadUrl(window.location.href);
|
||||
if (!parsed.type) { throw new Error(); }
|
||||
var defaultTitle = Cryptpad.getDefaultName(parsed);
|
||||
var proxy = Cryptpad.getProxy();
|
||||
var updateMeta = function () {
|
||||
//console.log('EV_METADATA_UPDATE');
|
||||
var name;
|
||||
|
@ -65,7 +66,7 @@ define([
|
|||
uid: Cryptpad.getUid(),
|
||||
avatar: Cryptpad.getAvatarUrl(),
|
||||
profile: Cryptpad.getProfileUrl(),
|
||||
curvePublic: Cryptpad.getProxy().curvePublic,
|
||||
curvePublic: proxy.curvePublic,
|
||||
netfluxId: Cryptpad.getNetwork().webChannels[0].myID,
|
||||
},
|
||||
priv: {
|
||||
|
@ -76,13 +77,15 @@ define([
|
|||
availableHashes: hashes,
|
||||
isTemplate: Cryptpad.isTemplate(window.location.href),
|
||||
feedbackAllowed: Cryptpad.isFeedbackAllowed(),
|
||||
friends: Cryptpad.getProxy().friends || {}
|
||||
friends: proxy.friends || {},
|
||||
settings: proxy.settings || {}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Cryptpad.onDisplayNameChanged(updateMeta);
|
||||
sframeChan.onReg('EV_METADATA_UPDATE', updateMeta);
|
||||
proxy.on('change', 'settings', updateMeta);
|
||||
|
||||
Cryptpad.onError(function (info) {
|
||||
console.log('error');
|
||||
|
|
|
@ -286,15 +286,15 @@ define([
|
|||
button.addClass('rightside-button');
|
||||
}
|
||||
return button;
|
||||
|
||||
};
|
||||
|
||||
/* funcs.storeLinkToClipboard = function (readOnly, cb) {
|
||||
ctx.sframeChan.query('Q_STORE_LINK_TO_CLIPBOARD', readOnly, function (err) {
|
||||
if (cb) { cb(err); }
|
||||
});
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
Object.freeze(funcs);
|
||||
return { create: function (cb) {
|
||||
nThen(function (waitFor) {
|
||||
|
|
|
@ -82,4 +82,6 @@ define({
|
|||
// Set the tab notification when the content of the pad changes
|
||||
'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();
|
||||
|
||||
// Loaded in load #2
|
||||
var CpNfOuter;
|
||||
var Cryptpad;
|
||||
var Crypto;
|
||||
var Cryptget;
|
||||
|
||||
var sframeChan;
|
||||
var secret;
|
||||
var hashes;
|
||||
|
||||
nThen(function (waitFor) {
|
||||
$(waitFor());
|
||||
}).nThen(function (waitFor) {
|
||||
|
|
|
@ -131,6 +131,7 @@ define([
|
|||
};
|
||||
var createIndentUnitSelector = function (obj) {
|
||||
var proxy = obj.proxy;
|
||||
proxy.settings = proxy.settings || {};
|
||||
|
||||
var $div = $('<div>', {
|
||||
'class': 'indentUnit element'
|
||||
|
@ -148,26 +149,28 @@ define([
|
|||
}).on('change', function () {
|
||||
var val = parseInt($input.val());
|
||||
if (typeof(val) !== 'number') { return; }
|
||||
proxy['cryptpad.indentUnit'] = val;
|
||||
proxy.settings.indentUnit = val;
|
||||
}).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) {
|
||||
if (e) { return void console.error(e); }
|
||||
//Cryptpad.getAttribute('indentUnit', function (e, val) {
|
||||
//if (e) { return void console.error(e); }
|
||||
var val = proxy.settings.indentUnit;
|
||||
if (typeof(val) !== 'number') {
|
||||
$input.val(2);
|
||||
} else {
|
||||
$input.val(val);
|
||||
}
|
||||
});
|
||||
//});
|
||||
return $div;
|
||||
};
|
||||
|
||||
var createIndentTypeSelector = function (obj) {
|
||||
var proxy = obj.proxy;
|
||||
proxy.settings = proxy.settings || {};
|
||||
|
||||
var key = 'cryptpad.indentWithTabs';
|
||||
var key = 'indentWithTabs';
|
||||
|
||||
var $div = $('<div>', {
|
||||
'class': 'indentType element'
|
||||
|
@ -184,11 +187,11 @@ define([
|
|||
}).on('change', function () {
|
||||
var val = $input.is(':checked');
|
||||
if (typeof(val) !== 'boolean') { return; }
|
||||
proxy[key] = val;
|
||||
proxy.settings[key] = val;
|
||||
}).appendTo($inputBlock);
|
||||
|
||||
$input[0].checked = !!proxy[key];
|
||||
proxy.on('change', [key], function (o, n) { $input[0].checked = !!n; });
|
||||
$input[0].checked = !!proxy.settings[key];
|
||||
proxy.on('change', ['settings', key], function (o, n) { $input[0].checked = !!n; });
|
||||
|
||||
return $div;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue