request 1217212, set cursor in new PHP/HTML wizards to file name, if container is...
authorbananeweizen <bananeweizen>
Tue, 20 Dec 2005 19:40:27 +0000 (19:40 +0000)
committerbananeweizen <bananeweizen>
Tue, 20 Dec 2005 19:40:27 +0000 (19:40 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/wizards/HTMLFileWizardPage.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/wizards/PHPFileWizardPage.java

index 796e732..8eca3c0 100644 (file)
@@ -13,8 +13,6 @@ package net.sourceforge.phpeclipse.wizards;
  **********************************************************************/
 
 import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IPath;
@@ -43,7 +41,9 @@ import org.eclipse.ui.dialogs.ContainerSelectionDialog;
  */
 
 public class HTMLFileWizardPage extends WizardPage {
-  private Text containerText;
+  private static final String INITIAL_FILENAME = "file.html";
+
+private Text containerText;
    
   private Text fileText;
 
@@ -126,7 +126,7 @@ public class HTMLFileWizardPage extends WizardPage {
         fileText.setFocus();
       }
     }
-    fileText.setText("*.html");
+    fileText.setText(INITIAL_FILENAME);
   }
 
   /**
@@ -164,10 +164,6 @@ public class HTMLFileWizardPage extends WizardPage {
       return;
     }
 
-//    if (!PHPFileUtil.isPHPFileName(fileName)) {
-//      updateStatus(PHPWizardMessages.getString("WizardPage.mustBePHP"));
-//      return;
-//    }
     updateStatus(null);
   }
 
@@ -192,43 +188,54 @@ public class HTMLFileWizardPage extends WizardPage {
   }
 
   /**
-   * Finds the current directory where the file should be created
-   */
-  protected boolean checkFolderForExistingFile() {
-    boolean result = false;
-
-    if (containerText.getText() != null) {
-      IPath containerPath = new Path(containerText.getText().trim());
-      if (containerPath.segmentCount() > 1) {
-        IFolder container = ResourcesPlugin.getWorkspace().getRoot().getFolder(
-            containerPath);
-        if (container != null && container.exists()) {
-          IResource file = container.getFile(fileText.getText().trim());
-          if (file != null && file.exists()) {
-            this.setErrorMessage(PHPWizardMessages
-                .getString("WizardPage.fileAlreadyExists"));
-            result = true;
-          }
-        }
-      } else {
-        // this is a project
-        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
-            containerText.getText().trim());
-        if (project != null && project.exists()) {
-          IResource file = project.getFile(fileText.getText().trim());
-          if (file != null && file.exists()) {
-            this.setErrorMessage(PHPWizardMessages
-                .getString("WizardPage.fileAlreadyExists"));
-            result = true;
-          }
-        }
-      }
-    }
-
-    if (!result)
-      ((HTMLFileWizard) this.getWizard()).setFileName(fileText.getText().trim());
-
-    return result;
-  }
+        * Finds the current directory where the file should be created
+        */
+       protected boolean checkFolderForExistingFile() {
+               IContainer container = getFileContainer();
+               if (container != null) {
+                       IResource file = container.getFile(new Path(fileText.getText()
+                                       .trim()));
+                       if (file != null && file.exists()) {
+                               this.setErrorMessage(PHPWizardMessages
+                                               .getString("WizardPage.fileAlreadyExists"));
+                               return true;
+                       }
+
+                       ((HTMLFileWizard) this.getWizard()).setFileName(fileText.getText()
+                                       .trim());
+               }
+               return false;
+       }
+
+       private IContainer getFileContainer() {
+               if (containerText.getText() != null) {
+                       IPath containerPath = new Path(containerText.getText().trim());
+                       IContainer container;
+                       if (containerPath.segmentCount() > 1) {
+                               container = ResourcesPlugin.getWorkspace().getRoot().getFolder(
+                                               containerPath);
+                       } else {
+                               // this is a project
+                               container = ResourcesPlugin.getWorkspace().getRoot()
+                                               .getProject(containerText.getText().trim());
+                       }
+                       if (container != null && container.exists()) {
+                               return container;
+                       }
+               }
+               return null;
+       }
+
+       public void setVisible(boolean visible) {
+               super.setVisible(visible);
+               if (visible) {
+                       String fileName=fileText.getText().trim();
+                       if (getFileContainer() != null && fileName.equalsIgnoreCase(INITIAL_FILENAME)) {
+                               fileText.setFocus();
+                               fileText.setText(fileName);
+                               fileText.setSelection(0, fileName.length()-(new Path(INITIAL_FILENAME)).getFileExtension().length()-1);
+                       }
+               }
+       }
 
 }
\ No newline at end of file
index 4e6a174..cb4cb35 100644 (file)
@@ -13,8 +13,6 @@ package net.sourceforge.phpeclipse.wizards;
  **********************************************************************/
 
 import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IPath;
@@ -43,7 +41,9 @@ import org.eclipse.ui.dialogs.ContainerSelectionDialog;
  */
 
 public class PHPFileWizardPage extends WizardPage {
-  private Text containerText;
+  private static final String INITIAL_FILENAME = "file.php";
+
+private Text containerText;
 
   private Text fileText;
 
@@ -126,7 +126,7 @@ public class PHPFileWizardPage extends WizardPage {
         fileText.setFocus();
       }
     }
-    fileText.setText("*.php");
+    fileText.setText(INITIAL_FILENAME);
   }
 
   /**
@@ -167,10 +167,6 @@ public class PHPFileWizardPage extends WizardPage {
       return;
     }
 
-//    if (!PHPFileUtil.isPHPFileName(fileName)) {
-//      updateStatus(PHPWizardMessages.getString("WizardPage.mustBePHP"));
-//      return;
-//    }
     updateStatus(null);
   }
 
@@ -195,43 +191,54 @@ public class PHPFileWizardPage extends WizardPage {
   }
 
   /**
-   * Finds the current directory where the file should be created
-   */
-  protected boolean checkFolderForExistingFile() {
-    boolean result = false;
-
-    if (containerText.getText() != null) {
-      IPath containerPath = new Path(containerText.getText().trim());
-      if (containerPath.segmentCount() > 1) {
-        IFolder container = ResourcesPlugin.getWorkspace().getRoot().getFolder(
-            containerPath);
-        if (container != null && container.exists()) {
-          IResource file = container.getFile(fileText.getText().trim());
-          if (file != null && file.exists()) {
-            this.setErrorMessage(PHPWizardMessages
-                .getString("WizardPage.fileAlreadyExists"));
-            result = true;
-          }
-        }
-      } else {
-        // this is a project
-        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
-            containerText.getText().trim());
-        if (project != null && project.exists()) {
-          IResource file = project.getFile(fileText.getText().trim());
-          if (file != null && file.exists()) {
-            this.setErrorMessage(PHPWizardMessages
-                .getString("WizardPage.fileAlreadyExists"));
-            result = true;
-          }
-        }
-      }
-    }
-
-    if (!result)
-      ((PHPFileWizard) this.getWizard()).setFileName(fileText.getText().trim());
-
-    return result;
-  }
+        * Finds the current directory where the file should be created
+        */
+       protected boolean checkFolderForExistingFile() {
+               IContainer container = getFileContainer();
+               if (container != null) {
+                       IResource file = container.getFile(new Path(fileText.getText()
+                                       .trim()));
+                       if (file != null && file.exists()) {
+                               this.setErrorMessage(PHPWizardMessages
+                                               .getString("WizardPage.fileAlreadyExists"));
+                               return true;
+                       }
+
+                       ((PHPFileWizard) this.getWizard()).setFileName(fileText.getText()
+                                       .trim());
+               }
+               return false;
+       }
+
+       private IContainer getFileContainer() {
+               if (containerText.getText() != null) {
+                       IPath containerPath = new Path(containerText.getText().trim());
+                       IContainer container;
+                       if (containerPath.segmentCount() > 1) {
+                               container = ResourcesPlugin.getWorkspace().getRoot().getFolder(
+                                               containerPath);
+                       } else {
+                               // this is a project
+                               container = ResourcesPlugin.getWorkspace().getRoot()
+                                               .getProject(containerText.getText().trim());
+                       }
+                       if (container != null && container.exists()) {
+                               return container;
+                       }
+               }
+               return null;
+       }
+
+       public void setVisible(boolean visible) {
+               super.setVisible(visible);
+               if (visible) {
+                       String fileName=fileText.getText().trim();
+                       if (getFileContainer() != null && fileName.equalsIgnoreCase(INITIAL_FILENAME)) {
+                               fileText.setFocus();
+                               fileText.setText(fileName);
+                               fileText.setSelection(0, fileName.length()-(new Path(INITIAL_FILENAME)).getFileExtension().length()-1);
+                       }
+               }
+       }
 
 }
\ No newline at end of file