示例#1
0
    protected CompileCppDialog(
        Project _project, CompileHandler compilerHandler, CompileCppOptions options) {
      super(_project, false);

      project = _project;
      setModal(true);

      doRun.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              final boolean b = doRun.isSelected();
              executableFileName.setEnabled(b);
              executableFileName.setEditable(b);
            }
          });

      executableFileName.getEditor().setItem(options != null ? options.getOutputFileName() : "");
      doRun.setSelected(lastRunStatus);

      final CppSupportLoader loader = CppSupportLoader.getInstance(project);
      final String compileParameters = loader.getAdditionalCompileParameters();

      compileProperties.setText(
          (compileParameters != null && compileParameters.length() > 0
                  ? compileParameters + " "
                  : "")
              + CompileHandler.MARKER);

      setTitle(CppBundle.message("compile.cpp.file.dialog.title"));

      compilerSelector.setModel(
          new DefaultComboBoxModel(CppSupportSettings.CompilerSelectOptions.values()));
      compilerSelector.setSelectedItem(getCurrentCompilerOption(project));

      setSelectedProjectCompile();

      includeProjectCompileParametersCheckBox.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              setSelectedProjectCompile();
            }
          });

      includeProjectCompileParametersCheckBox.setSelected(loader.isIncludeProjectSettings());
      final String compileParametersText = compilerHandler.buildProjectCompileOptions(project);
      projectCompileParameters.setText(compileParametersText != null ? compileParametersText : "");

      init();
    }
示例#2
0
  private void invoke(final Project project, final VirtualFile file, CompileCppOptions _options) {
    CompileHandler handler = getCompileHandler(CompileCppDialog.getCurrentCompilerOption(project));

    final CompileCppDialog dialog = new CompileCppDialog(project, handler, _options);
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return;

    _options =
        new CompileCppOptions() {
          public String getCompilerOptions() {
            return dialog.getCompilerOptions();
          }

          public String getProjectCompilerOptions() {
            return dialog.getProjectCompilerOptions();
          }

          public boolean doRun() {
            return dialog.doRun();
          }

          public String getOutputFileName() {
            final String fileName = dialog.getOutputFileName();
            return fileName.length() > 0 ? fileName : null;
          }

          public Project getProject() {
            return project;
          }

          public boolean isCppFile() {
            return "cpp".endsWith(file.getExtension());
          }
        };

    final CompileCppOptions options = _options;
    handler = getCompileHandler(CompileCppDialog.getCurrentCompilerOption(project));
    List<String> runCommand = handler.buildCommand(file, options);

    if (runCommand == null) throw new RuntimeException("Cannot invoke compilation");

    final Map<String, String> commandLineProperties = handler.getCommandLineProperties();

    final String baseForExecutableFile = file.getParent().getPath() + File.separatorChar;
    final String fileToExecute = baseForExecutableFile + handler.getOutputFileName(file, options);
    new File(fileToExecute).delete();

    final ConsoleBuilder consoleBuilderRef[] = new ConsoleBuilder[1];
    Runnable action =
        new Runnable() {
          public void run() {
            if (options.doRun() && new File(fileToExecute).exists()) {
              new ConsoleBuilder(
                      "Run " + file.getName(),
                      new BuildState(
                          Arrays.asList(fileToExecute),
                          new File(file.getParent().getPath()),
                          commandLineProperties),
                      project,
                      null,
                      new Runnable() {
                        public void run() {
                          invoke(project, file, options);
                        }
                      },
                      new Runnable() {
                        public void run() {
                          consoleBuilderRef[0].start();
                        }
                      },
                      null)
                  .start();
            }
          }
        };

    final ConsoleBuilder consoleBuilder =
        new ConsoleBuilder(
            "Compile File " + file.getName(),
            new BuildState(runCommand, new File(file.getParent().getPath()), commandLineProperties),
            project,
            handler.getCompileLogFilter(file, options),
            new Runnable() {
              public void run() {
                invoke(project, file, options);
              }
            },
            null,
            action);
    consoleBuilderRef[0] = consoleBuilder;
    consoleBuilder.start();
  }