[Kde-java] Questions about KCommandHistory
Maik Schulz
list at maikschulz.de
Fri Jul 9 15:16:51 CEST 2004
Hi all,
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.
Thanks in advance,
-Maik
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);
}
}
More information about the Kde-java
mailing list