private void onSaveAs() { if (mySchemesTableModel.isProjectScheme(getSelectedScheme())) { int rowToSelect = mySchemesTableModel.exportProjectScheme(); if (rowToSelect > 0) { mySchemesTable.getSelectionModel().setSelectionInterval(rowToSelect, rowToSelect); } } else { CodeStyleScheme[] schemes = CodeStyleSchemes.getInstance().getSchemes(); ArrayList<String> names = new ArrayList<String>(); for (CodeStyleScheme scheme : schemes) { names.add(scheme.getName()); } String selectedName = getSelectedScheme().getName(); SaveSchemeDialog saveDialog = new SaveSchemeDialog(myParent, ApplicationBundle.message("title.save.code.style.scheme.as"), names, selectedName); if (saveDialog.showAndGet()) { int row = mySchemesTableModel.createNewScheme(getSelectedScheme(), saveDialog.getSchemeName()); mySchemesTable.getSelectionModel().setSelectionInterval(row, row); } } }
private MySchemesTable() { myFixedItemsRenderer = new DefaultTableCellRenderer() { @NotNull @Override public Component getTableCellRendererComponent(@NotNull JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component defaultComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof CodeStyleScheme) { CodeStyleScheme scheme = (CodeStyleScheme)value; if (scheme.isDefault() || myModel.isProjectScheme(scheme)) { defaultComponent.setFont(defaultComponent.getFont().deriveFont(Font.BOLD)); } } return defaultComponent; } }; }
public int exportProjectScheme() { String name = Messages.showInputDialog("Enter new scheme name:", "Copy Project Scheme to Global List", Messages.getQuestionIcon()); if (name != null && !CodeStyleSchemesModel.PROJECT_SCHEME_NAME.equals(name)) { CodeStyleScheme newScheme = mySchemesModel.exportProjectScheme(name); updateSchemes(); int switchToGlobal = Messages .showYesNoDialog("Project scheme was copied to global scheme list as '" + newScheme.getName() + "'.\n" + "Switch to this created scheme?", "Copy Project Scheme to Global List", Messages.getQuestionIcon()); if (switchToGlobal == Messages.YES) { mySchemesModel.setUsePerProjectSettings(false); mySchemesModel.selectScheme(newScheme, null); } int row = 0; for (CodeStyleScheme scheme : mySchemes) { if (scheme == newScheme) { fireTableRowsInserted(row, row); return switchToGlobal == 0 ? row : -1; } row++; } } return -1; }
public void resetSchemesCombo() { myIsReset = true; try { List<CodeStyleScheme> schemes = new ArrayList<CodeStyleScheme>(); schemes.addAll(myModel.getAllSortedSchemes()); DefaultComboBoxModel model = new DefaultComboBoxModel(schemes.toArray()); myCombo.setModel(model); if (myModel.isUsePerProjectSettings()) { myCombo.setSelectedItem(myModel.getProjectScheme()); } else { myCombo.setSelectedItem(myModel.getSelectedGlobalScheme()); } } finally { myIsReset = false; } }
private NewCodeStyleSettingsPanel ensurePanel(final CodeStyleScheme scheme) { String name = scheme.getName(); if (!mySettingsPanels.containsKey(name)) { NewCodeStyleSettingsPanel panel = myFactory.createPanel(scheme); panel.reset(); panel.setModel(myModel); CodeStyleAbstractPanel settingsPanel = panel.getSelectedPanel(); if (settingsPanel instanceof TabbedLanguageCodeStylePanel) { TabbedLanguageCodeStylePanel tabbedPanel = (TabbedLanguageCodeStylePanel)settingsPanel; tabbedPanel.setListener(this); String currentTab = myProperties.getValue(getSelectedTabPropertyName(tabbedPanel)); if (currentTab != null) { tabbedPanel.changeTab(currentTab); } } mySettingsPanels.put(name, panel); mySettingsPanel.add(scheme.getName(), panel); } return mySettingsPanels.get(name); }
public void reset() { myUsePerProjectSettings = getProjectSettings().USE_PER_PROJECT_SETTINGS; CodeStyleScheme[] allSchemes = CodeStyleSchemes.getInstance().getSchemes(); mySettingsToClone.clear(); mySchemes.clear(); ContainerUtil.addAll(mySchemes, allSchemes); myGlobalSelected = CodeStyleSchemes.getInstance().findPreferredScheme(getProjectSettings().PREFERRED_PROJECT_CODE_STYLE); CodeStyleSettings perProjectSettings = getProjectSettings().PER_PROJECT_SETTINGS; if (perProjectSettings != null) { myProjectScheme.setCodeStyleSettings(perProjectSettings); } myDispatcher.getMulticaster().schemeListChanged(); myDispatcher.getMulticaster().currentSchemeChanged(this); }
public List<CodeStyleScheme> getAllSortedSchemes() { List<CodeStyleScheme> schemes = new ArrayList<CodeStyleScheme>(); schemes.addAll(getSchemes()); schemes.add(myProjectScheme); Collections.sort(schemes, new Comparator<CodeStyleScheme>() { @Override public int compare(CodeStyleScheme s1, CodeStyleScheme s2) { if (isProjectScheme(s1)) return -1; if (isProjectScheme(s2)) return 1; if (s1.isDefault()) return -1; if (s2.isDefault()) return 1; return s1.getName().compareToIgnoreCase(s2.getName()); } }); return schemes; }
private void init(@Nullable CodeStyleScheme parentScheme, Element root) { if (parentScheme == null) { myCodeStyleSettings = new CodeStyleSettings(); } else { CodeStyleSettings parentSettings = parentScheme.getCodeStyleSettings(); myCodeStyleSettings = parentSettings.clone(); while (parentSettings.getParentSettings() != null) { parentSettings = parentSettings.getParentSettings(); } myCodeStyleSettings.setParentSettings(parentSettings); } if (root != null) { try { readExternal(root); } catch (InvalidDataException e) { LOG.error(e); } } }
@Nullable @Override public Element getState() { CodeStyleScheme currentScheme = getCurrentScheme(); CURRENT_SCHEME_NAME = currentScheme == null ? null : currentScheme.getName(); return XmlSerializer.serialize(this, new SerializationFilter() { @Override public boolean accepts(@NotNull Accessor accessor, @NotNull Object bean) { if ("CURRENT_SCHEME_NAME".equals(accessor.getName())) { return !DEFAULT_SCHEME_NAME.equals(accessor.read(bean)); } else { return accessor.getValueClass().equals(String.class); } } }); }
@Override protected void fillActions(Project project, @NotNull DefaultActionGroup group, @NotNull DataContext dataContext) { final CodeStyleSettingsManager manager = CodeStyleSettingsManager.getInstance(project); if (manager.PER_PROJECT_SETTINGS != null) { //noinspection HardCodedStringLiteral group.add(new AnAction("<project>", "", manager.USE_PER_PROJECT_SETTINGS ? ourCurrentAction : ourNotCurrentAction) { @Override public void actionPerformed(@NotNull AnActionEvent e) { manager.USE_PER_PROJECT_SETTINGS = true; } }); } CodeStyleScheme currentScheme = CodeStyleSchemes.getInstance().getCurrentScheme(); for (CodeStyleScheme scheme : CodeStyleSchemes.getInstance().getSchemes()) { addScheme(group, manager, currentScheme, scheme, false); } }
public void importScheme(@NotNull InputStream inputStream, final @Nullable String sourceScheme, final CodeStyleScheme scheme) throws SchemeImportException { final CodeStyleSettings settings = scheme.getCodeStyleSettings(); EclipseXmlProfileReader reader = new EclipseXmlProfileReader(new EclipseXmlProfileReader.OptionHandler() { private String myCurrScheme; @Override public void handleOption(@NotNull String eclipseKey, @NotNull String value) throws SchemeImportException { if (sourceScheme == null || myCurrScheme != null && myCurrScheme.equals(sourceScheme)) { setCodeStyleOption(settings, eclipseKey, value); } } @Override public void handleName(String name) { myCurrScheme = name; } }); reader.readSettings(inputStream); }
@Nullable @Override public CodeStyleScheme importScheme(@NotNull Project project, @NotNull VirtualFile selectedFile, CodeStyleScheme currentScheme, SchemeFactory<CodeStyleScheme> schemeFactory) throws SchemeImportException { final String[] schemeNames = readSchemeNames(selectedFile); final ImportSchemeChooserDialog schemeChooserDialog = new ImportSchemeChooserDialog(project, schemeNames, !currentScheme.isDefault() ? currentScheme.getName() : null); if (! schemeChooserDialog.showAndGet()) return null; final CodeStyleScheme scheme = schemeChooserDialog.isUseCurrentScheme() && (! currentScheme.isDefault()) ? currentScheme : schemeFactory.createNewScheme(schemeChooserDialog.getTargetName()); if (scheme == null) return null; readFromStream(selectedFile, new ThrowableConsumer<InputStream, SchemeImportException>() { @Override public void consume(InputStream stream) throws SchemeImportException { new EclipseCodeStyleImportWorker().importScheme(stream, schemeChooserDialog.getSelectedName(), scheme); } }); return scheme; }
private MySchemesTable() { myFixedItemsRenderer = new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component defaultComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof CodeStyleScheme) { CodeStyleScheme scheme = (CodeStyleScheme)value; if (scheme.isDefault() || myModel.isProjectScheme(scheme)) { defaultComponent.setFont(defaultComponent.getFont().deriveFont(Font.BOLD)); } } return defaultComponent; } }; }
public int exportProjectScheme() { String name = Messages.showInputDialog("Enter new scheme name:", "Copy Project Scheme to Global List", Messages.getQuestionIcon()); if (name != null && !CodeStyleSchemesModel.PROJECT_SCHEME_NAME.equals(name)) { CodeStyleScheme newScheme = mySchemesModel.exportProjectScheme(name); updateSchemes(); int switchToGlobal = Messages .showYesNoDialog("Project scheme was copied to global scheme list as '" + newScheme.getName() + "'.\n" + "Switch to this created scheme?", "Copy Project Scheme to Global List", Messages.getQuestionIcon()); if (switchToGlobal == 0) { mySchemesModel.setUsePerProjectSettings(false); mySchemesModel.selectScheme(newScheme, null); } int row = 0; for (CodeStyleScheme scheme : mySchemes) { if (scheme == newScheme) { fireTableRowsInserted(row, row); return switchToGlobal == 0 ? row : -1; } row++; } } return -1; }
private void onSaveAs() { if (mySchemesTableModel.isProjectScheme(getSelectedScheme())) { int rowToSelect = mySchemesTableModel.exportProjectScheme(); if (rowToSelect > 0) { mySchemesTable.getSelectionModel().setSelectionInterval(rowToSelect, rowToSelect); } } else { CodeStyleScheme[] schemes = CodeStyleSchemes.getInstance().getSchemes(); ArrayList<String> names = new ArrayList<String>(); for (CodeStyleScheme scheme : schemes) { names.add(scheme.getName()); } SaveSchemeDialog saveDialog = new SaveSchemeDialog(myParent, ApplicationBundle.message("title.save.code.style.scheme.as"), names); saveDialog.show(); if (saveDialog.isOK()) { int row = mySchemesTableModel.createNewScheme(getSelectedScheme(), saveDialog.getSchemeName()); mySchemesTable.getSelectionModel().setSelectionInterval(row, row); } } }
private void init(CodeStyleScheme parentScheme, Element root) { CodeStyleSettings parentSettings = parentScheme == null ? null : parentScheme.getCodeStyleSettings(); if (parentSettings == null){ myCodeStyleSettings = new CodeStyleSettings(); } else{ myCodeStyleSettings = parentSettings.clone(); while(parentSettings.getParentSettings() != null){ parentSettings = parentSettings.getParentSettings(); } myCodeStyleSettings.setParentSettings(parentSettings); } if (root != null) { try { readExternal(root); } catch (InvalidDataException e) { LOG.error(e); } } }
@Override public void actionPerformed(AnActionEvent event) { final DataContext dataContext = event.getDataContext(); final Module module = LangDataKeys.MODULE.getData(dataContext); if (module != null) { ModuleCodeStyleComponent component = module.getComponent(ModuleCodeStyleComponent.class); if (component != null && component.getState() != null) { final String moduleCodeStyleScheme = component.getState().getCodeStyleSchemeName(); final CodeStyleSchemes schemes = PersistableCodeStyleSchemes.getInstance(); final CodeStyleScheme scheme = schemes.findSchemeByName(moduleCodeStyleScheme); if (scheme != null) schemes.setCurrentScheme(scheme); } } super.actionPerformed(event); }
private void loadAvailableCodeStyleSchemes() { final CodeStyleSchemes schemes = PersistableCodeStyleSchemes.getInstance(); if (schemes != null) { final List<String> schemesList = new ArrayList<String>(schemes.getSchemes().length); String selectedCodeStyleSchemeName = getModuleCodeStyleSchemeName(); boolean schemeExists = false; for (CodeStyleScheme scheme : schemes.getSchemes()) { schemesList.add(scheme.getName()); if (scheme.getName().equals(selectedCodeStyleSchemeName)) schemeExists = true; } if (!schemeExists) selectedCodeStyleSchemeName = ModuleCodeStyleState.defaultState().getCodeStyleSchemeName(); final ComboBoxModel model = new CollectionComboBoxModel(schemesList, selectedCodeStyleSchemeName); codeStyleSchemesComboBox.setModel(model); } else { mainPanel.setEnabled(false); } }
@Override protected Configurable[] buildConfigurables() { myPanels = new ArrayList<CodeStyleConfigurableWrapper>(); for (final CodeStyleSettingsProvider provider : CodeStyleSettingsProvider.EXTENSION_POINT_NAME.getExtensions()) { if (provider.hasSettingsPage()) { myPanels.add(new CodeStyleConfigurableWrapper(provider, new CodeStyleSettingsPanelFactory() { @Override public NewCodeStyleSettingsPanel createPanel(final CodeStyleScheme scheme) { return new NewCodeStyleSettingsPanel(provider.createSettingsPage(scheme.getCodeStyleSettings(), ensureModel().getCloneSettings(scheme))); } })); } } return myPanels.toArray(new Configurable[myPanels.size()]); }
private MySchemesTable() { myFixedItemsRenderer = new DefaultTableCellRenderer() { @Nonnull @Override public Component getTableCellRendererComponent(@Nonnull JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component defaultComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof CodeStyleScheme) { CodeStyleScheme scheme = (CodeStyleScheme)value; if (scheme.isDefault() || myModel.isProjectScheme(scheme)) { defaultComponent.setFont(defaultComponent.getFont().deriveFont(Font.BOLD)); } } return defaultComponent; } }; }
@Override protected void fillActions(Project project, @Nonnull DefaultActionGroup group, @Nonnull DataContext dataContext) { final CodeStyleSettingsManager manager = CodeStyleSettingsManager.getInstance(project); if (manager.PER_PROJECT_SETTINGS != null) { //noinspection HardCodedStringLiteral group.add(new AnAction("<project>", "", manager.USE_PER_PROJECT_SETTINGS ? ourCurrentAction : ourNotCurrentAction) { @Override public void actionPerformed(@Nonnull AnActionEvent e) { manager.USE_PER_PROJECT_SETTINGS = true; } }); } CodeStyleScheme currentScheme = CodeStyleSchemes.getInstance().getCurrentScheme(); for (CodeStyleScheme scheme : CodeStyleSchemes.getInstance().getSchemes()) { addScheme(group, manager, currentScheme, scheme, false); } }
private void disableWrapOnType(final Language impexLanguage) { final CodeStyleScheme currentScheme = CodeStyleSchemes.getInstance().getCurrentScheme(); final CodeStyleSettings codeStyleSettings = currentScheme.getCodeStyleSettings(); if (impexLanguage != null) { CommonCodeStyleSettings langSettings = codeStyleSettings.getCommonSettings(impexLanguage); if (langSettings != null) { langSettings.WRAP_ON_TYPING = CommonCodeStyleSettings.WrapOnTyping.NO_WRAP.intValue; } } }
@Override public void apply() throws ConfigurationException { if (!myApplyCompleted) { try { super.apply(); for (CodeStyleScheme scheme : new ArrayList<CodeStyleScheme>(myModel.getSchemes())) { final boolean isDefaultModified = CodeStyleSchemesModel.cannotBeModified(scheme) && isSchemeModified(scheme); if (isDefaultModified) { CodeStyleScheme newscheme = myModel.createNewScheme(null, scheme); CodeStyleSettings settingsWillBeModified = scheme.getCodeStyleSettings(); CodeStyleSettings notModifiedSettings = settingsWillBeModified.clone(); ((CodeStyleSchemeImpl)scheme).setCodeStyleSettings(notModifiedSettings); ((CodeStyleSchemeImpl)newscheme).setCodeStyleSettings(settingsWillBeModified); myModel.addScheme(newscheme, false); if (myModel.getSelectedScheme() == scheme) { myModel.selectScheme(newscheme, this); } } } for (CodeStyleConfigurableWrapper panel : myPanels) { panel.applyPanel(); } myModel.apply(); EditorFactory.getInstance().refreshAllEditors(); } finally { myApplyCompleted = true; } } }
private boolean isSchemeModified(final CodeStyleScheme scheme) { for (CodeStyleConfigurableWrapper panel : myPanels) { if (panel.isPanelModified(scheme)) { return true; } } return false; }
private CodeStyleSchemesModel ensureModel() { if (myModel == null) { myModel = new CodeStyleSchemesModel(myProject); myRootSchemesPanel = new CodeStyleSchemesPanel(myModel); myModel.addListener(new CodeStyleSettingsListener(){ @Override public void currentSchemeChanged(final Object source) { if (source != myRootSchemesPanel) { myRootSchemesPanel.onSelectedSchemeChanged(); } } @Override public void schemeListChanged() { myRootSchemesPanel.resetSchemesCombo(); } @Override public void currentSettingsChanged() { } @Override public void usePerProjectSettingsOptionChanged() { myRootSchemesPanel.usePerProjectSettingsOptionChanged(); } @Override public void schemeChanged(final CodeStyleScheme scheme) { //do nothing } }); } return myModel; }
private static String[] enumExporters() { List<String> names = new ArrayList<String>(); Collection<SchemeExporterEP<CodeStyleScheme>> extensions = SchemeExporterEP.getExtensions(CodeStyleScheme.class); for (SchemeExporterEP<CodeStyleScheme> extension : extensions) { names.add(extension.name); } return ArrayUtil.toStringArray(names); }
@Nullable private CodeStyleScheme importExternalCodeStyle(final SchemeImporter<CodeStyleScheme> importer) throws SchemeImportException { final VirtualFile selectedFile = selectImportSource(importer.getSourceExtensions()); if (selectedFile != null) { CodeStyleSchemesUIConfiguration.Util.setRecentImportFile(selectedFile); final SchemeCreator schemeCreator = new SchemeCreator(); final CodeStyleScheme schemeImported = importer.importScheme(myModel.getProject(), selectedFile, myModel.getSelectedScheme(), schemeCreator); if (schemeImported != null) { myModel.fireSchemeChanged(schemeImported); return schemeImported; } } return null; }
@Override public CodeStyleScheme createNewScheme(@Nullable String targetName) { if (targetName == null) targetName = ApplicationBundle.message("code.style.scheme.import.unnamed"); final int row = mySchemesTableModel.createNewScheme(getSelectedScheme(), targetName); mySchemesTable.getSelectionModel().setSelectionInterval(row, row); return mySchemesTableModel.getSchemeAt(row); }
public int createNewScheme(CodeStyleScheme selectedScheme, String schemeName) { CodeStyleScheme newScheme = mySchemesModel.createNewScheme(schemeName, selectedScheme); mySchemesModel.addScheme(newScheme, true); updateSchemes(); int row = 0; for (CodeStyleScheme scheme : mySchemes) { if (scheme == newScheme) { fireTableRowsInserted(row, row); break; } row ++; } return row; }
public int getDefaultRow() { int row = 0; for (CodeStyleScheme scheme : mySchemes) { if (scheme.isDefault()) return row; row ++; } return 0; }