Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.openapi.wm.impl.content.ToolWindowContentUi
import com.intellij.ui.components.JBPanel
import com.intellij.ui.content.Content
import com.intellij.ui.content.ContentFactory
import com.intellij.ui.content.ContentManagerEvent
import com.intellij.ui.content.ContentManagerListener
import com.intellij.ui.content.*
import fi.aalto.cs.apluscourses.MyBundle.message
import fi.aalto.cs.apluscourses.actions.ActionGroups.EXERCISE_ACTIONS
import fi.aalto.cs.apluscourses.actions.ActionGroups.MODULE_ACTIONS
import fi.aalto.cs.apluscourses.actions.ActionGroups.TOOL_WINDOW_ACTIONS
import fi.aalto.cs.apluscourses.icons.CoursesIcons
import fi.aalto.cs.apluscourses.model.Course
import fi.aalto.cs.apluscourses.model.component.Module
import fi.aalto.cs.apluscourses.model.exercise.Exercise
Expand Down Expand Up @@ -55,7 +53,7 @@
val modulesView = createModulesView(project)
val exercisesView = createExercisesView(project)

val contentFactory = ContentFactory.getInstance()
val contentFactory = toolWindow.contentManager.factory

val overviewTab = contentFactory.createContent(
overviewView,
Expand All @@ -78,42 +76,71 @@
true
)

overviewTab.icon = CoursesIcons.LogoColor
modulesTab.icon = CoursesIcons.Module
exercisesTab.icon = CoursesIcons.ExerciseGroup

// modulesTab.modulesTab.popupIcon = CoursesIcons.Module

fun addAllTabs() {
toolWindow.contentManager.addContent(exercisesTab)
toolWindow.contentManager.addContent(modulesTab)
toolWindow.contentManager.addContent(newsTab)
toolWindow.contentManager.addContent(exercisesTab)
// toolWindow.contentManager.addContent(newsTab)
}

fun removeAllTabs() {
toolWindow.contentManager.removeContent(exercisesTab, true)
toolWindow.contentManager.removeContent(modulesTab, true)
toolWindow.contentManager.removeContent(newsTab, true)
toolWindow.contentManager.removeContent(exercisesTab, true)
// toolWindow.contentManager.removeContent(newsTab, true)
}

toolWindow.contentManager.addContent(overviewTab)
toolWindow.contentManager.addContent(exercisesTab)
toolWindow.contentManager.addContent(modulesTab)
toolWindow.contentManager.addContent(newsTab)
toolWindow.contentManager.addContent(exercisesTab)
// toolWindow.contentManager.addContent(newsTab)
toolWindow.contentManager.setSelectedContent(overviewTab)

toolWindow.setAdditionalGearActions(TOOL_WINDOW_ACTIONS)

// Shorten titles when toolwindow is too small
toolWindow.component.addComponentListener(object : ComponentAdapter() {
override fun componentResized(e: ComponentEvent) {
if (e.component.bounds.width <= 424) {
overviewTab.displayName = message("toolwindows.APlusToolWindowFactory.tabs.overviewShort")
println(e.component.bounds.width)

Check warning on line 108 in src/main/kotlin/fi/aalto/cs/apluscourses/toolwindows/APlusToolWindowFactory.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Call to 'print()' or 'println()'

Uses of `println` should probably be replaced with more robust logging
if (e.component.bounds.width <= 325) {
overviewTab.displayName = ""//message("toolwindows.APlusToolWindowFactory.tabs.overviewShort")
overviewTab.putUserData(
ToolWindow.SHOW_CONTENT_ICON, true
)
} else {
overviewTab.displayName = message("toolwindows.APlusToolWindowFactory.tabs.overview")
overviewTab.putUserData(
ToolWindow.SHOW_CONTENT_ICON, false
)
}
if (e.component.bounds.width <= 370) {
if (e.component.bounds.width <= 300) {
newsView.setShortTab(true)
modulesTab.displayName = message("toolwindows.APlusToolWindowFactory.tabs.modulesShort")
exercisesTab.displayName = message("toolwindows.APlusToolWindowFactory.tabs.exercisesShort")
modulesTab.icon = CoursesIcons.Module
modulesTab.popupIcon = CoursesIcons.Module
modulesTab.displayName =
""//message("toolwindows.APlusToolWindowFactory.tabs.modulesShort")
exercisesTab.displayName =
""//message("toolwindows.APlusToolWindowFactory.tabs.exercisesShort")
modulesTab.putUserData(
ToolWindow.SHOW_CONTENT_ICON, true
)
exercisesTab.putUserData(
ToolWindow.SHOW_CONTENT_ICON, true
)
} else {
newsView.setShortTab(false)
modulesTab.displayName = message("toolwindows.APlusToolWindowFactory.tabs.modules")
exercisesTab.displayName = message("toolwindows.APlusToolWindowFactory.tabs.exercises")
modulesTab.putUserData(
ToolWindow.SHOW_CONTENT_ICON, false
)
exercisesTab.putUserData(
ToolWindow.SHOW_CONTENT_ICON, false
)
}
}
})
Expand Down Expand Up @@ -182,6 +209,7 @@
connection.subscribe(CourseManager.NEWS_TOPIC, object : NewsUpdaterListener {
override fun onNewsUpdated(newsList: NewsList) {
newsView.viewModelChanged(newsList)
overviewView.news.viewModelChanged(newsList)
}
})
connection.subscribe(CourseManager.MODULES_TOPIC, object : CourseManager.ModuleListener {
Expand Down
93 changes: 93 additions & 0 deletions src/main/kotlin/fi/aalto/cs/apluscourses/ui/news/NewsPanel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package fi.aalto.cs.apluscourses.ui.news

import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.JBColor
import com.intellij.ui.dsl.builder.AlignY
import com.intellij.ui.dsl.builder.BottomGap
import com.intellij.ui.dsl.builder.IntelliJSpacingConfiguration
import com.intellij.ui.dsl.builder.panel
import com.intellij.util.application
import com.intellij.util.ui.JBFont
import fi.aalto.cs.apluscourses.icons.CoursesIcons
import fi.aalto.cs.apluscourses.model.news.NewsList
import java.awt.Font

class NewsPanel {
var content: DialogPanel = panel {
row {
label("News")
}
}
private var news: NewsList? = null
// private var shortTab = false
// private val shortTabTitle = message("toolwindows.APlusToolWindowFactory.tabs.newsShort")
// private val longTabTitle = message("toolwindows.APlusToolWindowFactory.tabs.news")
// private val tabTitle
// get() = if (shortTab) shortTabTitle else longTabTitle

// private val notificationDot = message("ui.NewsView.notificationDot")
// private val unreadTabTitle
// get() = """<html><body>${
// if (shortTab)
// notificationDot
// else
// message("ui.NewsView.titleWithDot")
// }</body></html>"""

// init {
// val content = JBScrollPane()
// setContent(content)
// emptyText.text = message("ui.NewsView.noNews")
// }

/**
* Sets the view model of this view, or does nothing if the given view model is null.
*/
fun viewModelChanged(newsList: NewsList?) {
application.invokeLater {
this.news = newsList
if (newsList == null || newsList.news.isEmpty()) {
content.removeAll()
return@invokeLater
}
val newsPanel = panel {
customizeSpacingConfiguration(object : IntelliJSpacingConfiguration() {
override val verticalComponentGap: Int = 1
}) {
for (node in newsList.news) {
row {
text(node.title).applyToComponent {
font = JBFont.regular().biggerOn(6f).deriveFont(Font.BOLD)
}.resizableColumn()
if (!node.isRead) {
icon(CoursesIcons.NewChip).align(AlignY.TOP)
}
}
row {
text(node.publishTimeInfo).applyToComponent {
foreground = JBColor.GRAY
}
}.bottomGap(BottomGap.SMALL)
row { text(node.body) }.bottomGap(BottomGap.SMALL)
separator().bottomGap(BottomGap.SMALL)
}
}
}
content = newsPanel
// updateTitle()
// updateUI()
}
}

// fun setShortTab(short: Boolean) {
// shortTab = short
// updateTitle()
// }
//
// private fun updateTitle() {
// val currentNews = news
// val content = toolWindow.contentManager.getContent(this) ?: return
// content.displayName =
// if (currentNews != null && currentNews.unreadCount() > 0) unreadTabTitle else tabTitle
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import fi.aalto.cs.apluscourses.ui.BannerPanel
import fi.aalto.cs.apluscourses.ui.TokenForm
import fi.aalto.cs.apluscourses.ui.Utils.loadingPanel
import fi.aalto.cs.apluscourses.ui.Utils.myActionLink
import fi.aalto.cs.apluscourses.ui.news.NewsPanel
import fi.aalto.cs.apluscourses.utils.DateDifferenceFormatter
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
Expand All @@ -44,6 +45,8 @@ class OverviewView(private val project: Project) : SimpleToolWindowPanel(true, t

private var panel = createPanel()

val news: NewsPanel = NewsPanel()

fun update(loading: Boolean = false) {
panel = createPanel(loading)
val content = JBScrollPane(panel)
Expand Down Expand Up @@ -220,7 +223,23 @@ class OverviewView(private val project: Project) : SimpleToolWindowPanel(true, t
row {
text(course.name).applyToComponent {
font = JBFont.h0()
}.comment(user.userName)
}.comment(user.userName).resizableColumn()
panel {
row {
link(message("ui.OverviewView.pluginSettings")) {
ShowSettingsUtil.getInstance().showSettingsDialog(project, message("aplusCourses"))
}.applyToComponent {
icon = AllIcons.General.Settings
isFocusPainted = false
}
}
row {
browserLink(message("ui.OverviewView.coursePage"), course.htmlUrl).applyToComponent {
setIcon(CoursesIcons.LogoColor, atRight = false)
isFocusPainted = false
}
}
}
}.topGap(TopGap.SMALL)
if (points == null || maxPoints == null) {
row {
Expand Down Expand Up @@ -272,23 +291,13 @@ class OverviewView(private val project: Project) : SimpleToolWindowPanel(true, t
}
separator().bottomGap(BottomGap.MEDIUM)
weekClosingTime(weeks)
row {
link(message("ui.OverviewView.pluginSettings")) {
ShowSettingsUtil.getInstance().showSettingsDialog(project, message("aplusCourses"))
}.applyToComponent {
icon = AllIcons.General.Settings
isFocusPainted = false
}
}
row {
browserLink(message("ui.OverviewView.coursePage"), course.htmlUrl).applyToComponent {
setIcon(CoursesIcons.LogoColor, atRight = false)
isFocusPainted = false
}
}
}
}
}.customize(UnscaledGaps(16, 32, 16, 32))
row {
cell(news.content)
}
}.customize(UnscaledGaps(16, 16, 16, 16))

}
mainPanel.preferredSize = Dimension(mainPanelMaxWidth, mainPanel.preferredSize.height)
// mainPanel.maximumSize = Dimension(mainPanelMaxWidth, Int.MAX_VALUE)
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/messages/resources.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ services.progress.refreshingCourse=Refreshing course
services.progress.refreshingAssignments=Refreshing assignments
services.progress.gradingAssignments=Assignment in grading
# Main tool window
toolwindows.APlusToolWindowFactory.tabs.overview=<html><body><b>A+ Courses</b></body></html>
toolwindows.APlusToolWindowFactory.tabs.overviewShort=<html><body><b>A+</b></body></html>
toolwindows.APlusToolWindowFactory.tabs.overview=Course
toolwindows.APlusToolWindowFactory.tabs.overviewShort=<html><body><p>Course</p>/body></html>
toolwindows.APlusToolWindowFactory.tabs.exercises=Assignments
toolwindows.APlusToolWindowFactory.tabs.exercisesShort=📚
toolwindows.APlusToolWindowFactory.tabs.modules=Modules
Expand Down
Loading