mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-24 22:02:44 -06:00
ide: Diff ignore indent refactored to support all comparison modes
This commit is contained in:
parent
70657d2923
commit
fd0edd3076
6 changed files with 70 additions and 47 deletions
|
|
@ -21,6 +21,8 @@ IMAGE_ID(CopyLeft)
|
|||
IMAGE_ID(CopyLeft__UHD)
|
||||
IMAGE_ID(CopyRight)
|
||||
IMAGE_ID(CopyRight__UHD)
|
||||
IMAGE_ID(Indent__UHD)
|
||||
IMAGE_ID(Indent)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,237,219,59,82,195,48,20,133,97,53,52,84,233,104,50,147,150,37,164,163,101,3,212,176,161,172,33,125,54,1)
|
||||
|
|
@ -237,3 +239,17 @@ IMAGE_DATA(143,254,249,209,63,63,250,231,71,255,252,232,175,255,127,157,74,233,1
|
|||
IMAGE_DATA(44,233,117,29,97,232,167,125,150,246,89,218,103,105,159,165,125,150,246,89,218,103,105,159,165,125,150,246,89,218,103,105)
|
||||
IMAGE_DATA(159,165,125,150,246,89,218,103,105,159,165,125,150,246,0,0,0,0,0,0,0,0,64,159,79,13,244,113,151,0,0,0)
|
||||
IMAGE_END_DATA(288, 2)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,237,208,91,110,194,64,20,68,65,214,147,85,177,6,246,47,37,255,17,52,126,76,27,143,169,146,230,183,237,123)
|
||||
IMAGE_DATA(126,238,183,251,13,0,0,0,0,0,0,0,0,96,54,143,199,227,183,189,255,236,53,191,57,147,118,15,253,179,118,19)
|
||||
IMAGE_DATA(253,179,118,23,253,179,118,27,253,179,118,31,253,179,87,125,70,53,210,63,75,253,71,116,210,63,123,215,127,111,43,253)
|
||||
IMAGE_DATA(179,37,253,247,244,210,63,91,218,127,107,51,253,179,53,253,183,116,211,63,91,219,127,109,59,253,179,45,253,215,244,211)
|
||||
IMAGE_DATA(63,219,218,127,105,67,253,179,61,253,151,116,212,63,219,219,255,93,75,253,179,17,253,83,79,253,179,81,253,95,53,213)
|
||||
IMAGE_DATA(63,27,217,255,89,87,253,179,209,253,255,183,29,213,191,241,159,87,126,250,127,254,233,127,222,167,191,254,87,127,169,155)
|
||||
IMAGE_DATA(254,253,246,35,251,95,85,179,125,218,255,212,189,103,211,108,159,246,63,113,235,25,53,219,167,253,163,239,60,171,102,251)
|
||||
IMAGE_DATA(180,127,228,141,103,214,108,159,246,143,186,239,236,154,237,211,254,17,183,205,160,217,62,237,183,239,154,69,179,125,218,111)
|
||||
IMAGE_DATA(222,52,147,102,251,180,223,186,103,54,205,246,105,191,113,203,140,154,237,211,254,232,59,102,213,108,159,246,71,222,48,179)
|
||||
IMAGE_DATA(102,251,180,63,234,255,103,215,108,159,246,71,252,251,21,52,219,167,253,17,219,87,208,238,163,127,214,110,163,127,214,238)
|
||||
IMAGE_DATA(162,127,214,110,162,127,214,238,161,127,214,110,161,63,0,0,0,0,0,0,0,0,124,143,63,152,66,11,252,0,0,0)
|
||||
IMAGE_END_DATA(352, 1)
|
||||
|
|
|
|||
|
|
@ -9,8 +9,14 @@ namespace Upp {
|
|||
TextDiffCtrl::TextDiffCtrl()
|
||||
{
|
||||
left.SetLeft();
|
||||
indent.SetImage(DiffImg::Indent());
|
||||
indent.Tip("Compare indentation");
|
||||
indent <<= true;
|
||||
next.SetImage(DiffImg::Next());
|
||||
next.Tip("Next difference");
|
||||
prev.SetImage(DiffImg::Prev());
|
||||
prev.Tip("Previous difference");
|
||||
left.scroll.y.AddFrame(indent);
|
||||
left.scroll.y.AddFrame(prev);
|
||||
left.scroll.y.AddFrame(next);
|
||||
next << [=] { FindDiff(true); };
|
||||
|
|
@ -70,7 +76,7 @@ static bool SmallDiff(const char *s1, const char *s2)
|
|||
|
||||
void TextDiffCtrl::Set(Stream& l, Stream& r)
|
||||
{
|
||||
bool ignore_indent = DirDiffDlg::GetIgnoreIndentation(this);
|
||||
bool ignore_indent = !indent;
|
||||
Vector<String> ll = GetLineMap(l, ignore_indent);
|
||||
Vector<String> rl = GetLineMap(r, ignore_indent);
|
||||
Array<TextSection> sections = CompareLineMaps(ll, rl);
|
||||
|
|
@ -331,6 +337,7 @@ FileDiff::FileDiff(FileSel& fs_)
|
|||
Icon(DiffImg::Diff());
|
||||
diff.InsertFrameRight(r);
|
||||
r <<= THISBACK(Open);
|
||||
diff.indent << [=] { Finish(); };
|
||||
}
|
||||
|
||||
void FileDiff::Set(const String& f)
|
||||
|
|
|
|||
|
|
@ -11,12 +11,11 @@ DirDiffDlg::DirDiffDlg()
|
|||
|
||||
hidden.SetLabel(t_("Hidden"));
|
||||
split_lines.SetLabel(t_("Split long lines"));
|
||||
ignore_indentation.SetLabel(t_("Ignore indentation"));
|
||||
|
||||
|
||||
added.SetColor(Green()).SetLabel(t_("New"));
|
||||
modified.SetLabel(t_("Modified"));
|
||||
removed.SetColor(Red()).SetLabel(t_("Removed"));
|
||||
|
||||
|
||||
recent <<= Null;
|
||||
recent.Add(Null, "All");
|
||||
recent.Add(1, "1 Day");
|
||||
|
|
@ -27,22 +26,21 @@ DirDiffDlg::DirDiffDlg()
|
|||
recent.Add(60, "3 Months");
|
||||
recent.Add(180, "6 Months");
|
||||
recent.Add(365, "1 Year");
|
||||
|
||||
|
||||
compare.SetLabel(t_("Compare"));
|
||||
int bcy = max(cy, compare.GetStdSize().cy);
|
||||
|
||||
|
||||
files_pane.Add(dir1.TopPos(0, cy).HSizePos());
|
||||
files_pane.Add(dir2.TopPos(cy + div, cy).HSizePos());
|
||||
files_pane.Add(hidden.TopPos(2 * cy + 2 * div, bcy).LeftPos(0, bcx));
|
||||
files_pane.Add(split_lines.TopPos(2 * cy + 2 * div, bcy).LeftPosZ(55, 100));
|
||||
files_pane.Add(ignore_indentation.TopPos(2 * cy + 2 * div, bcy).LeftPosZ(152, 120));
|
||||
|
||||
files_pane.Add(split_lines.TopPos(2 * cy + 2 * div, bcy).LeftPosZ(52, 100));
|
||||
|
||||
files_pane.Add(added.TopPos(3 * cy + 3 * div, bcy).LeftPosZ(2, 60));
|
||||
files_pane.Add(modified.TopPos(3 * cy + 3 * div, bcy).LeftPosZ(52, 70));
|
||||
files_pane.Add(removed.TopPos(3 * cy + 3 * div, bcy).LeftPosZ(128, 80));
|
||||
files_pane.Add(recent.TopPos(3 * cy + 3 * div, bcy).RightPos(0, bcx + Zx(8)));
|
||||
files_pane.Add(extension.TopPos(3 * cy + 3 * div, bcy).RightPos(bcx + Zx(8) + DPI(8), bcx));
|
||||
|
||||
|
||||
removed = 1;
|
||||
added = 1;
|
||||
modified = 1;
|
||||
|
|
@ -50,7 +48,7 @@ DirDiffDlg::DirDiffDlg()
|
|||
clearFind.SetLabel("X");
|
||||
clearFind.RightPosZ(1, 16).VSizePosZ(1, 1);
|
||||
find.AddChild(&clearFind);
|
||||
|
||||
|
||||
files_pane.Add(compare.TopPos(2 * cy + 2 * div, bcy).RightPos(0, bcx));
|
||||
files_pane.Add(files.VSizePos(3 * cy + bcy + 4 * div, Zy(24)).HSizePos());
|
||||
files_pane.Add(find.BottomPosZ(4, 19).HSizePosZ());
|
||||
|
|
@ -59,19 +57,19 @@ DirDiffDlg::DirDiffDlg()
|
|||
files_diff.Set(files_pane, diff);
|
||||
files_diff.SetPos(2000);
|
||||
files_diff.SetMinPixels(0, Zx(256));
|
||||
|
||||
|
||||
Sizeable().Zoomable();
|
||||
|
||||
|
||||
seldir1.Attach(dir1);
|
||||
seldir2.Attach(dir2);
|
||||
|
||||
|
||||
seldir1.Title("First directory to compare");
|
||||
seldir2.Title("Second directory to compare");
|
||||
|
||||
|
||||
compare <<= THISBACK(Compare);
|
||||
dir1 <<= THISBACK(ClearFiles);
|
||||
dir2 <<= THISBACK(ClearFiles);
|
||||
|
||||
|
||||
modified << [=] { ShowResult(); };
|
||||
removed << [=] { ShowResult(); };
|
||||
added << [=] { ShowResult(); };
|
||||
|
|
@ -79,7 +77,7 @@ DirDiffDlg::DirDiffDlg()
|
|||
extension << [=] { ShowResult(); };
|
||||
recent << [=] { ShowResult(); };
|
||||
clearFind << [=] { find.Clear(); ShowResult();};
|
||||
|
||||
|
||||
files.WhenSel = THISBACK(File);
|
||||
|
||||
diff.InsertFrameLeft(left);
|
||||
|
|
@ -98,7 +96,7 @@ DirDiffDlg::DirDiffDlg()
|
|||
right.Add(copyleft.VSizePos().LeftPosZ(0, 70));
|
||||
right.Add(removeright.VSizePos().LeftPosZ(74, 70));
|
||||
right.Add(revertright.VSizePos().LeftPosZ(148, 70));
|
||||
|
||||
|
||||
auto SetupCopy = [=](Button& copy, bool left) {
|
||||
copy.SetImage(left ? DiffImg::CopyLeft() : DiffImg::CopyRight());
|
||||
copy.SetLabel("Copy");
|
||||
|
|
@ -106,7 +104,7 @@ DirDiffDlg::DirDiffDlg()
|
|||
copy.Disable();
|
||||
copy << [=] { Copy(left); };
|
||||
};
|
||||
|
||||
|
||||
SetupCopy(copyleft, true);
|
||||
SetupCopy(copyright, false);
|
||||
|
||||
|
|
@ -124,39 +122,39 @@ DirDiffDlg::DirDiffDlg()
|
|||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
SetupRevert(revertleft, &dir1);
|
||||
SetupRevert(revertright, &dir2);
|
||||
|
||||
|
||||
auto SetupRemove = [=](Button& remove, TextCompareCtrl *text, EditString *dir)
|
||||
{
|
||||
remove.SetLabel("Remove");
|
||||
remove.Tip("F8");
|
||||
remove.SetImage(CtrlImg::remove());
|
||||
remove.Disable();
|
||||
|
||||
|
||||
remove << [=] {
|
||||
String path = AppendFileName(~*dir, files.GetCurrentName());
|
||||
Backup(path);
|
||||
SaveFile(path, text->RemoveSelected(HasCrs(path)));
|
||||
Refresh();
|
||||
};
|
||||
|
||||
|
||||
text->WhenSel << [=, &remove] {
|
||||
remove.Enable(text->IsSelection());
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
SetupRemove(removeleft, &diff.left, &dir1);
|
||||
SetupRemove(removeright, &diff.right, &dir2);
|
||||
|
||||
|
||||
split_lines << [=] { File(); };
|
||||
ignore_indentation << [=] { File(); };
|
||||
diff.indent << [=] { File(); };
|
||||
|
||||
Icon(DiffImg::DirDiff());
|
||||
|
||||
WhenIcon = [](const char *path) -> Image { return NativePathIcon(path); };
|
||||
|
||||
|
||||
Title("Compare directories");
|
||||
};
|
||||
|
||||
|
|
@ -194,7 +192,7 @@ bool DirDiffDlg::FileEqual(const String& f1, const String& f2, int& kind)
|
|||
}
|
||||
else
|
||||
kind = in1 ? DELETED_FILE : NEW_FILE;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -209,12 +207,12 @@ void DirDiffDlg::Compare()
|
|||
|
||||
removeleft.Disable();
|
||||
removeright.Disable();
|
||||
|
||||
|
||||
files.Clear();
|
||||
SortByKey(fs);
|
||||
Progress pi(t_("Comparing.."));
|
||||
pi.SetTotal(fs.GetCount());
|
||||
|
||||
|
||||
list.Clear();
|
||||
Index<String> exts;
|
||||
for(int i = 0; i < fs.GetCount(); i++) {
|
||||
|
|
@ -237,13 +235,13 @@ void DirDiffDlg::Compare()
|
|||
m.kind = kind;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension.Clear();
|
||||
extension.Add(Null, "*.*");
|
||||
for(int ii : GetSortOrder(exts))
|
||||
extension.Add(exts[ii], "*" + exts[ii]);
|
||||
extension.Enable();
|
||||
|
||||
|
||||
ShowResult();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -193,6 +193,7 @@ public:
|
|||
struct TextDiffCtrl : public Splitter {
|
||||
TextCompareCtrl left;
|
||||
TextCompareCtrl right;
|
||||
FrameTop<ButtonOption> indent;
|
||||
FrameTop<Button> next, prev;
|
||||
int cl = 0; // to lock WhenCursor -> SetLine
|
||||
|
||||
|
|
@ -292,7 +293,6 @@ protected:
|
|||
WithDropChoice<EditString> dir2;
|
||||
Option hidden;
|
||||
Option split_lines;
|
||||
Option ignore_indentation;
|
||||
Button compare;
|
||||
|
||||
Option removed, added, modified;
|
||||
|
|
@ -359,7 +359,7 @@ public:
|
|||
int GetLMid() const { return lmid; }
|
||||
int GetRMid() const { return rmid; }
|
||||
|
||||
static bool GetIgnoreIndentation(Ctrl *q) { auto *p = q->GetAscendant<DirDiffDlg>(); return p && p->ignore_indentation; }
|
||||
static bool GetIgnoreIndentation(Ctrl *q) { auto *p = q->GetAscendant<DirDiffDlg>(); return p && !p->diff.indent; }
|
||||
|
||||
DirDiffDlg();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ DirRepoDiffDlg::DirRepoDiffDlg()
|
|||
for(String s : git)
|
||||
l.Add(s, "git " + s);
|
||||
AddSelectGit(l);
|
||||
|
||||
|
||||
branch[i] << [=] { Revs(i); };
|
||||
};
|
||||
|
||||
|
|
@ -53,8 +53,7 @@ DirRepoDiffDlg::DirRepoDiffDlg()
|
|||
}
|
||||
|
||||
files_pane.Add(hidden.TopPos(y, bcy).LeftPos(0, bcx));
|
||||
files_pane.Add(split_lines.TopPos(y, bcy).LeftPosZ(55, 100));
|
||||
files_pane.Add(ignore_indentation.TopPos(y, bcy).LeftPosZ(152, 120));
|
||||
files_pane.Add(split_lines.TopPos(y, bcy).LeftPosZ(52, 100));
|
||||
files_pane.Add(compare.TopPos(y, bcy).RightPos(0, bcx));
|
||||
y += bcy + div;
|
||||
|
||||
|
|
@ -67,19 +66,19 @@ DirRepoDiffDlg::DirRepoDiffDlg()
|
|||
|
||||
files_pane.Add(files.VSizePos(y, Zy(24)).HSizePos());
|
||||
files_pane.Add(find.BottomPosZ(6, 19).HSizePosZ());
|
||||
|
||||
|
||||
extension.Disable();
|
||||
|
||||
Mode(0);
|
||||
Mode(1);
|
||||
|
||||
|
||||
compare ^= [=] { Compare(); };
|
||||
|
||||
|
||||
dir1 << [=] { SyncCompare(); };
|
||||
dir2 << [=] { SyncCompare(); };
|
||||
|
||||
|
||||
session_id = String() << Random() << Random() << Random() << Random();
|
||||
|
||||
|
||||
branch[0].SetDropLines(32);
|
||||
branch[1].SetDropLines(32);
|
||||
r[0].SetDropLines(32);
|
||||
|
|
@ -127,10 +126,10 @@ void DirRepoDiffDlg::Mode(int i)
|
|||
LoadBranches(branch[i], ~~dl);
|
||||
Revs(i);
|
||||
}
|
||||
|
||||
|
||||
ClearFiles();
|
||||
SyncCompare();
|
||||
|
||||
|
||||
editable_left = !IsGit(0);
|
||||
editable_right = !IsGit(1);
|
||||
}
|
||||
|
|
@ -175,4 +174,4 @@ void DirRepoDiffDlg::Compare()
|
|||
};
|
||||
if(Clone(0, dir1, lmid) && Clone(1, dir2, rmid))
|
||||
DirDiffDlg::Compare();
|
||||
}
|
||||
}
|
||||
|
|
@ -1114,8 +1114,11 @@ void Ide::EditorMenu(Bar& bar)
|
|||
"Compare with clipboard..", IdeImg::DiffClip(), [=]() {
|
||||
DiffDlg& dlg = CreateNewWindow<DiffDlg>();
|
||||
dlg.diff.left.RemoveFrame(dlg.p);
|
||||
dlg.diff.Set(ReadClipboardText(), editor.IsSelection() ? editor.GetSelection()
|
||||
: editor.Get());
|
||||
String left = ReadClipboardText();
|
||||
String right = editor.IsSelection() ? editor.GetSelection() : editor.Get();
|
||||
dlg.diff.Set(left, right);
|
||||
dlg.diff.indent <<= false;
|
||||
dlg.diff.indent << [=, &dlg] { dlg.diff.Set(left, right); };
|
||||
dlg.Title("Compare with clipboard");
|
||||
dlg.Icon(IdeImg::DiffClip());
|
||||
dlg.OpenMain();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue