App-SocialCalc-Multiplayer
view release on metacpan or search on metacpan
socialcalc/socialcalc-3.js view on Meta::CPAN
(newattribs.fontfamily.def ? "*" : newattribs.fontfamily.val);
}
else {
value = "";
}
if (value != (sheet.fonts[attribs.defaultfont] || "")) {
DoCmd("defaultfont "+value);
}
// color: textcolor
CheckChanges("textcolor", sheet.colors[attribs.defaultcolor], "defaultcolor");
// bgcolor: bgcolor
CheckChanges("bgcolor", sheet.colors[attribs.defaultbgcolor], "defaultbgcolor");
// formatting: numberformat, textformat
CheckChanges("numberformat", sheet.valueformats[attribs.defaultnontextvalueformat], "defaultnontextvalueformat");
CheckChanges("textformat", sheet.valueformats[attribs.defaulttextvalueformat], "defaulttextvalueformat");
// recalc: recalc
CheckChanges("recalc", sheet.attribs.recalc, "recalc");
// if any changes return command(s)
if (changed) {
return cmdstr;
}
else {
return null;
}
}
// *************************************
//
// Sheet command routines
//
// *************************************
//
// SocialCalc.SheetCommandInfo - object with information used during command execution
//
SocialCalc.SheetCommandInfo = { // only one of these
sheetobj: null, // sheet being operated on
parseobj: null, // SocialCalc.Parse object with the command string, etc.
timerobj: null, // used for timeslicing
firsttimerdelay: 50, // wait before starting cmds (for Chrome - to give time to update)
timerdelay: 1, // wait between slices
maxtimeslice: 100, // do another slice after this many milliseconds
saveundo: false, // arg for ExecuteSheetCommand
CmdExtensionCallbacks: {}, // for startcmdextension, in form: cmdname, {func:function(cmdname, data, sheet, SocialCalc.Parse object, saveundo), data:whatever}
cmdextensionbusy: "" // if length>0, command loop waits for SocialCalc.ResumeFromCmdExtension()
// statuscallback: null, // called during execution - obsolete: use sheet obj's
// statuscallbackparams: null
};
//
// SocialCalc.ScheduleSheetCommands
//
// statuscallback is called at the beginning (cmdstart) and end (cmdend).
//
SocialCalc.ScheduleSheetCommands = function(sheet, cmdstr, saveundo, isRemote) {
if (SocialCalc.Callbacks.broadcast && !isRemote) {
if (cmdstr != 'redisplay' && cmdstr != 'set sheet defaulttextvalueformat text-wiki') {
SocialCalc.Callbacks.broadcast('execute', { cmdstr: cmdstr, saveundo: saveundo });
}
}
var sci = SocialCalc.SheetCommandInfo;
sci.sheetobj = sheet;
sci.parseobj = new SocialCalc.Parse(cmdstr);
sci.saveundo = saveundo;
if (sci.sheetobj.statuscallback) { // notify others if requested
sheet.statuscallback(sci, "cmdstart", "", sci.sheetobj.statuscallbackparams);
}
if (sci.saveundo) {
sci.sheetobj.changes.PushChange(""); // add a step to undo stack
}
sci.timerobj = window.setTimeout(SocialCalc.SheetCommandsTimerRoutine, sci.firsttimerdelay);
}
SocialCalc.SheetCommandsTimerRoutine = function() {
var errortext;
var sci = SocialCalc.SheetCommandInfo;
var starttime = new Date();
sci.timerobj = null;
while (!sci.parseobj.EOF()) { // go through all commands (separated by newlines)
errortext = SocialCalc.ExecuteSheetCommand(sci.sheetobj, sci.parseobj, sci.saveundo);
if (errortext) alert(errortext);
sci.parseobj.NextLine();
if (sci.cmdextensionbusy.length > 0) { // forced wait
if (sci.sheetobj.statuscallback) { // notify others if requested
sci.sheetobj.statuscallback(sci, "cmdextension", sci.cmdextensionbusy, sci.sheetobj.statuscallbackparams);
}
return;
}
if (((new Date()) - starttime) >= sci.maxtimeslice) { // if taking too long, give up CPU for a while
sci.timerobj = window.setTimeout(SocialCalc.SheetCommandsTimerRoutine, sci.timerdelay);
return;
}
}
if (sci.sheetobj.statuscallback) { // notify others if requested
sci.sheetobj.statuscallback(sci, "cmdend", "", sci.sheetobj.statuscallbackparams);
}
}
SocialCalc.ResumeFromCmdExtension = function() {
var sci = SocialCalc.SheetCommandInfo;
sci.cmdextensionbusy = "";
SocialCalc.SheetCommandsTimerRoutine();
}
//
// errortext = SocialCalc.ExecuteSheetCommand(sheet, cmd, saveundo)
//
// cmd is a SocialCalc.Parse object.
//
// Executes commands that modify the sheet data.
// Sets sheet "needsrecalc" as needed.
// Sets sheet "changedrendervalues" as needed.
//
// The cmd string may be multiple commands, separated by newlines. In that case
// only one "step" is put on the undo stack representing all the commands.
// Note that because of this, in "set A1 text ..." and "set A1 comment ..." text is
// treated as encoded (newline => \n, \ => \b, : => \c).
//
// The commands are in the forms:
//
// set sheet attributename value (plus lastcol and lastrow)
// set 22 attributename value
// set B attributename value
// set A1 attributename value1 value2... (see each attribute in code for details)
// set A1:B5 attributename value1 value2...
// erase/copy/cut/paste/fillright/filldown A1:B5 all/formulas/format
// loadclipboard save-encoded-clipboard-data
// clearclipboard
// merge C3:F3
// unmerge C3
// insertcol/insertrow C5
// deletecol/deleterow C5:E7
// movepaste/moveinsert A1:B5 A8 all/formulas/format (if insert, destination must be in same rows or columns or else paste done)
// sort cr1:cr2 col1 up/down col2 up/down col3 up/down
// name define NAME definition
// name desc NAME description
// name delete NAME
// recalc
// redisplay
// changedrendervalues
// startcmdextension extension rest-of-command
//
// If saveundo is true, then undo information is saved in sheet.changes.
//
SocialCalc.ExecuteSheetCommand = function(sheet, cmd, saveundo) {
var cmdstr, cmd1, rest, what, attrib, num, pos, pos2, errortext, undostart, val;
var cr1, cr2, col, row, cr, cell, newcell;
var fillright, rowstart, colstart, crbase, rowoffset, coloffset, basecell;
var clipsheet, cliprange, numcols, numrows, attribtable;
var colend, rowend, newcolstart, newrowstart, newcolend, newrowend, rownext, colnext, colthis, cellnext;
var lastrow, lastcol, rowbefore, colbefore, oldformula, oldcr;
var cols, dirs, lastsortcol, i, sortlist, sortcells, sortvalues, sorttypes;
var sortfunction, slen, valtype, originalrow, sortedcr;
var name, v1, v2;
var cmdextension;
var attribs = sheet.attribs;
( run in 1.793 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )