mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
only a partial patch. will rework immediately.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20785 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f39116c9df
commit
58f5bed05d
@ -1,164 +0,0 @@
|
||||
/**
|
||||
* \file ControlEmbeddedFiles.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Bo Peng
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "ControlEmbeddedFiles.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
|
||||
#include "FuncRequest.h"
|
||||
#include "gettext.h"
|
||||
#include "debug.h"
|
||||
#include "Format.h"
|
||||
#include "LyXRC.h"
|
||||
|
||||
#include "frontend_helpers.h"
|
||||
#include "frontends/LyXView.h"
|
||||
|
||||
#include "support/FileFilterList.h"
|
||||
#include "support/convert.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::FileFilterList;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
ControlEmbeddedFiles::ControlEmbeddedFiles(Dialog & parent)
|
||||
: Controller(parent)
|
||||
{}
|
||||
|
||||
|
||||
EmbeddedFiles & ControlEmbeddedFiles::embeddedFiles()
|
||||
{
|
||||
return buffer().embeddedFiles();
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::initialiseParams(string const &)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::updateEmbeddedFiles()
|
||||
{
|
||||
// copy buffer embeddedFiles to a local copy
|
||||
buffer().embeddedFiles().update();
|
||||
buffer().embeddingChanged();
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::dispatchMessage(string const & msg)
|
||||
{
|
||||
// FIXME: the right thing to do? QT guys?
|
||||
// lyx view will only be updated if we do something to the main window. :-)
|
||||
dispatch(FuncRequest(LFUN_MESSAGE, msg));
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::isReadonly()
|
||||
{
|
||||
return buffer().isReadonly();
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::setEmbedding(bool enable)
|
||||
{
|
||||
if (embeddedFiles().enabled() == enable)
|
||||
return;
|
||||
embeddedFiles().enable(enable);
|
||||
buffer().markDirty();
|
||||
if (enable)
|
||||
dispatchMessage("Stop saving in bundled format.");
|
||||
else
|
||||
dispatchMessage("Save in bundled format.");
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::goTo(EmbeddedFile const & item, int idx)
|
||||
{
|
||||
BOOST_ASSERT(idx < item.refCount());
|
||||
item.saveBookmark(&buffer(), idx);
|
||||
lyxview().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::view(EmbeddedFile const & item)
|
||||
{
|
||||
formats.view(buffer(), item, formats.getFormatFromFile(item));
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update)
|
||||
{
|
||||
if (item.embedded() == embed)
|
||||
return;
|
||||
item.setEmbed(embed);
|
||||
if (update) {
|
||||
if (embed)
|
||||
item.updateFromExternalFile(&buffer());
|
||||
else
|
||||
item.extract(&buffer());
|
||||
item.updateInsets(&buffer());
|
||||
// FIXME: unless we record the type of file item, we will
|
||||
// need to update all possible dialogs (bibtex etc).
|
||||
updateDialog("graphics");
|
||||
}
|
||||
if (embed)
|
||||
dispatchMessage("Embed file " + item.outputFilename(buffer().filePath()));
|
||||
else
|
||||
dispatchMessage("Stop embedding file " + item.outputFilename(buffer().filePath()));
|
||||
buffer().markDirty();
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::browseAndAddFile()
|
||||
{
|
||||
std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
|
||||
from_utf8(lyxrc.document_path));
|
||||
FileFilterList const filter(_("All file (*.*)"));
|
||||
docstring const file = browseRelFile(docstring(), from_utf8(bufferFilepath()),
|
||||
_("Select a file to embed"),
|
||||
filter, false, dir1);
|
||||
if (!file.empty()) {
|
||||
EmbeddedFile & ef = embeddedFiles().registerFile(to_utf8(file), true);
|
||||
if (embeddedFiles().enabled())
|
||||
ef.updateFromExternalFile(&buffer());
|
||||
buffer().markDirty();
|
||||
dispatchMessage("Add an embedded file" + to_utf8(file));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::extract(EmbeddedFile const & item)
|
||||
{
|
||||
if (item.embedded())
|
||||
return item.extract(&buffer());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::update(EmbeddedFile const & item)
|
||||
{
|
||||
if (item.embedded())
|
||||
return item.updateFromExternalFile(&buffer());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
@ -1,71 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file ControlEmbeddedFiles.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Bo Peng
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef CONTROLEMBEDDEDFILES_H
|
||||
#define CONTROLEMBEDDEDFILES_H
|
||||
|
||||
#include "Dialog.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
|
||||
namespace lyx {
|
||||
|
||||
namespace frontend {
|
||||
|
||||
class ControlEmbeddedFiles : public Controller {
|
||||
public:
|
||||
///
|
||||
ControlEmbeddedFiles(Dialog &);
|
||||
///
|
||||
virtual ~ControlEmbeddedFiles() {}
|
||||
///
|
||||
EmbeddedFiles & embeddedFiles();
|
||||
///
|
||||
virtual bool initialiseParams(std::string const &);
|
||||
/// obtain embedded files from buffer
|
||||
void updateEmbeddedFiles();
|
||||
///
|
||||
virtual void clearParams() {};
|
||||
///
|
||||
virtual bool isBufferDependent() const { return true; }
|
||||
///
|
||||
bool canApply() const { return true; }
|
||||
///
|
||||
virtual bool canApplyToReadOnly() const { return false; }
|
||||
///
|
||||
void dispatchMessage(std::string const & msg);
|
||||
///
|
||||
void dispatchParams() {};
|
||||
///
|
||||
bool isReadonly();
|
||||
///
|
||||
void setEmbedding(bool enable);
|
||||
///
|
||||
void goTo(EmbeddedFile const & item, int idx);
|
||||
///
|
||||
void view(EmbeddedFile const & item);
|
||||
///
|
||||
void setEmbed(EmbeddedFile & item, bool embed, bool update);
|
||||
///
|
||||
bool browseAndAddFile();
|
||||
///
|
||||
bool extract(EmbeddedFile const & item);
|
||||
///
|
||||
bool update(EmbeddedFile const & item);
|
||||
|
||||
protected:
|
||||
//
|
||||
std::string message_;
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#endif // CONTROLEMBEDDEDFILES_H
|
@ -1,102 +0,0 @@
|
||||
/**
|
||||
* \file ControlViewSource.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author John Levon
|
||||
* \author Angus Leeming
|
||||
* \author Bo Peng
|
||||
* \author Abdelrazak Younes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "ControlViewSource.h"
|
||||
|
||||
#include "BufferView.h"
|
||||
#include "Buffer.h"
|
||||
#include "Cursor.h"
|
||||
#include "gettext.h"
|
||||
#include "Paragraph.h"
|
||||
#include "TexRow.h"
|
||||
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
ControlViewSource::ControlViewSource(Dialog & parent)
|
||||
: Controller(parent)
|
||||
{}
|
||||
|
||||
|
||||
bool ControlViewSource::initialiseParams(string const & /*source*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
docstring const ControlViewSource::updateContent(bool fullSource)
|
||||
{
|
||||
// get the *top* level paragraphs that contain the cursor,
|
||||
// or the selected text
|
||||
pit_type par_begin;
|
||||
pit_type par_end;
|
||||
|
||||
BufferView * view = bufferview();
|
||||
if (!view->cursor().selection()) {
|
||||
par_begin = view->cursor().bottom().pit();
|
||||
par_end = par_begin;
|
||||
} else {
|
||||
par_begin = view->cursor().selectionBegin().bottom().pit();
|
||||
par_end = view->cursor().selectionEnd().bottom().pit();
|
||||
}
|
||||
if (par_begin > par_end)
|
||||
std::swap(par_begin, par_end);
|
||||
odocstringstream ostr;
|
||||
view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource);
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, int> ControlViewSource::getRows() const
|
||||
{
|
||||
BufferView const * view = bufferview();
|
||||
CursorSlice beg = view->cursor().selectionBegin().bottom();
|
||||
CursorSlice end = view->cursor().selectionEnd().bottom();
|
||||
|
||||
int begrow = view->buffer().texrow().
|
||||
getRowFromIdPos(beg.paragraph().id(), beg.pos());
|
||||
int endrow = view->buffer().texrow().
|
||||
getRowFromIdPos(end.paragraph().id(), end.pos());
|
||||
int nextendrow = view->buffer().texrow().
|
||||
getRowFromIdPos(end.paragraph().id(), end.pos() + 1);
|
||||
return std::make_pair(begrow, endrow == nextendrow ? endrow : (nextendrow - 1));
|
||||
}
|
||||
|
||||
|
||||
void ControlViewSource::clearParams()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
docstring const ControlViewSource::title() const
|
||||
{
|
||||
switch (docType()) {
|
||||
case LATEX:
|
||||
return _("LaTeX Source");
|
||||
case DOCBOOK:
|
||||
return _("DocBook Source");
|
||||
case LITERATE:
|
||||
return _("Literate Source");
|
||||
default:
|
||||
BOOST_ASSERT(false);
|
||||
return docstring();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
@ -1,58 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file ControlViewSource.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author John Levon
|
||||
* \author Angus Leeming
|
||||
* \Bo Peng
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef CONTROLVIEWSOURCE_H
|
||||
#define CONTROLVIEWSOURCE_H
|
||||
|
||||
#include "Dialog.h"
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
/**
|
||||
* A controller for a read-only text browser.
|
||||
*/
|
||||
class ControlViewSource : public Controller {
|
||||
public:
|
||||
///
|
||||
ControlViewSource(Dialog &);
|
||||
/** \param source source code to be displayed
|
||||
*/
|
||||
virtual bool initialiseParams(std::string const & source);
|
||||
///
|
||||
virtual void clearParams();
|
||||
///
|
||||
virtual void dispatchParams() {}
|
||||
///
|
||||
virtual bool isBufferDependent() const { return true; }
|
||||
///
|
||||
bool canApply() const { return true; }
|
||||
///
|
||||
virtual bool canApplyToReadOnly() const { return true; }
|
||||
|
||||
/// The title displayed by the dialog reflects source type.
|
||||
docstring const title() const;
|
||||
|
||||
/** get the source code of selected paragraphs, or the whole document
|
||||
\param fullSource get full source code
|
||||
*/
|
||||
docstring const updateContent(bool fullSource);
|
||||
/** get the cursor position in the source code
|
||||
*/
|
||||
std::pair<int, int> getRows() const;
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#endif // CONTROLVIEWSOURCE_H
|
@ -12,10 +12,8 @@ SOURCEFILES = \
|
||||
ControlCommand.cpp \
|
||||
ControlCommandBuffer.cpp \
|
||||
ControlDocument.cpp \
|
||||
ControlEmbeddedFiles.cpp \
|
||||
ControlExternal.cpp \
|
||||
ControlGraphics.cpp \
|
||||
ControlViewSource.cpp \
|
||||
ControlMath.cpp \
|
||||
ControlParagraph.cpp \
|
||||
ControlPrefs.cpp \
|
||||
@ -32,10 +30,8 @@ HEADERFILES = \
|
||||
ControlCommand.h \
|
||||
ControlCommandBuffer.h \
|
||||
ControlDocument.h \
|
||||
ControlEmbeddedFiles.h \
|
||||
ControlExternal.h \
|
||||
ControlGraphics.h \
|
||||
ControlViewSource.h \
|
||||
ControlMath.h \
|
||||
ControlParagraph.h \
|
||||
ControlPrefs.h \
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "GuiSpellchecker.h"
|
||||
#include "GuiToc.h"
|
||||
#include "GuiView.h"
|
||||
#include "GuiViewSource.h"
|
||||
#include "TocWidget.h"
|
||||
#include "GuiURL.h"
|
||||
|
||||
@ -127,6 +126,7 @@ Dialog * createGuiTexInfo(LyXView & lv);
|
||||
Dialog * createGuiThesaurus(LyXView & lv);
|
||||
Dialog * createGuiURL(LyXView & lv);
|
||||
Dialog * createGuiVSpace(LyXView & lv);
|
||||
Dialog * createGuiViewSource(LyXView & lv);
|
||||
Dialog * createGuiWrap(LyXView & lv);
|
||||
|
||||
|
||||
@ -189,8 +189,7 @@ Dialog * Dialogs::build(string const & name)
|
||||
} else if (name == "log") {
|
||||
createGuiLog(lyxview_);
|
||||
} else if (name == "view-source") {
|
||||
dialog = new DockView<ControlViewSource, GuiViewSourceDialog>(
|
||||
guiview, name, Qt::BottomDockWidgetArea);
|
||||
createGuiViewSource(lyxview_);
|
||||
} else if (name == "mathdelimiter") {
|
||||
dialog = new GuiDelimiterDialog(lyxview_);
|
||||
} else if (name == "mathmatrix") {
|
||||
|
@ -16,11 +16,19 @@
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "BufferView.h"
|
||||
#include "Buffer.h"
|
||||
#include "Cursor.h"
|
||||
#include "gettext.h"
|
||||
#include "Paragraph.h"
|
||||
#include "TexRow.h"
|
||||
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocument>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
@ -164,6 +172,78 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
|
||||
}
|
||||
|
||||
|
||||
ControlViewSource::ControlViewSource(Dialog & parent)
|
||||
: Controller(parent)
|
||||
{}
|
||||
|
||||
|
||||
bool ControlViewSource::initialiseParams(string const & /*source*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
docstring const ControlViewSource::updateContent(bool fullSource)
|
||||
{
|
||||
// get the *top* level paragraphs that contain the cursor,
|
||||
// or the selected text
|
||||
pit_type par_begin;
|
||||
pit_type par_end;
|
||||
|
||||
BufferView * view = bufferview();
|
||||
if (!view->cursor().selection()) {
|
||||
par_begin = view->cursor().bottom().pit();
|
||||
par_end = par_begin;
|
||||
} else {
|
||||
par_begin = view->cursor().selectionBegin().bottom().pit();
|
||||
par_end = view->cursor().selectionEnd().bottom().pit();
|
||||
}
|
||||
if (par_begin > par_end)
|
||||
std::swap(par_begin, par_end);
|
||||
odocstringstream ostr;
|
||||
view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource);
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, int> ControlViewSource::getRows() const
|
||||
{
|
||||
BufferView const * view = bufferview();
|
||||
CursorSlice beg = view->cursor().selectionBegin().bottom();
|
||||
CursorSlice end = view->cursor().selectionEnd().bottom();
|
||||
|
||||
int begrow = view->buffer().texrow().
|
||||
getRowFromIdPos(beg.paragraph().id(), beg.pos());
|
||||
int endrow = view->buffer().texrow().
|
||||
getRowFromIdPos(end.paragraph().id(), end.pos());
|
||||
int nextendrow = view->buffer().texrow().
|
||||
getRowFromIdPos(end.paragraph().id(), end.pos() + 1);
|
||||
return std::make_pair(begrow, endrow == nextendrow ? endrow : (nextendrow - 1));
|
||||
}
|
||||
|
||||
|
||||
docstring const ControlViewSource::title() const
|
||||
{
|
||||
switch (docType()) {
|
||||
case LATEX:
|
||||
return _("LaTeX Source");
|
||||
case DOCBOOK:
|
||||
return _("DocBook Source");
|
||||
case LITERATE:
|
||||
return _("Literate Source");
|
||||
default:
|
||||
BOOST_ASSERT(false);
|
||||
return docstring();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Dialog * createGuiViewSource(LyXView & lv)
|
||||
{
|
||||
return new GuiViewSource(static_cast<GuiViewBase &>(lv));
|
||||
}
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -16,8 +16,12 @@
|
||||
|
||||
#include "ui_ViewSourceUi.h"
|
||||
|
||||
#include "ControlViewSource.h"
|
||||
#include "controllers/Dialog.h"
|
||||
#include "GuiView.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QWidget>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QTextCharFormat>
|
||||
@ -42,6 +46,7 @@ private:
|
||||
QTextCharFormat mathFormat;
|
||||
};
|
||||
|
||||
class ControlViewSource;
|
||||
|
||||
class GuiViewSourceDialog : public QWidget, public Ui::ViewSourceUi
|
||||
{
|
||||
@ -67,6 +72,95 @@ private:
|
||||
LaTeXHighlighter * highlighter_;
|
||||
};
|
||||
|
||||
/**
|
||||
* A controller for a read-only text browser.
|
||||
*/
|
||||
class ControlViewSource : public Controller {
|
||||
public:
|
||||
///
|
||||
ControlViewSource(Dialog &);
|
||||
/** \param source source code to be displayed
|
||||
*/
|
||||
bool initialiseParams(std::string const & source);
|
||||
///
|
||||
void clearParams() {}
|
||||
///
|
||||
void dispatchParams() {}
|
||||
///
|
||||
bool isBufferDependent() const { return true; }
|
||||
///
|
||||
bool canApply() const { return true; }
|
||||
///
|
||||
bool canApplyToReadOnly() const { return true; }
|
||||
|
||||
/// The title displayed by the dialog reflects source type.
|
||||
docstring const title() const;
|
||||
|
||||
/** get the source code of selected paragraphs, or the whole document
|
||||
\param fullSource get full source code
|
||||
*/
|
||||
docstring const updateContent(bool fullSource);
|
||||
/** get the cursor position in the source code
|
||||
*/
|
||||
std::pair<int, int> getRows() const;
|
||||
};
|
||||
|
||||
|
||||
class GuiViewSource : public QDockWidget, public Dialog
|
||||
{
|
||||
public:
|
||||
GuiViewSource(GuiViewBase & parent)
|
||||
: QDockWidget(&parent, Qt::WindowFlags(0)), name_("view-source")
|
||||
{
|
||||
ControlViewSource * c = new ControlViewSource(*this);
|
||||
controller_ = c;
|
||||
controller_->setLyXView(parent);
|
||||
widget_ = new GuiViewSourceDialog(*c);
|
||||
setWidget(widget_);
|
||||
setWindowTitle(widget_->windowTitle());
|
||||
parent.addDockWidget(Qt::BottomDockWidgetArea, this);
|
||||
}
|
||||
~GuiViewSource() { delete widget_; delete controller_; }
|
||||
|
||||
/// Dialog inherited methods
|
||||
//@{
|
||||
void applyView() {}
|
||||
void hideView() { QDockWidget::hide(); }
|
||||
void showData(std::string const & data)
|
||||
{
|
||||
controller_->initialiseParams(data);
|
||||
showView();
|
||||
}
|
||||
void showView()
|
||||
{
|
||||
widget_->updateView(); // make sure its up-to-date
|
||||
QDockWidget::show();
|
||||
}
|
||||
bool isVisibleView() const { return QDockWidget::isVisible(); }
|
||||
void checkStatus() { updateView(); }
|
||||
void redraw() { redrawView(); }
|
||||
void redrawView() {}
|
||||
void updateData(std::string const & data)
|
||||
{
|
||||
controller_->initialiseParams(data);
|
||||
updateView();
|
||||
}
|
||||
void updateView()
|
||||
{
|
||||
widget_->updateView();
|
||||
QDockWidget::update();
|
||||
}
|
||||
bool isClosing() const { return false; }
|
||||
void partialUpdateView(int /*id*/) {}
|
||||
Controller & controller() { return *controller_; }
|
||||
std::string name() const { return name_; }
|
||||
//@}
|
||||
private:
|
||||
/// The encapsulated widget.
|
||||
GuiViewSourceDialog * widget_;
|
||||
Controller * controller_;
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
Loading…
Reference in New Issue
Block a user