diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog
index 49e0b006dac..dc72f0ced75 100644
--- a/core/org.eclipse.cdt.core.tests/ChangeLog
+++ b/core/org.eclipse.cdt.core.tests/ChangeLog
@@ -1,3 +1,6 @@
+2004-05-03 Bogdan Gheorghe
+ Changed search and indexer tests to work with new index enablement
+
2004-04-30 Hoda Amer
Final fix for bug#57526 : [CModel] CModelElementsTest needs to test STRUCTURAL_PARSE mode as well
Now All CModel tests run twice, once for quick mode and once for Structural mode (Except for IIncludeTests.java
diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
index 979fea6dfbe..355b0841aeb 100644
--- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
+++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/DependencyTests.java
@@ -10,17 +10,13 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Set;
-
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
@@ -93,6 +89,9 @@ import org.eclipse.core.runtime.Platform;
super.setUp();
//Create temp project
testProject = createProject("DepTestProject");
+
+ testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+
if (testProject==null)
fail("Unable to create project");
diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java
index dc21dd6ac18..bb53e14ce50 100644
--- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java
+++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java
@@ -69,6 +69,9 @@ public class IndexManagerTests extends TestCase {
//Create temp project
testProject = createProject("IndexerTestProject");
+
+ testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+
if (testProject==null)
fail("Unable to create project");
diff --git a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java
index 6c2de725b04..de8d05ee0ac 100644
--- a/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java
+++ b/core/org.eclipse.cdt.core.tests/search/org/eclipse/cdt/core/search/tests/BaseSearchTest.java
@@ -14,9 +14,7 @@
package org.eclipse.cdt.core.search.tests;
import java.io.FileInputStream;
-
import junit.framework.TestCase;
-
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
@@ -25,6 +23,7 @@ import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.testplugin.CProjectHelper;
import org.eclipse.cdt.testplugin.CTestPlugin;
import org.eclipse.cdt.testplugin.FileManager;
@@ -67,7 +66,9 @@ public class BaseSearchTest extends TestCase implements ICSearchConstants {
//Create temp project
testProject = createProject("SearchTestProject");
-
+
+ testProject.setSessionProperty(IndexManager.activationKey,new Boolean(true));
+
if (testProject == null)
fail("Unable to create project");
diff --git a/core/org.eclipse.cdt.core/index/ChangeLog b/core/org.eclipse.cdt.core/index/ChangeLog
index 7c2609be782..05e938bd178 100644
--- a/core/org.eclipse.cdt.core/index/ChangeLog
+++ b/core/org.eclipse.cdt.core/index/ChangeLog
@@ -1,3 +1,6 @@
+2004-05-03 Bogdan Gheorghe
+ Added index enablement checking to index manager
+
2004-04-20 Bogdan Gheorghe
Fix for Bug 54155
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
index 82da101c818..27a3fa4865f 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
@@ -20,8 +20,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.zip.CRC32;
-
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.impl.Index;
@@ -38,8 +38,10 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.QualifiedName;
public class IndexManager extends JobManager implements IIndexConstants {
@@ -71,6 +73,11 @@ public class IndexManager extends JobManager implements IIndexConstants {
private TimeOut timeoutThread = null;
+ public final static String INDEX_MODEL_ID = CCorePlugin.PLUGIN_ID + ".newindexmodel"; //$NON-NLS-1$
+ public final static String ACTIVATION = "enable"; //$NON-NLS-1$
+ public final static QualifiedName activationKey = new QualifiedName(INDEX_MODEL_ID, ACTIVATION);
+
+
public synchronized void aboutToUpdateIndex(IPath path, Integer newIndexState) {
// newIndexState is either UPDATING_STATE or REBUILDING_STATE
// must tag the index as inconsistent, in case we exit before the update job is started
@@ -109,17 +116,29 @@ public class IndexManager extends JobManager implements IIndexConstants {
* Note: the actual operation is performed in background
*/
public void addSource(IFile resource, IPath indexedContainer){
+
+ IProject project = resource.getProject();
+
+ boolean indexEnabled = false;
+ if (project != null)
+ indexEnabled = isIndexEnabled(project);
+ else
+ org.eclipse.cdt.internal.core.model.Util.log(null, "IndexManager addSource: File has no project associated : " + resource.getName(), ICLogConstants.CDT); //$NON-NLS-1$
+
if (CCorePlugin.getDefault() == null) return;
- AddCompilationUnitToIndex job = new AddCompilationUnitToIndex(resource, indexedContainer, this);
- if (!jobSet.add(job.resource.getLocation()))
- return;
-
- if (this.awaitingJobsCount() < MAX_FILES_IN_MEMORY) {
- // reduces the chance that the file is open later on, preventing it from being deleted
- if (!job.initializeContents()) return;
+ if (indexEnabled){
+ AddCompilationUnitToIndex job = new AddCompilationUnitToIndex(resource, indexedContainer, this);
+
+ if (!jobSet.add(job.resource.getLocation()))
+ return;
+
+ if (this.awaitingJobsCount() < MAX_FILES_IN_MEMORY) {
+ // reduces the chance that the file is open later on, preventing it from being deleted
+ if (!job.initializeContents()) return;
+ }
+ request(job);
}
- request(job);
}
public void updateDependencies(IResource resource){
@@ -247,12 +266,36 @@ public class IndexManager extends JobManager implements IIndexConstants {
*/
public void indexAll(IProject project) {
if (CCorePlugin.getDefault() == null) return;
-
- // check if the same request is not already in the queue
- IndexRequest request = new IndexAllProject(project, this);
- for (int i = this.jobEnd; i > this.jobStart; i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488)
- if (request.equals(this.awaitingJobs[i])) return;
- this.request(request);
+
+ //check to see if indexing isEnabled for this project
+ boolean indexEnabled = isIndexEnabled(project);
+
+ if (indexEnabled){
+ // check if the same request is not already in the queue
+ IndexRequest request = new IndexAllProject(project, this);
+ for (int i = this.jobEnd; i > this.jobStart; i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488)
+ if (request.equals(this.awaitingJobs[i])) return;
+ this.request(request);
+ }
+ }
+ /**
+ * @param project
+ * @return
+ */
+ private boolean isIndexEnabled(IProject project) {
+ Boolean indexValue = null;
+
+ try {
+ indexValue = (Boolean) project.getSessionProperty(activationKey);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ if (indexValue != null)
+ return indexValue.booleanValue();
+
+ return false;
}
/**
* Index the content of the given source folder.
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index edb16df3b93..27fb51c4535 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,3 +1,6 @@
+2004-05-03 Bogdan Gheorghe
+ Added indexer block property pages
+
2004-05-01 Alain Magloire
Fix for PR 57620
diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index 863d4d29b74..91ffb3cd2eb 100644
--- a/core/org.eclipse.cdt.ui/plugin.properties
+++ b/core/org.eclipse.cdt.ui/plugin.properties
@@ -153,6 +153,8 @@ HideHeaderFiles.description= Hides all Header files
WorkInProgress.name=Work In Progress
+CDTIndexerProperty.name=CDT Indexer
+
cDocumentFactory=C Document Factory
cDocumentSetupParticipant=C Document Setup Participant
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index 01d166407bd..6a7cd40c7b0 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -33,7 +33,6 @@
-
@@ -41,19 +40,25 @@
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +210,6 @@
-
-
@@ -636,7 +639,7 @@
id="org.eclipse.cdt.ui.preferneces.WorkInProgressPreferencePage">
-
+
+
+
+
-
+
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties
index cb24c8cda65..84146b15371 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties
@@ -44,7 +44,7 @@ BinaryParserBlock.label=Binary Parser
BinaryParserBlock.desc=Set required binary parser for this project
IndexerBlock.label=Indexer
-IndexerBlock.desc=Project Indexer option
+IndexerBlock.desc=Indexer setting for this project. The indexer is required for search and other related features.
ReferenceBlock.label= Projects
ReferenceBlock.desc= Referenced C/C++ Projects
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/properties/IndexerBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/properties/IndexerBlock.java
new file mode 100644
index 00000000000..71ebdeaf115
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/properties/IndexerBlock.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Corp. - Rational Software - initial implementation
+ ******************************************************************************/
+
+package org.eclipse.cdt.ui.properties;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+
+public class IndexerBlock extends AbstractCOptionPage {
+
+ private IndexerOptionDialogPage optionPage;
+ public static final String INDEXER_ENABLED = "indexEnabled"; //$NON-NLS-1$
+ public static final String CDT_INDEXER = "cdt_indexer"; //$NON-NLS-1$
+ public static final String INDEXER_VALUE = "indexValue"; //$NON-NLS-1$
+
+ private static final String INDEXER_LABEL = "IndexerBlock.label"; //$NON-NLS-1$
+ private static final String INDEXER_DESC = "IndexerBlock.desc"; //$NON-NLS-1$
+
+ public IndexerBlock(){
+ super(CUIPlugin.getResourceString(INDEXER_LABEL));
+ setDescription(CUIPlugin.getResourceString(INDEXER_DESC));
+ optionPage = new IndexerOptionDialogPage();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void performApply(IProgressMonitor monitor) throws CoreException {
+ IProject newProject = null;
+ newProject = getContainer().getProject();
+
+ optionPage.persistIndexerValue(newProject);
+
+ boolean indexProject = optionPage.getIndexerValue();
+ if (indexProject && newProject != null)
+ CCorePlugin.getDefault().getCoreModel().getIndexManager().indexAll(newProject);
+
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
+ */
+ public void performDefaults() {
+ // TODO Auto-generated method stub
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite result = new Composite(parent, SWT.NONE);
+ result.setLayout(new GridLayout());
+ result.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ optionPage.createControl(result);
+ optionPage.setIndexerValue(true);
+
+ setControl(result);
+
+
+ }
+
+ public boolean isIndexEnabled(){
+ return optionPage.getIndexerValue();
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/properties/IndexerOptionDialogPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/properties/IndexerOptionDialogPage.java
new file mode 100644
index 00000000000..b86ffcebe56
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/properties/IndexerOptionDialogPage.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Corp. - Rational Software - initial implementation
+ ******************************************************************************/
+
+package org.eclipse.cdt.ui.properties;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+
+public class IndexerOptionDialogPage extends DialogPage {
+
+ private Button indexerEnabled;
+
+ public IndexerOptionDialogPage(){
+ super();
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite result= new Composite(parent, SWT.NONE);
+ GridLayout layout= new GridLayout();
+ layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth= 0;
+ layout.verticalSpacing= convertVerticalDLUsToPixels(10);
+ layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ result.setLayout(layout);
+
+ Group group= new Group(result, SWT.NONE);
+ group.setLayout(new GridLayout());
+ group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ group.setText("CDT Indexer"); //$NON-NLS-1$
+
+ indexerEnabled = createCheckButton(group, "Enable CDT Indexing"); //$NON-NLS-1$
+
+ setControl(result);
+ }
+
+ /**
+ * Creates a button with the given label and sets the default
+ * configuration data.
+ */
+ private Button createCheckButton( Composite parent, String label )
+ {
+ Button button = new Button( parent, SWT.CHECK | SWT.LEFT );
+ button.setText( label );
+ // FieldEditor GridData
+ GridData data = new GridData();
+ button.setLayoutData( data );
+ return button;
+ }
+
+ public void setIndexerValue(boolean value){
+ indexerEnabled.setSelection(value);
+ }
+
+ public boolean getIndexerValue(){
+ return indexerEnabled.getSelection();
+ }
+
+ public void persistIndexerValue(IProject project){
+ ICDescriptor descriptor = null;
+ Element rootElement = null;
+ IProject newProject = null;
+
+ try {
+ newProject = project;
+ descriptor = CCorePlugin.getDefault().getCProjectDescription(newProject);
+ rootElement = descriptor.getProjectData(IndexerBlock.CDT_INDEXER);
+
+
+ // Clear out all current children
+ Node child = rootElement.getFirstChild();
+ while (child != null) {
+ rootElement.removeChild(child);
+ child = rootElement.getFirstChild();
+ }
+ Document doc = rootElement.getOwnerDocument();
+
+ boolean indexProject = getIndexerValue();
+
+ saveIndexerEnabled(indexProject, rootElement, doc);
+
+ descriptor.saveProjectData();
+
+ //Update project session property
+
+ project.setSessionProperty(IndexManager.activationKey,new Boolean(indexProject));
+
+
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+ private static void saveIndexerEnabled (boolean indexerEnabled, Element rootElement, Document doc ) {
+
+ Element indexEnabled = doc.createElement(IndexerBlock.INDEXER_ENABLED);
+ Boolean tempValue= new Boolean(indexerEnabled);
+
+ indexEnabled.setAttribute(IndexerBlock.INDEXER_VALUE,tempValue.toString());
+ rootElement.appendChild(indexEnabled);
+
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/properties/IndexerOptionPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/properties/IndexerOptionPropertyPage.java
new file mode 100644
index 00000000000..ee86eadb61f
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/properties/IndexerOptionPropertyPage.java
@@ -0,0 +1,154 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Corp. - Rational Software - initial implementation
+ ******************************************************************************/
+
+package org.eclipse.cdt.ui.properties;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.dialogs.PropertyPage;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+
+public class IndexerOptionPropertyPage extends PropertyPage {
+
+ private IndexerOptionDialogPage optionPage;
+ private boolean oldIndexerValue;
+
+ public IndexerOptionPropertyPage(){
+ super();
+ optionPage = new IndexerOptionDialogPage();
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createContents(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new FillLayout());
+
+ optionPage.createControl(composite);
+
+ initialize();
+
+ return composite;
+ }
+
+
+ protected void performDefaults() {
+ initialize();
+ super.performDefaults();
+ }
+
+ private void initialize(){
+ IProject project = getProject();
+
+
+ try {
+ oldIndexerValue = getIndexerEnabled(project);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ optionPage.setIndexerValue(oldIndexerValue);
+ }
+
+ /*
+ * @see IPreferencePage#performOk()
+ */
+ public boolean performOk() {
+
+ boolean newIndexerValue = optionPage.getIndexerValue();
+
+ if (oldIndexerValue != newIndexerValue){
+ //persist new value
+ IProject tempProject = getProject();
+ optionPage.persistIndexerValue(tempProject);
+
+ //if indexer is now on send a index all request
+ if (newIndexerValue)
+ CCorePlugin.getDefault().getCoreModel().getIndexManager().indexAll(tempProject);
+
+
+ }
+
+ return true;
+ }
+
+ public IProject getProject(){
+ Object tempElement = getElement();
+ IProject project = null;
+ if (tempElement != null && tempElement instanceof IProject)
+ project = (IProject) tempElement;
+
+ return project;
+ }
+
+ public boolean getIndexerEnabled(IProject project) throws CoreException {
+ boolean indexerEnabled = false;
+
+ // See if there's already one associated with the resource for this
+ // session
+ Boolean indexValue = (Boolean) project.getSessionProperty(IndexManager.activationKey);
+
+ // Try to load one for the project
+ if (indexValue == null) {
+ indexValue = loadIndexerEnabledromCDescriptor(project);
+ }
+
+ // There is nothing persisted for the session, or saved in a file so
+ // create a build info object
+ if (indexValue != null) {
+ project.setSessionProperty(IndexManager.activationKey, indexValue);
+ }
+ else{
+ //Hmm, no persisted indexer value. Could be an old project - set to true and persist
+ indexValue = new Boolean(true);
+ optionPage.setIndexerValue(true);
+ optionPage.persistIndexerValue(project);
+ }
+
+ return indexValue.booleanValue();
+ }
+
+ /**
+ * Loads dis from .cdtproject file
+ * @param project
+ * @param includes
+ * @param symbols
+ * @throws CoreException
+ */
+ private Boolean loadIndexerEnabledromCDescriptor(IProject project) throws CoreException {
+ ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project);
+
+ Node child = descriptor.getProjectData(IndexerBlock.CDT_INDEXER).getFirstChild();
+ Boolean strBool = null;
+
+ while (child != null) {
+ if (child.getNodeName().equals(IndexerBlock.INDEXER_ENABLED))
+ strBool = Boolean.valueOf(((Element)child).getAttribute(IndexerBlock.INDEXER_VALUE));
+
+
+ child = child.getNextSibling();
+ }
+
+ return strBool;
+ }
+
+
+}