[Kde-java] Questions about KCommandHistory

Richard Dale Richard_Dale at tipitina.demon.co.uk
Sat Jul 10 11:46:37 CEST 2004


On Friday 09 July 2004 14:16, Maik Schulz wrote:
> I'm trying to use KCommands in my application to allow for undo/redo
> operations. However, I'm not getting very far when I follow the directions
> from the API documentation:
>
> 1. KCommands don't get executed automatically when I add them to the
> KCommandHistory
> 2. The undo/redo items in the edit menu remain unchanged, i.e. deactivated
>
>
> Could someone please point out to me what I'm doing wrong? I included the
> relevant code snippets at the end of this email.
Hi Maik

You're not doing anything wrong. The problem is that virtual method callbacks 
are only implemented for subclasses of QObject at the moment. As KCommand 
isn't a QObject, it doesn't have any, which is a bit of a show stopper here 
:(.

I'll add some more virtual method callbacks for the KDE 3.3 release as it's 
the biggest limitation of the bindings. Fixing KCommand.execute() should be 
straightforward, so I can to a patch this weekend and either mail it to you 
or post it on this list if it isn't too big.

-- Richard

>
> This is my KApplication class:
>
> public class PJBoxManagerApp extends KMainWindow {
> 	PJBoxManagerApp() {
> 		super( null, "PJBox Manager" );
> 		m_view = new PJBoxManagerView(this);
> 		[...]
> 		setCentralWidget(m_view);
> 		[...]
> 	}
> }
>
> And here is the class for the central widget:
>
> //frmWidget has been generated by juic and extends QWidget
> public class PJBoxManagerView extends frmWidget {
> 	KCommandHistory commandHistory;
>
> 	public PJBoxManagerView(QWidget parent) {
> 		super(parent);
> 		[...]
> 		commandHistory = new
> KCommandHistory(((KMainWindow)parent).actionCollection(), true);
> 		[...]
> 	}
>
> 	//this is a method that handles a user action
> 	public void editRemove() {
> 		KCommand command = new RemoveNode(tr("Remove Node"), this);
>
> 		//setting the execute parameter to true doesn't help
> 		commandHistory.addCommand(command);
>
> 		//I have to manually call execute, otherwise it isn't even executed
> 		command.execute();
> 	}
> }
>
> And here is the Command class:
>
> public class RemoveNode extends KCommand {
> 	private PJBoxManagerView controller;
> 	private String name;
>
> 	public RemoveNode(String name, PJBoxManagerView controller) {
> 		super(RemoveNode.class);
> 		this.name = name;
> 		this.controller = controller;
> 	}
>
> 	public String name() {
> 		return name;
> 	}
>
> 	public void execute() {
> 		System.out.println("execute " + name);
> 	}
>
> 	public void unexecute() {
> 		System.out.println("unexecute " + name);
> 	}
> }
> _______________________________________________
> Kde-java mailing list
> Kde-java at kde.org
> https://mail.kde.org/mailman/listinfo/kde-java


More information about the Kde-java mailing list