mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-13 11:52:45 +00:00
Update on view-source feature (r13610), from Bo Peng (ben.bob@gmail.com)
* src/text3.C, src/lyxfunc.C: no special treatment of view-source dialog now. * src/frontends/controllers/ControlViewSource.h, .C: handle everything (get source type, code) in the controller. * src/insets/insetbibtex.C, insetexternal.C insetinclude.C: add dryrun mode to file copying etc. * src/frontends/qt2/QViewSource.C: small changes when calling the controller. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13627 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
69664082da
commit
d7bccc5f88
src
12
src/buffer.C
12
src/buffer.C
@ -1576,7 +1576,7 @@ void Buffer::changeRefsIfUnique(string const & from, string const & to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Buffer::getSourceCode(ostream& os, lyx::pit_type par_begin, lyx::pit_type par_end)
|
void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end)
|
||||||
{
|
{
|
||||||
OutputParams runparams;
|
OutputParams runparams;
|
||||||
runparams.nice = true;
|
runparams.nice = true;
|
||||||
@ -1587,16 +1587,6 @@ void Buffer::getSourceCode(ostream& os, lyx::pit_type par_begin, lyx::pit_type p
|
|||||||
// No side effect of file copying and image conversion
|
// No side effect of file copying and image conversion
|
||||||
runparams.dryrun = true;
|
runparams.dryrun = true;
|
||||||
|
|
||||||
// set source type for the view-source dialog
|
|
||||||
if (isLatex())
|
|
||||||
os << "%LaTeX\n";
|
|
||||||
else if (isLinuxDoc())
|
|
||||||
os << "%LinuxDoc\n";
|
|
||||||
else if (isDocBook())
|
|
||||||
os << "%DocBook\n";
|
|
||||||
else
|
|
||||||
BOOST_ASSERT(false);
|
|
||||||
// start text
|
|
||||||
if (par_begin + 1 == par_end)
|
if (par_begin + 1 == par_end)
|
||||||
os << "% Preview source code for paragraph " << par_begin << "\n\n";
|
os << "% Preview source code for paragraph " << par_begin << "\n\n";
|
||||||
else
|
else
|
||||||
|
@ -14,8 +14,14 @@
|
|||||||
|
|
||||||
#include "ControlViewSource.h"
|
#include "ControlViewSource.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
|
#include "support/types.h"
|
||||||
|
#include "BufferView.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
#include "cursor.h"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::ostringstream;
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
@ -27,39 +33,58 @@ ControlViewSource::ControlViewSource(Dialog & parent)
|
|||||||
|
|
||||||
bool ControlViewSource::initialiseParams(string const & source)
|
bool ControlViewSource::initialiseParams(string const & source)
|
||||||
{
|
{
|
||||||
string sourcetype = source.substr(1, 5);
|
|
||||||
if (sourcetype == "LaTeX") {
|
|
||||||
type_ = LatexSource;
|
|
||||||
source_ = source.substr(7);
|
|
||||||
} else if (sourcetype == "Linux") {
|
|
||||||
type_ = LinuxDocSource;
|
|
||||||
source_ = source.substr(10);
|
|
||||||
} else if (sourcetype == "DocBo") {
|
|
||||||
type_ = DocBookSource;
|
|
||||||
source_ = source.substr(9);
|
|
||||||
} else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string const ControlViewSource::updateContent()
|
||||||
|
{
|
||||||
|
// get the *top* level paragraphs that contain the cursor,
|
||||||
|
// or the selected text
|
||||||
|
lyx::pit_type par_begin;
|
||||||
|
lyx::pit_type par_end;
|
||||||
|
|
||||||
|
BufferView * view = kernel().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);
|
||||||
|
ostringstream ostr;
|
||||||
|
view->buffer()->getSourceCode(ostr, par_begin, par_end + 1);
|
||||||
|
return ostr.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ControlViewSource::clearParams()
|
void ControlViewSource::clearParams()
|
||||||
{
|
{
|
||||||
source_.erase();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string const ControlViewSource::title() const
|
string const ControlViewSource::title() const
|
||||||
{
|
{
|
||||||
switch (type_) {
|
string source_type;
|
||||||
case LatexSource:
|
|
||||||
return _("LaTeX Source");
|
Kernel::DocType doctype = kernel().docType();
|
||||||
case LinuxDocSource:
|
switch (doctype) {
|
||||||
return _("LinuxDoc Source");
|
case Kernel::LATEX:
|
||||||
case DocBookSource:
|
source_type = "LaTeX";
|
||||||
return _("DocBook Source");
|
break;
|
||||||
|
case Kernel::LINUXDOC:
|
||||||
|
source_type = "LinuxDoc";
|
||||||
|
break;
|
||||||
|
case Kernel::DOCBOOK:
|
||||||
|
source_type = "DocBook";
|
||||||
|
break;
|
||||||
|
case Kernel::LITERATE:
|
||||||
|
source_type = "Literate";
|
||||||
|
default:
|
||||||
|
BOOST_ASSERT(false);
|
||||||
}
|
}
|
||||||
|
return _(source_type + " Source");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
@ -36,22 +36,11 @@ public:
|
|||||||
///
|
///
|
||||||
virtual bool isBufferDependent() const { return true; }
|
virtual bool isBufferDependent() const { return true; }
|
||||||
|
|
||||||
/// The title displayed by the dialog reflects the \c VIEWSOURCETYPE
|
/// The title displayed by the dialog reflects source type.
|
||||||
std::string const title() const;
|
std::string const title() const;
|
||||||
|
|
||||||
/// get the source code
|
/// get the source code of selected paragraphs
|
||||||
std::string const str() const { return source_; }
|
std::string const updateContent();
|
||||||
|
|
||||||
private:
|
|
||||||
/// Recognized source code type
|
|
||||||
enum SOURCETYPE {
|
|
||||||
LatexSource,
|
|
||||||
LinuxDocSource,
|
|
||||||
DocBookSource
|
|
||||||
};
|
|
||||||
|
|
||||||
SOURCETYPE type_;
|
|
||||||
std::string source_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "QViewSource.h"
|
#include "QViewSource.h"
|
||||||
#include "QViewSourceDialog.h"
|
#include "QViewSourceDialog.h"
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
#include "lyx_gui.h"
|
||||||
|
|
||||||
#include "controllers/ControlViewSource.h"
|
#include "controllers/ControlViewSource.h"
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ void QViewSource::build_dialog()
|
|||||||
dialog_->viewSourceTV->setReadOnly(true);
|
dialog_->viewSourceTV->setReadOnly(true);
|
||||||
dialog_->viewSourceTV->setTextFormat(Qt::PlainText);
|
dialog_->viewSourceTV->setTextFormat(Qt::PlainText);
|
||||||
// this is personal. I think source code should be in fixed-size font
|
// this is personal. I think source code should be in fixed-size font
|
||||||
QFont font("Courier New");
|
QFont font(toqstr(lyx_gui::typewriter_font_name()));
|
||||||
font.setFixedPitch(true);
|
font.setFixedPitch(true);
|
||||||
font.setStyleHint(QFont::TypeWriter);
|
font.setStyleHint(QFont::TypeWriter);
|
||||||
dialog_->viewSourceTV->setFont(font);
|
dialog_->viewSourceTV->setFont(font);
|
||||||
@ -50,8 +51,7 @@ void QViewSource::build_dialog()
|
|||||||
void QViewSource::update_contents()
|
void QViewSource::update_contents()
|
||||||
{
|
{
|
||||||
setTitle(controller().title());
|
setTitle(controller().title());
|
||||||
|
dialog_->viewSourceTV->setText(toqstr(controller().updateContent()));
|
||||||
dialog_->viewSourceTV->setText(toqstr(controller().str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
@ -161,7 +161,7 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os,
|
|||||||
normalize_name(buffer, runparams, input, ".bib");
|
normalize_name(buffer, runparams, input, ".bib");
|
||||||
string const in_file = database + ".bib";
|
string const in_file = database + ".bib";
|
||||||
|
|
||||||
if (!runparams.inComment && !runparams.nice &&
|
if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
|
||||||
isFileReadable(in_file)) {
|
isFileReadable(in_file)) {
|
||||||
|
|
||||||
// mangledFilename() needs the extension
|
// mangledFilename() needs the extension
|
||||||
@ -216,7 +216,7 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os,
|
|||||||
// exporting to .tex copy it to the tmp directory.
|
// exporting to .tex copy it to the tmp directory.
|
||||||
// This prevents problems with spaces and 8bit charcaters
|
// This prevents problems with spaces and 8bit charcaters
|
||||||
// in the file name.
|
// in the file name.
|
||||||
if (!runparams.inComment && !runparams.nice &&
|
if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
|
||||||
isFileReadable(in_file)) {
|
isFileReadable(in_file)) {
|
||||||
// use new style name
|
// use new style name
|
||||||
base = removeExtension(
|
base = removeExtension(
|
||||||
|
@ -688,7 +688,7 @@ int InsetExternal::latex(Buffer const & buf, ostream & os,
|
|||||||
// run through the LaTeX compiler.
|
// run through the LaTeX compiler.
|
||||||
// If we're running through the LaTeX compiler, we should write the
|
// If we're running through the LaTeX compiler, we should write the
|
||||||
// generated files in the bufer's temporary directory.
|
// generated files in the bufer's temporary directory.
|
||||||
bool const external_in_tmpdir = !runparams.nice;
|
bool const external_in_tmpdir = !runparams.nice && !runparams.dryrun;
|
||||||
|
|
||||||
// If the template has specified a PDFLaTeX output, then we try and
|
// If the template has specified a PDFLaTeX output, then we try and
|
||||||
// use that.
|
// use that.
|
||||||
|
@ -359,7 +359,7 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
|
|||||||
lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
|
lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
|
||||||
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
|
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
|
||||||
|
|
||||||
if (runparams.inComment)
|
if (runparams.inComment || runparams.dryrun)
|
||||||
// Don't try to load or copy the file
|
// Don't try to load or copy the file
|
||||||
;
|
;
|
||||||
else if (loadIfNeeded(buffer, params_)) {
|
else if (loadIfNeeded(buffer, params_)) {
|
||||||
|
@ -1165,9 +1165,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
data = freefont2string();
|
data = freefont2string();
|
||||||
if (!data.empty())
|
if (!data.empty())
|
||||||
owner->getDialogs().show("character", data);
|
owner->getDialogs().show("character", data);
|
||||||
}
|
} else if (name == "latexlog") {
|
||||||
|
|
||||||
else if (name == "latexlog") {
|
|
||||||
pair<Buffer::LogType, string> const logfile =
|
pair<Buffer::LogType, string> const logfile =
|
||||||
owner->buffer()->getLogName();
|
owner->buffer()->getLogName();
|
||||||
switch (logfile.first) {
|
switch (logfile.first) {
|
||||||
@ -1180,32 +1178,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
}
|
}
|
||||||
data += logfile.second;
|
data += logfile.second;
|
||||||
owner->getDialogs().show("log", data);
|
owner->getDialogs().show("log", data);
|
||||||
}
|
} else if (name == "vclog") {
|
||||||
else if (name == "vclog") {
|
|
||||||
string const data = "vc " +
|
string const data = "vc " +
|
||||||
owner->buffer()->lyxvc().getLogFile();
|
owner->buffer()->lyxvc().getLogFile();
|
||||||
owner->getDialogs().show("log", data);
|
owner->getDialogs().show("log", data);
|
||||||
}
|
} else
|
||||||
else if (name == "view-source") {
|
|
||||||
// get the *top* level paragraphs that contain the cursor,
|
|
||||||
// or the selected text
|
|
||||||
lyx::pit_type par_begin;
|
|
||||||
lyx::pit_type par_end;
|
|
||||||
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);
|
|
||||||
ostringstream ostr;
|
|
||||||
view()->buffer()->getSourceCode(ostr, par_begin, par_end + 1);
|
|
||||||
// display the dialog and show source code
|
|
||||||
owner->getDialogs().show("view-source", ostr.str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
owner->getDialogs().show(name, data);
|
owner->getDialogs().show(name, data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
15
src/text3.C
15
src/text3.C
@ -1108,21 +1108,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
|||||||
bv->switchKeyMap();
|
bv->switchKeyMap();
|
||||||
bv->owner()->updateMenubar();
|
bv->owner()->updateMenubar();
|
||||||
bv->owner()->updateToolbars();
|
bv->owner()->updateToolbars();
|
||||||
|
|
||||||
// if view-source dialog is visible, send source code of selected
|
|
||||||
// text to the dialog
|
|
||||||
if (cmd.button() == mouse_button::button1 && cur.selection()
|
|
||||||
&& bv->owner()->getDialogs().visible("view-source")) {
|
|
||||||
// get *top* level paragraphs that contain the selection
|
|
||||||
lyx::pit_type par_begin = bv->cursor().selectionBegin().bottom().pit();
|
|
||||||
lyx::pit_type par_end = bv->cursor().selectionEnd().bottom().pit();
|
|
||||||
if (par_begin > par_end)
|
|
||||||
std::swap(par_begin, par_end);
|
|
||||||
ostringstream ostr;
|
|
||||||
bv->buffer()->getSourceCode(ostr, par_begin, par_end + 1);
|
|
||||||
// display the dialog and show source code
|
|
||||||
bv->owner()->getDialogs().update("view-source", ostr.str());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user