File dialog fixes. Implement optional menu items

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5103 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2002-08-25 20:53:39 +00:00
parent 2a15d6e5d6
commit c14be97bfc
7 changed files with 102 additions and 65 deletions

View File

@ -1,3 +1,16 @@
2002-08-25 John Levon <levon@movementarian.org>
* FileDialog.C:
* FileDialog_private.h:
* FileDialog_private.C: disable non-sync code due
to Qt bug. Add support for buttons
2002-08-25 John Levon <levon@movementarian.org>
* QLPopupMenu.C: implement optional() support
* TODO: update
2002-08-25 John Levon <levon@movementarian.org>
* Makefile.am:

View File

@ -20,19 +20,28 @@
#include "FileDialog_private.h"
#include "debug.h"
#include <qapplication.h>
using std::make_pair;
using std::pair;
using std::endl;
FileDialog::FileDialog(LyXView *lv, string const &t, kb_action s, Button b1, Button b2)
: private_(0), lv_(lv), title_(t), success_(s)
struct FileDialog::Private {
Button b1;
Button b2;
};
FileDialog::FileDialog(LyXView *lv, string const & t, kb_action s, Button b1, Button b2)
: private_(new FileDialog::Private()), lv_(lv), title_(t), success_(s)
{
// FIXME
private_->b1 = b1;
private_->b2 = b2;
}
FileDialog::~FileDialog()
{
delete private_;
}
@ -42,23 +51,27 @@ FileDialog::Result const FileDialog::Select(string const & path, string const &
if (mask.empty())
filter = _("*|All files");
LyXFileDialog * dlg = new LyXFileDialog(lv_, success_, path, filter, title_);
LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
lyxerr[Debug::GUI] << "Select with path \"" << path << "\", mask \"" << filter << "\", suggested \"" << suggested << endl;
if (!suggested.empty())
dlg->setSelection(suggested.c_str());
dlg.setSelection(suggested.c_str());
if (success_ == LFUN_SELECT_FILE_SYNC) {
FileDialog::Result result;
lyxerr[Debug::GUI] << "Synchronous FileDialog : " << endl;
result.first = FileDialog::Chosen;
int res = dlg->exec();
lyxerr[Debug::GUI] << "result " << res << endl;
if (res == QDialog::Accepted)
result.second = string(dlg->selectedFile().data());
delete dlg;
return result;
}
// This code relies on DestructiveClose which is broken
// in Qt < 3.0.5. So we just don't allow it for now.
//if (success_ == LFUN_SELECT_FILE_SYNC) {
FileDialog::Result result;
lyxerr[Debug::GUI] << "Synchronous FileDialog : " << endl;
result.first = FileDialog::Chosen;
int res = dlg.exec();
lyxerr[Debug::GUI] << "result " << res << endl;
if (res == QDialog::Accepted)
result.second = string(dlg.selectedFile().data());
dlg.hide();
return result;
#if 0
dlg->show();
return make_pair(FileDialog::Later, string());
#endif
}

View File

