]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCompare.cpp
QDialogButtonBox for the remaining dialogs.
[lyx.git] / src / frontends / qt4 / GuiCompare.cpp
index 79a6832f0d60ffb8b007a2209caa5dd8e56d3e53..d282df95263ae6c568d7e05ef026113ed7f65928 100644 (file)
@@ -29,6 +29,7 @@
 #include "support/FileName.h"
 #include "support/gettext.h"
 
+#include <QDialogButtonBox>
 #include <QThread>
 
 
@@ -46,8 +47,8 @@ GuiCompare::GuiCompare(GuiView & lv)
        setupUi(this);
        setModal(Qt::WindowModal);
 
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotCancel()));
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
 
        connect(newFilePB, SIGNAL(clicked()), this, SLOT(selectNewFile()));
        connect(oldFilePB, SIGNAL(clicked()), this, SLOT(selectOldFile()));
@@ -62,14 +63,12 @@ GuiCompare::GuiCompare(GuiView & lv)
                this, SLOT(changeAdaptor()));
 
        newSettingsRB->setChecked(true);
+       trackingCB->setChecked(true);
 
-       progressBar->setValue(0);
-       progressBar->setEnabled(false);
-
-       closePB->setCursor(Qt::ArrowCursor);
+       buttonBox->button(QDialogButtonBox::Ok)->setCursor(Qt::ArrowCursor);
 
        bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
-       bc().setOK(okPB);
+       bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
 }
 
 GuiCompare::~GuiCompare()
@@ -80,7 +79,7 @@ GuiCompare::~GuiCompare()
 
 void GuiCompare::closeEvent(QCloseEvent *)
 {
-       slotCancel();   
+       slotCancel();
 }
 
 
@@ -116,10 +115,10 @@ void GuiCompare::updateContents()
                newFileCB->addItem(filename);
                oldFileCB->addItem(filename);
        }
-       if (lyxview().documentBufferView())
-               newFileCB->setEditText(toqstr(buffer().absFileName()));
-       else
+       if (!restore_filename1.isEmpty())
                newFileCB->setEditText(restore_filename1);
+       else if (lyxview().documentBufferView())
+               newFileCB->setEditText(toqstr(buffer().absFileName()));
 
        if (!restore_filename2.isEmpty())
                oldFileCB->setEditText(restore_filename2);
@@ -156,19 +155,19 @@ QString GuiCompare::browse(QString const & in_name) const
        QString const title = qt_("Select document");
 
        QStringList const & filters = fileFilters(qt_("LyX Documents (*.lyx)"));
-       
+
        QString filename;
        if (lyxview().documentBufferView()) {
                QString path = bufferFilePath();
-               filename = browseRelFile(in_name, path, title, filters, false, 
-                       qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+               filename = browseRelToParent(in_name, path, title, filters, false,
+                       qt_("D&ocuments"), toqstr(lyxrc.document_path));
        } else {
                QString path = toqstr(lyxrc.document_path);
-               QString rel_filename = browseRelFile(in_name, path, title, filters, false, 
-                       qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+               QString rel_filename = browseRelToParent(in_name, path, title, filters, false,
+                       qt_("D&ocuments"), toqstr(lyxrc.document_path));
                filename = makeAbsPath(rel_filename, path);
        }
-       return filename;        
+       return filename;
 }
 
 
@@ -184,14 +183,14 @@ void GuiCompare::enableControls(bool enable)
        oldFileLA->setEnabled(enable);
        oldFilePB->setEnabled(enable);
        oldFileCB->setEnabled(enable);
-       okPB->setEnabled(enable);
+       buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable);
        groupBox->setEnabled(enable);
        progressBar->setEnabled(!enable);
 
        if (enable)
-               closePB->setText(qt_("Close"));
+               buttonBox->button(QDialogButtonBox::Cancel)->setText(qt_("Close"));
        else
-               closePB->setText(qt_("Cancel"));
+               buttonBox->button(QDialogButtonBox::Cancel)->setText(qt_("Cancel"));
 }
 
 
@@ -209,7 +208,7 @@ void GuiCompare::finished(bool aborted)
                delete compare_;
                compare_ = 0;
        }
-       
+
        if (aborted) {
                if (dest_buffer_) {
                        dest_buffer_->markClean();
@@ -223,6 +222,10 @@ void GuiCompare::finished(bool aborted)
                if (dest_buffer_) {
                        dispatch(FuncRequest(LFUN_BUFFER_SWITCH,
                                dest_buffer_->absFileName()));
+                       if (trackingCB->isChecked()) {
+                               dispatch(FuncRequest(LFUN_CHANGES_OUTPUT));
+                               dispatch(FuncRequest(LFUN_CHANGES_TRACK));
+                       }
                }
                statusBar->showMessage(qt_("Finished"), 5000);
        }
@@ -268,6 +271,21 @@ void GuiCompare::slotCancel()
 }
 
 
+void GuiCompare::slotButtonBox(QAbstractButton * button)
+{
+       switch (buttonBox->standardButton(button)) {
+       case QDialogButtonBox::Ok:
+               slotOK();
+               break;
+       case QDialogButtonBox::Cancel:
+               slotCancel();
+               break;
+       default:
+               break;
+       }
+}
+
+
 Buffer const * GuiCompare::bufferFromFileName(string const & file) const
 {
        FileName fname;
@@ -318,6 +336,22 @@ int GuiCompare::run()
        return 1;
 }
 
+bool GuiCompare::initialiseParams(std::string const &par)
+{
+       //just for the sake of parsing arguments
+       FuncRequest cmd(LFUN_UNKNOWN_ACTION, par);
+       if (cmd.getArg(0) == "run") {
+               oldFileCB->setEditText(toqstr(cmd.getArg(1)));
+               newFileCB->setEditText(toqstr(cmd.getArg(2)));
+               slotOK();
+       }
+
+       progressBar->setValue(0);
+       progressBar->setEnabled(false);
+       progressBar->setMaximum(1);
+
+       return true;
+}
 
 Dialog * createGuiCompare(GuiView & lv) { return new GuiCompare(lv); }