ADDON: Edit Any Shortcut, Run Saved Searches/Macros

Add-Ons let you add features to Citavi. Be sure to check the minimum Citavi version required for each Add-On.

ADDON: Edit Any Shortcut, Run Saved Searches/Macros

Postby MrMagoo » 2017-07-12 09:51

A while back I made an earlier support post asking about configuring hotkeys and a better way to run macros.

Unfortunately this was not possible....until now...

I felt like a challenge on the weekend and so decided to streamline my workflow. The initial dev spike went so well it turned into a fully functional addon and so I am dropping it here in case anyone else wants to try it.
To this end this addon does not edit any core Citavi configuration. If you delete the configuration files and/or the core addon files any changes made will vanish when you restart Citavi.
It also tries to provide helpful messages and functionality to make playing around with the configuration quick and easy if not fun.
Many will not agree, but they should remember it was a lot harder to make this addon! ;)

What it does/has:
  • Edit any existing Citavi shortcuts or bind new shortcuts to most, if not all, commands in Citavi.
  • Adds new commands to run (or add as a filter) 20 saved searches which can be bound to shortcuts.
  • Adds new commands to load, compile and optionally auto-run up to 20 Macros.
  • Controlled via 2 "simple" configuration files for which defaults can be generated automatically to get you started quickly.
  • While existing configuration files are auto-loaded on Citavi start, you can also manually refresh these as you make changes.
  • When loading macro configuration, it will check that any files referred to exist and let you know in the results window if it cannot find them.
  • An xls spreadsheet listing the commands, keys and default Citavi shortcuts.
  • Can list all currently configured shortcuts so you can avoid collisions.
  • Source code provided for hackers.


Installation:
  1. Unzip the Addons.zip file into your Citavi installation directory.
  2. The default to something like: C:\Program Files (x86)\Citavi 5\
  3. Make sure that the 6 files have unpacked into a subdirectory called: Addons
  4. e.g. C:\Program Files (x86)\Citavi 5\AddOns\
  5. Start Citavi
  6. You should see two new menus in the top right of the main Citavi window: "Shortcuts" & "Run Macro"

Create Default Config
On both the menus there is an option to "Create Default Config" which will create a sensible default configuration file in the user folder.
This will NOT apply the configuration to give you a chance to make changes before you apply them. But remember that when you restart Citavi they WILL be applied. (I picked sensible defaults so nothing bad will happen)
To create both configuration files you must use this option in BOTH menus.

If you do not use macros you can happily ignore the entire macro menu.

Reload Config Now
On both the menus there is an option to "Reload Config Now" which will look for and then apply the configuration file associated with that menu.
It will display a window when it is done showing what changes were made. The changes will also appear in the menus themselves.
It will also tell you if you have overwritten an existing shortcut.
If you accidentally overwrite a core Citavi shortcut you can simply edit the configuration to remove the mistake and then restart Citavi - any other change does not require a restart.
NB: If you see the message: "An item with the same key has already been added" this means that two shortcuts have the same "Command" and this is not allowed.

Shortcuts -> List All Shortcuts
Shows a window with all currently configured shortcuts (or at least the ones I can find) and the commands they are bound to. This is to help you avoid over-writing existing shortcuts.

Shortcuts -> Run (or Add) Saved Search
This list shows either the command name (e.g. "RunSearch01" or "AddSearch15") or the name of the saved search bound to that command prefixed by the search number (e.g. "01: my_search"). The ordering is the same alphabetical sort order that citavi uses. I recommend numbering your searches to keep them in order else you shortcuts will change when the order does.
You CAN run the searches from these menus but obviously the idea is to bind shortcuts to them.
The "Run" versions remove any existing filters you might have and applies the search as the only filter. "Add" adds the filter to any existing filters you might have.
You can see how you might use a clever combination of add/run commands with shortcuts to have both core searches and common filters you can apply to any view.

Once you configure shortcuts for these commands this list will also show you the shortcuts you have configured and what searches they belong to.
See the image below for an example.
SavedSearch.png


Shortcuts -> Run (or Add) Saved Search -> Manually Refresh Names
If something has gone wrong and the names of the searches are not correctly displayed, this button should fix that. (but that should not happen...)

Shortcuts -> Run Macro
This works similar to searches but can load, compile and run macros without having to manage an additional window.
The name of the file will appear in this list if it is configured, otherwise the command name. (e.g. "RunMacro01")
Shortcuts for these commands will also appear if you configure them, but you can also just run the macros from the menu also if you prefer.
Most macros can be set to auto-run which means the Macro Editor window is "hidden" and the macro runs in the background and then is closed when done. If there is an error with the macro, it will pop up the macro editor so you can see it.
Should you want the macro window left open, just turn off auto-run.
NB: Due to a limitation in the Citavi code I unfortunately cannot load external references via the addon without writing my own compiler code. If your macro does use external references you should turn off auto-run for that macro and it will instead bring up the macro window with your macro already loaded.

