mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Extend fix for #7404 to allow any inset collapsible to be edited
externally.
This commit is contained in:
parent
7cb0284a3f
commit
e5fc7327e3
@ -1,5 +1,5 @@
|
||||
#LyX 2.4 created this file. For more info see https://www.lyx.org/
|
||||
\lyxformat 564
|
||||
\lyxformat 565
|
||||
\begin_document
|
||||
\begin_header
|
||||
\save_transient_properties true
|
||||
@ -130,6 +130,7 @@ logicalmkup
|
||||
\html_css_as_file 0
|
||||
\html_be_strict true
|
||||
\author -712698321 "Jürgen Spitzmüller"
|
||||
\author 731793113 "Richard Kimberly Heck" rikiheck@lyx.org
|
||||
\end_header
|
||||
|
||||
\begin_body
|
||||
@ -18796,6 +18797,34 @@ LatexName
|
||||
|
||||
tags.
|
||||
Default is true.
|
||||
\change_inserted 731793113 1538674858
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Description
|
||||
|
||||
\change_inserted 731793113 1538674891
|
||||
\begin_inset Flex Code
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted 731793113 1538674863
|
||||
EditExternal
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
[
|
||||
\emph on
|
||||
0
|
||||
\emph default
|
||||
,1] Allow the contents of the inset to be edited externally (using whatever
|
||||
editor is defined for the document's output format).
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Description
|
||||
|
@ -52,4 +52,5 @@ InsetLayout "Flex:Chunk"
|
||||
ResetsFont false
|
||||
ForceOwnlines true
|
||||
NeedCProtect true
|
||||
EditExternal true
|
||||
End
|
||||
|
@ -220,6 +220,7 @@ InsetLayout ERT
|
||||
KeepEmpty true
|
||||
FreeSpacing true
|
||||
ForceLTR true
|
||||
EditExternal true
|
||||
End
|
||||
|
||||
InsetLayout Phantom
|
||||
|
@ -11,7 +11,7 @@
|
||||
# This script will update a .layout file to current format
|
||||
|
||||
# The latest layout format is also defined in src/TextClass.cpp
|
||||
currentFormat = 69
|
||||
currentFormat = 70
|
||||
|
||||
|
||||
# Incremented to format 4, 6 April 2007, lasgouttes
|
||||
@ -233,6 +233,9 @@ currentFormat = 69
|
||||
# Incremented to format 69, 16 August 2018 by spitz
|
||||
# New argument type "listpreamble"
|
||||
|
||||
# Incremented to format 69, 5 June 2018 by rkh
|
||||
# New InsetLayout tag EditExternal
|
||||
|
||||
# Do not forget to document format change in Customization
|
||||
# Manual (section "Declaring a new text class").
|
||||
|
||||
@ -482,7 +485,7 @@ def convert(lines, end_format):
|
||||
i += 1
|
||||
continue
|
||||
|
||||
if format >= 65 and format <= 68:
|
||||
if format >= 65 and format <= 69:
|
||||
# nothing to do.
|
||||
i += 1
|
||||
continue
|
||||
|
@ -62,7 +62,7 @@ namespace lyx {
|
||||
// You should also run the development/tools/updatelayouts.py script,
|
||||
// to update the format of all of our layout files.
|
||||
//
|
||||
int const LAYOUT_FORMAT = 69; //spitz: New argument type listpreamble
|
||||
int const LAYOUT_FORMAT = 70; // rkh: InsetLayout EditExternal
|
||||
|
||||
|
||||
// Layout format for the current lyx file format. Controls which format is
|
||||
|
@ -15,15 +15,19 @@
|
||||
#include "InsetCollapsible.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "CutAndPaste.h"
|
||||
#include "Cursor.h"
|
||||
#include "Dimension.h"
|
||||
#include "Format.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "InsetLayout.h"
|
||||
#include "Lexer.h"
|
||||
#include "MetricsInfo.h"
|
||||
#include "OutputParams.h"
|
||||
#include "TextClass.h"
|
||||
#include "TocBackend.h"
|
||||
|
||||
#include "frontends/FontMetrics.h"
|
||||
@ -35,6 +39,7 @@
|
||||
#include "support/lassert.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/RefChanger.h"
|
||||
#include "support/TempFile.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -55,7 +60,18 @@ InsetCollapsible::InsetCollapsible(InsetCollapsible const & rhs)
|
||||
: InsetText(rhs),
|
||||
status_(rhs.status_),
|
||||
labelstring_(rhs.labelstring_)
|
||||
{}
|
||||
{
|
||||
tempfile_.reset();
|
||||
}
|
||||
|
||||
|
||||
InsetCollapsible const & InsetCollapsible::operator=(InsetCollapsible const & that)
|
||||
{
|
||||
if (&that == this)
|
||||
return *this;
|
||||
*this = InsetCollapsible(that);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
InsetCollapsible::~InsetCollapsible()
|
||||
@ -393,6 +409,9 @@ void InsetCollapsible::cursorPos(BufferView const & bv,
|
||||
|
||||
bool InsetCollapsible::editable() const
|
||||
{
|
||||
if (tempfile_)
|
||||
return false;
|
||||
|
||||
switch (decoration()) {
|
||||
case InsetLayout::CLASSIC:
|
||||
case InsetLayout::MINIMALISTIC:
|
||||
@ -405,6 +424,9 @@ bool InsetCollapsible::editable() const
|
||||
|
||||
bool InsetCollapsible::descendable(BufferView const & bv) const
|
||||
{
|
||||
if (tempfile_)
|
||||
return false;
|
||||
|
||||
return geometry(bv) != ButtonOnly;
|
||||
}
|
||||
|
||||
@ -550,6 +572,41 @@ void InsetCollapsible::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
cur.dispatched();
|
||||
break;
|
||||
|
||||
case LFUN_INSET_EDIT: {
|
||||
cur.push(*this);
|
||||
text().selectAll(cur);
|
||||
string const format =
|
||||
cur.buffer()->params().documentClass().outputFormat();
|
||||
string const ext = theFormats().extension(format);
|
||||
tempfile_.reset(new support::TempFile("ert_editXXXXXX." + ext));
|
||||
support::FileName const tempfilename = tempfile_->name();
|
||||
string const name = tempfilename.toFilesystemEncoding();
|
||||
ofdocstream os(name.c_str());
|
||||
os << cur.selectionAsString(false);
|
||||
os.close();
|
||||
// Since we lock the inset while the external file is edited,
|
||||
// we need to move the cursor outside and clear any selection inside
|
||||
cur.clearSelection();
|
||||
cur.pop();
|
||||
cur.leaveInset(*this);
|
||||
theFormats().edit(buffer(), tempfilename, format);
|
||||
break;
|
||||
}
|
||||
case LFUN_INSET_END_EDIT: {
|
||||
support::FileName const tempfilename = tempfile_->name();
|
||||
docstring const s = tempfilename.fileContents("UTF-8");
|
||||
cur.recordUndoInset(this);
|
||||
cur.push(*this);
|
||||
text().selectAll(cur);
|
||||
cap::replaceSelection(cur);
|
||||
cur.text()->insertStringAsLines(cur, s, cur.current_font);
|
||||
// FIXME (gb) it crashes without this
|
||||
cur.fixIfBroken();
|
||||
tempfile_.reset();
|
||||
cur.pop();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
InsetText::doDispatch(cur, cmd);
|
||||
break;
|
||||
@ -573,6 +630,14 @@ bool InsetCollapsible::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
flag.setEnabled(false);
|
||||
return true;
|
||||
|
||||
case LFUN_INSET_EDIT:
|
||||
flag.setEnabled(getLayout().editExternally() && tempfile_ == 0);
|
||||
return true;
|
||||
|
||||
case LFUN_INSET_END_EDIT:
|
||||
flag.setEnabled(getLayout().editExternally() && tempfile_ != 0);
|
||||
return true;
|
||||
|
||||
default:
|
||||
return InsetText::getStatus(cur, cmd, flag);
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ namespace lyx {
|
||||
class CursorSlice;
|
||||
class InsetLayout;
|
||||
|
||||
namespace support { class TempFile; }
|
||||
|
||||
namespace frontend { class Painter; }
|
||||
|
||||
/** A collapsible text inset
|
||||
@ -37,6 +39,8 @@ public:
|
||||
///
|
||||
InsetCollapsible(InsetCollapsible const & rhs);
|
||||
///
|
||||
InsetCollapsible const & operator=(InsetCollapsible const &);
|
||||
///
|
||||
virtual ~InsetCollapsible();
|
||||
///
|
||||
InsetCollapsible * asInsetCollapsible() { return this; }
|
||||
@ -169,6 +173,8 @@ private:
|
||||
Dimension dimensionCollapsed(BufferView const & bv) const;
|
||||
///
|
||||
docstring labelstring_;
|
||||
///
|
||||
unique_ptr<support::TempFile> tempfile_;
|
||||
|
||||
// These variables depend of the view in which the inset is displayed
|
||||
struct View
|
||||
|
@ -17,9 +17,7 @@
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Cursor.h"
|
||||
#include "CutAndPaste.h"
|
||||
#include "DispatchResult.h"
|
||||
#include "Format.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "Language.h"
|
||||
@ -29,10 +27,8 @@
|
||||
#include "OutputParams.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "Paragraph.h"
|
||||
#include "TextClass.h"
|
||||
|
||||
#include "support/docstream.h"
|
||||
#include "support/FileName.h"
|
||||
#include "support/gettext.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/TempFile.h"
|
||||
@ -51,21 +47,11 @@ InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
|
||||
}
|
||||
|
||||
|
||||
// Do not copy the temp file on purpose: If a copy of an inset which is
|
||||
// currently being edited is made, then we simply copy the current contents.
|
||||
InsetERT::InsetERT(InsetERT const & that) : InsetCollapsible(that)
|
||||
InsetERT::InsetERT(InsetERT const & old)
|
||||
: InsetCollapsible(old)
|
||||
{}
|
||||
|
||||
|
||||
InsetERT & InsetERT::operator=(InsetERT const & that)
|
||||
{
|
||||
if (&that == this)
|
||||
return *this;
|
||||
tempfile_.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void InsetERT::write(ostream & os) const
|
||||
{
|
||||
os << "ERT" << "\n";
|
||||
@ -129,40 +115,6 @@ int InsetERT::docbook(odocstream & os, OutputParams const &) const
|
||||
void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
{
|
||||
switch (cmd.action()) {
|
||||
case LFUN_INSET_EDIT: {
|
||||
cur.push(*this);
|
||||
text().selectAll(cur);
|
||||
string const format =
|
||||
cur.buffer()->params().documentClass().outputFormat();
|
||||
string const ext = theFormats().extension(format);
|
||||
tempfile_.reset(new TempFile("ert_editXXXXXX." + ext));
|
||||
FileName const tempfilename = tempfile_->name();
|
||||
string const name = tempfilename.toFilesystemEncoding();
|
||||
ofdocstream os(name.c_str());
|
||||
os << cur.selectionAsString(false);
|
||||
os.close();
|
||||
// Since we lock the inset while the external file is edited,
|
||||
// we need to move the cursor outside and clear any selection inside
|
||||
cur.clearSelection();
|
||||
cur.pop();
|
||||
cur.leaveInset(*this);
|
||||
theFormats().edit(buffer(), tempfilename, format);
|
||||
break;
|
||||
}
|
||||
case LFUN_INSET_END_EDIT: {
|
||||
FileName const tempfilename = tempfile_->name();
|
||||
docstring const s = tempfilename.fileContents("UTF-8");
|
||||
cur.recordUndoInset(this);
|
||||
cur.push(*this);
|
||||
text().selectAll(cur);
|
||||
cap::replaceSelection(cur);
|
||||
cur.text()->insertStringAsLines(cur, s, cur.current_font);
|
||||
// FIXME it crashes without this
|
||||
cur.fixIfBroken();
|
||||
tempfile_.reset();
|
||||
cur.pop();
|
||||
break;
|
||||
}
|
||||
case LFUN_INSET_MODIFY:
|
||||
if (cmd.getArg(0) == "ert") {
|
||||
cur.recordUndoInset(this);
|
||||
@ -204,21 +156,6 @@ bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
}
|
||||
|
||||
|
||||
bool InsetERT::editable() const
|
||||
{
|
||||
if (tempfile_)
|
||||
return false;
|
||||
return InsetCollapsible::editable();
|
||||
}
|
||||
|
||||
|
||||
bool InsetERT::descendable(BufferView const & bv) const
|
||||
{
|
||||
if (tempfile_)
|
||||
return false;
|
||||
return InsetCollapsible::descendable(bv);
|
||||
}
|
||||
|
||||
|
||||
docstring const InsetERT::buttonLabel(BufferView const & bv) const
|
||||
{
|
||||
|
@ -28,18 +28,12 @@ namespace lyx {
|
||||
|
||||
class Language;
|
||||
|
||||
namespace support {
|
||||
class TempFile;
|
||||
}
|
||||
|
||||
class InsetERT : public InsetCollapsible {
|
||||
public:
|
||||
///
|
||||
InsetERT(Buffer *, CollapseStatus status = Open);
|
||||
///
|
||||
InsetERT(InsetERT const &);
|
||||
///
|
||||
InsetERT & operator=(InsetERT const &);
|
||||
InsetERT(InsetERT const & old);
|
||||
///
|
||||
static CollapseStatus string2params(std::string const &);
|
||||
///
|
||||
@ -70,10 +64,6 @@ private:
|
||||
///
|
||||
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
|
||||
///
|
||||
bool editable() const;
|
||||
///
|
||||
bool descendable(BufferView const &) const;
|
||||
///
|
||||
Inset * clone() const { return new InsetERT(*this); }
|
||||
///
|
||||
docstring const buttonLabel(BufferView const & bv) const;
|
||||
|
@ -90,6 +90,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
|
||||
IL_CUSTOMPARS,
|
||||
IL_DECORATION,
|
||||
IL_DISPLAY,
|
||||
IL_EDITEXTERNAL,
|
||||
IL_FIXEDWIDTH_PREAMBLE_ENCODING,
|
||||
IL_FONT,
|
||||
IL_FORCE_LOCAL_FONT_SWITCH,
|
||||
@ -146,6 +147,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
|
||||
{ "custompars", IL_CUSTOMPARS },
|
||||
{ "decoration", IL_DECORATION },
|
||||
{ "display", IL_DISPLAY },
|
||||
{ "editexternal", IL_EDITEXTERNAL },
|
||||
{ "end", IL_END },
|
||||
{ "fixedwidthpreambleencoding", IL_FIXEDWIDTH_PREAMBLE_ENCODING },
|
||||
{ "font", IL_FONT },
|
||||
@ -473,6 +475,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
|
||||
case IL_ISTOCCAPTION:
|
||||
lex >> is_toc_caption_;
|
||||
break;
|
||||
case IL_EDITEXTERNAL:
|
||||
lex >> edit_external_;
|
||||
break;
|
||||
case IL_END:
|
||||
getout = true;
|
||||
break;
|
||||
|
@ -189,6 +189,8 @@ public:
|
||||
std::string tocType() const { return toc_type_; }
|
||||
///
|
||||
bool isTocCaption() const { return is_toc_caption_; }
|
||||
///
|
||||
bool editExternally () const { return edit_external_; }
|
||||
private:
|
||||
///
|
||||
void makeDefaultCSS() const;
|
||||
@ -312,6 +314,8 @@ private:
|
||||
std::string toc_type_;
|
||||
///
|
||||
bool is_toc_caption_;
|
||||
///
|
||||
bool edit_external_;
|
||||
};
|
||||
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user