1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 02:36:01 +02:00

Another NPE in build console fixed + cleanup wizard

This commit is contained in:
Andrew Gvozdev 2010-03-15 16:28:05 +00:00
parent 6d9cc48125
commit 0c0bb08f51

View file

@ -8,8 +8,8 @@
* Contributors: * Contributors:
* QNX Software Systems - initial API and implementation * QNX Software Systems - initial API and implementation
* Red Hat Inc. - multiple build console support * Red Hat Inc. - multiple build console support
* Dmitry Kozlov (CodeSourcery) - Build error highlighting and navigation * Dmitry Kozlov (CodeSourcery) - Build error highlighting and navigation
* Save build output * Save build output
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.buildconsole; package org.eclipse.cdt.internal.ui.buildconsole;
@ -27,9 +27,9 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuListener;
@ -117,7 +117,7 @@ public class BuildConsolePage extends Page
static final int POSITION_NEXT = -1; static final int POSITION_NEXT = -1;
static final int POSITION_PREV = -2; static final int POSITION_PREV = -2;
static final int POSITION_FIST = -3; static final int POSITION_FIST = -3;
private BuildConsole fConsole; private BuildConsole fConsole;
private IConsoleView fConsoleView; private IConsoleView fConsoleView;
private String fContextMenuId; private String fContextMenuId;
@ -151,7 +151,7 @@ public class BuildConsolePage extends Page
* @param console * @param console
* @param contextId * @param contextId
*/ */
public BuildConsolePage(IConsoleView view, BuildConsole console, public BuildConsolePage(IConsoleView view, BuildConsole console,
String contextId) { String contextId) {
fConsole = console; fConsole = console;
fConsoleView = view; fConsoleView = view;
@ -162,18 +162,20 @@ public class BuildConsolePage extends Page
} }
protected void setProject(IProject project) { protected void setProject(IProject project) {
if (fProject != project && project.isAccessible()) { if (fProject != project && project.isAccessible()) {
fProject = project;
ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project); ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project);
fSaveConsoleAction.setChecked(false); if (projDesc!=null) {
ICConfigurationDescription configDesc = projDesc.getActiveConfiguration(); fProject = project;
// Read save console log preferences fSaveConsoleAction.setChecked(false);
try { ICConfigurationDescription configDesc = projDesc.getActiveConfiguration();
IEclipsePreferences pref = new InstanceScope().getNode(CCorePlugin.PLUGIN_ID); // Read save console log preferences
boolean b = pref.getBoolean(BuildOutputLogger.getIsSavingKey(project, configDesc.getName()),false); try {
fSaveConsoleAction.setChecked(b); IEclipsePreferences pref = new InstanceScope().getNode(CCorePlugin.PLUGIN_ID);
} catch (Exception e) { boolean b = pref.getBoolean(BuildOutputLogger.getIsSavingKey(project, configDesc.getName()),false);
CUIPlugin.log(e); fSaveConsoleAction.setChecked(b);
} catch (Exception e) {
CUIPlugin.log(e);
}
} }
} }
} }
@ -190,7 +192,7 @@ public class BuildConsolePage extends Page
IProject project = getProject(); IProject project = getProject();
if (project != null) { if (project != null) {
IBuildConsoleManager consoleManager = getConsole().getConsoleManager(); IBuildConsoleManager consoleManager = getConsole().getConsoleManager();
getViewer().setDocument(consoleManager.getConsoleDocument(project)); getViewer().setDocument(consoleManager.getConsoleDocument(project));
IConsole console = consoleManager.getConsole(project); IConsole console = consoleManager.getConsole(project);
if ( console instanceof BuildConsolePartitioner) { if ( console instanceof BuildConsolePartitioner) {
BuildConsolePartitioner par = (BuildConsolePartitioner)console; BuildConsolePartitioner par = (BuildConsolePartitioner)console;
@ -209,7 +211,7 @@ public class BuildConsolePage extends Page
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see java.lang.Runnable#run() * @see java.lang.Runnable#run()
*/ */
public void run() { public void run() {
@ -235,7 +237,7 @@ public class BuildConsolePage extends Page
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite) * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
*/ */
@Override @Override
@ -274,7 +276,7 @@ public class BuildConsolePage extends Page
/** /**
* Fill the context menu * Fill the context menu
* *
* @param menu * @param menu
* menu * menu
*/ */
@ -290,7 +292,7 @@ public class BuildConsolePage extends Page
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
*/ */
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
@ -307,7 +309,7 @@ public class BuildConsolePage extends Page
getViewer().getTextWidget().redraw(); getViewer().getTextWidget().redraw();
} }
}); });
} }
} else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_FONT)) { } else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_FONT)) {
setFont(JFaceResources.getFont(BuildConsolePreferencePage.PREF_BUILDCONSOLE_FONT)); setFont(JFaceResources.getFont(BuildConsolePreferencePage.PREF_BUILDCONSOLE_FONT));
} else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_TAB_WIDTH)) { } else if (property.equals(BuildConsolePreferencePage.PREF_BUILDCONSOLE_TAB_WIDTH)) {
@ -322,7 +324,7 @@ public class BuildConsolePage extends Page
fScrollLockAction = new ScrollLockAction(getViewer()); fScrollLockAction = new ScrollLockAction(getViewer());
fScrollLockAction.setChecked(fIsLocked); fScrollLockAction.setChecked(fIsLocked);
fNextErrorAction = new NextErrorAction(this); fNextErrorAction = new NextErrorAction(this);
fPreviousErrorAction = new PreviousErrorAction(this); fPreviousErrorAction = new PreviousErrorAction(this);
fShowErrorAction = new ShowErrorAction(this); fShowErrorAction = new ShowErrorAction(this);
fSaveConsoleAction = new SaveConsoleAction(this); fSaveConsoleAction = new SaveConsoleAction(this);
fSaveConsoleAction.setChecked(false); fSaveConsoleAction.setChecked(false);
@ -333,22 +335,22 @@ public class BuildConsolePage extends Page
// each action // each action
IActionBars actionBars = getSite().getActionBars(); IActionBars actionBars = getSite().getActionBars();
TextViewerAction action = new TextViewerAction(getViewer(), ITextOperationTarget.COPY); TextViewerAction action = new TextViewerAction(getViewer(), ITextOperationTarget.COPY);
action.configureAction(ConsoleMessages.BuildConsolePage__Copy_Ctrl_C_6, action.configureAction(ConsoleMessages.BuildConsolePage__Copy_Ctrl_C_6,
ConsoleMessages.BuildConsolePage_Copy_7, ConsoleMessages.BuildConsolePage_Copy_7); ConsoleMessages.BuildConsolePage_Copy_7, ConsoleMessages.BuildConsolePage_Copy_7);
action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
action.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( action.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
ISharedImages.IMG_TOOL_COPY_DISABLED)); ISharedImages.IMG_TOOL_COPY_DISABLED));
action.setHoverImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); action.setHoverImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
setGlobalAction(actionBars, ActionFactory.COPY.getId(), action); setGlobalAction(actionBars, ActionFactory.COPY.getId(), action);
action = new TextViewerAction(getViewer(), ITextOperationTarget.SELECT_ALL); action = new TextViewerAction(getViewer(), ITextOperationTarget.SELECT_ALL);
action.configureAction(ConsoleMessages.BuildConsolePage_Select__All_Ctrl_A_12, action.configureAction(ConsoleMessages.BuildConsolePage_Select__All_Ctrl_A_12,
ConsoleMessages.BuildConsolePage_Select_All, ConsoleMessages.BuildConsolePage_Select_All,
ConsoleMessages.BuildConsolePage_Select_All); ConsoleMessages.BuildConsolePage_Select_All);
setGlobalAction(actionBars, ActionFactory.SELECT_ALL.getId(), action); setGlobalAction(actionBars, ActionFactory.SELECT_ALL.getId(), action);
//XXX Still using "old" resource access //XXX Still using "old" resource access
ResourceBundle bundle = ResourceBundle.getBundle(ConsoleMessages.BUNDLE_NAME); ResourceBundle bundle = ResourceBundle.getBundle(ConsoleMessages.BUNDLE_NAME);
setGlobalAction(actionBars, ActionFactory.FIND.getId(), new FindReplaceAction(bundle, "find_replace_action_", //$NON-NLS-1$ setGlobalAction(actionBars, ActionFactory.FIND.getId(), new FindReplaceAction(bundle, "find_replace_action_", //$NON-NLS-1$
getConsoleView())); getConsoleView()));
action = new TextViewerGotoLineAction(getViewer()); action = new TextViewerGotoLineAction(getViewer());
setGlobalAction(actionBars, ITextEditorActionConstants.GOTO_LINE, action); setGlobalAction(actionBars, ITextEditorActionConstants.GOTO_LINE, action);
actionBars.updateActionBars(); actionBars.updateActionBars();
@ -391,7 +393,7 @@ public class BuildConsolePage extends Page
/** /**
* Returns the view this page is contained in * Returns the view this page is contained in
* *
* @return the view this page is contained in * @return the view this page is contained in
*/ */
protected IConsoleView getConsoleView() { protected IConsoleView getConsoleView() {
@ -400,7 +402,7 @@ public class BuildConsolePage extends Page
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ui.part.IPage#dispose() * @see org.eclipse.ui.part.IPage#dispose()
*/ */
@Override @Override
@ -424,7 +426,7 @@ public class BuildConsolePage extends Page
ISelection selection= null; ISelection selection= null;
if (page != null) if (page != null)
selection= page.getSelection(); selection= page.getSelection();
if (convertSelectionToProject(selection) == null) { if (convertSelectionToProject(selection) == null) {
if (selection instanceof ITextSelection) { if (selection instanceof ITextSelection) {
Object part= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); Object part= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
@ -457,7 +459,7 @@ public class BuildConsolePage extends Page
} }
return false; return false;
} }
public void selectionChanged(IWorkbenchPart part, ISelection selection) { public void selectionChanged(IWorkbenchPart part, ISelection selection) {
IProject newProject = convertSelectionToProject(selection); IProject newProject = convertSelectionToProject(selection);
IProject oldProject = getProject(); IProject oldProject = getProject();
@ -492,7 +494,7 @@ public class BuildConsolePage extends Page
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ui.part.IPage#getControl() * @see org.eclipse.ui.part.IPage#getControl()
*/ */
@Override @Override
@ -505,7 +507,7 @@ public class BuildConsolePage extends Page
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ui.part.IPage#setFocus() * @see org.eclipse.ui.part.IPage#setFocus()
*/ */
@Override @Override
@ -519,7 +521,7 @@ public class BuildConsolePage extends Page
/** /**
* Sets the font for this page. * Sets the font for this page.
* *
* @param font * @param font
* font * font
*/ */
@ -529,7 +531,7 @@ public class BuildConsolePage extends Page
/** /**
* Sets the tab width for this page. * Sets the tab width for this page.
* *
* @param tabs * @param tabs
* tab width * tab width
*/ */
@ -559,14 +561,14 @@ public class BuildConsolePage extends Page
// return this; // return this;
// } // }
// if (IShowInTargetList.class.equals(required)) { // if (IShowInTargetList.class.equals(required)) {
// return this; // return this;
// } // }
return null; return null;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.jface.text.ITextListener#textChanged(org.eclipse.jface.text.TextEvent) * @see org.eclipse.jface.text.ITextListener#textChanged(org.eclipse.jface.text.TextEvent)
*/ */
public void textChanged(TextEvent event) { public void textChanged(TextEvent event) {
@ -579,7 +581,7 @@ public class BuildConsolePage extends Page
/** /**
* Highlight next/previous error or error by console offset * Highlight next/previous error or error by console offset
* @param position POSITION_NEXT (-1), POSITION_PREV (-2), or offset * @param position POSITION_NEXT (-1), POSITION_PREV (-2), or offset
*/ */
void moveToError(int position) { void moveToError(int position) {
IProject project = getProject(); IProject project = getProject();
@ -601,7 +603,7 @@ public class BuildConsolePage extends Page
} }
} }
showError(par, position > 0 || fShowErrorAction.isChecked() ); showError(par, position > 0 || fShowErrorAction.isChecked() );
} }
} }
/** /**
@ -613,24 +615,24 @@ public class BuildConsolePage extends Page
if ( p == null ) return; if ( p == null ) return;
getViewer().selectPartition(par, p); getViewer().selectPartition(par, p);
// Show error in editor if necessary // Show error in editor if necessary
// (always show when absolute positioning, otherwise depends // (always show when absolute positioning, otherwise depends
// on fShowErrorAction state) // on fShowErrorAction state)
if ( openInEditor ) { if ( openInEditor ) {
openErrorInEditor(par.fDocumentMarkerManager.getCurrentErrorMarker()); openErrorInEditor(par.fDocumentMarkerManager.getCurrentErrorMarker());
} }
} }
/** /**
* Open error specified by marker in editor * Open error specified by marker in editor
*/ */
public static void openErrorInEditor(ProblemMarkerInfo marker) { public static void openErrorInEditor(ProblemMarkerInfo marker) {
IWorkbenchWindow window = CUIPlugin.getActiveWorkbenchWindow(); IWorkbenchWindow window = CUIPlugin.getActiveWorkbenchWindow();
if ( marker == null || marker.file == null || window == null ) return; if ( marker == null || marker.file == null || window == null ) return;
IWorkbenchPage page = window.getActivePage(); IWorkbenchPage page = window.getActivePage();
if (page == null) return; if (page == null) return;
IEditorPart editor = page.getActiveEditor(); IEditorPart editor = page.getActiveEditor();
if (editor != null) { if (editor != null) {
IEditorInput input = editor.getEditorInput(); IEditorInput input = editor.getEditorInput();
@ -639,7 +641,7 @@ public class BuildConsolePage extends Page
page.activate(editor); page.activate(editor);
} }
} }
if ( marker.file instanceof IFile ) { if ( marker.file instanceof IFile ) {
try { try {
// Find IMarker corresponding to ProblemMarkerInfo // Find IMarker corresponding to ProblemMarkerInfo
@ -651,15 +653,15 @@ public class BuildConsolePage extends Page
IDE.openEditor(page, m, OpenStrategy.activateOnOpen()); IDE.openEditor(page, m, OpenStrategy.activateOnOpen());
return; return;
} }
} }
} catch (PartInitException e) { } catch (PartInitException e) {
CUIPlugin.log(e); CUIPlugin.log(e);
} catch (CoreException e) { } catch (CoreException e) {
CUIPlugin.log(e); CUIPlugin.log(e);
} }
} }
} }
public void preferenceChange(PreferenceChangeEvent event) { public void preferenceChange(PreferenceChangeEvent event) {
if (fProject != null) { if (fProject != null) {
ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(fProject); ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(fProject);
@ -681,12 +683,12 @@ public class BuildConsolePage extends Page
ICProjectDescription newPd = event.getNewCProjectDescription(); ICProjectDescription newPd = event.getNewCProjectDescription();
ICProjectDescription oldPd = event.getOldCProjectDescription(); ICProjectDescription oldPd = event.getOldCProjectDescription();
if ( fProject != null && fProject.equals(event.getProject()) && if ( fProject != null && fProject.equals(event.getProject()) &&
newPd != null && oldPd != null && newPd != null && oldPd != null &&
newPd.getActiveConfiguration() != null && newPd.getActiveConfiguration() != null &&
newPd.getActiveConfiguration() != oldPd.getActiveConfiguration() ) { newPd.getActiveConfiguration() != oldPd.getActiveConfiguration() ) {
BuildOutputLogger.SaveBuildOutputPreferences bp = BuildOutputLogger.readSaveBuildOutputPreferences(fProject); BuildOutputLogger.SaveBuildOutputPreferences bp = BuildOutputLogger.readSaveBuildOutputPreferences(fProject);
fSaveConsoleAction.setChecked(bp.isSaving); fSaveConsoleAction.setChecked(bp.isSaving);
} }
} }
} }