Skip to content

Commit

Permalink
Modify JumpToLastPositionAfterActionExecutionAddon to adapt citavi 6.18
Browse files Browse the repository at this point in the history
  • Loading branch information
xh542428798 committed Mar 28, 2024
1 parent 8fd2da1 commit de14a3d
Show file tree
Hide file tree
Showing 14 changed files with 723 additions and 0 deletions.
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.29230.47
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JumpToLastPositionAfterActionExecutionAddon", "JumpToLastPositionAfterActionExecutionAddon\JumpToLastPositionAfterActionExecution.csproj", "{0398A56B-EA28-4D28-8173-CD9E25F3EF69}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0398A56B-EA28-4D28-8173-CD9E25F3EF69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0398A56B-EA28-4D28-8173-CD9E25F3EF69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0398A56B-EA28-4D28-8173-CD9E25F3EF69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0398A56B-EA28-4D28-8173-CD9E25F3EF69}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B9B8AF54-3CBC-40F0-B1AC-61B931A32B8D}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using JumpToLastPositionAfterActionExecution.Properties;
using pdftron.PDF;
using SwissAcademic.Citavi.Shell;
using SwissAcademic.Citavi.Shell.Controls.Preview;
using SwissAcademic.Controls;
using SwissAcademic.Pdf;
using System;
using System.Windows.Forms;

namespace JumpToLastPositionAfterActionExecution
{
public class Addon : CitaviAddOn<MainForm>
{
#region Constants

const string Keys_Button_JumpToLastPosition = "PDFActionObserver.Button.JumpToLastPosition";

#endregion

#region Fields

readonly ActionSources _actionSources;

#endregion

#region Constructors

public Addon() => _actionSources = new ActionSources();

#endregion

#region Methods

public override void OnHostingFormLoaded(MainForm mainForm)
{
mainForm.FormClosed += MainForm_FormClosed;

var button = mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.Tools).InsertCommandbarButton(7, Keys_Button_JumpToLastPosition, Resources.Button_JumpToLastPosition);
button.Shortcut = Shortcut.AltF3;
button.HasSeparator = true;

mainForm.PreviewControl.ActiveUriChanged += PreviewControl_ActiveUriChanged;

var viewer = mainForm.PreviewControl.GetPdftronViewer();
viewer.OnAction += Viewer_OnAction;

_actionSources.Add(new ActionSource(mainForm, viewer));
}

public override void OnApplicationIdle(MainForm mainForm)
{
if (mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.Tools).GetCommandbarButton(Keys_Button_JumpToLastPosition) is CommandbarButton button)
{
button.Enabled = mainForm.PreviewControl.ActivePreviewType == PreviewType.Pdf && _actionSources.GetSourceEntryPoint(mainForm) != null;
}
}

public override void OnBeforePerformingCommand(MainForm mainForm, BeforePerformingCommandEventArgs e)
{
if (e.Key.Equals(Keys_Button_JumpToLastPosition, StringComparison.OrdinalIgnoreCase))
{
if (mainForm.PreviewControl.ActivePreviewType == PreviewType.Pdf && _actionSources.GetSourceEntryPoint(mainForm) is EntryPoint point)
{
mainForm.PreviewControl.GetPdfViewer()?.SetEntryPoint(point);
}
e.Handled = true;
}
}

public override void OnLocalizing(MainForm mainForm)
{
if (mainForm.GetPreviewCommandbar(MainFormPreviewCommandbarId.Toolbar).GetCommandbarMenu(MainFormPreviewCommandbarMenuId.Tools).GetCommandbarButton(Keys_Button_JumpToLastPosition) is CommandbarButton button)
{
button.Text = Resources.Button_JumpToLastPosition;
}
}

#endregion

#region EventHandlers

void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (sender is MainForm mainForm)
{
mainForm.FormClosed -= MainForm_FormClosed;
mainForm.PreviewControl.ActiveUriChanged -= PreviewControl_ActiveUriChanged;
var viewer = mainForm.PreviewControl.GetPdftronViewer();
viewer.OnAction -= Viewer_OnAction;

_actionSources.RemoveAt(mainForm);
}
}

void Viewer_OnAction(PDFViewWPF viewer, PDFViewWPF.ActionEventArgs e)
{

if (_actionSources.GetActionSource(viewer) is ActionSource actionSource)
{
actionSource.EntryPoint = actionSource.Form.PreviewControl.GetPdfViewer()?.GetActualEntryPoint();
}
}

