1 // -*- C++ -*- 2 /** 3 * \file InsetInclude.h 4 * This file is part of LyX, the document processor. 5 * Licence details can be found in the file COPYING. 6 * 7 * \author Lars Gullik Bjønnes 8 * \author Richard Heck (conversion to InsetCommand) 9 * 10 * Full author contact details are available in file CREDITS. 11 */ 12 13 #ifndef INSET_INCLUDE_H 14 #define INSET_INCLUDE_H 15 16 #include "InsetCommand.h" 17 18 #include "RenderButton.h" 19 20 #include "support/unique_ptr.h" 21 22 23 namespace lyx { 24 25 class BiblioInfo; 26 class Buffer; 27 class Dimension; 28 class InsetCommandParams; 29 class InsetLabel; 30 class LaTeXFeatures; 31 class RenderMonitoredPreview; 32 33 namespace support { 34 class FileNameList; 35 } 36 37 /// for including tex/lyx files 38 class InsetInclude : public InsetCommand { 39 // Disable assignment operator, since it is not used, and cannot be 40 // implemented consistently with the copy constructor, because 41 // include_label is const. 42 InsetInclude & operator=(InsetInclude const &); 43 public: 44 /// 45 InsetInclude(Buffer * buf, InsetCommandParams const &); 46 /// 47 ~InsetInclude(); 48 49 /// 50 void setChildBuffer(Buffer * buffer); 51 /// \return the child buffer if the file is a LyX doc and could be loaded 52 Buffer * getChildBuffer() const; 53 54 /** Update the cache with all bibfiles in use of the child buffer 55 * (including bibfiles of grandchild documents). 56 * Does nothing if the child document is not loaded to prevent 57 * automatic loading of all child documents upon loading the master. 58 * \param buffer the Buffer containing this inset. 59 */ 60 void updateBibfilesCache(); 61 62 /** Return the cache with all bibfiles in use of the child buffer 63 * (including bibfiles of grandchild documents). 64 * Return an empty vector if the child doc is not loaded. 65 * \param buffer the Buffer containing this inset. 66 */ 67 support::FileNameList const & 68 getBibfilesCache() const; 69 70 /// 71 void updateCommand(); 72 /// 73 void write(std::ostream &) const; 74 75 /// \name Public functions inherited from Inset class 76 //@{ 77 /// 78 void setBuffer(Buffer & buffer); 79 /// isLabeled()80 bool isLabeled() const { return true; } 81 /// Override these InsetButton methods if Previewing 82 void metrics(MetricsInfo & mi, Dimension & dim) const; 83 /// 84 void draw(PainterInfo & pi, int x, int y) const; 85 /// 86 DisplayType display() const; 87 /// lyxCode()88 InsetCode lyxCode() const { return INCLUDE_CODE; } 89 /// 90 docstring layoutName() const; 91 /** Fills \c key 92 * \param keys the list of bibkeys in the child buffer. 93 * \param it not used here 94 */ 95 void collectBibKeys(InsetIterator const &, support::FileNameList &) const; 96 /// hasSettings()97 bool hasSettings() const { return true; } 98 /// 99 void latex(otexstream &, OutputParams const &) const; 100 /// 101 int plaintext(odocstringstream & ods, OutputParams const & op, 102 size_t max_length = INT_MAX) const; 103 /// 104 int docbook(odocstream &, OutputParams const &) const; 105 /// 106 docstring xhtml(XHTMLStream &, OutputParams const &) const; 107 /// 108 void validate(LaTeXFeatures &) const; 109 /// 110 void addPreview(DocIterator const &, graphics::PreviewLoader &) const; 111 /// 112 void addToToc(DocIterator const & di, bool output_active, 113 UpdateType utype, TocBackend & backend) const; 114 /// 115 void updateBuffer(ParIterator const &, UpdateType); 116 /// 117 std::string contextMenuName() const; 118 //@} 119 120 /// \name Static public methods obligated for InsetCommand derived classes 121 //@{ 122 /// 123 static ParamInfo const & findInfo(std::string const &); 124 /// defaultCommand()125 static std::string defaultCommand() { return "include"; } 126 /// 127 static bool isCompatibleCommand(std::string const & s); 128 //@} 129 130 protected: 131 /// 132 InsetInclude(InsetInclude const &); 133 134 private: 135 /** Slot receiving a signal that the external file has changed 136 * and the preview should be regenerated. 137 */ 138 void fileChanged() const; 139 /// \return loaded Buffer or zero if the file loading did not proceed. 140 Buffer * loadIfNeeded() const; 141 /// launch external application 142 void editIncluded(std::string const & file); 143 /// 144 bool isChildIncluded() const; 145 146 /// \name Private functions inherited from Inset class 147 //@{ clone()148 Inset * clone() const { return new InsetInclude(*this); } 149 /// 150 void doDispatch(Cursor & cur, FuncRequest & cmd); 151 /// 152 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; 153 //@} 154 155 /// \name Private functions inherited from InsetCommand class 156 //@{ 157 /// set the parameters 158 // FIXME:InsetCommmand::setParams is not virtual 159 void setParams(InsetCommandParams const & params); 160 /// get the text displayed on the button 161 docstring screenLabel() const; 162 //@} 163 164 /// holds the entity name that defines the file location (SGML) 165 docstring const include_label; 166 167 /// The pointer never changes although *preview_'s contents may. 168 unique_ptr<RenderMonitoredPreview> const preview_; 169 170 /// 171 mutable bool failedtoload_; 172 /// cache 173 mutable bool set_label_; 174 mutable RenderButton button_; 175 mutable docstring listings_label_; 176 InsetLabel * label_; 177 mutable Buffer * child_buffer_; 178 }; 179 180 181 } // namespace lyx 182 183 #endif // INSET_INCLUDE_H 184