Commit 820a7def authored by Thomas's avatar Thomas
Browse files

Allow for custom editors to modify patches and set background color if patch is not open anymore

parent 8eeab9ee
using pEp.DPE.Interfaces; using pEp.DPE.Interfaces;
using pEp.Extensions; using pEp.Extensions;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Outlook = Microsoft.Office.Interop.Outlook; using Outlook = Microsoft.Office.Interop.Outlook;
...@@ -12,7 +11,6 @@ namespace pEp.DPE ...@@ -12,7 +11,6 @@ namespace pEp.DPE
{ {
private static readonly string DPE_FOLDER = Path.Combine(Globals.PEPUserFolder, "DPE"); private static readonly string DPE_FOLDER = Path.Combine(Globals.PEPUserFolder, "DPE");
public static readonly string DPE_TEMP_LOCATION = Path.Combine(DistributedPolicyEngine.DPE_FOLDER, "temp"); public static readonly string DPE_TEMP_LOCATION = Path.Combine(DistributedPolicyEngine.DPE_FOLDER, "temp");
private const string PATCH_EXTENSION = ".patch";
private const string PATCH_MESSAGE_SUBJECT = "Configuration changes"; private const string PATCH_MESSAGE_SUBJECT = "Configuration changes";
public const string DPE_MESSAGE_CLASS = "IPM.Note.DPE"; public const string DPE_MESSAGE_CLASS = "IPM.Note.DPE";
...@@ -30,7 +28,7 @@ namespace pEp.DPE ...@@ -30,7 +28,7 @@ namespace pEp.DPE
} }
#region Event handlers #region Event handlers
/// <summary> /// <summary>
/// Event handler for when a patch has been accepted. /// Event handler for when a patch has been accepted.
/// </summary> /// </summary>
...@@ -90,7 +88,7 @@ namespace pEp.DPE ...@@ -90,7 +88,7 @@ namespace pEp.DPE
{ MapiProperty.PidTagMessageDeliveryTime, DateTime.UtcNow } { MapiProperty.PidTagMessageDeliveryTime, DateTime.UtcNow }
}); });
omi.SetMessageFlag(MapiPropertyValue.EnumPidTagMessageFlags.mfUnsent, false); omi.SetMessageFlag(MapiPropertyValue.EnumPidTagMessageFlags.mfUnsent, false);
// Move to inbox and set Received time // Move to inbox and set Received time
mi = omi.Move(Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)); mi = omi.Move(Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox));
mi.Save(); mi.Save();
......
...@@ -62,8 +62,9 @@ namespace pEp ...@@ -62,8 +62,9 @@ namespace pEp
public const string CULTURE_CODE_DEFAULT = "en"; public const string CULTURE_CODE_DEFAULT = "en";
public const bool DELETE_MIRROR_MESSAGES_DEFAULT = false; public const bool DELETE_MIRROR_MESSAGES_DEFAULT = false;
public const string DISCLAIMER_TEXT_DEFAULT = null; public const string DISCLAIMER_TEXT_DEFAULT = null;
public static readonly string DPE_WEB_CLIENT_URL_DEFAULT = "http://localhost:30457/pEpDPE/"; public const string DPE_EDITOR_PATH_DEFAULT = "Notepad.exe";
public static readonly string DPE_WEB_SERVER_URL_DEFAULT = "http://localhost:30456/pEpDPE/"; public const string DPE_WEB_CLIENT_URL_DEFAULT = "http://localhost:30457/pEpDPE/";
public const string DPE_WEB_SERVER_URL_DEFAULT = "http://localhost:30456/pEpDPE/";
public const bool ENABLE_NATIVE_METHODS_DEFAULT = true; public const bool ENABLE_NATIVE_METHODS_DEFAULT = true;
public const bool ENCRYPT_ACCOUNTS_BY_DEFAULT = true; public const bool ENCRYPT_ACCOUNTS_BY_DEFAULT = true;
public const bool HIDE_INTERNAL_MESSAGES_DEFAULT = true; public const bool HIDE_INTERNAL_MESSAGES_DEFAULT = true;
...@@ -172,6 +173,12 @@ namespace pEp ...@@ -172,6 +173,12 @@ namespace pEp
/// </summary> /// </summary>
public bool DeleteMirrorMessages { get; private set; } = PEPSettings.DELETE_MIRROR_MESSAGES_DEFAULT; public bool DeleteMirrorMessages { get; private set; } = PEPSettings.DELETE_MIRROR_MESSAGES_DEFAULT;
/// <summary>
/// Gets the path to the editor to use to edit config files.
/// Can only be set from the Registry.
/// </summary>
public string DPEEditorPath { get; private set; } = PEPSettings.DPE_EDITOR_PATH_DEFAULT;
/// <summary> /// <summary>
/// Gets the URL of the DPE Web client. /// Gets the URL of the DPE Web client.
/// </summary> /// </summary>
......
using pEp.DPE; using pEp.DPE;
using System; using System;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Media;
namespace pEp.UI.ViewModels namespace pEp.UI.ViewModels
{ {
...@@ -18,14 +19,21 @@ namespace pEp.UI.ViewModels ...@@ -18,14 +19,21 @@ namespace pEp.UI.ViewModels
private readonly Patch patch; private readonly Patch patch;
private PatchStatus _Status = PatchStatus.Open; private Brush _Background = Brushes.White;
private FlowDocument _DisplayDiff = null;
private DateTime? _EditDate = null; private DateTime? _EditDate = null;
private string _Explanation = null; private string _Explanation = null;
private PatchStatus _Status = PatchStatus.Open;
#endregion #endregion
#region Properties #region Properties
/// <summary>
/// Gets or sets the background.
/// </summary>
public Brush Background { get => this._Background; set => this.SetProperty(ref this._Background, value); }
/// <summary> /// <summary>
/// The commit message of the patch. /// The commit message of the patch.
/// </summary> /// </summary>
...@@ -58,9 +66,9 @@ namespace pEp.UI.ViewModels ...@@ -58,9 +66,9 @@ namespace pEp.UI.ViewModels
} }
/// <summary> /// <summary>
/// Gets the diff of this patch as formatted flow document. /// Gets or sets the diff of this patch as formatted flow document.
/// </summary> /// </summary>
public FlowDocument DisplayDiff => PatchDialogViewModel.FormatDiff(this.Diff); public FlowDocument DisplayDiff { get => this._DisplayDiff; set => this.SetProperty(ref this._DisplayDiff, value); }
/// <summary> /// <summary>
/// Gets or sets the last date the patch was edited. /// Gets or sets the last date the patch was edited.
...@@ -154,10 +162,9 @@ namespace pEp.UI.ViewModels ...@@ -154,10 +162,9 @@ namespace pEp.UI.ViewModels
this.EditDate = editDate; this.EditDate = editDate;
this.patch = patch; this.patch = patch;
this.Submitter = submitter; this.Submitter = submitter;
this.Status = status;
this.IsRejectButtonVisible = true; this.IsRejectButtonVisible = true;
this.OKButtonText = "Support"; this.OKButtonText = "Support";
this.SetExplanation(); this.UpdateView(status);
} }
#endregion #endregion
...@@ -171,9 +178,7 @@ namespace pEp.UI.ViewModels ...@@ -171,9 +178,7 @@ namespace pEp.UI.ViewModels
private void RejectPatch(object parameter) private void RejectPatch(object parameter)
{ {
Globals.ThisAddIn.DistributedPolicyEngine.Reject(this.patch, new PEPIdentity()); Globals.ThisAddIn.DistributedPolicyEngine.Reject(this.patch, new PEPIdentity());
this.Status = PatchStatus.Rejected; this.UpdateView(PatchStatus.Rejected);
this.EditDate = DateTime.UtcNow;
this.SetExplanation();
} }
/// <summary> /// <summary>
...@@ -212,9 +217,20 @@ namespace pEp.UI.ViewModels ...@@ -212,9 +217,20 @@ namespace pEp.UI.ViewModels
private void SupportPatch(object parameter) private void SupportPatch(object parameter)
{ {
Globals.ThisAddIn.DistributedPolicyEngine.Support(this.patch, new PEPIdentity()); Globals.ThisAddIn.DistributedPolicyEngine.Support(this.patch, new PEPIdentity());
this.Status = PatchStatus.Supported; this.UpdateView(PatchStatus.Supported);
}
/// <summary>
/// Updates the view according to a new patch status.
/// </summary>
/// <param name="patchStatus">The new patch status.</param>
private void UpdateView(PatchStatus patchStatus)
{
this.Status = patchStatus;
this.EditDate = DateTime.UtcNow; this.EditDate = DateTime.UtcNow;
this.SetExplanation(); this.SetExplanation();
this.DisplayDiff = PatchDialogViewModel.FormatDiff(this.Diff, this.Status == PatchStatus.Open);
this.Background = (patchStatus == PatchStatus.Open) ? Brushes.White : Brushes.WhiteSmoke;
} }
#endregion #endregion
......
...@@ -488,15 +488,20 @@ namespace pEp.UI.ViewModels ...@@ -488,15 +488,20 @@ namespace pEp.UI.ViewModels
File.Copy(fileName, originalFileName, true); File.Copy(fileName, originalFileName, true);
} }
// Open temp file in Notepad for the user to edit // Open temp file for the user to edit
using (Process modifyFileProcess = Process.Start(new ProcessStartInfo using (Process modifyFileProcess = Process.Start(new ProcessStartInfo
{ {
FileName = "Notepad.exe", FileName = Globals.ThisAddIn.Settings.DPEEditorPath,
Arguments = fileName, Arguments = fileName,
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true CreateNoWindow = true
})) }))
{ {
while (!modifyFileProcess.HasExited)
{
System.Threading.Thread.Sleep(200);
}
modifyFileProcess.WaitForExit(); modifyFileProcess.WaitForExit();
} }
...@@ -602,11 +607,14 @@ namespace pEp.UI.ViewModels ...@@ -602,11 +607,14 @@ namespace pEp.UI.ViewModels
#region Static methods #region Static methods
/// <summary> /// <summary>
/// Formats the diff displaying colors of changes. /// Formats the diff displaying colors of changes.
/// </summary> /// </summary>
/// <param name="diff">The diff to format.</param>
/// <param name="isOpen">Whether the patch is still open.</param>
/// <returns>The formatted diff or null if no diff is available.</returns> /// <returns>The formatted diff or null if no diff is available.</returns>
public static FlowDocument FormatDiff(string diff) public static FlowDocument FormatDiff(string diff, bool isOpen = true)
{ {
if (string.IsNullOrEmpty(diff)) if (string.IsNullOrEmpty(diff))
{ {
...@@ -616,7 +624,7 @@ namespace pEp.UI.ViewModels ...@@ -616,7 +624,7 @@ namespace pEp.UI.ViewModels
// Initialize the document with zero width to set the real width later // Initialize the document with zero width to set the real width later
FlowDocument document = new FlowDocument FlowDocument document = new FlowDocument
{ {
Background = Brushes.White, Background = isOpen ? Brushes.White : Brushes.WhiteSmoke,
PageWidth = 0 PageWidth = 0
}; };
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
mc:Ignorable="d" mc:Ignorable="d"
FontFamily="Segoe UI" FontFamily="Segoe UI"
FontSize="12" FontSize="12"
Background="{Binding Background}"
d:DataContext="{d:DesignInstance Type=vm:FormControlPatchViewModel}" d:DataContext="{d:DesignInstance Type=vm:FormControlPatchViewModel}"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources> <UserControl.Resources>
...@@ -27,7 +28,7 @@ ...@@ -27,7 +28,7 @@
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
...@@ -41,19 +42,19 @@ ...@@ -41,19 +42,19 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Grid.Column="0" <Label Grid.Column="0"
Grid.Row="0"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Grid.Row="0"
Content="{Binding Explanation}" Content="{Binding Explanation}"
FontWeight="Bold" FontWeight="Bold"
Margin="10,5"/> Margin="10,5"/>
<Label Grid.Column="0" <Label Grid.Column="0"
Grid.Row="1"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Grid.Row="1"
Content="{Binding Submitter.DisplayString}" Content="{Binding Submitter.DisplayString}"
Margin="10,1" /> Margin="10,1" />
<Label Grid.Column="0" <Label Grid.Column="0"
Grid.Row="2"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Grid.Row="2"
Content="{Binding CreationDateString}" Content="{Binding CreationDateString}"
Margin="10,1" /> Margin="10,1" />
<Image Grid.Column="2" <Image Grid.Column="2"
...@@ -84,11 +85,11 @@ ...@@ -84,11 +85,11 @@
<TextBox Grid.Column="1" <TextBox Grid.Column="1"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Grid.Row="4" Grid.Row="4"
Background="{Binding Background}"
VerticalAlignment="Center" VerticalAlignment="Center"
Padding="2" Padding="2"
Text="{Binding Uri}" Text="{Binding Uri}"
IsReadOnly="True" IsReadOnly="True"
MinWidth="400"
Margin="5,10,10,10"/> Margin="5,10,10,10"/>
<Label Grid.Column="0" <Label Grid.Column="0"
Grid.Row="5" Grid.Row="5"
...@@ -97,11 +98,11 @@ ...@@ -97,11 +98,11 @@
<TextBox Grid.Column="1" <TextBox Grid.Column="1"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Grid.Row="5" Grid.Row="5"
Background="{Binding Background}"
VerticalAlignment="Center" VerticalAlignment="Center"
Padding="2" Padding="2"
Text="{Binding CommitMessage}" Text="{Binding CommitMessage}"
IsReadOnly="True" IsReadOnly="True"
MinWidth="400"
Margin="5,10,10,10"/> Margin="5,10,10,10"/>
<Label Grid.Column="0" <Label Grid.Column="0"
Grid.Row="6" Grid.Row="6"
...@@ -110,11 +111,11 @@ ...@@ -110,11 +111,11 @@
<TextBox Grid.Column="1" <TextBox Grid.Column="1"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Grid.Row="6" Grid.Row="6"
Background="{Binding Background}"
VerticalAlignment="Center" VerticalAlignment="Center"
Padding="2" Padding="2"
Text="{Binding Tag}" Text="{Binding Tag}"
IsReadOnly="True" IsReadOnly="True"
MinWidth="400"
Margin="5,10,10,10"/> Margin="5,10,10,10"/>
<StackPanel Grid.Column="0" <StackPanel Grid.Column="0"
Grid.ColumnSpan="3" Grid.ColumnSpan="3"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment