Skip to content

Commit

Permalink
fix ctrl+r
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Dec 28, 2024
1 parent 0299332 commit fc83324
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
23 changes: 17 additions & 6 deletions OneMore/Commands/References/CheckUrlsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,18 @@ private async Task Execute(ProgressDialog progress, CancellationToken token)
await BuildHyperlinkMap(scope, progress, token);
}

if (token.IsCancellationRequested)
{
return;
}

progress.SetMaximum(candidates.Count);
progress.SetMessage(string.Format(Resx.CheckUrlsCommand_checkingMsg, candidates.Count));

try
{
await ValidateUrls(progress);
if (badCount > 0)
await ValidateUrls(progress, token);
if (badCount > 0 && !token.IsCancellationRequested)
{
await one.Update(page);
}
Expand Down Expand Up @@ -182,7 +187,7 @@ private async Task BuildHyperlinkMap(
}


private async Task ValidateUrls(ProgressDialog progress)
private async Task ValidateUrls(ProgressDialog progress, CancellationToken token)
{
// parallelize internet access for all chosen hyperlinks on the page...

Expand All @@ -192,22 +197,28 @@ private async Task ValidateUrls(ProgressDialog progress)
foreach (var candidate in candidates)
{
// do not use await in the body loop; just build list of tasks
tasks.Add(ValidateUrl(candidate, progress));
tasks.Add(ValidateUrl(candidate, progress, token));
}

await Task.WhenAll(tasks.ToArray());
//var count = tasks.Sum(t => t.IsFaulted ? 0 : t.Result);
}


private async Task ValidateUrl(XElement element, ProgressDialog progress)
private async Task ValidateUrl(
XElement element, ProgressDialog progress, CancellationToken token)
{
var cdata = element.GetCData();
var wrapper = cdata.GetWrapper();

var count = badCount;
foreach (var anchor in wrapper.Elements("a"))
{
if (token.IsCancellationRequested)
{
return;
}

progress.Increment();

var href = anchor.Attribute("href")?.Value;
Expand Down Expand Up @@ -246,7 +257,7 @@ private async Task ValidateUrl(XElement element, ProgressDialog progress)
}
}

if (badCount > count)
if (badCount > count && !token.IsCancellationRequested)
{
cdata.ReplaceWith(wrapper.GetInnerXml());
}
Expand Down
13 changes: 12 additions & 1 deletion OneMore/UI/MoreForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class MoreForm : Form, IOneMoreWindow
protected readonly ThemeManager manager;
protected readonly ILogger logger;

private ApplicationContext appContext;
private bool modeless = false;


Expand Down Expand Up @@ -117,13 +118,23 @@ public void RunModeless(EventHandler closedAction = null, int topDelta = 0)
ModelessClosed += (sender, e) => { closedAction(sender, e); };
}

Application.Run(new ApplicationContext(this));
if (Application.MessageLoop)
{
// starting a second message loop on a single thread is not a valid operation
// so just display the form if we already have a message loop
Show();
return;
}

appContext = new ApplicationContext(this);
Application.Run(appContext);
}


protected override void OnFormClosed(FormClosedEventArgs e)
{
base.OnFormClosed(e);
appContext?.Dispose();
ModelessClosed?.Invoke(this, e);
}

Expand Down

0 comments on commit fc83324

Please sign in to comment.