externally.
#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
\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
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
ResetsFont false
ForceOwnlines true
NeedCProtect true
+ EditExternal true
End
KeepEmpty true
FreeSpacing true
ForceLTR true
+ EditExternal true
End
InsetLayout Phantom
# 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
# 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").
i += 1
continue
- if format >= 65 and format <= 68:
+ if format >= 65 and format <= 69:
# nothing to do.
i += 1
continue
// 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
#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"
#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/RefChanger.h"
+#include "support/TempFile.h"
using namespace std;
: 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()
bool InsetCollapsible::editable() const
{
+ if (tempfile_)
+ return false;
+
switch (decoration()) {
case InsetLayout::CLASSIC:
case InsetLayout::MINIMALISTIC:
bool InsetCollapsible::descendable(BufferView const & bv) const
{
+ if (tempfile_)
+ return false;
+
return geometry(bv) != ButtonOnly;
}
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;
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);
}
class CursorSlice;
class InsetLayout;
+namespace support { class TempFile; }
+
namespace frontend { class Painter; }
/** A collapsible text inset
///
InsetCollapsible(InsetCollapsible const & rhs);
///
+ InsetCollapsible const & operator=(InsetCollapsible const &);
+ ///
virtual ~InsetCollapsible();
///
InsetCollapsible * asInsetCollapsible() { return this; }
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
#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"
#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"
}
-// 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";
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);
}
-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
{
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 &);
///
///
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;
IL_CUSTOMPARS,
IL_DECORATION,
IL_DISPLAY,
+ IL_EDITEXTERNAL,
IL_FIXEDWIDTH_PREAMBLE_ENCODING,
IL_FONT,
IL_FORCE_LOCAL_FONT_SWITCH,
{ "custompars", IL_CUSTOMPARS },
{ "decoration", IL_DECORATION },
{ "display", IL_DISPLAY },
+ { "editexternal", IL_EDITEXTERNAL },
{ "end", IL_END },
{ "fixedwidthpreambleencoding", IL_FIXEDWIDTH_PREAMBLE_ENCODING },
{ "font", IL_FONT },
case IL_ISTOCCAPTION:
lex >> is_toc_caption_;
break;
+ case IL_EDITEXTERNAL:
+ lex >> edit_external_;
+ break;
case IL_END:
getout = true;
break;
std::string tocType() const { return toc_type_; }
///
bool isTocCaption() const { return is_toc_caption_; }
+ ///
+ bool editExternally () const { return edit_external_; }
private:
///
void makeDefaultCSS() const;
std::string toc_type_;
///
bool is_toc_caption_;
+ ///
+ bool edit_external_;
};
///