mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
restore cursor position in preamble.
* ControlDocument::id(): new method returning the id of the current buffer. * PreambleModule: new class for the preamble module. Handle everything preamble related, including memorizing the cursor position for each Buffer. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18307 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c35007dbce
commit
06099a8959
@ -79,6 +79,12 @@ BufferParams & ControlDocument::params() const
|
||||
}
|
||||
|
||||
|
||||
int ControlDocument::id() const
|
||||
{
|
||||
return (int) &kernel().buffer();
|
||||
}
|
||||
|
||||
|
||||
TextClass const & ControlDocument::textClass() const
|
||||
{
|
||||
return textclasslist[bp_->textclass];
|
||||
|
@ -50,6 +50,8 @@ public:
|
||||
///
|
||||
BufferParams & params() const;
|
||||
///
|
||||
int id() const;
|
||||
///
|
||||
void setLanguage() const;
|
||||
///
|
||||
void saveAsDefault() const;
|
||||
|
@ -11,21 +11,21 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "QDocument.h"
|
||||
#include "Qt2BC.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "QBranches.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
|
||||
#include "CheckedLineEdit.h"
|
||||
#include "FloatPlacement.h"
|
||||
#include "LengthCombo.h"
|
||||
#include "Validator.h"
|
||||
#include "PanelStack.h"
|
||||
#include "Qt2BC.h"
|
||||
#include "CheckedLineEdit.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "Validator.h"
|
||||
|
||||
// For latexHighlighter use in the preamble.
|
||||
#include "QViewSource.h"
|
||||
// For the Branches module
|
||||
#include "QBranches.h"
|
||||
|
||||
#include "QViewSource.h" // For latexHighlighter use in the preamble.
|
||||
|
||||
#include "controllers/ControlDocument.h"
|
||||
|
||||
#include "BufferParams.h"
|
||||
#include "Encoding.h"
|
||||
@ -41,8 +41,10 @@
|
||||
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include "controllers/ControlDocument.h"
|
||||
#include <QCloseEvent>
|
||||
#include <QTextCursor>
|
||||
|
||||
#include <map>
|
||||
|
||||
using lyx::support::token;
|
||||
using lyx::support::bformat;
|
||||
@ -50,6 +52,7 @@ using lyx::support::findToken;
|
||||
using lyx::support::getVectorFromString;
|
||||
|
||||
using std::distance;
|
||||
using std::make_pair;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
@ -93,6 +96,67 @@ char const * tex_fonts_monospaced_gui[] = { N_("Default"), N_("Computer Modern T
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PreambleModule
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
PreambleModule::PreambleModule(): current_id_(0)
|
||||
{
|
||||
// This is not a memory leak. The object will be destroyed
|
||||
// with this.
|
||||
(void) new LaTeXHighlighter(preambleTE->document());
|
||||
setFocusProxy(preambleTE);
|
||||
}
|
||||
|
||||
|
||||
void PreambleModule::update(BufferParams const & params, int id)
|
||||
{
|
||||
QString preamble = toqstr(params.preamble);
|
||||
// Nothing to do if the params and preamble are unchanged.
|
||||
if (id == current_id_
|
||||
&& preamble == preambleTE->document()->toPlainText())
|
||||
return;
|
||||
|
||||
QTextCursor cur = preambleTE->textCursor();
|
||||
// Save the coords before switching to the new one.
|
||||
preamble_coords_[current_id_] =
|
||||
make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
|
||||
|
||||
// Save the params address for further use.
|
||||
current_id_ = id;
|
||||
preambleTE->document()->setPlainText(preamble);
|
||||
Coords::const_iterator it = preamble_coords_.find(current_id_);
|
||||
if (it == preamble_coords_.end())
|
||||
// First time we open this one.
|
||||
preamble_coords_[current_id_] = make_pair(0,0);
|
||||
else {
|
||||
// Restore saved coords.
|
||||
QTextCursor cur = preambleTE->textCursor();
|
||||
cur.setPosition(it->second.first);
|
||||
preambleTE->setTextCursor(cur);
|
||||
preambleTE->verticalScrollBar()->setValue(it->second.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PreambleModule::apply(BufferParams & params)
|
||||
{
|
||||
params.preamble = fromqstr(preambleTE->document()->toPlainText());
|
||||
}
|
||||
|
||||
|
||||
void PreambleModule::closeEvent(QCloseEvent * e)
|
||||
{
|
||||
// Save the coords before closing.
|
||||
QTextCursor cur = preambleTE->textCursor();
|
||||
preamble_coords_[current_id_] =
|
||||
make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
|
||||
e->accept();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DocumentDialog
|
||||
@ -481,13 +545,9 @@ QDocumentDialog::QDocumentDialog(QDocument * form)
|
||||
this, SLOT(change_adaptor()));
|
||||
|
||||
// preamble
|
||||
preambleModule = new UiWidget<Ui::PreambleUi>;
|
||||
connect(preambleModule->preambleTE, SIGNAL(textChanged()),
|
||||
preambleModule = new PreambleModule;
|
||||
connect(preambleModule, SIGNAL(changed()),
|
||||
this, SLOT(change_adaptor()));
|
||||
// This is not a memory leak. The object will be destroyed
|
||||
// with preambleModule.
|
||||
(void) new LaTeXHighlighter(preambleModule->preambleTE->document());
|
||||
|
||||
|
||||
// bullets
|
||||
bulletsModule = new BulletsModule;
|
||||
@ -770,8 +830,7 @@ void QDocumentDialog::updateNumbering()
|
||||
void QDocumentDialog::apply(BufferParams & params)
|
||||
{
|
||||
// preamble
|
||||
params.preamble =
|
||||
fromqstr(preambleModule->preambleTE->document()->toPlainText());
|
||||
preambleModule->apply(params);
|
||||
|
||||
// biblio
|
||||
params.setCiteEngine(biblio::ENGINE_BASIC);
|
||||
@ -1050,9 +1109,7 @@ void QDocumentDialog::updateParams(BufferParams const & params)
|
||||
}
|
||||
|
||||
// preamble
|
||||
QString preamble = toqstr(params.preamble);
|
||||
if (preamble != preambleModule->preambleTE->document()->toPlainText())
|
||||
preambleModule->preambleTE->document()->setPlainText(preamble);
|
||||
preambleModule->update(params, form_->controller().id());
|
||||
|
||||
// biblio
|
||||
biblioModule->citeDefaultRB->setChecked(
|
||||
@ -1291,7 +1348,6 @@ void QDocumentDialog::updateParams(BufferParams const & params)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Document
|
||||
|
@ -25,10 +25,13 @@
|
||||
#include "ui/BiblioUi.h"
|
||||
#include "ui/NumberingUi.h"
|
||||
#include "ui/MarginsUi.h"
|
||||
|
||||
// For the Preamble module
|
||||
#include "ui/PreambleUi.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QDialog>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@ -49,6 +52,7 @@ namespace frontend {
|
||||
|
||||
class QBranches;
|
||||
class QDocument;
|
||||
class PreambleModule;
|
||||
|
||||
class QDocumentDialog : public QDialog, public Ui::QDocumentUi {
|
||||
Q_OBJECT
|
||||
@ -99,7 +103,7 @@ private:
|
||||
UiWidget<Ui::BiblioUi> *biblioModule;
|
||||
UiWidget<Ui::MathsUi> *mathsModule;
|
||||
UiWidget<Ui::LaTeXUi> *latexModule;
|
||||
UiWidget<Ui::PreambleUi> *preambleModule;
|
||||
PreambleModule *preambleModule;
|
||||
|
||||
QBranches *branchesModule;
|
||||
|
||||
@ -113,7 +117,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
class ControlDocument;
|
||||
|
||||
class QDocument
|
||||
@ -140,6 +143,31 @@ private:
|
||||
void useClassDefaults();
|
||||
};
|
||||
|
||||
|
||||
class PreambleModule : public UiWidget<Ui::PreambleUi>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PreambleModule();
|
||||
void update(BufferParams const & params, int id);
|
||||
void apply(BufferParams & params);
|
||||
|
||||
Q_SIGNALS:
|
||||
/// signal that something's changed in the Widget.
|
||||
void changed();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
void on_preambleTE_textChanged() { changed(); }
|
||||
|
||||
private:
|
||||
typedef std::map<int, std::pair<int,int> > Coords;
|
||||
Coords preamble_coords_;
|
||||
int current_id_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user