Search in sources :

Example 1 with FlutterSettings

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();
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) FlutterSettings(io.flutter.settings.FlutterSettings)

Example 2 with FlutterSettings

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) FlutterSettings(io.flutter.settings.FlutterSettings)

Example 3 with FlutterSettings

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;
}
Also used : FlutterSettings(io.flutter.settings.FlutterSettings)

Example 4 with FlutterSettings

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());
}
Also used : FlutterSettings(io.flutter.settings.FlutterSettings)

Aggregations

FlutterSettings (io.flutter.settings.FlutterSettings)4 Module (com.intellij.openapi.module.Module)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1