コード例 #1
0
  public void wrap(final String selection, @NotNull final CustomTemplateCallback callback) {
    InputValidatorEx validator =
        new InputValidatorEx() {
          public String getErrorText(String inputString) {
            if (!checkTemplateKey(inputString, callback)) {
              return XmlBundle.message("zen.coding.incorrect.abbreviation.error");
            }
            return null;
          }

          public boolean checkInput(String inputString) {
            return getErrorText(inputString) == null;
          }

          public boolean canClose(String inputString) {
            return checkInput(inputString);
          }
        };
    final String abbreviation =
        Messages.showInputDialog(
            callback.getProject(),
            XmlBundle.message("zen.coding.enter.abbreviation.dialog.label"),
            XmlBundle.message("zen.coding.title"),
            Messages.getQuestionIcon(),
            "",
            validator);
    if (abbreviation != null) {
      doWrap(selection, abbreviation, callback);
    }
  }
コード例 #2
0
 @NotNull
 private static XmlFile parseXmlFileInTemplate(
     String templateString, CustomTemplateCallback callback, boolean createPhysicalFile) {
   XmlFile xmlFile =
       (XmlFile)
           PsiFileFactory.getInstance(callback.getProject())
               .createFileFromText(
                   "dummy.xml",
                   StdFileTypes.XML,
                   templateString,
                   LocalTimeCounter.currentTime(),
                   createPhysicalFile);
   VirtualFile vFile = xmlFile.getVirtualFile();
   if (vFile != null) {
     vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
   }
   return xmlFile;
 }