See the image below for an example.
RunMacro.png



Configuration files
The configuration is not as easy as I would have liked but the only alternative is to build a full configuration interface and I do not have time for that. (Sorry!)
I have tried to make it as simple as I can.
(For those that care, they are YAML files)
As mentioned the structure of the file is very important. If you don't follow it you will get somewhat helpful errors from the YAML processor - don't blame me for the quality! :)

Shortcut configuration file and the Spreadsheet
Each shortcut has three lines which configure it. Note that the structure (spaces, colons and dashes) are important and need to be the same as in the example. The default configuration file helps as you will have many examples to work from.
e.g. A two commands:
Code: Select all
- Command: Main.RunSearch01
  Modifiers: cs
  ShortcutKey: D1
- Command: ReferenceEditorFilter.ClearFilter
  Modifiers: cs
  ShortcutKey: Oemtilde

Command:
This is the command that will run when the shortcut is pressed.
To find a list of commands, refer to the spreadsheet on sheets "Default Shortcuts" or "All Menu Items". These will show all available commands and the default Citavi shortcut if it exists. The spreadsheet does not contain the new commands the addon has added such as RunSearch01 but there are examples below and in the menus themselves.
The first column shows the Command name with orange headings for each section.
Note that you must COMBINE the orange heading (e.g. "Main.") with the command name (e.g. "Copy") for use in the configuration file.
e.g.
Code: Select all
   Main.Copy
   Main.RunMacro01
   Main.RunSearch15
   Main.AddSearch01
   ReferenceEditorCategoriesAndKeywords.GoTo
   ReferenceEditorNavigation.SelectAll

The second column in the spreadsheet shows the menu/button text you would see on the screen. Use this to help identify what each of the commands does by using this and hunting through the Citavi interface. I know, I know...but think of it as an adventure!
NB 1: Some of these commands will not do anything as they are sub-menus or other commands which cannot be executed. Also note some will only work in certain areas of Citavi. Trial and error unfortunately but any command that has a shortcut already will certainly work.
NB 2: Some items appear in multiple sections (e.g. Copy, Undo, Paste) and when you change one, you change them all.

Modifiers:
These are the control, shift and alt keys that can be used with the shortcut.
c = control, s = shift, a =alt.
The configuration does not care about the order and will only search for those letters.
The windows key cannot be used as a modifier due to MS Windows limitations.

ShortcutKey:
The keyboard key that needs to be pressed along with the modifiers to trigger the command. These MUST be one of the items on the 3rd spreadsheet page ("Valid Keys")
Most keys are usable but remember they ARE used for other things so make sure they are free or you want to over-write them!
e.g. The keys you will use the most:
Code: Select all
   D0 ... D9 = Basic Number Keys (Number pad is not supported)
   A-Z = Basic Letters
   F1 ... F12
   etc

Some keys can be strange and there are notes in the spreadsheet on this.

Macro configuration file
This one is a little easier and is also a YAML file:
Code: Select all
- MacroNumber: 1
  MacroFile: Macros/RunMacroTest3.cs
- MacroNumber: 2
  MacroFile: Macros/RunMacroTest2.cs
  AutoRun: true

MacroNumber:
You have macros numbered 1-20 and this is the first entry "MacroNumber".

MacroFile:
The next is the file location. The location is relative to the user settings folder unless you use a full path.
e.g. Full path example
O:/UserFiles/Macros/RunMacroTest2.cs
NB: You must use "/" characters and not "\" characters when entering the path.
If you make a mistake don't worry: when you try to run a file it cannot find a pop up will tell you were it was looking to find the file allowing you to adjust accordingly.

AutoRun:
This is optional and defaults to false. When true it will run the file in the background and only bring up the macro editor if there was an error.
Last edited by MrMagoo on 2017-07-12 10:06, edited 1 time in total.
MrMagoo
 

Re: ADDON: Edit Any Shortcut, Run Saved Searches/Macros

Postby MrMagoo » 2017-07-12 09:53

And now the files. (forum only allows 3 attachments)

AddOns.zip
Addon Files
(304.47 KiB) Downloaded 22 times

AddonData.zip
XLS Spreadsheet
(47.75 KiB) Downloaded 26 times

AddonSource.zip
Source Code
(14.28 KiB) Downloaded 29 times
MrMagoo
 

Re: ADDON: Edit Any Shortcut, Run Saved Searches/Macros

Postby MrMagoo » 2017-07-13 01:14

