]> git.lyx.org Git - features.git/commitdiff
File dialog fixes. Implement optional menu items
authorJohn Levon <levon@movementarian.org>
Sun, 25 Aug 2002 20:53:39 +0000 (20:53 +0000)
committerJohn Levon <levon@movementarian.org>
Sun, 25 Aug 2002 20:53:39 +0000 (20:53 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5103 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/FileDialog.C
src/frontends/qt2/FileDialog_private.C
src/frontends/qt2/FileDialog_private.h
src/frontends/qt2/QGraphicsDialog.C
src/frontends/qt2/QLPopupMenu.C
src/frontends/qt2/TODO

index 94057198d72008d9100d0babb7fd9e5f1acbe2e4..5183adced2854aa60dacaf1858f9eb6a8350511f 100644 (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:
index fcc3dd9223ef82030c1720048784840de82c3285..e08c76c0ffc2710b27e9cd2800d770431f2bd945 100644 (file)
 #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
 }
index 03942dfa9e99a8c7e5c7cd794cd4893c7bfbfee2..dc61f7e9ff851e9148e822b80b97851c5b0ca00a 100644 (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"
 
 #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 (!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 (action_ == LFUN_SELECT_FILE_SYNC) {
-               QDialog::done(what);
-               return;
+       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_);
        }
+}
 
-       if (what == QDialog::Accepted)
-               lv_->getLyXFunc().dispatch(FuncRequest(action_, selectedFile().data()));
 
-       delete this;
+void LyXFileDialog::buttonClicked()
+{
+       if (sender() == b1_)
+               setDir(b1_dir_.c_str());
+       else if (sender() == b2_)
+               setDir(b2_dir_.c_str());
 }
index 1c39556e572e0ef1712dfe43a1eaedf633e68928..6870f7f7627281fb3ddde253917d690349504db7 100644 (file)
 
 #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
index cf667ba912e2ead6c7b55981372c1514ff4f66fc..d067effe08bac9e70363e399a4f6bfe19121e47e 100644 (file)
@@ -37,7 +37,6 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form)
 
 void QGraphicsDialog::change_adaptor()
 {
-       lyxerr << "changed" << endl; 
        form_->changed();
 }
 
index 76beaeb5ac295e3e2a7a8e7c642e71f3e4d65c56..ed8065215a0746a9553f7d8bb350642f00707c75 100644 (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));
                }
index 428f543cbe550c7e55a8519e8acc83f272053908..9511ad8d453d2515ad253ad1de6461890a445c5b 100644 (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