diff options
author | Doug Schaefer | 2016-08-25 19:52:40 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-08-25 20:49:28 +0000 |
commit | 50bc082f8413b14cd7f5c5c6b72b493c6e43539e (patch) | |
tree | 37d90e309b5620586687398bd01cdd75978da3f8 /build/org.eclipse.cdt.cmake.ui/src | |
parent | 6cbe4a684917c9b7d04d23b9313bede705150b95 (diff) | |
download | org.eclipse.cdt-50bc082f8413b14cd7f5c5c6b72b493c6e43539e.tar.gz org.eclipse.cdt-50bc082f8413b14cd7f5c5c6b72b493c6e43539e.tar.xz org.eclipse.cdt-50bc082f8413b14cd7f5c5c6b72b493c6e43539e.zip |
Bug 174176 - Hook up CMake build to LaunchBar to select toolchain files
Use launch target os and cpu arch properties to pick toolchains and
toolchain files. UI to add toolchain files. And build support.
Also some clean up of Qt as I found bugs.
Change-Id: Icd1da43460b5954eea15e95ed8ec27850fc4e54e
Diffstat (limited to 'build/org.eclipse.cdt.cmake.ui/src')
8 files changed, 380 insertions, 6 deletions
diff --git a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Activator.java b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Activator.java index a8318124293..3a7e319dd55 100644 --- a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Activator.java +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Activator.java @@ -12,16 +12,19 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; public class Activator extends AbstractUIPlugin { private static Activator plugin; + @Override public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } + @Override public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); @@ -47,4 +50,10 @@ public class Activator extends AbstractUIPlugin { } } + public static <T> T getService(Class<T> service) { + BundleContext context = plugin.getBundle().getBundleContext(); + ServiceReference<T> ref = context.getServiceReference(service); + return ref != null ? context.getService(ref) : null; + } + } diff --git a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakePreferencePage.java b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakePreferencePage.java new file mode 100644 index 00000000000..e6cae98fb80 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakePreferencePage.java @@ -0,0 +1,190 @@ +/******************************************************************************* + * Copyright (c) 2016 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.cdt.cmake.ui.internal; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.cmake.core.ICMakeToolChainFile; +import org.eclipse.cdt.cmake.core.ICMakeToolChainManager; +import org.eclipse.cdt.core.build.IToolChain; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.layout.TableColumnLayout; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +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.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +public class CMakePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + + private ICMakeToolChainManager manager; + private Table filesTable; + private Button removeButton; + + private Map<Path, ICMakeToolChainFile> filesToAdd = new HashMap<>(); + private Map<Path, ICMakeToolChainFile> filesToRemove = new HashMap<>(); + + @Override + public void init(IWorkbench workbench) { + manager = Activator.getService(ICMakeToolChainManager.class); + } + + @Override + protected Control createContents(Composite parent) { + Composite control = new Composite(parent, SWT.NONE); + control.setLayout(new GridLayout()); + + Group filesGroup = new Group(control, SWT.NONE); + filesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + filesGroup.setText("ToolChain Files"); + filesGroup.setLayout(new GridLayout(2, false)); + + Composite filesComp = new Composite(filesGroup, SWT.NONE); + filesComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + filesTable = new Table(filesComp, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION); + filesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + filesTable.setHeaderVisible(true); + filesTable.setLinesVisible(true); + filesTable.addListener(SWT.Selection, e -> { + TableItem[] items = filesTable.getSelection(); + removeButton.setEnabled(items.length > 0); + }); + + TableColumn pathColumn = new TableColumn(filesTable, SWT.NONE); + pathColumn.setText("ToolChain File"); + + TableColumn osColumn = new TableColumn(filesTable, SWT.NONE); + osColumn.setText("OS"); + + TableColumn archColumn = new TableColumn(filesTable, SWT.NONE); + archColumn.setText("CPU"); + + TableColumnLayout tableLayout = new TableColumnLayout(); + tableLayout.setColumnData(pathColumn, new ColumnWeightData(75, 350, true)); + tableLayout.setColumnData(osColumn, new ColumnWeightData(25, 100, true)); + tableLayout.setColumnData(archColumn, new ColumnWeightData(25, 100, true)); + filesComp.setLayout(tableLayout); + + Composite buttonsComp = new Composite(filesGroup, SWT.NONE); + buttonsComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true)); + buttonsComp.setLayout(new GridLayout()); + + Button addButton = new Button(buttonsComp, SWT.PUSH); + addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + addButton.setText("Add..."); + addButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + NewCMakeToolChainFileWizard wizard = new NewCMakeToolChainFileWizard(getFiles()); + WizardDialog dialog = new WizardDialog(getShell(), wizard); + if (dialog.open() == Window.OK) { + ICMakeToolChainFile file = wizard.getNewFile(); + if (filesToRemove.containsKey(file.getPath())) { + filesToRemove.remove(file.getPath()); + } else { + filesToAdd.put(file.getPath(), file); + } + updateTable(); + } + } + }); + + removeButton = new Button(buttonsComp, SWT.PUSH); + removeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + removeButton.setText("Remove"); + removeButton.setEnabled(false); + removeButton.addListener(SWT.Selection, e -> { + if (MessageDialog.openConfirm(getShell(), "Deregister CMake ToolChain File", + "Do you wish to deregister the selected files?")) { + for (TableItem item : filesTable.getSelection()) { + ICMakeToolChainFile file = (ICMakeToolChainFile) item.getData(); + if (filesToAdd.containsKey(file.getPath())) { + filesToAdd.remove(file.getPath()); + } else { + filesToRemove.put(file.getPath(), file); + } + updateTable(); + } + } + }); + + updateTable(); + + return control; + } + + private void updateTable() { + List<ICMakeToolChainFile> sorted = new ArrayList<>(getFiles().values()); + Collections.sort(sorted, (o1, o2) -> o1.getPath().toString().compareToIgnoreCase(o2.getPath().toString())); + + filesTable.removeAll(); + for (ICMakeToolChainFile file : sorted) { + TableItem item = new TableItem(filesTable, SWT.NONE); + item.setText(0, file.getPath().toString()); + String os = file.getProperty(IToolChain.ATTR_OS); + if (os != null) { + item.setText(1, os); + } + String arch = file.getProperty(IToolChain.ATTR_ARCH); + if (arch != null) { + item.setText(2, arch); + } + item.setData(file); + } + } + + private Map<Path, ICMakeToolChainFile> getFiles() { + Map<Path, ICMakeToolChainFile> files = new HashMap<>(); + for (ICMakeToolChainFile file : manager.getToolChainFiles()) { + files.put(file.getPath(), file); + } + + for (ICMakeToolChainFile file : filesToAdd.values()) { + files.put(file.getPath(), file); + } + + for (ICMakeToolChainFile file : filesToRemove.values()) { + files.remove(file.getPath()); + } + + return files; + } + + @Override + public boolean performOk() { + for (ICMakeToolChainFile file : filesToAdd.values()) { + manager.addToolChainFile(file); + } + + for (ICMakeToolChainFile file : filesToRemove.values()) { + manager.removeToolChainFile(file); + } + + return true; + } + +} diff --git a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/properties/Messages.java b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Messages.java index 33caa15ce4f..172957a1a42 100644 --- a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/properties/Messages.java +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Messages.java @@ -1,4 +1,4 @@ -package org.eclipse.cdt.cmake.ui.properties; +package org.eclipse.cdt.cmake.ui.internal; import org.eclipse.osgi.util.NLS; diff --git a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeProjectWizard.java b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeProjectWizard.java index 0e4e431da92..ba0e59ba7f2 100644 --- a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeProjectWizard.java +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeProjectWizard.java @@ -1,3 +1,10 @@ +/******************************************************************************* + * Copyright (c) 2016 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ package org.eclipse.cdt.cmake.ui.internal; import org.eclipse.cdt.cmake.core.CMakeProjectGenerator; diff --git a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeToolChainFilePage.java b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeToolChainFilePage.java new file mode 100644 index 00000000000..9317a9316b6 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeToolChainFilePage.java @@ -0,0 +1,129 @@ +package org.eclipse.cdt.cmake.ui.internal; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Map; + +import org.eclipse.cdt.cmake.core.ICMakeToolChainFile; +import org.eclipse.cdt.cmake.core.ICMakeToolChainManager; +import org.eclipse.cdt.core.build.IToolChain; +import org.eclipse.jface.wizard.WizardPage; +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.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +public class NewCMakeToolChainFilePage extends WizardPage { + + private final Map<Path, ICMakeToolChainFile> existing; + private Text pathText; + private Text osText; + private Text archText; + + public NewCMakeToolChainFilePage(Map<Path, ICMakeToolChainFile> existing) { + super("NewCMakeToolChainFilePage", "New CMake ToolChain File", null); //$NON-NLS-1$ + this.existing = existing; + } + + @Override + public void createControl(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + comp.setLayout(new GridLayout(2, false)); + + Label pathLabel = new Label(comp, SWT.NONE); + pathLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + pathLabel.setText("Path:"); + + Composite pathComp = new Composite(comp, SWT.NONE); + pathComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = layout.marginWidth = 0; + pathComp.setLayout(layout); + + pathText = new Text(pathComp, SWT.BORDER); + pathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + pathText.addModifyListener(e -> validate()); + + Button pathButton = new Button(pathComp, SWT.PUSH); + pathButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + pathButton.setText("Browse..."); + pathButton.addListener(SWT.Selection, e -> { + FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); + dialog.setText("Select location for CMake toolchain file"); + String path = dialog.open(); + if (path != null) { + pathText.setText(path); + } + }); + + Label osLabel = new Label(comp, SWT.NONE); + osLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + osLabel.setText("Target OS:"); + + osText = new Text(comp, SWT.BORDER); + osText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + osText.addModifyListener(e -> validate()); + + Label archLabel = new Label(comp, SWT.NONE); + archLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + archLabel.setText("Target CPU:"); + + archText = new Text(comp, SWT.BORDER); + archText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + archText.addModifyListener(e -> validate()); + + setControl(comp); + validate(); + } + + private void validate() { + setPageComplete(false); + + String path = pathText.getText(); + if (path.isEmpty()) { + setErrorMessage("Please set the path to the CMake toolchain file."); + return; + } + + if (existing.containsKey(Paths.get(path))) { + setErrorMessage("CMake toolchain file entry already exists."); + return; + } + + if (osText.getText().isEmpty()) { + setErrorMessage("Please set the target operating system."); + return; + } + + if (archText.getText().isEmpty()) { + setErrorMessage("Please set the target CPU architecture."); + return; + } + + setPageComplete(true); + setErrorMessage(null); + } + + public ICMakeToolChainFile getNewFile() { + ICMakeToolChainManager manager = Activator.getService(ICMakeToolChainManager.class); + ICMakeToolChainFile file = manager.newToolChainFile(Paths.get(pathText.getText())); + + String os = osText.getText(); + if (!os.isEmpty()) { + file.setProperty(IToolChain.ATTR_OS, os); + } + + String arch = archText.getText(); + if (!arch.isEmpty()) { + file.setProperty(IToolChain.ATTR_ARCH, arch); + } + + return file; + } + +} diff --git a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeToolChainFileWizard.java b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeToolChainFileWizard.java new file mode 100644 index 00000000000..f5be2f3e642 --- /dev/null +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/NewCMakeToolChainFileWizard.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2016 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.cdt.cmake.ui.internal; + +import java.nio.file.Path; +import java.util.Map; + +import org.eclipse.cdt.cmake.core.ICMakeToolChainFile; +import org.eclipse.jface.wizard.Wizard; + +public class NewCMakeToolChainFileWizard extends Wizard { + + private ICMakeToolChainFile newFile; + private NewCMakeToolChainFilePage page; + + public NewCMakeToolChainFileWizard(Map<Path, ICMakeToolChainFile> existing) { + page = new NewCMakeToolChainFilePage(existing); + } + + @Override + public void addPages() { + addPage(page); + } + + @Override + public boolean performFinish() { + newFile = page.getNewFile(); + return true; + } + + public ICMakeToolChainFile getNewFile() { + return newFile; + } + +} diff --git a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/properties/messages.properties b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/messages.properties index ebbe62ef2b5..ebbe62ef2b5 100644 --- a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/properties/messages.properties +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/messages.properties diff --git a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/properties/CMakePropertyPage.java b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/properties/CMakePropertyPage.java index 65052826fcc..7699a3c82d4 100644 --- a/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/properties/CMakePropertyPage.java +++ b/build/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/properties/CMakePropertyPage.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.cmake.ui.properties; import java.io.IOException; +import org.eclipse.cdt.cmake.ui.internal.Messages; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.dialogs.MessageDialog; @@ -35,13 +36,11 @@ import org.eclipse.ui.dialogs.PropertyPage; */ public class CMakePropertyPage extends PropertyPage { + @Override protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(); - composite.setLayout(layout); - GridData data = new GridData(GridData.FILL); - data.grabExcessHorizontalSpace = true; - composite.setLayoutData(data); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setLayout(new GridLayout()); Button b = new Button(composite, SWT.NONE); b.setText(Messages.CMakePropertyPage_LaunchCMakeGui); |