From e2c0424c17abfa105aca6f6708133d8e3d7dd575 Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Tue, 7 Sep 2010 11:28:57 +0000 Subject: [PATCH] Add decent UI for VC_COMPARE git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35306 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/scons/scons_manifest.py | 3 + src/LyXAction.cpp | 7 +- src/frontends/qt4/GuiCompareHistory.cpp | 124 ++++++++++++++ src/frontends/qt4/GuiCompareHistory.h | 61 +++++++ src/frontends/qt4/GuiView.cpp | 21 ++- src/frontends/qt4/Makefile.am | 3 + src/frontends/qt4/ui/CompareHistoryUi.ui | 205 +++++++++++++++++++++++ 7 files changed, 414 insertions(+), 10 deletions(-) create mode 100644 src/frontends/qt4/GuiCompareHistory.cpp create mode 100644 src/frontends/qt4/GuiCompareHistory.h create mode 100644 src/frontends/qt4/ui/CompareHistoryUi.ui diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 160898c5a4..ad70ed3c13 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -721,6 +721,7 @@ src_frontends_qt4_header_files = Split(''' GuiCommandBuffer.h GuiCommandEdit.h GuiCompare.h + GuiCompareHistory.h GuiCompleter.h GuiDelimiter.h GuiDialog.h @@ -823,6 +824,7 @@ src_frontends_qt4_files = Split(''' GuiCommandBuffer.cpp GuiCommandEdit.cpp GuiCompare.cpp + GuiCompareHistory.cpp GuiCompleter.cpp GuiDelimiter.cpp GuiDialog.cpp @@ -921,6 +923,7 @@ src_frontends_qt4_ui_files = Split(''' CitationUi.ui ColorUi.ui CompareUi.ui + CompareHistoryUi.ui DelimiterUi.ui DocumentUi.ui ERTUi.ui diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 963cfd2b1a..1a55e24044 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -2192,13 +2192,14 @@ void LyXAction::init() * \var lyx::FuncCode lyx::LFUN_VC_COMPARE * \li Action: Compares two revisions of the same file under version control. * \li Notion: This is currently implemented only for SVN and RCS. - * \li Syntax: vc-compare [] + * \li Syntax: vc-compare [] [] * \li Params: Revision number either points directly to commit in history - or if negative number -x it points to last commit - x.\n + or if negative number -x it points to (last commit - x).\n In RCS we subtract only in the last number of revision specification. Special case "0" is reserved for the last committed revision.\n : Older file.\n - : Newer file. Used only if REV1 > 0. + : Newer file. Used only if REV1 > 0.\n + If no parameter is given, interactive dialog will be shown. * \li Sample: Compare current document against last commit\n vc-compare 0 * \li Sample: Compare current document against current revision - 5 commits\n diff --git a/src/frontends/qt4/GuiCompareHistory.cpp b/src/frontends/qt4/GuiCompareHistory.cpp new file mode 100644 index 0000000000..35cff62151 --- /dev/null +++ b/src/frontends/qt4/GuiCompareHistory.cpp @@ -0,0 +1,124 @@ +/** + * \file GuiCompareHistory.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Pavel Sanda + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "GuiCompareHistory.h" + +#include "Buffer.h" +#include "BufferView.h" +#include "FuncRequest.h" +#include "GuiView.h" +#include "LyXVC.h" + +#include "support/convert.h" +#include "support/lstrings.h" + + + +using namespace std; +using namespace lyx::support; + +namespace lyx { +namespace frontend { + + +GuiCompareHistory::GuiCompareHistory(GuiView & lv) + : GuiDialog(lv, "comparehistory", qt_("Compare different revisions")) + +{ + setupUi(this); + setModal(Qt::WindowModal); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(cancelPB, SIGNAL(clicked()), this, SLOT(slotCancel())); + + connect(revbackRB, SIGNAL(clicked()), this, SLOT(selectRevback())); + connect(betweenrevRB, SIGNAL(clicked()), this, SLOT(selectBetweenrev())); + + string revstring = lv.currentBufferView()->buffer().lyxvc().revisionInfo(LyXVC::File); + int rev=0; + if (prefixIs(revstring, "r")) + revstring = ltrim(revstring,"r"); + if (isStrInt(revstring)) + rev = convert(revstring); + + okPB->setEnabled(rev); + rev1SB->setMaximum(rev); + rev2SB->setMaximum(rev); + revbackSB->setMaximum(rev); + rev2SB->setValue(rev); + rev1SB->setValue(rev-1); + + //bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy); + //bc().setOK(okPB); + //bc().setCancel(cancelPB); + enableControls(); +} + + +void GuiCompareHistory::updateContents() +{ + enableControls(); +} + + +void GuiCompareHistory::selectRevback() +{ + betweenrevRB->setChecked(false); + enableControls(); +} + + +void GuiCompareHistory::selectBetweenrev() +{ + revbackRB->setChecked(false); + enableControls(); +} + + +void GuiCompareHistory::enableControls() +{ + bool rb = revbackRB->isChecked(); + rev1SB->setEnabled(!rb); + rev2SB->setEnabled(!rb); + betweenrevRB->setChecked(!rb); + revbackSB->setEnabled(rb); +} + + +void GuiCompareHistory::slotOK() +{ + string param; + if (revbackRB->isChecked()) + param = "-" + convert(revbackSB->value()); + else + param = convert(rev1SB->value()) + + + " " + convert(rev2SB->value()); + + GuiDialog::slotClose(); + dispatch(FuncRequest(LFUN_VC_COMPARE, param)); +} + + +void GuiCompareHistory::slotCancel() +{ + GuiDialog::slotClose(); +} + + +Dialog * createGuiCompareHistory(GuiView & lv) { return new GuiCompareHistory(lv); } + + +} // namespace frontend +} // namespace lyx + + +#include "moc_GuiCompareHistory.cpp" diff --git a/src/frontends/qt4/GuiCompareHistory.h b/src/frontends/qt4/GuiCompareHistory.h new file mode 100644 index 0000000000..bb9eac5a8a --- /dev/null +++ b/src/frontends/qt4/GuiCompareHistory.h @@ -0,0 +1,61 @@ +// -*- C++ -*- +/** + * \file GuiCompareHistory.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Pavel Sanda + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef GUICOMPAREHISTORY_H +#define GUICOMPAREHISTORY_H + +#include "GuiDialog.h" +#include "ui_CompareHistoryUi.h" +#include "qt_helpers.h" + + +namespace lyx { +namespace frontend { + + +class GuiCompareHistory : public GuiDialog, public Ui::CompareHistoryUi +{ + Q_OBJECT + +public: + /// + GuiCompareHistory(GuiView & lv); + +private Q_SLOTS: + /// + void slotOK(); + /// + void slotCancel(); + /// + void selectRevback(); + /// + void selectBetweenrev(); +private: + /// + void updateContents(); + /// + bool initialiseParams(std::string const &) { return true; } + /// + bool isBufferDependent() const { return true; } + /// + void clearParams() {} + /// + void dispatchParams() {} + /// + void enableControls(); + +private: +}; + +} // namespace frontend +} // namespace lyx + +#endif // GUICOMPAREHISTORY_H diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 0a1b4ba150..1e04338002 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -1667,8 +1667,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) break; } case LFUN_VC_COMPARE: - enable = doc_buffer && !cmd.argument().empty() - && doc_buffer->lyxvc().prepareFileRevisionEnabled(); + enable = doc_buffer && doc_buffer->lyxvc().prepareFileRevisionEnabled(); break; case LFUN_SERVER_GOTO_FILE_ROW: @@ -2665,6 +2664,11 @@ void GuiView::dispatchVC(FuncRequest const & cmd) case LFUN_VC_COMPARE: { + if (cmd.argument().empty()) { + lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "comparehistory")); + break; + } + string rev1 = cmd.getArg(0); string f1, f2; @@ -3456,15 +3460,15 @@ namespace { // docs in LyXAction.cpp. char const * const dialognames[] = { + "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character", -"citation", "compare", "document", "errorlist", "ert", "external", -"file", "findreplace", "findreplaceadv", "float", "graphics", "href", -"include", "index", "index_print", "info", "listings", "label", "line", +"citation", "compare", "comparehistory", "document", "errorlist", "ert", +"external", "file", "findreplace", "findreplaceadv", "float", "graphics", +"href", "include", "index", "index_print", "info", "listings", "label", "line", "log", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note", "paragraph", "phantom", "prefs", "print", "ref", "sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate", -"thesaurus", "texinfo", "toc", "view-source", "vspace", "wrap", -"progress"}; +"thesaurus", "texinfo", "toc", "view-source", "vspace", "wrap", "progress"}; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -3643,6 +3647,7 @@ Dialog * createGuiChanges(GuiView & lv); Dialog * createGuiCharacter(GuiView & lv); Dialog * createGuiCitation(GuiView & lv); Dialog * createGuiCompare(GuiView & lv); +Dialog * createGuiCompareHistory(GuiView & lv); Dialog * createGuiDelimiter(GuiView & lv); Dialog * createGuiDocument(GuiView & lv); Dialog * createGuiErrorList(GuiView & lv); @@ -3701,6 +3706,8 @@ Dialog * GuiView::build(string const & name) return createGuiCitation(*this); if (name == "compare") return createGuiCompare(*this); + if (name == "comparehistory") + return createGuiCompareHistory(*this); if (name == "document") return createGuiDocument(*this); if (name == "errorlist") diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 12b3d0d4da..83c940e206 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -74,6 +74,7 @@ SOURCEFILES = \ GuiCommandBuffer.cpp \ GuiCommandEdit.cpp \ GuiCompare.cpp \ + GuiCompareHistory.cpp \ GuiCompleter.cpp \ GuiDelimiter.cpp \ GuiDialog.cpp \ @@ -185,6 +186,7 @@ MOCHEADER = \ GuiCommandBuffer.h \ GuiCommandEdit.h \ GuiCompare.h \ + GuiCompareHistory.h \ GuiCompleter.h \ GuiDelimiter.h \ GuiDialog.h \ @@ -263,6 +265,7 @@ UIFILES = \ CitationUi.ui \ ColorUi.ui \ CompareUi.ui \ + CompareHistoryUi.ui \ DelimiterUi.ui \ DocumentUi.ui \ ErrorListUi.ui \ diff --git a/src/frontends/qt4/ui/CompareHistoryUi.ui b/src/frontends/qt4/ui/CompareHistoryUi.ui new file mode 100644 index 0000000000..019a066956 --- /dev/null +++ b/src/frontends/qt4/ui/CompareHistoryUi.ui @@ -0,0 +1,205 @@ + + CompareHistoryUi + + + + 0 + 0 + 356 + 172 + + + + + + + true + + + + + + Compare Revisions + + + + + + + + &Revisions back + + + true + + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + 1 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + &Between revisions + + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + 1 + + + 1 + + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + 1 + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + &Ok + + + false + + + true + + + false + + + + + + + + 0 + 0 + + + + &Cancel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + qt_i18n.h + + + + -- 2.39.5