use of com.intellij.psi.codeStyle.extractor.ui.CodeStyleSettingsNameProvider in project intellij-community by JetBrains.
the class ExtractCodeStyleAction method reportResult.
public void reportResult(final ValuesExtractionResult forSelection, final Project project, final CodeStyleSettings cloneSettings, final PsiFile file, final Map<Value, Object> backup) {
final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder("Formatting Options were extracted<br/><a href=\"apply\">Apply</a> <a href=\"details\">Details...</a>", MessageType.INFO, new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
boolean apply = "apply".equals(e.getDescription());
ExtractedSettingsDialog myDialog = null;
if (!apply) {
final List<Value> values = forSelection.getValues();
final LanguageCodeStyleSettingsProvider[] providers = Extensions.getExtensions(LanguageCodeStyleSettingsProvider.EP_NAME);
Language language = file.getLanguage();
CodeStyleSettingsNameProvider nameProvider = new CodeStyleSettingsNameProvider();
for (final LanguageCodeStyleSettingsProvider provider : providers) {
Language target = provider.getLanguage();
if (target.equals(language)) {
//this is our language
nameProvider.addSettings(provider);
myDialog = new ExtractedSettingsDialog(project, nameProvider, values);
apply = myDialog.showAndGet();
break;
}
}
}
if (apply && myDialog != null) {
//create new settings named after the file
final ExtractedSettingsDialog finalMyDialog = myDialog;
forSelection.applyConditioned(value -> finalMyDialog.valueIsSelectedInTree(value), backup);
CodeStyleScheme derivedScheme = CodeStyleSchemes.getInstance().createNewScheme("Derived from " + file.getName(), null);
derivedScheme.getCodeStyleSettings().copyFrom(cloneSettings);
CodeStyleSchemes.getInstance().addScheme(derivedScheme);
CodeStyleSchemesImpl.getSchemeManager().setCurrent(derivedScheme);
CodeStyleSettingsManager.getInstance(project).PREFERRED_PROJECT_CODE_STYLE = derivedScheme.getName();
}
}
}
}).setDisposable(ApplicationManager.getApplication()).setShowCallout(false).setFadeoutTime(0).setShowCallout(false).setAnimationCycle(0).setHideOnClickOutside(false).setHideOnKeyOutside(false).setCloseButtonEnabled(true).setHideOnLinkClick(true).createBalloon();
ApplicationManager.getApplication().invokeLater(() -> {
Window window = WindowManager.getInstance().getFrame(project);
if (window == null) {
window = JOptionPane.getRootFrame();
}
if (window instanceof IdeFrame) {
BalloonLayout layout = ((IdeFrame) window).getBalloonLayout();
if (layout != null) {
layout.add(balloon);
}
}
});
}
Aggregations