use of io.flutter.settings.FlutterSettings in project flutter-intellij by flutter.
the class FlutterSettingsConfigurable method apply.
@Override
public void apply() throws ConfigurationException {
final String errorMessage = FlutterSdkUtil.getErrorMessageIfWrongSdkRootPath(getSdkPathText());
if (errorMessage != null) {
throw new ConfigurationException(errorMessage);
}
final String sdkHomePath = getSdkPathText();
if (FlutterSdkUtil.isFlutterSdkHome(sdkHomePath)) {
ApplicationManager.getApplication().runWriteAction(() -> {
FlutterSdkUtil.setFlutterSdkPath(myProject, sdkHomePath);
FlutterSdkUtil.enableDartSdk(myProject);
});
}
FlutterInitializer.setCanReportAnalytics(myReportUsageInformationCheckBox.isSelected());
final FlutterSettings settings = FlutterSettings.getInstance();
settings.setReloadOnSave(myHotReloadOnSaveCheckBox.isSelected());
settings.setFormatCodeOnSave(myFormatCodeOnSaveCheckBox.isSelected());
settings.setOrganizeImportsOnSaveKey(myOrganizeImportsOnSaveCheckBox.isSelected());
settings.setShowPreviewArea(myShowPreviewAreaCheckBox.isSelected());
settings.setShowHeapDisplay(myShowHeapDisplayCheckBox.isSelected());
settings.setOpenInspectorOnAppLaunch(myOpenInspectorOnAppLaunchCheckBox.isSelected());
settings.setDart2ModeSettingOrdinal(myPreviewDart2Combo.getSelectedIndex());
settings.setVerboseLogging(myEnableVerboseLoggingCheckBox.isSelected());
// because we rely on remembering initial state
reset();
}
use of io.flutter.settings.FlutterSettings in project flutter-intellij by flutter.
the class FlutterSaveActionsManager method handleBeforeDocumentSaving.
private void handleBeforeDocumentSaving(@NotNull Document document) {
final FlutterSettings settings = FlutterSettings.getInstance();
if (!settings.isFormatCodeOnSave()) {
return;
}
if (!myProject.isInitialized() || myProject.isDisposed()) {
return;
}
final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file == null) {
return;
}
if (!FlutterUtils.isDartFile(file)) {
return;
}
final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
if (psiFile == null || !psiFile.isValid()) {
return;
}
final Module module = ModuleUtil.findModuleForFile(file, myProject);
if (module == null) {
return;
}
if (!DartPlugin.isDartSdkEnabled(module)) {
return;
}
// check for errors
if (PsiErrorElementUtil.hasErrors(myProject, psiFile.getVirtualFile())) {
return;
}
DartAnalysisServerService.getInstance(myProject).serverReadyForRequest(myProject);
if (settings.isOrganizeImportsOnSaveKey()) {
performOrganizeThenFormat(document, file);
} else {
performFormat(document, file, false);
}
}
use of io.flutter.settings.FlutterSettings in project flutter-intellij by flutter.
the class FlutterSettingsConfigurable method isModified.
@Override
public boolean isModified() {
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(myProject);
final FlutterSettings settings = FlutterSettings.getInstance();
final String sdkPathInModel = sdk == null ? "" : sdk.getHomePath();
final String sdkPathInUI = FileUtilRt.toSystemIndependentName(getSdkPathText());
if (!sdkPathInModel.equals(sdkPathInUI)) {
return true;
}
if (FlutterInitializer.getCanReportAnalytics() != myReportUsageInformationCheckBox.isSelected()) {
return true;
}
if (settings.isReloadOnSave() != myHotReloadOnSaveCheckBox.isSelected()) {
return true;
}
if (settings.isFormatCodeOnSave() != myFormatCodeOnSaveCheckBox.isSelected()) {
return true;
}
if (settings.isOrganizeImportsOnSaveKey() != myOrganizeImportsOnSaveCheckBox.isSelected()) {
return true;
}
if (settings.isShowPreviewArea() != myShowPreviewAreaCheckBox.isSelected()) {
return true;
}
if (settings.isShowHeapDisplay() != myShowHeapDisplayCheckBox.isSelected()) {
return true;
}
if (settings.isOpenInspectorOnAppLaunch() != myOpenInspectorOnAppLaunchCheckBox.isSelected()) {
return true;
}
if (settings.getDart2ModeSetting().getOrdinal() != myPreviewDart2Combo.getSelectedIndex()) {
return true;
}
// noinspection RedundantIfStatement
if (settings.isVerboseLogging() != myEnableVerboseLoggingCheckBox.isSelected()) {
return true;
}
return false;
}
use of io.flutter.settings.FlutterSettings in project flutter-intellij by flutter.
the class FlutterSettingsConfigurable method reset.
@Override
public void reset() {
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(myProject);
final String path = sdk != null ? sdk.getHomePath() : "";
FlutterSdkUtil.addKnownSDKPathsToCombo(mySdkCombo.getComboBox());
// Set this after populating the combo box to display correctly when the Flutter SDK is unset.
// (This can happen if the user changed the Dart SDK.)
mySdkCombo.getComboBox().getEditor().setItem(FileUtil.toSystemDependentName(path));
updateVersionText();
myReportUsageInformationCheckBox.setSelected(FlutterInitializer.getCanReportAnalytics());
final FlutterSettings settings = FlutterSettings.getInstance();
myHotReloadOnSaveCheckBox.setSelected(settings.isReloadOnSave());
myFormatCodeOnSaveCheckBox.setSelected(settings.isFormatCodeOnSave());
myOrganizeImportsOnSaveCheckBox.setSelected(settings.isOrganizeImportsOnSaveKey());
myShowPreviewAreaCheckBox.setSelected(settings.isShowPreviewArea());
myShowHeapDisplayCheckBox.setSelected(settings.isShowHeapDisplay());
myOpenInspectorOnAppLaunchCheckBox.setSelected(settings.isOpenInspectorOnAppLaunch());
myPreviewDart2Combo.setSelectedIndex(settings.getDart2ModeSetting().getOrdinal());
myEnableVerboseLoggingCheckBox.setSelected(settings.isVerboseLogging());
myOrganizeImportsOnSaveCheckBox.setEnabled(myFormatCodeOnSaveCheckBox.isSelected());
}
Aggregations