Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Windows
pEp for Outlook
Commits
3545f8c3
Commit
3545f8c3
authored
Sep 20, 2021
by
Thomas
Browse files
Don't wrap text in the diff view
parent
6817211a
Changes
5
Hide whitespace changes
Inline
Side-by-side
UI/ViewModels/FormControlPatchViewModel.cs
View file @
3545f8c3
using
pEp.DPE
;
using
pEp.DPE
;
using
System.Windows.Documents
;
using
System.Windows.Documents
;
using
System.Windows.Media
;
namespace
pEp.UI.ViewModels
namespace
pEp.UI.ViewModels
{
{
...
@@ -8,7 +7,7 @@ namespace pEp.UI.ViewModels
...
@@ -8,7 +7,7 @@ namespace pEp.UI.ViewModels
{
{
#
region
Fields
#
region
Fields
private
Patch
patch
;
private
readonly
Patch
patch
;
#
endregion
#
endregion
...
@@ -48,7 +47,7 @@ namespace pEp.UI.ViewModels
...
@@ -48,7 +47,7 @@ namespace pEp.UI.ViewModels
/// <summary>
/// <summary>
/// Gets the diff of this patch as formatted flow document.
/// Gets the diff of this patch as formatted flow document.
/// </summary>
/// </summary>
public
FlowDocument
DisplayDiff
{
get
;
}
public
FlowDocument
DisplayDiff
=>
PatchDialogViewModel
.
FormatDiff
(
this
.
Diff
);
/// <summary>
/// <summary>
/// The explanation shown in the UI regarding this patch.
/// The explanation shown in the UI regarding this patch.
...
@@ -132,59 +131,12 @@ namespace pEp.UI.ViewModels
...
@@ -132,59 +131,12 @@ namespace pEp.UI.ViewModels
this
.
Explanation
=
"New configuration changes pending approval"
;
this
.
Explanation
=
"New configuration changes pending approval"
;
this
.
IsRejectButtonVisible
=
true
;
this
.
IsRejectButtonVisible
=
true
;
this
.
OKButtonText
=
"Support"
;
this
.
OKButtonText
=
"Support"
;
this
.
DisplayDiff
=
this
.
FormatDiff
();
}
}
#
endregion
#
endregion
#
region
Methods
#
region
Methods
/// <summary>
/// Formats the diff displaying colors of changes.
/// </summary>
/// <returns>The formatted diff or null if no diff is available.</returns>
private
FlowDocument
FormatDiff
()
{
if
(
string
.
IsNullOrEmpty
(
this
.
Diff
))
{
return
null
;
}
FlowDocument
document
=
new
FlowDocument
{
FontFamily
=
new
FontFamily
(
"Courier New"
),
FontSize
=
12.0
,
Background
=
Brushes
.
White
};
string
[]
lines
=
this
.
Diff
?.
Replace
(
"\r\n"
,
"\n"
)?.
Split
(
'\n'
)
??
new
string
[]
{
};
foreach
(
string
line
in
lines
)
{
Paragraph
paragraph
=
new
Paragraph
(
new
Run
(
line
))
{
Margin
=
new
System
.
Windows
.
Thickness
(
1
),
LineHeight
=
14.0
};
if
(
line
.
StartsWith
(
"-"
))
{
paragraph
.
Background
=
Globals
.
ResourceDict
[
"BrushRedBackground"
]
as
Brush
;
}
else
if
(
line
.
StartsWith
(
"+"
))
{
paragraph
.
Background
=
Globals
.
ResourceDict
[
"BrushGreenBackground"
]
as
Brush
;
}
else
if
(
line
.
StartsWith
(
"@@"
))
{
paragraph
.
Background
=
Brushes
.
LightGray
;
}
document
.
Blocks
.
Add
(
paragraph
);
}
return
document
;
}
/// <summary>
/// <summary>
/// Rejects this patch.
/// Rejects this patch.
/// </summary>
/// </summary>
...
...
UI/ViewModels/PatchDialogViewModel.cs
View file @
3545f8c3
...
@@ -10,6 +10,7 @@ using System.Diagnostics;
...
@@ -10,6 +10,7 @@ using System.Diagnostics;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Linq
;
using
System.Windows
;
using
System.Windows
;
using
System.Windows.Controls
;
using
System.Windows.Documents
;
using
System.Windows.Documents
;
using
System.Windows.Media
;
using
System.Windows.Media
;
...
@@ -522,53 +523,6 @@ namespace pEp.UI.ViewModels
...
@@ -522,53 +523,6 @@ namespace pEp.UI.ViewModels
Log
.
Error
(
$"EditFileAndCreateDiff: Error reading file content from
{
fileName
}
:
{
ex
}
"
);
Log
.
Error
(
$"EditFileAndCreateDiff: Error reading file content from
{
fileName
}
:
{
ex
}
"
);
}
}
}
}
/// <summary>
/// Formats the diff displaying colors of changes.
/// </summary>
/// <returns>The formatted diff or null if no diff is available.</returns>
private
FlowDocument
FormatDiff
(
string
diff
)
{
if
(
string
.
IsNullOrEmpty
(
diff
))
{
return
null
;
}
FlowDocument
document
=
new
FlowDocument
{
FontFamily
=
new
FontFamily
(
"Courier New"
),
FontSize
=
12.0
,
Background
=
Brushes
.
White
,
};
string
[]
lines
=
diff
?.
Replace
(
"\r\n"
,
"\n"
)?.
Split
(
'\n'
)
??
new
string
[]
{
};
foreach
(
string
line
in
lines
)
{
Paragraph
paragraph
=
new
Paragraph
(
new
Run
(
line
))
{
Margin
=
new
System
.
Windows
.
Thickness
(
1
),
LineHeight
=
14.0
};
if
(
line
.
StartsWith
(
"-"
))
{
paragraph
.
Background
=
Globals
.
ResourceDict
[
"BrushRedBackground"
]
as
Brush
;
}
else
if
(
line
.
StartsWith
(
"+"
))
{
paragraph
.
Background
=
Globals
.
ResourceDict
[
"BrushGreenBackground"
]
as
Brush
;
}
else
if
(
line
.
StartsWith
(
"@@"
))
{
paragraph
.
Background
=
Brushes
.
LightGray
;
}
document
.
Blocks
.
Add
(
paragraph
);
}
return
document
;
}
/// <summary>
/// <summary>
/// Gets a common root URI from all selected files in the dialog.
/// Gets a common root URI from all selected files in the dialog.
/// </summary>
/// </summary>
...
@@ -630,7 +584,7 @@ namespace pEp.UI.ViewModels
...
@@ -630,7 +584,7 @@ namespace pEp.UI.ViewModels
/// </summary>
/// </summary>
private
void
UpdateVisibleDiff
()
private
void
UpdateVisibleDiff
()
{
{
this
.
VisibleDiff
=
this
.
FormatDiff
(
this
.
SelectedFile
?.
Diff
);
this
.
VisibleDiff
=
PatchDialogViewModel
.
FormatDiff
(
this
.
SelectedFile
?.
Diff
);
}
}
/// <summary>
/// <summary>
...
@@ -645,5 +599,73 @@ namespace pEp.UI.ViewModels
...
@@ -645,5 +599,73 @@ namespace pEp.UI.ViewModels
}
}
#
endregion
#
endregion
#
region
Static
methods
/// <summary>
/// Formats the diff displaying colors of changes.
/// </summary>
/// <returns>The formatted diff or null if no diff is available.</returns>
public
static
FlowDocument
FormatDiff
(
string
diff
)
{
if
(
string
.
IsNullOrEmpty
(
diff
))
{
return
null
;
}
// Initialize the document with zero width to set the real width later
FlowDocument
document
=
new
FlowDocument
{
Background
=
Brushes
.
White
,
PageWidth
=
0
};
string
[]
lines
=
diff
.
Replace
(
"\r\n"
,
"\n"
)?.
Split
(
'\n'
)
??
new
string
[]
{
};
foreach
(
string
line
in
lines
)
{
Paragraph
paragraph
=
new
Paragraph
()
{
Margin
=
new
Thickness
(
1
),
};
TextBlock
textBlock
=
new
TextBlock
()
{
Text
=
line
,
FontFamily
=
new
FontFamily
(
"Courier New"
),
LineHeight
=
14.0
,
FontSize
=
12.0
,
TextWrapping
=
TextWrapping
.
NoWrap
};
// Set the document width to the biggest textblock width plus some margin
// to account for padding inside the scroll viewer
textBlock
.
Measure
(
new
Size
(
double
.
PositiveInfinity
,
double
.
PositiveInfinity
));
if
(
textBlock
.
DesiredSize
.
Width
>
document
.
PageWidth
)
{
document
.
PageWidth
=
textBlock
.
DesiredSize
.
Width
+
50
;
}
paragraph
.
Inlines
.
Add
(
textBlock
);
// Color the added and removed lines accordingly
if
(
line
.
StartsWith
(
"-"
))
{
paragraph
.
Background
=
Globals
.
ResourceDict
[
"BrushRedBackground"
]
as
Brush
;
}
else
if
(
line
.
StartsWith
(
"+"
))
{
paragraph
.
Background
=
Globals
.
ResourceDict
[
"BrushGreenBackground"
]
as
Brush
;
}
else
if
(
line
.
StartsWith
(
"@@"
))
{
paragraph
.
Background
=
Brushes
.
LightGray
;
}
document
.
Blocks
.
Add
(
paragraph
);
}
return
document
;
}
#
endregion
}
}
}
}
UI/Views/FormControlPatchView.xaml
View file @
3545f8c3
...
@@ -72,6 +72,7 @@
...
@@ -72,6 +72,7 @@
<FlowDocumentScrollViewer Grid.Column="1"
<FlowDocumentScrollViewer Grid.Column="1"
Grid.ColumnSpan="2"
Grid.ColumnSpan="2"
Grid.Row="3"
Grid.Row="3"
HorizontalScrollBarVisibility="Auto"
BorderBrush="Black"
BorderBrush="Black"
BorderThickness="1"
BorderThickness="1"
Margin="5,10,10,10"
Margin="5,10,10,10"
...
...
UI/Views/FormControlPatchView.xaml.cs
View file @
3545f8c3
using
System
;
using
System.Windows.Controls
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows
;
using
System.Windows.Controls
;
using
System.Windows.Data
;
using
System.Windows.Documents
;
using
System.Windows.Input
;
using
System.Windows.Media
;
using
System.Windows.Media.Imaging
;
using
System.Windows.Navigation
;
using
System.Windows.Shapes
;
namespace
pEp.UI.Views
namespace
pEp.UI.Views
{
{
...
...
UI/Views/PatchDialogView.xaml
View file @
3545f8c3
...
@@ -72,6 +72,7 @@
...
@@ -72,6 +72,7 @@
BorderBrush="Black"
BorderBrush="Black"
BorderThickness="1"
BorderThickness="1"
Margin="5,10,10,10"
Margin="5,10,10,10"
HorizontalScrollBarVisibility="Auto"
Document="{Binding VisibleDiff}"/>
Document="{Binding VisibleDiff}"/>
<ui:TextBoxWithPlaceholder Grid.Column="0"
<ui:TextBoxWithPlaceholder Grid.Column="0"
Grid.ColumnSpan="3"
Grid.ColumnSpan="3"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment