hi,

this patch tries to implement the draft from http://www.lyx.org/trac/ticket/6255
which i found to be much better compared to solutions i was thinking before.

except the issue with insetinfo for revision number, this somewhat finishes the
support i wanted to have done wrt subversion. //last famous words

comments?

good night ;)
pavel
diff --git a/lib/ui/stdtoolbars.inc b/lib/ui/stdtoolbars.inc
index 5f419ed..8d12792 100644
--- a/lib/ui/stdtoolbars.inc
+++ b/lib/ui/stdtoolbars.inc
@@ -257,6 +257,8 @@ ToolbarSet
                Item "Revert changes" "vc-revert"
                Separator
                Item "Use SVN file locking property" "vc-locking-toggle"
+               Separator
+               Item "Synchro with repository" "vc-repo-synchro"
        End
 
        Toolbar "math_panels" "Math Panels"
diff --git a/src/FuncCode.h b/src/FuncCode.h
index 2a1b767..9a24ce5 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -228,6 +228,7 @@ enum FuncCode
        LFUN_VC_COMMAND,
        LFUN_VC_LOCKING_TOGGLE,
        // 165
+       LFUN_VC_REPO_SYNCHRO,
        LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE, // ARRae 971202
        LFUN_BUFFER_CHKTEX,             // Asger 971030
        LFUN_HYPERLINK_INSERT,          // CFO-G 971121
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 9bb658c..17bb42e 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -2171,6 +2171,16 @@ void LyXAction::init()
  * \endvar
  */
                { LFUN_VC_LOCKING_TOGGLE, "vc-locking-toggle", ReadOnly, System 
},
+/*!
+ * \var lyx::FuncCode lyx::LFUN_VC_REPO_SYNCHRO
+ * \li Action: Synchronize the local archive directory in which resides
+               the current document with repository.
+ * \li Notion: This is currently implemented only for SVN as revert + update 
operation.
+ * \li Syntax: vc-repo-synchro
+ * \li Origin: sanda, 16 Oct 2009
+ * \endvar
+ */
+               { LFUN_VC_REPO_SYNCHRO, "vc-repo-synchro", ReadOnly, System },
 
 /*!
  * \var lyx::FuncCode lyx::LFUN_CHANGES_TRACK
diff --git a/src/LyXVC.cpp b/src/LyXVC.cpp
index a845554..4acdd39 100644
--- a/src/LyXVC.cpp
+++ b/src/LyXVC.cpp
@@ -170,6 +170,13 @@ string LyXVC::checkOut()
 }
 
 
+string LyXVC::repoSynchro()
+{
+       LYXERR(Debug::LYXVC, "LyXVC: repoSynchro");
+       return vcs->repoSynchro();
+}
+
+
 string LyXVC::lockingToggle()
 {
        LYXERR(Debug::LYXVC, "LyXVC: toggle locking property");
diff --git a/src/LyXVC.h b/src/LyXVC.h
index 1d576f9..4285db7 100644
--- a/src/LyXVC.h
+++ b/src/LyXVC.h
@@ -77,6 +77,11 @@ public:
        /// Does the current VC supports this operation?
        bool checkOutEnabled();
 
+       /// Synchronize the whole archive with repository
+       std::string repoSynchro();
+       /// Does the current VC supports this operation?
+       bool repoSynchroEnabled();
+
        /**
         * Toggle locking property of the edited file,
         * i.e. whether the file uses locking mechanism.
diff --git a/src/VCBackend.cpp b/src/VCBackend.cpp
index 421a748..6f6b605 100644
--- a/src/VCBackend.cpp
+++ b/src/VCBackend.cpp
@@ -204,6 +204,20 @@ bool RCS::checkOutEnabled()
        return owner_ && owner_->isReadonly();
 }
 
+
+string RCS::repoSynchro()
+{
+       lyxerr << "Sorry, not implemented." << endl;
+       return string();
+}
+
+
+bool RCS::repoSynchroEnabled()
+{
+       return false;
+}
+
+
 string RCS::lockingToggle()
 {
        lyxerr << "Sorry, not implemented." << endl;
@@ -379,6 +393,19 @@ bool CVS::checkOutEnabled()
 }
 
 
+string CVS::repoSynchro()
+{
+       lyxerr << "Sorry, not implemented." << endl;
+       return string();
+}
+
+
+bool CVS::repoSynchroEnabled()
+{
+       return false;
+}
+
+
 string CVS::lockingToggle()
 {
        lyxerr << "Sorry, not implemented." << endl;
@@ -672,6 +699,55 @@ bool SVN::checkOutEnabled()
 }
 
 
+string SVN::repoSynchro()
+{
+       FileName tmpf = FileName::tempName("lyxvcout");
+       if (tmpf.empty()) {
+               LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+               return N_("Error: Could not generate logfile.");
+       }
+
+       doVCCommand("svn diff " + quoteName(owner_->filePath())
+       + " > " + quoteName(tmpf.toFilesystemEncoding()),
+       FileName(owner_->filePath()));
+       docstring res = tmpf.fileContents("UTF-8");
+       if (!res.empty()) {
+               LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
+               docstring const file = from_utf8(owner_->filePath());
+               docstring text = bformat(_("There were detected changes"
+                               "in the working directory.\n"
+                               "Synchronizing with repository will discard "
+                               "any uncommitted changes in the 
directory:\n%1$s"
+                               "\n\nContinue?"), file);
+               int const ret = frontend::Alert::prompt(_("Changes detected"),
+                               text, 0, 1, _("&Yes"), _("&No"));
+               if (ret) {
+                       tmpf.erase();
+                       return string();
+               }
+       }
+
+       doVCCommand("svn revert -R " + quoteName(owner_->filePath())
+       + " > " + quoteName(tmpf.toFilesystemEncoding()),
+       FileName(owner_->filePath()));
+       res = "Revert log:\n" + tmpf.fileContents("UTF-8");
+       doVCCommand("svn update " + quoteName(owner_->filePath())
+       + " > " + quoteName(tmpf.toFilesystemEncoding()),
+       FileName(owner_->filePath()));
+       res += "Update log:\n" + tmpf.fileContents("UTF-8");
+
+       LYXERR(Debug::LYXVC, res);
+       tmpf.erase();
+       return to_utf8(res);
+}
+
+
+bool SVN::repoSynchroEnabled()
+{
+       return true;
+}
+
+
 string SVN::lockingToggle()
 {
        FileName tmpf = FileName::tempName("lyxvcout");
diff --git a/src/VCBackend.h b/src/VCBackend.h
index 2a06631..dc571d4 100644
--- a/src/VCBackend.h
+++ b/src/VCBackend.h
@@ -43,6 +43,10 @@ public:
        virtual std::string checkOut() = 0;
        // can be this operation processed in the current RCS?
        virtual bool checkOutEnabled() = 0;
+       /// synchronize with repository, returns log
+       virtual std::string repoSynchro() = 0;
+       // can be this operation processed in the current RCS?
+       virtual bool repoSynchroEnabled() = 0;
        // toggle locking property of the file
        virtual std::string lockingToggle() = 0;
        // can be this operation processed in the current RCS?
@@ -131,6 +135,10 @@ public:
 
        virtual bool checkOutEnabled();
 
+       virtual std::string repoSynchro();
+
+       virtual bool repoSynchroEnabled();
+
        virtual std::string lockingToggle();
 
        virtual bool lockingToggleEnabled();
@@ -174,6 +182,10 @@ public:
 
        virtual bool checkOutEnabled();
 
+       virtual std::string repoSynchro();
+
+       virtual bool repoSynchroEnabled();
+
        virtual std::string lockingToggle();
 
        virtual bool lockingToggleEnabled();
@@ -220,6 +232,10 @@ public:
 
        virtual bool checkOutEnabled();
 
+       virtual std::string repoSynchro();
+
+       virtual bool repoSynchroEnabled();
+
        virtual std::string lockingToggle();
 
        virtual bool lockingToggleEnabled();
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 06d0ad1..02716fc 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -1414,6 +1414,9 @@ bool GuiView::getStatus(FuncRequest const & cmd, 
FuncStatus & flag)
        case LFUN_VC_UNDO_LAST:
                enable = doc_buffer && doc_buffer->lyxvc().undoLastEnabled();
                break;
+       case LFUN_VC_REPO_SYNCHRO:
+               enable = doc_buffer && doc_buffer->lyxvc().inUse();
+               break;
        case LFUN_VC_COMMAND: {
                if (cmd.argument().empty())
                        enable = false;
@@ -2334,6 +2337,15 @@ void GuiView::dispatchVC(FuncRequest const & cmd)
                reloadBuffer();
                break;
 
+       case LFUN_VC_REPO_SYNCHRO:
+               LASSERT(buffer, return);
+               if (ensureBufferClean(buffer)) {
+                       string res = buffer->lyxvc().repoSynchro();
+                       message(from_utf8(res));
+                       reloadBuffer();
+               }
+               break;
+
        case LFUN_VC_COMMAND: {
                string flag = cmd.getArg(0);
                if (buffer && contains(flag, 'R') && !ensureBufferClean(buffer))
@@ -2754,6 +2766,7 @@ bool GuiView::dispatch(FuncRequest const & cmd)
                case LFUN_VC_REGISTER:
                case LFUN_VC_CHECK_IN:
                case LFUN_VC_CHECK_OUT:
+               case LFUN_VC_REPO_SYNCHRO:
                case LFUN_VC_LOCKING_TOGGLE:
                case LFUN_VC_REVERT:
                case LFUN_VC_UNDO_LAST:

Reply via email to