Skip to content

Commit

Permalink
Export and import projects on working sets export/import. Fixes ilove…
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Feb 22, 2021
1 parent cb10491 commit ddc2c2c
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 36 deletions.
8 changes: 4 additions & 4 deletions AnyEditTools/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,9 @@
class="de.loskutov.anyedit.ui.wizards.WorkingSetExportWizard"
icon="icons/workingSets2.gif"
id="AnyEditTools.workingSetExportWizard"
name="Working Sets">
name="Working Sets and Projects">
<description>
Exports all working sets to the file.
Exports all working sets and local projects to a file.
</description>
</wizard>
</extension>
Expand All @@ -616,9 +616,9 @@
class="de.loskutov.anyedit.ui.wizards.WorkingSetImportWizard"
icon="icons/workingSets.gif"
id="AnyEditTools.workingSetImportWizard"
name="Working Sets">
name="Working Sets and Projects">
<description>
Imports all working sets from file.
Imports all working sets and projects from previously exported file.
</description>
</wizard>
</extension>
Expand Down
38 changes: 37 additions & 1 deletion AnyEditTools/src/de/loskutov/anyedit/ui/wizards/ExportPage.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
/*******************************************************************************
* Copyright (c) 2009 Andrey Loskutov.
* Copyright (c) 2009-2021 Andrey Loskutov.
* 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
* Contributor: Andrey Loskutov - initial API and implementation
* Contributor: Fabio Zadrozny - import local projects
*******************************************************************************/
package de.loskutov.anyedit.ui.wizards;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PlatformUI;
Expand Down Expand Up @@ -46,11 +56,29 @@ private boolean storeSets() {
}
File file = new File(pathname);
XMLMemento memento = XMLMemento.createWriteRoot("workingSets");
Set<IProject> projects = new HashSet<>();

Object[] sets = getSelectedWorkingSets();
for (int i = 0; i < sets.length; i++) {
IMemento childMem = memento.createChild("workingSet");
IWorkingSet set = (IWorkingSet) sets[i];
set.saveState(childMem);
IAdaptable[] elements = set.getElements();
for (IAdaptable iAdaptable : elements) {
IProject project = iAdaptable.getAdapter(IProject.class);
if(project != null) {
projects.add(project);
}
}
}

for(IProject project: projects) {
IMemento child = memento.createChild("project");
IPath location = project.getLocation();
if(location != null) {
child.putString("name", project.getName());
child.putString("location", location.toPortableString());
}
}

FileWriter writer = null;
Expand Down Expand Up @@ -79,6 +107,14 @@ private boolean storeSets() {
return true;
}

@Override
public void createControl(Composite parent) {
super.createControl(parent);
Label label = new Label(comp, SWT.NONE);

label.setText("Note: all "+ResourcesPlugin.getWorkspace().getRoot().getProjects().length+" projects will also be exported");
}

public boolean finish() {
return storeSets();
}
Expand Down
Loading

0 comments on commit ddc2c2c

Please sign in to comment.