void PreviewControl_ActiveUriChanged(object sender, EventArgs e)
{
if (sender is PreviewControl previewControl && previewControl.FindForm() is MainForm mainForm)
{
_actionSources.ResetEntryPoint(mainForm);
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using pdftron.PDF;
using SwissAcademic.Citavi.Shell;
using SwissAcademic.Pdf;

namespace JumpToLastPositionAfterActionExecution
{
public class ActionSource
{
#region Constructors

public ActionSource(MainForm form, PDFViewWPF viewer)
{
Form = form;
Viewer = viewer;
}

#endregion

#region Properties

public MainForm Form { get; }

public PDFViewWPF Viewer { get; }

public EntryPoint EntryPoint { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using pdftron.PDF;
using SwissAcademic.Citavi.Shell;
using SwissAcademic.Pdf;
using System.Collections.Generic;
using System.Linq;

namespace JumpToLastPositionAfterActionExecution
{
public class ActionSources : List<ActionSource>
{
#region Methods

public EntryPoint GetSourceEntryPoint(MainForm form) => this.FirstOrDefault(obj => obj.Form.Equals(form))?.EntryPoint;

public ActionSource GetActionSource(MainForm mainForm) => this.FirstOrDefault(obj => obj.Form.Equals(mainForm));

public ActionSource GetActionSource(PDFViewWPF viewer) => this.FirstOrDefault(obj => obj.Viewer.Equals(viewer));

public void RemoveAt(MainForm form)
{
var obj = GetActionSource(form);
if (obj != null) Remove(obj);
}

public void ResetEntryPoint(MainForm form)
{
var obj = GetActionSource(form);
if (obj != null) obj.EntryPoint = null;
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using SwissAcademic.Citavi.Controls.Wpf;
using SwissAcademic.Citavi.Shell.Controls.Preview;
using System.Collections.Generic;
using System.Reflection;
using pdftron.PDF;

namespace JumpToLastPositionAfterActionExecution
{
public static class Extensions
{
#region System.Collections.Generic.Dictionary<TKey,TValue>

public static void AddOrUpdateSafe<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
{
if (dictionary.ContainsKey(key))
{
dictionary[key] = value;
}
else
{
dictionary.Add(key, value);
}
}

public static void RemoveSafe<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key)
{
if (dictionary.ContainsKey(key))
{
dictionary.Remove(key);
}
}

#endregion

#region SwissAcademic.Citavi.Shell.Controls.Preview.PreviewControl

public static PdfViewControl GetPdfViewer(this PreviewControl previewControl)
{
return previewControl.GetType().GetProperty("PdfViewControl", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(previewControl) as PdfViewControl;
}

public static PDFViewWPF GetPdftronViewer(this PreviewControl previewControl)
{
var pdfViewControl = previewControl.GetPdfViewer();

return pdfViewControl.GetType().GetProperty("Viewer", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(pdfViewControl) as PDFViewWPF;
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0398A56B-EA28-4D28-8173-CD9E25F3EF69}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>JumpToLastPositionAfterActionExecution</RootNamespace>
<AssemblyName>JumpToLastPositionAfterActionExecutionAddon</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\..\Software\CitaviTest\Addons\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files (x86)\Citavi 6\bin\Citavi.exe</StartProgram>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="Citavi">
<HintPath>..\..\..\..\Software\CitaviTest\bin\Citavi.exe</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="PDFNet">
<HintPath>..\..\..\..\Software\CitaviTest\bin\PDFNet.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="SwissAcademic">
<HintPath>..\..\..\..\Software\CitaviTest\bin\SwissAcademic.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SwissAcademic.Citavi">
<HintPath>..\..\..\..\Software\CitaviTest\bin\SwissAcademic.Citavi.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SwissAcademic.Citavi.Controls.Wpf">
<HintPath>..\..\..\..\Software\CitaviTest\bin\SwissAcademic.Citavi.Controls.Wpf.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SwissAcademic.Controls">
<HintPath>..\..\..\..\Software\CitaviTest\bin\SwissAcademic.Controls.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SwissAcademic.Pdf">
<HintPath>..\..\..\..\Software\CitaviTest\bin\SwissAcademic.Pdf.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System " />
<Reference Include="System.Core " />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Addon.cs" />
<Compile Include="Core\Extensions.cs" />
<Compile Include="Core\ActionSource.cs" />
<Compile Include="Core\ActionSources.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.de.resx" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartProgram>E:\Software\CitaviTest\bin\Citavi.exe</StartProgram>
</PropertyGroup>
</Project>
Loading

0 comments on commit de14a3d

Please sign in to comment.