Java源码示例:com.intellij.openapi.ui.ex.MessagesEx
示例1
private static boolean askForceOpenDiff(DiffRequest data) {
byte[] bytes1;
byte[] bytes2;
try {
bytes1 = data.getContents()[0].getBytes();
bytes2 = data.getContents()[1].getBytes();
}
catch (IOException e) {
MessagesEx.error(data.getProject(), e.getMessage()).showNow();
return false;
}
String message = Arrays.equals(bytes1, bytes2)
? DiffBundle.message("diff.contents.are.identical.message.text")
: DiffBundle.message("diff.contents.have.differences.only.in.line.separators.message.text");
Messages.showInfoMessage(data.getProject(), message, DiffBundle.message("no.differences.dialog.title"));
return false;
//return Messages.showDialog(data.getProject(), message + "\nShow diff anyway?", "No Differences", new String[]{"Yes", "No"}, 1,
// Messages.getQuestionIcon()) == 0;
}
示例2
/**
* Called when user invokes intention.
*/
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
VirtualFile vFile = file.getVirtualFile();
Document document = PsiDocumentManager.getInstance(project).getDocument(file);
if (document == null) return;
FileDocumentManager.getInstance().saveDocument(document);
try {
vFile.rename(file.getManager(), myTargetName);
} catch (IOException e) {
MessagesEx.error(project, e.getMessage()).showLater();
}
}
示例3
@Override
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) {
VirtualFile vFile = file.getVirtualFile();
Document document = PsiDocumentManager.getInstance(project).getDocument(file);
FileDocumentManager.getInstance().saveDocument(document);
try {
vFile.rename(file.getManager(), myNewFileName);
}
catch(IOException e){
MessagesEx.error(project, e.getMessage()).showLater();
}
}
示例4
private boolean checkFileWritable(final PsiFile file) {
if (!file.isWritable()) {
MessagesEx.fileIsReadOnly(myProject, file.getVirtualFile()).setTitle(CodeInsightBundle.message("error.dialog.readonly.file.title")).showLater();
return false;
}
else {
return true;
}
}
示例5
@Override
public Module createModule(final ModifiableModuleModel moduleModel) throws InvalidDataException, IOException,
ModuleWithNameAlreadyExists, ConfigurationException, JDOMException {
final Module module = super.createModule(moduleModel);
getApplication().invokeLater(() -> {
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
final ProjectDownloader downloader = new ProjectDownloader(this, request);
try {
downloader.download(ProgressManager.getInstance().getProgressIndicator());
} catch (IOException e) {
getApplication()
.invokeLater(() -> MessagesEx
.showErrorDialog(e.getMessage(), getMessage("download.project.file.error")));
}
}, getMessage("download.project.file"), true, null);
final Project moduleProject = module.getProject();
switch (jsonProject.get("buildType").getAsString()) {
case "Maven":
final VirtualFile pomFile = findFileUnderRootInModule(module, "pom.xml");
if (pomFile != null) {
final MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(moduleProject);
mavenProjectsManager.addManagedFiles(singletonList(pomFile));
}
break;
case "Gradle":
final VirtualFile gradleFile = findFileUnderRootInModule(module, "build.gradle");
if (gradleFile != null) {
final ProjectDataManager projectDataManager = getService(ProjectDataManager.class);
// todo: move to JavaGradleProjectImportBuilder
final GradleProjectImportBuilder importBuilder = new GradleProjectImportBuilder(projectDataManager);
final GradleProjectImportProvider importProvider = new GradleProjectImportProvider(importBuilder);
final AddModuleWizard addModuleWizard =
new AddModuleWizard(moduleProject, gradleFile.getPath(), importProvider);
if (addModuleWizard.getStepCount() == 0 && addModuleWizard.showAndGet()) {
// user chose to import via the gradle import prompt
importBuilder.commit(moduleProject, null, null);
}
}
break;
default:
break;
}
}, ModalityState.current());
return module;
}