From ae247b9ad463106e7ecbfd06baa2cc93557f70dd Mon Sep 17 00:00:00 2001 From: rylek Date: Sat, 28 Mar 2009 17:17:59 +0000 Subject: [PATCH] SVN synchronization dialog extended to support SVN-based file comparison git-svn-id: svn://ultimatepp.org/upp/trunk@1013 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/TextDiffCtrl/DiffCtrl.cpp | 11 +++- uppsrc/ide/icon.ico | Bin 2862 -> 2862 bytes uppsrc/ide/ide.cpp | 21 +++++++ uppsrc/ide/ide.upp | 1 - uppsrc/{ide => usvn}/Diff.cpp | 102 +++++++++++++++++-------------- uppsrc/usvn/SvnSync.cpp | 11 ++++ uppsrc/usvn/init | 2 +- uppsrc/usvn/usvn.h | 7 ++- uppsrc/usvn/usvn.iml | 15 +++++ uppsrc/usvn/usvn.lay | 2 +- uppsrc/usvn/usvn.upp | 4 +- 11 files changed, 123 insertions(+), 53 deletions(-) rename uppsrc/{ide => usvn}/Diff.cpp (72%) create mode 100644 uppsrc/usvn/usvn.iml diff --git a/uppsrc/TextDiffCtrl/DiffCtrl.cpp b/uppsrc/TextDiffCtrl/DiffCtrl.cpp index 31587d1bf..61a48d829 100644 --- a/uppsrc/TextDiffCtrl/DiffCtrl.cpp +++ b/uppsrc/TextDiffCtrl/DiffCtrl.cpp @@ -38,16 +38,19 @@ void TextDiffCtrl::Set(Stream& l, Stream& r) Vector rl = GetLineMap(r); Array sections = CompareLineMaps(ll, rl); - Point left_pos = left.GetPos(); - Point right_pos = right.GetPos(); - int sb_pos = left.GetSb(); +// Point left_pos = left.GetPos(); +// Point right_pos = right.GetPos(); +// int sb_pos = left.GetSb(); int outln = 0; left.SetCount(0); right.SetCount(0); + int firstdiff = -1; for(int i = 0; i < sections.GetCount(); i++) { const TextSection& sec = sections[i]; bool diff = !sec.same; + if(firstdiff < 0 && diff) + firstdiff = outln; Color c1 = (diff ? LtBlue() : SBlack()), c2 = (diff ? LtBlue() : SBlack()); int maxcount = max(sec.count1, sec.count2); left.AddCount(maxcount); @@ -67,6 +70,8 @@ void TextDiffCtrl::Set(Stream& l, Stream& r) right.Set(outln + l, Null, c2, Null, 2); outln += maxcount; } + if(firstdiff >= 0) + left.SetSb(max(firstdiff - 2, 0)); } void TextDiffCtrl::Set(const String& l, const String& r) diff --git a/uppsrc/ide/icon.ico b/uppsrc/ide/icon.ico index 74f9e3888db090968031f61749e98855525020cc..3fbfb8a5881abb6b5aaa669cbca302327a137013 100644 GIT binary patch literal 2862 zcmcguy>8S%5FYhC8+w{8>d zqlWc9Ya&mg1FrjzV!2nSyV{4fmIJnJThSR@Qny;IEEM&?D+hc(H!+BXFv2OYICUJ- zpCig0;H96`aJ|}|&5LQSvus5AdyeiqOe36{gJl#{p@+;;|ENV~@8Is2wGOw= zRN0*V{QN~#YN=!b%W=ywxAG7*!$15)_A08>z+w(x&(6lapTilL2>+Kc$E=5B6@PR@ zRuwp$C-K0(Vtq8mhkezb?2q2hV!Za(-mnoK{n7geE6=I(YroJ&c=QIIvG(_XpX!a8 z2oJ0(&v5DfxHtC|4!%o>59f&b1FQSH%KdR~%m5A#ANGYmd4JtM=J4=1PiZti-ka{< z!)t%#P(Q@OzpU!-f2K9_q|UOwFiR3s*O_4>QWb?M>)I5Zk6>BWE@@20V$!n20Ws&N zW4}mK%?qw5QpFqa=d8*ve(w2IWwJas)i5G+b^c|jy#n<<1u3-Dn+06skrrEs2bG!VuL_OOVVvpC)w@;B- LKgKhV>+b0v@@TmI delta 1270 zcmaKoc~F#f7{@>CzPo^cL_-URO4Ow25XP*aQh`i}fDV>uo`5JvkPce9KoPH3k&Lt= zqX-l@&UjP?2BA_bhsR(Dnk1u+D5rvn980ebvOo()=|6sFe)Bw^=R40azXDZ(>cn4y zIDOvB+?LIwTKti;$qV_^-4>OugzZ_DOqk@wo>Ozs=ugu7eil3Oju5TU&{;MMP4p>x zPbJgdJ3vbJASpf?!V)uZ48Oy7U*F}GDHm|Buf||e-Z6UL(_| zm~34xo1*$ro?k*xZz2pYUP2n1&F9`F_E0ieX=Q{;5<|xw zsI?!@;p)r8`&T2jrE`C|o=68zZbwI=jxXfGJ08?t%wu&`F*EyBDAF7;1dd1W$Y5hs z5BuU*vpuGeyp$|-%hyw5FS=5=ZY3AbS|l-a_W{jA(`d2UPpEe} zC7CnP-44UIt_E#W2zh5bjo+x_h~XuQymHuT=*K7Co(IMkA28!aA8tG^6Cn&=4nV$=vYrsdT|PxFz2^a6>`cuKkaKa!i6NJ^z#GKNu^ zDHM{aQYk6^<&mPPsq(2QNphnknW^bWGE#fWvgcVLla2YKeF}w4iW-|RvOqAtu?3?n gJi}&Yl3WlZv;S{24im=OUmP>Tgy3S^aT84b0X^y?nE(I) diff --git a/uppsrc/ide/ide.cpp b/uppsrc/ide/ide.cpp index fc73d418f..d5d76a3f5 100644 --- a/uppsrc/ide/ide.cpp +++ b/uppsrc/ide/ide.cpp @@ -805,3 +805,24 @@ const Workspace& Ide::IdeWorkspace() const } return wspc; } + +void Ide::Diff() +{ + if(IsNull(editfile)) + return; + RunFileDiff(editfile, AnySourceFs()); +} + +void Ide::Patch() +{ + if(IsNull(editfile)) + return; + RunPatchDiff(editfile, AnySourceFs()); +} + +void Ide::SvnHistory() +{ + if(IsNull(editfile)) + return; + RunSvnDiff(editfile); +} diff --git a/uppsrc/ide/ide.upp b/uppsrc/ide/ide.upp index 64c5454fb..bfdd505e1 100644 --- a/uppsrc/ide/ide.upp +++ b/uppsrc/ide/ide.upp @@ -60,7 +60,6 @@ file Calc.cpp, FormatCode.cpp, Abbr.cpp, - Diff.cpp, Compile readonly separator, Methods.cpp, AutoSetup.cpp, diff --git a/uppsrc/ide/Diff.cpp b/uppsrc/usvn/Diff.cpp similarity index 72% rename from uppsrc/ide/Diff.cpp rename to uppsrc/usvn/Diff.cpp index ced588f66..9fbdff176 100644 --- a/uppsrc/ide/Diff.cpp +++ b/uppsrc/usvn/Diff.cpp @@ -1,4 +1,8 @@ -#include "ide.h" +#include "usvn.h" + +#define IMAGECLASS UsvnImg +#define IMAGEFILE "usvn.iml" +#include struct DiffDlg : public TopWindow { TextDiffCtrl diff; @@ -70,14 +74,16 @@ struct FileDiff : DiffDlg { typedef FileDiff CLASSNAME; - FileDiff(); + FileDiff(FileSel& fs); + + FileSel& fs; }; void FileDiff::Open() { - if(!AnySourceFs().ExecuteOpen()) + if(!fs.ExecuteOpen()) return; - String f = ~AnySourceFs(); + String f = ~fs; r <<= f; diff.Set(LoadFile(editfile), extfile = LoadFile(f)); } @@ -91,19 +97,20 @@ void FileDiff::Execute(const String& f) DiffDlg::Execute(f); } -FileDiff::FileDiff() +FileDiff::FileDiff(FileSel& fs_) +: fs(fs_) { r.Height(EditField::GetStdHeight()); - Icon(IdeImg::Diff()); + Icon(UsvnImg::Diff()); diff.InsertFrameRight(r); r <<= THISBACK(Open); } -void Ide::Diff() +void RunFileDiff(String editfile, FileSel& fs) { if(IsNull(editfile)) return; - FileDiff dlg; + FileDiff dlg(fs); dlg.Execute(editfile); } @@ -117,6 +124,8 @@ FileSel& DiffFs() { } struct PatchDiff : FileDiff { + PatchDiff(FileSel& fs) : FileDiff(fs) {} + virtual void Open(); void Copy(FileIn& in, FileIn& oin, int& l, int ln, int n); @@ -220,12 +229,12 @@ void PatchDiff::Open() diff.Set(LoadFile(editfile), extfile); } -void Ide::Patch() +void RunPatchDiff(String editfile, FileSel& fs) { if(IsNull(editfile)) return; - PatchDiff dlg; - dlg.Execute(editfile); + PatchDiff dlg(fs); + dlg.Execute(editfile); } struct SvnDiff : DiffDlg { @@ -241,42 +250,45 @@ struct SvnDiff : DiffDlg { void SvnDiff::Execute(const String& f) { - editfile = f; - String log = Sys("svn log " + f); - if(log.IsVoid()) { - Exclamation("Error executing 'svn log'"); - return; - } - StringStream ss(log); - while(!ss.IsEof()) { - String l = ss.GetLine(); - if(l[0] == 'r') { - Vector h = Split(l, '|'); - if(h.GetCount() > 3) { - String rev = TrimBoth(h[0]); - String s = rev; - Vector t = Split(h[2], ' '); - if(t.GetCount() > 1) - s << ' ' << t[0]; - s << ' ' << TrimBoth(h[1]); - while(!ss.IsEof()) { - l = ss.GetLine(); - if(l.GetCount()) { - if(l[0] != '-') - s << ": " << l; - break; + { + WaitCursor wait; + editfile = f; + String log = Sys("svn log " + f); + if(log.IsVoid()) { + Exclamation("Error executing 'svn log'"); + return; + } + StringStream ss(log); + while(!ss.IsEof()) { + String l = ss.GetLine(); + if(l[0] == 'r') { + Vector h = Split(l, '|'); + if(h.GetCount() > 3) { + String rev = TrimBoth(h[0]); + String s = rev; + Vector t = Split(h[2], ' '); + if(t.GetCount() > 1) + s << ' ' << t[0]; + s << ' ' << TrimBoth(h[1]); + while(!ss.IsEof()) { + l = ss.GetLine(); + if(l.GetCount()) { + if(l[0] != '-') + s << ": " << l; + break; + } } + r.Add(rev, s); } - r.Add(rev, s); } } + if(r.GetCount() == 0) { + Exclamation("No parsable history for the file"); + return; + } + r.SetIndex(0); + Load(); } - if(r.GetCount() == 0) { - Exclamation("No parsable history for the file"); - return; - } - r.SetIndex(0); - Load(); DiffDlg::Execute(f); } @@ -289,15 +301,15 @@ SvnDiff::SvnDiff() { r.Height(EditField::GetStdHeight()); r.SetDropLines(32); - Icon(IdeImg::SvnDiff()); + Icon(UsvnImg::SvnDiff()); diff.InsertFrameRight(r); r <<= THISBACK(Load); } -void Ide::SvnHistory() +void RunSvnDiff(String editfile) { if(IsNull(editfile)) return; SvnDiff dlg; - dlg.Execute(editfile); + dlg.Execute(editfile); } diff --git a/uppsrc/usvn/SvnSync.cpp b/uppsrc/usvn/SvnSync.cpp index f027ffc3e..7e9c684f2 100644 --- a/uppsrc/usvn/SvnSync.cpp +++ b/uppsrc/usvn/SvnSync.cpp @@ -10,6 +10,7 @@ SvnSync::SvnSync() list.ColumnWidths("170 600"); list.NoCursor().EvenRowColor(); list.SetLineCy(max(Draw::GetStdFontCy(), 20)); + list.WhenLeftClick = THISBACK(Diff); Sizeable().Zoomable(); setup <<= THISBACK(Setup); } @@ -107,6 +108,16 @@ void SvnSync::SyncList() } } +void SvnSync::Diff() +{ + int cr = list.GetClickRow(); + if(cr >= 0) { + String f = list.Get(cr, 1); + if(!IsNull(f)) + RunSvnDiff(f); + } +} + #ifdef PLATFORM_WIN32 void sDeleteFolderDeep(const char *dir) { diff --git a/uppsrc/usvn/init b/uppsrc/usvn/init index 64977b789..c1c62b484 100644 --- a/uppsrc/usvn/init +++ b/uppsrc/usvn/init @@ -1,4 +1,4 @@ #ifndef _usvn_icpp_init_stub #define _usvn_icpp_init_stub -#include "CtrlLib/init" +#include "TextDiffCtrl/init" #endif diff --git a/uppsrc/usvn/usvn.h b/uppsrc/usvn/usvn.h index 068d1ef91..cd0beee79 100644 --- a/uppsrc/usvn/usvn.h +++ b/uppsrc/usvn/usvn.h @@ -1,7 +1,7 @@ #ifndef _usvn_usvn_h_ #define _usvn_usvn_h_ -#include +#include using namespace Upp; @@ -115,6 +115,7 @@ struct SvnSync : WithSvnSyncLayout { void SyncList(); void Setup(); + void Diff(); typedef SvnSync CLASSNAME; @@ -129,4 +130,8 @@ public: SvnSync(); }; +void RunFileDiff(String editfile, FileSel& fs); +void RunPatchDiff(String editfile, FileSel& fs); +void RunSvnDiff(String editfile); + #endif diff --git a/uppsrc/usvn/usvn.iml b/uppsrc/usvn/usvn.iml new file mode 100644 index 000000000..cad697e67 --- /dev/null +++ b/uppsrc/usvn/usvn.iml @@ -0,0 +1,15 @@ +PREMULTIPLIED +IMAGE_ID(Diff) +IMAGE_ID(SvnDiff) +IMAGE_ID(Patch) + +IMAGE_BEGIN_DATA +IMAGE_DATA(120,156,213,148,209,13,195,32,12,68,111,4,198,235,56,44,80,169,203,244,163,95,101,148,172,208,9,104,29,53,205,145) +IMAGE_DATA(216,184,82,64,73,28,157,20,44,158,13,150,49,2,2,14,100,185,174,232,8,121,24,6,85,19,127,189,61,85,245,224) +IMAGE_DATA(121,205,188,252,123,188,22,139,243,47,99,48,239,215,113,86,143,252,45,238,191,206,109,215,127,238,141,53,47,190,148,146) +IMAGE_DATA(201,139,255,254,120,153,231,23,214,226,39,150,249,141,253,187,175,157,105,24,132,75,168,10,206,99,30,247,24,95,15,158) +IMAGE_DATA(215,5,15,159,215,98,21,249,97,243,94,29,11,117,200,223,226,254,218,48,48,235,15,155,7,13,3,149,255,248,197,172) +IMAGE_DATA(243,243,48,88,241,95,150,249,141,253,187,175,157,105,24,68,71,112,30,179,236,201,134,122,240,188,102,30,127,240,90,44) +IMAGE_DATA(206,191,140,193,188,87,71,86,143,252,45,238,175,13,3,171,254,168,240,160,97,160,241,163,63,70,243,252,60,12,150,252) +IMAGE_DATA(143,37,126,99,255,238,106,111,203,14,174,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) +IMAGE_END_DATA(256, 3) diff --git a/uppsrc/usvn/usvn.lay b/uppsrc/usvn/usvn.lay index a26c764af..a75040447 100644 --- a/uppsrc/usvn/usvn.lay +++ b/uppsrc/usvn/usvn.lay @@ -1,5 +1,5 @@ LAYOUT(SvnSyncLayout, 672, 592) - ITEM(ArrayCtrl, list, HSizePosZ(4, 4).VSizePosZ(4, 36)) + ITEM(ArrayCtrl, list, AutoHideSb(true).HSizePosZ(4, 4).VSizePosZ(4, 36)) ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(4, 64).BottomPosZ(4, 24)) ITEM(Button, setup, SetLabel(t_("Setup working directories")).LeftPosZ(88, 144).TopPosZ(564, 24)) ITEM(Button, ok, SetLabel(t_("Synchronize!")).RightPosZ(4, 84).BottomPosZ(4, 24)) diff --git a/uppsrc/usvn/usvn.upp b/uppsrc/usvn/usvn.upp index 071f5c829..16fb093e6 100644 --- a/uppsrc/usvn/usvn.upp +++ b/uppsrc/usvn/usvn.upp @@ -1,7 +1,7 @@ description "Simple svn GUI frontend, also a module that can be used in other applications"; uses - CtrlLib; + TextDiffCtrl; file usvn.h, @@ -9,7 +9,9 @@ file SvnFs.cpp, SvnWorks.cpp, SvnSync.cpp, + Diff.cpp, notes.txt, + usvn.iml, usvn.lay, Info readonly separator, Copying;