mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Changes to allow for enablement of the indexer at project creation time - includes new project property for disabling indexer.
This commit is contained in:
parent
35d26b9e76
commit
580e67dcec
13 changed files with 476 additions and 40 deletions
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -68,6 +67,8 @@ 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");
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 (indexEnabled){
|
||||
AddCompilationUnitToIndex job = new AddCompilationUnitToIndex(resource, indexedContainer, this);
|
||||
|
||||
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 (!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){
|
||||
|
@ -248,11 +267,35 @@ 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.
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
2004-05-03 Bogdan Gheorghe
|
||||
Added indexer block property pages
|
||||
|
||||
2004-05-01 Alain Magloire
|
||||
|
||||
Fix for PR 57620
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
<extension-point id="CElementFilters" name="%elementFiltersName"/>
|
||||
<extension-point id="BinaryParserPage" name="%binaryParserPage"/>
|
||||
<extension-point id="PathContainerPage" name="%pathContainerPage" schema="schema/PathContainerPage.exsd"/>
|
||||
|
||||
<!-- =========================================================================== -->
|
||||
<!-- Extension point: org.eclipse.cdt.ui.textHovers -->
|
||||
<!-- Extension Implementation: must implement org.eclipse.jface.text.ITextHover -->
|
||||
|
@ -41,19 +40,25 @@
|
|||
<!-- =========================================================================== -->
|
||||
<extension-point id="textHovers" name="%textHoversName"/>
|
||||
|
||||
<extension point="org.eclipse.core.runtime.adapters">
|
||||
<factory
|
||||
<extension
|
||||
point="org.eclipse.core.runtime.adapters">
|
||||
<factory
|
||||
class="org.eclipse.cdt.internal.ui.CElementAdapterFactory"
|
||||
adaptableType="org.eclipse.cdt.core.model.ICElement">
|
||||
|
||||
<adapter type="org.eclipse.core.resources.IResource"/>
|
||||
<adapter type="org.eclipse.core.resources.IProject"/>
|
||||
|
||||
<adapter type="org.eclipse.ui.model.IWorkbenchAdapter"/>
|
||||
<adapter type="org.eclipse.ui.views.properties.IPropertySource"/>
|
||||
</factory>
|
||||
<adapter
|
||||
type="org.eclipse.core.resources.IResource">
|
||||
</adapter>
|
||||
<adapter
|
||||
type="org.eclipse.core.resources.IProject">
|
||||
</adapter>
|
||||
<adapter
|
||||
type="org.eclipse.ui.model.IWorkbenchAdapter">
|
||||
</adapter>
|
||||
<adapter
|
||||
type="org.eclipse.ui.views.properties.IPropertySource">
|
||||
</adapter>
|
||||
</factory>
|
||||
</extension>
|
||||
|
||||
<!-- Implement our filters for C-View. -->
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.CElementFilters">
|
||||
|
@ -205,7 +210,6 @@
|
|||
</description>
|
||||
</wizard>
|
||||
</extension>
|
||||
|
||||
<!-- Define the document provider and partitionner for the CEditor -->
|
||||
<extension
|
||||
id="org.eclipse.cdt.ui.CDocumentSetupParticipant"
|
||||
|
@ -225,7 +229,6 @@
|
|||
class="org.eclipse.cdt.internal.ui.editor.CDocumentFactory">
|
||||
</factory>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
id="org.eclipse.cdt.ui.ceditor"
|
||||
point="org.eclipse.ui.editors">
|
||||
|
@ -636,7 +639,7 @@
|
|||
id="org.eclipse.cdt.ui.preferneces.WorkInProgressPreferencePage">
|
||||
</page>
|
||||
</extension>
|
||||
<extension
|
||||
<extension
|
||||
point="org.eclipse.search.searchResultViewPages">
|
||||
<viewPage
|
||||
targetClass="org.eclipse.cdt.internal.ui.search.CSearchResult"
|
||||
|
@ -644,6 +647,16 @@
|
|||
id="org.eclipse.cdt.ui.CSearchResultPage">
|
||||
</viewPage>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.propertyPages">
|
||||
<page
|
||||
objectClass="org.eclipse.core.resources.IProject"
|
||||
adaptable="true"
|
||||
name="%CDTIndexerProperty.name"
|
||||
class="org.eclipse.cdt.internal.ui.properties.IndexerOptionPropertyPage"
|
||||
id="org.eclipse.cdt.ui.indexer">
|
||||
</page>
|
||||
</extension>
|
||||
<!--
|
||||
<extension
|
||||
point="org.eclipse.ui.propertyPages">
|
||||
|
@ -683,7 +696,7 @@
|
|||
</page>
|
||||
</extension>
|
||||
-->
|
||||
<extension
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.PathContainerPage">
|
||||
<PathContainerPage
|
||||
name="%defaultPathContainerPage"
|
||||
|
@ -691,4 +704,5 @@
|
|||
id="*">
|
||||
</PathContainerPage>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue