Fix hidden add/remove template buttons, add per-template login filter
The add/remove template buttons sat directly below the fixed-height list with only 6px of margin to the tab's bottom edge - enough on this dev machine but not on the operator's real one (different DPI/font scale), so the buttons rendered off the visible area. Moved them above the list instead (visibility no longer depends on how much space is left at the bottom) and gave the whole "Шаблоны" tab substantially more vertical room throughout. Also added an optional per-template login regex filter (MailTemplateDefinition.LoginPattern): once a file's suffix matches a template, its login must also match that template's pattern (if any) or the row surfaces as a clear Error in the preview instead of silently going through - addresses "непонятно что будет работать". Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
804b9610ca
commit
6e823954a3
8 files changed
+385
-50
No files matched your search
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
using BulkArchiveMailer.Core;
|
||||
using Outlook = Microsoft.Office.Interop.Outlook;
|
||||
@@ -194,6 +195,7 @@ namespace BulkArchiveMailer.AddIn.UI
|
||||
var t = templates[editedIndex];
|
||||
t.DisplayName = txtTplDisplayName.Text;
|
||||
t.FileSuffix = txtTplFileSuffix.Text.Trim();
|
||||
t.LoginPattern = txtTplLoginPattern.Text.Trim();
|
||||
t.Subject = txtTplSubject.Text;
|
||||
t.BodyHtml = txtTplBody.Text;
|
||||
}
|
||||
@@ -206,6 +208,7 @@ namespace BulkArchiveMailer.AddIn.UI
|
||||
|
||||
txtTplDisplayName.Enabled = hasSelection;
|
||||
txtTplFileSuffix.Enabled = hasSelection;
|
||||
txtTplLoginPattern.Enabled = hasSelection;
|
||||
txtTplSubject.Enabled = hasSelection;
|
||||
txtTplBody.Enabled = hasSelection;
|
||||
|
||||
@@ -214,6 +217,7 @@ namespace BulkArchiveMailer.AddIn.UI
|
||||
lstTemplates.Tag = -1;
|
||||
txtTplDisplayName.Text = "";
|
||||
txtTplFileSuffix.Text = "";
|
||||
txtTplLoginPattern.Text = "";
|
||||
txtTplSubject.Text = "";
|
||||
txtTplBody.Text = "";
|
||||
return;
|
||||
@@ -223,6 +227,7 @@ namespace BulkArchiveMailer.AddIn.UI
|
||||
lstTemplates.Tag = index;
|
||||
txtTplDisplayName.Text = t.DisplayName;
|
||||
txtTplFileSuffix.Text = t.FileSuffix;
|
||||
txtTplLoginPattern.Text = t.LoginPattern;
|
||||
txtTplSubject.Text = t.Subject;
|
||||
txtTplBody.Text = t.BodyHtml;
|
||||
}
|
||||
@@ -265,6 +270,7 @@ namespace BulkArchiveMailer.AddIn.UI
|
||||
{
|
||||
DisplayName = "Новый шаблон",
|
||||
FileSuffix = "",
|
||||
LoginPattern = "",
|
||||
Subject = "",
|
||||
BodyHtml = "",
|
||||
};
|
||||
@@ -446,6 +452,15 @@ namespace BulkArchiveMailer.AddIn.UI
|
||||
return;
|
||||
}
|
||||
|
||||
var loginPatternError = ValidateTemplateLoginPatterns();
|
||||
if (loginPatternError != null)
|
||||
{
|
||||
MessageBox.Show(this, loginPatternError, "BulkArchiveMailer", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
tabControl.SelectedTab = tabTemplates;
|
||||
lstTemplates.Focus();
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedAccount = cboFromAccount.SelectedItem as FromAccountItem;
|
||||
|
||||
var data = new AppSettingsData
|
||||
@@ -502,6 +517,41 @@ namespace BulkArchiveMailer.AddIn.UI
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Every template's LoginPattern (if non-empty) must compile as a
|
||||
/// .NET regular expression - ArchiveScanner treats an uncompilable
|
||||
/// pattern defensively as "never matches" rather than throwing, but
|
||||
/// that would silently turn a typo'd filter into "this template
|
||||
/// never applies to anything", which is worth catching here instead
|
||||
/// while the operator still has the exact field in front of them.
|
||||
/// Returns null if every configured pattern is either empty or
|
||||
/// compiles, otherwise a message naming the offending template and
|
||||
/// the underlying regex error.
|
||||
/// </summary>
|
||||
private string ValidateTemplateLoginPatterns()
|
||||
{
|
||||
for (var i = 0; i < templates.Count; i++)
|
||||
{
|
||||
var pattern = templates[i].LoginPattern;
|
||||
if (string.IsNullOrEmpty(pattern))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_ = new Regex(pattern);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
var name = string.IsNullOrWhiteSpace(templates[i].DisplayName) ? $"#{i + 1}" : templates[i].DisplayName;
|
||||
return $"У шаблона \"{name}\" некорректное регулярное выражение в поле \"Фильтр логина\" (\"{pattern}\"): {ex.Message}";
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void btnCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
|
||||
Reference in new issue
Block a user