Adds the user interface for the new Comparison feature.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31707 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-10-24 15:47:05 +00:00
parent 9722c8f1ea
commit d4be6cf24c
9 changed files with 613 additions and 6 deletions

View File

@ -716,6 +716,7 @@ src_frontends_qt4_header_files = Split('''
GuiClipboard.h
GuiCommandBuffer.h
GuiCommandEdit.h
GuiCompare.h
GuiCompleter.h
GuiDelimiter.h
GuiDialog.h
@ -813,6 +814,7 @@ src_frontends_qt4_files = Split('''
GuiClipboard.cpp
GuiCommandBuffer.cpp
GuiCommandEdit.cpp
GuiCompare.cpp
GuiCompleter.cpp
GuiDelimiter.cpp
GuiDialog.cpp

View File

@ -530,6 +530,7 @@ Menuset
Item "Statistics...|a" "statistics"
OptItem "Check TeX|h" "buffer-chktex"
Item "TeX Information|I" "dialog-show texinfo"
Item "Compare...|C" "dialog-show compare"
Separator
# A LOT of applications have Tools->Prefs. Remember this
# should be rarely used - Edit menu is not a good place to

View File

@ -2596,8 +2596,8 @@ void LyXAction::init()
* \li Action: Shows hidden dialog or create new one for a given function/inset settings etc.
* \li Syntax: dialog-show <NAME> [<DATA>]
* \li Params: <NAME>: aboutlyx|bibitem|bibtex|box|branch|changes|character|citation|\n
document|errorlist|ert|external|file|findreplace|findreplaceadv|float|graphics|\n
href|include|index|index_print|info|label|listings|log|mathdelimiter|\n
compare|document|errorlist|ert|external|file|findreplace|findreplaceadv|float|\n
graphics|href|include|index|index_print|info|label|listings|log|mathdelimiter|\n
mathmatrix|mathspace|nomenclature|nomencl_print|note|paragraph|phantom|prefs|\n
print|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n
thesaurus|texinfo|toc|view-source|vspace|wrap|<SPECIAL> \n

View File

@ -0,0 +1,273 @@
/**
* \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"

View File

@ -0,0 +1,103 @@
// -*- 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

View File

@ -1301,7 +1301,8 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
enable = name == "aboutlyx"
|| name == "file" //FIXME: should be removed.
|| name == "prefs"
|| name == "texinfo";
|| name == "texinfo"
|| name == "compare";
else if (name == "print")
enable = doc_buffer->isExportable("dvi")
&& lyxrc.print_command != "none";
@ -2920,9 +2921,9 @@ namespace {
char const * const dialognames[] = {
"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
"citation", "document", "errorlist", "ert", "external", "file", "findreplace",
"findreplaceadv", "float", "graphics", "href", "include", "index",
"index_print", "info", "listings", "label", "log", "mathdelimiter",
"citation", "compare", "document", "errorlist", "ert", "external", "file",
"findreplace", "findreplaceadv", "float", "graphics", "href", "include",
"index", "index_print", "info", "listings", "label", "log", "mathdelimiter",
"mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note",
"paragraph", "phantom", "prefs", "print", "ref", "sendto", "space",
"spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo",
@ -3083,6 +3084,7 @@ Dialog * createGuiBranch(GuiView & lv);
Dialog * createGuiChanges(GuiView & lv);
Dialog * createGuiCharacter(GuiView & lv);
Dialog * createGuiCitation(GuiView & lv);
Dialog * createGuiCompare(GuiView & lv);
Dialog * createGuiDelimiter(GuiView & lv);
Dialog * createGuiDocument(GuiView & lv);
Dialog * createGuiErrorList(GuiView & lv);
@ -3145,6 +3147,8 @@ Dialog * GuiView::build(string const & name)
return createGuiCharacter(*this);
if (name == "citation")
return createGuiCitation(*this);
if (name == "compare")
return createGuiCompare(*this);
if (name == "document")
return createGuiDocument(*this);
if (name == "errorlist")

View File

@ -73,6 +73,7 @@ SOURCEFILES = \
GuiClipboard.cpp \
GuiCommandBuffer.cpp \
GuiCommandEdit.cpp \
GuiCompare.cpp \
GuiCompleter.cpp \
GuiDelimiter.cpp \
GuiDialog.cpp \
@ -179,6 +180,7 @@ MOCHEADER = \
GuiClipboard.h \
GuiCommandBuffer.h \
GuiCommandEdit.h \
GuiCompare.h \
GuiCompleter.h \
GuiDelimiter.h \
GuiDialog.h \

View File

@ -0,0 +1,221 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CompareUi</class>
<widget class="QDialog" name="CompareUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>495</width>
<height>302</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="newFileLA">
<property name="text">
<string>&amp;New Document:</string>
</property>
<property name="buddy">
<cstring>newFileCB</cstring>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="newFileCB">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newFilePB">
<property name="text">
<string>&amp;Browse...</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="oldFileLA">
<property name="text">
<string>&amp;Old Document:</string>
</property>
<property name="buddy">
<cstring>oldFileCB</cstring>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QComboBox" name="oldFileCB">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="oldFilePB">
<property name="text">
<string>Bro&amp;wse...</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Options</string>
</property>
<widget class="QRadioButton" name="newSettingsRB">
<property name="geometry">
<rect>
<x>20</x>
<y>40</y>
<width>151</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>New Document</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="oldSettingsRB">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>151</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Old Document</string>
</property>
<attribute name="buttonGroup">
<string>buttonGroup</string>
</attribute>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>161</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Copy Document Settings from:</string>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>&amp;OK</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB">
<property name="text">
<string>&amp;Close</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<includes>
<include location="local">qt_i18n.h</include>
</includes>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

View File

@ -11,6 +11,7 @@ uic BulletsUi.ui -o BulletsUi.h
uic ChangesUi.ui -o ChangesUi.h
uic CharacterUi.ui -o CharacterUi.h
uic CitationUi.ui -o CitationUi.h
uic CompareUi.ui -o CompareUi.h
uic DelimiterUi.ui -o DelimiterUi.h
uic DocumentUi.ui -o DocumentUi.h
uic ErrorListUi.ui -o ErrorListUi.h