From d999b3307c1f8e03406da4bb284da02aeea8d866 Mon Sep 17 00:00:00 2001 From: Lennard Sprong Date: Mon, 2 Jan 2023 10:34:34 +0100 Subject: [PATCH] Re-enable saving with history --- src-ui/js/ui/PopupMenu.js | 54 +++++++++++++++++++++++---------------- src-ui/p.html | 1 + src-ui/res/p.en.json | 1 + src-ui/res/p.ja.json | 3 ++- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src-ui/js/ui/PopupMenu.js b/src-ui/js/ui/PopupMenu.js index cbb11a56c..30b3e9c38 100644 --- a/src-ui/js/ui/PopupMenu.js +++ b/src-ui/js/ui/PopupMenu.js @@ -561,6 +561,10 @@ ui.popupmgr.addpopup("filesave", { init: function() { ui.popupmgr.popups.template.init.call(this); + pzpr.util.addEvent(this.form.filetype, "change", this, function(e) { + this.updatetextarea(); + }); + this.anchor = !ui.enableSaveBlob && pzpr.env.API.anchor_download ? getEL("saveanchor") @@ -569,11 +573,9 @@ ui.popupmgr.addpopup("filesave", { reset: function() { /* ファイル形式選択オプション */ var ispencilbox = pzpr.variety(ui.puzzle.pid).exists.pencilbox; - this.form.filetype.options[1].disabled = !ispencilbox; this.form.filetype.options[2].disabled = !ispencilbox; - var parser = pzpr.parser; - this.form.ta.value = ui.puzzle.getFileData(parser.FILE_PZPR, {}); - this.form.ta2.value = this.form.ta.value.replace(/\n/g, "/"); + this.form.filetype.options[3].disabled = !ispencilbox; + this.updatetextarea(); }, /* オーバーライド */ show: function(px, py) { @@ -608,6 +610,30 @@ ui.popupmgr.addpopup("filesave", { } this.form.filename.value = filename + ext; }, + updatetextarea: function() { + this.form.ta.value = this.getdata(); + this.form.ta2.style.display = + this.form.filetype.value === "filesave" ? "" : "none"; + this.form.ta2.value = this.form.ta.value.replace(/\n/g, "/"); + }, + getdata: function() { + var parser = pzpr.parser, + filetype = parser.FILE_PZPR, + option = {}; + switch (this.form.filetype.value) { + case "filesave2": + filetype = parser.FILE_PBOX; + break; + case "filesave4": + filetype = parser.FILE_PBOX_XML; + break; + case "filesave3": + filetype = parser.FILE_PZPR; + option.history = true; + break; + } + return ui.puzzle.getFileData(filetype, option); + }, //------------------------------------------------------------------------------ // filesave() ファイルを保存する @@ -624,30 +650,14 @@ ui.popupmgr.addpopup("filesave", { } } - var parser = pzpr.parser, - filetype = parser.FILE_PZPR, - option = {}; - switch (form.filetype.value) { - case "filesave2": - filetype = parser.FILE_PBOX; - break; - case "filesave4": - filetype = parser.FILE_PBOX_XML; - break; - case "filesave3": - filetype = parser.FILE_PZPR; - option.history = true; - break; - } - var blob = null, filedata = null; if (ui.enableSaveBlob || !!this.anchor) { - blob = new Blob([ui.puzzle.getFileData(filetype, option)], { + blob = new Blob([this.getdata()], { type: "text/plain" }); } else { - filedata = ui.puzzle.getFileData(filetype, option); + filedata = this.getdata(); } if (ui.enableSaveBlob) { diff --git a/src-ui/p.html b/src-ui/p.html index c2e8bbc8b..db11ad35b 100644 --- a/src-ui/p.html +++ b/src-ui/p.html @@ -553,6 +553,7 @@

読み込み中です...

__filesave.format__ diff --git a/src-ui/res/p.en.json b/src-ui/res/p.en.json index c60bd7443..9993296f0 100644 --- a/src-ui/res/p.en.json +++ b/src-ui/res/p.en.json @@ -225,6 +225,7 @@ "filesave.title": "Save File", "filesave.format": "File format", "filesave.format.pzprv3": "Puz-Pre v3 format", + "filesave.format.pzprv3.history": "Puz-Pre v3 with history", "filesave.format.penciltxt": "Pencilbox Text format", "filesave.format.pencilxml": "Pencilbox XML format", "filesave.filename": "Filename", diff --git a/src-ui/res/p.ja.json b/src-ui/res/p.ja.json index c4029a767..e39e6896b 100644 --- a/src-ui/res/p.ja.json +++ b/src-ui/res/p.ja.json @@ -224,7 +224,8 @@ "fileopen.choose": "ファイル選択", "filesave.title": "ファイルを保存する", "filesave.format": "ファイル形式", - "filesave.format.pzprv3": "ファイル形式", + "filesave.format.pzprv3": "ぱずぷれv3形式", + "filesave.format.pzprv3.history": "ぱずぷれv3(履歴つき)", "filesave.format.penciltxt": "pencilbox形式", "filesave.format.pencilxml": "pencilbox XML形式", "filesave.filename": "ファイル名",