Skip to content

Commit

Permalink
Reset and clear all checked tasks on page (stevencohn#1627)
Browse files Browse the repository at this point in the history
* Reset and clear all checked tasks on page
stevencohn#1626

* space
  • Loading branch information
stevencohn authored and weissm committed Oct 23, 2024
1 parent 7c7e3d7 commit aa221f0
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 40 deletions.
5 changes: 5 additions & 0 deletions OneMore/AddInCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,11 @@ public async Task ReportRemindersCmd(IRibbonControl control)
=> await factory.Run<ReportRemindersCommand>();


[Command("ribResetTasksButton_Label", Keys.None, "ribRemindersMenu")]
public async Task ResetTasksCmd(IRibbonControl control)
=> await factory.Run<ResetTasksCommand>();


[Command("ribRestoreAutosizeButton_Label", Keys.None, "ribCleanMenu")]
public async Task RestoreAutosizeCmd(IRibbonControl control)
=> await factory.Run<RestoreAutosizeCommand>();
Expand Down
151 changes: 113 additions & 38 deletions OneMore/Commands/Reminders/StrikeoutTasksCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,46 @@ namespace River.OneMoreAddIn.Commands
using System.Xml.Linq;


#region Wrappers
internal class ResetTasksCommand : EditTasksCommand
{
public ResetTasksCommand() : base() { }
public override Task Execute(params object[] args)
{
return base.Execute(ResetCmd);
}
}

internal class StrikeoutTasksCommand : EditTasksCommand
{
public StrikeoutTasksCommand() : base() { }
public override Task Execute(params object[] args)
{
return base.Execute(StrikeoutCmd);
}
}
#endregion


/// <summary>
/// Toggles strikethrough text next to all completed/incompleted tags
/// Resets completed tasks or toggles strikethrough text next to all
/// completed/incompleted tags
/// </summary>
internal class StrikeoutTasksCommand : Command
internal class EditTasksCommand : Command
{
private string strikeColor;
protected int ResetCmd = 0;
protected int StrikeoutCmd = 1;

private readonly List<int> symbols;
private readonly string strikeColor;

public StrikeoutTasksCommand()
{
}
private string fontColor;


public override async Task Execute(params object[] args)
public EditTasksCommand()
{
// built-in checkable/completeable tags
var symbols = new List<int> {
symbols = new List<int> {
3, // To do
8, // Client request
12, // Schedule meeting | Callback
Expand All @@ -37,6 +60,17 @@ public override async Task Execute(params object[] args)
95 // Discuss with manager
};

strikeColor = Settings.ColorsSheet.GetStrikethroughForeColor();
}


public override async Task Execute(params object[] args)
{
if (args.Length != 1)
{
return;
}

await using var one = new OneNote(out var page, out var ns);

var indexes =
Expand All @@ -58,9 +92,55 @@ public override async Task Execute(params object[] args)
return;
}

strikeColor = Settings.ColorsSheet.GetStrikethroughForeColor() ?? Style.Automatic;
var modified = (int)args[0] == ResetCmd
? ResetAllTasks(tags)
: StrikethroughAllTasks(tags);

if (modified)
{
await one.Update(page);
}
}


private bool ResetAllTasks(IEnumerable<XElement> tags)
{
var modified = false;
fontColor = Style.Automatic;

foreach (var tag in tags)
{
tag.GetAttributeValue<bool>("completed", out var completed);
if (completed)
{
tag.SetAttributeValue("completed", "false");

// each OE can only have 0..1 cdata but there can be more than one run after
// the tag if the text caret is position on the paragraph so must enumerate

var cdatas = tag.NodesAfterSelf().OfType<XElement>()
.Where(e => e.Name.LocalName == "T")
.Nodes().OfType<XCData>()
.ToList();

foreach (var cdata in cdatas)
{
if (!string.IsNullOrEmpty(cdata.Value)) // use Empty! not whitespace
{
modified |= RestyleWithoutStrikethrough(cdata);
}
}
}
}

return modified;
}


private bool StrikethroughAllTasks(IEnumerable<XElement> tags)
{
var modified = false;
fontColor = strikeColor ?? Style.Automatic;

foreach (var tag in tags)
{
Expand All @@ -85,10 +165,7 @@ public override async Task Execute(params object[] args)
}
}

if (modified)
{
await one.Update(page);
}
return modified;
}


Expand All @@ -99,7 +176,7 @@ private bool RestyleWithStrikethrough(XCData cdata)

var basicCss = new Style
{
Color = strikeColor,
Color = fontColor,
IsStrikethrough = true,
ApplyColors = true
}
Expand All @@ -122,7 +199,7 @@ private bool RestyleWithStrikethrough(XCData cdata)
if (!style.IsStrikethrough)
{
style.IsStrikethrough = true;
style.Color = strikeColor;
style.Color = fontColor;
style.ApplyColors = true;
span.SetAttributeValue("style", style.ToCss(withColor: true));

Expand All @@ -136,7 +213,7 @@ private bool RestyleWithStrikethrough(XCData cdata)
if (cdata.Parent.Attribute("style") is XAttribute attribute)
{
var style = new Style(attribute.Value);
style.Color = strikeColor;
style.Color = fontColor;
style.ApplyColors = true;
attribute.Value = style.ToCss(withColor: true);
}
Expand All @@ -150,38 +227,36 @@ private bool RestyleWithStrikethrough(XCData cdata)

private bool RestyleWithoutStrikethrough(XCData cdata)
{
bool Unstrike(XElement span)
{
// span always has exactly one style attribute
if (span.Attribute("style") is XAttribute attribute)
{
var style = new Style(attribute.Value);
if (style.IsStrikethrough || (strikeColor is not null && style.Color == strikeColor))
{
style.IsStrikethrough = false;
style.Color = Style.Automatic;
span.SetAttributeValue("style", style.ToCss(withColor: true));
return true;
}
}
return false;
}

var modified = false;
var wrapper = cdata.GetWrapper();

var emptyStyle = new Style();

// target only XElement/span nodes, ignore XText nodes
foreach (var span in wrapper
.Nodes().OfType<XElement>()
.Where(n => n.Name.LocalName == "span").ToList())
{
// span always and only have a style attribute
var style = new Style(span.Attribute("style").Value);
if (style.IsStrikethrough)
{
style.IsStrikethrough = false;

// this will override any inline span styling with the CData
style.Color = Style.Automatic;

if (style.Equals(emptyStyle))
{
span.ReplaceWith(new XText(span.Value));
}
else
{
span.SetAttributeValue("style", style.ToCss(withColor: true));
}
}

modified = true;
modified |= Unstrike(span);
}

modified |= Unstrike(cdata.Parent.Parent); // cdata->T->OE

if (modified)
{
cdata.Value = wrapper.GetInnerXml().Replace("&amp;", "&");
Expand Down
18 changes: 18 additions & 0 deletions OneMore/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.ar-SA.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3914,6 +3914,14 @@ ISO-code then comma then language name</comment>
<value>قم بإنشاء تقرير موجز للتذكيرات</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Label" xml:space="preserve">
<value>إعادة تعيين جميع المهام المكتملة</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Screentip" xml:space="preserve">
<value>قم بإلغاء تحديد وإعادة تعيين جميع المهام المكتملة في هذه الصفحة</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribRestoreAutosizeButton_Label" xml:space="preserve">
<value>استعادة عرض الحاوية</value>
<comment>ribbon clean</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3787,6 +3787,14 @@ Nach der letzten Gruppe</value>
<value>Generiert einen zusammenfassenden Bericht der Erinnerungen</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Label" xml:space="preserve">
<value>Alle abgeschlossenen Aufgaben zurücksetzen</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Screentip" xml:space="preserve">
<value>Deaktivieren Sie alle abgeschlossenen Aufgaben auf dieser Seite und setzen Sie sie zurück</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribRestoreAutosizeButton_Label" xml:space="preserve">
<value>Behälterbreiten wiederherstellen</value>
<comment>ribbon clean</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.es-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3914,6 +3914,14 @@ Después del último grupo</value>
<value>Generar un informe resumido de recordatorios</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Label" xml:space="preserve">
<value>Restablecer todas las tareas completadas</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Screentip" xml:space="preserve">
<value>Desmarque y restablezca todas las tareas completadas en esta página</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribRestoreAutosizeButton_Label" xml:space="preserve">
<value>Restaurar los anchos del contenedor</value>
<comment>ribbon clean</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3913,6 +3913,14 @@ Après le dernier groupe</value>
<value>Générer un rapport récapitulatif des rappels</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Label" xml:space="preserve">
<value>Réinitialiser toutes les tâches terminées</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Screentip" xml:space="preserve">
<value>Décochez et réinitialisez toutes les tâches terminées sur cette page</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribRestoreAutosizeButton_Label" xml:space="preserve">
<value>Restaurer les largeurs de conteneurs</value>
<comment>ribbon clean</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.he-IL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3913,6 +3913,14 @@ ISO-code then comma then language name</comment>
<value>צור דוח סיכום של תזכורות</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Label" xml:space="preserve">
<value>אפס את כל המשימות שהושלמו</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Screentip" xml:space="preserve">
<value>בטל את הסימון ואפס את כל המשימות שהושלמו בדף זה</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribRestoreAutosizeButton_Label" xml:space="preserve">
<value>שחזור רוחב מיכל</value>
<comment>ribbon clean</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.ja-JP.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3917,6 +3917,14 @@ ISO-code then comma then language name</comment>
<value>リマインダーの概要レポートを生成</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Label" xml:space="preserve">
<value>完了したタスクをすべてリセット</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Screentip" xml:space="preserve">
<value>このページ上の完了したタスクをすべてオフにしてリセットします</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribRestoreAutosizeButton_Label" xml:space="preserve">
<value>コンテナ幅を自動調整</value>
<comment>ribbon clean</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.nl-NL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3914,6 +3914,14 @@ Na de laatste groep</value>
<value>Genereer een overzichtsrapport van herinneringen</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Label" xml:space="preserve">
<value>Reset alle voltooide taken</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Screentip" xml:space="preserve">
<value>Schakel alle voltooide taken op deze pagina uit en reset ze</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribRestoreAutosizeButton_Label" xml:space="preserve">
<value>Herstel containerbreedtes</value>
<comment>ribbon clean</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.pl-PL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3915,6 +3915,14 @@ Po ostatniej grupie</value>
<value>Wygeneruj raport podsumowujący przypomnienia</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Label" xml:space="preserve">
<value>Zresetuj wszystkie ukończone zadania</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Screentip" xml:space="preserve">
<value>Odznacz i zresetuj wszystkie ukończone zadania na tej stronie</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribRestoreAutosizeButton_Label" xml:space="preserve">
<value>Przywróć szerokości pojemników</value>
<comment>ribbon clean</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.pt-BR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3914,6 +3914,14 @@ Depois do último grupo</value>
<value>Gerar um relatório resumido de lembretes</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Label" xml:space="preserve">
<value>Redefinir todas as tarefas concluídas</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribResetTasksButton_Screentip" xml:space="preserve">
<value>Desmarque e redefina todas as tarefas concluídas nesta página</value>
<comment>ribbon reminders</comment>
</data>
<data name="ribRestoreAutosizeButton_Label" xml:space="preserve">
<value>Restaure as larguras dos contêineres</value>
<comment>ribbon clean</comment>
Expand Down
Loading

0 comments on commit aa221f0

Please sign in to comment.