-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Erwin Dondorp
authored and
Erwin Dondorp
committed
May 23, 2021
1 parent
832b922
commit 6fd34f5
Showing
9 changed files
with
155 additions
and
90 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,18 @@ | ||
import {DropDownMenu} from "./DropDown.js"; | ||
|
||
export class DropDownMenuCheckbox extends DropDownMenu { | ||
// constructor (pParentElement) { | ||
// super(pParentElement); | ||
// } | ||
|
||
/* | ||
addMenuItemCheckbox (pTitle, pCallback) { | ||
const menuItem = super.addMenuItem(pTitle, () => { | ||
this._selectCallback(pValue, pTitle, pMenuTitle); | ||
}, (pMenuItem) => { | ||
return this._verifyMenuItem(pMenuItem); | ||
pCallback(ev); | ||
}); | ||
} | ||
*/ | ||
} |
This file contains 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,24 @@ | ||
import {DropDownMenu} from "./DropDown.js"; | ||
|
||
export class DropDownMenuCmd extends DropDownMenu { | ||
// constructor (pParentElement) { | ||
// super(pParentElement); | ||
// } | ||
|
||
_selectCallback (pMenuItem, pTitle) { | ||
// show the chosen value | ||
if (typeof pTitle !== "string") { | ||
pTitle = pTitle(pMenuItem); | ||
} | ||
this.setTitle(pTitle); | ||
} | ||
|
||
addMenuItemCmd (pTitle, pCallback) { | ||
const menuItem = super.addMenuItem(pTitle, (pMenuItem) => { | ||
this._selectCallback(pMenuItem, pTitle); | ||
}, (pMenuItem) => { | ||
pCallback(pMenuItem); | ||
}); | ||
return menuItem; | ||
} | ||
} |
This file contains 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,69 @@ | ||
import {DropDownMenu} from "./DropDown.js"; | ||
|
||
export class DropDownMenuRadio extends DropDownMenu { | ||
constructor (pParentElement) { | ||
super(pParentElement); | ||
this.value = null; | ||
this.defaultValue = null; | ||
} | ||
|
||
getValue () { | ||
if (this.value === null) { | ||
return this.defaultValue; | ||
} | ||
return this.value; | ||
} | ||
|
||
setValue (pValue) { | ||
this.value = pValue; | ||
} | ||
|
||
setDefaultValue (pDefaultValue) { | ||
this.defaultValue = pDefaultValue; | ||
} | ||
|
||
_verifyMenuItem (pMenuItem) { | ||
let title; | ||
if (typeof pMenuItem._title === "string") { | ||
title = pMenuItem._title; | ||
} else { | ||
title = pMenuItem._title(pMenuItem); | ||
} | ||
|
||
if (title === null) { | ||
// menu item will be hidden | ||
} else if (pMenuItem._value === this.value) { | ||
// 25CF = BLACK CIRCLE | ||
title = "\u25CF " + title; | ||
} else if (this.value === null && pMenuItem._value === this.defaultValue) { | ||
// 25CB = WHITE CIRCLE | ||
title = "\u25CB " + title; | ||
} | ||
return title; | ||
} | ||
|
||
_selectCallback (pValue, pTitle, pMenuTitle) { | ||
|
||
this.value = pValue; | ||
|
||
// show the chosen value | ||
if (pMenuTitle === null) { | ||
// caller can specify a more specific menu title | ||
// usually an abbreviation of the chosen menu item | ||
if (typeof pTitle !== "string") { | ||
pTitle = pTitle(); | ||
} | ||
this.setTitle(pTitle); | ||
} else { | ||
this.setTitle(pMenuTitle); | ||
} | ||
} | ||
|
||
addMenuItemRadio (pValue, pTitle, pMenuTitle = null) { | ||
const menuItem = super.addMenuItem(pTitle, () => { | ||
this._selectCallback(pValue, pTitle, pMenuTitle); | ||
}, (pMenuItem) => this._verifyMenuItem(pMenuItem)); | ||
|
||
menuItem._value = pValue; | ||
} | ||
} |
This file contains 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,59 +1,26 @@ | ||
/* global console document */ | ||
/* global document */ | ||
|
||
import {Character} from "./Character.js"; | ||
import {DropDownMenu} from "./DropDown.js"; | ||
import {DropDownMenuRadio} from "./DropDownRadio.js"; | ||
|
||
export class RunType { | ||
|
||
static createMenu () { | ||
const runblock = document.getElementById("run-block"); | ||
RunType.menuRunType = new DropDownMenu(runblock); | ||
// do not show the menu title at first | ||
RunType.menuRunType.setTitle(""); | ||
RunType.menuRunType.addMenuItem("Normal", this._updateRunTypeText, "normal"); | ||
RunType.menuRunType.addMenuItem("Async", this._updateRunTypeText, "async"); | ||
RunType._updateRunTypeText(); | ||
} | ||
|
||
static _updateRunTypeText () { | ||
const runType = RunType.getRunType(); | ||
|
||
switch (runType) { | ||
case "normal": | ||
// now that the menu is used show the menu title | ||
RunType.menuRunType.setTitle("Normal"); | ||
break; | ||
case "async": | ||
RunType.menuRunType.setTitle("Async"); | ||
break; | ||
default: | ||
console.error("runType", runType); | ||
} | ||
|
||
const menuItems = RunType.menuRunType.menuDropdownContent.children; | ||
for (let i = 0; i < menuItems.length; i++) { | ||
let menuItemText = menuItems[i].innerText; | ||
menuItemText = menuItemText.replace(/^. /, ""); | ||
if (menuItems[i]._value === runType) { | ||
menuItemText = Character.BLACK_CIRCLE + " " + menuItemText; | ||
} | ||
menuItems[i].innerText = menuItemText; | ||
} | ||
RunType.menuRunType = new DropDownMenuRadio(runblock); | ||
RunType.menuRunType.setDefaultValue("normal"); | ||
RunType.menuRunType.addMenuItemRadio("normal", "Normal"); | ||
RunType.menuRunType.addMenuItemRadio("async", "Async"); | ||
} | ||
|
||
static setRunTypeDefault () { | ||
RunType.menuRunType._value = "normal"; | ||
RunType._updateRunTypeText(); | ||
RunType.menuRunType.setValue(null); | ||
// reset the title to the absolute minimum | ||
// so that the menu does not stand out in trivial situations | ||
RunType.menuRunType.setTitle(""); | ||
} | ||
|
||
static getRunType () { | ||
const runType = RunType.menuRunType._value; | ||
if (runType === undefined || runType === "") { | ||
return "normal"; | ||
} | ||
const runType = RunType.menuRunType.getValue(); | ||
return runType; | ||
} | ||
} |
This file contains 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.