Implemeted action for uploading Wikipedia articles (thanks to D.Wunsch)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / actions / OpenWikiLinkEditorAction.java
index de7a91f..d8b4537 100644 (file)
@@ -9,6 +9,7 @@ import net.sourceforge.phpeclipse.wiki.preferences.Util;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IResourceStatus;
 import org.eclipse.core.resources.ResourcesPlugin;
@@ -146,7 +147,27 @@ public final class OpenWikiLinkEditorAction implements IEditorActionDelegate {
     openWikiFile(ei.getFile(), textRegion);
   }
 
-  void openWikiFile(IFile cfile, String word) {
+  public static void openWikiUrl(IProject project, String word) {
+    if (word != null && !word.equals("")) {
+      IFile cfile = project.getFile("dummy.wp");
+      IFile file = getWikiFile(cfile, word);
+      try {
+        createNewFileIfNeeded(file, word);
+        //                             if (WikiEditorPlugin.getDefault().getPreferenceStore().getBoolean(WikiConstants.REUSE_EDITOR)) {
+        //                                     saveIfNeeded();
+        //                                     getActivePage().reuseEditor(reusableEditor, new FileEditorInput(file));
+        //                             } else {
+        IDE.openEditor(WikiEditorPlugin.getDefault().getActivePage(), file, true);
+        //                                     redrawText();
+        //                             }
+      } catch (Exception e) {
+        //                       WikiEditorPlugin.getDefault().logAndReport(WikiEditorPlugin.getResourceString(WikiConstants.RESOURCE_WIKI_ERROR_DIALOGUE_OPEN_WIKI_FILE_TITLE),
+        // WikiPlugin.getResourceString(WikiConstants.RESOURCE_WIKI_ERROR_DIALOGUE_OPEN_WIKI_FILE_TEXT), e);
+      }
+    } 
+  } 
+  
+  public static void openWikiFile(IFile cfile, String word) {
     if (word != null && !word.equals("")) {
       IFile file = getWikiFile(cfile, word);
       try {
@@ -165,13 +186,13 @@ public final class OpenWikiLinkEditorAction implements IEditorActionDelegate {
     } 
   }
 
-  private void createNewFileIfNeeded(IFile file, String word) throws CoreException {
+  private static void createNewFileIfNeeded(IFile file, String word) throws CoreException {
     if (!file.exists()) {
       createWikiFile(file, word);
     }
   }
 
-  private IFile getWikiFile(IFile file, String word) {
+  private static IFile getWikiFile(IFile file, String word) {
     String wikiFileName = Util.getWikiFileName(word, file, WikiEditorPlugin.HTML_OUTPUT_PATH);
     IPath path = new Path(wikiFileName);
     return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
@@ -186,11 +207,11 @@ public final class OpenWikiLinkEditorAction implements IEditorActionDelegate {
    * @return the new folder resource handle
    * @see #createFolder
    */
-  private IFolder createFolderHandle(IPath folderPath) {
+  private static IFolder createFolderHandle(IPath folderPath) {
     return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(folderPath);
   }
 
-  private void createFolder(IFolder folderHandle, IProgressMonitor monitor) throws CoreException {
+  private static void createFolder(IFolder folderHandle, IProgressMonitor monitor) throws CoreException {
     try {
       // Create the folder resource in the workspace
       // Recursive to create any folders which do not exist already
@@ -213,7 +234,7 @@ public final class OpenWikiLinkEditorAction implements IEditorActionDelegate {
     }
   }
 
-  private void createWikiFile(IFile file, String word) throws CoreException {
+  private static void createWikiFile(IFile file, String word) throws CoreException {
     IContainer parent = file.getParent();
     if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
       createFolder((IFolder) parent, null);