Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2932352220 | ||
|
|
a7b07db034 | ||
|
|
7fd54fe84a | ||
|
|
d29a9ac38e | ||
|
|
210d0b65ed | ||
|
|
e84db09bd6 | ||
|
|
8714eec6ca | ||
|
|
253847323a | ||
|
|
a2c4e1853d | ||
|
|
e7076a76c2 | ||
|
|
ce6d9d2f83 | ||
|
|
4a88033695 | ||
|
|
1ecb48316d | ||
|
|
05a5169129 | ||
|
|
d3b071b0be | ||
|
|
c9523d0953 | ||
|
|
f9f0e71453 | ||
|
|
23f7806e2d |
No files matched your search
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 yyc12345
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -28,4 +28,4 @@ by the manually triggered workflow in `.github/workflows/build.yml`;
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT
|
MIT — see [LICENSE](LICENSE).
|
||||||
@@ -226,6 +226,7 @@ These are invalid:
|
|||||||
|---|---|
|
|---|---|
|
||||||
| Unbalanced parentheses | `(tag:bug`, `tag:bug)` |
|
| Unbalanced parentheses | `(tag:bug`, `tag:bug)` |
|
||||||
| Parentheses nested more than 64 levels deep | `((((…a…))))` with 65 `(` |
|
| Parentheses nested more than 64 levels deep | `((((…a…))))` with 65 `(` |
|
||||||
|
| More than 256 search terms (words, phrases and qualifiers) | 257 words |
|
||||||
| An operator with a missing side | `bug AND`, `OR bug` |
|
| An operator with a missing side | `bug AND`, `OR bug` |
|
||||||
| Consecutive operators | `a AND OR b` |
|
| Consecutive operators | `a AND OR b` |
|
||||||
| A qualifier without a value | `tag:` |
|
| A qualifier without a value | `tag:` |
|
||||||
|
|||||||
@@ -181,6 +181,21 @@ public class MarkdownExporterTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("D:\\", "D")]
|
||||||
|
[DataRow("a<b>c|d?e*f\"g", "abcdefg")]
|
||||||
|
[DataRow("/", null)]
|
||||||
|
public void FileNameDropsCharactersThatAreInvalidInFileNames(string workspaceName, string? expectedName)
|
||||||
|
{
|
||||||
|
string fileName = MarkdownExporter.BuildFileName(workspaceName, ExportedAt);
|
||||||
|
|
||||||
|
CultureInfo culture = Resources.Culture ?? CultureInfo.CurrentUICulture;
|
||||||
|
Assert.AreEqual(
|
||||||
|
string.Format(culture, Resources.Export_FileNamePattern, expectedName ?? Resources.App_Name, ExportedAt),
|
||||||
|
fileName);
|
||||||
|
Assert.AreEqual(-1, fileName.IndexOfAny(Path.GetInvalidFileNameChars()));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TagTableCellsEscapePipesAndLineBreaks()
|
public void TagTableCellsEscapePipesAndLineBreaks()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -248,6 +248,28 @@ public class SearchQueryParserTests
|
|||||||
Assert.IsNotNull(SearchQueryParser.Parse(groups));
|
Assert.IsNotNull(SearchQueryParser.Parse(groups));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AtomCountAtTheLimitParses()
|
||||||
|
{
|
||||||
|
Assert.IsNotNull(SearchQueryParser.Parse(string.Join(" ", Enumerable.Repeat("a", SearchQueryParser.MaxAtomCount))));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow(" ")]
|
||||||
|
[DataRow(" OR ")]
|
||||||
|
public void AtomCountBeyondTheLimitIsAnError(string separator)
|
||||||
|
{
|
||||||
|
AssertSyntaxError(string.Join(separator, Enumerable.Repeat("a", SearchQueryParser.MaxAtomCount + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void QualifiersAndPhrasesCountTowardsTheAtomLimit()
|
||||||
|
{
|
||||||
|
int half = SearchQueryParser.MaxAtomCount / 2;
|
||||||
|
string text = string.Join(" ", Enumerable.Repeat("tag:\"a b\"", half).Concat(Enumerable.Repeat("\"c\"", half + 1)));
|
||||||
|
AssertSyntaxError(text);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void VeryDeepNestingIsAnErrorRatherThanACrash()
|
public void VeryDeepNestingIsAnErrorRatherThanACrash()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -190,4 +190,20 @@ public class SearchSqlCompilerTests
|
|||||||
CollectionAssert.AreEqual(new[] { 5L }, fixture.Search("tag:äpfel"));
|
CollectionAssert.AreEqual(new[] { 5L }, fixture.Search("tag:äpfel"));
|
||||||
CollectionAssert.AreEqual(new[] { 5L }, fixture.Search("column:érable"));
|
CollectionAssert.AreEqual(new[] { 5L }, fixture.Search("column:érable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LargestAcceptedQueriesRunWithinTheSqliteExpressionDepth()
|
||||||
|
{
|
||||||
|
using var fixture = new SearchFixture();
|
||||||
|
int count = SearchQueryParser.MaxAtomCount;
|
||||||
|
int depth = SearchQueryParser.MaxNestingDepth;
|
||||||
|
string nested = string.Concat(Enumerable.Repeat("(tag:x OR ", depth))
|
||||||
|
+ string.Join(" ", Enumerable.Repeat("apple", count - depth))
|
||||||
|
+ new string(')', depth);
|
||||||
|
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L }, fixture.Search(string.Join(" ", Enumerable.Repeat("apple", count))));
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L }, fixture.Search(string.Join(" OR ", Enumerable.Repeat("apple", count))));
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L }, fixture.Search(string.Join(" ", Enumerable.Repeat("title:apple", count))));
|
||||||
|
CollectionAssert.AreEqual(new[] { 2L }, fixture.Search(nested));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -45,6 +45,43 @@ public class AppConfigStoreTests
|
|||||||
Assert.AreEqual("{ this is not valid json", File.ReadAllText(path + ".bak"));
|
Assert.AreEqual("{ this is not valid json", File.ReadAllText(path + ".bak"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LoadUnreadableFileReturnsDefaults()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
File.WriteAllText(path, "{ \"language\": \"zh-Hans\" }");
|
||||||
|
var store = new AppConfigStore(path);
|
||||||
|
|
||||||
|
AppConfig config;
|
||||||
|
using (new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
|
||||||
|
{
|
||||||
|
config = store.Load();
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.AreEqual(AppConfig.DefaultLanguage, config.Language);
|
||||||
|
Assert.IsFalse(File.Exists(path + ".bak"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LoadCorruptFileReturnsDefaultsWhenTheBackupCannotBeWritten()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
File.WriteAllText(path, "{ this is not valid json");
|
||||||
|
File.WriteAllText(path + ".bak", "older backup");
|
||||||
|
var store = new AppConfigStore(path);
|
||||||
|
|
||||||
|
AppConfig config;
|
||||||
|
using (new FileStream(path + ".bak", FileMode.Open, FileAccess.ReadWrite, FileShare.None))
|
||||||
|
{
|
||||||
|
config = store.Load();
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.AreEqual(AppConfig.CurrentFormatVersion, config.Version);
|
||||||
|
Assert.AreEqual("older backup", File.ReadAllText(path + ".bak"));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void LoadJsonNullReturnsDefaults()
|
public void LoadJsonNullReturnsDefaults()
|
||||||
{
|
{
|
||||||
@@ -185,6 +222,13 @@ public class AppConfigStoreTests
|
|||||||
[DataRow("\"column-width\": { \"custom-pixels\": \"wide\" }")]
|
[DataRow("\"column-width\": { \"custom-pixels\": \"wide\" }")]
|
||||||
[DataRow("\"confirmations\": { \"delete-card\": \"nope\" }")]
|
[DataRow("\"confirmations\": { \"delete-card\": \"nope\" }")]
|
||||||
[DataRow("\"version\": \"one\"")]
|
[DataRow("\"version\": \"one\"")]
|
||||||
|
[DataRow("\"version\": \"1\"")]
|
||||||
|
[DataRow("\"language\": [\"zh-Hans\"]")]
|
||||||
|
[DataRow("\"confirmations\": { \"delete-card\": 0 }")]
|
||||||
|
[DataRow("\"confirmations\": { \"delete-card\": \"false\" }")]
|
||||||
|
[DataRow("\"column-width\": { \"custom-pixels\": \"500\" }")]
|
||||||
|
[DataRow("\"column-width\": { \"custom-pixels\": 500.0 }")]
|
||||||
|
[DataRow("\"column-width\": { \"custom-pixels\": 99999999999 }")]
|
||||||
public void InvalidFieldFallsBackAloneWithoutBackup(string invalidMember)
|
public void InvalidFieldFallsBackAloneWithoutBackup(string invalidMember)
|
||||||
{
|
{
|
||||||
using var directory = new TempDirectory();
|
using var directory = new TempDirectory();
|
||||||
@@ -252,7 +296,7 @@ public class AppConfigStoreTests
|
|||||||
|
|
||||||
AppConfig config = store.Load();
|
AppConfig config = store.Load();
|
||||||
|
|
||||||
Assert.IsFalse(store.SaveIfChanged(config));
|
Assert.IsFalse(store.SaveIfDirty(config));
|
||||||
Assert.IsFalse(File.Exists(path));
|
Assert.IsFalse(File.Exists(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +311,7 @@ public class AppConfigStoreTests
|
|||||||
|
|
||||||
AppConfig config = store.Load();
|
AppConfig config = store.Load();
|
||||||
|
|
||||||
Assert.IsFalse(store.SaveIfChanged(config));
|
Assert.IsFalse(store.SaveIfDirty(config));
|
||||||
Assert.AreEqual(original, File.ReadAllText(path));
|
Assert.AreEqual(original, File.ReadAllText(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,15 +325,15 @@ public class AppConfigStoreTests
|
|||||||
|
|
||||||
config.Sort.Card = CardSortOption.UpdatedAt;
|
config.Sort.Card = CardSortOption.UpdatedAt;
|
||||||
|
|
||||||
Assert.IsTrue(store.SaveIfChanged(config));
|
Assert.IsTrue(store.SaveIfDirty(config));
|
||||||
Assert.AreEqual(CardSortOption.UpdatedAt, new AppConfigStore(path).Load().Sort.Card);
|
Assert.AreEqual(CardSortOption.UpdatedAt, new AppConfigStore(path).Load().Sort.Card);
|
||||||
|
|
||||||
// Saved state is the new baseline.
|
// Saved state is the new baseline.
|
||||||
Assert.IsFalse(store.SaveIfChanged(config));
|
Assert.IsFalse(store.SaveIfDirty(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ChangeRevertedWithinSessionIsNotWritten()
|
public void ChangeRevertedWithinSessionIsStillWritten()
|
||||||
{
|
{
|
||||||
using var directory = new TempDirectory();
|
using var directory = new TempDirectory();
|
||||||
string path = Path.Combine(directory.FullPath, "app.json");
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
@@ -299,7 +343,49 @@ public class AppConfigStoreTests
|
|||||||
config.Theme = ThemeOption.Dark;
|
config.Theme = ThemeOption.Dark;
|
||||||
config.Theme = ThemeOption.FollowSystem;
|
config.Theme = ThemeOption.FollowSystem;
|
||||||
|
|
||||||
Assert.IsFalse(store.SaveIfChanged(config));
|
Assert.IsTrue(store.SaveIfDirty(config));
|
||||||
|
Assert.IsTrue(File.Exists(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AssigningTheCurrentValuesIsNotAChange()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
var store = new AppConfigStore(path);
|
||||||
|
AppConfig config = store.Load();
|
||||||
|
|
||||||
|
config.Theme = config.Theme;
|
||||||
|
config.Sort.Card = config.Sort.Card;
|
||||||
|
config.Confirmations.DeleteTag = config.Confirmations.DeleteTag;
|
||||||
|
|
||||||
|
Assert.IsFalse(store.SaveIfDirty(config));
|
||||||
Assert.IsFalse(File.Exists(path));
|
Assert.IsFalse(File.Exists(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void NestedSettingChangeMarksTheConfigurationDirty()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
var store = new AppConfigStore(path);
|
||||||
|
AppConfig config = store.Load();
|
||||||
|
|
||||||
|
config.Confirmations.DiscardEdit = false;
|
||||||
|
|
||||||
|
Assert.IsTrue(config.IsDirty);
|
||||||
|
Assert.IsTrue(store.SaveIfDirty(config));
|
||||||
|
Assert.IsFalse(config.IsDirty);
|
||||||
|
Assert.IsFalse(new AppConfigStore(path).Load().Confirmations.DiscardEdit);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void LoadedFileIsNotDirty()
|
||||||
|
{
|
||||||
|
using var directory = new TempDirectory();
|
||||||
|
string path = Path.Combine(directory.FullPath, "app.json");
|
||||||
|
File.WriteAllText(path, """{ "theme": "dark", "confirmations": { "delete-card": false } }""");
|
||||||
|
|
||||||
|
Assert.IsFalse(new AppConfigStore(path).Load().IsDirty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -27,10 +27,12 @@ internal sealed class ScriptedDialogService : IDialogService
|
|||||||
return result ?? false;
|
return result ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<string?> PickSaveFilePathAsync(string suggestedFileName)
|
public Task<Func<Task<Stream>>?> PickSaveFileAsync(string suggestedFileName)
|
||||||
{
|
{
|
||||||
SuggestedFileNames.Add(suggestedFileName);
|
SuggestedFileNames.Add(suggestedFileName);
|
||||||
return Task.FromResult(SaveFilePath);
|
string? path = SaveFilePath;
|
||||||
|
return Task.FromResult<Func<Task<Stream>>?>(
|
||||||
|
path is null ? null : () => Task.FromResult<Stream>(File.Create(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Answers every confirmation dialog with the given choice.</summary>
|
/// <summary>Answers every confirmation dialog with the given choice.</summary>
|
||||||
|
|||||||
@@ -204,6 +204,66 @@ public class BoardViewModelTests
|
|||||||
Assert.AreEqual(card.Id, board.Columns[0].Cards.Single().Card.Id);
|
Assert.AreEqual(card.Id, board.Columns[0].Cards.Single().Card.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task EditorThatWroteNothingLeavesTheColumnsAlone()
|
||||||
|
{
|
||||||
|
using var fixture = new Fixture();
|
||||||
|
ColumnModel column = fixture.Repository.AddColumn("A", "");
|
||||||
|
fixture.Repository.AddCard(column.Id, "t", "", []);
|
||||||
|
BoardViewModel board = fixture.CreateBoard();
|
||||||
|
ColumnViewModel shown = board.Columns.Single();
|
||||||
|
int writes = 0;
|
||||||
|
board.DataWritten += (_, _) => writes++;
|
||||||
|
|
||||||
|
// Cancel a new card, confirm an unchanged existing card, confirm an empty new card.
|
||||||
|
fixture.Dialogs.Script = dialog => dialog is CardEditorDialogViewModel editor
|
||||||
|
? editor.RequestCancelAsync()
|
||||||
|
: Task.CompletedTask;
|
||||||
|
await shown.AddCardCommand.ExecuteAsync(null);
|
||||||
|
fixture.Dialogs.Script = dialog =>
|
||||||
|
{
|
||||||
|
(dialog as CardEditorDialogViewModel)?.ConfirmCommand.Execute(null);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
};
|
||||||
|
await shown.Cards.Single().EditCommand.ExecuteAsync(null);
|
||||||
|
await shown.AddCardCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
|
Assert.AreSame(shown, board.Columns.Single());
|
||||||
|
Assert.AreEqual(0, writes);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task TagCreatedInACancelledEditRefreshesTheBoard()
|
||||||
|
{
|
||||||
|
using var fixture = new Fixture();
|
||||||
|
fixture.Repository.AddColumn("A", "");
|
||||||
|
BoardViewModel board = fixture.CreateBoard();
|
||||||
|
ColumnViewModel shown = board.Columns.Single();
|
||||||
|
int writes = 0;
|
||||||
|
board.DataWritten += (_, _) => writes++;
|
||||||
|
fixture.Dialogs.Script = async dialog =>
|
||||||
|
{
|
||||||
|
switch (dialog)
|
||||||
|
{
|
||||||
|
case CardEditorDialogViewModel editor:
|
||||||
|
await editor.AddTagCommand.ExecuteAsync(null);
|
||||||
|
editor.Tags.Clear();
|
||||||
|
await editor.RequestCancelAsync();
|
||||||
|
break;
|
||||||
|
case TagPickerDialogViewModel picker:
|
||||||
|
picker.NewName = "fresh";
|
||||||
|
picker.NewColor = "#123456";
|
||||||
|
picker.CreateCommand.Execute(null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await shown.AddCardCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
|
Assert.AreNotSame(shown, board.Columns.Single());
|
||||||
|
Assert.AreEqual(1, writes);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void UnchangedEditConfirmationWritesNothing()
|
public void UnchangedEditConfirmationWritesNothing()
|
||||||
{
|
{
|
||||||
@@ -225,6 +285,48 @@ public class BoardViewModelTests
|
|||||||
Assert.AreEqual(100, fixture.Repository.GetCard(card.Id)!.UpdatedAt);
|
Assert.AreEqual(100, fixture.Repository.GetCard(card.Id)!.UpdatedAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ConfirmingAnEmptyNewCardCreatesNothing()
|
||||||
|
{
|
||||||
|
using var fixture = new Fixture();
|
||||||
|
ColumnModel column = fixture.Repository.AddColumn("A", "");
|
||||||
|
var editor = CardEditorDialogViewModel.ForNewCard(fixture.Repository, fixture.Dialogs, column.Id, confirmDiscard: true);
|
||||||
|
bool? closedWith = null;
|
||||||
|
editor.CloseRequested += (_, result) => closedWith = result;
|
||||||
|
editor.CardTitle = "draft";
|
||||||
|
editor.CardTitle = "";
|
||||||
|
|
||||||
|
editor.ConfirmCommand.Execute(null);
|
||||||
|
|
||||||
|
Assert.IsTrue(closedWith);
|
||||||
|
Assert.IsNull(editor.SavedCard);
|
||||||
|
Assert.AreEqual(0, fixture.Repository.GetCards().Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task NewCardWithOnlyATagIsCreated()
|
||||||
|
{
|
||||||
|
using var fixture = new Fixture();
|
||||||
|
ColumnModel column = fixture.Repository.AddColumn("A", "");
|
||||||
|
TagModel bug = fixture.Repository.AddTag("bug", new RgbColor(255, 0, 0), "");
|
||||||
|
var editor = CardEditorDialogViewModel.ForNewCard(fixture.Repository, fixture.Dialogs, column.Id, confirmDiscard: true);
|
||||||
|
fixture.Dialogs.Script = dialog =>
|
||||||
|
{
|
||||||
|
if (dialog is TagPickerDialogViewModel picker)
|
||||||
|
{
|
||||||
|
picker.PickCommand.Execute(picker.FilteredTags.Single());
|
||||||
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
|
};
|
||||||
|
|
||||||
|
await editor.AddTagCommand.ExecuteAsync(null);
|
||||||
|
editor.ConfirmCommand.Execute(null);
|
||||||
|
|
||||||
|
CardModel card = fixture.Repository.GetCards().Single();
|
||||||
|
Assert.AreEqual("", card.Title);
|
||||||
|
Assert.AreEqual(bug.Id, card.Tags.Single().Id);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task DirtyCancelAsksAndStaysOpenWhenDeclined()
|
public async Task DirtyCancelAsksAndStaysOpenWhenDeclined()
|
||||||
{
|
{
|
||||||
@@ -285,6 +387,52 @@ public class BoardViewModelTests
|
|||||||
Assert.AreEqual(0, fixture.Repository.GetCards().Count);
|
Assert.AreEqual(0, fixture.Repository.GetCards().Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task FailedSearchQueryIsReportedAndKeepsThePreviousResultAndFilter()
|
||||||
|
{
|
||||||
|
using var fixture = new Fixture();
|
||||||
|
ColumnModel column = fixture.Repository.AddColumn("A", "");
|
||||||
|
fixture.Repository.AddCard(column.Id, "alpha", "", []);
|
||||||
|
fixture.Repository.AddCard(column.Id, "beta", "", []);
|
||||||
|
BoardViewModel board = fixture.CreateBoard();
|
||||||
|
board.SearchText = "alpha";
|
||||||
|
await board.SearchCommand.ExecuteAsync(null);
|
||||||
|
CompiledSearch? alphaFilter = board.ActiveFilter;
|
||||||
|
|
||||||
|
// Every read fails from now on.
|
||||||
|
fixture.Repository.Dispose();
|
||||||
|
board.SearchText = "beta";
|
||||||
|
await board.SearchCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
|
var error = (MessageDialogViewModel)fixture.Dialogs.Shown.Single();
|
||||||
|
Assert.AreEqual(Resources.Error_Read_Title, error.Title);
|
||||||
|
Assert.AreSame(alphaFilter, board.ActiveFilter);
|
||||||
|
CollectionAssert.AreEqual(new[] { "alpha" }, board.Columns.Single().Cards.Select(card => card.Title).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task ReadFailuresOnBoardCommandsAreReportedInsteadOfThrown()
|
||||||
|
{
|
||||||
|
using var fixture = new Fixture();
|
||||||
|
ColumnModel column = fixture.Repository.AddColumn("A", "");
|
||||||
|
CardModel card = fixture.Repository.AddCard(column.Id, "a", "", []);
|
||||||
|
BoardViewModel board = fixture.CreateBoard();
|
||||||
|
var editor = CardEditorDialogViewModel.ForExistingCard(fixture.Repository, fixture.Dialogs, card, confirmDiscard: false);
|
||||||
|
fixture.Repository.Dispose();
|
||||||
|
|
||||||
|
board.SelectedSort = board.SortOptions.Single(option => (CardSortOption)option.Value == CardSortOption.Title);
|
||||||
|
await board.ClearSearchCommand.ExecuteAsync(null);
|
||||||
|
await board.Columns.Single().Cards.Single().EditCommand.ExecuteAsync(null);
|
||||||
|
await board.Columns.Single().Cards.Single().MoveToCommand.ExecuteAsync(column.Id);
|
||||||
|
await editor.AddTagCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
|
// Sort, clear, edit, the failed move with its refresh, and the tag picker.
|
||||||
|
string read = Resources.Error_Read_Title;
|
||||||
|
CollectionAssert.AreEqual(
|
||||||
|
new[] { read, read, read, Resources.Error_Operation_Title, read, read },
|
||||||
|
fixture.Dialogs.Shown.Select(dialog => ((MessageDialogViewModel)dialog).Title).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TagPickerReportsInvalidColorAndDuplicateNameWithoutClosing()
|
public void TagPickerReportsInvalidColorAndDuplicateNameWithoutClosing()
|
||||||
{
|
{
|
||||||
@@ -308,6 +456,13 @@ public class BoardViewModelTests
|
|||||||
Assert.AreEqual(1, fixture.Repository.GetTags().Count);
|
Assert.AreEqual(1, fixture.Repository.GetTags().Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TagBadgeShowsNoTooltipForAnEmptyDescription()
|
||||||
|
{
|
||||||
|
Assert.IsNull(new TagBadgeViewModel(new TagModel(1, "bug", new RgbColor(1, 2, 3), "")).ToolTip);
|
||||||
|
Assert.AreEqual("why", new TagBadgeViewModel(new TagModel(1, "bug", new RgbColor(1, 2, 3), "why")).ToolTip);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TagPickerHidesAssignedTagsAndFiltersCaseInsensitively()
|
public void TagPickerHidesAssignedTagsAndFiltersCaseInsensitively()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
using YKanBan.Storage.AppData;
|
||||||
|
using YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
|
namespace YKanBan.Tests.ViewModels;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for the settings dialog: the theme is previewed as soon as it is
|
||||||
|
/// selected, saved on accept and restored on cancel.
|
||||||
|
/// </summary>
|
||||||
|
[TestClass]
|
||||||
|
public class SettingsDialogViewModelTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void OpeningTheDialogAppliesNothing()
|
||||||
|
{
|
||||||
|
var applied = new List<ThemeOption>();
|
||||||
|
|
||||||
|
_ = new SettingsDialogViewModel(new AppConfig(), AppConfig.DefaultLanguage, applied.Add);
|
||||||
|
|
||||||
|
Assert.AreEqual(0, applied.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void SelectingAThemeAppliesItImmediatelyWithoutSavingIt()
|
||||||
|
{
|
||||||
|
var config = new AppConfig();
|
||||||
|
var applied = new List<ThemeOption>();
|
||||||
|
var dialog = new SettingsDialogViewModel(config, AppConfig.DefaultLanguage, applied.Add);
|
||||||
|
|
||||||
|
dialog.SelectedTheme = dialog.Themes.Single(option => option.Value.Equals(ThemeOption.Dark));
|
||||||
|
|
||||||
|
CollectionAssert.AreEqual(new[] { ThemeOption.Dark }, applied);
|
||||||
|
Assert.AreEqual(ThemeOption.FollowSystem, config.Theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void AcceptSavesThePreviewedTheme()
|
||||||
|
{
|
||||||
|
var config = new AppConfig();
|
||||||
|
var applied = new List<ThemeOption>();
|
||||||
|
var dialog = new SettingsDialogViewModel(config, AppConfig.DefaultLanguage, applied.Add);
|
||||||
|
dialog.SelectedTheme = dialog.Themes.Single(option => option.Value.Equals(ThemeOption.Light));
|
||||||
|
|
||||||
|
dialog.Accept();
|
||||||
|
|
||||||
|
Assert.AreEqual(ThemeOption.Light, config.Theme);
|
||||||
|
CollectionAssert.AreEqual(new[] { ThemeOption.Light }, applied);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void CancelRestoresTheThemeTheDialogOpenedWith()
|
||||||
|
{
|
||||||
|
var config = new AppConfig { Theme = ThemeOption.Light };
|
||||||
|
var applied = new List<ThemeOption>();
|
||||||
|
var dialog = new SettingsDialogViewModel(config, AppConfig.DefaultLanguage, applied.Add);
|
||||||
|
dialog.SelectedTheme = dialog.Themes.Single(option => option.Value.Equals(ThemeOption.Dark));
|
||||||
|
|
||||||
|
dialog.Cancel();
|
||||||
|
|
||||||
|
Assert.AreEqual(ThemeOption.Light, config.Theme);
|
||||||
|
CollectionAssert.AreEqual(new[] { ThemeOption.Dark, ThemeOption.Light }, applied);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -138,7 +138,7 @@ public class TagsAndSearchViewModelTests
|
|||||||
board.SearchText = "alpha";
|
board.SearchText = "alpha";
|
||||||
await board.SearchCommand.ExecuteAsync(null);
|
await board.SearchCommand.ExecuteAsync(null);
|
||||||
Assert.IsTrue(board.HasSearchText);
|
Assert.IsTrue(board.HasSearchText);
|
||||||
board.ClearSearchCommand.Execute(null);
|
await board.ClearSearchCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
Assert.AreEqual("", board.SearchText);
|
Assert.AreEqual("", board.SearchText);
|
||||||
Assert.IsFalse(board.HasSearchText);
|
Assert.IsFalse(board.HasSearchText);
|
||||||
@@ -312,6 +312,24 @@ public class TagsAndSearchViewModelTests
|
|||||||
Assert.AreEqual(0, fixture.Repository.GetTags().Count);
|
Assert.AreEqual(0, fixture.Repository.GetTags().Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task TagReadFailuresAreReportedInsteadOfThrown()
|
||||||
|
{
|
||||||
|
using var fixture = new Fixture();
|
||||||
|
fixture.Repository.AddTag("bug", new RgbColor(1, 2, 3), "");
|
||||||
|
fixture.Config.Confirmations.DeleteTag = false;
|
||||||
|
TagsViewModel tags = fixture.CreateTags();
|
||||||
|
|
||||||
|
// Every read and write fails from now on.
|
||||||
|
fixture.Repository.Dispose();
|
||||||
|
await tags.Tags[0].DeleteCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
|
CollectionAssert.AreEqual(
|
||||||
|
new[] { Resources.Error_Operation_Title, Resources.Error_Read_Title },
|
||||||
|
fixture.Dialogs.Shown.Select(dialog => ((MessageDialogViewModel)dialog).Title).ToArray());
|
||||||
|
Assert.AreEqual("bug", tags.Tags.Single().Tag.Name);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Workspace wiring and export
|
#region Workspace wiring and export
|
||||||
@@ -334,7 +352,7 @@ public class TagsAndSearchViewModelTests
|
|||||||
Assert.AreEqual(0, workspace.Board.Columns.Sum(column => column.CardCount));
|
Assert.AreEqual(0, workspace.Board.Columns.Sum(column => column.CardCount));
|
||||||
|
|
||||||
// Re-tag through the repository, then a board write updates the usage count.
|
// Re-tag through the repository, then a board write updates the usage count.
|
||||||
workspace.Board.ClearSearchCommand.Execute(null);
|
await workspace.Board.ClearSearchCommand.ExecuteAsync(null);
|
||||||
TagModel ui = fixture.Repository.AddTag("ui", new RgbColor(4, 5, 6), "");
|
TagModel ui = fixture.Repository.AddTag("ui", new RgbColor(4, 5, 6), "");
|
||||||
fixture.Repository.UpdateCard(card.Id, "a", "", [ui.Id]);
|
fixture.Repository.UpdateCard(card.Id, "a", "", [ui.Id]);
|
||||||
Assert.AreEqual(0, workspace.Tags.Tags.Count);
|
Assert.AreEqual(0, workspace.Tags.Tags.Count);
|
||||||
@@ -396,5 +414,22 @@ public class TagsAndSearchViewModelTests
|
|||||||
Assert.IsTrue(message.HasDetails);
|
Assert.IsTrue(message.HasDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task ExportReadFailureIsReportedAndLeavesTheTargetUntouched()
|
||||||
|
{
|
||||||
|
using var fixture = new Fixture();
|
||||||
|
WorkspaceViewModel workspace = fixture.CreateWorkspace();
|
||||||
|
string path = Path.Combine(fixture.Directory.FullPath, "out.md");
|
||||||
|
File.WriteAllText(path, "previous");
|
||||||
|
fixture.Dialogs.SaveFilePath = path;
|
||||||
|
|
||||||
|
fixture.Repository.Dispose();
|
||||||
|
await workspace.ExportCommand.ExecuteAsync(null);
|
||||||
|
|
||||||
|
var message = (MessageDialogViewModel)fixture.Dialogs.Shown.Single();
|
||||||
|
Assert.AreEqual(Resources.Export_Failed_Title, message.Title);
|
||||||
|
Assert.AreEqual("previous", File.ReadAllText(path));
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -343,6 +343,15 @@
|
|||||||
<data name="Error_Operation_Message" xml:space="preserve">
|
<data name="Error_Operation_Message" xml:space="preserve">
|
||||||
<value>The change could not be written to the workspace. The board shows the stored state.</value>
|
<value>The change could not be written to the workspace. The board shows the stored state.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Error_ViewNotFound" xml:space="preserve">
|
||||||
|
<value>View not found: {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_Read_Title" xml:space="preserve">
|
||||||
|
<value>Reading failed</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_Read_Message" xml:space="preserve">
|
||||||
|
<value>The data could not be read from the workspace. What is shown may be out of date.</value>
|
||||||
|
</data>
|
||||||
<data name="TagEditor_TitleNew" xml:space="preserve">
|
<data name="TagEditor_TitleNew" xml:space="preserve">
|
||||||
<value>New tag</value>
|
<value>New tag</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -343,6 +343,15 @@
|
|||||||
<data name="Error_Operation_Message" xml:space="preserve">
|
<data name="Error_Operation_Message" xml:space="preserve">
|
||||||
<value>更改未能写入工作区,看板显示的是已保存的状态。</value>
|
<value>更改未能写入工作区,看板显示的是已保存的状态。</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Error_ViewNotFound" xml:space="preserve">
|
||||||
|
<value>找不到视图:{0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_Read_Title" xml:space="preserve">
|
||||||
|
<value>读取失败</value>
|
||||||
|
</data>
|
||||||
|
<data name="Error_Read_Message" xml:space="preserve">
|
||||||
|
<value>无法从工作区读取数据,当前显示的内容可能不是最新的。</value>
|
||||||
|
</data>
|
||||||
<data name="TagEditor_TitleNew" xml:space="preserve">
|
<data name="TagEditor_TitleNew" xml:space="preserve">
|
||||||
<value>新建标签</value>
|
<value>新建标签</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 172 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
@@ -67,7 +67,10 @@ public static class MarkdownExporter
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Builds the default export file name in the UI language, for example
|
/// Builds the default export file name in the UI language, for example
|
||||||
/// "MyRepo-export-20260930-142537.md".
|
/// "MyRepo-export-20260930-142537.md". Characters that are not allowed in a
|
||||||
|
/// file name on any supported platform are dropped from the workspace name
|
||||||
|
/// (a workspace at a drive root is named "D:\"); a name left empty falls
|
||||||
|
/// back to the application name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="workspaceName">Workspace display name.</param>
|
/// <param name="workspaceName">Workspace display name.</param>
|
||||||
/// <param name="exportedAt">Export moment.</param>
|
/// <param name="exportedAt">Export moment.</param>
|
||||||
@@ -75,8 +78,22 @@ public static class MarkdownExporter
|
|||||||
public static string BuildFileName(string workspaceName, DateTimeOffset exportedAt)
|
public static string BuildFileName(string workspaceName, DateTimeOffset exportedAt)
|
||||||
{
|
{
|
||||||
CultureInfo culture = Resources.Culture ?? CultureInfo.CurrentUICulture;
|
CultureInfo culture = Resources.Culture ?? CultureInfo.CurrentUICulture;
|
||||||
return string.Format(culture, Resources.Export_FileNamePattern, workspaceName, exportedAt);
|
string safeName = new(workspaceName.Where(character => !IsInvalidFileNameCharacter(character)).ToArray());
|
||||||
|
if (safeName.Length == 0)
|
||||||
|
{
|
||||||
|
safeName = Resources.App_Name;
|
||||||
}
|
}
|
||||||
|
return string.Format(culture, Resources.Export_FileNamePattern, safeName, exportedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tells whether a character is invalid in a file name on Windows, Linux or
|
||||||
|
/// macOS; the Windows set is the widest, so the result is the same on every platform.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="character">The character to test.</param>
|
||||||
|
/// <returns><see langword="true"/> when the character must not appear in a file name.</returns>
|
||||||
|
private static bool IsInvalidFileNameCharacter(char character) =>
|
||||||
|
character < ' ' || character is '<' or '>' or ':' or '"' or '/' or '\\' or '|' or '?' or '*';
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Appends one card block: heading, body, tags line and timestamps line.
|
/// Appends one card block: heading, body, tags line and timestamps line.
|
||||||
|
|||||||
+8
-1
@@ -12,10 +12,17 @@ sealed class Program
|
|||||||
{
|
{
|
||||||
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||||
|
|
||||||
// The lifetime has ended: persist the configuration once, then release services.
|
// The lifetime has ended: persist the configuration once, then release
|
||||||
|
// services; the workspace lock and connection are released even if saving fails.
|
||||||
|
try
|
||||||
|
{
|
||||||
App.Services?.SaveConfiguration();
|
App.Services?.SaveConfiguration();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
App.Services?.Dispose();
|
App.Services?.Dispose();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Avalonia configuration, don't remove; also used by visual designer.
|
// Avalonia configuration, don't remove; also used by visual designer.
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace YKanBan.Search;
|
|||||||
/// phrases, invalid escapes, a backslash in a bare word, unknown qualifier
|
/// phrases, invalid escapes, a backslash in a bare word, unknown qualifier
|
||||||
/// keys, qualifiers without a value, unquoted values containing ':' or equal
|
/// keys, qualifiers without a value, unquoted values containing ':' or equal
|
||||||
/// to AND/OR, id values that are not an unquoted positive integer with an
|
/// to AND/OR, id values that are not an unquoted positive integer with an
|
||||||
/// optional '#', and parentheses nested deeper than <see cref="MaxNestingDepth"/>)
|
/// optional '#', parentheses nested deeper than <see cref="MaxNestingDepth"/>,
|
||||||
/// raises <see cref="SearchSyntaxException"/>.
|
/// and more than <see cref="MaxAtomCount"/> atoms) raises <see cref="SearchSyntaxException"/>.
|
||||||
///
|
///
|
||||||
/// Only uppercase AND/OR are operators (lowercase ones are plain words); AND —
|
/// Only uppercase AND/OR are operators (lowercase ones are plain words); AND —
|
||||||
/// explicit or by adjacency — binds tighter than OR; parentheses group. Blank
|
/// explicit or by adjacency — binds tighter than OR; parentheses group. Blank
|
||||||
@@ -25,6 +25,14 @@ public static class SearchQueryParser
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const int MaxNestingDepth = 64;
|
public const int MaxNestingDepth = 64;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Most atoms (words, phrases and qualifiers) accepted in one expression.
|
||||||
|
/// The compiled SQL chains every atom into one expression, and SQLite
|
||||||
|
/// rejects expressions nested deeper than 1000 levels; together with
|
||||||
|
/// <see cref="MaxNestingDepth"/> this keeps every valid query well below that.
|
||||||
|
/// </summary>
|
||||||
|
public const int MaxAtomCount = 256;
|
||||||
|
|
||||||
/// <summary>The recognized qualifier keys; add new entries here to extend the grammar.</summary>
|
/// <summary>The recognized qualifier keys; add new entries here to extend the grammar.</summary>
|
||||||
private static readonly (string Key, QualifierKind Kind)[] QualifierTable =
|
private static readonly (string Key, QualifierKind Kind)[] QualifierTable =
|
||||||
[
|
[
|
||||||
@@ -122,7 +130,9 @@ public static class SearchQueryParser
|
|||||||
{
|
{
|
||||||
List<SearchToken> tokens = SearchLexer.Tokenize(text).ToList();
|
List<SearchToken> tokens = SearchLexer.Tokenize(text).ToList();
|
||||||
EnsureNestingWithinLimit(tokens);
|
EnsureNestingWithinLimit(tokens);
|
||||||
return Query.ParseOrThrow(tokens);
|
SearchNode query = Query.ParseOrThrow(tokens);
|
||||||
|
EnsureAtomCountWithinLimit(query);
|
||||||
|
return query;
|
||||||
}
|
}
|
||||||
catch (ParseException exception)
|
catch (ParseException exception)
|
||||||
{
|
{
|
||||||
@@ -152,6 +162,31 @@ public static class SearchQueryParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rejects expressions with more than <see cref="MaxAtomCount"/> atoms.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The parsed query.</param>
|
||||||
|
/// <exception cref="SearchSyntaxException">The expression has too many atoms.</exception>
|
||||||
|
private static void EnsureAtomCountWithinLimit(SearchNode query)
|
||||||
|
{
|
||||||
|
if (CountAtoms(query) > MaxAtomCount)
|
||||||
|
{
|
||||||
|
throw new SearchSyntaxException($"The expression has more than {MaxAtomCount} search terms.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Counts the atoms (leaves) of a parsed query.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="node">The node to count.</param>
|
||||||
|
/// <returns>The number of atoms under the node.</returns>
|
||||||
|
private static int CountAtoms(SearchNode node) => node switch
|
||||||
|
{
|
||||||
|
SearchNode.And and => and.Terms.Sum(CountAtoms),
|
||||||
|
SearchNode.Or or => or.Terms.Sum(CountAtoms),
|
||||||
|
_ => 1,
|
||||||
|
};
|
||||||
|
|
||||||
#region Atom construction
|
#region Atom construction
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
using YKanBan.Storage.AppData;
|
using YKanBan.Storage.AppData;
|
||||||
using YKanBan.Storage.Workspace;
|
using YKanBan.Storage.Workspace;
|
||||||
|
|
||||||
@@ -63,9 +64,31 @@ public sealed class AppServices : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Persists the configuration when this session changed a setting; called once at shutdown.
|
/// Releases the open workspace session, if any, so its lock and connection
|
||||||
|
/// do not outlive a workspace that could not be shown.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SaveConfiguration() => ConfigStore.SaveIfChanged(Config);
|
public void CloseWorkspace()
|
||||||
|
{
|
||||||
|
Session?.Dispose();
|
||||||
|
Session = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Persists the configuration when this session changed a setting; called
|
||||||
|
/// once at shutdown. A write failure only loses this session's settings
|
||||||
|
/// changes, the same accepted loss as a crash, so it is logged and ignored.
|
||||||
|
/// </summary>
|
||||||
|
public void SaveConfiguration()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ConfigStore.SaveIfDirty(Config);
|
||||||
|
}
|
||||||
|
catch (Exception exception) when (exception is IOException or UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Releases the workspace session, if any.
|
/// Releases the workspace session, if any.
|
||||||
|
|||||||
@@ -62,65 +62,101 @@ public enum ThemeOption
|
|||||||
FollowSystem,
|
FollowSystem,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base of the app.json sections: records whether any setting was changed
|
||||||
|
/// since the last load or save (the dirty flag). Assigning the value a setting
|
||||||
|
/// already holds is not a change; changing a setting and changing it back is.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class ConfigSection
|
||||||
|
{
|
||||||
|
private bool _changed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether a setting of this section, or of a nested section, was changed.
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
public virtual bool IsDirty => _changed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clears the dirty flag of this section and its nested sections.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void AcceptChanges() => _changed = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stores a setting and marks the section dirty when the value differs.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The setting type.</typeparam>
|
||||||
|
/// <param name="field">The backing field.</param>
|
||||||
|
/// <param name="value">The new value.</param>
|
||||||
|
protected void Set<T>(ref T field, T value)
|
||||||
|
{
|
||||||
|
if (!EqualityComparer<T>.Default.Equals(field, value))
|
||||||
|
{
|
||||||
|
field = value;
|
||||||
|
_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Card ordering settings. The chosen order is global, not per workspace.
|
/// Card ordering settings. The chosen order is global, not per workspace.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class SortSettings
|
public sealed class SortSettings : ConfigSection
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the order used by the board.
|
/// Gets or sets the order used by the board.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("card")]
|
[JsonProperty("card")]
|
||||||
public CardSortOption Card { get; set; } = CardSortOption.Id;
|
public CardSortOption Card { get; set => Set(ref field, value); } = CardSortOption.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Board column width settings, applied globally.
|
/// Board column width settings, applied globally.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ColumnWidthSettings
|
public sealed class ColumnWidthSettings : ConfigSection
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the active width preset.
|
/// Gets or sets the active width preset.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("preset")]
|
[JsonProperty("preset")]
|
||||||
public ColumnWidthPreset Preset { get; set; } = ColumnWidthPreset.Standard;
|
public ColumnWidthPreset Preset { get; set => Set(ref field, value); } = ColumnWidthPreset.Standard;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the manual width in pixels, used when <see cref="Preset"/>
|
/// Gets or sets the manual width in pixels, used when <see cref="Preset"/>
|
||||||
/// is <see cref="ColumnWidthPreset.Custom"/> (range 160–720).
|
/// is <see cref="ColumnWidthPreset.Custom"/> (range 160–720).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("custom-pixels")]
|
[JsonProperty("custom-pixels")]
|
||||||
public int CustomPixels { get; set; } = 320;
|
public int CustomPixels { get; set => Set(ref field, value); } = 320;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Confirmation-dialog toggles for the destructive actions.
|
/// Confirmation-dialog toggles for the destructive actions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ConfirmationSettings
|
public sealed class ConfirmationSettings : ConfigSection
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets whether deleting a card asks for confirmation.
|
/// Gets or sets whether deleting a card asks for confirmation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("delete-card")]
|
[JsonProperty("delete-card")]
|
||||||
public bool DeleteCard { get; set; } = true;
|
public bool DeleteCard { get; set => Set(ref field, value); } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets whether deleting a column asks for confirmation.
|
/// Gets or sets whether deleting a column asks for confirmation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("delete-column")]
|
[JsonProperty("delete-column")]
|
||||||
public bool DeleteColumn { get; set; } = true;
|
public bool DeleteColumn { get; set => Set(ref field, value); } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets whether deleting a tag asks for confirmation.
|
/// Gets or sets whether deleting a tag asks for confirmation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("delete-tag")]
|
[JsonProperty("delete-tag")]
|
||||||
public bool DeleteTag { get; set; } = true;
|
public bool DeleteTag { get; set => Set(ref field, value); } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets whether discarding card edits asks for confirmation.
|
/// Gets or sets whether discarding card edits asks for confirmation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("discard-edit")]
|
[JsonProperty("discard-edit")]
|
||||||
public bool DiscardEdit { get; set; } = true;
|
public bool DiscardEdit { get; set => Set(ref field, value); } = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -129,7 +165,7 @@ public sealed class ConfirmationSettings
|
|||||||
/// <see cref="JsonPropertyAttribute"/> and <see cref="EnumMemberAttribute"/>).
|
/// <see cref="JsonPropertyAttribute"/> and <see cref="EnumMemberAttribute"/>).
|
||||||
/// The <c>version</c> field is the migration hook for future format changes.
|
/// The <c>version</c> field is the migration hook for future format changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class AppConfig
|
public sealed class AppConfig : ConfigSection
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current configuration format version.
|
/// Current configuration format version.
|
||||||
@@ -165,35 +201,47 @@ public sealed class AppConfig
|
|||||||
/// Gets or sets the configuration format version of this file.
|
/// Gets or sets the configuration format version of this file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("version")]
|
[JsonProperty("version")]
|
||||||
public int Version { get; set; } = CurrentFormatVersion;
|
public int Version { get; set => Set(ref field, value); } = CurrentFormatVersion;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the UI language code ("en" default or "zh-Hans").
|
/// Gets or sets the UI language code ("en" default or "zh-Hans").
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("language")]
|
[JsonProperty("language")]
|
||||||
public string Language { get; set; } = DefaultLanguage;
|
public string Language { get; set => Set(ref field, value); } = DefaultLanguage;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the UI theme selection (default: follow the system).
|
/// Gets or sets the UI theme selection (default: follow the system).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("theme")]
|
[JsonProperty("theme")]
|
||||||
public ThemeOption Theme { get; set; } = ThemeOption.FollowSystem;
|
public ThemeOption Theme { get; set => Set(ref field, value); } = ThemeOption.FollowSystem;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the card ordering settings.
|
/// Gets or sets the card ordering settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("sort")]
|
[JsonProperty("sort")]
|
||||||
public SortSettings Sort { get; set; } = new();
|
public SortSettings Sort { get; set => Set(ref field, value); } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the board column width settings.
|
/// Gets or sets the board column width settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("column-width")]
|
[JsonProperty("column-width")]
|
||||||
public ColumnWidthSettings ColumnWidth { get; set; } = new();
|
public ColumnWidthSettings ColumnWidth { get; set => Set(ref field, value); } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the confirmation-dialog settings.
|
/// Gets or sets the confirmation-dialog settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("confirmations")]
|
[JsonProperty("confirmations")]
|
||||||
public ConfirmationSettings Confirmations { get; set; } = new();
|
public ConfirmationSettings Confirmations { get; set => Set(ref field, value); } = new();
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool IsDirty => base.IsDirty || Sort.IsDirty || ColumnWidth.IsDirty || Confirmations.IsDirty;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override void AcceptChanges()
|
||||||
|
{
|
||||||
|
base.AcceptChanges();
|
||||||
|
Sort.AcceptChanges();
|
||||||
|
ColumnWidth.AcceptChanges();
|
||||||
|
Confirmations.AcceptChanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Globalization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@@ -8,9 +9,10 @@ namespace YKanBan.Storage.AppData;
|
|||||||
/// Loads and saves app.json with graceful degradation: a missing file yields
|
/// Loads and saves app.json with graceful degradation: a missing file yields
|
||||||
/// defaults; a file that is not a JSON object is backed up to app.json.bak and
|
/// defaults; a file that is not a JSON object is backed up to app.json.bak and
|
||||||
/// then defaults are used; an individual invalid field (unknown enum value or
|
/// then defaults are used; an individual invalid field (unknown enum value or
|
||||||
/// language, out-of-range width, wrong type) falls back to its own default while
|
/// language, out-of-range width, wrong JSON type — no implicit conversion) falls back to its own default while
|
||||||
/// the other fields are kept. Saving happens only when the configuration differs
|
/// the other fields are kept; a file that exists but cannot be read (I/O or
|
||||||
/// from what was loaded, and writes the file directly (no atomic replace) —
|
/// permission error) also yields defaults. Saving happens only when this session
|
||||||
|
/// changed a setting (<see cref="ConfigSection.IsDirty"/>), and writes the file directly (no atomic replace) —
|
||||||
/// losing the last session's settings to a crash is an accepted trade-off.
|
/// losing the last session's settings to a crash is an accepted trade-off.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class AppConfigStore
|
public sealed class AppConfigStore
|
||||||
@@ -28,16 +30,13 @@ public sealed class AppConfigStore
|
|||||||
private static readonly JsonSerializer FieldTolerantSerializer = JsonSerializer.Create(new JsonSerializerSettings
|
private static readonly JsonSerializer FieldTolerantSerializer = JsonSerializer.Create(new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
NullValueHandling = NullValueHandling.Ignore,
|
NullValueHandling = NullValueHandling.Ignore,
|
||||||
Converters = { new StringEnumConverter { AllowIntegerValues = false } },
|
Converters = { new StringEnumConverter { AllowIntegerValues = false }, new StrictPrimitiveConverter() },
|
||||||
|
|
||||||
// The JSON text is already known to be well formed here, so every error is a
|
// The JSON text is already known to be well formed here, so every error is a
|
||||||
// single member that fails to convert: skip it and keep that member's default.
|
// single member that fails to convert: skip it and keep that member's default.
|
||||||
Error = (_, args) => args.ErrorContext.Handled = true,
|
Error = (_, args) => args.ErrorContext.Handled = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>The serialized form of the configuration as last loaded or saved.</summary>
|
|
||||||
private string _persistedSnapshot = Serialize(new AppConfig());
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a store bound to a specific app.json path.
|
/// Initializes a store bound to a specific app.json path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -50,50 +49,49 @@ public sealed class AppConfigStore
|
|||||||
public string FilePath { get; }
|
public string FilePath { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the configuration and records it as the persisted baseline for
|
/// Loads the configuration with a clear dirty flag, the baseline for
|
||||||
/// <see cref="SaveIfChanged"/>. A missing file yields defaults; a file that
|
/// <see cref="SaveIfDirty"/>. A missing file yields defaults; a file that
|
||||||
/// is not a JSON object is backed up to app.json.bak and then defaults are
|
/// is not a JSON object is backed up to app.json.bak (best effort) and then
|
||||||
/// used; invalid fields fall back to their defaults individually.
|
/// defaults are used; invalid fields fall back to their defaults
|
||||||
|
/// individually; a file that cannot be read yields defaults. Never throws for
|
||||||
|
/// file-system reasons, because a bad app.json must not stop the app.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The loaded configuration, or defaults when none could be read.</returns>
|
/// <returns>The loaded configuration, or defaults when none could be read.</returns>
|
||||||
/// <exception cref="IOException">The file exists but cannot be read.</exception>
|
|
||||||
public AppConfig Load()
|
public AppConfig Load()
|
||||||
{
|
{
|
||||||
AppConfig config = Read();
|
AppConfig config = Read();
|
||||||
|
|
||||||
// The baseline is the effective configuration, so field fallbacks alone never trigger a write.
|
// Deserializing and field fallbacks go through the setters; neither is a change by this session.
|
||||||
_persistedSnapshot = Serialize(config);
|
config.AcceptChanges();
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the configuration only when it differs from the loaded or last
|
/// Writes the configuration only when a setting was changed since it was
|
||||||
/// saved one, i.e. when this session changed a setting.
|
/// loaded or last saved, even if it was later changed back.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="config">The live configuration.</param>
|
/// <param name="config">The live configuration.</param>
|
||||||
/// <returns><see langword="true"/> when the file was written.</returns>
|
/// <returns><see langword="true"/> when the file was written.</returns>
|
||||||
public bool SaveIfChanged(AppConfig config)
|
public bool SaveIfDirty(AppConfig config)
|
||||||
{
|
{
|
||||||
string json = Serialize(config);
|
if (!config.IsDirty)
|
||||||
if (json == _persistedSnapshot)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Write(json);
|
Save(config);
|
||||||
_persistedSnapshot = json;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the configuration directly to disk (no atomic replace), unconditionally.
|
/// Writes the configuration directly to disk (no atomic replace),
|
||||||
|
/// unconditionally, and clears its dirty flag.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="config">The configuration to serialize.</param>
|
/// <param name="config">The configuration to serialize.</param>
|
||||||
public void Save(AppConfig config)
|
public void Save(AppConfig config)
|
||||||
{
|
{
|
||||||
string json = Serialize(config);
|
Write(Serialize(config));
|
||||||
Write(json);
|
config.AcceptChanges();
|
||||||
_persistedSnapshot = json;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -108,7 +106,16 @@ public sealed class AppConfigStore
|
|||||||
return new AppConfig();
|
return new AppConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
string json = File.ReadAllText(FilePath);
|
string json;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
json = File.ReadAllText(FilePath);
|
||||||
|
}
|
||||||
|
catch (Exception exception) when (exception is IOException or UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
return new AppConfig();
|
||||||
|
}
|
||||||
|
|
||||||
JToken root;
|
JToken root;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -137,12 +144,20 @@ public sealed class AppConfigStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Keeps a copy of an unusable file for inspection, then continues with defaults.
|
/// Keeps a copy of an unusable file for inspection, then continues with
|
||||||
|
/// defaults; a backup that cannot be written is skipped.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The default configuration.</returns>
|
/// <returns>The default configuration.</returns>
|
||||||
private AppConfig BackUpAndUseDefaults()
|
private AppConfig BackUpAndUseDefaults()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
File.Copy(FilePath, FilePath + ".bak", overwrite: true);
|
File.Copy(FilePath, FilePath + ".bak", overwrite: true);
|
||||||
|
}
|
||||||
|
catch (Exception exception) when (exception is IOException or UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
// The backup is only a diagnostic aid; starting with defaults matters more.
|
||||||
|
}
|
||||||
return new AppConfig();
|
return new AppConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,6 +212,41 @@ public sealed class AppConfigStore
|
|||||||
File.WriteAllText(FilePath, json);
|
File.WriteAllText(FilePath, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads booleans, integers and strings only from JSON tokens of exactly that
|
||||||
|
/// type, so a wrong type is an invalid field (falling back to its default)
|
||||||
|
/// instead of being converted: <c>0</c> or <c>"false"</c> is not a boolean,
|
||||||
|
/// <c>"500"</c> or <c>500.0</c> is not an integer, <c>5</c> is not a string.
|
||||||
|
/// </summary>
|
||||||
|
private sealed class StrictPrimitiveConverter : JsonConverter
|
||||||
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool CanWrite => false;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override bool CanConvert(Type objectType) =>
|
||||||
|
objectType == typeof(bool) || objectType == typeof(int) || objectType == typeof(string);
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
JsonToken expected = objectType == typeof(bool) ? JsonToken.Boolean
|
||||||
|
: objectType == typeof(int) ? JsonToken.Integer
|
||||||
|
: JsonToken.String;
|
||||||
|
if (reader.TokenType != expected)
|
||||||
|
{
|
||||||
|
throw new JsonSerializationException($"Expected a {expected} token for {objectType.Name}, got {reader.TokenType}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Integer tokens are read as Int64 (or BigInteger); a value outside the Int32 range is invalid too.
|
||||||
|
return objectType == typeof(int) ? checked((int)Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture)) : reader.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) =>
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Serializes a configuration in the on-disk format.
|
/// Serializes a configuration in the on-disk format.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
+14
-11
@@ -1,31 +1,34 @@
|
|||||||
using System;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Templates;
|
using Avalonia.Controls.Templates;
|
||||||
using YKanBan.ViewModels;
|
using YKanBan.ViewModels;
|
||||||
|
|
||||||
namespace YKanBan;
|
namespace YKanBan;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resolves the view of a view model by naming convention: the type name with
|
||||||
|
/// "ViewModel" replaced by "View". A missing view is a programming error; it
|
||||||
|
/// shows a localized placeholder naming the type that was looked for.
|
||||||
|
/// </summary>
|
||||||
public class ViewLocator : IDataTemplate
|
public class ViewLocator : IDataTemplate
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
public Control? Build(object? param)
|
public Control? Build(object? param)
|
||||||
{
|
{
|
||||||
if (param is null)
|
if (param is null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
|
string name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
|
||||||
var type = Type.GetType(name);
|
Type? type = Type.GetType(name);
|
||||||
|
if (type is not null)
|
||||||
if (type != null)
|
|
||||||
{
|
{
|
||||||
return (Control)Activator.CreateInstance(type)!;
|
return (Control)Activator.CreateInstance(type)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TextBlock { Text = "Not Found: " + name };
|
return new TextBlock { Text = string.Format(YKanBan.Resources.Culture, YKanBan.Resources.Error_ViewNotFound, name) };
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Match(object? data)
|
/// <inheritdoc/>
|
||||||
{
|
public bool Match(object? data) => data is ViewModelBase;
|
||||||
return data is ViewModelBase;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -107,10 +107,25 @@ public sealed partial class BoardViewModel : ViewModelBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reloads the columns and the cards matching <see cref="ActiveFilter"/>.
|
/// Reloads the columns and the cards matching <see cref="ActiveFilter"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Refresh()
|
/// <exception cref="Exception">Reading the workspace failed; the board is left unchanged.</exception>
|
||||||
|
public void Refresh() => Load(ActiveFilter);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads like <see cref="Refresh"/>, but reports a read failure in a
|
||||||
|
/// message dialog instead of throwing.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><see langword="true"/> when the board was reloaded.</returns>
|
||||||
|
public Task<bool> RefreshOrReportAsync() => TryLoadAsync(ActiveFilter);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads the board with the given filter; the columns are only replaced
|
||||||
|
/// once both queries have succeeded.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filter">The search to apply; <see langword="null"/> shows every card.</param>
|
||||||
|
private void Load(CompiledSearch? filter)
|
||||||
{
|
{
|
||||||
IReadOnlyList<ColumnModel> columns = _repository.GetColumns();
|
IReadOnlyList<ColumnModel> columns = _repository.GetColumns();
|
||||||
ILookup<long, CardModel> cardsByColumn = _repository.GetCards(ActiveFilter).ToLookup(card => card.ColumnId);
|
ILookup<long, CardModel> cardsByColumn = _repository.GetCards(filter).ToLookup(card => card.ColumnId);
|
||||||
var sort = (CardSortOption)SelectedSort.Value;
|
var sort = (CardSortOption)SelectedSort.Value;
|
||||||
|
|
||||||
ColumnModels = columns;
|
ColumnModels = columns;
|
||||||
@@ -121,9 +136,30 @@ public sealed partial class BoardViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads the board with the given filter and reports a read failure in a message dialog.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filter">The search to apply; <see langword="null"/> shows every card.</param>
|
||||||
|
/// <returns><see langword="true"/> when the board was reloaded.</returns>
|
||||||
|
private async Task<bool> TryLoadAsync(CompiledSearch? filter)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Load(filter);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
await _dialogs.ShowReadFailedAsync(exception);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses and runs the search box text; blank text shows every card. An
|
/// Parses and runs the search box text; blank text shows every card. An
|
||||||
/// invalid expression only shows the error dialog.
|
/// invalid expression only shows the error dialog. The expression becomes
|
||||||
|
/// <see cref="ActiveFilter"/> only once its query has succeeded, so a failed
|
||||||
|
/// search leaves the previous result and later refreshes untouched.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A task completing after the refresh or the error dialog.</returns>
|
/// <returns>A task completing after the refresh or the error dialog.</returns>
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
@@ -143,19 +179,24 @@ public sealed partial class BoardViewModel : ViewModelBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (await TryLoadAsync(filter))
|
||||||
|
{
|
||||||
ActiveFilter = filter;
|
ActiveFilter = filter;
|
||||||
Refresh();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Empties the search box and shows every card again.
|
/// Empties the search box and shows every card again.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <returns>A task completing after the refresh.</returns>
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private void ClearSearch()
|
private async Task ClearSearchAsync()
|
||||||
{
|
{
|
||||||
SearchText = "";
|
SearchText = "";
|
||||||
|
if (await TryLoadAsync(null))
|
||||||
|
{
|
||||||
ActiveFilter = null;
|
ActiveFilter = null;
|
||||||
Refresh();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -168,7 +209,7 @@ public sealed partial class BoardViewModel : ViewModelBase
|
|||||||
var dialog = new ColumnEditorDialogViewModel(null, (title, description) => _repository.AddColumn(title, description));
|
var dialog = new ColumnEditorDialogViewModel(null, (title, description) => _repository.AddColumn(title, description));
|
||||||
if (await _dialogs.ShowAsync(dialog))
|
if (await _dialogs.ShowAsync(dialog))
|
||||||
{
|
{
|
||||||
RefreshAfterWrite();
|
await RefreshAfterWriteAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +237,7 @@ public sealed partial class BoardViewModel : ViewModelBase
|
|||||||
column, (title, description) => _repository.UpdateColumn(column.Id, title, description));
|
column, (title, description) => _repository.UpdateColumn(column.Id, title, description));
|
||||||
if (await _dialogs.ShowAsync(dialog))
|
if (await _dialogs.ShowAsync(dialog))
|
||||||
{
|
{
|
||||||
RefreshAfterWrite();
|
await RefreshAfterWriteAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,9 +274,7 @@ public sealed partial class BoardViewModel : ViewModelBase
|
|||||||
var editor = CardEditorDialogViewModel.ForNewCard(
|
var editor = CardEditorDialogViewModel.ForNewCard(
|
||||||
_repository, _dialogs, columnId, _config.Confirmations.DiscardEdit);
|
_repository, _dialogs, columnId, _config.Confirmations.DiscardEdit);
|
||||||
await _dialogs.ShowAsync(editor);
|
await _dialogs.ShowAsync(editor);
|
||||||
|
await RefreshAfterEditorAsync(editor);
|
||||||
// Refresh even after a cancel: the nested picker may have created tags.
|
|
||||||
RefreshAfterWrite();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -245,19 +284,40 @@ public sealed partial class BoardViewModel : ViewModelBase
|
|||||||
/// <returns>A task completing when the editor closes.</returns>
|
/// <returns>A task completing when the editor closes.</returns>
|
||||||
internal async Task EditCardAsync(long cardId)
|
internal async Task EditCardAsync(long cardId)
|
||||||
{
|
{
|
||||||
CardModel? card = _repository.GetCard(cardId);
|
CardModel? card;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
card = _repository.GetCard(cardId);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
await _dialogs.ShowReadFailedAsync(exception);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (card is null)
|
if (card is null)
|
||||||
{
|
{
|
||||||
Refresh();
|
await RefreshOrReportAsync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var editor = CardEditorDialogViewModel.ForExistingCard(
|
var editor = CardEditorDialogViewModel.ForExistingCard(
|
||||||
_repository, _dialogs, card, _config.Confirmations.DiscardEdit);
|
_repository, _dialogs, card, _config.Confirmations.DiscardEdit);
|
||||||
await _dialogs.ShowAsync(editor);
|
await _dialogs.ShowAsync(editor);
|
||||||
RefreshAfterWrite();
|
await RefreshAfterEditorAsync(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refreshes after the card editor closes, but only when it wrote something:
|
||||||
|
/// a saved card, or a tag created in the nested picker even if the edit was
|
||||||
|
/// cancelled. An editor that wrote nothing leaves the columns, and so their
|
||||||
|
/// scroll positions, untouched.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="editor">The closed editor.</param>
|
||||||
|
/// <returns>A task completing after the refresh, if any.</returns>
|
||||||
|
private Task RefreshAfterEditorAsync(CardEditorDialogViewModel editor) =>
|
||||||
|
editor.WroteToWorkspace ? RefreshAfterWriteAsync() : Task.CompletedTask;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes a card, asking first when that confirmation is enabled.
|
/// Deletes a card, asking first when that confirmation is enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -314,17 +374,21 @@ public sealed partial class BoardViewModel : ViewModelBase
|
|||||||
await _dialogs.ShowMessageAsync(
|
await _dialogs.ShowMessageAsync(
|
||||||
Resources.Error_Operation_Title, Resources.Error_Operation_Message, exception.Message);
|
Resources.Error_Operation_Title, Resources.Error_Operation_Message, exception.Message);
|
||||||
}
|
}
|
||||||
RefreshAfterWrite();
|
await RefreshAfterWriteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Refreshes after a write and announces it.
|
/// Refreshes after a write and announces it; a failed refresh is reported
|
||||||
|
/// and not announced, so a broken workspace yields one read-failure dialog.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void RefreshAfterWrite()
|
/// <returns>A task completing after the refresh.</returns>
|
||||||
|
private async Task RefreshAfterWriteAsync()
|
||||||
|
{
|
||||||
|
if (await RefreshOrReportAsync())
|
||||||
{
|
{
|
||||||
Refresh();
|
|
||||||
DataWritten?.Invoke(this, EventArgs.Empty);
|
DataWritten?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Persists the sort option and re-sorts the board.
|
/// Persists the sort option and re-sorts the board.
|
||||||
@@ -333,6 +397,8 @@ public sealed partial class BoardViewModel : ViewModelBase
|
|||||||
partial void OnSelectedSortChanged(OptionItem value)
|
partial void OnSelectedSortChanged(OptionItem value)
|
||||||
{
|
{
|
||||||
_config.Sort.Card = (CardSortOption)value.Value;
|
_config.Sort.Card = (CardSortOption)value.Value;
|
||||||
Refresh();
|
|
||||||
|
// A property setter cannot await; the refresh reports its own failures.
|
||||||
|
_ = RefreshOrReportAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,12 @@ public sealed class TagBadgeViewModel : ViewModelBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Description => Tag.Description;
|
public string Description => Tag.Description;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the badge tooltip: the description, or <see langword="null"/> (no
|
||||||
|
/// tooltip at all) when the description is empty.
|
||||||
|
/// </summary>
|
||||||
|
public string? ToolTip => Tag.Description.Length > 0 ? Tag.Description : null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the badge fill: the tag's own color.
|
/// Gets the badge fill: the tag's own color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ namespace YKanBan.ViewModels.Dialogs;
|
|||||||
/// The card editor — one unit of work. Title, content and the tag assignment
|
/// The card editor — one unit of work. Title, content and the tag assignment
|
||||||
/// are edited in memory and written together in a single transaction on
|
/// are edited in memory and written together in a single transaction on
|
||||||
/// confirmation; cancelling writes nothing about the card or its assignment.
|
/// confirmation; cancelling writes nothing about the card or its assignment.
|
||||||
/// Confirming an existing card without effective changes writes nothing and
|
/// Confirming without effective changes writes nothing: an existing card keeps
|
||||||
/// keeps its timestamps. The only immediate write is the creation of a new tag
|
/// its timestamps, and a new card left empty is not created. The only immediate write is the creation of a new tag
|
||||||
/// in the nested tag picker (see <see cref="TagPickerDialogViewModel"/>).
|
/// in the nested tag picker (see <see cref="TagPickerDialogViewModel"/>).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class CardEditorDialogViewModel : DialogViewModelBase
|
public sealed partial class CardEditorDialogViewModel : DialogViewModelBase
|
||||||
@@ -113,10 +113,17 @@ public sealed partial class CardEditorDialogViewModel : DialogViewModelBase
|
|||||||
public ObservableCollection<TagBadgeViewModel> Tags { get; }
|
public ObservableCollection<TagBadgeViewModel> Tags { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the card written on confirmation; <see langword="null"/> until then.
|
/// Gets the card written on confirmation; <see langword="null"/> until then,
|
||||||
|
/// and after confirming a new card that was left empty.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CardModel? SavedCard { get; private set; }
|
public CardModel? SavedCard { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether this edit session wrote anything: the card on confirmation,
|
||||||
|
/// or a tag created in the nested picker (kept even when the edit is cancelled).
|
||||||
|
/// </summary>
|
||||||
|
public bool WroteToWorkspace { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the card title; the empty string means "no title".
|
/// Gets or sets the card title; the empty string means "no title".
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -156,10 +163,23 @@ public sealed partial class CardEditorDialogViewModel : DialogViewModelBase
|
|||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private async Task AddTagAsync()
|
private async Task AddTagAsync()
|
||||||
{
|
{
|
||||||
var picker = new TagPickerDialogViewModel(_repository, Tags.Select(tag => tag.Tag.Id).ToHashSet());
|
TagPickerDialogViewModel picker;
|
||||||
if (await _dialogs.ShowAsync(picker) && picker.PickedTag is { } picked)
|
try
|
||||||
{
|
{
|
||||||
Tags.Add(new TagBadgeViewModel(picked));
|
picker = new TagPickerDialogViewModel(_repository, Tags.Select(tag => tag.Tag.Id).ToHashSet());
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
// The picker lists the tags as it opens; a read failure must not escape the command.
|
||||||
|
await _dialogs.ShowReadFailedAsync(exception);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool picked = await _dialogs.ShowAsync(picker);
|
||||||
|
WroteToWorkspace |= picker.CreatedTag;
|
||||||
|
if (picked && picker.PickedTag is { } tag)
|
||||||
|
{
|
||||||
|
Tags.Add(new TagBadgeViewModel(tag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,13 +191,13 @@ public sealed partial class CardEditorDialogViewModel : DialogViewModelBase
|
|||||||
private void RemoveTag(TagBadgeViewModel tag) => Tags.Remove(tag);
|
private void RemoveTag(TagBadgeViewModel tag) => Tags.Remove(tag);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the card in one transaction and closes; an unchanged existing card
|
/// Writes the card in one transaction and closes; an unchanged card is not
|
||||||
/// is not written at all.
|
/// written at all, so a new card left empty is not created.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private void Confirm()
|
private void Confirm()
|
||||||
{
|
{
|
||||||
if (_existing is not null && !IsDirty)
|
if (!IsDirty)
|
||||||
{
|
{
|
||||||
SavedCard = _existing;
|
SavedCard = _existing;
|
||||||
Close(true);
|
Close(true);
|
||||||
@@ -190,6 +210,7 @@ public sealed partial class CardEditorDialogViewModel : DialogViewModelBase
|
|||||||
SavedCard = _existing is null
|
SavedCard = _existing is null
|
||||||
? _repository.AddCard(_columnId, CardTitle, Content, tagIds)
|
? _repository.AddCard(_columnId, CardTitle, Content, tagIds)
|
||||||
: _repository.UpdateCard(_existing.Id, CardTitle, Content, tagIds);
|
: _repository.UpdateCard(_existing.Id, CardTitle, Content, tagIds);
|
||||||
|
WroteToWorkspace = true;
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace YKanBan.ViewModels.Dialogs;
|
namespace YKanBan.ViewModels.Dialogs;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -18,8 +20,12 @@ public interface IDialogService
|
|||||||
/// Shows the system save-file dialog for a Markdown file.
|
/// Shows the system save-file dialog for a Markdown file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="suggestedFileName">The proposed file name.</param>
|
/// <param name="suggestedFileName">The proposed file name.</param>
|
||||||
/// <returns>The chosen local path, or <see langword="null"/> when the user cancelled.</returns>
|
/// <returns>
|
||||||
Task<string?> PickSaveFilePathAsync(string suggestedFileName);
|
/// A function opening the chosen file for writing, emptied first, or
|
||||||
|
/// <see langword="null"/> when the user cancelled. Nothing is created or
|
||||||
|
/// truncated until the function is called.
|
||||||
|
/// </returns>
|
||||||
|
Task<Func<Task<Stream>>?> PickSaveFileAsync(string suggestedFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -47,4 +53,16 @@ public static class DialogServiceExtensions
|
|||||||
/// <returns>A task completing when the dialog closes.</returns>
|
/// <returns>A task completing when the dialog closes.</returns>
|
||||||
public static Task ShowMessageAsync(this IDialogService dialogs, string title, string message, string? details = null) =>
|
public static Task ShowMessageAsync(this IDialogService dialogs, string title, string message, string? details = null) =>
|
||||||
dialogs.ShowAsync(new MessageDialogViewModel(title, message, details));
|
dialogs.ShowAsync(new MessageDialogViewModel(title, message, details));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reports that reading from the workspace failed, so the view may be stale.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dialogs">The dialog service.</param>
|
||||||
|
/// <param name="exception">The read failure; its untranslated message is shown as details.</param>
|
||||||
|
/// <returns>A task completing when the dialog closes.</returns>
|
||||||
|
public static Task ShowReadFailedAsync(this IDialogService dialogs, Exception exception)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(exception);
|
||||||
|
return dialogs.ShowMessageAsync(Resources.Error_Read_Title, Resources.Error_Read_Message, exception.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,23 +5,27 @@ namespace YKanBan.ViewModels.Dialogs;
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The settings dialog: language (restart to apply), theme and the four
|
/// The settings dialog: language (restart to apply), theme and the four
|
||||||
/// confirmation-dialog toggles. Nothing is applied until the user accepts;
|
/// confirmation-dialog toggles. A theme selection is previewed immediately;
|
||||||
/// cancelling or closing the window discards the changes.
|
/// everything else waits until the user accepts. Cancelling or closing the
|
||||||
|
/// window discards the changes and restores the theme the dialog opened with.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class SettingsDialogViewModel : ViewModelBase
|
public sealed partial class SettingsDialogViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
private readonly AppConfig _config;
|
private readonly AppConfig _config;
|
||||||
private readonly string _startupLanguage;
|
private readonly string _startupLanguage;
|
||||||
|
private readonly Action<ThemeOption> _applyTheme;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the dialog from the live configuration.
|
/// Initializes the dialog from the live configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="config">The live application configuration.</param>
|
/// <param name="config">The live application configuration.</param>
|
||||||
/// <param name="startupLanguage">The language applied at startup, for the restart notice.</param>
|
/// <param name="startupLanguage">The language applied at startup, for the restart notice.</param>
|
||||||
public SettingsDialogViewModel(AppConfig config, string startupLanguage)
|
/// <param name="applyTheme">Applies a theme to the running app; defaults to <see cref="App.ApplyTheme"/>.</param>
|
||||||
|
public SettingsDialogViewModel(AppConfig config, string startupLanguage, Action<ThemeOption>? applyTheme = null)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_startupLanguage = startupLanguage;
|
_startupLanguage = startupLanguage;
|
||||||
|
_applyTheme = applyTheme ?? App.ApplyTheme;
|
||||||
|
|
||||||
Languages =
|
Languages =
|
||||||
[
|
[
|
||||||
@@ -63,7 +67,8 @@ public sealed partial class SettingsDialogViewModel : ViewModelBase
|
|||||||
private OptionItem? selectedLanguage;
|
private OptionItem? selectedLanguage;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the selected theme; applied when the dialog is accepted.
|
/// Gets or sets the selected theme; applied to the running app as soon as it
|
||||||
|
/// changes, and saved to the configuration when the dialog is accepted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private OptionItem? selectedTheme;
|
private OptionItem? selectedTheme;
|
||||||
@@ -110,7 +115,6 @@ public sealed partial class SettingsDialogViewModel : ViewModelBase
|
|||||||
if (SelectedTheme is not null)
|
if (SelectedTheme is not null)
|
||||||
{
|
{
|
||||||
_config.Theme = (ThemeOption)SelectedTheme.Value;
|
_config.Theme = (ThemeOption)SelectedTheme.Value;
|
||||||
App.ApplyTheme(_config.Theme);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_config.Confirmations.DeleteCard = ConfirmDeleteCard;
|
_config.Confirmations.DeleteCard = ConfirmDeleteCard;
|
||||||
@@ -119,6 +123,23 @@ public sealed partial class SettingsDialogViewModel : ViewModelBase
|
|||||||
_config.Confirmations.DiscardEdit = ConfirmDiscardEdit;
|
_config.Confirmations.DiscardEdit = ConfirmDiscardEdit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Discards the working values and restores the theme the dialog opened with.
|
||||||
|
/// </summary>
|
||||||
|
public void Cancel() => _applyTheme(_config.Theme);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Previews a theme selection on the running app.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The new selection.</param>
|
||||||
|
partial void OnSelectedThemeChanged(OptionItem? value)
|
||||||
|
{
|
||||||
|
if (value is not null)
|
||||||
|
{
|
||||||
|
_applyTheme((ThemeOption)value.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Refreshes the restart notice after a language selection change.
|
/// Refreshes the restart notice after a language selection change.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ public sealed partial class TagPickerDialogViewModel : DialogViewModelBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TagModel? PickedTag { get; private set; }
|
public TagModel? PickedTag { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether <see cref="PickedTag"/> was newly created, i.e. written to the workspace.
|
||||||
|
/// </summary>
|
||||||
|
public bool CreatedTag { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the available tags matching <see cref="FilterText"/>.
|
/// Gets the available tags matching <see cref="FilterText"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -127,6 +132,7 @@ public sealed partial class TagPickerDialogViewModel : DialogViewModelBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
PickedTag = _repository.AddTag(NewName, color, NewDescription);
|
PickedTag = _repository.AddTag(NewName, color, NewDescription);
|
||||||
|
CreatedTag = true;
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -113,8 +113,18 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
/// <param name="folderPath">The workspace folder.</param>
|
/// <param name="folderPath">The workspace folder.</param>
|
||||||
/// <param name="session">The opened workspace session.</param>
|
/// <param name="session">The opened workspace session.</param>
|
||||||
private void ShowWorkspace(string folderPath, WorkspaceSession session)
|
private void ShowWorkspace(string folderPath, WorkspaceSession session)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Content = new WorkspaceViewModel(session, ShowSettings, ShowAbout, _services.Config, _dialogs);
|
Content = new WorkspaceViewModel(session, ShowSettings, ShowAbout, _services.Config, _dialogs);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// The first board read failed: the caller shows an error page, which holds no workspace.
|
||||||
|
_services.CloseWorkspace();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
Title = $"{new DirectoryInfo(folderPath).Name} - {Resources.App_Name}";
|
Title = $"{new DirectoryInfo(folderPath).Name} - {Resources.App_Name}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,10 +57,12 @@ public sealed partial class TagsViewModel : ViewModelBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reloads the tags with their usage counts.
|
/// Reloads the tags with their usage counts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <exception cref="Exception">Reading the workspace failed; the list is left unchanged.</exception>
|
||||||
public void Refresh()
|
public void Refresh()
|
||||||
{
|
{
|
||||||
|
IReadOnlyList<(TagModel Tag, long UsageCount)> tags = _repository.GetTagsWithUsage();
|
||||||
Tags.Clear();
|
Tags.Clear();
|
||||||
foreach ((TagModel tag, long usage) in _repository.GetTagsWithUsage())
|
foreach ((TagModel tag, long usage) in tags)
|
||||||
{
|
{
|
||||||
Tags.Add(new TagRowViewModel(this, tag, usage));
|
Tags.Add(new TagRowViewModel(this, tag, usage));
|
||||||
}
|
}
|
||||||
@@ -68,6 +70,25 @@ public sealed partial class TagsViewModel : ViewModelBase
|
|||||||
OnPropertyChanged(nameof(IsEmpty));
|
OnPropertyChanged(nameof(IsEmpty));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads like <see cref="Refresh"/>, but reports a read failure in a
|
||||||
|
/// message dialog instead of throwing.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><see langword="true"/> when the list was reloaded.</returns>
|
||||||
|
public async Task<bool> RefreshOrReportAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Refresh();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
await _dialogs.ShowReadFailedAsync(exception);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens the new-tag dialog.
|
/// Opens the new-tag dialog.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -81,7 +102,7 @@ public sealed partial class TagsViewModel : ViewModelBase
|
|||||||
(name, color, description) => _repository.AddTag(name, color, description));
|
(name, color, description) => _repository.AddTag(name, color, description));
|
||||||
if (await _dialogs.ShowAsync(dialog))
|
if (await _dialogs.ShowAsync(dialog))
|
||||||
{
|
{
|
||||||
AfterWrite();
|
await AfterWriteAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +119,7 @@ public sealed partial class TagsViewModel : ViewModelBase
|
|||||||
(name, color, description) => _repository.UpdateTag(tag.Id, name, color, description));
|
(name, color, description) => _repository.UpdateTag(tag.Id, name, color, description));
|
||||||
if (await _dialogs.ShowAsync(dialog))
|
if (await _dialogs.ShowAsync(dialog))
|
||||||
{
|
{
|
||||||
AfterWrite();
|
await AfterWriteAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,15 +151,19 @@ public sealed partial class TagsViewModel : ViewModelBase
|
|||||||
await _dialogs.ShowMessageAsync(
|
await _dialogs.ShowMessageAsync(
|
||||||
Resources.Error_Operation_Title, Resources.Error_Operation_Message, exception.Message);
|
Resources.Error_Operation_Title, Resources.Error_Operation_Message, exception.Message);
|
||||||
}
|
}
|
||||||
AfterWrite();
|
await AfterWriteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reloads the list and tells the board that tags changed.
|
/// Reloads the list and tells the board that tags changed; a failed reload
|
||||||
|
/// is reported and not announced.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void AfterWrite()
|
/// <returns>A task completing after the reload.</returns>
|
||||||
|
private async Task AfterWriteAsync()
|
||||||
|
{
|
||||||
|
if (await RefreshOrReportAsync())
|
||||||
{
|
{
|
||||||
Refresh();
|
|
||||||
TagsChanged?.Invoke(this, EventArgs.Empty);
|
TagsChanged?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -45,8 +45,8 @@ public sealed partial class WorkspaceViewModel : ViewModelBase
|
|||||||
_dialogs = dialogs;
|
_dialogs = dialogs;
|
||||||
Board = new BoardViewModel(session.Repository, config, dialogs);
|
Board = new BoardViewModel(session.Repository, config, dialogs);
|
||||||
Tags = new TagsViewModel(session.Repository, config, dialogs);
|
Tags = new TagsViewModel(session.Repository, config, dialogs);
|
||||||
Board.DataWritten += (_, _) => Tags.Refresh();
|
Board.DataWritten += async (_, _) => await Tags.RefreshOrReportAsync();
|
||||||
Tags.TagsChanged += (_, _) => Board.Refresh();
|
Tags.TagsChanged += async (_, _) => await Board.RefreshOrReportAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -96,18 +96,22 @@ public sealed partial class WorkspaceViewModel : ViewModelBase
|
|||||||
private async Task ExportAsync()
|
private async Task ExportAsync()
|
||||||
{
|
{
|
||||||
DateTimeOffset exportedAt = DateTimeOffset.Now;
|
DateTimeOffset exportedAt = DateTimeOffset.Now;
|
||||||
string? path = await _dialogs.PickSaveFilePathAsync(MarkdownExporter.BuildFileName(WorkspaceName, exportedAt));
|
try
|
||||||
if (path is null)
|
{
|
||||||
|
Func<Task<Stream>>? openTarget =
|
||||||
|
await _dialogs.PickSaveFileAsync(MarkdownExporter.BuildFileName(WorkspaceName, exportedAt));
|
||||||
|
if (openTarget is null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
// Read everything before opening the target, so a failed read leaves an existing file untouched.
|
||||||
{
|
|
||||||
WorkspaceRepository repository = Session.Repository;
|
WorkspaceRepository repository = Session.Repository;
|
||||||
string markdown = MarkdownExporter.Export(
|
string markdown = MarkdownExporter.Export(
|
||||||
WorkspaceName, repository.GetColumns(), repository.GetCards(), repository.GetTagsWithUsage(), exportedAt);
|
WorkspaceName, repository.GetColumns(), repository.GetCards(), repository.GetTagsWithUsage(), exportedAt);
|
||||||
await File.WriteAllTextAsync(path, markdown, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
|
await using Stream stream = await openTarget();
|
||||||
|
await using var writer = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
|
||||||
|
await writer.WriteAsync(markdown);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public sealed class DialogService : IDialogService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<string?> PickSaveFilePathAsync(string suggestedFileName)
|
public async Task<Func<Task<Stream>>?> PickSaveFileAsync(string suggestedFileName)
|
||||||
{
|
{
|
||||||
if (!_owners.TryPeek(out Window? owner))
|
if (!_owners.TryPeek(out Window? owner))
|
||||||
{
|
{
|
||||||
@@ -69,7 +69,28 @@ public sealed class DialogService : IDialogService
|
|||||||
new FilePickerFileType(YKanBan.Resources.Export_FileTypeMarkdown) { Patterns = ["*.md"] },
|
new FilePickerFileType(YKanBan.Resources.Export_FileTypeMarkdown) { Patterns = ["*.md"] },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
return file?.TryGetLocalPath();
|
if (file is null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A local file is replaced through the file system; a target without a
|
||||||
|
// local path (a sandboxed or virtual location) is written through the
|
||||||
|
// storage provider, emptied first because it may already have content.
|
||||||
|
string? localPath = file.TryGetLocalPath();
|
||||||
|
if (localPath is not null)
|
||||||
|
{
|
||||||
|
return () => Task.FromResult<Stream>(new FileStream(localPath, FileMode.Create, FileAccess.Write));
|
||||||
|
}
|
||||||
|
return async () =>
|
||||||
|
{
|
||||||
|
Stream stream = await file.OpenWriteAsync();
|
||||||
|
if (stream.CanSeek)
|
||||||
|
{
|
||||||
|
stream.SetLength(0);
|
||||||
|
}
|
||||||
|
return stream;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate x:DataType="board:TagBadgeViewModel">
|
<DataTemplate x:DataType="board:TagBadgeViewModel">
|
||||||
<Border Background="{Binding Background}" CornerRadius="10" Padding="8,2,4,2"
|
<Border Background="{Binding Background}" CornerRadius="10" Padding="8,2,4,2"
|
||||||
Margin="0,0,6,6" ToolTip.Tip="{Binding Description}">
|
Margin="0,0,6,6" ToolTip.Tip="{Binding ToolTip}">
|
||||||
<StackPanel Orientation="Horizontal" Spacing="2">
|
<StackPanel Orientation="Horizontal" Spacing="2">
|
||||||
<TextBlock Text="{Binding Name}" Foreground="{Binding Foreground}"
|
<TextBlock Text="{Binding Name}" Foreground="{Binding Foreground}"
|
||||||
VerticalAlignment="Center" FontSize="12"/>
|
VerticalAlignment="Center" FontSize="12"/>
|
||||||
|
|||||||
@@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
<StackPanel Margin="20" Spacing="16">
|
<StackPanel Margin="20" Spacing="16">
|
||||||
<TextBlock Text="{Binding Message}" TextWrapping="Wrap"/>
|
<TextBlock Text="{Binding Message}" TextWrapping="Wrap"/>
|
||||||
|
<!-- Every confirmation guards a destructive action, so Enter answers with the safe choice. -->
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
|
||||||
<Button Content="{Binding ConfirmLabel}" Command="{Binding ConfirmCommand}"
|
<Button Content="{Binding ConfirmLabel}" Command="{Binding ConfirmCommand}"
|
||||||
Classes="Danger" MinWidth="90" IsDefault="True"/>
|
Classes="Danger" MinWidth="90"/>
|
||||||
<Button Content="{x:Static lang:Resources.Common_Cancel}" Command="{Binding CancelCommand}"
|
<Button Content="{x:Static lang:Resources.Common_Cancel}" Command="{Binding CancelCommand}"
|
||||||
MinWidth="90" IsCancel="True"/>
|
MinWidth="90" IsDefault="True" IsCancel="True"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</dialogs:DialogWindow>
|
</dialogs:DialogWindow>
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using Avalonia.VisualTree;
|
using Avalonia.VisualTree;
|
||||||
@@ -85,6 +86,12 @@ public class DialogWindow : Window
|
|||||||
{
|
{
|
||||||
await _viewModel.RequestCancelAsync();
|
await _viewModel.RequestCancelAsync();
|
||||||
}
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
// An async void handler must not let a failure escape and end the
|
||||||
|
// process; the dialog simply stays open.
|
||||||
|
Debug.WriteLine(exception);
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_cancelPending = false;
|
_cancelPending = false;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ namespace YKanBan.Views.Dialogs;
|
|||||||
|
|
||||||
public partial class SettingsDialog : Window
|
public partial class SettingsDialog : Window
|
||||||
{
|
{
|
||||||
|
private bool _accepted;
|
||||||
|
|
||||||
public SettingsDialog()
|
public SettingsDialog()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -15,9 +17,24 @@ public partial class SettingsDialog : Window
|
|||||||
private void OnOkClick(object? sender, RoutedEventArgs e)
|
private void OnOkClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
(DataContext as SettingsDialogViewModel)?.Accept();
|
(DataContext as SettingsDialogViewModel)?.Accept();
|
||||||
|
_accepted = true;
|
||||||
Close(true);
|
Close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Closes without applying anything.</summary>
|
/// <summary>Closes without applying anything.</summary>
|
||||||
private void OnCancelClick(object? sender, RoutedEventArgs e) => Close(false);
|
private void OnCancelClick(object? sender, RoutedEventArgs e) => Close(false);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restores the previewed theme on every close that did not accept,
|
||||||
|
/// including the title-bar close button and Escape.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e">The event arguments.</param>
|
||||||
|
protected override void OnClosed(EventArgs e)
|
||||||
|
{
|
||||||
|
if (!_accepted)
|
||||||
|
{
|
||||||
|
(DataContext as SettingsDialogViewModel)?.Cancel();
|
||||||
|
}
|
||||||
|
base.OnClosed(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="640"
|
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="640"
|
||||||
x:Class="YKanBan.Views.MainWindow"
|
x:Class="YKanBan.Views.MainWindow"
|
||||||
x:DataType="vm:MainWindowViewModel"
|
x:DataType="vm:MainWindowViewModel"
|
||||||
Icon="/Assets/avalonia-logo.ico"
|
Icon="/Assets/ykanban.ico"
|
||||||
Title="{Binding Title}"
|
Title="{Binding Title}"
|
||||||
Width="1000" Height="640" MinWidth="720" MinHeight="480">
|
Width="1000" Height="640" MinWidth="720" MinHeight="480">
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
|
<ApplicationIcon>Assets\ykanban.ico</ApplicationIcon>
|
||||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -39,7 +40,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.3.22" />
|
<PackageReference Include="Avalonia" Version="11.3.22" />
|
||||||
<PackageReference Include="Avalonia.Desktop" Version="11.3.22" />
|
<PackageReference Include="Avalonia.Desktop" Version="11.3.22" />
|
||||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.22" />
|
|
||||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.22" />
|
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.22" />
|
||||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||||
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.22">
|
<PackageReference Include="Avalonia.Diagnostics" Version="11.3.22">
|
||||||
|
|||||||
+7
-2
@@ -30,7 +30,8 @@
|
|||||||
|
|
||||||
### A3 主题三态切换
|
### A3 主题三态切换
|
||||||
|
|
||||||
- [ ] 设置 → 主题 亮色 / 暗色 / 跟随系统 依次切换:**即时生效**,无重启提示
|
- [ ] 设置 → 主题 亮色 / 暗色 / 跟随系统 依次切换:下拉框一选中就**即时生效**(无需点确认),无重启提示
|
||||||
|
- [ ] 切换主题后点取消、按 Esc 或点标题栏关闭:恢复为打开设置时的主题;重启后仍是原主题
|
||||||
- [ ] 每种主题下检查:主窗口、看板列与卡片、标签 tab、全部模态、全部错误页颜色完整切换,无亮底暗字/暗底亮字残留
|
- [ ] 每种主题下检查:主窗口、看板列与卡片、标签 tab、全部模态、全部错误页颜色完整切换,无亮底暗字/暗底亮字残留
|
||||||
- [ ] 标签徽章在两种主题下均显示原色(§5.9 例外),文字颜色保持可读
|
- [ ] 标签徽章在两种主题下均显示原色(§5.9 例外),文字颜色保持可读
|
||||||
- [ ] 跟随系统:程序运行中切换 Windows 深浅色 → 程序跟随变化
|
- [ ] 跟随系统:程序运行中切换 Windows 深浅色 → 程序跟随变化
|
||||||
@@ -40,9 +41,10 @@
|
|||||||
|
|
||||||
- [ ] 同时打开两个实例(不同工作区)。实例 1 改排序,实例 2 改列宽;先关实例 1、后关实例 2 → `app.json` 为实例 2 的完整设置(后退出者覆盖,实例 1 的排序改动丢失——已接受)
|
- [ ] 同时打开两个实例(不同工作区)。实例 1 改排序,实例 2 改列宽;先关实例 1、后关实例 2 → `app.json` 为实例 2 的完整设置(后退出者覆盖,实例 1 的排序改动丢失——已接受)
|
||||||
- [ ] 打开两个实例,只在实例 1 改设置;先关实例 1,再关**未改过设置**的实例 2 → `app.json` 保持实例 1 写入的内容(未改设置的实例不写盘)
|
- [ ] 打开两个实例,只在实例 1 改设置;先关实例 1,再关**未改过设置**的实例 2 → `app.json` 保持实例 1 写入的内容(未改设置的实例不写盘)
|
||||||
|
- [ ] 删除 `app.json`,打开设置、不改任何项直接确认后退出 → `app.json` 不被创建;改一项再改回原值后退出 → `app.json` 被写出(脏标记按"改动过"判定)
|
||||||
- [ ] 处于错误页(例如参数错误页)的实例退出时不写 `app.json`(可先删除 `app.json`,退出后确认文件未被创建)
|
- [ ] 处于错误页(例如参数错误页)的实例退出时不写 `app.json`(可先删除 `app.json`,退出后确认文件未被创建)
|
||||||
- [ ] `app.json` 写成非法 JSON → 启动正常、使用默认值,生成 `app.json.bak`;改一次设置退出后 `app.json` 恢复为合法内容
|
- [ ] `app.json` 写成非法 JSON → 启动正常、使用默认值,生成 `app.json.bak`;改一次设置退出后 `app.json` 恢复为合法内容
|
||||||
- [ ] `app.json` 中单个字段非法(如 `"theme": "pink"`、列宽 `"custom-pixels": 9999`)→ 仅该字段回退默认,其余设置保留,不生成 `.bak`
|
- [ ] `app.json` 中单个字段非法(如 `"theme": "pink"`、列宽 `"custom-pixels": 9999`、类型不符如 `"delete-card": 0`、`"custom-pixels": "500"`)→ 仅该字段回退默认,其余设置保留,不生成 `.bak`
|
||||||
|
|
||||||
## B. 启动与错误页(M4 / M4R)
|
## B. 启动与错误页(M4 / M4R)
|
||||||
|
|
||||||
@@ -62,7 +64,9 @@
|
|||||||
|
|
||||||
- [ ] 新建列、编辑列(标题 + 描述);空标题、重名(含仅大小写不同,如 `Done` / `done`)→ 模态内提示错误,模态不关、输入保留
|
- [ ] 新建列、编辑列(标题 + 描述);空标题、重名(含仅大小写不同,如 `Done` / `done`)→ 模态内提示错误,模态不关、输入保留
|
||||||
- [ ] 删除列:确认框提示将删除 N 张卡片;确认后列与卡片一并删除
|
- [ ] 删除列:确认框提示将删除 N 张卡片;确认后列与卡片一并删除
|
||||||
|
- [ ] 各类确认框(删除卡片 / 列 / 标签、丢弃编辑)弹出后直接按回车 → 等同取消,不执行删除或丢弃
|
||||||
- [ ] 新建卡片、点击卡片编辑:标题可空;内容多行;`#id` / 创建时间 / 修改时间只读显示(新建时不显示)
|
- [ ] 新建卡片、点击卡片编辑:标题可空;内容多行;`#id` / 创建时间 / 修改时间只读显示(新建时不显示)
|
||||||
|
- [ ] 新建卡片什么都不填(标题、内容、标签均空)直接确认:不产生卡片;只加一个标签再确认:产生无标题卡片
|
||||||
- [ ] 编辑确认但内容未变 → 修改时间不变;改动后确认 → 修改时间刷新
|
- [ ] 编辑确认但内容未变 → 修改时间不变;改动后确认 → 修改时间刷新
|
||||||
- [ ] 有未保存改动时取消或点标题栏关闭 → 丢弃确认(开关开启时)
|
- [ ] 有未保存改动时取消或点标题栏关闭 → 丢弃确认(开关开启时)
|
||||||
- [ ] 卡片菜单"移动到列":卡片移动,修改时间**不**变
|
- [ ] 卡片菜单"移动到列":卡片移动,修改时间**不**变
|
||||||
@@ -72,6 +76,7 @@
|
|||||||
- [ ] 列宽:窄 240 / 标准 320 / 宽 480 / 手动 160–720;全局生效,重启保持
|
- [ ] 列宽:窄 240 / 标准 320 / 宽 480 / 手动 160–720;全局生效,重启保持
|
||||||
- [ ] 排序:id 升序 / 最后修改时间降序 / 标题升序(空标题在前);只影响卡片,列始终 id 序;重启保持
|
- [ ] 排序:id 升序 / 最后修改时间降序 / 标题升序(空标题在前);只影响卡片,列始终 id 序;重启保持
|
||||||
- [ ] 大数据量:用脚本向一列灌入约 10000 张卡片,滚动流畅、打开工作区无明显卡顿(虚拟化)
|
- [ ] 大数据量:用脚本向一列灌入约 10000 张卡片,滚动流畅、打开工作区无明显卡顿(虚拟化)
|
||||||
|
- [ ] 长列滚动到中部后打开某张卡片,不改动就取消或确认 → 各列滚动位置不变(未写库不刷新看板)
|
||||||
- [ ] 所有模态在父窗口居中;使用系统原生标题栏
|
- [ ] 所有模态在父窗口居中;使用系统原生标题栏
|
||||||
- [ ] 打开带输入框的模态时,第一个输入框自动获得焦点并全选
|
- [ ] 打开带输入框的模态时,第一个输入框自动获得焦点并全选
|
||||||
|
|
||||||
|
|||||||
+10
-7
@@ -16,7 +16,7 @@
|
|||||||
- 网络共享明确不支持;命令行参数边界;macOS 无参启动行为写入文档(§2.3、§4.1、附录)
|
- 网络共享明确不支持;命令行参数边界;macOS 无参启动行为写入文档(§2.3、§4.1、附录)
|
||||||
- 补充:导出转义规则、卡片列表虚拟化、模态窗口 FlowDirection、`Resources` 类名使用规则、CI osx-x64 运行器(§5、§7、§8)
|
- 补充:导出转义规则、卡片列表虚拟化、模态窗口 FlowDirection、`Resources` 类名使用规则、CI osx-x64 运行器(§5、§7、§8)
|
||||||
- 依赖:Avalonia 11.3.6 → 11.3.22,Semi.Avalonia 11.2.1.10 → 11.3.22(§7)
|
- 依赖:Avalonia 11.3.6 → 11.3.22,Semi.Avalonia 11.2.1.10 → 11.3.22(§7)
|
||||||
- 实现回补:搜索括号嵌套上限 64 层,空短语、短语紧贴文本、`key:` 后空白均为非法(§6.1、§6.2);导出表格单元格转义 `\`(§5.8);初始化中途锁冲突进锁冲突页、数据库文件缺失不静默新建(§4.4)
|
- 实现回补:搜索括号嵌套上限 64 层、单个表达式至多 256 个原子,空短语、短语紧贴文本、`key:` 后空白均为非法(§6.1、§6.2);导出表格单元格转义 `\`、默认文件名剔除非法字符(§5.8);初始化中途锁冲突进锁冲突页、数据库文件缺失不静默新建(§4.4);app.json 读不出 / 备份写不出 / 退出写盘失败均不阻断启动与退出(§4.3);主题下拉选中即预览、取消恢复(§5.6);空白新卡片确认不创建(§5.4);app.json 脏标记按"改动过"判定(改回原值仍写盘),字段类型不符不做隐式转换(§4.3);确认对话框回车默认取消(§5.5)
|
||||||
- 里程碑:标注 M0–M4 已完成,新增 **M4R(v1.9 回补)**(§9)
|
- 里程碑:标注 M0–M4 已完成,新增 **M4R(v1.9 回补)**(§9)
|
||||||
|
|
||||||
## 1. 项目概述
|
## 1. 项目概述
|
||||||
@@ -137,11 +137,13 @@ card_tags: (card_id, tag_id) 复合主键,双向 ON DELETE CASCADE
|
|||||||
|
|
||||||
- 强类型根对象 `AppConfig` 整体序列化,根含 `"version": 1` 迁移钩子
|
- 强类型根对象 `AppConfig` 整体序列化,根含 `"version": 1` 迁移钩子
|
||||||
- 字段:语言(`Language`:`"en"` 默认 / `"zh-Hans"`)、主题(`Theme`:`"follow-system"` 默认 / `"light"` / `"dark"`)、卡片排序选择(`"id"` 默认 / `"updated-at"` / `"title"`)、列宽、四类确认开关;枚举值序列化为 kebab-case 字符串
|
- 字段:语言(`Language`:`"en"` 默认 / `"zh-Hans"`)、主题(`Theme`:`"follow-system"` 默认 / `"light"` / `"dark"`)、卡片排序选择(`"id"` 默认 / `"updated-at"` / `"title"`)、列宽、四类确认开关;枚举值序列化为 kebab-case 字符串
|
||||||
- 写入时机:**应用退出时,仅当本实例在会话内修改过任一设置(脏标记)才整体写盘**(直接写,不做原子替换);错误页状态的实例、未改过设置的实例退出时不写。多实例均改过设置时后退出者覆盖(已接受);崩溃/断电丢失当次会话的设置变更(已接受:配置低价值)
|
- 写入时机:**应用退出时,仅当本实例在会话内修改过任一设置(脏标记)才整体写盘**(直接写,不做原子替换);脏标记按"是否改动过"判定:设置项被赋予与当前不同的值即置脏,改后又改回原值仍为脏;赋予相同值(如设置模态未改任何项直接确认)不置脏;读取时的字段回退不置脏;错误页状态的实例、未改过设置的实例退出时不写。多实例均改过设置时后退出者覆盖(已接受);崩溃/断电丢失当次会话的设置变更(已接受:配置低价值)
|
||||||
- 读取:
|
- 读取:
|
||||||
- 文件缺失 → 默认值启动照常运行(下次脏退出时自然创建)
|
- 文件缺失 → 默认值启动照常运行(下次脏退出时自然创建)
|
||||||
- JSON 本身无法解析 → 备份为 `app.json.bak`(覆盖旧备份)→ 以默认值启动
|
- JSON 本身无法解析 → 备份为 `app.json.bak`(覆盖旧备份)→ 以默认值启动
|
||||||
- JSON 完好但个别字段非法(未知枚举值、未知语言、列宽越界 160–720、类型不符等)→ **仅该字段回退默认值**,其余字段保留,不生成备份
|
- JSON 完好但个别字段非法(未知枚举值、未知语言、列宽越界 160–720、类型不符等;类型须严格匹配,不做隐式转换——如布尔字段写 `0` / `"false"`、整数字段写 `"500"` / `500.0` 均视为非法)→ **仅该字段回退默认值**,其余字段保留,不生成备份
|
||||||
|
- 文件存在但无法读取(IO / 权限错误)→ 以默认值启动;`.bak` 备份写不出时跳过备份,照常以默认值启动
|
||||||
|
- 退出写盘失败(IO / 权限错误)→ 忽略,等同丢失当次会话的设置变更;无论写盘成败都释放工作区锁与连接
|
||||||
|
|
||||||
### 4.4 全窗口错误页体系
|
### 4.4 全窗口错误页体系
|
||||||
|
|
||||||
@@ -199,20 +201,20 @@ card_tags: (card_id, tag_id) 复合主键,双向 ON DELETE CASCADE
|
|||||||
- 字段:标题(可空,空串 = 无标题)、内容(多行)、标签区、只读 `#id` / 创建时间 / 修改时间(新增时未生成则不显示)
|
- 字段:标题(可空,空串 = 无标题)、内容(多行)、标签区、只读 `#id` / 创建时间 / 修改时间(新增时未生成则不显示)
|
||||||
- 底部:确认(当前数据一次性写入数据库)/ 取消(丢弃更改)
|
- 底部:确认(当前数据一次性写入数据库)/ 取消(丢弃更改)
|
||||||
- 编辑对话框是一个工作单元:确认时一次性落库(单事务,见 §3),取消不产生任何卡片/指派写入;其余操作(删除、移动等)仍即时写库
|
- 编辑对话框是一个工作单元:确认时一次性落库(单事务,见 §3),取消不产生任何卡片/指派写入;其余操作(删除、移动等)仍即时写库
|
||||||
- 确认时内容无变化 → 不写库、不刷新时间戳
|
- 确认时内容无变化 → 不写库、不刷新时间戳;新建卡片时即标题、内容、标签均为空 → 确认不创建卡片(等同取消)
|
||||||
- 标签指派:编辑模态标签区显示已指派标签(各带 × 移除),"添加标签"按钮弹**嵌套模态** = 已有标签搜索/列表 + 新建标签入口,选中即添加,可反复打开继续添加下一个
|
- 标签指派:编辑模态标签区显示已指派标签(各带 × 移除),"添加标签"按钮弹**嵌套模态** = 已有标签搜索/列表 + 新建标签入口,选中即添加,可反复打开继续添加下一个
|
||||||
- **例外**:嵌套模态中新建的标签**立即写入 `tags` 表**(标签是全局实体);外层编辑取消时仅丢弃指派关系,新建的标签保留(与"tag 永不自动清理"一致)
|
- **例外**:嵌套模态中新建的标签**立即写入 `tags` 表**(标签是全局实体);外层编辑取消时仅丢弃指派关系,新建的标签保留(与"tag 永不自动清理"一致)
|
||||||
|
|
||||||
### 5.5 确认对话框开关
|
### 5.5 确认对话框开关
|
||||||
|
|
||||||
按类型分设独立开关:删除卡片 / 删除列 / 删除标签 / 丢弃编辑确认,承载于设置模态,存 app.json。
|
按类型分设独立开关:删除卡片 / 删除列 / 删除标签 / 丢弃编辑确认,承载于设置模态,存 app.json。确认对话框的默认按钮(回车)为"取消",执行操作须显式点击确认按钮。
|
||||||
|
|
||||||
### 5.6 设置模态
|
### 5.6 设置模态
|
||||||
|
|
||||||
入口 = 顶部显示区域右侧"设置"按钮,承载各类全局设置:
|
入口 = 顶部显示区域右侧"设置"按钮,承载各类全局设置:
|
||||||
|
|
||||||
- 语言选择(英文 / 简体中文),切换后显示"重启后生效"提示(提示文本本身为资源键)
|
- 语言选择(英文 / 简体中文),切换后显示"重启后生效"提示(提示文本本身为资源键)
|
||||||
- 主题选择(亮色 / 暗色 / 跟随系统),切换后**即时生效**,无重启提示(与语言项的行为差异)
|
- 主题选择(亮色 / 暗色 / 跟随系统),下拉框选中即**即时生效**(预览),无重启提示(与语言项的行为差异);点确认才写入配置,取消或关闭设置模态则恢复打开时的主题
|
||||||
- 四类确认开关(见 §5.5)
|
- 四类确认开关(见 §5.5)
|
||||||
|
|
||||||
### 5.7 关于模态
|
### 5.7 关于模态
|
||||||
@@ -221,7 +223,7 @@ card_tags: (card_id, tag_id) 复合主键,双向 ON DELETE CASCADE
|
|||||||
|
|
||||||
### 5.8 导出
|
### 5.8 导出
|
||||||
|
|
||||||
- 点击后弹系统保存文件对话框,默认文件名按当前语言生成(模式为资源键,**精确到秒**):英文 `MyRepo-export-20260930-142537.md`;中文 `MyRepo-导出-20260930-142537.md`
|
- 点击后弹系统保存文件对话框,默认文件名按当前语言生成(模式为资源键,**精确到秒**):英文 `MyRepo-export-20260930-142537.md`;中文 `MyRepo-导出-20260930-142537.md`;工作区名中任一平台的文件名非法字符(`<>:"/\|?*` 与控制字符)剔除,剔除后为空(如工作区位于 `/`)则用 `YKanBan`
|
||||||
- 人类可读格式,无回导需求;模板文本直接读取 ResX 资源(见 §8),导出语言跟随当前界面语言
|
- 人类可读格式,无回导需求;模板文本直接读取 ResX 资源(见 §8),导出语言跟随当前界面语言
|
||||||
- 导出范围为工作区全量数据,不受当前搜索筛选与卡片排序选项影响:列按 id 升序,列内卡片按 id 升序
|
- 导出范围为工作区全量数据,不受当前搜索筛选与卡片排序选项影响:列按 id 升序,列内卡片按 id 升序
|
||||||
- 全文时间戳(导出时间与卡片创建/修改时间)格式随语言:英文 `yyyy-MM-dd HH:mm:ss`;中文 `yyyy年M月d日 HH:mm`
|
- 全文时间戳(导出时间与卡片创建/修改时间)格式随语言:英文 `yyyy-MM-dd HH:mm:ss`;中文 `yyyy年M月d日 HH:mm`
|
||||||
@@ -295,6 +297,7 @@ phrase := '"' 一个或多个字符 '"' (内部支持转义:\" → 字面
|
|||||||
- **严格校验**:非法表达式弹出错误对话框,不执行搜索。非法集合:
|
- **严格校验**:非法表达式弹出错误对话框,不执行搜索。非法集合:
|
||||||
- 括号不配对
|
- 括号不配对
|
||||||
- 括号嵌套超过 64 层(防止递归解析栈溢出;顺序并列的括号组不计入深度)
|
- 括号嵌套超过 64 层(防止递归解析栈溢出;顺序并列的括号组不计入深度)
|
||||||
|
- 原子(裸词、短语、限定符)超过 256 个(编译出的 SQL 把全部原子串成一个表达式,SQLite 表达式深度上限为 1000)
|
||||||
- 运算符悬空(`bug AND`)、连续运算符(`a AND OR b`)
|
- 运算符悬空(`bug AND`)、连续运算符(`a AND OR b`)
|
||||||
- 限定符无值(`tag:`)、限定符值为裸 `AND`/`OR`(`tag:AND`,须写 `tag:"AND"`)
|
- 限定符无值(`tag:`)、限定符值为裸 `AND`/`OR`(`tag:AND`,须写 `tag:"AND"`)
|
||||||
- 短语引号未闭合、无效转义(`tag:"a\x"`)、裸词中出现 `\`
|
- 短语引号未闭合、无效转义(`tag:"a\x"`)、裸词中出现 `\`
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
<string>YKanBan</string>
|
<string>YKanBan</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>cn.blumia.code.yyc12345.ykanban</string>
|
<string>cn.blumia.code.yyc12345.ykanban</string>
|
||||||
|
<key>CFBundleIconFile</key>
|
||||||
|
<string>ykanban.icns</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>YKanBan</string>
|
<string>YKanBan</string>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
|
|||||||
Binary file not shown.
@@ -45,8 +45,9 @@ case "$rid" in
|
|||||||
;;
|
;;
|
||||||
osx-*)
|
osx-*)
|
||||||
app="$staging/YKanBan.app"
|
app="$staging/YKanBan.app"
|
||||||
mkdir -p "$app/Contents/MacOS"
|
mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources"
|
||||||
cp -R "$publish_dir/." "$app/Contents/MacOS/"
|
cp -R "$publish_dir/." "$app/Contents/MacOS/"
|
||||||
|
cp "$script_dir/macos/ykanban.icns" "$app/Contents/Resources/"
|
||||||
chmod +x "$app/Contents/MacOS/YKanBan"
|
chmod +x "$app/Contents/MacOS/YKanBan"
|
||||||
sed "s/@VERSION@/${version}/g" "$script_dir/macos/Info.plist" > "$app/Contents/Info.plist"
|
sed "s/@VERSION@/${version}/g" "$script_dir/macos/Info.plist" > "$app/Contents/Info.plist"
|
||||||
if command -v codesign > /dev/null 2>&1; then
|
if command -v codesign > /dev/null 2>&1; then
|
||||||
|
|||||||
Reference in new issue
Block a user