From c14be97bfc28d1ee822b7fc66a4552a219dce0ca Mon Sep 17 00:00:00 2001 From: John Levon Date: Sun, 25 Aug 2002 20:53:39 +0000 Subject: [PATCH] File dialog fixes. Implement optional menu items git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5103 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 13 ++++++ src/frontends/qt2/FileDialog.C | 45 ++++++++++++------- src/frontends/qt2/FileDialog_private.C | 61 ++++++++++++++++++-------- src/frontends/qt2/FileDialog_private.h | 21 ++++----- src/frontends/qt2/QGraphicsDialog.C | 1 - src/frontends/qt2/QLPopupMenu.C | 4 +- src/frontends/qt2/TODO | 22 ++-------- 7 files changed, 102 insertions(+), 65 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 94057198d7..5183adced2 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,16 @@ +2002-08-25 John Levon + + * 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 + + * QLPopupMenu.C: implement optional() support + + * TODO: update + 2002-08-25 John Levon * Makefile.am: diff --git a/src/frontends/qt2/FileDialog.C b/src/frontends/qt2/FileDialog.C index fcc3dd9223..e08c76c0ff 100644 --- a/src/frontends/qt2/FileDialog.C +++ b/src/frontends/qt2/FileDialog.C @@ -20,19 +20,28 @@ #include "FileDialog_private.h" #include "debug.h" +#include + 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 } diff --git a/src/frontends/qt2/FileDialog_private.C b/src/frontends/qt2/FileDialog_private.C index 03942dfa9e..dc61f7e9ff 100644 --- a/src/frontends/qt2/FileDialog_private.C +++ b/src/frontends/qt2/FileDialog_private.C @@ -9,9 +9,11 @@ #include #include "LString.h" +#include "support/lstrings.h" #include #include +#include #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()); } diff --git a/src/frontends/qt2/FileDialog_private.h b/src/frontends/qt2/FileDialog_private.h index 1c39556e57..6870f7f762 100644 --- a/src/frontends/qt2/FileDialog_private.h +++ b/src/frontends/qt2/FileDialog_private.h @@ -19,23 +19,24 @@ #include -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 diff --git a/src/frontends/qt2/QGraphicsDialog.C b/src/frontends/qt2/QGraphicsDialog.C index cf667ba912..d067effe08 100644 --- a/src/frontends/qt2/QGraphicsDialog.C +++ b/src/frontends/qt2/QGraphicsDialog.C @@ -37,7 +37,6 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form) void QGraphicsDialog::change_adaptor() { - lyxerr << "changed" << endl; form_->changed(); } diff --git a/src/frontends/qt2/QLPopupMenu.C b/src/frontends/qt2/QLPopupMenu.C index 76beaeb5ac..ed8065215a 100644 --- a/src/frontends/qt2/QLPopupMenu.C +++ b/src/frontends/qt2/QLPopupMenu.C @@ -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)); } diff --git a/src/frontends/qt2/TODO b/src/frontends/qt2/TODO index 428f543cbe..9511ad8d45 100644 --- a/src/frontends/qt2/TODO +++ b/src/frontends/qt2/TODO @@ -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