Lines 7-23
Link Here
|
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* QNX Software Systems - Initial API and implementation |
9 |
* QNX Software Systems - Initial API and implementation |
|
|
10 |
* Axel Mueller - [69922] Rebuild last target |
10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
11 |
package org.eclipse.cdt.make.ui.actions; |
12 |
package org.eclipse.cdt.make.ui.actions; |
12 |
|
13 |
|
13 |
import org.eclipse.cdt.core.model.ICContainer; |
14 |
import org.eclipse.cdt.core.model.ICContainer; |
14 |
import org.eclipse.cdt.core.model.ICElement; |
15 |
import org.eclipse.cdt.core.model.ICElement; |
15 |
import org.eclipse.cdt.core.model.ICProject; |
16 |
import org.eclipse.cdt.core.model.ICProject; |
|
|
17 |
import org.eclipse.cdt.make.core.IMakeTarget; |
16 |
import org.eclipse.cdt.make.core.MakeCorePlugin; |
18 |
import org.eclipse.cdt.make.core.MakeCorePlugin; |
17 |
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; |
19 |
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; |
18 |
import org.eclipse.core.resources.IContainer; |
20 |
import org.eclipse.core.resources.IContainer; |
|
|
21 |
import org.eclipse.core.resources.IFile; |
19 |
import org.eclipse.core.resources.IResource; |
22 |
import org.eclipse.core.resources.IResource; |
20 |
import org.eclipse.jface.action.IAction; |
23 |
import org.eclipse.jface.action.IAction; |
|
|
24 |
import org.eclipse.jface.text.ITextSelection; |
21 |
import org.eclipse.jface.viewers.ISelection; |
25 |
import org.eclipse.jface.viewers.ISelection; |
22 |
import org.eclipse.jface.viewers.IStructuredSelection; |
26 |
import org.eclipse.jface.viewers.IStructuredSelection; |
23 |
import org.eclipse.swt.widgets.Shell; |
27 |
import org.eclipse.swt.widgets.Shell; |
Lines 26-38
Link Here
|
26 |
import org.eclipse.ui.IWorkbenchWindow; |
30 |
import org.eclipse.ui.IWorkbenchWindow; |
27 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
31 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
28 |
import org.eclipse.ui.actions.ActionDelegate; |
32 |
import org.eclipse.ui.actions.ActionDelegate; |
|
|
33 |
import org.eclipse.ui.editors.text.TextEditor; |
34 |
import org.eclipse.ui.part.EditorPart; |
29 |
|
35 |
|
30 |
public abstract class AbstractTargetAction |
36 |
public abstract class AbstractTargetAction |
31 |
extends ActionDelegate |
37 |
extends ActionDelegate |
32 |
implements IObjectActionDelegate, IWorkbenchWindowActionDelegate { |
38 |
implements IObjectActionDelegate, IWorkbenchWindowActionDelegate { |
33 |
private IWorkbenchPart fPart; |
39 |
private IWorkbenchPart fPart; |
34 |
private IWorkbenchWindow fWindow; |
40 |
private IWorkbenchWindow fWindow; |
35 |
private IContainer fContainer; |
41 |
private boolean isEnabled; |
|
|
42 |
protected IContainer fContainer; |
36 |
|
43 |
|
37 |
protected Shell getShell() { |
44 |
protected Shell getShell() { |
38 |
if (fPart != null) { |
45 |
if (fPart != null) { |
Lines 55-62
Link Here
|
55 |
fWindow = window; |
62 |
fWindow = window; |
56 |
} |
63 |
} |
57 |
|
64 |
|
|
|
65 |
@Override |
58 |
public void selectionChanged(IAction action, ISelection selection) { |
66 |
public void selectionChanged(IAction action, ISelection selection) { |
59 |
boolean enabled = false; |
67 |
isEnabled = false; |
60 |
if (selection instanceof IStructuredSelection) { |
68 |
if (selection instanceof IStructuredSelection) { |
61 |
IStructuredSelection sel = (IStructuredSelection) selection; |
69 |
IStructuredSelection sel = (IStructuredSelection) selection; |
62 |
Object obj = sel.getFirstElement(); |
70 |
Object obj = sel.getFirstElement(); |
Lines 75-88
Link Here
|
75 |
} else { |
83 |
} else { |
76 |
fContainer = ((IResource)obj).getParent(); |
84 |
fContainer = ((IResource)obj).getParent(); |
77 |
} |
85 |
} |
|
|
86 |
} else if (obj instanceof IMakeTarget) { |
87 |
fContainer = ((IMakeTarget)obj).getContainer(); |
78 |
} else { |
88 |
} else { |
79 |
fContainer = null; |
89 |
fContainer = null; |
80 |
} |
90 |
} |
81 |
if (fContainer != null && MakeCorePlugin.getDefault().getTargetManager().hasTargetBuilder(fContainer.getProject())) { |
91 |
} else if (selection instanceof ITextSelection) |
82 |
enabled = true; |
92 |
{ // key binding pressed inside active text editor |
|
|
93 |
IWorkbenchPart part = fPart != null ? fPart : fWindow.getActivePage().getActivePart(); |
94 |
if ( part instanceof TextEditor ) { |
95 |
IFile file = org.eclipse.ui.ide.ResourceUtil.getFile(((EditorPart) part).getEditorInput()); |
96 |
fContainer = file.getParent(); |
97 |
} else { |
98 |
fContainer = null; |
83 |
} |
99 |
} |
84 |
} |
100 |
} |
85 |
action.setEnabled(enabled); |
101 |
if (fContainer != null && MakeCorePlugin.getDefault().getTargetManager().hasTargetBuilder(fContainer.getProject())) { |
|
|
102 |
isEnabled = true; |
103 |
} |
104 |
if ( action != null ) |
105 |
action.setEnabled(isEnabled); |
86 |
} |
106 |
} |
87 |
|
107 |
|
|
|
108 |
public boolean isEnabled() { |
109 |
return isEnabled; |
110 |
} |
88 |
} |
111 |
} |