From 5be04a3535b98969ec1d7e1c39bc2efcdd4376e3 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 13 Oct 2011 13:30:42 +0200 Subject: [PATCH] tweaking recent projects display on welcome screen (IDEA-75483) --- .../ide/RecentProjectsManagerBase.java | 26 --------- .../com/intellij/ide/ReopenProjectAction.java | 57 +++++++++++++++++++ .../wm/impl/welcomeScreen/WelcomeScreen.java | 23 ++++++-- .../util/src/com/intellij/util/ui/UIUtil.java | 16 ++++-- 4 files changed, 85 insertions(+), 37 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/ide/ReopenProjectAction.java diff --git a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java index fd9ddd2e4210..927e69617265 100644 --- a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java +++ b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java @@ -18,7 +18,6 @@ package com.intellij.ide; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectManagerAdapter; @@ -32,7 +31,6 @@ import com.intellij.util.messages.MessageBus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.awt.event.InputEvent; import java.io.*; import java.util.*; @@ -271,30 +269,6 @@ public abstract class RecentProjectsManagerBase implements PersistentStateCompon return null; } - private class ReopenProjectAction extends AnAction implements DumbAware { - private final String myProjectPath; - - public ReopenProjectAction(final String projectPath, final String projectName) { - myProjectPath = projectPath; - - String _text = projectPath; - if (projectName != null) { - _text = String.format("%s", projectName); - } - - final Presentation presentation = getTemplatePresentation(); - presentation.setText(_text, false); - presentation.setDescription(projectPath); - } - - - public void actionPerformed(AnActionEvent e) { - final int modifiers = e.getModifiers(); - final boolean forceOpenInNewFrame = (modifiers & InputEvent.CTRL_MASK) != 0 || (modifiers & InputEvent.SHIFT_MASK) != 0; - doOpenProject(myProjectPath, PlatformDataKeys.PROJECT.getData(e.getDataContext()), forceOpenInNewFrame); - } - } - private class MyAppLifecycleListener extends AppLifecycleListener.Adapter { public void appFrameCreated(final String[] commandLineArgs, @NotNull final Ref willOpenProject) { if (GeneralSettings.getInstance().isReopenLastProject() && getLastProjectPath() != null) { diff --git a/platform/platform-impl/src/com/intellij/ide/ReopenProjectAction.java b/platform/platform-impl/src/com/intellij/ide/ReopenProjectAction.java new file mode 100644 index 000000000000..67525ff18801 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/ReopenProjectAction.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.Project; + +import java.awt.event.InputEvent; + +/** +* @author yole +*/ +public class ReopenProjectAction extends AnAction implements DumbAware { + private final String myProjectPath; + + public ReopenProjectAction(final String projectPath, final String projectName) { + myProjectPath = projectPath; + + String _text = projectPath; + if (projectName != null) { + _text = String.format("%s", projectName); + } + + final Presentation presentation = getTemplatePresentation(); + presentation.setText(_text, false); + presentation.setDescription(projectPath); + } + + + public void actionPerformed(AnActionEvent e) { + final int modifiers = e.getModifiers(); + final boolean forceOpenInNewFrame = (modifiers & InputEvent.CTRL_MASK) != 0 || (modifiers & InputEvent.SHIFT_MASK) != 0; + Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); + RecentProjectsManagerBase.getInstance().doOpenProject(myProjectPath, project, forceOpenInNewFrame); + } + + public String getProjectPath() { + return myProjectPath; + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeScreen.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeScreen.java index b5e7faf683dc..e137c79555bc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeScreen.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeScreen.java @@ -18,6 +18,7 @@ package com.intellij.openapi.wm.impl.welcomeScreen; import com.intellij.ide.BrowserUtil; import com.intellij.ide.DataManager; import com.intellij.ide.RecentProjectsManagerBase; +import com.intellij.ide.ReopenProjectAction; import com.intellij.ide.plugins.*; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; @@ -27,11 +28,10 @@ import com.intellij.openapi.application.ex.ApplicationInfoEx; import com.intellij.openapi.application.impl.PluginsFacade; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.impl.IdeRootPane; -import com.intellij.ui.LabeledIcon; -import com.intellij.ui.ScrollPaneFactory; -import com.intellij.ui.UIBundle; +import com.intellij.ui.*; import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; @@ -82,6 +82,10 @@ public class WelcomeScreen implements Disposable { private static final Color PLUGINS_PANEL_BACKGROUND = new Color(248, 248, 248); private static final Color PLUGINS_PANEL_BORDER = new Color(234, 234, 234); private static final Color CAPTION_COLOR = new Color(47, 67, 96); + public static final SimpleTextAttributes CAPTION_BOLD_UNDERLINE_ATTRIBUTES = + new SimpleTextAttributes(SimpleTextAttributes.STYLE_UNDERLINE | SimpleTextAttributes.STYLE_BOLD, CAPTION_COLOR); + public static final SimpleTextAttributes CAPTION_UNDERLINE_ATTRIBUTES = + new SimpleTextAttributes(SimpleTextAttributes.STYLE_UNDERLINE, CAPTION_COLOR); private static final Color DISABLED_CAPTION_COLOR = UIUtil.getInactiveTextColor(); private static final Color ACTION_BUTTON_COLOR = WELCOME_PANEL_BACKGROUND; private static final Color BUTTON_POPPED_COLOR = new Color(241, 241, 241); @@ -238,8 +242,17 @@ public class WelcomeScreen implements Disposable { int row = 1; for (final AnAction action : recentProjectsActions) { - JLabel actionLabel = new JLabel(underlineHtmlText(row + ". " + StringUtil.escapeXml(action.getTemplatePresentation().getText()))); - actionLabel.setFont(LINK_FONT); + SimpleColoredComponent actionLabel = new SimpleColoredComponent(); + actionLabel.append(String.valueOf(row), CAPTION_UNDERLINE_ATTRIBUTES); + actionLabel.append(". ", new SimpleTextAttributes(0, CAPTION_COLOR)); + actionLabel.append(action.getTemplatePresentation().getText(), CAPTION_BOLD_UNDERLINE_ATTRIBUTES); + + if (action instanceof ReopenProjectAction) { + String path = FileUtil.getLocationRelativeToUserHome(((ReopenProjectAction)action).getProjectPath()); + actionLabel.append(" " + path, new SimpleTextAttributes(SimpleTextAttributes.STYLE_SMALLER, Color.GRAY)); + } + + actionLabel.setFont(new Font(CAPTION_FONT_NAME, Font.PLAIN, 12)); actionLabel.setForeground(CAPTION_COLOR); actionLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); actionLabel.addMouseListener(new MouseAdapter() { diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index f54d8cdf68bc..e513d208502c 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -282,18 +282,22 @@ public class UIUtil { @NotNull public static Font getFont(@NotNull FontSize size, @Nullable Font base) { - Font defFont = getLabelFont(); - if (base == null) base = defFont; + if (base == null) base = getLabelFont(); + return base.deriveFont(getFontSize(size)); + } + + public static float getFontSize(FontSize size) { + int defSize = getLabelFont().getSize(); switch (size) { case TREE: - return base.deriveFont(Math.max(defFont.getSize() - 2f, 12f)); + return Math.max(defSize - 2f, 12f); case SMALL: - return base.deriveFont(Math.max(defFont.getSize() - 2f, 11f)); + return Math.max(defSize - 2f, 11f); case MINI: - return base.deriveFont(defFont.getSize() - 4f); + return defSize - 4f; default: - return base.deriveFont(defFont.getSize()); + return defSize; } }