From cec6ed072dacdea57380990691530429cbc8494a Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 1 Jul 2014 13:30:22 +0000 Subject: [PATCH] ide: Diff now jumps to the line in editor on double-click git-svn-id: svn://ultimatepp.org/upp/trunk@7481 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/TextDiffCtrl/DiffCtrl.cpp | 2 ++ uppsrc/TextDiffCtrl/TextCtrl.cpp | 29 +++++++++++++++++------------ uppsrc/TextDiffCtrl/TextDiffCtrl.h | 8 +++++++- uppsrc/ide/ide.cpp | 14 ++++++++++++++ uppsrc/ide/ide.h | 2 ++ 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/uppsrc/TextDiffCtrl/DiffCtrl.cpp b/uppsrc/TextDiffCtrl/DiffCtrl.cpp index 1f21a0a78..4b4b074a4 100644 --- a/uppsrc/TextDiffCtrl/DiffCtrl.cpp +++ b/uppsrc/TextDiffCtrl/DiffCtrl.cpp @@ -14,6 +14,8 @@ TextDiffCtrl::TextDiffCtrl() left.WhenScroll = right.ScrollWhen(left); right.WhenScroll = left.ScrollWhen(right); right.HideSb(); + left.WhenLeftDouble = Proxy(WhenLeftLine); + right.WhenLeftDouble = Proxy(WhenRightLine); } static bool SmallDiff(const char *s1, const char *s2) diff --git a/uppsrc/TextDiffCtrl/TextCtrl.cpp b/uppsrc/TextDiffCtrl/TextCtrl.cpp index 05ee11ce1..03ad4133d 100644 --- a/uppsrc/TextDiffCtrl/TextCtrl.cpp +++ b/uppsrc/TextDiffCtrl/TextCtrl.cpp @@ -25,19 +25,22 @@ TextCompareCtrl::TextCompareCtrl() gutter_capture = false; } -void TextCompareCtrl::DoSelection(int y, bool shift) +int TextCompareCtrl::GetLineNo(int y) { int ii = scroll.Get().y + y / letter.cy; - if(ii >= 0 && ii < lines.GetCount()) { - int i = lines[ii].number; - if(!IsNull(i)) { - if(shift) - cursor = i; - else - cursor = anchor = i; - Refresh(); - scroll.ScrollIntoY(i); - } + return ii >= 0 && ii < lines.GetCount() ? lines[ii].number : Null; +} + +void TextCompareCtrl::DoSelection(int y, bool shift) +{ + int i = GetLineNo(y); + if(!IsNull(i)) { + if(shift) + cursor = i; + else + cursor = anchor = i; + Refresh(); + scroll.ScrollIntoY(i); } } @@ -62,7 +65,9 @@ void TextCompareCtrl::LeftDown(Point pt, dword keyflags) void TextCompareCtrl::LeftDouble(Point pt, dword keyflags) { - + int i = GetLineNo(pt.y); + if(!IsNull(i)) + WhenLeftDouble(i - 1); } void TextCompareCtrl::MouseMove(Point pt, dword flags) diff --git a/uppsrc/TextDiffCtrl/TextDiffCtrl.h b/uppsrc/TextDiffCtrl/TextDiffCtrl.h index 9c7a393db..49a8596f0 100644 --- a/uppsrc/TextDiffCtrl/TextDiffCtrl.h +++ b/uppsrc/TextDiffCtrl/TextDiffCtrl.h @@ -49,6 +49,7 @@ private: bool GetSelection(int& l, int& h); void DoSelection(int y, bool shift); void Copy(); + int GetLineNo(int y); private: struct Line { @@ -79,7 +80,7 @@ private: public: Callback WhenScroll; - Callback WhenLeftDouble; + Callback1 WhenLeftDouble; void SetCount(int c); void AddCount(int c); @@ -135,6 +136,9 @@ public: void SetFont(Font f, Font nf) { left.SetFont(f, nf); right.SetFont(f, nf); } void SetFont(Font f) { left.SetFont(f); right.SetFont(f); } + Callback1 WhenLeftLine; + Callback1 WhenRightLine; + TextDiffCtrl(); }; @@ -164,6 +168,8 @@ struct FileDiff : DiffDlg { typedef FileDiff CLASSNAME; + String GetExtPath() const { return ~r; } + FileDiff(FileSel& fs); FileSel& fs; diff --git a/uppsrc/ide/ide.cpp b/uppsrc/ide/ide.cpp index 7ee3faf1d..8eaccf09b 100644 --- a/uppsrc/ide/ide.cpp +++ b/uppsrc/ide/ide.cpp @@ -548,12 +548,26 @@ int Ide::GetPackageIndex() return -1; } +void Ide::GotoDiffLeft(int line, DiffDlg *df) +{ + EditFile(df->editfile); + editor.SetCursor(editor.GetPos(line)); +} + +void Ide::GotoDiffRight(int line, FileDiff *df) +{ + EditFile(df->GetExtPath()); + editor.SetCursor(editor.GetPos(line)); + editor.SetFocus(); +} void Ide::Diff() { if(IsNull(editfile)) return; FileDiff diffdlg(AnySourceFs()); + diffdlg.diff.WhenLeftLine = THISBACK1(GotoDiffLeft, &diffdlg); + diffdlg.diff.WhenRightLine = THISBACK1(GotoDiffRight, &diffdlg); diffdlg.Execute(editfile); } diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index fcb9e24c4..54577e106 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -845,6 +845,8 @@ public: void GoOpposite(); void Print(); void Diff(); + void GotoDiffLeft(int line, DiffDlg *df); + void GotoDiffRight(int line, FileDiff *df); void Patch(); void SvnHistory();