/** * @return default LookAndFeelInfo for the running OS. For Win32 and Linux the method returns * Alloy LAF or IDEA LAF if first not found, for Mac OS X it returns Aqua RubyMine uses Native * L&F for linux as well */ private UIManager.LookAndFeelInfo getDefaultLaf() { final String systemLafClassName = UIManager.getSystemLookAndFeelClassName(); if (SystemInfo.isMac) { UIManager.LookAndFeelInfo laf = findLaf(systemLafClassName); LOG.assertTrue(laf != null); return laf; } if (PlatformUtils.isRubyMine() || PlatformUtils.isPyCharm()) { final String desktop = AccessController.doPrivileged(new GetPropertyAction("sun.desktop")); if ("gnome".equals(desktop)) { UIManager.LookAndFeelInfo laf = findLaf(systemLafClassName); if (laf != null) { return laf; } LOG.info("Could not find system look and feel: " + laf); } } // Default final String defaultLafName = StartupUtil.getDefaultLAF(); if (defaultLafName != null) { UIManager.LookAndFeelInfo defaultLaf = findLaf(defaultLafName); if (defaultLaf != null) { return defaultLaf; } } UIManager.LookAndFeelInfo ideaLaf = findLaf( isIntelliJLafEnabled() ? IntelliJLaf.class.getName() : IdeaLookAndFeelInfo.CLASS_NAME); if (ideaLaf != null) { return ideaLaf; } throw new IllegalStateException("No default look&feel found"); }
private static String getProductPrefix() { String prefix = null; if (PlatformUtils.isIdeaCommunity()) { prefix = "IC"; } else if (PlatformUtils.isIdeaUltimate()) { prefix = "IU"; } return prefix; }
@NotNull @Override protected Configurable createModuleConfigurable(Module module) { if (PlatformUtils.isPyCharmCommunity()) return new PlatformContentEntriesConfigurable(module, JavaSourceRootType.SOURCE); return new PyContentEntriesModuleConfigurable(module); }
public void initComponent() { log.info("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)"); // System.out.println("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)"); // Set runtime constants IDE_NAME = PlatformUtils.getPlatformPrefix(); IDE_VERSION = ApplicationInfo.getInstance().getFullVersion(); if (!Dependencies.isCLIInstalled()) { log.info("Downloading and installing wakatime-cli ..."); Dependencies.installCLI(); } else if (Dependencies.isCLIOld()) { log.info("Upgrading wakatime-cli ..."); Dependencies.upgradeCLI(); } if (Dependencies.isPythonInstalled()) { WakaTime.DEBUG = WakaTime.isDebugEnabled(); if (WakaTime.DEBUG) { log.setLevel(Level.DEBUG); log.debug("Logging level set to DEBUG"); } log.debug("Python location: " + Dependencies.getPythonLocation()); log.debug("CLI location: " + Dependencies.getCLILocation()); // prompt for apiKey if it does not already exist if (ApiKey.getApiKey().equals("")) { Project project = ProjectManager.getInstance().getDefaultProject(); ApiKey apiKey = new ApiKey(project); apiKey.promptForApiKey(); } log.debug("Api Key: " + ApiKey.getApiKey()); // add WakaTime item to File menu ActionManager am = ActionManager.getInstance(); PluginMenu action = new PluginMenu(); am.registerAction("WakaTimeApiKey", action); DefaultActionGroup fileMenu = (DefaultActionGroup) am.getAction("FileMenu"); fileMenu.addSeparator(); fileMenu.add(action); // Setup message listeners MessageBus bus = ApplicationManager.getApplication().getMessageBus(); connection = bus.connect(); connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new CustomSaveListener()); EditorFactory.getInstance() .getEventMulticaster() .addDocumentListener(new CustomDocumentListener()); log.debug("Finished initializing WakaTime plugin"); } else { Messages.showErrorDialog( "WakaTime requires Python to be installed.\nYou can install it from https://www.python.org/downloads/\nAfter installing Python, restart your IDE.", "Error"); } }
@Override public void update(AnActionEvent event) { final Presentation presentation = event.getPresentation(); final Project project = event.getData(CommonDataKeys.PROJECT); presentation.setEnabled(project != null); presentation.setVisible( ActionPlaces.isMainMenuOrActionSearch(event.getPlace()) && !PlatformUtils.isCidr()); }
private void tweakPlatformDefaults() { // TODO: Make it pluggable if (PlatformUtils.isCidr()) { SHOW_MAIN_TOOLBAR = false; SHOW_ICONS_IN_MENUS = false; SHOW_MEMORY_INDICATOR = false; } }
public FindSettingsImpl() { RECENT_FILE_MASKS.add("*.properties"); RECENT_FILE_MASKS.add("*.html"); RECENT_FILE_MASKS.add("*.jsp"); RECENT_FILE_MASKS.add("*.xml"); RECENT_FILE_MASKS.add("*.java"); RECENT_FILE_MASKS.add("*.js"); RECENT_FILE_MASKS.add("*.as"); RECENT_FILE_MASKS.add("*.css"); RECENT_FILE_MASKS.add("*.mxml"); if (PlatformUtils.isPyCharm()) { RECENT_FILE_MASKS.add("*.py"); } else if (PlatformUtils.isRubyMine()) { RECENT_FILE_MASKS.add("*.rb"); } else if (PlatformUtils.isPhpStorm()) { RECENT_FILE_MASKS.add("*.php"); } }
@NotNull private static ConfigImportSettings getConfigImportSettings() { try { @SuppressWarnings("unchecked") Class<ConfigImportSettings> customProviderClass = (Class<ConfigImportSettings>) Class.forName( "com.intellij.openapi.application." + PlatformUtils.getPlatformPrefix() + "ConfigImportSettings"); if (ConfigImportSettings.class.isAssignableFrom(customProviderClass)) { return ReflectionUtil.newInstance(customProviderClass); } } catch (ClassNotFoundException ignored) { } catch (RuntimeException ignored) { } return new ConfigImportSettings(); }
protected void setupEnvironment(@NotNull Map<String, String> environment) { environment.clear(); if (myPassParentEnvironment) { environment.putAll( PlatformUtils.isAppCode() ? System.getenv() // Temporarily fix for OC-8606 : EnvironmentUtil.getEnvironmentMap()); } if (!myEnvParams.isEmpty()) { if (SystemInfo.isWindows) { THashMap<String, String> envVars = new THashMap<String, String>(CaseInsensitiveStringHashingStrategy.INSTANCE); envVars.putAll(environment); envVars.putAll(myEnvParams); environment.clear(); environment.putAll(envVars); } else { environment.putAll(myEnvParams); } } }
private static void addLibrariesFromModule(Module module, Collection<String> list) { final OrderEntry[] entries = ModuleRootManager.getInstance(module).getOrderEntries(); for (OrderEntry entry : entries) { if (entry instanceof LibraryOrderEntry) { final String name = ((LibraryOrderEntry) entry).getLibraryName(); if (name != null && name.endsWith(LibraryContributingFacet.PYTHON_FACET_LIBRARY_NAME_SUFFIX)) { // skip libraries from Python facet continue; } for (VirtualFile root : ((LibraryOrderEntry) entry).getRootFiles(OrderRootType.CLASSES)) { final Library library = ((LibraryOrderEntry) entry).getLibrary(); if (!PlatformUtils.isPyCharm()) { addToPythonPath(root, list); } else if (library instanceof LibraryImpl) { final PersistentLibraryKind<?> kind = ((LibraryImpl) library).getKind(); if (kind == PythonLibraryType.getInstance().getKind()) { addToPythonPath(root, list); } } } } } }
@NotNull @Override public List<SearchScope> getPredefinedScopes( @NotNull final Project project, @Nullable final DataContext dataContext, boolean suggestSearchInLibs, boolean prevSearchFiles, boolean currentSelection, boolean usageView, boolean showEmptyScopes) { Collection<SearchScope> result = ContainerUtil.newLinkedHashSet(); result.add(GlobalSearchScope.projectScope(project)); if (suggestSearchInLibs) { result.add(GlobalSearchScope.allScope(project)); } if (ModuleUtil.isSupportedRootType(project, JavaSourceRootType.TEST_SOURCE)) { result.add(GlobalSearchScopesCore.projectProductionScope(project)); result.add(GlobalSearchScopesCore.projectTestScope(project)); } final GlobalSearchScope openFilesScope = GlobalSearchScopes.openFilesScope(project); if (openFilesScope != GlobalSearchScope.EMPTY_SCOPE) { result.add(openFilesScope); } else if (showEmptyScopes) { result.add( new LocalSearchScope(PsiElement.EMPTY_ARRAY, IdeBundle.message("scope.open.files"))); } final Editor selectedTextEditor = ApplicationManager.getApplication().isDispatchThread() ? FileEditorManager.getInstance(project).getSelectedTextEditor() : null; final PsiFile psiFile = (selectedTextEditor != null) ? PsiDocumentManager.getInstance(project).getPsiFile(selectedTextEditor.getDocument()) : null; PsiFile currentFile = psiFile; if (dataContext != null) { PsiElement dataContextElement = CommonDataKeys.PSI_FILE.getData(dataContext); if (dataContextElement == null) { dataContextElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext); } if (dataContextElement == null && psiFile != null) { dataContextElement = psiFile; } if (dataContextElement != null) { if (!PlatformUtils.isCidr()) { // TODO: have an API to disable module scopes. Module module = ModuleUtilCore.findModuleForPsiElement(dataContextElement); if (module == null) { module = LangDataKeys.MODULE.getData(dataContext); } if (module != null && !(ModuleType.get(module) instanceof InternalModuleType)) { result.add(module.getModuleScope()); } } if (currentFile == null) { currentFile = dataContextElement.getContainingFile(); } } } if (currentFile != null || showEmptyScopes) { PsiElement[] scope = currentFile != null ? new PsiElement[] {currentFile} : PsiElement.EMPTY_ARRAY; result.add(new LocalSearchScope(scope, IdeBundle.message("scope.current.file"))); } if (currentSelection && selectedTextEditor != null && psiFile != null) { SelectionModel selectionModel = selectedTextEditor.getSelectionModel(); if (selectionModel.hasSelection()) { int start = selectionModel.getSelectionStart(); final PsiElement startElement = psiFile.findElementAt(start); if (startElement != null) { int end = selectionModel.getSelectionEnd(); final PsiElement endElement = psiFile.findElementAt(end); if (endElement != null) { final PsiElement parent = PsiTreeUtil.findCommonParent(startElement, endElement); if (parent != null) { final List<PsiElement> elements = new ArrayList<PsiElement>(); final PsiElement[] children = parent.getChildren(); TextRange selection = new TextRange(start, end); for (PsiElement child : children) { if (!(child instanceof PsiWhiteSpace) && child.getContainingFile() != null && selection.contains(child.getTextOffset())) { elements.add(child); } } if (!elements.isEmpty()) { SearchScope local = new LocalSearchScope( PsiUtilCore.toPsiElementArray(elements), IdeBundle.message("scope.selection")); result.add(local); } } } } } } if (usageView) { addHierarchyScope(project, result); UsageView selectedUsageView = UsageViewManager.getInstance(project).getSelectedUsageView(); if (selectedUsageView != null && !selectedUsageView.isSearchInProgress()) { final Set<Usage> usages = ContainerUtil.newTroveSet(selectedUsageView.getUsages()); usages.removeAll(selectedUsageView.getExcludedUsages()); final List<PsiElement> results = new ArrayList<PsiElement>(usages.size()); if (prevSearchFiles) { final Set<VirtualFile> files = collectFiles(usages, true); if (!files.isEmpty()) { GlobalSearchScope prev = new GlobalSearchScope(project) { private Set<VirtualFile> myFiles = null; @NotNull @Override public String getDisplayName() { return IdeBundle.message("scope.files.in.previous.search.result"); } @Override public synchronized boolean contains(@NotNull VirtualFile file) { if (myFiles == null) { myFiles = collectFiles(usages, false); } return myFiles.contains(file); } @Override public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) { return 0; } @Override public boolean isSearchInModuleContent(@NotNull Module aModule) { return true; } @Override public boolean isSearchInLibraries() { return true; } }; result.add(prev); } } else { for (Usage usage : usages) { if (usage instanceof PsiElementUsage) { final PsiElement element = ((PsiElementUsage) usage).getElement(); if (element != null && element.isValid() && element.getContainingFile() != null) { results.add(element); } } } if (!results.isEmpty()) { result.add( new LocalSearchScope( PsiUtilCore.toPsiElementArray(results), IdeBundle.message("scope.previous.search.results"))); } } } } final FavoritesManager favoritesManager = FavoritesManager.getInstance(project); if (favoritesManager != null) { for (final String favorite : favoritesManager.getAvailableFavoritesListNames()) { final Collection<TreeItem<Pair<AbstractUrl, String>>> rootUrls = favoritesManager.getFavoritesListRootUrls(favorite); if (rootUrls.isEmpty()) continue; // ignore unused root result.add( new GlobalSearchScope(project) { @NotNull @Override public String getDisplayName() { return "Favorite \'" + favorite + "\'"; } @Override public boolean contains(@NotNull final VirtualFile file) { return ApplicationManager.getApplication() .runReadAction( (Computable<Boolean>) () -> favoritesManager.contains(favorite, file)); } @Override public int compare( @NotNull final VirtualFile file1, @NotNull final VirtualFile file2) { return 0; } @Override public boolean isSearchInModuleContent(@NotNull final Module aModule) { return true; } @Override public boolean isSearchInLibraries() { return true; } }); } } ContainerUtil.addIfNotNull(result, getSelectedFilesScope(project, dataContext)); return ContainerUtil.newArrayList(result); }
private List<TemplatesGroup> fillTemplatesMap(WizardContext context) { List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders(); if (context.isCreatingNewProject()) { builders.add(new EmptyModuleBuilder()); } Map<String, TemplatesGroup> groupMap = new HashMap<String, TemplatesGroup>(); for (ModuleBuilder builder : builders) { BuilderBasedTemplate template = new BuilderBasedTemplate(builder); if (builder.isTemplate()) { TemplatesGroup group = groupMap.get(builder.getGroupName()); if (group == null) { group = new TemplatesGroup(builder); } myTemplatesMap.putValue(group, template); } else { TemplatesGroup group = new TemplatesGroup(builder); groupMap.put(group.getName(), group); myTemplatesMap.put(group, new ArrayList<ProjectTemplate>()); } } MultiMap<TemplatesGroup, ProjectTemplate> map = CreateFromTemplateMode.getTemplatesMap(context); myTemplatesMap.putAllValues(map); for (ProjectCategory category : ProjectCategory.EXTENSION_POINT_NAME.getExtensions()) { TemplatesGroup group = new TemplatesGroup(category); myTemplatesMap.remove(group); myTemplatesMap.put(group, new ArrayList<ProjectTemplate>()); } if (context.isCreatingNewProject()) { MultiMap<String, ProjectTemplate> localTemplates = loadLocalTemplates(); for (TemplatesGroup group : myTemplatesMap.keySet()) { myTemplatesMap.putValues(group, localTemplates.get(group.getId())); } } // remove Static Web group in IDEA Community if no specific templates found (IDEA-120593) if (PlatformUtils.isIdeaCommunity()) { for (TemplatesGroup group : myTemplatesMap.keySet()) { if (WebModuleTypeBase.WEB_MODULE.equals(group.getId()) && myTemplatesMap.get(group).isEmpty()) { myTemplatesMap.remove(group); break; } } } List<TemplatesGroup> groups = new ArrayList<TemplatesGroup>(myTemplatesMap.keySet()); // sorting by module type popularity final MultiMap<ModuleType, TemplatesGroup> moduleTypes = new MultiMap<ModuleType, TemplatesGroup>(); for (TemplatesGroup group : groups) { ModuleType type = getModuleType(group); moduleTypes.putValue(type, group); } Collections.sort( groups, new Comparator<TemplatesGroup>() { @Override public int compare(TemplatesGroup o1, TemplatesGroup o2) { int i = o2.getWeight() - o1.getWeight(); if (i != 0) return i; int i1 = moduleTypes.get(getModuleType(o2)).size() - moduleTypes.get(getModuleType(o1)).size(); if (i1 != 0) return i1; return o1.compareTo(o2); } }); Set<String> groupNames = ContainerUtil.map2Set( groups, new Function<TemplatesGroup, String>() { @Override public String fun(TemplatesGroup group) { return group.getParentGroup(); } }); // move subgroups MultiMap<String, TemplatesGroup> subGroups = new MultiMap<String, TemplatesGroup>(); for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) { TemplatesGroup group = iterator.next(); String parentGroup = group.getParentGroup(); if (parentGroup != null && groupNames.contains(parentGroup) && !group.getName().equals(parentGroup) && groupMap.containsKey(parentGroup)) { subGroups.putValue(parentGroup, group); iterator.remove(); } } for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) { TemplatesGroup group = iterator.next(); for (TemplatesGroup subGroup : subGroups.get(group.getName())) { iterator.add(subGroup); } } return groups; }
public static List<SearchScope> getPredefinedScopes( @NotNull final Project project, @Nullable final DataContext dataContext, boolean suggestSearchInLibs, boolean prevSearchFiles, boolean currentSelection, boolean usageView) { ArrayList<SearchScope> result = new ArrayList<SearchScope>(); result.add(GlobalSearchScope.projectScope(project)); if (suggestSearchInLibs) { result.add(GlobalSearchScope.allScope(project)); } if (!PlatformUtils.isCidr() && ModuleUtil.isSupportedRootType( project, JavaSourceRootType.TEST_SOURCE)) { // TODO: fix these scopes in AppCode result.add(GlobalSearchScopes.projectProductionScope(project)); result.add(GlobalSearchScopes.projectTestScope(project)); } result.add(GlobalSearchScopes.openFilesScope(project)); if (dataContext != null) { PsiElement dataContextElement = CommonDataKeys.PSI_FILE.getData(dataContext); if (dataContextElement == null) { dataContextElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext); } if (dataContextElement != null) { if (!PlatformUtils.isCidr()) { // TODO: have an API to disable module scopes. Module module = ModuleUtilCore.findModuleForPsiElement(dataContextElement); if (module == null) { module = LangDataKeys.MODULE.getData(dataContext); } if (module != null) { result.add(module.getModuleScope()); } } if (dataContextElement.getContainingFile() != null) { result.add( new LocalSearchScope(dataContextElement, IdeBundle.message("scope.current.file"))); } } } if (currentSelection) { FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); final Editor selectedTextEditor = fileEditorManager.getSelectedTextEditor(); if (selectedTextEditor != null) { final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(selectedTextEditor.getDocument()); if (psiFile != null) { if (selectedTextEditor.getSelectionModel().hasSelection()) { final PsiElement startElement = psiFile.findElementAt(selectedTextEditor.getSelectionModel().getSelectionStart()); if (startElement != null) { final PsiElement endElement = psiFile.findElementAt(selectedTextEditor.getSelectionModel().getSelectionEnd()); if (endElement != null) { final PsiElement parent = PsiTreeUtil.findCommonParent(startElement, endElement); if (parent != null) { final List<PsiElement> elements = new ArrayList<PsiElement>(); final PsiElement[] children = parent.getChildren(); for (PsiElement child : children) { if (!(child instanceof PsiWhiteSpace) && child.getContainingFile() != null) { elements.add(child); } } if (!elements.isEmpty()) { SearchScope local = new LocalSearchScope( PsiUtilCore.toPsiElementArray(elements), IdeBundle.message("scope.selection")); result.add(local); } } } } } } } } if (usageView) { UsageView selectedUsageView = UsageViewManager.getInstance(project).getSelectedUsageView(); if (selectedUsageView != null && !selectedUsageView.isSearchInProgress()) { final Set<Usage> usages = selectedUsageView.getUsages(); final List<PsiElement> results = new ArrayList<PsiElement>(usages.size()); if (prevSearchFiles) { final Set<VirtualFile> files = new HashSet<VirtualFile>(); for (Usage usage : usages) { if (usage instanceof PsiElementUsage) { PsiElement psiElement = ((PsiElementUsage) usage).getElement(); if (psiElement != null && psiElement.isValid()) { PsiFile psiFile = psiElement.getContainingFile(); if (psiFile != null) { VirtualFile file = psiFile.getVirtualFile(); if (file != null) files.add(file); } } } } if (!files.isEmpty()) { GlobalSearchScope prev = new GlobalSearchScope(project) { @Override public String getDisplayName() { return IdeBundle.message("scope.files.in.previous.search.result"); } @Override public boolean contains(@NotNull VirtualFile file) { return files.contains(file); } @Override public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) { return 0; } @Override public boolean isSearchInModuleContent(@NotNull Module aModule) { return true; } @Override public boolean isSearchInLibraries() { return true; } }; result.add(prev); } } else { for (Usage usage : usages) { if (usage instanceof PsiElementUsage) { final PsiElement element = ((PsiElementUsage) usage).getElement(); if (element != null && element.isValid() && element.getContainingFile() != null) { results.add(element); } } } if (!results.isEmpty()) { result.add( new LocalSearchScope( PsiUtilCore.toPsiElementArray(results), IdeBundle.message("scope.previous.search.results"))); } } } } final FavoritesManager favoritesManager = FavoritesManager.getInstance(project); if (favoritesManager != null) { for (final String favorite : favoritesManager.getAvailableFavoritesListNames()) { final Collection<TreeItem<Pair<AbstractUrl, String>>> rootUrls = favoritesManager.getFavoritesListRootUrls(favorite); if (rootUrls.isEmpty()) continue; // ignore unused root result.add( new GlobalSearchScope(project) { @Override public String getDisplayName() { return "Favorite \'" + favorite + "\'"; } @Override public boolean contains(@NotNull final VirtualFile file) { return favoritesManager.contains(favorite, file); } @Override public int compare( @NotNull final VirtualFile file1, @NotNull final VirtualFile file2) { return 0; } @Override public boolean isSearchInModuleContent(@NotNull final Module aModule) { return true; } @Override public boolean isSearchInLibraries() { return true; } }); } } if (dataContext != null) { final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); if (files != null) { final List<VirtualFile> openFiles = Arrays.asList(files); result.add( new DelegatingGlobalSearchScope(GlobalSearchScope.filesScope(project, openFiles)) { @Override public String getDisplayName() { return "Selected Files"; } }); } } return result; }
@State( name = "UISettings", storages = {@Storage(file = "$APP_CONFIG$/ui.lnf.xml")}) public class UISettings implements PersistentStateComponent<UISettings>, ExportableApplicationComponent { private final EventListenerList myListenerList; @Property(filter = FontFilter.class) @NonNls public String FONT_FACE; @Property(filter = FontFilter.class) public int FONT_SIZE; public int RECENT_FILES_LIMIT = 15; public int CONSOLE_COMMAND_HISTORY_LIMIT = 20; public int EDITOR_TAB_LIMIT = 10; public boolean ANIMATE_WINDOWS = true; public int ANIMATION_SPEED = 2000; // Pixels per second public boolean SHOW_TOOL_WINDOW_NUMBERS = true; public boolean HIDE_TOOL_STRIPES = false; public boolean SHOW_MEMORY_INDICATOR = true; public boolean ALLOW_MERGE_BUTTONS = true; public boolean SHOW_MAIN_TOOLBAR = true; public boolean SHOW_STATUS_BAR = true; public boolean SHOW_NAVIGATION_BAR = true; public boolean ALWAYS_SHOW_WINDOW_BUTTONS = false; public boolean CYCLE_SCROLLING = true; public boolean SCROLL_TAB_LAYOUT_IN_EDITOR = PlatformUtils.isCidr(); public boolean SHOW_CLOSE_BUTTON = true; public int EDITOR_TAB_PLACEMENT = 1; public boolean HIDE_KNOWN_EXTENSION_IN_TABS = false; public boolean SHOW_ICONS_IN_QUICK_NAVIGATION = true; public boolean CLOSE_NON_MODIFIED_FILES_FIRST = false; public boolean ACTIVATE_MRU_EDITOR_ON_CLOSE = false; public boolean ACTIVATE_RIGHT_EDITOR_ON_CLOSE = PlatformUtils.isCidr(); public boolean ANTIALIASING_IN_EDITOR = true; public boolean MOVE_MOUSE_ON_DEFAULT_BUTTON = false; public boolean ENABLE_ALPHA_MODE = false; public int ALPHA_MODE_DELAY = 1500; public float ALPHA_MODE_RATIO = 0.5f; public int MAX_CLIPBOARD_CONTENTS = 5; public boolean OVERRIDE_NONIDEA_LAF_FONTS = false; public boolean SHOW_ICONS_IN_MENUS = true; public boolean DISABLE_MNEMONICS = SystemInfo.isMac; // IDEADEV-33409, should be disabled by default on MacOS public boolean DISABLE_MNEMONICS_IN_CONTROLS = false; public boolean SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = false; public int MAX_LOOKUP_WIDTH2 = 500; public int MAX_LOOKUP_LIST_HEIGHT = 11; public boolean HIDE_NAVIGATION_ON_FOCUS_LOSS = true; public boolean FILE_COLORS_IN_PROJECT_VIEW = false; /** Defines whether asterisk is shown on modified editor tab or not */ public boolean MARK_MODIFIED_TABS_WITH_ASTERISK = false; public boolean SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES = false; /** Not tabbed pane */ public static final int TABS_NONE = 0; public UISettings() { myListenerList = new EventListenerList(); tweakPlatformDefaults(); setSystemFontFaceAndSize(); } private void tweakPlatformDefaults() { // TODO: Make it pluggable if (PlatformUtils.isCidr()) { SHOW_MAIN_TOOLBAR = false; SHOW_ICONS_IN_MENUS = false; SHOW_MEMORY_INDICATOR = false; } } /** * @deprecated use {@link UISettings#addUISettingsListener(com.intellij.ide.ui.UISettingsListener, * Disposable disposable)} instead. */ public void addUISettingsListener(UISettingsListener listener) { myListenerList.add(UISettingsListener.class, listener); } public void addUISettingsListener( @NotNull final UISettingsListener listener, @NotNull Disposable parentDisposable) { myListenerList.add(UISettingsListener.class, listener); Disposer.register( parentDisposable, new Disposable() { @Override public void dispose() { removeUISettingsListener(listener); } }); } /** Notifies all registered listeners that UI settings has been changed. */ public void fireUISettingsChanged() { UISettingsListener[] listeners = myListenerList.getListeners(UISettingsListener.class); for (UISettingsListener listener : listeners) { listener.uiSettingsChanged(this); } } public static UISettings getInstance() { return ApplicationManager.getApplication().getComponent(UISettings.class); } /** * Use this method if you are not sure is application initialized or not * * @return UISettings instance or default values */ public static UISettings getShadowInstance() { Application application = ApplicationManager.getApplication(); return application != null ? getInstance() : new UISettings(); } public void removeUISettingsListener(UISettingsListener listener) { myListenerList.remove(UISettingsListener.class, listener); } private static boolean isValidFont(final Font font) { try { return font.canDisplay('a') && font.canDisplay('z') && font.canDisplay('A') && font.canDisplay('Z') && font.canDisplay('0') && font.canDisplay('1'); } catch (Exception e) { // JRE has problems working with the font. Just skip. return false; } } private void setSystemFontFaceAndSize() { if (FONT_FACE == null || FONT_SIZE <= 0) { final Pair<String, Integer> fontData = getSystemFontFaceAndSize(); FONT_FACE = fontData.first; FONT_SIZE = fontData.second; } } private static Pair<String, Integer> getSystemFontFaceAndSize() { final Pair<String, Integer> fontData = UIUtil.getSystemFontData(); if (fontData != null) { return fontData; } if (SystemInfo.isWindows) { //noinspection HardCodedStringLiteral final Font font = (Font) Toolkit.getDefaultToolkit().getDesktopProperty("win.messagebox.font"); if (font != null) { return Pair.create(font.getName(), font.getSize()); } } return Pair.create("Dialog", 12); } public static class FontFilter implements SerializationFilter { public boolean accepts(Accessor accessor, Object bean) { UISettings settings = (UISettings) bean; return !hasDefaultFontSetting(settings); } } private static boolean hasDefaultFontSetting(final UISettings settings) { final Pair<String, Integer> fontData = getSystemFontFaceAndSize(); return fontData.first.equals(settings.FONT_FACE) && fontData.second.equals(settings.FONT_SIZE); } public UISettings getState() { return this; } public void loadState(UISettings object) { XmlSerializerUtil.copyBean(object, this); // Check tab placement in editor if (EDITOR_TAB_PLACEMENT != TABS_NONE && EDITOR_TAB_PLACEMENT != SwingConstants.TOP && EDITOR_TAB_PLACEMENT != SwingConstants.LEFT && EDITOR_TAB_PLACEMENT != SwingConstants.BOTTOM && EDITOR_TAB_PLACEMENT != SwingConstants.RIGHT) { EDITOR_TAB_PLACEMENT = SwingConstants.TOP; } // Check that alpha delay and ratio are valid if (ALPHA_MODE_DELAY < 0) { ALPHA_MODE_DELAY = 1500; } if (ALPHA_MODE_RATIO < 0.0f || ALPHA_MODE_RATIO > 1.0f) { ALPHA_MODE_RATIO = 0.5f; } setSystemFontFaceAndSize(); // 1. Sometimes system font cannot display standard ASCII symbols. If so we have // find any other suitable font withing "preferred" fonts first. boolean fontIsValid = isValidFont(new Font(FONT_FACE, Font.PLAIN, FONT_SIZE)); if (!fontIsValid) { @NonNls final String[] preferredFonts = {"dialog", "Arial", "Tahoma"}; for (String preferredFont : preferredFonts) { if (isValidFont(new Font(preferredFont, Font.PLAIN, FONT_SIZE))) { FONT_FACE = preferredFont; fontIsValid = true; break; } } // 2. If all preferred fonts are not valid in current environment // we have to find first valid font (if any) if (!fontIsValid) { Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); for (Font font : fonts) { if (isValidFont(font)) { FONT_FACE = font.getName(); break; } } } } if (MAX_CLIPBOARD_CONTENTS <= 0) { MAX_CLIPBOARD_CONTENTS = 5; } fireUISettingsChanged(); } private static final boolean DEFAULT_ALIASING = SystemProperties.getBooleanProperty("idea.use.default.antialiasing.in.editor", false); public static void setupAntialiasing(final Graphics g) { if (DEFAULT_ALIASING) return; Graphics2D g2d = (Graphics2D) g; UISettings uiSettings = getInstance(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); if (uiSettings == null || uiSettings.ANTIALIASING_IN_EDITOR) { Toolkit tk = Toolkit.getDefaultToolkit(); //noinspection HardCodedStringLiteral Map map = (Map) tk.getDesktopProperty("awt.font.desktophints"); if (map != null) { if (isRemoteDesktopConnected()) { g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); } else { g2d.addRenderingHints(map); } } else { g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } } else { g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } } /** @return true when Remote Desktop (i.e. Windows RDP) is connected */ // TODO[neuro]: move to UIUtil public static boolean isRemoteDesktopConnected() { if (System.getProperty("os.name").contains("Windows")) { final Map map = (Map) Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints"); return map != null && RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT.equals( map.get(RenderingHints.KEY_TEXT_ANTIALIASING)); } return false; } @NotNull public File[] getExportFiles() { return new File[] {PathManager.getOptionsFile("ui.lnf")}; } @NotNull public String getPresentableName() { return IdeBundle.message("ui.settings"); } @NonNls @NotNull public String getComponentName() { return "UISettings"; } public void initComponent() {} public void disposeComponent() {} }
public static boolean isAvailable() { return Registry.is("ide.new.welcome.screen.force") || (PlatformUtils.isJetBrainsProduct() && !PlatformUtils.isDatabaseIDE()); }