Skip to content

Commit

Permalink
[se] Fix bug 63997
Browse files Browse the repository at this point in the history
  • Loading branch information
GoshaZotov authored and K0R0L committed Oct 11, 2023
1 parent 38d19de commit 8fafa92
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
21 changes: 11 additions & 10 deletions cell/Local/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,26 +192,27 @@ var c_oAscError = Asc.c_oAscError;
return printOptionsObj;
};

spreadsheet_api.prototype["updateSourceFromFile"] = function()
spreadsheet_api.prototype["asc_changeExternalReference"] = function(eR)
{
let isSavedFile = window["AscDesktopEditor"]["LocalFileGetSaved"]();
if (!isSavedFile)
{
// file not saved
return false;
let wb = this.wb;
if (!wb) {
return;
}

window["AscDesktopEditor"]["OpenFilenameDialog"]("cell", false, function(_file) {
let file = _file;
if (Array.isArray(file))
file = file[0];
if (!file)
return;

let relativePath = window["AscDesktopEditor"]["LocalFileGetRelativePath"](file);
//if not saved - put absolute path
let isSavedFile = window["AscDesktopEditor"]["LocalFileGetSaved"]();
let relativePath = isSavedFile && window["AscDesktopEditor"]["LocalFileGetRelativePath"](file);

// TODO:
console.log(relativePath);
let obj = {};
obj["path"] = relativePath;
obj["filePath"] = file;
wb.changeExternalReference(eR, obj);
});
};

Expand Down
21 changes: 20 additions & 1 deletion cell/model/WorkbookElems.js
Original file line number Diff line number Diff line change
Expand Up @@ -15030,7 +15030,7 @@ QueryTableField.prototype.clone = function() {
//path
//referenceData
if (obj["path"] !== this.Id) {
this.setId(obj["path"]);
this.setId(this._checkAndCorrectPath(obj["path"], obj["filePath"]));
}

if (obj["referenceData"] && (!this.referenceData || this.referenceData["instanceId"] !== obj["referenceData"]["instanceId"] ||
Expand All @@ -15039,6 +15039,25 @@ QueryTableField.prototype.clone = function() {
}
};

ExternalReference.prototype._checkAndCorrectPath = function (sPath, sAbsolutePath) {
if (!sPath || 1 === sPath.indexOf("../")) {
// sPath -> ../../from.xlsx
//sAbsolutePath - > C:\root\from.xlsx
// need -> /root/from.xlsx
if (sAbsolutePath) {
sPath = sAbsolutePath.substring(sAbsolutePath.indexOf("\\"))
sPath = sPath.replace(/\\/g,"/")
}
} else if (sPath && -1 !== sPath.indexOf(":/")) {
// sPath -> C:/root/from1.xlsx
//need -> file:///C:\root\from1.xlsx
sPath = sPath.replace(/\//g,"\\");
sPath = "file:///" + sPath;
}

return sPath;
};


function asc_CExternalReference() {
this.type = null;
Expand Down
7 changes: 6 additions & 1 deletion cell/view/WorkbookView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5216,11 +5216,16 @@
return;
}

History.Create_NewPoint();
History.StartTransaction();

let index = this.model.getExternalLinkIndexByName(eR.externalReference.Id);
let toER = eR.externalReference.clone(true);
toER.initFromObj(to);

this.model.changeExternalReference(index, toER);

History.EndTransaction();

this.model.handlers && this.model.handlers.trigger("asc_onUpdateExternalReferenceList");
};

Expand Down

0 comments on commit 8fafa92

Please sign in to comment.