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