use of com.intellij.ide.util.PropertiesComponent in project ideavim by JetBrains.
the class VimPlugin method setupStatisticsReporter.
/**
* Reports statistics about installed IdeaVim and enabled Vim emulation.
*
* See https://github.com/go-lang-plugin-org/go-lang-idea-plugin/commit/5182ab4a1d01ad37f6786268a2fe5e908575a217
*/
private void setupStatisticsReporter(@NotNull EventFacade eventFacade) {
final Application application = ApplicationManager.getApplication();
eventFacade.addEditorFactoryListener(new EditorFactoryAdapter() {
@Override
public void editorCreated(@NotNull EditorFactoryEvent event) {
final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
final long lastUpdate = propertiesComponent.getOrInitLong(IDEAVIM_STATISTICS_TIMESTAMP_KEY, 0);
final boolean outOfDate = lastUpdate == 0 || System.currentTimeMillis() - lastUpdate > TimeUnit.DAYS.toMillis(1);
if (outOfDate && isEnabled()) {
application.executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
final String buildNumber = ApplicationInfo.getInstance().getBuild().asString();
final String pluginId = IDEAVIM_PLUGIN_ID;
final String version = URLEncoder.encode(getVersion(), CharsetToolkit.UTF8);
final String os = URLEncoder.encode(SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, CharsetToolkit.UTF8);
final String uid = UpdateChecker.getInstallationUID(PropertiesComponent.getInstance());
final String url = "https://plugins.jetbrains.com/plugins/list" + "?pluginId=" + pluginId + "&build=" + buildNumber + "&pluginVersion=" + version + "&os=" + os + "&uuid=" + uid;
PropertiesComponent.getInstance().setValue(IDEAVIM_STATISTICS_TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
HttpRequests.request(url).connect(new HttpRequests.RequestProcessor<Object>() {
@Override
public Object process(@NotNull HttpRequests.Request request) throws IOException {
LOG.info("Sending statistics: " + url);
try {
JDOMUtil.load(request.getInputStream());
} catch (JDOMException e) {
LOG.warn(e);
}
return null;
}
});
} catch (IOException e) {
LOG.warn(e);
}
}
});
}
}
}, application);
}
use of com.intellij.ide.util.PropertiesComponent in project intellij-community by JetBrains.
the class GenerateAntBuildDialog method loadSettings.
private void loadSettings() {
final PropertiesComponent properties = PropertiesComponent.getInstance(myProject);
if (properties.isValueSet(SINGLE_FILE_PROPERTY)) {
final boolean singleFile = properties.isTrueValue(SINGLE_FILE_PROPERTY);
myRbGenerateSingleFileBuild.setSelected(singleFile);
myRbGenerateMultipleFilesBuild.setSelected(!singleFile);
}
if (properties.isValueSet(UI_FORM_PROPERTY)) {
myCbEnableUIFormsCompilation.setSelected(properties.isTrueValue(UI_FORM_PROPERTY));
}
if (properties.isValueSet(FORCE_TARGET_JDK_PROPERTY)) {
myCbForceTargetJdk.setSelected(properties.isTrueValue(FORCE_TARGET_JDK_PROPERTY));
}
if (properties.isValueSet(BACKUP_FILES_PROPERTY)) {
final boolean backup = properties.isTrueValue(BACKUP_FILES_PROPERTY);
myRbBackupFiles.setSelected(backup);
myRbOverwriteFiles.setSelected(!backup);
}
if (properties.isValueSet(INLINE_RUNTIME_CLASSPATH_PROPERTY)) {
myCbInlineRuntimeClasspath.setSelected(properties.isTrueValue(INLINE_RUNTIME_CLASSPATH_PROPERTY));
}
if (properties.isValueSet(GENERATE_IDEA_HOME_PROPERTY)) {
myGenerateIdeaHomeProperty.setSelected(properties.isTrueValue(GENERATE_IDEA_HOME_PROPERTY));
}
if (properties.isValueSet(OUTPUT_FILE_NAME_PROPERTY)) {
myOutputFileNameField.setText(properties.getValue(OUTPUT_FILE_NAME_PROPERTY));
} else {
myOutputFileNameField.setText(BuildProperties.getProjectBuildFileName(myProject));
}
}
use of com.intellij.ide.util.PropertiesComponent in project intellij-community by JetBrains.
the class SearchEverywhereAction method initSearchActions.
private void initSearchActions(JBPopup balloon, MySearchTextField searchTextField) {
final JTextField editor = searchTextField.getTextEditor();
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
jumpNextGroup(true);
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("TAB"), editor, balloon);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
jumpNextGroup(false);
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), editor, balloon);
final AnAction escape = ActionManager.getInstance().getAction("EditorEscape");
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (myBalloon != null && myBalloon.isVisible()) {
myBalloon.cancel();
}
if (myPopup != null && myPopup.isVisible()) {
myPopup.cancel();
}
}
}.registerCustomShortcutSet(escape == null ? CommonShortcuts.ESCAPE : escape.getShortcutSet(), editor, balloon);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
final int index = myList.getSelectedIndex();
if (index != -1) {
doNavigate(index);
}
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER", "shift ENTER"), editor, balloon);
new DumbAwareAction() {
@Override
public void actionPerformed(AnActionEvent e) {
final PropertiesComponent storage = PropertiesComponent.getInstance(e.getProject());
final String[] values = storage.getValues(SE_HISTORY_KEY);
if (values != null) {
if (values.length > myHistoryIndex) {
final List<String> data = StringUtil.split(values[myHistoryIndex], "\t");
myHistoryItem = new HistoryItem(data.get(0), data.get(1), data.get(2));
myHistoryIndex++;
editor.setText(myHistoryItem.pattern);
editor.setCaretPosition(myHistoryItem.pattern.length());
editor.moveCaretPosition(0);
}
}
}
@Override
public void update(AnActionEvent e) {
e.getPresentation().setEnabled(editor.getCaretPosition() == 0);
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("LEFT"), editor, balloon);
}
use of com.intellij.ide.util.PropertiesComponent in project intellij-community by JetBrains.
the class AllFileTemplatesConfigurable method createComponent.
@Override
public JComponent createComponent() {
myUIDisposable = Disposer.newDisposable();
myTemplatesList = new FileTemplateTabAsList(TEMPLATES_TITLE) {
@Override
public void onTemplateSelected() {
onListSelectionChanged();
}
};
myIncludesList = new FileTemplateTabAsList(INCLUDES_TITLE) {
@Override
public void onTemplateSelected() {
onListSelectionChanged();
}
};
myCodeTemplatesList = new FileTemplateTabAsList(CODE_TITLE) {
@Override
public void onTemplateSelected() {
onListSelectionChanged();
}
};
myCurrentTab = myTemplatesList;
final List<FileTemplateTab> allTabs = new ArrayList<>(Arrays.asList(myTemplatesList, myIncludesList, myCodeTemplatesList));
final FileTemplateGroupDescriptorFactory[] factories = Extensions.getExtensions(FileTemplateGroupDescriptorFactory.EXTENSION_POINT_NAME);
if (factories.length != 0) {
myOtherTemplatesList = new FileTemplateTabAsTree(OTHER_TITLE) {
@Override
public void onTemplateSelected() {
onListSelectionChanged();
}
@Override
protected FileTemplateNode initModel() {
SortedSet<FileTemplateGroupDescriptor> categories = new TreeSet<>((o1, o2) -> o1.getTitle().compareTo(o2.getTitle()));
for (FileTemplateGroupDescriptorFactory templateGroupFactory : factories) {
ContainerUtil.addIfNotNull(categories, templateGroupFactory.getFileTemplatesDescriptor());
}
//noinspection HardCodedStringLiteral
return new FileTemplateNode("ROOT", null, ContainerUtil.map2List(categories, s -> new FileTemplateNode(s)));
}
};
allTabs.add(myOtherTemplatesList);
}
myEditor = new FileTemplateConfigurable(myProject);
myEditor.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
onEditorChanged();
}
});
myEditorComponent = myEditor.createComponent();
myEditorComponent.setBorder(JBUI.Borders.empty(10, 0, 10, 10));
myTabs = allTabs.toArray(new FileTemplateTab[allTabs.size()]);
myTabbedPane = new TabbedPaneWrapper(myUIDisposable);
myTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
myLeftPanel = new JPanel(new CardLayout());
myLeftPanel.setBorder(JBUI.Borders.empty(10, 10, 10, 0));
for (FileTemplateTab tab : myTabs) {
myLeftPanel.add(ScrollPaneFactory.createScrollPane(tab.getComponent()), tab.getTitle());
JPanel fakePanel = new JPanel();
fakePanel.setPreferredSize(new Dimension(0, 0));
myTabbedPane.addTab(tab.getTitle(), fakePanel);
}
myTabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
onTabChanged();
}
});
DefaultActionGroup group = new DefaultActionGroup();
AnAction removeAction = new AnAction(IdeBundle.message("action.remove.template"), null, AllIcons.General.Remove) {
@Override
public void actionPerformed(AnActionEvent e) {
onRemove();
}
@Override
public void update(AnActionEvent e) {
super.update(e);
FileTemplate selectedItem = myCurrentTab.getSelectedTemplate();
e.getPresentation().setEnabled(selectedItem != null && !isInternalTemplate(selectedItem.getName(), myCurrentTab.getTitle()));
}
};
AnAction addAction = new AnAction(IdeBundle.message("action.create.template"), null, AllIcons.General.Add) {
@Override
public void actionPerformed(AnActionEvent e) {
onAdd();
}
@Override
public void update(AnActionEvent e) {
super.update(e);
e.getPresentation().setEnabled(!(myCurrentTab == myCodeTemplatesList || myCurrentTab == myOtherTemplatesList));
}
};
AnAction cloneAction = new AnAction(IdeBundle.message("action.copy.template"), null, PlatformIcons.COPY_ICON) {
@Override
public void actionPerformed(AnActionEvent e) {
onClone();
}
@Override
public void update(AnActionEvent e) {
super.update(e);
e.getPresentation().setEnabled(myCurrentTab != myCodeTemplatesList && myCurrentTab != myOtherTemplatesList && myCurrentTab.getSelectedTemplate() != null);
}
};
AnAction resetAction = new AnAction(IdeBundle.message("action.reset.to.default"), null, AllIcons.Actions.Reset) {
@Override
public void actionPerformed(AnActionEvent e) {
onReset();
}
@Override
public void update(AnActionEvent e) {
super.update(e);
final FileTemplate selectedItem = myCurrentTab.getSelectedTemplate();
e.getPresentation().setEnabled(selectedItem instanceof BundledFileTemplate && !selectedItem.isDefault());
}
};
group.add(addAction);
group.add(removeAction);
group.add(cloneAction);
group.add(resetAction);
addAction.registerCustomShortcutSet(CommonShortcuts.INSERT, myCurrentTab.getComponent());
removeAction.registerCustomShortcutSet(CommonShortcuts.getDelete(), myCurrentTab.getComponent());
myToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent();
myToolBar.setBorder(IdeBorderFactory.createEmptyBorder());
JPanel toolbarPanel = new JPanel(new BorderLayout());
toolbarPanel.add(myToolBar, BorderLayout.WEST);
JComponent schemaComponent = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, new DefaultCompactActionGroup(new ChangeSchemaCombo(this)), true).getComponent();
JPanel schemaPanel = new JPanel(new BorderLayout());
schemaPanel.add(schemaComponent, BorderLayout.EAST);
schemaPanel.add(new JLabel("Schema:"), BorderLayout.WEST);
toolbarPanel.add(schemaPanel, BorderLayout.EAST);
JPanel centerPanel = new JPanel(new BorderLayout());
centerPanel.add(myTabbedPane.getComponent(), BorderLayout.NORTH);
Splitter splitter = new Splitter(false, 0.3f);
splitter.setDividerWidth(JBUI.scale(10));
splitter.setFirstComponent(myLeftPanel);
splitter.setSecondComponent(myEditorComponent);
centerPanel.add(splitter, BorderLayout.CENTER);
myMainPanel = new JPanel(new BorderLayout());
myMainPanel.add(toolbarPanel, BorderLayout.NORTH);
myMainPanel.add(centerPanel, BorderLayout.CENTER);
final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
final String tabName = propertiesComponent.getValue(CURRENT_TAB);
if (selectTab(tabName)) {
//final String selectedTemplateName = propertiesComponent.getValue(SELECTED_TEMPLATE);
//for (FileTemplate template : myCurrentTab.getTemplates()) {
// if (Comparing.strEqual(template.getName(), selectedTemplateName)) {
// myCurrentTab.selectTemplate(template);
// break;
// }
//}
}
return myMainPanel;
}
use of com.intellij.ide.util.PropertiesComponent in project intellij-community by JetBrains.
the class FileColorsModel method setConfigurations.
public void setConfigurations(@NotNull List<FileColorConfiguration> configurations, boolean isProjectLevel) {
if (isProjectLevel) {
myProjectLevelConfigurations.clear();
myProjectLevelConfigurations.addAll(configurations);
} else {
myApplicationLevelConfigurations.clear();
Map<String, String> predefinedScopeNameToPropertyKey = new THashMap<>(FileColorsModel.predefinedScopeNameToPropertyKey);
PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
for (FileColorConfiguration configuration : configurations) {
myApplicationLevelConfigurations.add(configuration);
String propertyKey = predefinedScopeNameToPropertyKey.remove(configuration.getScopeName());
if (propertyKey != null) {
propertiesComponent.setValue(propertyKey, configuration.getColorName());
}
}
for (String scopeName : predefinedScopeNameToPropertyKey.keySet()) {
// empty string means that value deleted
propertiesComponent.setValue(predefinedScopeNameToPropertyKey.get(scopeName), "");
// previously it was saved incorrectly as scope name instead of specified property key
propertiesComponent.setValue(scopeName, null);
}
}
}
Aggregations