Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

How to add a key definition to the editor

alxzaur edited this page Oct 2, 2014 · 3 revisions

Its quite straight forward to add some functionality to the SharpDevelop editor. But there are a few steps. Each key must be assigned to a class that inherits from AbstractEditCommand. So for each key you must define a class. In the addin file you will assign that key to the class.

The following is an example of adding navigate back and forward to the test editor.

The addin project name I use is MyKeySettings. These instructions are based off of that name.

  1. First you will need to create a SharpDevelop AddIn project.
  2. Edit the addin file (in this case MyKeySettings.addin).
  3. Remove:
<Path name = "/SharpDevelop/Workbench/Pads">
  <Pad id       = "MyKeySettingsPad"
       category = "Main"
       title    = "MyKeySettingsPad"
       icon     = "PadIcons.Output"
       shortcut = "Control|Alt|T"
       class    = "MyKeySettingsPad.TestPad"/>
</Path>
  1. Add the following to the addin file:
<Path name = "/AddIns/DefaultTextEditor/EditActions">
  <EditAction id = "MyNavigateForward"  class = "MyKeySettings.MyNavigateForward"  keys = "Control|Shift|K"/>
  <EditAction id = "MyNavigateBackwards"  class = "MyKeySettings.MyNavigateBackwards"  keys = "Control|K"/>
</Path>
  1. Delete the TestPad.cs and MyUserControl.cs files from the project.
  2. Add a class file to your project (I called mine MyKeyClasses.cs). However it holds 2 classes, not just one. You can organize your files/classes anyway you want.
  3. Add the following using statements:
using System;
using System.Collections.Generic;
using System.Drawing;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.TextEditor.Actions;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.TextEditor;
using ICSharpCode.SharpDevelop;
  1. Add the necessary references to the project.
  2. Here is the text of my navigate forward and backward classes. They make use of an existing service "NavigationService" to implement the back and forth navigation:
public class MyNavigateForward : AbstractEditAction 
{
	public override void Execute(TextArea textArea) 
	{
		StatusBarService.SetMessage("forward");
		NavigationService.Go(1);
	}		
}

public class MyNavigateBackwards : AbstractEditAction
{
	public override void Execute(TextArea textArea)
	{
		StatusBarService.SetMessage("back");
		NavigationService.Go(-1);
	}
}
  1. You will also need to set the output of your project to the sharpdevelop addin directory in a subdirectory named like your project. (Project properties, Compile tab).

Works for me, if you have problems ask on the forums or email me.