Skip to content

Commit

Permalink
More ribbon API prototyping
Browse files Browse the repository at this point in the history
Default taskbar key policy, sample anchored commands

For #56
  • Loading branch information
kirill-grouchnikov committed Dec 19, 2022
1 parent 6459893 commit 8d0a1d3
Show file tree
Hide file tree
Showing 7 changed files with 1,107 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ class RibbonApplicationMenuCommandButtonProjection(
data class Ribbon(
val tasks: List<RibbonTask>,
val selectedTask: RibbonTask,
val onTaskClick: () -> Unit,
val contextualTaskGroups: List<RibbonContextualTaskGroup>?,
val anchoredCommands: List<CommandButtonProjection>?,
val onTaskClick: (RibbonTask) -> Unit,
val contextualTaskGroups: List<RibbonContextualTaskGroup> = emptyList(),
val anchoredCommands: List<CommandButtonProjection> = emptyList(),
val taskbarCommandProjections: List<RibbonTaskbarCommandButtonProjection> = emptyList(),
val taskbarComponentProjections: List<RibbonComponentProjection<ContentModel, PresentationModel>> = emptyList(),
val taskbarGalleryProjections: List<RibbonGalleryProjection> = emptyList(),
val taskbarKeyTipPolicy: RibbonTaskbarKeyTipPolicy,
val applicationMenuCommandButtonProjection: RibbonApplicationMenuCommandButtonProjection,
val applicationMenuCommandButtonProjection: RibbonApplicationMenuCommandButtonProjection? = null,
val isMinimized: Boolean = false,
val onShowContextualMenuListener: OnShowContextualMenuListener?
val onShowContextualMenuListener: OnShowContextualMenuListener? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ interface RibbonTaskbarKeyTipPolicy {
val overflowButtonKeyTip: String
}

class DefaultRibbonTaskbarKeyTipPolicy : RibbonTaskbarKeyTipPolicy {
override val overflowButtonKeyTip = "00"

override fun getContentKeyTip(contentIndex: Int): String {
var contentIndex = contentIndex
if (contentIndex < 10) {
return contentIndex.toString()
}
contentIndex -= 10

// Creates a sequence of 01, 02, 03, ..., 09, 0A, 0B, 0C, ..., 0Z, 11, 12, ...
return (contentIndex / LETTERS.length).toString() +
LETTERS[contentIndex % LETTERS.length]
}

companion object {
private const val LETTERS = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
}
}

class RibbonTaskbarCommandButtonProjection(
val contentModel: Command,
val presentationModel: RibbonTaskbarCommandButtonPresentationModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ import org.pushingpixels.aurora.demo.ColorSolidIcon
import org.pushingpixels.aurora.demo.DecoratedIcon
import org.pushingpixels.aurora.demo.getQuickStylesContentModel
import org.pushingpixels.aurora.demo.svg.tango.*
import org.pushingpixels.aurora.theming.PopupPlacementStrategy
import org.pushingpixels.aurora.theming.marinerSkin
import org.pushingpixels.aurora.window.auroraApplication
import java.text.MessageFormat
import java.util.*
import javax.swing.JOptionPane

fun main() = auroraApplication {
val state = rememberWindowState(
Expand Down Expand Up @@ -83,6 +85,73 @@ fun main() = auroraApplication {
resizeSequencingPolicy = CoreRibbonResizeSequencingPolicies.RoundRobin(),
keyTip = "W"
)

var selectedTask by remember { mutableStateOf(pageLayoutTask) }

// "Share" anchored menu
val shareEntrySendMail = Command(
text = resourceBundle.getString("AppMenuSend.email.text"),
action = { println("Shared to email") }
)
val shareEntrySendHtml = Command(
text = resourceBundle.getString("AppMenuSend.html.text"),
action = { println("Shared to browser") }
)
val shareEntrySendDoc = Command(
text = resourceBundle.getString("AppMenuSend.word.text"),
action = { println("Shared to Word") }
)

val anchoredCommands = listOf(
CommandButtonProjection(
contentModel = Command(
text = resourceBundle.getString("Share.title"),
icon = internet_mail(),
secondaryContentModel = CommandMenuContentModel(
group = CommandGroup(
commands = listOf(shareEntrySendMail, shareEntrySendHtml, shareEntrySendDoc)
)
)
),
presentationModel = CommandButtonPresentationModel(
popupPlacementStrategy = PopupPlacementStrategy.Downward.HAlignEnd,
popupKeyTip = "GS"
)
),
CommandButtonProjection(
contentModel = Command(
text = "",
icon = internet_group_chat(),
action = { println("Chat button clicked!") },
isActionToggle = true
),
presentationModel = CommandButtonPresentationModel(
popupKeyTip = "GC"
)
),
CommandButtonProjection(
contentModel = Command(
text = "",
icon = help_browser(),
action = { println("Help button clicked!") },
actionRichTooltip = RichTooltip(
title = resourceBundle.getString("Help.tooltip.title"),
descriptionSections = listOf(resourceBundle.getString("Help.tooltip.actionParagraph"))
)
),
presentationModel = CommandButtonPresentationModel(
popupKeyTip = "GH"
)
)
)

val ribbon = Ribbon(
tasks = listOf(pageLayoutTask, writeTask),
selectedTask = selectedTask,
onTaskClick = { selectedTask = it },
taskbarKeyTipPolicy = DefaultRibbonTaskbarKeyTipPolicy(),
anchoredCommands = anchoredCommands
)
}

private class RibbonBuilder(val resourceBundle: ResourceBundle) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8d0a1d3

Please sign in to comment.