use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project flutter-intellij by flutter.
the class FlutterErrorReportSubmitter method submitAsync.
@SuppressWarnings("deprecation")
@Override
public void submitAsync(@NotNull IdeaLoggingEvent[] events, @Nullable String additionalInfo, @NotNull Component parentComponent, @NotNull Consumer<SubmittedReportInfo> consumer) {
if (events.length == 0) {
consumer.consume(new SubmittedReportInfo(null, null, SubmittedReportInfo.SubmissionStatus.FAILED));
return;
}
final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
Project project = PlatformDataKeys.PROJECT.getData(dataContext);
if (project == null) {
project = ProjectManager.getInstance().getDefaultProject();
}
final StringBuilder builder = new StringBuilder();
builder.append("Please file this bug report at https://github.com/flutter/flutter-intellij/issues/new.\n");
builder.append("\n");
builder.append("---\n");
builder.append("\n");
builder.append("## What happened\n");
builder.append("\n");
if (additionalInfo != null) {
builder.append(additionalInfo.trim()).append("\n");
} else {
builder.append("(please describe what you were doing when this exception occurred)\n");
}
builder.append("\n");
builder.append("## Version information\n");
builder.append("\n");
// IntelliJ version
final ApplicationInfo info = ApplicationInfo.getInstance();
builder.append(info.getVersionName()).append(" `").append(info.getFullVersion()).append("`");
final PluginId pid = FlutterUtils.getPluginId();
final IdeaPluginDescriptor flutterPlugin = PluginManager.getPlugin(pid);
// noinspection ConstantConditions
builder.append(" • Flutter plugin `").append(pid.getIdString()).append(' ').append(flutterPlugin.getVersion()).append("`");
final IdeaPluginDescriptor dartPlugin = PluginManager.getPlugin(PluginId.getId("Dart"));
if (dartPlugin != null) {
// noinspection ConstantConditions
builder.append(" • Dart plugin `").append(dartPlugin.getVersion()).append("`");
}
builder.append("\n\n");
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
if (sdk == null) {
builder.append("No Flutter sdk configured.\n");
} else {
final String flutterVersion = getFlutterVersion(sdk);
if (flutterVersion != null) {
builder.append(flutterVersion.trim()).append("\n");
} else {
builder.append("Error getting Flutter sdk information.\n");
}
}
builder.append("\n");
for (IdeaLoggingEvent event : events) {
builder.append("## Exception\n");
builder.append("\n");
builder.append(event.getMessage()).append("\n");
builder.append("\n");
if (event.getThrowable() != null) {
builder.append("```\n");
builder.append(event.getThrowableText().trim()).append("\n");
builder.append("```\n");
builder.append("\n");
FlutterInitializer.getAnalytics().sendException(event.getThrowable(), false);
}
}
final String text = builder.toString().trim() + "\n";
// Create scratch file.
final ScratchRootType scratchRoot = ScratchRootType.getInstance();
final VirtualFile file = scratchRoot.createScratchFile(project, "bug-report.md", Language.ANY, text);
if (file != null) {
// Open the file.
new OpenFileDescriptor(project, file).navigate(true);
} else {
consumer.consume(new SubmittedReportInfo(null, null, SubmittedReportInfo.SubmissionStatus.FAILED));
}
consumer.consume(new SubmittedReportInfo(null, "", SubmittedReportInfo.SubmissionStatus.NEW_ISSUE));
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project idea-php-typo3-plugin by cedricziel.
the class GenerateActionControllerAction method write.
@Override
protected void write(@NotNull Project project, @NotNull PsiDirectory extensionRootDirectory, @NotNull String className) {
if (!className.endsWith("Controller")) {
className += "Controller";
}
final String finalClassName = className;
RunResult<PsiElement> elementRunResult = new WriteCommandAction<PsiElement>(project) {
@Override
protected void run(@NotNull Result result) throws Throwable {
PsiElement extensionFile;
Map<String, String> context = new HashMap<>();
String calculatedNamespace = ExtensionUtility.findDefaultNamespace(extensionRootDirectory);
if (calculatedNamespace == null) {
result.setResult(null);
return;
}
calculatedNamespace += "Controller";
context.put("namespace", calculatedNamespace);
context.put("className", finalClassName);
try {
extensionFile = ExtensionFileGenerationUtil.fromTemplate("extension_file/ExtbaseActionController.php", "Classes/Controller", finalClassName + ".php", extensionRootDirectory, context, project);
if (extensionFile != null) {
result.setResult(extensionFile);
}
} catch (IncorrectOperationException e) {
// file already exists
}
}
}.execute();
if (elementRunResult.getResultObject() != null) {
new OpenFileDescriptor(project, elementRunResult.getResultObject().getContainingFile().getVirtualFile(), 0).navigate(true);
} else {
Messages.showErrorDialog("Cannot create extension file", "Error");
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project idea-php-typo3-plugin by cedricziel.
the class GenerateExtbaseEntityAction method write.
@Override
protected void write(@NotNull Project project, @NotNull PsiDirectory extensionRootDirectory, @NotNull String className) {
final String finalClassName = className;
RunResult<PsiElement> elementRunResult = new WriteCommandAction<PsiElement>(project) {
@Override
protected void run(@NotNull Result result) throws Throwable {
PsiElement extensionFile;
Map<String, String> context = new HashMap<>();
String calculatedNamespace = ExtensionUtility.findDefaultNamespace(extensionRootDirectory);
if (calculatedNamespace == null) {
result.setResult(null);
return;
}
calculatedNamespace += "Domain\\Model";
context.put("namespace", calculatedNamespace);
context.put("className", finalClassName);
try {
extensionFile = ExtensionFileGenerationUtil.fromTemplate("extension_file/ExtbaseEntity.php", "Classes/Domain/Model", finalClassName + ".php", extensionRootDirectory, context, project);
if (extensionFile != null) {
result.setResult(extensionFile);
}
} catch (IncorrectOperationException e) {
// file already exists
}
}
}.execute();
if (elementRunResult.getResultObject() != null) {
new OpenFileDescriptor(project, elementRunResult.getResultObject().getContainingFile().getVirtualFile(), 0).navigate(true);
} else {
Messages.showErrorDialog("Cannot create extension file", "Error");
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project idea-php-typo3-plugin by cedricziel.
the class GenerateFscElementForm method generate.
/**
* Does the actual code generation.
*/
private void generate() {
String formElementName = this.elementName.getText();
String formElementTitle = this.elementTitle.getText();
String formElementDescription = this.elementDescription.getText();
String successMessage = "New Content Element \"" + formElementName + "\" in extension " + extensionDefinition.getExtensionKey() + " successfully created.";
String errorMessageOverridesExist = "The TCA definition file for the element already exists. Unsupported operation.";
// Exit if element exists. Maybe one day... *sigh*
if (ExtensionFileGenerationUtil.extensionHasFile(extensionDefinition, "Configuration/TCA/Overrides/tt_content_element_" + formElementName + ".php")) {
Notification notification = new Notification("TYPO3 CMS Plugin", "TYPO3 CMS", errorMessageOverridesExist, NotificationType.ERROR);
Notifications.Bus.notify(notification, this.project);
this.dispose();
return;
}
/*
* Build template context. It will be available in the templates through '{{ marker }}' markers
*/
Map<String, String> context = new HashMap<>();
context.put("elementName", formElementName);
context.put("elementTitle", formElementTitle);
context.put("elementDescription", formElementDescription);
context.put("extensionKey", extensionDefinition.getExtensionKey());
context.put("templateName", StringUtils.capitalize(formElementName) + ".html");
context.put("icon", (String) this.icon.getSelectedItem());
/*
* Generate element main TypoScript
*/
PsiElement element = ExtensionFileGenerationUtil.fromTemplate("contentElement/fsc/ts_setup.typoscript", "Configuration/TypoScript/ContentElement", formElementName + ".typoscript", extensionDefinition, context, project);
new OpenFileDescriptor(project, element.getContainingFile().getVirtualFile(), 0).navigate(true);
/*
* Generate element main fluid template
*/
PsiElement templateElement = ExtensionFileGenerationUtil.fromTemplate("contentElement/fsc/element.html", "Resources/Private/Templates/ContentElements", context.get("templateName"), extensionDefinition, context, project);
new OpenFileDescriptor(project, templateElement.getContainingFile().getVirtualFile(), 0).navigate(true);
/*
* Generate element TypoScript include to main TS template
*/
String ceImport = "<INCLUDE_TYPOSCRIPT: source=\"FILE:EXT:" + extensionDefinition.getExtensionKey() + "/Configuration/TypoScript/ContentElement/" + formElementName + ".typoscript\">";
VirtualFile mainTsFile = ExtensionFileGenerationUtil.appendOrCreate(ceImport, "Configuration/TypoScript", "setup.txt", extensionDefinition, context, project);
if (mainTsFile == null) {
return;
}
new OpenFileDescriptor(project, mainTsFile, 0).navigate(true);
/*
* Generate New content element wizard tsconfig
*/
String newCeTsconfig = ExtensionFileGenerationUtil.readTemplateToString("contentElement/fsc/newcewizard.tsconfig", context);
VirtualFile newCeTsConfigFile = ExtensionFileGenerationUtil.appendOrCreate(newCeTsconfig, "Configuration/PageTSconfig", "NewContentElementWizard.tsconfig", extensionDefinition, context, project);
new OpenFileDescriptor(project, newCeTsConfigFile, 0).navigate(true);
/*
* Generate element TCA overrides
*/
PsiElement elementTcaOverrides = ExtensionFileGenerationUtil.fromTemplate("contentElement/fsc/tca_overrides_ttcontent.php", "Configuration/TCA/Overrides", "tt_content_element_" + formElementName + ".php", extensionDefinition, context, project);
new OpenFileDescriptor(project, elementTcaOverrides.getContainingFile().getVirtualFile(), 0).navigate(true);
if (!ExtensionFileGenerationUtil.extensionHasFile(extensionDefinition, "Configuration/TCA/Overrides/sys_template.php")) {
/*
* Generate static template imports
*/
PsiElement sysTemplateImport = ExtensionFileGenerationUtil.fromTemplate("contentElement/fsc/tca_overrides_systemplate.php", "Configuration/TCA/Overrides", "sys_template.php", extensionDefinition, context, project);
new OpenFileDescriptor(project, sysTemplateImport.getContainingFile().getVirtualFile(), 0).navigate(true);
} else {
successMessage += "\nsys_template overrides already exist. Please check that the static template is added.";
}
Notification notification = new Notification("TYPO3 CMS Plugin", "TYPO3 CMS", successMessage, NotificationType.INFORMATION);
Notifications.Bus.notify(notification, this.project);
this.dispose();
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoConsoleFilterTest method doFileLineTest.
private void doFileLineTest(@NotNull String line, int startOffset, int endOffset, String targetPath, int targetLine, int targetColumn) {
Filter.Result result = myFilter.applyFilter(line, line.length());
assertNotNull(result);
HyperlinkInfo info = assertResultAndGetHyperlink(result, startOffset, endOffset);
assertInstanceOf(info, OpenFileHyperlinkInfo.class);
OpenFileDescriptor fileDescriptor = ((OpenFileHyperlinkInfo) info).getDescriptor();
assertNotNull(fileDescriptor);
assertEquals(targetPath, fileDescriptor.getFile().getPath());
assertEquals("line", targetLine, fileDescriptor.getLine() + 1);
assertEquals("column", targetColumn, fileDescriptor.getColumn() + 1);
}
Aggregations