mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
TextDiffCtrl: Now supports selection & copy #171
git-svn-id: svn://ultimatepp.org/upp/trunk@6946 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
5b641eeaeb
commit
a2a391f4e3
4 changed files with 86 additions and 8 deletions
|
|
@ -67,7 +67,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PLATFORM_WIN32
|
#ifdef PLATFORM_WIN32
|
||||||
int GetProcessHandle() const { return hProcess; }
|
HANDLE GetProcessHandle() const { return hProcess; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LocalProcess& ConvertCharset(bool b = true) { convertcharset = b; return *this; }
|
LocalProcess& ConvertCharset(bool b = true) { convertcharset = b; return *this; }
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,23 @@ TextCompareCtrl::TextCompareCtrl()
|
||||||
gutter_width = 0;
|
gutter_width = 0;
|
||||||
gutter_bg = Color(151, 190, 239);
|
gutter_bg = Color(151, 190, 239);
|
||||||
gutter_fg = SGreen;
|
gutter_fg = SGreen;
|
||||||
|
cursor = anchor = Null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextCompareCtrl::DoSelection(int y, bool shift)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextCompareCtrl::LeftDown(Point pt, dword keyflags)
|
void TextCompareCtrl::LeftDown(Point pt, dword keyflags)
|
||||||
|
|
@ -33,21 +50,51 @@ void TextCompareCtrl::LeftDown(Point pt, dword keyflags)
|
||||||
int page_lines = sz.cy / letter.cy;
|
int page_lines = sz.cy / letter.cy;
|
||||||
scroll.SetY(line - page_lines / 2);
|
scroll.SetY(line - page_lines / 2);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
DoSelection(pt.y, keyflags & K_SHIFT);
|
||||||
|
SetCapture();
|
||||||
|
}
|
||||||
SetWantFocus();
|
SetWantFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextCompareCtrl::MouseMove(Point pt, dword)
|
||||||
|
{
|
||||||
|
if(HasCapture())
|
||||||
|
DoSelection(pt.y, true);
|
||||||
|
}
|
||||||
|
|
||||||
void TextCompareCtrl::LeftUp(Point pt, dword keyflags)
|
void TextCompareCtrl::LeftUp(Point pt, dword keyflags)
|
||||||
{
|
{
|
||||||
ReleaseCapture();
|
ReleaseCapture();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextCompareCtrl::MouseMove(Point pt, dword keyflags)
|
void TextCompareCtrl::Copy()
|
||||||
{
|
{
|
||||||
if(HasCapture()) {
|
int sell, selh;
|
||||||
LeftDown(pt, keyflags);
|
if(GetSelection(sell, selh)) {
|
||||||
|
String clip;
|
||||||
|
for(int i = 0; i < lines.GetCount(); i++) {
|
||||||
|
const Line& l = lines[i];
|
||||||
|
if(l.number >= sell && l.number <= selh) {
|
||||||
|
clip << l.text;
|
||||||
|
#ifdef PLATFORM_WIN32
|
||||||
|
clip << "\r\n";
|
||||||
|
#else
|
||||||
|
clip << "\n";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ClearClipboard();
|
||||||
|
AppendClipboardText(clip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextCompareCtrl::RightDown(Point p, dword keyflags)
|
||||||
|
{
|
||||||
|
MenuBar b;
|
||||||
|
b.Add(cursor != anchor, t_("Copy"), CtrlImg::copy(), THISBACK(Copy)).Key(K_CTRL_C);
|
||||||
|
b.Execute();
|
||||||
|
}
|
||||||
|
|
||||||
bool TextCompareCtrl::Key(dword key, int repcnt)
|
bool TextCompareCtrl::Key(dword key, int repcnt)
|
||||||
{
|
{
|
||||||
|
|
@ -65,6 +112,9 @@ bool TextCompareCtrl::Key(dword key, int repcnt)
|
||||||
case K_END: newpos.x = maxwidth - page.x; break;
|
case K_END: newpos.x = maxwidth - page.x; break;
|
||||||
case K_CTRL_HOME: newpos.y = 0; break;
|
case K_CTRL_HOME: newpos.y = 0; break;
|
||||||
case K_CTRL_END: newpos.y = lines.GetCount() - page.y; break;
|
case K_CTRL_END: newpos.y = lines.GetCount() - page.y; break;
|
||||||
|
case K_CTRL_C:
|
||||||
|
Copy();
|
||||||
|
break;
|
||||||
case K_F3: {
|
case K_F3: {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
int i = max(pos.y + 2, 0);
|
int i = max(pos.y + 2, 0);
|
||||||
|
|
@ -153,11 +203,19 @@ void TextCompareCtrl::Paint(Draw& draw)
|
||||||
draw.DrawText(0, y + number_yshift, FormatInt(l.number), number_font, l.color);
|
draw.DrawText(0, y + number_yshift, FormatInt(l.number), number_font, l.color);
|
||||||
}
|
}
|
||||||
draw.Clip(number_width, 0, sz.cx - gutter_width - number_width, sz.cy);
|
draw.Clip(number_width, 0, sz.cx - gutter_width - number_width, sz.cy);
|
||||||
|
int sell, selh;
|
||||||
|
GetSelection(sell, selh);
|
||||||
for(int i = first_line; i <= last_line; i++) {
|
for(int i = first_line; i <= last_line; i++) {
|
||||||
const Line& l = lines[i];
|
const Line& l = lines[i];
|
||||||
int y = i * letter.cy - offset.cy;
|
int y = i * letter.cy - offset.cy;
|
||||||
draw.DrawRect(0, y, sz.cx, letter.cy, SWhite());
|
Color ink = l.color;
|
||||||
draw.DrawText(number_width - offset.cx, y, ExpandTabs(l.text), l.level == 1 ? ifont : font, l.color);
|
Color paper = SColorPaper();
|
||||||
|
if(!IsNull(l.number) && l.number >= sell && l.number <= selh) {
|
||||||
|
ink = SColorHighlightText;
|
||||||
|
paper = SColorHighlight;
|
||||||
|
}
|
||||||
|
draw.DrawRect(0, y, sz.cx, letter.cy, paper);
|
||||||
|
draw.DrawText(number_width - offset.cx, y, ExpandTabs(l.text), l.level == 1 ? ifont : font, ink);
|
||||||
}
|
}
|
||||||
int lcy = lcnt * letter.cy - offset.cy;
|
int lcy = lcnt * letter.cy - offset.cy;
|
||||||
draw.DrawRect(0, lcy, sz.cx, sz.cy - lcy, SGray());
|
draw.DrawRect(0, lcy, sz.cx, sz.cy - lcy, SGray());
|
||||||
|
|
@ -258,6 +316,17 @@ int TextCompareCtrl::MeasureLength(const char *text) const
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TextCompareCtrl::GetSelection(int& l, int& h)
|
||||||
|
{
|
||||||
|
if(IsNull(cursor)) {
|
||||||
|
l = h = -1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
l = min(cursor, anchor);
|
||||||
|
h = max(cursor, anchor);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String TextCompareCtrl::ExpandTabs(const char *text) const
|
String TextCompareCtrl::ExpandTabs(const char *text) const
|
||||||
{
|
{
|
||||||
String out;
|
String out;
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ public:
|
||||||
virtual void MouseMove(Point pt, dword keyflags);
|
virtual void MouseMove(Point pt, dword keyflags);
|
||||||
virtual void LeftDown(Point pt, dword keyflags);
|
virtual void LeftDown(Point pt, dword keyflags);
|
||||||
virtual void LeftUp(Point pt, dword keyflags);
|
virtual void LeftUp(Point pt, dword keyflags);
|
||||||
|
virtual void RightDown(Point p, dword keyflags);
|
||||||
virtual bool Key(dword key, int repcnt);
|
virtual bool Key(dword key, int repcnt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -40,6 +41,9 @@ private:
|
||||||
void UpdateWidth();
|
void UpdateWidth();
|
||||||
String ExpandTabs(const char *line) const;
|
String ExpandTabs(const char *line) const;
|
||||||
int MeasureLength(const char *line) const;
|
int MeasureLength(const char *line) const;
|
||||||
|
bool GetSelection(int& l, int& h);
|
||||||
|
void DoSelection(int y, bool shift);
|
||||||
|
void Copy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Line {
|
struct Line {
|
||||||
|
|
@ -62,6 +66,8 @@ private:
|
||||||
int number_width;
|
int number_width;
|
||||||
int number_yshift;
|
int number_yshift;
|
||||||
int gutter_width;
|
int gutter_width;
|
||||||
|
int cursor;
|
||||||
|
int anchor;
|
||||||
|
|
||||||
typedef TextCompareCtrl CLASSNAME;
|
typedef TextCompareCtrl CLASSNAME;
|
||||||
|
|
||||||
|
|
@ -99,6 +105,9 @@ public:
|
||||||
int GetSb() const { return scroll.Get().y; }
|
int GetSb() const { return scroll.Get().y; }
|
||||||
void SetSb(int y) { scroll.Set(0, y); }
|
void SetSb(int y) { scroll.Set(0, y); }
|
||||||
|
|
||||||
|
void ClearSelection() { cursor = Null; Refresh(); }
|
||||||
|
void SetSelection(int l, int h) { cursor = l; anchor = h; }
|
||||||
|
|
||||||
Callback ScrollWhen(TextCompareCtrl& pair) { return THISBACK1(PairScroll, &pair); }
|
Callback ScrollWhen(TextCompareCtrl& pair) { return THISBACK1(PairScroll, &pair); }
|
||||||
|
|
||||||
TextCompareCtrl();
|
TextCompareCtrl();
|
||||||
|
|
|
||||||
|
|
@ -168,9 +168,9 @@ bool Gdb_MI2::InterruptDebugger(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PLATFORM_POSIX
|
|
||||||
void Gdb_MI2::AsyncBrk()
|
void Gdb_MI2::AsyncBrk()
|
||||||
{
|
{
|
||||||
|
#ifdef PLATFORM_POSIX
|
||||||
// data must be refreshed
|
// data must be refreshed
|
||||||
dataSynced = false;
|
dataSynced = false;
|
||||||
|
|
||||||
|
|
@ -187,8 +187,8 @@ void Gdb_MI2::AsyncBrk()
|
||||||
if(stopped)
|
if(stopped)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Gdb_MI2::Stop()
|
void Gdb_MI2::Stop()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue