| |
| Posted by yidabu | PermalinkReply |
|
yidabu
|
dwt 2 updated to revision 70, the app still not work
1. right click on tree node A, popup a contextmenu
2. right click on tree node B, popup a contextmenu
3. right click on tree node A, the contenextmenu is not shown
the issue maybe releated to ActionContributionItem.updateImages the exception from sample code:
Unhandled D Exception (tango.core.Exception.IllegalArgumentException
"Argument not valid") at KERNEL32.dll (0x7c812a5b) thread(4092)
->us
#0 ?? () at core\Exception.d:545 from KERNEL32.dll
#1 0x007bbfcf in __d_throw@4 () at core\Exception.d:545
#2 0x0045002e in org.eclipse.swt.SWT.SWT.error () at org\eclipse\swt\SWT.d:3728
#3 0x00450015 in org.eclipse.swt.SWT.SWT.error () at org\eclipse\swt\SWT.d:3699
#4 0x00489037 in org.eclipse.swt.widgets.Widget.Widget.error () at org\eclipse\swt\widgets\Widget.d:492
#5 0x004bd12c in org.eclipse.swt.widgets.Item.Item.setImage () at org\eclipse\swt\widgets\Item.d:168
#6 0x0048d194 in org.eclipse.swt.widgets.MenuItem.MenuItem.setImage () at org\eclipse\swt\widgets\MenuItem.d:788
#7 0x005e4cd2 in org.eclipse.jface.action.ActionContributionItem.ActionContributionItem.updateImages () at org\eclipse\jface\action\ActionContributionItem.d:1131
#8 0x005e4701 in org.eclipse.jface.action.ActionContributionItem.ActionContributionItem.update () at org\eclipse\jface\action\ActionContributionItem.d:959
#9 0x005e3070 in org.eclipse.jface.action.ActionContributionItem.ActionContributionItem.fill () at org\eclipse\jface\action\ActionContributionItem.d:306
#10 0x00556be4 in org.eclipse.jface.action.MenuManager.MenuManager.doItemFill () at org\eclipse\jface\action\MenuManager.d:752
#11 0x005570a7 in org.eclipse.jface.action.MenuManager.MenuManager.update () at org\eclipse\jface\action\MenuManager.d:833
#12 0x005567ed in org.eclipse.jface.action.MenuManager.MenuManager.handleAboutToShow () at org\eclipse\jface\action\MenuManager.d:485
#13 0x0055687e in org.eclipse.jface.action.MenuManager.MenuManager.initializeMenu () at org\eclipse\jface\action\MenuManager.d:506
#14 0x004927fe in org.eclipse.swt.widgets.TypedListener.TypedListener.handleEvent () at org\eclipse\swt\widgets\TypedListener.d:279
#15 0x0045746e in org.eclipse.swt.widgets.EventTable.EventTable.sendEvent () at org\eclipse\swt\widgets\EventTable.d:91
#16 0x00489978 in org.eclipse.swt.widgets.Widget.Widget.sendEvent () at org\eclipse\swt\widgets\Widget.d:1037
#17 0x00489a5c in org.eclipse.swt.widgets.Widget.Widget.sendEvent () at org\eclipse\swt\widgets\Widget.d:1059
#18 0x004899a1 in org.eclipse.swt.widgets.Widget.Widget.sendEvent () at org\eclipse\swt\widgets\Widget.d:1041
#19 0x004725eb in org.eclipse.swt.internal.win32.OS.LDWTRESULT org.eclipse.swt.widgets.Control.Control.WM_INITMENUPOPUP () at org\eclipse\swt\widgets\Control.d:4163
#20 0x004718ad in org.eclipse.swt.widgets.Control.Control.windowProc () at org\eclipse\swt\widgets\Control.d:3865
#21 0x00499686 in org.eclipse.swt.widgets.Canvas.Canvas.windowProc () at org\eclipse\swt\widgets\Canvas.d:357
#22 0x004916b4 in org.eclipse.swt.widgets.Decorations.Decorations.windowProc () at org\eclipse\swt\widgets\Decorations.d:1610
#23 0x0044d475 in org.eclipse.swt.widgets.Shell.Shell.windowProc () at org\eclipse\swt\widgets\Shell.d:1997
#24 0x00449cf3 in org.eclipse.swt.widgets.Display.Display.windowProc () at org\eclipse\swt\widgets\Display.d:4646
#25 0x00449b4c in extern (lParam = 0, wParam = 0x008f0579, msg = 0x00000117, hwnd = 0x00110562) at org\eclipse\swt\widgets\Display.d:4596
#26 0x7e418734 in ?? () at org\eclipse\swt\widgets\Menu.d:266 from USER32.dll
#27 0x7e418816 in ?? () at org\eclipse\swt\widgets\Menu.d:266 from USER32.dll
#28 0x7e41b4c0 in ?? () at org\eclipse\swt\widgets\Menu.d:266 from USER32.dll
#29 0x7e41b50c in ?? () at org\eclipse\swt\widgets\Menu.d:266 from USER32.dll
#30 0x7c90eae3 in ?? () at org\eclipse\swt\widgets\Menu.d:266 from ntdll.dll
#31 0x00455742 in org.eclipse.swt.widgets.Menu.Menu._setVisible () at org\eclipse\swt\widgets\Menu.d:266
#32 0x00448152 in org.eclipse.swt.widgets.Display.Display.runPopups () at org\eclipse\swt\widgets\Display.d:3951
#33 0x00446e2f in org.eclipse.swt.widgets.Display.Display.readAndDispatch () at org\eclipse\swt\widgets\Display.d:3516
#34 0x00405a2d in _Dmain () at dwt2.d:211
#35 0x007bb1b4 in extern (C) int rt.dmain2.main(int, char**) . void runMain(void*) () from dmain2
#36 0x007bb1eb in extern (C) int rt.dmain2.main(int, char**) . void runAll(void*) () from dmain2
#37 0x007bb0c0 in _main () from dmain2
#38 0x007c5e71 in _mainCRTStartup () from constart
#39 0x7c816fd7 in ?? () from KERNEL32.dll
->q
the sample code:
/*******************************************************************************
* Copyright (c) 2006 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Tom Schindl - initial API and implementation
* Port to the D programming language:
* wbaxter at gmail dot com
*******************************************************************************/
module org.eclipse.jface.snippets.viewers.Snippet002TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import java.lang.all;
import tango.util.Convert;
import tango.io.Stdout;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
/**
* A simple TreeViewer to demonstrate usage
*
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
class Snippet002TreeViewer {
private class MyContentProvider : ITreeContentProvider {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement) {
return (cast(MyModel)inputElement).child/*.dup*/;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
public Object[] getChildren(Object parentElement) {
return getElements(parentElement);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
public Object getParent(Object element) {
if( element is null) {
return null;
}
return (cast(MyModel)element).parent;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
public bool hasChildren(Object element) {
return (cast(MyModel)element).child.length > 0;
}
}
public class MyModel {
public MyModel parent;
public MyModel[] child;
public int counter;
public this(int counter, MyModel parent) {
this.parent = parent;
this.counter = counter;
}
public String toString() {
String rv = "Item ";
if( parent !is null ) {
rv = parent.toString() ~ ".";
}
rv ~= to!(char[])(counter);
return rv;
}
}
public class Test2Action : Action
{
public this() {
super("&Test2 Action@Ctrl+X", ImageDescriptor.createFromFile(getImportData!("eclipse-red-16.png"))); // not work
//super("&Test2 Action@Ctrl+X", null); works
}
public void run() { }
}
public class TestAction : Action
{
public this() {
super("&Test Action@Ctrl+X", ImageDescriptor.createFromFile(getImportData!("eclipse-red-16.png"))); // not work
//super("&Test Action@Ctrl+X", null); //works
}
public void run() { }
}
class MyListener : IMenuListener
{
void menuAboutToShow(IMenuManager manager)
{
//auto t = Kiss.instance.natural(0,2);
static int t = 0;
if( t == 0)
{
manager.add(new TestAction);
t = 1;
}
else
{
manager.add(new TestAction);
t = 0;
}
/*
in my app:
if(nodea)
{
manager.add(actiona);
manager.add(actionb);
}
else if(nodeb)
{
manager.add(actionc);
manager.add(actiond);
}
manager.add(actione);
*/
}
}
//
TestAction testAction;
Test2Action test2Action;
public this(Shell shell) {
testAction = new TestAction();
test2Action = new Test2Action();
TreeViewer v = new TreeViewer(shell);
v.setLabelProvider(new LabelProvider());
v.setContentProvider(new MyContentProvider());
v.setInput(createModel());
auto menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener( new MyListener());
auto menu = menuManager.createContextMenu( v.getControl() );
v.getControl.setMenu( menu );
}
private MyModel createModel() {
MyModel root = new MyModel(0,null);
root.counter = 0;
MyModel tmp;
for( int i = 1; i < 10; i++ ) {
tmp = new MyModel(i, root);
root.child ~= tmp;
for( int j = 1; j < i; j++ ) {
tmp.child ~= new MyModel(j,tmp);
}
}
return root;
}
}
void main() {
Display display = new Display ();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new Snippet002TreeViewer(shell);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
--
yidabu <yidabu.spam@gmail.com> http://www.dsource.org/projects/dwin/
D 语言-中文(D Chinese): http://www.d-programming-language-china.org/ http://bbs.d-programming-language-china.org/ http://dwin.d-programming-language-china.org/ http://scite4d.d-programming-language-china.org/
|