Skip to content

Commit

Permalink
Merge pull request #1178 from stevencohn/1143-copy-as-text
Browse files Browse the repository at this point in the history
Add Copy as Text command
  • Loading branch information
stevencohn authored Nov 21, 2023
2 parents d3862da + 901f35d commit 0b6ea68
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 0 deletions.
6 changes: 6 additions & 0 deletions OneMore/AddInCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ public async Task CopyAcrossCmd(IRibbonControl control)
=> await factory.Run<FillCellsCommand>(FillCells.CopyAcross);



[Command("ribCopyAsTextButton_Label", Keys.None, "ribEditMenu")]
public async Task CopyAsTextCmd(IRibbonControl control)
=> await factory.Run<CopyAsTextCommand>();


[Command("ribCopyDownButton_Label", Keys.None, "ribTableMenu")]
public async Task CopyDownCmd(IRibbonControl control)
=> await factory.Run<FillCellsCommand>(FillCells.CopyDown);
Expand Down
77 changes: 77 additions & 0 deletions OneMore/Commands/Edit/CopyAsTextCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//************************************************************************************************
// Copyright © 2023 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace River.OneMoreAddIn.Commands
{
using System.Linq;
using System.Threading.Tasks;
using River.OneMoreAddIn.Models;


/// <summary>
/// Copy the page or selected content as plan text onto the system clipboard
/// </summary>
internal class CopyAsTextCommand : Command
{
public CopyAsTextCommand()
{
}


public override async Task Execute(params object[] args)
{
using var one = new OneNote(out var page, out var _);
var cursor = page.GetTextCursor();

if (// cursor is not null if selection range is empty
cursor != null &&
// selection range is a single line containing a hyperlink
!(page.SelectionSpecial && page.SelectionScope == SelectionScope.Empty))
{
await CopyPageAsText(one, page);
}
else
{
// if only images are selected and no text content then copy entire page...

var other = page.Root.Descendants().Where(e =>
e.Attribute("selected")?.Value == "all" &&
e.Name.LocalName != "Image");

if (other.Any())
{
// some text was found, maybe with one or more images
var clipboard = new ClipboardProvider();
await clipboard.Copy();
await clipboard.SetText(await clipboard.GetText());
}
else
{
// no range selection or only an image was selected
await CopyPageAsText(one, page);
}
}
}


private async Task CopyPageAsText(OneNote one, Page page)
{
var updated = one.GetPage(OneNote.PageDetail.Basic);
var ns = updated.Root.GetNamespaceOfPrefix(OneNote.Prefix);

updated.Root.Elements(ns + "Outline").ForEach(e =>
{
e.SetAttributeValue("selected", "all");
});

await one.Update(updated);

var clipboard = new ClipboardProvider();
await clipboard.Copy();
await clipboard.SetText(await clipboard.GetText());

await one.Update(page);
}
}
}
1 change: 1 addition & 0 deletions OneMore/OneMore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<Compile Include="Commands\Edit\ColorizeDialog.Designer.cs">
<DependentUpon>ColorizeDialog.cs</DependentUpon>
</Compile>
<Compile Include="Commands\Edit\CopyAsTextCommand.cs" />
<Compile Include="Commands\Edit\DuplicateLineCommand.cs" />
<Compile Include="Commands\File\FileQuickNotesCommand.cs" />
<Compile Include="Commands\File\Markdown\MarkdownConverter.cs" />
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 @@ -2616,6 +2616,14 @@ ISO-code then comma then language name</comment>
<value>نسخ حدد المحتوى باعتباره تخفيض السعر</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Label" xml:space="preserve">
<value>نسخ كنص</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Screentip" xml:space="preserve">
<value>انسخ السياق المحدد كنص عادي</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyDownButton_Label" xml:space="preserve">
<value>انسخ</value>
<comment>ribbon</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 @@ -2620,6 +2620,14 @@ Polaroid</value>
<value>Kopieren Sie ausgewählte Inhalte als Markdown</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Label" xml:space="preserve">
<value>Als Text kopieren</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Screentip" xml:space="preserve">
<value>Kopieren Sie den ausgewählten Kontext als einfachen Text</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyDownButton_Label" xml:space="preserve">
<value>Abschreiben</value>
<comment>ribbon</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 @@ -2616,6 +2616,14 @@ polaroid</value>
<value>Copiar contenido seleccionado como descuento</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Label" xml:space="preserve">
<value>Copiar como texto</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Screentip" xml:space="preserve">
<value>Copiar el contexto seleccionado como texto sin formato</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyDownButton_Label" xml:space="preserve">
<value>Copia</value>
<comment>ribbon</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 @@ -2612,6 +2612,14 @@ Polaroïd</value>
<value>Copiez le contenu sélectionné en tant que démarquage</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Label" xml:space="preserve">
<value>Copier sous forme de texte</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Screentip" xml:space="preserve">
<value>Copier le contexte de sélection sous forme de texte brut</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyDownButton_Label" xml:space="preserve">
<value>Recopie</value>
<comment>ribbon</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 @@ -2637,6 +2637,14 @@ ISO-code then comma then language name</comment>
<value>העתק בחר תוכן כ- Markdown</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Label" xml:space="preserve">
<value>העתק כטקסט</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Screentip" xml:space="preserve">
<value>העתק את ההקשר של הבחירה כטקסט רגיל</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyDownButton_Label" xml:space="preserve">
<value>העתק למטה</value>
<comment>ribbon</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 @@ -2617,6 +2617,14 @@ Polaroid</value>
<value>Kopieer geselecteerde inhoud als prijsverlaging</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Label" xml:space="preserve">
<value>Kopieer als tekst</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Screentip" xml:space="preserve">
<value>Kopieer de geselecteerde context als platte tekst</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyDownButton_Label" xml:space="preserve">
<value>Naar beneden kopiëren</value>
<comment>ribbon</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 @@ -2629,6 +2629,14 @@ Polaroid</value>
<value>Skopiuj wybraną zawartość jako przecenę</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Label" xml:space="preserve">
<value>Skopiuj jako tekst</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Screentip" xml:space="preserve">
<value>Skopiuj wybrany kontekst jako zwykły tekst</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyDownButton_Label" xml:space="preserve">
<value>Skopiować</value>
<comment>ribbon</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 @@ -2617,6 +2617,14 @@ Polaroid.</value>
<value>Copiar conteúdo selecionado como remarcação</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Label" xml:space="preserve">
<value>Copiar como texto</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Screentip" xml:space="preserve">
<value>Copie o contexto selecionado como texto simples</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyDownButton_Label" xml:space="preserve">
<value>Anote</value>
<comment>ribbon</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2657,6 +2657,14 @@ Polaroid</value>
<value>Copy select content as markdown</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Label" xml:space="preserve">
<value>Copy as Text</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Screentip" xml:space="preserve">
<value>Copy select context as plain text</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyDownButton_Label" xml:space="preserve">
<value>Copy Down</value>
<comment>ribbon table</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,14 @@ ISO-code then comma then language name</comment>
</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Label" xml:space="preserve">
<value>复制为文本</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyAsTextButton_Screentip" xml:space="preserve">
<value>将选择的上下文复制为纯文本</value>
<comment>ribbon edit</comment>
</data>
<data name="ribCopyDownButton_Label" xml:space="preserve">
<value>
向下复制
Expand Down
6 changes: 6 additions & 0 deletions OneMore/Ribbon/Ribbon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@
getLabel="GetRibbonLabel"
getScreentip="GetRibbonScreentip"
onAction="CopyAsMarkdownCmd"/>
<button
id="ribCopyAsTextButton"
imageMso="Copy"
getLabel="GetRibbonLabel"
getScreentip="GetRibbonScreentip"
onAction="CopyAsTextCmd"/>
<button
id="ribDisableSpellCheckButton"
image="NoSpellCheck"
Expand Down

0 comments on commit 0b6ea68

Please sign in to comment.