git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20822 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-07 18:40:01 +00:00
parent 24b95a387c
commit 6a2f951cf7
6 changed files with 172 additions and 52 deletions

View File

@ -10,7 +10,6 @@ SOURCEFILES = \
Dialog.cpp \
ButtonPolicy.cpp \
ControlCommand.cpp \
ControlCommandBuffer.cpp \
ControlMath.cpp \
ControlParagraph.cpp \
frontend_helpers.cpp
@ -19,7 +18,6 @@ HEADERFILES = \
Dialog.h \
ButtonPolicy.h \
ControlCommand.h \
ControlCommandBuffer.h \
ControlMath.h \
ControlParagraph.h \
frontend_helpers.h

View File

@ -57,12 +57,11 @@ using support::trim;
GuiBibtex::GuiBibtex(LyXView & lv)
: GuiDialog(lv, "bibtex"), ControlCommand(*this, "bibtex")
: GuiCommand(lv, "bibtex")
{
setupUi(this);
setViewTitle( _("BibTeX Bibliography"));
setController(this, false);
QDialog::setModal(true);
@ -259,7 +258,7 @@ void GuiBibtex::updateContents()
databaseLW->clear();
docstring bibs = params()["bibfiles"];
docstring bibs = params_["bibfiles"];
docstring bib;
while (!bibs.empty()) {
@ -284,7 +283,7 @@ void GuiBibtex::updateContents()
bibtocCB->setChecked(bibtotoc() && !bibtopic);
bibtocCB->setEnabled(!bibtopic);
docstring btprint(params()["btprint"]);
docstring btprint = params_["btprint"];
int btp = 0;
if (btprint == "btPrintNotCited")
btp = 1;
@ -330,22 +329,22 @@ void GuiBibtex::applyView()
dbs += qstring_to_ucs4(databaseLW->item(i)->text());
}
params()["bibfiles"] = dbs;
params_["bibfiles"] = dbs;
docstring const bibstyle(qstring_to_ucs4(styleCB->currentText()));
bool const bibtotoc(bibtocCB->isChecked());
docstring const bibstyle = qstring_to_ucs4(styleCB->currentText());
bool const bibtotoc = bibtocCB->isChecked();
if (bibtotoc && (!bibstyle.empty())) {
// both bibtotoc and style
params()["options"] = "bibtotoc," + bibstyle;
params_["options"] = "bibtotoc," + bibstyle;
} else if (bibtotoc) {
// bibtotoc and no style
params()["options"] = from_ascii("bibtotoc");
params_["options"] = from_ascii("bibtotoc");
} else {
// only style. An empty one is valid, because some
// documentclasses have an own \bibliographystyle{}
// command!
params()["options"] = bibstyle;
params_["options"] = bibstyle;
}
// bibtopic allows three kinds of sections:
@ -356,18 +355,18 @@ void GuiBibtex::applyView()
switch (btp) {
case 0:
params()["btprint"] = from_ascii("btPrintCited");
params_["btprint"] = from_ascii("btPrintCited");
break;
case 1:
params()["btprint"] = from_ascii("btPrintNotCited");
params_["btprint"] = from_ascii("btPrintNotCited");
break;
case 2:
params()["btprint"] = from_ascii("btPrintAll");
params_["btprint"] = from_ascii("btPrintAll");
break;
}
if (!usingBibtopic())
params()["btprint"] = docstring();
params_["btprint"] = docstring();
}
@ -454,7 +453,7 @@ bool GuiBibtex::usingBibtopic() const
bool GuiBibtex::bibtotoc() const
{
return prefixIs(to_utf8(params()["options"]), "bibtotoc");
return prefixIs(to_utf8(params_["options"]), "bibtotoc");
}
@ -479,7 +478,7 @@ string const GuiBibtex::getStylefile() const
break;
}
docstring bst = params()["options"];
docstring bst = params_["options"];
if (bibtotoc()){
// bibstyle exists?
if (contains(bst, ',')) {
@ -492,7 +491,7 @@ string const GuiBibtex::getStylefile() const
// propose default style file for new insets
// existing insets might have (legally) no bst files
// (if the class already provides a style)
if (bst.empty() && params()["bibfiles"].empty())
if (bst.empty() && params_["bibfiles"].empty())
bst = defaultstyle;
// FIXME UNICODE

View File

@ -18,8 +18,6 @@
#include "ui_BibtexUi.h"
#include "ui_BibtexAddUi.h"
#include "ControlCommand.h"
#include "support/docstring.h"
#include <vector>
@ -41,7 +39,7 @@ public:
};
class GuiBibtex : public GuiDialog, public Ui::BibtexUi, public ControlCommand
class GuiBibtex : public GuiCommand, public Ui::BibtexUi
{
Q_OBJECT
@ -63,14 +61,12 @@ private:
void closeEvent(QCloseEvent * e);
private:
/// parent controller
Controller & controller() { return *this; }
///
virtual bool isValid();
bool isValid();
/// Apply changes
virtual void applyView();
void applyView();
/// update
virtual void updateContents();
void updateContents();
/// Browse for a .bib file
docstring const browseBib(docstring const & in_name) const;

View File

@ -20,7 +20,6 @@
#include "ui_CitationUi.h"
#include "support/docstring.h"
#include "BiblioInfo.h"
#include "ControlCommand.h"
#include <QKeyEvent>
#include <QStringList>

View File

@ -3,6 +3,8 @@
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars
* \author Asger and Jürgen
* \author John Levon
*
* Full author contact details are available in file CREDITS.
@ -18,6 +20,16 @@
#include "GuiCommandEdit.h"
#include "qt_helpers.h"
#include "BufferView.h"
#include "Cursor.h"
#include "LyXFunc.h"
#include "LyXAction.h"
#include "FuncRequest.h"
#include "frontends/LyXView.h"
#include "support/lyxalgo.h"
#include "support/lstrings.h"
#include "support/filetools.h"
#include <QHBoxLayout>
@ -30,14 +42,19 @@
#include <QToolTip>
#include <QVBoxLayout>
using lyx::support::libFileSearch;
using std::vector;
using std::back_inserter;
using std::transform;
using std::string;
using std::vector;
namespace lyx {
namespace frontend {
using support::prefixIs;
using support::libFileSearch;
namespace {
class QTempListBox : public QListWidget {
@ -76,8 +93,11 @@ protected:
GuiCommandBuffer::GuiCommandBuffer(GuiViewBase * view)
: view_(view), controller_(*view)
: view_(view), lv_(*view), history_pos_(history_.end())
{
transform(lyxaction.func_begin(), lyxaction.func_end(),
back_inserter(commands_), firster());
QPixmap qpup(toqstr(libFileSearch("images", "up", "png").absFilename()));
QPixmap qpdown(toqstr(libFileSearch("images", "down", "png").absFilename()));
@ -86,8 +106,6 @@ GuiCommandBuffer::GuiCommandBuffer(GuiViewBase * view)
QPushButton * up = new QPushButton(qpup, "", this);
up->setMaximumSize(24, 24);
up->setToolTip(qt_("Previous command"));
connect(up, SIGNAL(clicked()), this, SLOT(up()));
QPushButton * down = new QPushButton(qpdown, "", this);
down->setToolTip(qt_("Next command"));
down->setMaximumSize(24, 24);
@ -123,7 +141,7 @@ void GuiCommandBuffer::cancel()
void GuiCommandBuffer::dispatch()
{
controller_.dispatch(fromqstr(edit_->text()));
dispatch(fromqstr(edit_->text()));
view_->setFocus();
edit_->setText(QString());
edit_->clearFocus();
@ -134,7 +152,7 @@ void GuiCommandBuffer::complete()
{
string const input = fromqstr(edit_->text());
string new_input;
vector<string> comp = controller_.completions(input, new_input);
vector<string> comp = completions(input, new_input);
if (comp.empty() && new_input == input) {
// show_info_suffix(qt_("[no match]"), input);
@ -188,7 +206,7 @@ void GuiCommandBuffer::complete_selected(QListWidgetItem * item)
void GuiCommandBuffer::up()
{
string const input = fromqstr(edit_->text());
string const h = controller_.historyUp();
string const h = historyUp();
if (h.empty()) {
// show_info_suffix(qt_("[Beginning of history]"), input);
@ -201,7 +219,7 @@ void GuiCommandBuffer::up()
void GuiCommandBuffer::down()
{
string const input = fromqstr(edit_->text());
string const h = controller_.historyDown();
string const h = historyDown();
if (h.empty()) {
// show_info_suffix(qt_("[End of history]"), input);
@ -216,27 +234,104 @@ void GuiCommandBuffer::hideParent()
view_->setFocus();
edit_->setText(QString());
edit_->clearFocus();
controller_.hide();
hide();
}
#if 0
void XMiniBuffer::show_info_suffix(string const & suffix, string const & input)
namespace {
class prefix_p {
public:
string p;
prefix_p(string const & s) : p(s) {}
bool operator()(string const & s) const { return prefixIs(s, p); }
};
} // end of anon namespace
string const GuiCommandBuffer::historyUp()
{
stored_input_ = input;
info_suffix_shown_ = true;
set_input(input + ' ' + suffix);
suffix_timer_->start();
if (history_pos_ == history_.begin())
return string();
return *(--history_pos_);
}
void XMiniBuffer::suffix_timeout()
string const GuiCommandBuffer::historyDown()
{
info_suffix_shown_ = false;
set_input(stored_input_);
if (history_pos_ == history_.end())
return string();
if (history_pos_ + 1 == history_.end())
return string();
return *(++history_pos_);
}
#endif
docstring const GuiCommandBuffer::getCurrentState() const
{
return lv_.view()->cursor().currentState();
}
void GuiCommandBuffer::hide() const
{
lv_.showMiniBuffer(false);
}
vector<string> const
GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
{
vector<string> comp;
copy_if(commands_.begin(), commands_.end(),
back_inserter(comp), prefix_p(prefix));
if (comp.empty()) {
new_prefix = prefix;
return comp;
}
if (comp.size() == 1) {
new_prefix = comp[0];
return vector<string>();
}
// find maximal available prefix
string const tmp = comp[0];
string test = prefix;
if (tmp.length() > test.length())
test += tmp[test.length()];
while (test.length() < tmp.length()) {
vector<string> vtmp;
copy_if(comp.begin(), comp.end(),
back_inserter(vtmp), prefix_p(test));
if (vtmp.size() != comp.size()) {
test.erase(test.length() - 1);
break;
}
test += tmp[test.length()];
}
new_prefix = test;
return comp;
}
void GuiCommandBuffer::dispatch(string const & str)
{
if (str.empty())
return;
history_.push_back(str);
history_pos_ = history_.end();
FuncRequest func = lyxaction.lookupFunc(str);
func.origin = FuncRequest::COMMANDBUFFER;
lv_.dispatch(func);
}
} // namespace frontend
} // namespace lyx

View File

@ -4,6 +4,8 @@
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars
* \author Asger and Jürgen
* \author John Levon
*
* Full author contact details are available in file CREDITS.
@ -12,15 +14,19 @@
#ifndef GUICOMMANDBUFFER_H
#define GUICOMMANDBUFFER_H
#include "ControlCommandBuffer.h"
#include "support/docstring.h"
#include <QWidget>
#include <vector>
class QListWidgetItem;
namespace lyx {
namespace frontend {
class LyXView;
class GuiViewBase;
class GuiCommandEdit;
class GuiCommandBuffer : public QWidget
@ -48,10 +54,37 @@ public Q_SLOTS:
private:
/// owning view
GuiViewBase * view_;
/// controller
ControlCommandBuffer controller_;
///
LyXView & lv_;
/// command widget
GuiCommandEdit * edit_;
/// return the previous history entry if any
std::string const historyUp();
/// return the next history entry if any
std::string const historyDown();
/// return the font and depth in the active BufferView as a message.
docstring const getCurrentState() const;
/// hide the command buffer.
void hide() const;
/// return the possible completions
std::vector<std::string> const completions(std::string const & prefix,
std::string & new_prefix);
/// dispatch a command
void dispatch(std::string const & str);
/// available command names
std::vector<std::string> commands_;
/// command history
std::vector<std::string> history_;
/// current position in command history
std::vector<std::string>::const_iterator history_pos_;
};
} // namespace frontend