@ -9,9 +9,11 @@
#include <config.h>
#include "LString.h"
#include "support/lstrings.h"
#include <qapplication.h>
#include <qfiledialog.h>
#include <qtoolbutton.h>
#include "QtLyXView.h"
#include "debug.h"
@ -19,27 +21,50 @@
#include "FileDialog_private.h"
LyXFileDialog::LyXFileDialog(LyXView * lv, kb_action a,
string const & p, string const & m, string const & t)
: QFileDialog(p.c_str(), m.c_str(), qApp->mainWidget(), t.c_str(),
a == LFUN_SELECT_FILE_SYNC),
lv_(lv), action_(a)
namespace {
/// return the Qt form of the label
string const getLabel(string const & str) {
string label;
string sc(split(str, label, '|'));
if (sc.length() < 2)
return label;
string::size_type pos = label.find(sc[1]);
if (pos == string::npos)
return label;
label.insert(pos, "&");
return label;
}
}
LyXFileDialog::LyXFileDialog(string const & p, string const & m, string const & t,
FileDialog::Button const & b1, FileDialog::Button const & b2)
: QFileDialog(p.c_str(), m.c_str(), qApp->mainWidget(), t.c_str(), true),
b1_(0), b2_(0)
{
setCaption(t.c_str());
}
void LyXFileDialog::done(int what)
{
lyxerr[Debug::GUI] << "Done FileDialog, value " << what << std::endl;
if (action_ == LFUN_SELECT_FILE_SYNC) {
QDialog::done(what);
return;
if (!b1.first.empty()) {
b1_dir_ = b1.second;
b1_ = new QToolButton(this);
connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
b1_->setText(getLabel(b1.first).c_str());
addToolButton(b1_, true);
}
if (what == QDialog::Accepted)
lv_->getLyXFunc().dispatch(FuncRequest(action_, selectedFile().data()));
delete this;
if (!b2.first.empty()) {
b2_dir_ = b2.second;
b2_ = new QToolButton(this);
connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
b2_->setText(getLabel(b2.first).c_str());
addToolButton(b2_);
}
}
void LyXFileDialog::buttonClicked()
{
if (sender() == b1_)
setDir(b1_dir_.c_str());
else if (sender() == b2_)
setDir(b2_dir_.c_str());
}

View File

@ -19,23 +19,24 @@
#include <qfiledialog.h>
class LyXView;
class QToolButton;
class LyXFileDialog : public QFileDialog
{
Q_OBJECT
Q_OBJECT
public:
LyXFileDialog(LyXView * lv, kb_action a, string const & p, string const & m, string const & t);
friend class FileDialog;
LyXFileDialog(string const & p, string const & m, string const & t,
FileDialog::Button const & b1, FileDialog::Button const & b2);
public slots:
void done(int);
void buttonClicked();
private:
LyXView * lv_;
kb_action action_;
QToolButton * b1_;
string b1_dir_;
QToolButton * b2_;
string b2_dir_;
};
#endif // FILEDIALOG_PRIVATE_H

View File

@ -37,7 +37,6 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form)
void QGraphicsDialog::change_adaptor()
{
lyxerr << "changed" << endl;
form_->changed();
}

View File

@ -92,9 +92,11 @@ void QLPopupMenu::showing()
int id(createMenu(this, m, owner_));
setItemEnabled(id, !disabled(m->submenuname()));
} else {
insertItem(getLabel(*m).c_str(), m->action());
FuncStatus const status =
owner_->view()->getLyXFunc().getStatus(m->action());
if (status.disabled() && m->optional())
continue;
insertItem(getLabel(*m).c_str(), m->action());
setItemEnabled(m->action(), !status.disabled());
setItemChecked(m->action(), status.onoff(true));
}

View File

@ -4,25 +4,14 @@ is incomplete.
Those with asterisks are what I perceive as being "big jobs"
FileDialog
- add buttons for Documents, Templates, etc. to the file dialog toolbar
- work around Qt crash bug with double click
lyx_gui (qt)
- move out lyxserver
- do dpi
- do dpi (cannot easily fix)
Menubar_pimpl
- fix disabling submenu labels when appropriate
- implement dynamic menus (may need serious backend changes) (*)(*)
- dynamic last files
- import/export/view/update
- navigate
- implement openByName
- why is note disabled, index enabled with no doc etc. ?
QAbout
@ -40,7 +29,7 @@ QContentPane
QDocument
- implement me. Need MVC (*)
- implement me. Need MVC (Edwin is on this)
qfont_loader
@ -56,16 +45,12 @@ QForks
QGraphics
- UI cleanups and fixes
- remaining UI cleanups and fixes
QInclude
- check no load stuff works ?
qlkey
- finish off the lists
QLImage
- get jpeg etc. to work
@ -79,7 +64,6 @@ QLPainter
QLyXKeySym
- isOK() - meaningful or not ?
- getISOEncoded - get this to work (*)
QPreferences