This repository has been archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev
- Loading branch information
Showing
9 changed files
with
644 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
--- | ||
type: Addon | ||
id: CA011 | ||
license: MIT | ||
--- | ||
|
||
# SetPDFSelectionAsAddon | ||
|
||
## Description | ||
This add-on adds new commands to the **More** menu of Citavi's PDF Viewer to take the text selection as title data. | ||
|
||
## Disclaimer | ||
|
||
>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**. | ||
## License | ||
|
||
This project is licensed under the [MIT](LICENSE) License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29215.179 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetPDFSelectionAsAddon", "SetPDFSelectionAsAddon\SetPDFSelectionAs.csproj", "{27EF81E0-5AE2-47A6-AE23-780EE8A0F3E0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{27EF81E0-5AE2-47A6-AE23-780EE8A0F3E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{27EF81E0-5AE2-47A6-AE23-780EE8A0F3E0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{27EF81E0-5AE2-47A6-AE23-780EE8A0F3E0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{27EF81E0-5AE2-47A6-AE23-780EE8A0F3E0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {669B6581-6A19-40B0-9488-B1B2D61164DD} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using SetPDFSelectionAs.Properties; | ||
using SwissAcademic.Citavi; | ||
using SwissAcademic.Citavi.Shell; | ||
using SwissAcademic.Controls; | ||
|
||
namespace SetPDFSelectionAs | ||
{ | ||
public class Addon : CitaviAddOn<MainForm> | ||
{ | ||
#region Constants | ||
|
||
const string Keys_Button_Title = "SetPDFSelectionAsAddon.Button_Title"; | ||
const string Keys_Button_Author_FirstName_LastName = "SetPDFSelectionAsAddon.Button_Author_FirstName_LastName"; | ||
const string Keys_Button_Author_LastName_FirstName = "SetPDFSelectionAsAddon.Button_Author_LastName_FirstName"; | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
public override void OnHostingFormLoaded(MainForm mainForm) | ||
{ | ||
var button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).InsertCommandbarButton(3, Keys_Button_Title, SetPDFSelectionAsAddonResources.Button_Title); | ||
button.HasSeparator = true; | ||
|
||
mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).InsertCommandbarButton(4, Keys_Button_Author_FirstName_LastName, SetPDFSelectionAsAddonResources.Button_Author_FirstName_LastName); | ||
mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).InsertCommandbarButton(5, Keys_Button_Author_LastName_FirstName, SetPDFSelectionAsAddonResources.Button_Author_LastName_FirstName); | ||
|
||
base.OnHostingFormLoaded(mainForm); | ||
} | ||
|
||
public override void OnLocalizing(MainForm mainForm) | ||
{ | ||
var button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).GetCommandbarButton(Keys_Button_Title); | ||
if (button != null) button.Text = SetPDFSelectionAsAddonResources.Button_Title; | ||
|
||
button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).GetCommandbarButton(Keys_Button_Author_FirstName_LastName); | ||
if (button != null) button.Text = SetPDFSelectionAsAddonResources.Button_Author_FirstName_LastName; | ||
|
||
button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).GetCommandbarButton(Keys_Button_Author_LastName_FirstName); | ||
if (button != null) button.Text = SetPDFSelectionAsAddonResources.Button_Author_LastName_FirstName; | ||
|
||
base.OnLocalizing(mainForm); | ||
} | ||
|
||
public override void OnBeforePerformingCommand(MainForm mainForm, BeforePerformingCommandEventArgs e) | ||
{ | ||
|
||
var reference = mainForm.PreviewControl.ActiveLocation?.Reference; | ||
|
||
if (reference != null) | ||
{ | ||
e.Handled = true; | ||
switch (e.Key) | ||
{ | ||
case (Keys_Button_Title): | ||
{ | ||
var selectionAsText = mainForm.PreviewControl.GetSelectionAsText(); | ||
reference.Title = selectionAsText; | ||
mainForm.PreviewControl.ClearSelection(); | ||
break; | ||
} | ||
|
||
case (Keys_Button_Author_FirstName_LastName): | ||
{ | ||
var selectionAsText = mainForm.PreviewControl.GetSelectionAsText(); | ||
var persons = PersonTextParser.ParseRawTextInFirstNameLastNameSequence(reference.Project, selectionAsText); | ||
reference.Authors.AddRange(persons); | ||
mainForm.PreviewControl.ClearSelection(); | ||
break; | ||
} | ||
case (Keys_Button_Author_LastName_FirstName): | ||
{ | ||
var selectionAsText = mainForm.PreviewControl.GetSelectionAsText(); | ||
var person = PersonTextParser.ParseSinglePersonName(selectionAsText, PersonTextParserSettings.CarriageReturnOrSemicolon_LastNameFirstnameWithComma, reference.Project); | ||
reference.Authors.Add(person); | ||
mainForm.PreviewControl.ClearSelection(); | ||
break; | ||
} | ||
|
||
default: | ||
{ | ||
e.Handled = false; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
base.OnBeforePerformingCommand(mainForm, e); | ||
} | ||
|
||
public override void OnApplicationIdle(MainForm mainForm) | ||
{ | ||
if (mainForm.PreviewControl.ActivePreviewType == SwissAcademic.Citavi.Shell.Controls.Preview.PreviewType.Pdf) | ||
{ | ||
var pdfViewer = mainForm.PreviewControl.GetPdfViewer(); | ||
var isTextSelected = pdfViewer.GetSelectedContentType() == SwissAcademic.Citavi.Controls.Wpf.ContentType.Text; | ||
|
||
var button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).GetCommandbarButton(Keys_Button_Title); | ||
if (button != null) button.Visible = isTextSelected; | ||
|
||
button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).GetCommandbarButton(Keys_Button_Author_FirstName_LastName); | ||
if (button != null) button.Visible = isTextSelected; | ||
|
||
button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).GetCommandbarButton(Keys_Button_Author_LastName_FirstName); | ||
if (button != null) button.Visible = isTextSelected; | ||
} | ||
else | ||
{ | ||
var button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).GetCommandbarButton(Keys_Button_Title); | ||
if (button != null) button.Visible = false; | ||
|
||
button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).GetCommandbarButton(Keys_Button_Author_FirstName_LastName); | ||
if (button != null) button.Visible = false; | ||
|
||
button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.More).GetCommandbarButton(Keys_Button_Author_LastName_FirstName); | ||
if (button != null) button.Visible = false; | ||
} | ||
|
||
base.OnApplicationIdle(mainForm); | ||
} | ||
|
||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using SwissAcademic.Citavi.Controls.Wpf; | ||
using SwissAcademic.Citavi.Shell.Controls.Preview; | ||
using System.Reflection; | ||
|
||
namespace SetPDFSelectionAs | ||
{ | ||
public static class Extension | ||
{ | ||
public static PdfViewControl GetPdfViewer(this PreviewControl previewControl) | ||
{ | ||
return previewControl.GetType().GetProperty("PdfViewControl", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(previewControl) as PdfViewControl; | ||
} | ||
|
||
public static string GetSelectionAsText(this PreviewControl previewControl) | ||
{ | ||
if (previewControl.GetPdfViewer()?.GetSelectedContentFromType(ContentType.Text) is TextContent textcontent) return textcontent.Text; | ||
return null; | ||
} | ||
|
||
public static void ClearSelection(this PreviewControl previewControl) | ||
{ | ||
previewControl.GetPdfViewer()?.ClearSelection(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("SetPDFSelectionAs")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("SetPDFSelectionAsAddon")] | ||
[assembly: AssemblyCopyright("Copyright © 2019 Daniel Lutz")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("27ef81e0-5ae2-47a6-ae23-780ee8a0f3e0")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
90 changes: 90 additions & 0 deletions
90
src/SetPDFSelectionAsAddon/Properties/SetPDFSelectionAsAddonResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.