Skip to content

Commit 8e49cc8

Browse files
authored
1903 allow dup fav in dialog (#1904)
* allow dup page by id rather than path * auto-correct name
1 parent e30f507 commit 8e49cc8

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

OneMore/Commands/Favorites/FavoritesDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ private async void AddCurrentPage(object sender, EventArgs e)
432432
Favorite favorite = null;
433433
while (index < source.Count && favorite == null)
434434
{
435-
if (source[index].Location.EqualsICIC(info.Path))
435+
if (source[index].ObjectID == info.PageId)
436436
{
437437
favorite = source[index];
438438
}

OneMore/Commands/Favorites/FavoritesProvider.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public async Task ValidateFavorites(List<Favorite> favorites)
222222
if (!string.IsNullOrWhiteSpace(f.NotebookID) &&
223223
!string.IsNullOrWhiteSpace(f.ObjectID))
224224
{
225-
await ConfirmByID(f);
225+
updated = await ConfirmByID(f) || updated;
226226
}
227227

228228
// ConfirmByID would only return either Known or Unknown
@@ -252,7 +252,7 @@ public async Task ValidateFavorites(List<Favorite> favorites)
252252
}
253253

254254

255-
private async Task ConfirmByID(Favorite favorite)
255+
private async Task<bool> ConfirmByID(Favorite favorite)
256256
{
257257
XElement notebook = null;
258258
if (notebooks.ContainsKey(favorite.NotebookID))
@@ -280,15 +280,33 @@ private async Task ConfirmByID(Favorite favorite)
280280
}
281281

282282
if (notebook is not null &&
283-
notebook.Descendants().Any(e => e.Attribute("ID")?.Value == favorite.ObjectID))
283+
notebook.Descendants().First(e => e.Attribute("ID")?.Value == favorite.ObjectID) is XElement node)
284284
{
285285
favorite.Status = FavoriteStatus.Known;
286+
287+
var name = node.Attribute("name").Value;
288+
if (favorite.Name != name)
289+
{
290+
// auto-correct page/section name
291+
favorite.Name = name;
292+
293+
if (name.Length > 50)
294+
{
295+
name = name.Substring(0, 50) + "...";
296+
}
297+
298+
favorite.Root.Attribute("label").Value = name;
299+
300+
return true;
301+
}
286302
}
287303
else
288304
{
289305
logger.WriteLine($"broken link to favorite notebook {favorite.Location}");
290306
favorite.Status = FavoriteStatus.Unknown;
291307
}
308+
309+
return false;
292310
}
293311

294312

0 commit comments

Comments
 (0)