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

Commit

Permalink
Merge pull request #1 from lutz/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lutz authored Dec 7, 2019
2 parents 77d43a2 + dba08bb commit 13dbfa9
Show file tree
Hide file tree
Showing 9 changed files with 644 additions and 7 deletions.
12 changes: 5 additions & 7 deletions README.md
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
25 changes: 25 additions & 0 deletions src/SetPDFSelectionAsAddon.sln
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
125 changes: 125 additions & 0 deletions src/SetPDFSelectionAsAddon/Addon.cs
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
}
}
25 changes: 25 additions & 0 deletions src/SetPDFSelectionAsAddon/Core/Extension.cs
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();
}
}
}
36 changes: 36 additions & 0 deletions src/SetPDFSelectionAsAddon/Properties/AssemblyInfo.cs
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")]

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

Loading

0 comments on commit 13dbfa9

Please sign in to comment.