From bfb3c865cc2b60e63f62f2483437d0e2562255b4 Mon Sep 17 00:00:00 2001 From: Alexey Merkulov Date: Wed, 7 Jul 2021 21:37:20 +0300 Subject: [PATCH] IFT-200 Add exit button-label It will be shown only in the learning project GitOrigin-RevId: 08c2c3525bf4f856d072b363da3346e1a1b6bfbf --- .../res/messages/LearnBundle.properties | 1 + .../src/training/ui/UISettings.kt | 5 +- .../src/training/ui/views/LearnPanel.kt | 58 +++++++++++++++---- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/plugins/ide-features-trainer/res/messages/LearnBundle.properties b/plugins/ide-features-trainer/res/messages/LearnBundle.properties index c38d67feff16..6714d1f725ed 100755 --- a/plugins/ide-features-trainer/res/messages/LearnBundle.properties +++ b/plugins/ide-features-trainer/res/messages/LearnBundle.properties @@ -98,3 +98,4 @@ completed.lessons.got.it=Finished lessons will be opened as completed. Press thi modules.panel.header=Learn IDE Features for {0} feedback.link.text=Leave feedback feedback.link.hint=Help us make learning the IDE better for everyone +exit.learning.link=Exit learning diff --git a/plugins/ide-features-trainer/src/training/ui/UISettings.kt b/plugins/ide-features-trainer/src/training/ui/UISettings.kt index b05cab94ffca..d1f871f46197 100644 --- a/plugins/ide-features-trainer/src/training/ui/UISettings.kt +++ b/plugins/ide-features-trainer/src/training/ui/UISettings.kt @@ -17,7 +17,7 @@ internal class UISettings { val width: Int by lazy { JBUI.scale(500) } //MAIN INSETS - val northInset: Int by lazy { JBUI.scale(24) } + val northInset: Int by lazy { JBUI.scale(20) } val westInset: Int by lazy { JBUI.scale(24) } val southInset: Int by lazy { JBUI.scale(24) } val eastInset: Int by lazy { JBUI.scale(24) } @@ -63,6 +63,9 @@ internal class UISettings { val emptyBorder: Border get() = EmptyBorder(northInset, westInset, southInset, eastInset) + val lessonHeaderBorder: Border + get() = EmptyBorder(0, JBUI.scale(14), 0, JBUI.scale(14)) + val checkmarkShiftBorder: Border get() = EmptyBorder(0, checkIndent, 0, 0) diff --git a/plugins/ide-features-trainer/src/training/ui/views/LearnPanel.kt b/plugins/ide-features-trainer/src/training/ui/views/LearnPanel.kt index d165686170b1..12bcd0d4758b 100644 --- a/plugins/ide-features-trainer/src/training/ui/views/LearnPanel.kt +++ b/plugins/ide-features-trainer/src/training/ui/views/LearnPanel.kt @@ -1,12 +1,15 @@ // Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package training.ui.views +import com.intellij.icons.AllIcons import com.intellij.ide.IdeBundle +import com.intellij.openapi.actionSystem.ActionManager import com.intellij.openapi.project.DumbService import com.intellij.openapi.util.NlsSafe import com.intellij.openapi.util.registry.Registry import com.intellij.ui.components.labels.LinkLabel import com.intellij.ui.components.labels.LinkListener +import com.intellij.ui.components.panels.VerticalBox import com.intellij.ui.components.panels.VerticalLayout import com.intellij.util.ui.JBUI import com.intellij.util.ui.UIUtil @@ -18,12 +21,11 @@ import training.learn.course.Lesson import training.learn.lesson.LessonManager import training.statistic.StatisticBase import training.ui.* -import training.util.getNextLessonForCurrent -import training.util.getPreviousLessonForCurrent -import training.util.openLinkInBrowser -import training.util.wrapWithUrlPanel +import training.util.* import java.awt.* import java.awt.event.ActionEvent +import java.awt.event.MouseAdapter +import java.awt.event.MouseEvent import javax.swing.* import javax.swing.border.EmptyBorder import javax.swing.border.MatteBorder @@ -121,10 +123,9 @@ internal class LearnPanel(val learnToolWindow: LearnToolWindow) : JPanel() { moduleNameLabel.name = "moduleNameLabel" moduleNameLabel.font = UISettings.instance.getFont(1) moduleNameLabel.isFocusable = false - moduleNameLabel.border = UISettings.instance.checkmarkShiftBorder lessonNameLabel.name = "lessonNameLabel" - lessonNameLabel.border = UISettings.instance.checkmarkShiftBorder + lessonNameLabel.border = UISettings.instance.lessonHeaderBorder lessonNameLabel.font = UISettings.instance.getFont(5).deriveFont(Font.BOLD) lessonNameLabel.alignmentX = Component.LEFT_ALIGNMENT lessonNameLabel.isFocusable = false @@ -134,7 +135,7 @@ internal class LearnPanel(val learnToolWindow: LearnToolWindow) : JPanel() { lessonMessagePane.isOpaque = false lessonMessagePane.alignmentX = Component.LEFT_ALIGNMENT lessonMessagePane.margin = JBUI.emptyInsets() - lessonMessagePane.border = EmptyBorder(0, 0, JBUI.scale(24), JBUI.scale(21)) + lessonMessagePane.border = EmptyBorder(0, 0, JBUI.scale(20), JBUI.scale(21)) lessonMessagePane.maximumSize = Dimension(UISettings.instance.width, 10000) //Set Next Button UI @@ -154,15 +155,43 @@ internal class LearnPanel(val learnToolWindow: LearnToolWindow) : JPanel() { buttonPanel.alignmentX = Component.LEFT_ALIGNMENT updateNavigationButtons() - //shift right for checkmark - lessonPanel.add(moduleNameLabel) - lessonPanel.add(Box.createVerticalStrut(JBUI.scale(20))) + lessonPanel.add(createHeaderPanel()) + lessonPanel.add(Box.createVerticalStrut(JBUI.scale(19))) lessonPanel.add(lessonNameLabel) lessonPanel.add(lessonMessagePane) lessonPanel.add(buttonPanel) lessonPanel.add(Box.createVerticalGlue()) } + private fun createHeaderPanel(): VerticalBox { + val linksPanel = JPanel() + linksPanel.layout = BoxLayout(linksPanel, BoxLayout.X_AXIS) + linksPanel.alignmentX = LEFT_ALIGNMENT + linksPanel.border = EmptyBorder(0, 0, JBUI.scale(12), 0) + + linksPanel.add(moduleNameLabel) + if (findLanguageSupport(learnToolWindow.project) != null) { + linksPanel.add(Box.createHorizontalGlue()) + + val exitLink = JLabel(LearnBundle.message("exit.learning.link"), AllIcons.Actions.Exit, SwingConstants.LEADING) + exitLink.cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) + exitLink.addMouseListener(object : MouseAdapter() { + override fun mouseClicked(e: MouseEvent) { + val action = ActionManager.getInstance().getAction("CloseProject") + invokeActionForFocusContext(action) + } + }) + linksPanel.add(exitLink) + } + + val headerPanel = VerticalBox() + headerPanel.alignmentX = LEFT_ALIGNMENT + headerPanel.border = UISettings.instance.lessonHeaderBorder + headerPanel.add(linksPanel) + headerPanel.add(createSmallSeparator()) + return headerPanel + } + fun setLessonName(@Nls lessonName: String) { lessonNameLabel.text = lessonName lessonNameLabel.foreground = UISettings.instance.defaultTextColor @@ -315,6 +344,15 @@ internal class LearnPanel(val learnToolWindow: LearnToolWindow) : JPanel() { lessonMessagePane.removeMessage(index) } + private fun createSmallSeparator(): Component { + // Actually standard JSeparator can be used, but it adds some extra size for Y and I don't know how to fix it :( + val separatorPanel = JPanel() + separatorPanel.layout = BoxLayout(separatorPanel, BoxLayout.X_AXIS) + separatorPanel.add(Box.createHorizontalGlue()) + separatorPanel.border = MatteBorder(0, 0, JBUI.scale(1), 0, UISettings.instance.separatorColor) + return separatorPanel + } + class LinkLabelWithBackArrow(linkListener: LinkListener) : LinkLabel("", null, linkListener) { init {