mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Bug 563051: Use new Rename API in platform for resource renaming
This removes use of internal API RenameResourceProcessor and removes copying of code from platform's RenameResourceWizard to take advantage of new UI API too. Change-Id: I0e596027751dacf6982d4a63def617ae19f69827
This commit is contained in:
parent
f14853b3d4
commit
fe2daff197
3 changed files with 23 additions and 86 deletions
|
@ -112,7 +112,7 @@ Require-Bundle: org.eclipse.cdt.core;bundle-version="[7.0.0,8.0.0)",
|
||||||
org.eclipse.e4.core.contexts;bundle-version="[1.8.300,2.0.0)",
|
org.eclipse.e4.core.contexts;bundle-version="[1.8.300,2.0.0)",
|
||||||
org.eclipse.help;bundle-version="[3.8.500,4.0.0)",
|
org.eclipse.help;bundle-version="[3.8.500,4.0.0)",
|
||||||
org.eclipse.jface.text;bundle-version="[3.15.300,4.0.0)",
|
org.eclipse.jface.text;bundle-version="[3.15.300,4.0.0)",
|
||||||
org.eclipse.ltk.core.refactoring;bundle-version="[3.10.200,4.0.0)",
|
org.eclipse.ltk.core.refactoring;bundle-version="[3.11.0,4.0.0)",
|
||||||
org.eclipse.ltk.ui.refactoring;bundle-version="[3.10.0,4.0.0)",
|
org.eclipse.ltk.ui.refactoring;bundle-version="[3.10.0,4.0.0)",
|
||||||
org.eclipse.search;bundle-version="[3.11.700,4.0.0)",
|
org.eclipse.search;bundle-version="[3.11.700,4.0.0)",
|
||||||
org.eclipse.ui;bundle-version="[3.114.0,4.0.0)",
|
org.eclipse.ui;bundle-version="[3.114.0,4.0.0)",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2018 Kichwa Coders Ltd and others.
|
* Copyright (c) 2018, 2020 Kichwa Coders Ltd and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -15,29 +15,23 @@ package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.preferences.OrganizeIncludesPreferencePage;
|
import org.eclipse.cdt.internal.ui.preferences.OrganizeIncludesPreferencePage;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.runtime.Assert;
|
||||||
import org.eclipse.jface.dialogs.Dialog;
|
|
||||||
import org.eclipse.jface.dialogs.IDialogSettings;
|
import org.eclipse.jface.dialogs.IDialogSettings;
|
||||||
import org.eclipse.jface.preference.PreferenceDialog;
|
import org.eclipse.jface.preference.PreferenceDialog;
|
||||||
import org.eclipse.jface.wizard.IWizardPage;
|
import org.eclipse.ltk.core.refactoring.participants.IRenameResourceProcessor;
|
||||||
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
import org.eclipse.ltk.ui.refactoring.resource.RenameResourceWizard;
|
||||||
import org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor;
|
|
||||||
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.events.ModifyEvent;
|
|
||||||
import org.eclipse.swt.events.ModifyListener;
|
|
||||||
import org.eclipse.swt.events.SelectionAdapter;
|
import org.eclipse.swt.events.SelectionAdapter;
|
||||||
import org.eclipse.swt.events.SelectionEvent;
|
import org.eclipse.swt.events.SelectionEvent;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
|
||||||
import org.eclipse.swt.widgets.Button;
|
import org.eclipse.swt.widgets.Button;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Control;
|
||||||
import org.eclipse.swt.widgets.Link;
|
import org.eclipse.swt.widgets.Link;
|
||||||
import org.eclipse.swt.widgets.Text;
|
|
||||||
import org.eclipse.ui.dialogs.PreferencesUtil;
|
import org.eclipse.ui.dialogs.PreferencesUtil;
|
||||||
|
|
||||||
public class CResourceRenameRefactoringInputPage extends UserInputWizardPage {
|
public class CResourceRenameRefactoringInputPage
|
||||||
|
extends RenameResourceWizard.RenameResourceRefactoringConfigurationPage {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialog settings key for default setting of update references checkbox.
|
* Dialog settings key for default setting of update references checkbox.
|
||||||
|
@ -47,13 +41,10 @@ public class CResourceRenameRefactoringInputPage extends UserInputWizardPage {
|
||||||
private static final String DIALOG_SETTINGS_KEY = "CResourceRenameRefactoringInputPage"; //$NON-NLS-1$
|
private static final String DIALOG_SETTINGS_KEY = "CResourceRenameRefactoringInputPage"; //$NON-NLS-1$
|
||||||
private IDialogSettings fDialogSettings;
|
private IDialogSettings fDialogSettings;
|
||||||
|
|
||||||
private Text fNameField;
|
|
||||||
private RenameResourceProcessor fRefactoringProcessor;
|
|
||||||
private Button updateReferences;
|
private Button updateReferences;
|
||||||
|
|
||||||
public CResourceRenameRefactoringInputPage(RenameResourceProcessor processor) {
|
public CResourceRenameRefactoringInputPage(IRenameResourceProcessor renameResourceProcessor) {
|
||||||
super("CResourceRenameRefactoringInputPage"); //$NON-NLS-1$
|
super(renameResourceProcessor);
|
||||||
fRefactoringProcessor = processor;
|
|
||||||
IDialogSettings ds = CUIPlugin.getDefault().getDialogSettings();
|
IDialogSettings ds = CUIPlugin.getDefault().getDialogSettings();
|
||||||
fDialogSettings = ds.getSection(DIALOG_SETTINGS_KEY);
|
fDialogSettings = ds.getSection(DIALOG_SETTINGS_KEY);
|
||||||
if (fDialogSettings == null) {
|
if (fDialogSettings == null) {
|
||||||
|
@ -63,32 +54,11 @@ public class CResourceRenameRefactoringInputPage extends UserInputWizardPage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createControl(Composite parent) {
|
public void createControl(Composite parent) {
|
||||||
Composite composite = new Composite(parent, SWT.NONE);
|
super.createControl(parent);
|
||||||
composite.setLayout(new GridLayout(2, false));
|
Control control = getControl();
|
||||||
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
Assert.isTrue(control instanceof Composite,
|
||||||
composite.setFont(parent.getFont());
|
"super class has changed from using composite to something else for the main control."); //$NON-NLS-1$
|
||||||
|
Composite composite = (Composite) control;
|
||||||
Label label = new Label(composite, SWT.NONE);
|
|
||||||
label.setText(RenameMessages.CResourceRenameRefactoringInputPage_new_name);
|
|
||||||
label.setLayoutData(new GridData());
|
|
||||||
|
|
||||||
fNameField = new Text(composite, SWT.BORDER);
|
|
||||||
String resourceName = fRefactoringProcessor.getNewResourceName();
|
|
||||||
fNameField.setText(resourceName);
|
|
||||||
fNameField.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
|
|
||||||
fNameField.addModifyListener(new ModifyListener() {
|
|
||||||
@Override
|
|
||||||
public void modifyText(ModifyEvent e) {
|
|
||||||
validatePage();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
int lastIndexOfDot = resourceName.lastIndexOf('.');
|
|
||||||
if ((fRefactoringProcessor.getResource().getType() == IResource.FILE) && (lastIndexOfDot > 0)) {
|
|
||||||
fNameField.setSelection(0, lastIndexOfDot);
|
|
||||||
} else {
|
|
||||||
fNameField.selectAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateReferences = new Button(composite, SWT.CHECK);
|
updateReferences = new Button(composite, SWT.CHECK);
|
||||||
updateReferences.setText(RenameMessages.CResourceRenameRefactoringInputPage_update_references);
|
updateReferences.setText(RenameMessages.CResourceRenameRefactoringInputPage_update_references);
|
||||||
|
@ -115,48 +85,17 @@ public class CResourceRenameRefactoringInputPage extends UserInputWizardPage {
|
||||||
dialog.open();
|
dialog.open();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Dialog.applyDialogFont(composite);
|
|
||||||
|
|
||||||
setPageComplete(false);
|
|
||||||
setControl(composite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setVisible(boolean visible) {
|
protected void storeSettings() {
|
||||||
if (visible) {
|
super.storeSettings();
|
||||||
fNameField.setFocus();
|
|
||||||
}
|
|
||||||
super.setVisible(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validatePage() {
|
|
||||||
String text = fNameField.getText();
|
|
||||||
RefactoringStatus status = fRefactoringProcessor.validateNewElementName(text);
|
|
||||||
setPageComplete(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean performFinish() {
|
|
||||||
saveRefactoringSettings();
|
|
||||||
saveDialogSettings();
|
|
||||||
return super.performFinish();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IWizardPage getNextPage() {
|
|
||||||
saveRefactoringSettings();
|
|
||||||
saveDialogSettings();
|
|
||||||
return super.getNextPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveDialogSettings() {
|
|
||||||
fDialogSettings.put(KEY_UPDATE_REFERENCES, updateReferences.getSelection());
|
fDialogSettings.put(KEY_UPDATE_REFERENCES, updateReferences.getSelection());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveRefactoringSettings() {
|
@Override
|
||||||
fRefactoringProcessor.setNewResourceName(fNameField.getText());
|
protected void initializeRefactoring() {
|
||||||
fRefactoringProcessor.setUpdateReferences(updateReferences.getSelection());
|
super.initializeRefactoring();
|
||||||
|
getProcessor().setUpdateReferences(updateReferences.getSelection());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2018 Kichwa Coders Ltd and others.
|
* Copyright (c) 2018, 2020 Kichwa Coders Ltd and others.
|
||||||
*
|
*
|
||||||
* This program and the accompanying materials
|
* This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License 2.0
|
* are made available under the terms of the Eclipse Public License 2.0
|
||||||
|
@ -14,7 +14,6 @@
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor;
|
|
||||||
import org.eclipse.ltk.ui.refactoring.resource.RenameResourceWizard;
|
import org.eclipse.ltk.ui.refactoring.resource.RenameResourceWizard;
|
||||||
|
|
||||||
public class CResourceRenameRefactoringWizard extends RenameResourceWizard {
|
public class CResourceRenameRefactoringWizard extends RenameResourceWizard {
|
||||||
|
@ -25,8 +24,7 @@ public class CResourceRenameRefactoringWizard extends RenameResourceWizard {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addUserInputPages() {
|
protected void addUserInputPages() {
|
||||||
RenameResourceProcessor processor = getRefactoring().getAdapter(RenameResourceProcessor.class);
|
addPage(new CResourceRenameRefactoringInputPage(getProcessor()));
|
||||||
addPage(new CResourceRenameRefactoringInputPage(processor));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue