mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 12:42:26 +01:00
extract editor.editFileExternally from buffer.viewSource and
editor.editWithExternalEditor
This commit is contained in:
@@ -1312,31 +1312,14 @@ function Buffer() //{{{
|
||||
docUrl, docCharset, reference, "selection");
|
||||
},
|
||||
|
||||
// url is optional
|
||||
viewSource: function (url, useExternalEditor)
|
||||
{
|
||||
url = url || buffer.URL;
|
||||
|
||||
if (useExternalEditor)
|
||||
{
|
||||
// TODO: make that a helper function
|
||||
// TODO: save return value in v:shell_error
|
||||
var editor = options["editor"];
|
||||
var args = commands.parseArgs(editor, [], "*", true);
|
||||
if (args.length < 1)
|
||||
{
|
||||
liberator.echoerr("No editor specified");
|
||||
return;
|
||||
}
|
||||
|
||||
var prog = args.shift();
|
||||
args.push(url);
|
||||
liberator.callFunctionInThread(null, io.run, prog, args, true);
|
||||
}
|
||||
editor.editFileExternally(url);
|
||||
else
|
||||
{
|
||||
liberator.open("view-source:" + url);
|
||||
}
|
||||
},
|
||||
|
||||
zoomIn: function (steps, fullZoom)
|
||||
|
||||
@@ -295,7 +295,7 @@ function Editor() //{{{
|
||||
|
||||
mappings.add([modes.INSERT, modes.TEXTAREA, modes.COMPOSE],
|
||||
["<C-i>"], "Edit text field with an external editor",
|
||||
function () { editor.editWithExternalEditor(); });
|
||||
function () { editor.editFieldExternally(); });
|
||||
|
||||
// FIXME: <esc> does not work correctly
|
||||
mappings.add([modes.INSERT],
|
||||
@@ -794,14 +794,32 @@ function Editor() //{{{
|
||||
return -1;
|
||||
},
|
||||
|
||||
// TODO: clean up with 2 functions for textboxes and currentEditor?
|
||||
editWithExternalEditor: function ()
|
||||
editFileExternally: function (path)
|
||||
{
|
||||
// TODO: save return value in v:shell_error
|
||||
let args = commands.parseArgs(options["editor"], [], "*", true);
|
||||
|
||||
if (args.length < 1)
|
||||
{
|
||||
liberator.echoerr("No editor specified");
|
||||
return;
|
||||
}
|
||||
|
||||
args.push(path);
|
||||
liberator.callFunctionInThread(null, io.run, args.shift(), args, true);
|
||||
},
|
||||
|
||||
// TODO: clean up with 2 functions for textboxes and currentEditor?
|
||||
editFieldExternally: function ()
|
||||
{
|
||||
if (!options["editor"])
|
||||
return false;
|
||||
|
||||
var textBox = null;
|
||||
if (!(config.isComposeWindow))
|
||||
textBox = document.commandDispatcher.focusedElement;
|
||||
|
||||
var text = "";
|
||||
var text = ""; // XXX
|
||||
if (textBox)
|
||||
text = textBox.value;
|
||||
else if (typeof GetCurrentEditor == "function") // Thunderbird composer
|
||||
@@ -809,14 +827,6 @@ function Editor() //{{{
|
||||
else
|
||||
return false;
|
||||
|
||||
var editor = options["editor"];
|
||||
var args = commands.parseArgs(editor, [], "*", true);
|
||||
if (args.length < 1)
|
||||
{
|
||||
liberator.echoerr("No editor specified");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var tmpfile = io.createTempFile();
|
||||
@@ -836,9 +846,6 @@ function Editor() //{{{
|
||||
return false;
|
||||
}
|
||||
|
||||
var prog = args.shift();
|
||||
args.push(tmpfile.path);
|
||||
|
||||
if (textBox)
|
||||
{
|
||||
textBox.setAttribute("readonly", "true");
|
||||
@@ -847,8 +854,7 @@ function Editor() //{{{
|
||||
textBox.style.backgroundColor = "#bbbbbb";
|
||||
}
|
||||
|
||||
// TODO: save return value in v:shell_error
|
||||
liberator.callFunctionInThread(null, io.run, prog, args, true);
|
||||
this.editFileExternally(tmpfile.path);
|
||||
|
||||
if (textBox)
|
||||
textBox.removeAttribute("readonly");
|
||||
|
||||
@@ -131,7 +131,7 @@ const config = { //{{{
|
||||
// TODO: move mappings elsewhere, probably compose.js
|
||||
mappings.add([modes.COMPOSE],
|
||||
["e"], "Edit message",
|
||||
function () { editor.editWithExternalEditor(); });
|
||||
function () { editor.editFieldExternally(); });
|
||||
|
||||
mappings.add([modes.COMPOSE],
|
||||
["y"], "Send message now",
|
||||
@@ -178,7 +178,7 @@ const config = { //{{{
|
||||
if (options["autoexternal"] && !window.messageWasEditedExternally/* && !gMsgCompose.recycledWindow*/)
|
||||
{
|
||||
window.messageWasEditedExternally = true;
|
||||
editor.editWithExternalEditor();
|
||||
editor.editFieldExternally();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user