1 package net.sourceforge.phpeclipse.wiki.actions;
3 import java.util.ArrayList;
4 import java.util.HashSet;
6 import org.eclipse.core.resources.IFile;
7 import org.eclipse.core.runtime.jobs.Job;
8 import org.eclipse.jface.text.IDocument;
9 import org.eclipse.ui.IFileEditorInput;
11 public final class CreateFilesFromLinksEditorAction extends OpenWikiLinkEditorAction {
13 public void openWikiLinkOnSelection() {
14 IDocument doc = getDocument();
15 // ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
16 // int pos = selection.getOffset();
17 ArrayList startPositionList = new ArrayList();
18 char[] text = doc.get().toCharArray();
34 if (ch == ']' && startPos != (-1)) {
35 startPositionList.add(new Integer(startPos));
44 } catch (IndexOutOfBoundsException e) {
47 HashSet wikiNames = new HashSet();
48 ArrayList filesList = new ArrayList();
49 ArrayList wikiList = new ArrayList();
52 IFile currentFile = ((IFileEditorInput) editor.getEditorInput()).getFile();
53 for (int i = 0; i < startPositionList.size(); i++) {
54 posInteger = (Integer) startPositionList.get(i);
55 wikiTitle = getWikiTitle(editor, doc, posInteger.intValue());
57 if (wikiTitle != null && !wikiTitle.equals("")) {
58 if (!wikiNames.contains(wikiTitle)) {
59 IFile file = getWikiFile(currentFile, wikiTitle);
61 wikiList.add(wikiTitle);
62 wikiNames.add(wikiTitle);
67 if (filesList.size() > 0) {
68 IFile[] files = new IFile[filesList.size()];
69 String[] wikiTitles = new String[filesList.size()];
70 filesList.toArray(files);
71 wikiList.toArray(wikiTitles);
72 Job job = new CreateFilesJob(files, wikiTitles);
73 // job.setRule(createRule(files));
80 // Iterator iter = wikiNames.iterator();
81 // while (iter.hasNext()) {
82 // openWikiFile(file, (String) iter.next(), false);
86 // public void openWikiFile(IFile cfile, String word, boolean openEditor) {
87 // if (word != null && !word.equals("")) {
88 // IFile file = getWikiFile(cfile, word);
90 // createNewFileIfNeeded(file, word);
91 // } catch (Exception e) {