forked from MapComplete/MapComplete
Refactoring: split 'ThemeViewState' into many classes
This commit is contained in:
parent
2b858bd2aa
commit
dbcbf2787d
34 changed files with 1503 additions and 1227 deletions
72
src/Models/ThemeViewState/WithGuiState.ts
Normal file
72
src/Models/ThemeViewState/WithGuiState.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import ThemeConfig from "../ThemeConfig/ThemeConfig"
|
||||
import { MenuState } from "../MenuState"
|
||||
import Hotkeys from "../../UI/Base/Hotkeys"
|
||||
import Translations from "../../UI/i18n/Translations"
|
||||
import { WithSpecialLayers } from "./WithSpecialLayers"
|
||||
|
||||
/**
|
||||
* Does all things related to:
|
||||
* - The UI state
|
||||
*/
|
||||
export class WithGuiState extends WithSpecialLayers {
|
||||
readonly guistate: MenuState
|
||||
|
||||
constructor(theme: ThemeConfig, mvtAvailableLayers: Set<string>) {
|
||||
super(theme, mvtAvailableLayers)
|
||||
this.guistate = new MenuState(
|
||||
this.featureSwitches.featureSwitchWelcomeMessage.data,
|
||||
theme.id
|
||||
)
|
||||
|
||||
Object.values(this.guistate.pageStates).forEach((toggle) => {
|
||||
toggle.addCallbackD((isOpened) => {
|
||||
// When a panel is closed: focus on the map again
|
||||
if (!isOpened) {
|
||||
if (!this.guistate.isSomethingOpen()) {
|
||||
this.focusOnMap()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
this.initHotkeysGui()
|
||||
}
|
||||
|
||||
|
||||
private initHotkeysGui() {
|
||||
const docs = Translations.t.hotkeyDocumentation
|
||||
|
||||
Hotkeys.RegisterHotkey({ nomod: "f" }, docs.selectFavourites, () => {
|
||||
this.guistate.pageStates.favourites.set(true)
|
||||
})
|
||||
|
||||
Hotkeys.RegisterHotkey(
|
||||
{
|
||||
nomod: "b"
|
||||
},
|
||||
docs.openLayersPanel,
|
||||
() => {
|
||||
if (this.featureSwitches.featureSwitchBackgroundSelection.data) {
|
||||
this.guistate.pageStates.background.setData(true)
|
||||
}
|
||||
}
|
||||
)
|
||||
Hotkeys.RegisterHotkey(
|
||||
{
|
||||
nomod: "s"
|
||||
},
|
||||
Translations.t.hotkeyDocumentation.openFilterPanel,
|
||||
() => {
|
||||
if (this.featureSwitches.featureSwitchFilter.data) {
|
||||
this.guistate.openFilterView()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public selectCurrentView() {
|
||||
this.guistate.closeAll()
|
||||
this.selectedElement.setData(this.currentView.features?.data?.[0])
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue