cleanup
[fedora-idea.git] / platform / platform-api / src / com / intellij / ui / TextFieldWithStoredHistory.java
bloba2bcc73d5aede38cb1da59c8ac17f83166f1c824
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.ui;
18 import com.intellij.ide.util.PropertiesComponent;
19 import com.intellij.openapi.util.text.StringUtil;
20 import org.jetbrains.annotations.NonNls;
22 import java.util.ArrayList;
24 /**
25 * User: anna
26 * Date: 16-Dec-2005
28 public class TextFieldWithStoredHistory extends TextFieldWithHistory {
29 private final String myPropertyName;
31 // API compatibility with 7.0.1
32 @SuppressWarnings({"UnusedDeclaration"})
33 public TextFieldWithStoredHistory(@NonNls final String propertyName, boolean cropList) {
34 this(propertyName);
37 public TextFieldWithStoredHistory(@NonNls final String propertyName) {
38 myPropertyName = propertyName;
39 reset();
42 public void addCurrentTextToHistory() {
43 super.addCurrentTextToHistory();
44 PropertiesComponent.getInstance().setValue(myPropertyName, StringUtil.join(getHistory(), "\n"));
47 public void reset() {
48 final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
49 final String history = propertiesComponent.getValue(myPropertyName);
50 if (history != null) {
51 final String[] items = history.split("\n");
52 ArrayList<String> result = new ArrayList<String>();
53 for (String item : items) {
54 if (item != null && item.length() > 0) {
55 result.add(item);
58 setHistory(result);
59 setSelectedItem("");