Update Plugins Problem

Hey there,

I created some plugins for old version of FoldingText based on the Plugins found in the Web. With the new kind of programming I don’t know how to update the old stuff. Can somebody help? For example this is my script to automatically create a lokal link based on the selection.

define(function(require, exports, module) {
exports.editorDidLoad = function editorDidLoad(editor) {

	editor.treeController.addCommand('local link from selection', 'Create a Markup E-Mail Link from selected Text.', function(treeController) {
		var treeView = treeController.treeView,
			treeModel = treeController.treeModel,
			selectedRange = treeView.selectedRange(),
			selectionLocation = selectedRange.location(),
			selectedText = selectedRange.textInRange(),
			linkText = selectedText.replace(/ /g,'').replace(/[äöüßÄÖÜ]/g,'').toLowerCase();
			newText = "[" + selectedText +"](#" + linkText + ")";

		treeView.beginUpdates();
		treeModel.replaceTextInRange(newText, selectedRange);
		treeView.setSelectedRange(treeModel.createRangeFromLocation(selectionLocation, newText.length));
		treeController.undoManager.setActionName("EMail");
		treeView.endUpdates();
	});

};

});

Thanks a lot.

Bye

Perhaps something like this ?

function(editor, options) {
	var	strSeln=editor.selectedText(),
		strLower=strSeln.toLowerCase(),
		strClean=strLower.replace(/[\säöüß]/g, ''),
		strLink=['[',strSeln,'](#',strClean,')'].join('');

		editor.replaceSelection(strLink, 'around');
}

There’s good documentation now for the new set of FT .js functions. You can find it through the FT menu system at:

Help > Software Development Kit > Documentation

or with the following link:

x-foldingtext://sdk/docs

As a simple Applescript:

property pstrJS : "
	function(editor, options) {
		
		var	strSeln=editor.selectedText(),
			strLower=strSeln.toLowerCase(),
			strClean=strLower.replace(/[\\säöüß]/g, ''),
			strLink=['[',strSeln,'](#',strClean,')'].join('');
	
			editor.replaceSelection(strLink, 'around');
	}
"

tell application "FoldingText"
	set lstDocs to documents
	if lstDocs ≠ {} then tell item 1 of lstDocs to (evaluate script pstrJS)
end tell

(Note that the \ character needs escaping as \\ if the .js code is in an Applescript string. Inside a plugin \ is enough)

Rob

Hey guys!

Thanks a lot for quick Answers! Will try it.

Bye

Andre