It´s possible add a button on IDE?

Hello community!
I have a question, would it be possible to add an extra button in the IDE next to the play and stop button to launch a custom script?

Exists any version of custom IDE?

1 Like

Hi @erkosone,

Can’t show you a concrete example by now as I’ve currently only mobile access, but take a look here …

If I find a bit time the next days I’ll try to provide a working example …

Cheers
— mnse

1 Like

Thanks for the info :wink:

Hi @erkosone,

As promised, here is an working example of how one could add a button to the PDE.
However, I must say that this is not intended in principle and is therefore more or less a small hack.
I would recommend to just add a sub-item in the Tools menu that would then execute what you want, described in the docs from above.

The example is based on the Java Mode Toolbar and I just reused the styles from the Run button, but one could just use ie. a JButton as well. The Tool extension works on both P3 and P4.

Code Example
import java.awt.Component;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import javax.swing.Box;
import javax.swing.JOptionPane;

import processing.app.Base;
import processing.app.tools.Tool;
import processing.app.ui.Editor;
import processing.app.ui.EditorButton;
import processing.app.ui.EditorToolbar;
import processing.app.ui.Toolkit;

public class DummyButtonExample implements Tool {
	private Base base;
	private Editor editor;

	public String getMenuTitle() {
		return "##tool.name##";
	}

	private ArrayList<Component> getAllComponents(final Container parentContainer) {
		Component[] components = parentContainer.getComponents();
		ArrayList<Component> componentList = new ArrayList<Component>();
		for (Component c : components) {
			componentList.add(c);
			if (c instanceof Container)
				componentList.addAll(getAllComponents((Container) c));
		}
		return componentList;
	}

	public void init(Base base) {
		this.base = base;
		this.editor = base.getActiveEditor();
		try {
			EventQueue.invokeLater(new Runnable() {
				public void run() {
					ArrayList<Component> allComponents = getAllComponents(editor.getRootPane());
					Component myParent = allComponents.get(13); // JavaEditor Toolbar
					Component myAddon = allComponents.get(14);  // Underlying container for buttons
					@SuppressWarnings("serial")
					EditorButton myButton = new EditorButton((EditorToolbar) myParent, "/lib/toolbar/run", "MyButton") {
						@Override
						public void actionPerformed(ActionEvent e) {
							// do what should be happen on button pressed
							JOptionPane.showMessageDialog(null, "MyButton Pressed!", "Info", JOptionPane.INFORMATION_MESSAGE);
						}
					};
					((javax.swing.Box) myAddon).add(myButton, 5);
					((javax.swing.Box) myAddon).add(Box.createHorizontalStrut(Toolkit.zoom(9)), 6);
				}
			});
		} catch (Exception e) {
			System.err.println("Exception at invoke DummyButtonExample EventQueue: " + e.getMessage());
		}
	}

	public void run() {
		// do nothing
	}
}

Button

Cheers
— mnse

2 Likes

Muchas gracias por interesarte en el tema :blush:. Has recompilado el ide?

Hi @erkosone,

No! The Tool works as a kind of addon/plugin to the PDE.

Just study the information from here …

And here…

Cheers
— mnse

1 Like