package net.sourceforge.phpeclipse.wiki.actions;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
+import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.window.Window;
import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.eclipse.ui.internal.dialogs.ListContentProvider;
public final class CreateFilesFromLinksEditorAction extends OpenWikiLinkEditorAction {
+ class WikiFile implements Comparable {
+ IFile file;
+
+ String wikiTitle;
+
+ public WikiFile(IFile f, String title) {
+ file = f;
+ wikiTitle = title;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return wikiTitle + " - " + file.getProjectRelativePath().toString();
+ }
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object o) {
+ return wikiTitle.compareTo(((WikiFile)o).wikiTitle);
+ }
+ }
+
public void openWikiLinkOnSelection() {
IDocument doc = getDocument();
ArrayList startPositionList = getLinksStartingPosition(doc);
if (wikiTitle != null && !wikiTitle.equals("")) {
if (!wikiNames.contains(wikiTitle)) {
IFile file = getWikiFile(currentFile, wikiTitle);
- filesList.add(file);
- wikiList.add(wikiTitle);
+ filesList.add(new WikiFile(file, wikiTitle));
+// wikiList.add(wikiTitle);
wikiNames.add(wikiTitle);
}
}
}
if (filesList.size() > 0) {
- IFile[] files = new IFile[filesList.size()];
- String[] wikiTitles = new String[filesList.size()];
- filesList.toArray(files);
- wikiList.toArray(wikiTitles);
-
- Job job = new CreateFilesJob(files, wikiTitles);
- // job.setRule(createRule(files));
- job.setRule(null);
- job.setUser(true);
- job.schedule();
+ Collections.sort(filesList);
+ ListSelectionDialog listSelectionDialog = new ListSelectionDialog(WikiEditorPlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getShell(), filesList, new ListContentProvider(), new LabelProvider(),
+ "Select the links for file creation:");
+ listSelectionDialog.setTitle("Links found in this article");
+ if (listSelectionDialog.open() == Window.OK) {
+ Object[] locations = listSelectionDialog.getResult();
+ if (locations.length > 0) {
+ IFile[] files = new IFile[locations.length];
+ String[] wikiTitles = new String[locations.length];
+ for (int i = 0; i < files.length; i++) {
+ files[i] = ((WikiFile) locations[i]).file;
+ wikiTitles[i] = ((WikiFile) locations[i]).wikiTitle;
+ }
+
+ Job job = new CreateFilesJob(files, wikiTitles);
+ // job.setRule(createRule(files));
+ job.setRule(null);
+ job.setUser(true);
+ job.schedule();
+ }
+ }
}
}