-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Experimental sharing of components between EditorToolbar and DeckOptions #1155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5010eda
Move DropdownMenu to sveltelib
hgiesel cbdd9ca
Use sveltelib/DropdownMenu instead of custom implementation in Option…
hgiesel c377e98
Generalize ButtonGroup to work for DeckOptions
hgiesel e8cc249
Define optionsDropdown completely dynamically
hgiesel 3b7ba51
Fix some typing issues
hgiesel 43fc04e
Allow theming of LabelButton
hgiesel 5c6de2b
Move StickyBar to sveltelib
hgiesel 995f622
Use SelectButton in deckoptions
hgiesel 5dfbbb9
Remove unused import
hgiesel 1b8a8f0
Fix import in EditorToolbar
hgiesel 029b3e7
Add license header
hgiesel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| @use "ts/sass/vars"; | ||
| @use "ts/sass/scrollbar"; | ||
| @use "ts/sass/bootstrap-dark"; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| // Copyright: Ankitects Pty Ltd and contributors | ||
| // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html | ||
| import * as tr from "lib/i18n"; | ||
| import { textInputModal } from "./textInputModal"; | ||
| import type { DeckOptionsState, ConfigListEntry } from "./lib"; | ||
| import { | ||
| DynamicSvelteComponent, | ||
| labelButton, | ||
| buttonGroup, | ||
| dropdownMenu, | ||
| dropdownItem, | ||
| dropdownDivider, | ||
| selectButton, | ||
| } from "sveltelib/dynamicComponents"; | ||
|
|
||
| function configLabel(entry: ConfigListEntry): string { | ||
| const count = tr.deckConfigUsedByDecks({ decks: entry.useCount }); | ||
| return `${entry.name} (${count})`; | ||
| } | ||
|
|
||
| export function getOptionsDropdown( | ||
| state: DeckOptionsState, | ||
| configList: ConfigListEntry[] | ||
| ): DynamicSvelteComponent { | ||
| function addConfig(): void { | ||
| textInputModal({ | ||
| title: "Add Config", | ||
| prompt: "Name:", | ||
| onOk: (text: string) => { | ||
| const trimmed = text.trim(); | ||
| if (trimmed.length) { | ||
| state.addConfig(trimmed); | ||
| } | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| function renameConfig(): void { | ||
| textInputModal({ | ||
| title: "Rename Config", | ||
| prompt: "Name:", | ||
| startingValue: state.getCurrentName(), | ||
| onOk: (text: string) => { | ||
| state.setCurrentName(text); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| function removeConfig(): void { | ||
| // show pop-up after dropdown has gone away | ||
| setTimeout(() => { | ||
| if (state.defaultConfigSelected()) { | ||
| alert(tr.schedulingTheDefaultConfigurationCantBeRemoved()); | ||
| return; | ||
| } | ||
| // fixme: move tr.qt_misc schema mod msg into core | ||
| // fixme: include name of deck in msg | ||
| const msg = state.removalWilLForceFullSync() | ||
| ? "This will require a one-way sync. Are you sure?" | ||
| : "Are you sure?"; | ||
| if (confirm(msg)) { | ||
| try { | ||
| state.removeCurrentConfig(); | ||
| } catch (err) { | ||
| alert(err); | ||
| } | ||
| } | ||
| }, 100); | ||
| } | ||
|
|
||
| function save(applyToChildDecks: boolean): void { | ||
| state.save(applyToChildDecks); | ||
| } | ||
|
|
||
| function blur(this: HTMLSelectElement) { | ||
| state.setCurrentIndex(parseInt(this.value)); | ||
| } | ||
|
|
||
| const options = configList.map((entry) => ({ | ||
| value: entry.idx, | ||
| selected: entry.current, | ||
| label: configLabel(entry), | ||
| })); | ||
|
|
||
| return buttonGroup({ | ||
| id: "configSelector", | ||
| className: "justify-content-between", | ||
| size: 35, | ||
| items: [ | ||
| buttonGroup({ | ||
| className: "flex-basis-75", | ||
| items: [ | ||
| selectButton({ | ||
| options, | ||
| className: "flex-basis-100", | ||
| onChange: blur, | ||
| }), | ||
| ], | ||
| }), | ||
| buttonGroup({ | ||
| id: "optionsDropdown", | ||
| items: [ | ||
| labelButton({ | ||
| label: "Save", | ||
| theme: "primary", | ||
| onClick: () => save(false), | ||
| }), | ||
| labelButton({ | ||
| dropdownToggle: true, | ||
| }), | ||
| dropdownMenu({ | ||
| items: [ | ||
| dropdownItem({ | ||
| label: "Add Config", | ||
| onClick: addConfig, | ||
| }), | ||
| dropdownItem({ | ||
| label: "Rename Config", | ||
| onClick: renameConfig, | ||
| }), | ||
| dropdownItem({ | ||
| label: "Remove Config", | ||
| onClick: removeConfig, | ||
| }), | ||
| dropdownDivider({}), | ||
| dropdownItem({ | ||
| label: "Save to All Children", | ||
| onClick: () => save(true), | ||
| }), | ||
| ], | ||
| }), | ||
| ], | ||
| }), | ||
| ], | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the height of the toolbar, maybe we could rename it to 'height'?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also affects the width of buttons / font-weight, so height seems to be a bit deceiving.