Search in sources :

Example 6 with PropertiesComponent

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);
}
Also used : EditorFactoryAdapter(com.intellij.openapi.editor.event.EditorFactoryAdapter) EditorFactoryEvent(com.intellij.openapi.editor.event.EditorFactoryEvent) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) HttpRequests(com.intellij.util.io.HttpRequests) Application(com.intellij.openapi.application.Application) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 7 with PropertiesComponent

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));
    }
}
Also used : PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 8 with PropertiesComponent

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);
}
Also used : JBList(com.intellij.ui.components.JBList) List(java.util.List) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 9 with PropertiesComponent

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;
}
Also used : java.util(java.util) AllIcons(com.intellij.icons.AllIcons) ShowSettingsUtil(com.intellij.openapi.options.ShowSettingsUtil) ArrayUtil(com.intellij.util.ArrayUtil) URL(java.net.URL) com.intellij.ide.fileTemplates(com.intellij.ide.fileTemplates) ContainerUtil(com.intellij.util.containers.ContainerUtil) MessageFormat(java.text.MessageFormat) Comparing(com.intellij.openapi.util.Comparing) JBUI(com.intellij.util.ui.JBUI) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) ChangeListener(javax.swing.event.ChangeListener) Logger(com.intellij.openapi.diagnostic.Logger) Splitter(com.intellij.openapi.ui.Splitter) PlatformIcons(com.intellij.util.PlatformIcons) ChangeEvent(javax.swing.event.ChangeEvent) Extensions(com.intellij.openapi.extensions.Extensions) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) Configurable(com.intellij.openapi.options.Configurable) Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) IdeBundle(com.intellij.ide.IdeBundle) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) ScrollPaneFactory(com.intellij.ui.ScrollPaneFactory) javax.swing(javax.swing) ChangeListener(javax.swing.event.ChangeListener) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) Splitter(com.intellij.openapi.ui.Splitter) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) ChangeEvent(javax.swing.event.ChangeEvent)

Example 10 with PropertiesComponent

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);
        }
    }
}
Also used : THashMap(gnu.trove.THashMap) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Aggregations

PropertiesComponent (com.intellij.ide.util.PropertiesComponent)53 File (java.io.File)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Project (com.intellij.openapi.project.Project)5 IOException (java.io.IOException)5 NotNull (org.jetbrains.annotations.NotNull)5 ArrayList (java.util.ArrayList)4 SdkPaths.validateAndroidSdk (com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk)2 CommitStepException (com.intellij.ide.wizard.CommitStepException)2 Notification (com.intellij.notification.Notification)2 NotificationListener (com.intellij.notification.NotificationListener)2 TIntArrayList (gnu.trove.TIntArrayList)2 List (java.util.List)2 JDOMException (org.jdom.JDOMException)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 Nullable (org.jetbrains.annotations.Nullable)2 Variant (com.android.builder.model.Variant)1 IDevice (com.android.ddmlib.IDevice)1 GradleVersion (com.android.ide.common.repository.GradleVersion)1 IdDisplay (com.android.sdklib.repository.IdDisplay)1