-/**\r
- * \file GuiCompare.cpp\r
- * This file is part of LyX, the document processor.\r
- * Licence details can be found in the file COPYING.\r
- *\r
- * \author Vincent van Ravesteijn\r
- *\r
- * Full author contact details are available in file CREDITS.\r
- */\r
-\r
-#include <config.h>\r
-\r
-#include "GuiCompare.h"\r
-\r
-#include "Buffer.h"\r
-#include "BufferView.h"\r
-#include "BufferList.h"\r
-#include "buffer_funcs.h"\r
-#include "FuncRequest.h"\r
-#include "GuiView.h"\r
-#include "LyXRC.h"\r
-#include "qt_helpers.h"\r
-\r
-#include "frontends/alert.h"\r
-\r
-#include "support/debug.h"\r
-#include "support/filetools.h"\r
-#include "support/FileName.h"\r
-#include "support/gettext.h"\r
-\r
-#include <QThread>\r
-\r
-\r
-using namespace std;\r
-using namespace lyx::support;\r
-\r
-namespace lyx {\r
-namespace frontend {\r
-\r
-\r
-GuiCompare::GuiCompare(GuiView & lv)\r
- : GuiDialog(lv, "compare", qt_("Compare LyX files")),\r
- compare_(0), dest_buffer_(0)\r
-{\r
- setupUi(this);\r
- setModal(Qt::WindowModal);\r
-\r
- connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));\r
- connect(closePB, SIGNAL(clicked()), this, SLOT(slotCancel()));\r
-\r
- connect(newFilePB, SIGNAL(clicked()), this, SLOT(select_newfile()));\r
- connect(oldFilePB, SIGNAL(clicked()), this, SLOT(select_oldfile()));\r
-\r
- connect(newFileCB, SIGNAL(currentIndexChanged(int)),\r
- this, SLOT(change_adaptor()));\r
- connect(newFileCB, SIGNAL(editTextChanged(const QString &)),\r
- this, SLOT(change_adaptor()));\r
- connect(oldFileCB, SIGNAL(currentIndexChanged(int)),\r
- this, SLOT(change_adaptor()));\r
- connect(oldFileCB, SIGNAL(editTextChanged(const QString &)),\r
- this, SLOT(change_adaptor()));\r
-\r
- newSettingsRB->setChecked(true);\r
-\r
- progressBar->setValue(0);\r
- progressBar->setEnabled(false);\r
-\r
- bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);\r
- bc().setOK(okPB);\r
-}\r
-\r
-GuiCompare::~GuiCompare()\r
-{\r
-}\r
-\r
-void GuiCompare::closeEvent(QCloseEvent *)\r
-{\r
- slotCancel(); \r
-}\r
-\r
-\r
-void GuiCompare::change_adaptor()\r
-{\r
- changed();\r
-}\r
-\r
-\r
-bool GuiCompare::isValid()\r
-{\r
- bool const valid = !newFileCB->currentText().isEmpty()\r
- && !oldFileCB->currentText().isEmpty();\r
- return valid;\r
-}\r
-\r
-\r
-void GuiCompare::updateContents()\r
-{\r
- QString restore_filename1 = newFileCB->currentText();\r
- QString restore_filename2 = oldFileCB->currentText();\r
- newFileCB->clear();\r
- oldFileCB->clear();\r
- progressBar->setValue(0);\r
- BufferList::iterator it = theBufferList().begin();\r
- BufferList::iterator const end = theBufferList().end();\r
- for (; it != end; ++it) {\r
- QString filename = toqstr((*it)->absFileName());\r
- newFileCB->addItem(filename);\r
- oldFileCB->addItem(filename);\r
- }\r
- if (lyxview().documentBufferView())\r
- newFileCB->setEditText(toqstr(buffer().absFileName()));\r
- else\r
- newFileCB->setEditText(restore_filename1);\r
-\r
- if (!restore_filename2.isEmpty())\r
- oldFileCB->setEditText(restore_filename2);\r
- else\r
- oldFileCB->clearEditText();\r
-\r
- if (isValid()) {\r
- bc().setValid(isValid());\r
- bc().apply();\r
- }\r
-}\r
-\r
-\r
-void GuiCompare::select_newfile()\r
-{\r
- QString name = browse(newFileCB->currentText());\r
- if (!name.isEmpty())\r
- newFileCB->setEditText(name);\r
- changed();\r
-}\r
-\r
-\r
-void GuiCompare::select_oldfile()\r
-{\r
- QString name = browse(oldFileCB->currentText());\r
- if (!name.isEmpty())\r
- oldFileCB->setEditText(name);\r
- changed();\r
-}\r
-\r
-\r
-QString GuiCompare::browse(QString const & in_name) const\r
-{\r
- QString const title = qt_("Select document");\r
-\r
- QStringList const & filters = fileFilters(qt_("LyX Documents (*.lyx)"));\r
- \r
- QString filename;\r
- if (lyxview().documentBufferView()) {\r
- QString path = bufferFilepath();\r
- filename = browseRelFile(in_name, path, title, filters, false, \r
- qt_("Documents|#o#O"), toqstr(lyxrc.document_path));\r
- } else {\r
- QString path = toqstr(lyxrc.document_path);\r
- QString rel_filename = browseRelFile(in_name, path, title, filters, false, \r
- qt_("Documents|#o#O"), toqstr(lyxrc.document_path));\r
- filename = makeAbsPath(rel_filename, path);\r
- }\r
- return filename; \r
-}\r
-\r
-\r
-void GuiCompare::enableControls(bool enable) const\r
-{\r
- newFileLA->setEnabled(enable);\r
- newFilePB->setEnabled(enable);\r
- newFileCB->setEnabled(enable);\r
- oldFileLA->setEnabled(enable);\r
- oldFilePB->setEnabled(enable);\r
- oldFileCB->setEnabled(enable);\r
- okPB->setEnabled(enable);\r
- groupBox->setEnabled(enable);\r
- progressBar->setEnabled(!enable);\r
-\r
- if (enable)\r
- closePB->setText(qt_("Close"));\r
- else\r
- closePB->setText(qt_("Cancel"));\r
-}\r
-\r
-\r
-void GuiCompare::finished(bool aborted)\r
-{\r
- enableControls(true);\r
- \r
- if (aborted) {\r
- dest_buffer_->markClean();\r
- theBufferList().release(dest_buffer_);\r
- setWindowTitle(window_title_);\r
- progressBar->setValue(0);\r
- } else {\r
- hideView();\r
- bc().ok();\r
- dispatch(FuncRequest(LFUN_BUFFER_SWITCH, dest_buffer_->absFileName()));\r
- }\r
-}\r
-\r
-\r
-void GuiCompare::nextIt(int val)\r
-{\r
- progressBar->setValue(progressBar->value() + val);\r
-}\r
-\r
-\r
-void GuiCompare::progress_max(int max) const\r
-{\r
- progressBar->setMaximum(max);\r
-}\r
- \r
-\r
-void GuiCompare::slotOK()\r
-{\r
- enableControls(false);\r
- if (!run()) {\r
- Alert::error(_("Error"),\r
- _("Unable to compare files."));\r
- finished(true);\r
- }\r
-}\r
-\r
-\r
-void GuiCompare::slotCancel()\r
-{\r
- GuiDialog::slotClose();\r
- progressBar->setValue(0);\r
-}\r
-\r
-\r
-Buffer const * GuiCompare::bufferFromFileName(string const & file) const\r
-{\r
- FileName fname;\r
- if (FileName::isAbsolute(file))\r
- fname.set(file);\r
- else if (lyxview().documentBufferView())\r
- fname = support::makeAbsPath(file, fromqstr(bufferFilepath()));\r
-\r
- if (fname.empty()\r
- || (!fname.exists() && !theBufferList().getBuffer(fname))) {\r
- LYXERR0( "Unable to read: " << file);\r
- return 0;\r
- }\r
- return loadIfNeeded(fname);\r
-}\r
-\r
-\r
-int GuiCompare::run()\r
-{\r
- progressBar->setValue(0);\r
-\r
- new_buffer_ = bufferFromFileName(fromqstr(newFileCB->currentText()));\r
- old_buffer_ = bufferFromFileName(fromqstr(oldFileCB->currentText()));\r
-\r
- // new buffer that will carry the output\r
- FileName initpath(lyxrc.document_path);\r
- dest_buffer_ = newUnnamedFile(initpath, to_utf8(_("differences")));\r
- dest_buffer_->changed();\r
- dest_buffer_->markDirty();\r
-\r
- return 0;\r
-}\r
-\r
-\r
-Dialog * createGuiCompare(GuiView & lv) { return new GuiCompare(lv); }\r
-\r
-\r
-} // namespace frontend\r
-} // namespace lyx\r
-\r
-\r
-#include "moc_GuiCompare.cpp"\r
+/**
+ * \file GuiCompare.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Vincent van Ravesteijn
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiCompare.h"
+
+#include "Buffer.h"
+#include "BufferView.h"
+#include "BufferList.h"
+#include "buffer_funcs.h"
+#include "FuncRequest.h"
+#include "GuiView.h"
+#include "LyXRC.h"
+#include "qt_helpers.h"
+
+#include "frontends/alert.h"
+
+#include "support/debug.h"
+#include "support/filetools.h"
+#include "support/FileName.h"
+#include "support/gettext.h"
+
+#include <QThread>
+
+
+using namespace std;
+using namespace lyx::support;
+
+namespace lyx {
+namespace frontend {
+
+
+GuiCompare::GuiCompare(GuiView & lv)
+ : GuiDialog(lv, "compare", qt_("Compare LyX files")),
+ compare_(0), dest_buffer_(0)
+{
+ setupUi(this);
+ setModal(Qt::WindowModal);
+
+ connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
+ connect(closePB, SIGNAL(clicked()), this, SLOT(slotCancel()));
+
+ connect(newFilePB, SIGNAL(clicked()), this, SLOT(select_newfile()));
+ connect(oldFilePB, SIGNAL(clicked()), this, SLOT(select_oldfile()));
+
+ connect(newFileCB, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(newFileCB, SIGNAL(editTextChanged(const QString &)),
+ this, SLOT(change_adaptor()));
+ connect(oldFileCB, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(oldFileCB, SIGNAL(editTextChanged(const QString &)),
+ this, SLOT(change_adaptor()));
+
+ newSettingsRB->setChecked(true);
+
+ progressBar->setValue(0);
+ progressBar->setEnabled(false);
+
+ bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
+ bc().setOK(okPB);
+}
+
+GuiCompare::~GuiCompare()
+{
+}
+
+void GuiCompare::closeEvent(QCloseEvent *)
+{
+ slotCancel();
+}
+
+
+void GuiCompare::change_adaptor()
+{
+ changed();
+}
+
+
+bool GuiCompare::isValid()
+{
+ bool const valid = !newFileCB->currentText().isEmpty()
+ && !oldFileCB->currentText().isEmpty();
+ return valid;
+}
+
+
+void GuiCompare::updateContents()
+{
+ QString restore_filename1 = newFileCB->currentText();
+ QString restore_filename2 = oldFileCB->currentText();
+ newFileCB->clear();
+ oldFileCB->clear();
+ progressBar->setValue(0);
+ BufferList::iterator it = theBufferList().begin();
+ BufferList::iterator const end = theBufferList().end();
+ for (; it != end; ++it) {
+ QString filename = toqstr((*it)->absFileName());
+ newFileCB->addItem(filename);
+ oldFileCB->addItem(filename);
+ }
+ if (lyxview().documentBufferView())
+ newFileCB->setEditText(toqstr(buffer().absFileName()));
+ else
+ newFileCB->setEditText(restore_filename1);
+
+ if (!restore_filename2.isEmpty())
+ oldFileCB->setEditText(restore_filename2);
+ else
+ oldFileCB->clearEditText();
+
+ if (isValid()) {
+ bc().setValid(isValid());
+ bc().apply();
+ }
+}
+
+
+void GuiCompare::select_newfile()
+{
+ QString name = browse(newFileCB->currentText());
+ if (!name.isEmpty())
+ newFileCB->setEditText(name);
+ changed();
+}
+
+
+void GuiCompare::select_oldfile()
+{
+ QString name = browse(oldFileCB->currentText());
+ if (!name.isEmpty())
+ oldFileCB->setEditText(name);
+ changed();
+}
+
+
+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));
+ } 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));
+ filename = makeAbsPath(rel_filename, path);
+ }
+ return filename;
+}
+
+
+void GuiCompare::enableControls(bool enable) const
+{
+ newFileLA->setEnabled(enable);
+ newFilePB->setEnabled(enable);
+ newFileCB->setEnabled(enable);
+ oldFileLA->setEnabled(enable);
+ oldFilePB->setEnabled(enable);
+ oldFileCB->setEnabled(enable);
+ okPB->setEnabled(enable);
+ groupBox->setEnabled(enable);
+ progressBar->setEnabled(!enable);
+
+ if (enable)
+ closePB->setText(qt_("Close"));
+ else
+ closePB->setText(qt_("Cancel"));
+}
+
+
+void GuiCompare::finished(bool aborted)
+{
+ enableControls(true);
+
+ if (aborted) {
+ dest_buffer_->markClean();
+ theBufferList().release(dest_buffer_);
+ setWindowTitle(window_title_);
+ progressBar->setValue(0);
+ } else {
+ hideView();
+ bc().ok();
+ dispatch(FuncRequest(LFUN_BUFFER_SWITCH, dest_buffer_->absFileName()));
+ }
+}
+
+
+void GuiCompare::nextIt(int val)
+{
+ progressBar->setValue(progressBar->value() + val);
+}
+
+
+void GuiCompare::progress_max(int max) const
+{
+ progressBar->setMaximum(max);
+}
+
+
+void GuiCompare::slotOK()
+{
+ enableControls(false);
+ if (!run()) {
+ Alert::error(_("Error"),
+ _("Unable to compare files."));
+ finished(true);
+ }
+}
+
+
+void GuiCompare::slotCancel()
+{
+ GuiDialog::slotClose();
+ progressBar->setValue(0);
+}
+
+
+Buffer const * GuiCompare::bufferFromFileName(string const & file) const
+{
+ FileName fname;
+ if (FileName::isAbsolute(file))
+ fname.set(file);
+ else if (lyxview().documentBufferView())
+ fname = support::makeAbsPath(file, fromqstr(bufferFilepath()));
+
+ if (fname.empty()
+ || (!fname.exists() && !theBufferList().getBuffer(fname))) {
+ LYXERR0( "Unable to read: " << file);
+ return 0;
+ }
+ return loadIfNeeded(fname);
+}
+
+
+int GuiCompare::run()
+{
+ progressBar->setValue(0);
+
+ new_buffer_ = bufferFromFileName(fromqstr(newFileCB->currentText()));
+ old_buffer_ = bufferFromFileName(fromqstr(oldFileCB->currentText()));
+
+ // new buffer that will carry the output
+ FileName initpath(lyxrc.document_path);
+ dest_buffer_ = newUnnamedFile(initpath, to_utf8(_("differences")));
+ dest_buffer_->changed();
+ dest_buffer_->markDirty();
+
+ return 0;
+}
+
+
+Dialog * createGuiCompare(GuiView & lv) { return new GuiCompare(lv); }
+
+
+} // namespace frontend
+} // namespace lyx
+
+
+#include "moc_GuiCompare.cpp"
-// -*- C++ -*-\r
-/**\r
- * \file GuiCompare.h\r
- * This file is part of LyX, the document processor.\r
- * Licence details can be found in the file COPYING.\r
- *\r
- * \author Vincent van Ravesteijn\r
- *\r
- * Full author contact details are available in file CREDITS.\r
- */\r
-\r
-#ifndef GUICOMPARE_H\r
-#define GUICOMPARE_H\r
-\r
-#include "GuiDialog.h"\r
-#include "ui_CompareUi.h"\r
-#include "qt_helpers.h"\r
-\r
-#include "Compare.h"\r
-\r
-namespace lyx {\r
-namespace frontend {\r
-\r
-\r
-class GuiCompare : public GuiDialog, public Ui::CompareUi\r
-{\r
- Q_OBJECT\r
-\r
-public:\r
- ///\r
- GuiCompare(GuiView & lv);\r
- ~GuiCompare();\r
-\r
- void closeEvent(QCloseEvent *);\r
- \r
-private Q_SLOTS:\r
- ///\r
- void slotOK();\r
- ///\r
- void slotCancel();\r
- ///\r
- void change_adaptor();\r
- ///\r
- void select_newfile();\r
- ///\r
- void select_oldfile();\r
-\r
- ///\r
- void finished(bool aborted);\r
- ///\r
- void nextIt(int);\r
- ///\r
- void progress_max(int) const;\r
-\r
-private:\r
- ///\r
- void updateContents();\r
- ///\r
- bool isValid();\r
- ///\r
- bool initialiseParams(std::string const &) { return true; }\r
- ///\r
- bool isBufferDependent() const { return false; }\r
- ///\r
- void clearParams() {}\r
- ///\r
- void dispatchParams() {}\r
- ///\r
- void apply() {}\r
-\r
-\r
- /// enable or disable all controls and rename the Close/Cancel button\r
- void enableControls(bool enable) const;\r
- \r
- /// browse for a file\r
- QString browse(QString const & in_name) const;\r
- /// retrieve the buffer from the specified filename\r
- Buffer const * bufferFromFileName(std::string const & file) const;\r
-\r
- /// create the compare object and run the comparison\r
- int run();\r
-\r
-private:\r
- /// the object that will do the comparison\r
- Compare * compare_;\r
-\r
- /// the buffer that will contain the result\r
- Buffer * dest_buffer_;\r
- /// the buffer that will contain the result\r
- Buffer const * old_buffer_;\r
- /// the buffer that will contain the result\r
- Buffer const * new_buffer_;\r
-\r
- /// the window title\r
- mutable QString window_title_;\r
-};\r
-\r
-\r
-\r
-} // namespace frontend\r
-} // namespace lyx\r
-\r
-#endif // GUICOMPARE_H\r
+// -*- C++ -*-
+/**
+ * \file GuiCompare.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Vincent van Ravesteijn
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef GUICOMPARE_H
+#define GUICOMPARE_H
+
+#include "GuiDialog.h"
+#include "ui_CompareUi.h"
+#include "qt_helpers.h"
+
+#include "Compare.h"
+
+namespace lyx {
+namespace frontend {
+
+
+class GuiCompare : public GuiDialog, public Ui::CompareUi
+{
+ Q_OBJECT
+
+public:
+ ///
+ GuiCompare(GuiView & lv);
+ ~GuiCompare();
+
+ void closeEvent(QCloseEvent *);
+
+private Q_SLOTS:
+ ///
+ void slotOK();
+ ///
+ void slotCancel();
+ ///
+ void change_adaptor();
+ ///
+ void select_newfile();
+ ///
+ void select_oldfile();
+
+ ///
+ void finished(bool aborted);
+ ///
+ void nextIt(int);
+ ///
+ void progress_max(int) const;
+
+private:
+ ///
+ void updateContents();
+ ///
+ bool isValid();
+ ///
+ bool initialiseParams(std::string const &) { return true; }
+ ///
+ bool isBufferDependent() const { return false; }
+ ///
+ void clearParams() {}
+ ///
+ void dispatchParams() {}
+ ///
+ void apply() {}
+
+
+ /// enable or disable all controls and rename the Close/Cancel button
+ void enableControls(bool enable) const;
+
+ /// browse for a file
+ QString browse(QString const & in_name) const;
+ /// retrieve the buffer from the specified filename
+ Buffer const * bufferFromFileName(std::string const & file) const;
+
+ /// create the compare object and run the comparison
+ int run();
+
+private:
+ /// the object that will do the comparison
+ Compare * compare_;
+
+ /// the buffer that will contain the result
+ Buffer * dest_buffer_;
+ /// the buffer that will contain the result
+ Buffer const * old_buffer_;
+ /// the buffer that will contain the result
+ Buffer const * new_buffer_;
+
+ /// the window title
+ mutable QString window_title_;
+};
+
+
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // GUICOMPARE_H