Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 87d09c8

Browse files
authored
Merge pull request #1 from lutz/dev
Dev
2 parents 36321ea + b988a5d commit 87d09c8

6 files changed

Lines changed: 304 additions & 7 deletions

File tree

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
---
2-
type: Addon
3-
id: CA013
4-
license: MIT
5-
---
6-
71
# CopyTextOfSelectedAnnotationAddon
82

9-
## Description
3+
This add-on adds a new function to the PDF viewer of Citavi to copy the text of a selected Citavi highlight. Select **one** Citavi Highlight and use the key combination <kbd>SHIFT</kbd>+<kbd>C</kbd> to copy the text to the clipboard.
4+
5+
The following Citavi highlights are supported:
6+
7+
- *Direct quotation*
8+
- *Indirect quotation*
9+
- *Summary*
10+
- *Comment*
11+
- *Task*
12+
- *Abstract*
13+
- *Table of contents*
14+
- *Highlight*
15+
- *Highlight in red*
1016

1117
## Disclaimer
1218

1319
>There are no support claims by the company **Swiss Academic Software GmbH**, the provider of **Citavi** or other liability claims for problems or data loss. Any use is at your own risk. All rights to the name **Citavi** and any logos used are owned by **Swiss Academic Software GmbH**.
20+
21+
## License
22+
23+
This project is licensed under the [MIT](LICENSE) License
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29230.47
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CopyTextOfSelectedAnnotationAddon", "CopyTextOfSelectedAnnotationAddon\CopyTextOfSelectedAnnotation.csproj", "{946ACAB0-23BA-4D8E-9AD3-FA1C01754525}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{946ACAB0-23BA-4D8E-9AD3-FA1C01754525}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{946ACAB0-23BA-4D8E-9AD3-FA1C01754525}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{946ACAB0-23BA-4D8E-9AD3-FA1C01754525}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{946ACAB0-23BA-4D8E-9AD3-FA1C01754525}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {C1771436-1C71-435B-A951-16A7B1B168CD}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using SwissAcademic.Citavi;
2+
using SwissAcademic.Citavi.Shell;
3+
using SwissAcademic.Citavi.Shell.Controls.Preview;
4+
using SwissAcademic.Controls;
5+
using SwissAcademic.Pdf.Analysis;
6+
using System;
7+
using System.Linq;
8+
using System.Windows.Forms;
9+
10+
namespace CopyTextOfSelectedAnnotation
11+
{
12+
public class Addon : CitaviAddOn<MainForm>
13+
{
14+
#region Constants
15+
16+
const string Keys_Button_CopyTextOfSelectedAnnotation = "CopyTextOfSelectedAnnotation.Button.CopyTextOfSelectedAnnotation";
17+
18+
#endregion
19+
20+
#region Methods
21+
22+
public override void OnHostingFormLoaded(MainForm mainForm)
23+
{
24+
var button = mainForm
25+
.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar)
26+
.GetCommandbarMenu(MainFormPreviewCommandbarMenuId.Tools)
27+
.AddCommandbarButton(Keys_Button_CopyTextOfSelectedAnnotation, "CopyTextOfSelectedAnnotation");
28+
button.Shortcut = (Shortcut)(Keys.Shift | Keys.C);
29+
button.Visible = false;
30+
31+
base.OnHostingFormLoaded(mainForm);
32+
}
33+
public override void OnBeforePerformingCommand(MainForm mainForm, BeforePerformingCommandEventArgs e)
34+
{
35+
if (e.Key.Equals(Keys_Button_CopyTextOfSelectedAnnotation, StringComparison.OrdinalIgnoreCase))
36+
{
37+
ExtractTextFromEntity(mainForm, mainForm.PreviewControl.GetSelectedCitaviEntity());
38+
e.Handled = true;
39+
}
40+
41+
base.OnBeforePerformingCommand(mainForm, e);
42+
}
43+
44+
public override void OnApplicationIdle(MainForm mainForm)
45+
{
46+
var button = mainForm
47+
.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar)
48+
.GetCommandbarMenu(MainFormPreviewCommandbarMenuId.Tools)
49+
.GetCommandbarButton(Keys_Button_CopyTextOfSelectedAnnotation);
50+
if (button != null)
51+
{
52+
button.Tool.SharedProps.Enabled = mainForm.PreviewControl.ActivePreviewType == PreviewType.Pdf
53+
&& mainForm.PreviewControl.GetSelectedCitaviEntity().IsSupportedCitaviEntity();
54+
}
55+
base.OnApplicationIdle(mainForm);
56+
}
57+
58+
void ExtractTextFromEntity(MainForm mainForm, ICitaviEntity citaviEntity)
59+
{
60+
if (citaviEntity.EntityLinks.FirstOrDefault(link => link.Indication.Equals("PdfKnowledgeItem", StringComparison.OrdinalIgnoreCase))?.Target is Annotation annotation)
61+
{
62+
var documentParser = new DocumentParser(mainForm.PreviewControl.GetPdfViewControl()?.Document)
63+
{
64+
ParseType = ParseType.Text,
65+
DetectParagraphAlignment = true,
66+
ExtractIdentifier = false
67+
};
68+
69+
var text = documentParser
70+
.Run(annotation.Quads.Where(q => !q.IsContainer).ToList())?
71+
.GetDocumentText()?
72+
.ContentAsPlainText;
73+
if (!string.IsNullOrEmpty(text)) Clipboard.SetText(text);
74+
}
75+
}
76+
77+
#endregion
78+
}
79+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{946ACAB0-23BA-4D8E-9AD3-FA1C01754525}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>CopyTextOfSelectedAnnotation</RootNamespace>
12+
<AssemblyName>CopyTextOfSelectedAnnotationAddon</AssemblyName>
13+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>C:\Program Files (x86)\Citavi 6\AddOns</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
<StartAction>Program</StartAction>
26+
<StartProgram>C:\Program Files (x86)\Citavi 6\bin\Citavi.exe</StartProgram>
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<StartAction>Program</StartAction>
31+
<StartProgram>C:\Program Files (x86)\Citavi 6\bin\Citavi.exe</StartProgram>
32+
<DebugType>none</DebugType>
33+
<Optimize>true</Optimize>
34+
<OutputPath>..\bin\Release\</OutputPath>
35+
<DefineConstants>TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
<PlatformTarget>AnyCPU</PlatformTarget>
39+
</PropertyGroup>
40+
<ItemGroup>
41+
<Reference Include="Citavi">
42+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Citavi 6\bin\Citavi.exe</HintPath>
43+
<Private>False</Private>
44+
</Reference>
45+
<Reference Include="Infragistics4.Win.UltraWinToolbars.v11.2, Version=11.2.20112.2135, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb, processorArchitecture=MSIL">
46+
<SpecificVersion>False</SpecificVersion>
47+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Citavi 6\bin\Infragistics4.Win.UltraWinToolbars.v11.2.dll</HintPath>
48+
<Private>False</Private>
49+
</Reference>
50+
<Reference Include="PDFNet">
51+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Citavi 6\bin\PDFNet\x86\PDFNet.dll</HintPath>
52+
<Private>False</Private>
53+
</Reference>
54+
<Reference Include="PresentationCore" />
55+
<Reference Include="PresentationFramework" />
56+
<Reference Include="SwissAcademic">
57+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Citavi 6\bin\SwissAcademic.dll</HintPath>
58+
<Private>False</Private>
59+
</Reference>
60+
<Reference Include="SwissAcademic.Citavi">
61+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Citavi 6\bin\SwissAcademic.Citavi.dll</HintPath>
62+
<Private>False</Private>
63+
</Reference>
64+
<Reference Include="SwissAcademic.Citavi.Controls.Wpf">
65+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Citavi 6\bin\SwissAcademic.Citavi.Controls.Wpf.dll</HintPath>
66+
<Private>False</Private>
67+
</Reference>
68+
<Reference Include="SwissAcademic.Controls">
69+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Citavi 6\bin\SwissAcademic.Controls.dll</HintPath>
70+
<Private>False</Private>
71+
</Reference>
72+
<Reference Include="SwissAcademic.Pdf">
73+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Citavi 6\bin\SwissAcademic.Pdf.dll</HintPath>
74+
<Private>False</Private>
75+
</Reference>
76+
<Reference Include="System " />
77+
<Reference Include="System.Core " />
78+
<Reference Include="System.Xml.Linq" />
79+
<Reference Include="System.Data.DataSetExtensions" />
80+
<Reference Include="Microsoft.CSharp" />
81+
<Reference Include="System.Data" />
82+
<Reference Include="System.Xml" />
83+
<Reference Include="System.Drawing" />
84+
<Reference Include="System.Windows.Forms" />
85+
<Reference Include="WindowsBase" />
86+
</ItemGroup>
87+
<ItemGroup>
88+
<Compile Include="Addon.cs" />
89+
<Compile Include="Core\Extensions.cs" />
90+
<Compile Include="Properties\AssemblyInfo.cs" />
91+
</ItemGroup>
92+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
93+
<PropertyGroup>
94+
<PostBuildEvent>if $(ConfigurationName) == Release cmd /x /c mkdir "$(SolutionDir)..\packages\"
95+
if $(ConfigurationName) == Release (powershell Compress-Archive -Path '$(TargetDir)*' -DestinationPath '$(SolutionDir)..\packages\$(TargetName).zip' -Force)
96+
</PostBuildEvent>
97+
</PropertyGroup>
98+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using SwissAcademic.Citavi;
2+
using SwissAcademic.Citavi.Controls.Wpf;
3+
using SwissAcademic.Citavi.Shell.Controls.Preview;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Reflection;
7+
8+
namespace CopyTextOfSelectedAnnotation
9+
{
10+
public static class Extensions
11+
{
12+
#region SwissAcademic.Citavi.Shell.Controls.Preview.PreviewControl
13+
14+
public static PdfViewControl GetPdfViewControl(this PreviewControl previewControl)
15+
{
16+
return previewControl
17+
.GetType()
18+
.GetProperty("PdfViewControl", BindingFlags.Instance | BindingFlags.NonPublic)?
19+
.GetValue(previewControl) as PdfViewControl;
20+
}
21+
22+
23+
static List<AdornmentCanvas> GetSelectedAdornmentCanvas(this PreviewControl previewControl)
24+
{
25+
26+
return previewControl
27+
.GetPdfViewControl()?
28+
.Tool
29+
.GetType()
30+
.GetField("SelectedAdornmentContainers", BindingFlags.Instance | BindingFlags.NonPublic)?
31+
.GetValue(previewControl.GetPdfViewControl()?.Tool) as List<AdornmentCanvas>;
32+
}
33+
34+
public static ICitaviEntity GetSelectedCitaviEntity(this PreviewControl previewControl)
35+
{
36+
return previewControl?
37+
.GetSelectedAdornmentCanvas()?
38+
.FirstOrDefault()?
39+
.CitaviEntity;
40+
}
41+
42+
public static bool IsSupportedCitaviEntity(this ICitaviEntity citaviEntity)
43+
{
44+
return citaviEntity is KnowledgeItem || citaviEntity is TaskItem;
45+
}
46+
47+
#endregion
48+
}
49+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("CopyTextOfSelectedAnnotation")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("CopyTextOfSelectedAnnotationAddon")]
13+
[assembly: AssemblyCopyright("Copyright © 2019 Daniel Lutz")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("946acab0-23ba-4d8e-9ad3-fa1c01754525")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)