Java Code Examples for com.intellij.ide.util.PropertiesComponent

The following examples show how to use com.intellij.ide.util.PropertiesComponent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void dependingOnBspProjectExistence(Project project, Runnable onNoBspProject, Consumer<String> onBspProject) {
  PropertiesComponent properties = PropertiesComponent.getInstance(project);

  String linkedBspProject = properties.getValue(BSP_LINKED_PROJECT_PATH);
  if (linkedBspProject == null) {
    onNoBspProject.run();
  }
  else {
    if (LocalFileSystem.getInstance().findFileByPath(linkedBspProject) == null) {
      properties.unsetValue(BSP_LINKED_PROJECT_PATH);
      onNoBspProject.run();
    }
    else {
      onBspProject.accept(linkedBspProject);
    }
  }
}
 
Example 2
@NotNull
public static String[] getKnownFlutterSdkPaths() {
  final Set<String> paths = new HashSet<>();

  // scan current projects for existing flutter sdk settings
  for (Project project : ProjectManager.getInstance().getOpenProjects()) {
    final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
    if (flutterSdk != null) {
      paths.add(flutterSdk.getHomePath());
    }
  }

  // use the list of paths they've entered in the past
  final String[] knownPaths = PropertiesComponent.getInstance().getValues(FLUTTER_SDK_KNOWN_PATHS);
  if (knownPaths != null) {
    paths.addAll(Arrays.asList(knownPaths));
  }

  // search the user's path
  final String fromUserPath = locateSdkFromPath();
  if (fromUserPath != null) {
    paths.add(fromUserPath);
  }

  return paths.toArray(new String[0]);
}
 
Example 3
Source Project: intellij   Source File: BlazeEditProjectViewControl.java    License: Apache License 2.0 6 votes vote down vote up
private String getDefaultProjectDataDirectory(String projectName) {
  File canonicalProjectDataLocation = workspaceData.canonicalProjectDataLocation();
  if (canonicalProjectDataLocation != null) {
    return canonicalProjectDataLocation.getPath();
  }
  String lastProjectLocation =
      PropertiesComponent.getInstance().getValue(LAST_PROJECT_LOCATION_PROPERTY);
  if (lastProjectLocation == null) {
    // TODO(brendandouglas): remove this temporary fall-back once LAST_PROJECT_LOCATION_PROPERTY
    // is populated
    lastProjectLocation = RecentProjectsManager.getInstance().getLastProjectCreationLocation();
  }
  if (lastProjectLocation == null) {
    return newUniquePath(new File(getDefaultProjectsDirectory(), projectName));
  }
  // Because RecentProjectsManager uses PathUtil.toSystemIndependentName.
  lastProjectLocation = lastProjectLocation.replace('/', File.separatorChar);
  File lastProjectParent = new File(lastProjectLocation);
  if (lastProjectParent.getName().equals(BlazeDataStorage.PROJECT_DATA_SUBDIRECTORY)) {
    lastProjectParent = lastProjectParent.getParentFile();
  }
  return newUniquePath(new File(lastProjectParent, projectName));
}
 
Example 4
Source Project: consulo   Source File: CommitChangeListDialog.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void dispose() {
  myDisposed = true;
  Disposer.dispose(myBrowser);
  Disposer.dispose(myCommitMessageArea);
  Disposer.dispose(myOKButtonUpdateAlarm);
  myUpdateButtonsRunnable.cancel();
  super.dispose();
  Disposer.dispose(myDiffDetails);
  PropertiesComponent.getInstance().setValue(SPLITTER_PROPORTION_OPTION, mySplitter.getProportion(), SPLITTER_PROPORTION_OPTION_DEFAULT);
  float usedProportion = myDetailsSplitter.getUsedProportion();
  if (usedProportion > 0) {
    PropertiesComponent.getInstance().setValue(DETAILS_SPLITTER_PROPORTION_OPTION, usedProportion, DETAILS_SPLITTER_PROPORTION_OPTION_DEFAULT);
  }
  PropertiesComponent.getInstance().setValue(DETAILS_SHOW_OPTION, myDetailsSplitter.isOn(), DETAILS_SHOW_OPTION_DEFAULT);
}
 
Example 5
Source Project: OkHttpParamsGet   Source File: KotlinParamsStringBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void addNullableValue(PsiField field, StringBuilder sb, String defaultName) {
    boolean add = PropertiesComponent.getInstance().getBoolean(Constant.VALUE_NULL, false);
    if (!add) {
        sb.append(field.getName()).append("?.also{\n");
        sb.append(mFieldName).append("[");
        if (defaultName == null) {
            sb.append('"').append(field.getName()).append('"');
        } else {
            sb.append(defaultName);
        }
        sb.append("] = ").append(toString(field, false, "it")).append("\n}\n");
    } else {
        sb.append(mFieldName).append("[");
        if (defaultName == null) {
            sb.append('"').append(field.getName()).append('"');
        } else {
            sb.append(defaultName);
        }
        sb.append("] = ").append(toString(field, true, null)).append("?: \"\"\n");
    }
}
 
Example 6
Source Project: OkHttpParamsGet   Source File: BaseBuilder.java    License: Apache License 2.0 6 votes vote down vote up
protected boolean isNullable(@NotNull PsiElement element) {
    if (element instanceof PsiField) {
        PsiField field = (PsiField) element;
        if (field.getType() instanceof PsiPrimitiveType) {
            return false;
        }
        boolean defaultNullable = PropertiesComponent.getInstance().getBoolean(Constant.NULLABLE, true);
        if (defaultNullable) {
            return !NonNullFactory.hasNonNull(field.getAnnotations());
        }
        return NonNullFactory.hasNullable(field.getAnnotations());
    } else if (element instanceof KtProperty) {
        KtProperty property = (KtProperty) element;
        KtTypeReference reference = property.getTypeReference();
        return reference != null && reference.getTypeElement() instanceof KtNullableType;
    }
    return false;
}
 
Example 7
Source Project: consulo   Source File: ComboBoxWithHistory.java    License: Apache License 2.0 6 votes vote down vote up
public void save() {
  final StringBuilder buf = new StringBuilder("<map>");
  for (Object key : myWeights.keySet()) {
    if (key != null) {
      final Long value = myWeights.get(key);
      if (value != null) {
        buf.append("<element>")
           .append("<key>").append(key).append("</key>")
           .append("<value>").append(value).append("</value>")
           .append("</element>");
      }
    }
  }

  final String xml = buf.append("</map>").toString();

  if (myProject == null) {
    PropertiesComponent.getInstance().setValue(myHistoryId, xml);
  } else {
    PropertiesComponent.getInstance(myProject).setValue(myHistoryId, xml);
  }
}
 
Example 8
private void checkForDisplayFirstReload() {
  final PropertiesComponent properties = PropertiesComponent.getInstance(myProject);

  final boolean alreadyRun = properties.getBoolean(RELOAD_ALREADY_RUN);
  if (!alreadyRun) {
    properties.setValue(RELOAD_ALREADY_RUN, true);

    final Notification notification = new Notification(
      FlutterMessages.FLUTTER_NOTIFICATION_GROUP_ID,
      FlutterBundle.message("flutter.reload.firstRun.title"),
      FlutterBundle.message("flutter.reload.firstRun.content"),
      NotificationType.INFORMATION);
    notification.setIcon(FlutterIcons.HotReload);
    notification.addAction(new AnAction("Learn more") {
      @Override
      public void actionPerformed(@NotNull AnActionEvent event) {
        BrowserUtil.browse(FlutterBundle.message("flutter.reload.firstRun.url"));
        notification.expire();
      }
    });
    Notifications.Bus.notify(notification);
  }
}
 
Example 9
Source Project: yiistorm   Source File: YiiStormSettingsPage.java    License: MIT License 6 votes vote down vote up
@Override
public void apply() throws ConfigurationException {
    PropertiesComponent properties = PropertiesComponent.getInstance(project);
    properties.setValue("enableYiiStorm", String.valueOf(enableYiiStorm.isSelected()));
    properties.setValue("themeName", themeNameField.getText());
    properties.setValue("langName", langField.getText());
    properties.setValue("yiicFile", yiicFileField.getText());
    // properties.setValue("yiiConfigPath", yiiConfigPath.getText());
    // properties.setValue("yiiLitePath", yiiLitePath.getText());
    // properties.setValue("useYiiCompleter", String.valueOf(useYiiCompleter.isSelected()));
    // properties.setValue("useYiiMigrations", String.valueOf(useMigrationsCheckbox.isSelected()));

    final ToolWindowManager manager = ToolWindowManager.getInstance(project);
    final ToolWindow tw = manager.getToolWindow("Migrations");
    if (tw != null) {
        tw.setAvailable(MigrationsCondition.makeCondition(project), null);
    }
   /* if (properties.getBoolean("useYiiCompleter", false)) {
        YiiStormProjectComponent.getInstance(project).loadConfigParser();
    } else {
        YiiStormProjectComponent.getInstance(project).clearConfigParser();
    } */

}
 
Example 10
Source Project: android-xml-sorter   Source File: XmlInstantSorterAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent event) {

    final Project project = getEventProject(event);
    final Editor editor = event.getData(PlatformDataKeys.EDITOR);
    XmlSorterDialog dialog = new XmlSorterDialog(project);

    PropertiesComponent pc = PropertiesComponent.getInstance();
    execute(project,
            editor,
            pc.getInt(PC_KEY_INPUT_CASE, 0) == 0,
            dialog.getPrefixSpacePositionValueAt(pc.getInt(PC_KEY_PREFIX_SPACE_POS, 0)),
            pc.getBoolean(PC_KEY_SPACE_BETWEEN_PREFIX, true),
            pc.getBoolean(PC_KEY_INSERT_XML_INFO, true),
            pc.getBoolean(PC_KEY_DELETE_COMMENT, false),
            dialog.getCodeIndentValueAt(pc.getInt(PC_KEY_CODE_INDENT, 1)),
            pc.getBoolean(PC_KEY_SEPARATE_NON_TRANSLATABLE, false));
}
 
Example 11
@NotNull
@Override
protected String getDirectory(AnActionEvent event, PluginSettingsState settings) {  // todo: settings are not required anymore
    Project project = getEventProject(event);
    if (project == null) {
        return System.getProperty("user.home");
    }

    PropertiesComponent properties = PropertiesComponent.getInstance(project);
    String defaultDirectory = properties.getValue(DEFAULT_DIRECTORY_PROPERTY_KEY);

    if (defaultDirectory == null) {
        defaultDirectory = project.getBasePath();
        if (defaultDirectory == null) {
            defaultDirectory = System.getProperty("user.home");
        }
    }
    return defaultDirectory;
}
 
Example 12
@Override
public void reset() {
    if (settingPanel == null || languageEngineBox == null || filterList == null
            || btnAddFilter == null || btnDeleteFilter == null)
        return;
    PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();

    currentEngine = TranslationEngineType.fromName(
            propertiesComponent.getValue(StorageDataKey.SettingLanguageEngine));
    languageEngineBox.setSelectedItem(currentEngine);
    languageEngineChanged = false;
    initUI(currentEngine);

    Log.i("reset, current engine: " + currentEngine);

    languageEngineBox.requestFocus();

    // filter rules
    filterRulesChanged = false;
    resetFilterList();
}
 
Example 13
Source Project: consulo   Source File: ProjectStructureConfigurable.java    License: Apache License 2.0 6 votes vote down vote up
@Inject
public ProjectStructureConfigurable(final Project project,
                                    final ProjectLibrariesConfigurable projectLibrariesConfigurable,
                                    final ModuleStructureConfigurable moduleStructureConfigurable,
                                    ArtifactsStructureConfigurable artifactsStructureConfigurable) {
  myProject = project;
  myArtifactsStructureConfigurable = artifactsStructureConfigurable;

  myModuleConfigurator = new ModulesConfigurator(myProject);
  myContext = new StructureConfigurableContext(myProject, myModuleConfigurator);
  myModuleConfigurator.setContext(myContext);

  myProjectLibrariesConfig = projectLibrariesConfigurable;
  myModulesConfig = moduleStructureConfigurable;

  myProjectLibrariesConfig.init(myContext);
  myModulesConfig.init(myContext);
  if (!project.isDefault()) {
    myArtifactsStructureConfigurable.init(myContext, myModulesConfig, myProjectLibrariesConfig);
  }

  myProjectConfig = new ProjectConfigurable(project, getContext(), getModuleConfigurator());
  final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(myProject);
  myUiState.lastEditedConfigurable = propertiesComponent.getValue("project.structure.last.edited");
}
 
Example 14
Source Project: trains-pycharm-plugin   Source File: HookConfigurable.java    License: Apache License 2.0 5 votes vote down vote up
private static void loadFromProperties(Project project){
    PropertiesComponent properties = PropertiesComponent.getInstance(project);
    storedKey = properties.getValue(PATH_KEY);
    storedSecret = properties.getValue(PATH_SECRET);
    storedAPI = properties.getValue(PATH_API);
    storedWEB = properties.getValue(PATH_WEB);
    storedFILES = properties.getValue(PATH_FILES);
}
 
Example 15
Source Project: consulo   Source File: NotificationTestAction.java    License: Apache License 2.0 5 votes vote down vote up
private NotificationDialog(@Nullable Project project) {
  super(project, true, IdeModalityType.MODELESS);
  myMessageBus = project != null ? project.getMessageBus() : Application.get().getMessageBus();
  init();
  setOKButtonText("Notify");
  setTitle("Test Notification");
  myMessage.setText(PropertiesComponent.getInstance().getValue(MESSAGE_KEY, "GroupID:\nTitle:\nSubtitle:\nContent:\nType:\nActions:\nSticky:\n"));
}
 
Example 16
Source Project: consulo   Source File: GotoClassModel2.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void saveInitialCheckBoxState(boolean state) {
  PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(myProject);
  if (Boolean.TRUE.toString().equals(propertiesComponent.getValue("GoToClass.toSaveIncludeLibraries"))){
    propertiesComponent.setValue("GoToClass.includeLibraries", Boolean.toString(state));
  }
}
 
Example 17
Source Project: AndroidLocalizePlugin   Source File: LanguageHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Save the language data selected in the current project.
 *
 * @param project   current project.
 * @param languages selected language.
 */
public static void saveSelectedLanguage(@NotNull Project project, @NotNull List<LANG> languages) {
    Objects.requireNonNull(project);
    Objects.requireNonNull(languages);

    PropertiesComponent.getInstance(project)
            .setValue(Constants.KEY_SELECTED_LANGUAGES, getLanguageCodeString(languages));
}
 
Example 18
Source Project: idea-gitignore   Source File: Properties.java    License: MIT License 5 votes vote down vote up
/**
 * Stores information about dismissed notification about editing ignored file.
 *
 * @param project current project
 * @param file    current file
 */
public static void setDismissedIgnoredEditingNotification(@NotNull Project project, @NotNull VirtualFile file) {
    final PropertiesComponent props = properties(project);
    String[] values = props.getValues(DISMISSED_IGNORED_EDITING_NOTIFICATION);

    final HashSet<String> set = ContainerUtil.newHashSet(values != null ? values : new String[0]);
    set.add(file.getCanonicalPath());

    props.setValues(DISMISSED_IGNORED_EDITING_NOTIFICATION, set.toArray(new String[0]));
}
 
Example 19
Source Project: GsonFormat   Source File: Config.java    License: Apache License 2.0 5 votes vote down vote up
public static Config getInstant() {

        if (config == null) {
            config = new Config();
            config.setFieldPrivateMode(PropertiesComponent.getInstance().getBoolean("fieldPrivateMode", true));
            config.setUseSerializedName(PropertiesComponent.getInstance().getBoolean("useSerializedName", false));
            config.setObjectFromData(PropertiesComponent.getInstance().getBoolean("objectFromData", false));
            config.setObjectFromData1(PropertiesComponent.getInstance().getBoolean("objectFromData1", false));
            config.setArrayFromData(PropertiesComponent.getInstance().getBoolean("arrayFromData", false));
            config.setArrayFromData1(PropertiesComponent.getInstance().getBoolean("arrayFromData1", false));
            config.setSuffixStr(PropertiesComponent.getInstance().getValue("suffixStr", "Bean"));
            config.setReuseEntity(PropertiesComponent.getInstance().getBoolean("reuseEntity", false));
            config.setObjectFromDataStr(PropertiesComponent.getInstance().getValue("objectFromDataStr", Constant.objectFromObject));
            config.setObjectFromDataStr1(PropertiesComponent.getInstance().getValue("objectFromDataStr1", Constant.objectFromObject1));
            config.setArrayFromDataStr(PropertiesComponent.getInstance().getValue("arrayFromDataStr", Constant.arrayFromData));
            config.setArrayFromData1Str(PropertiesComponent.getInstance().getValue("arrayFromData1Str", Constant.arrayFromData1));
            config.setAnnotationStr(PropertiesComponent.getInstance().getValue("annotationStr", Constant.gsonAnnotation));
            config.setEntityPackName(PropertiesComponent.getInstance().getValue("entityPackName"));
            config.setFiledNamePreFixStr(PropertiesComponent.getInstance().getValue("filedNamePreFixStr"));
            config.setErrorCount(PropertiesComponent.getInstance().getOrInitInt("errorCount", 0));
            config.setVirgoMode(PropertiesComponent.getInstance().getBoolean("virgoMode", true));
            config.setUseFieldNamePrefix(PropertiesComponent.getInstance().getBoolean("useFieldNamePrefix", false));
            config.setGenerateComments(PropertiesComponent.getInstance().getBoolean("generateComments", true));
            config.setSplitGenerate(PropertiesComponent.getInstance().getBoolean("splitGenerate", false));
            config.setUseWrapperClass(PropertiesComponent.getInstance().getBoolean("useWrapperClass", false));

        }
        return config;
    }
 
Example 20
Source Project: OkHttpParamsGet   Source File: JavaBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected StringBuilder createRequestBody(StringBuilder builder, String contentType, String content, boolean file) {
    boolean version4 = PropertiesComponent.getInstance().getBoolean(Constant.OKHTTP_VERSION, true);
    builder.append(getRequestBody()).append(".create(");
    if (version4) {
        builder.append(content).append(',');
        builder.append(getMediaType()).append(".parse(").append(contentType).append(")");
    } else {
        builder.append(getMediaType()).append(".parse(").append(contentType).append(")");
        builder.append(',').append(content);
    }
    builder.append(")");
    return builder;
}
 
Example 21
Source Project: OkHttpParamsGet   Source File: KotlinParamsStringBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected String getParamsType() {
    if (!PropertiesComponent.getInstance().getBoolean(Constant.ARRAY_MAP, true)) {
        return "HashMap<String, String>";
    }
    return "ArrayMap<String, String>";
}
 
Example 22
Source Project: MavenHelper   Source File: CreateCustomGoalAction.java    License: Apache License 2.0 5 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
	ApplicationService instance = ApplicationService.getInstance();
	ApplicationSettings state = instance.getState();

	DataContext context = e.getDataContext();
	Project project = MavenActionUtil.getProject(context);
	String pomDir = Utils.getPomDirAsString(context, mavenProject);
	MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
	PsiFile data = LangDataKeys.PSI_FILE.getData(e.getDataContext());
	ConfigurationContext configurationContext = ConfigurationContext.getFromContext(e.getDataContext());


	GoalEditor editor = new GoalEditor("Create and Run", "", state, true, e.getProject(), e.getDataContext());
	if (editor.showAndGet()) {
		String s = editor.getCmd();
		if (StringUtils.isNotBlank(s)) {

			Goal goal = new Goal(s);

			PropertiesComponent.getInstance().setValue(GoalEditor.SAVE, editor.isPersist(), true);
			if (editor.isPersist()) {
				state.getGoals().add(goal);
				instance.registerAction(goal, getRunGoalAction(goal));
			}

			if (runGoal) {
				getRunGoalAction(goal).actionPerformed(project, pomDir, projectsManager, data, configurationContext);
			}
		}
	}

}
 
Example 23
Source Project: consulo   Source File: TextFieldWithStoredHistory.java    License: Apache License 2.0 5 votes vote down vote up
public void reset() {
  final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
  final String history = propertiesComponent.getValue(myPropertyName);
  if (history != null) {
    final String[] items = history.split("\n");
    ArrayList<String> result = new ArrayList<String>();
    for (String item : items) {
      if (item != null && item.length() > 0) {
        result.add(item);
      }
    }
    setHistory(result);
    setSelectedItem("");
  }
}
 
Example 24
Source Project: consulo   Source File: PlatformOrPluginUpdateChecker.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate force bundle jre flag. If flag set version changed - it will be dropped
 */
private static void validateForceBundledJreVersion() {
  String oldVer = PropertiesComponent.getInstance().getValue(ourForceJREBuildVersion);

  String curVer = ApplicationInfo.getInstance().getBuild().toString();

  if (!Objects.equals(oldVer, curVer)) {
    PropertiesComponent.getInstance().unsetValue(ourForceJREBuild);
  }
}
 
Example 25
Source Project: OkHttpParamsGet   Source File: KotlinParamsObjectBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected String getParamsType() {
    if (!PropertiesComponent.getInstance().getBoolean(Constant.ARRAY_MAP, true)) {
        return "HashMap<String, Any>";
    }
    return "ArrayMap<String, Any>";
}
 
Example 26
Source Project: OkHttpParamsGet   Source File: KotlinParamsObjectBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected String[] getImports() {
    if (!PropertiesComponent.getInstance().getBoolean(Constant.ARRAY_MAP, true)) {
        return null;
    }
    return new String[]{PropertiesComponent.getInstance().getBoolean(Constant.ANDROIDX, true) ? "androidx.collection.ArrayMap" : "android.support.v4.util.ArrayMap"};
}
 
Example 27
Source Project: consulo   Source File: FileColorsModel.java    License: Apache License 2.0 5 votes vote down vote up
public void load(@Nonnull Element e, boolean isProjectLevel) {
  List<FileColorConfiguration> configurations = isProjectLevel ? myProjectLevelConfigurations : myApplicationLevelConfigurations;

  configurations.clear();

  Map<String, String> predefinedScopeNameToPropertyKey = new THashMap<>(myPredefinedScopeNameToPropertyKey);
  for (Element child : e.getChildren(FILE_COLOR)) {
    FileColorConfiguration configuration = FileColorConfiguration.load(child);
    if (configuration != null) {
      if (!isProjectLevel) {
        predefinedScopeNameToPropertyKey.remove(configuration.getScopeName());
      }
      configurations.add(configuration);
    }
  }

  if (!isProjectLevel) {
    PropertiesComponent properties = PropertiesComponent.getInstance();
    for (String scopeName : predefinedScopeNameToPropertyKey.keySet()) {
      String colorName = getColorNameForScope(properties, scopeName, predefinedScopeNameToPropertyKey);

      // empty means that value deleted
      if (!StringUtil.isEmpty(colorName)) {
        configurations.add(new FileColorConfiguration(scopeName, colorName));
      }
    }
  }
}
 
Example 28
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = getEventProject(e);
    VirtualFile directory = getSelectedDirectory(e);
    if (project == null || directory == null) return;

    PropertiesComponent properties = PropertiesComponent.getInstance(project);
    properties.setValue(DEFAULT_DIRECTORY_PROPERTY_KEY, directory.getPath());

    log.info("'" + properties.getValue(DEFAULT_DIRECTORY_PROPERTY_KEY) +
            "' is set as default directory for project: " + project.getName());
}
 
Example 29
Source Project: consulo   Source File: SearchTextFieldWithStoredHistory.java    License: Apache License 2.0 5 votes vote down vote up
public void reset() {
  final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
  final String history = propertiesComponent.getValue(myPropertyName);
  if (history != null) {
    final String[] items = history.split("\n");
    ArrayList<String> result = new ArrayList<>();
    for (String item : items) {
      if (item != null && item.length() > 0) {
        result.add(item);
      }
    }
    setHistory(result);
  }
  setSelectedItem("");
}
 
Example 30
Source Project: consulo   Source File: DesktopToolWindowContentUi.java    License: Apache License 2.0 5 votes vote down vote up
private static AnAction createMergeTabsAction(final ContentManager manager, final String tabPrefix) {
  return new DumbAwareAction("Merge tabs to '" + tabPrefix + "' group") {
    @RequiredUIAccess
    @Override
    public void actionPerformed(@Nonnull AnActionEvent e) {
      final Content selectedContent = manager.getSelectedContent();
      final List<Pair<String, JComponent>> tabs = new ArrayList<Pair<String, JComponent>>();
      int selectedTab = -1;
      for (Content content : manager.getContents()) {
        if (tabPrefix.equals(content.getUserData(Content.TAB_GROUP_NAME_KEY))) {
          final String label = content.getTabName().substring(tabPrefix.length() + 2);
          final JComponent component = content.getComponent();
          if (content == selectedContent) {
            selectedTab = tabs.size();
          }
          tabs.add(Pair.create(label, component));
          manager.removeContent(content, false);
          content.setComponent(null);
          Disposer.dispose(content);
        }
      }
      PropertiesComponent.getInstance().unsetValue(TabbedContent.SPLIT_PROPERTY_PREFIX + tabPrefix);
      for (int i = 0; i < tabs.size(); i++) {
        final Pair<String, JComponent> tab = tabs.get(i);
        ContentUtilEx.addTabbedContent(manager, tab.second, tabPrefix, tab.first, i == selectedTab);
      }
    }
  };
}