Could not resist an update:
Pressing the same Add or Run search hotkey repeatedly will INVERT the associated filter (has to be the last one applied) instead of adding/replacing it.

AddOns.zip
Addon Files - v2
(305.91 KiB) Downloaded 36 times

AddonData.zip
XLS Spreadsheet
(47.76 KiB) Downloaded 30 times

AddonSource.zip
Source Code
(14.52 KiB) Downloaded 30 times
MrMagoo
 

Re: ADDON: Edit Any Shortcut, Run Saved Searches/Macros

Postby jay-squared » 2017-07-13 15:20

This looks spectacular! One problem I am having is that I contacted Citavi to get the 64bit version of Citavi, and the AddOn does not run with the 64bit version. I tried compiling it myself but noticed that it refers to the Infragistics.Win.UltraWinToolbars namespace. I had a cursory look at their website, and I can't determine whether there is a free version for small-scale developers (I am not even a developer, literally the only reason I have Visual Studio 2017 is that I made a small Citavi AddOn.) You wouldn't happen to know if there is a free version of their framework?
jay-squared
Citavi Expert
 

Re: ADDON: Edit Any Shortcut, Run Saved Searches/Macros

Postby MrMagoo » 2017-07-13 19:57

jay-squared :

Well isn't that embarrassing! I have a 64 but system and run the standard 32 bit Citavi and don't have access to the 64 for testing.
I confess although I have decades of Java/other languages experience but have only been using c# for just over a year or so. I am ashamed to admit I am a convert.
I am also trying out Jetbrains Rider (from the company that makes Resharper for MS VS) as my IDE and so far have been impressed and it feels more like the java IDE I know.

The good news is you do not have to download anything as the libs are already there in the bin folder.

Here is the list of libs I used (Some will not be necessary):
From Citavi Bin folder:
As I am sure you are already aware: set their properties to not copy to the output folder on build and run your IDE in admin mode so it can access the "Program Files" directory when you release it.
  • Infragistics4.Win.v11.2.dll
  • Infragistics4.Win.UltraWinToolbars.v11.2.dll
  • Infragistics4.Shared.v11.2.dll
  • Citavi.exe
  • Gibraltar.Agent.dll - For Citavi compatible logging
  • SwissAcademic.*.dll (All except the "Icon" dll)
From nuget:
These need to copy to to the AddOns folder on build or be there already.
  • System.Collections.Immutable.1.3.1
  • YamlDotNet.4.2.1 (SIGNED version)

For anyone else that might want to setup a dev environment you can find the docs translated from german in this thread.

Also peer review of the code and any suggestions are more than welcome.

And if it wasn't clear: anyone is free to do whatever you like with the code but it would be nice if you posted any useful changes here so everyone can benefit. :)
MrMagoo
 

Re: ADDON: Edit Any Shortcut, Run Saved Searches/Macros

Postby jay-squared » 2017-07-13 20:41

Well, this is slightly embarrassing. I didn't check for the Infragistics dlls and managed not to see them when adding the SwissAcademic references. Thanks! It compiles successfully. Now the joy of customizing Citavi shortcuts to my heart’s desire. By the way: I got the 64bit version from the support because I kept running into memory shortages due to an extremely big project. I am sure they would send you a link as well if you shoot them an e-mail.
jay-squared
Citavi Expert
 

Re: ADDON: Edit Any Shortcut, Run Saved Searches/Macros

Postby MrMagoo » 2017-07-13 20:50

That is great news, glad to here you are up and running. If you have any questions, just let me know.
MrMagoo
 

Re: ADDON: Edit Any Shortcut, Run Saved Searches/Macros

Postby Daniel Mönch » 2017-07-26 14:45

Wow, this looks amazing.
I definitely have to give this a look. Shortcuts are a big pain point for me in Citavi.
Daniel Mönch
 

Re: ADDON: Edit Any Shortcut, Run Saved Searches/Macros

Postby MrMagoo » 2017-07-26 21:23

Hi Daniel:

They were for me as well. Also macros not being able to be run via shortcut made them of limited use.

Let me know if you have any issues. :)

Thankfully the Citavi team made their software very extensible and I was able to hook into the core GUI system. When I first investigated this I assumed I would hit a roadblock of some sort as this is not exactly your standard addon.

On a highly tangential note:
The only thing I was not able to do is to automatically add additional macro assemblies before running macros. Access to the assembly list is not available outside of Citavi code. (hint, hint, Citavi Devs!)
If they upgraded to .NET 4.6+ I would probably look into adding my own compiler and even support other languages. :)
I think that adding python support (I read this year Python was rated the most popular language) even with the current version should be trivial. I don't as yet use it myself but have to in the near for what I am working on.
MrMagoo
 


Return to Citavi Add-Ons