Skip to content

Commit f4556d4

Browse files
author
Rob Whitaker
committed
Added help dialog (displays keyboard shortcuts).
1 parent 649573e commit f4556d4

File tree

7 files changed

+191
-25
lines changed

7 files changed

+191
-25
lines changed

src/Planner/Component/Event.elm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ loadProjectEvent event =
4444
(Just { event | setContext <- Just Context.Default })
4545
Nothing,
4646
setContext <- Just Context.Dialog
47+
}
48+
49+
showHelpEvent : Event
50+
showHelpEvent =
51+
{ emptyEvent |
52+
action <-
53+
Event.Dialog <|
54+
Dialog.Show <|
55+
DialogBuilder.createDialog DialogBuilder.keyboardShortcutDialogModel,
56+
setContext <- Just Context.Dialog
4757
}

src/Planner/Component/Text.elm

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,72 @@ confirmLoadProject = "Are you sure you want to load a new project? Any unsaved p
1212

1313
newItemTitle = "new"
1414

15+
---- KEYBOARD SHORTCUTS ----
16+
17+
newProjectShortcut = ("New Project", "Ctrl+/")
18+
19+
saveProjectShortcut = ("Save Project", "Ctrl+S")
20+
21+
loadProjectShortcut = ("Load Project", "Ctrl+O")
22+
23+
newNodeShortcut = ("New Node", "Ctrl+Return")
24+
25+
renameNodeShortcut = ("Rename Node", "Return")
26+
27+
toggleExpandedShortcut = ("Toggle Expanded", "Space")
28+
29+
deleteNodeShortcut = ("Delete Node", "Del")
30+
31+
moveNodeLeftShortcut = ("Move Node Left", "Ctrl+LeftArrow")
32+
33+
moveNodeUpShortcut = ("Move Node Up", "Ctrl+UpArrow")
34+
35+
moveNodeDownShortcut = ("Move Node Down", "Ctrl+DownArrow")
36+
37+
moveNodeRightShortcut = ("Move Node Right", "Ctrl+RightArrow")
38+
39+
moveSelectionUpShortcut = ("Move Selection Up", "UpArrow")
40+
41+
moveSelectionDownShortcut = ("Move Selection Down", "DownArrow")
42+
43+
editTitleShortcut = ("Focus Title", "Esc")
44+
45+
toggleFocusShortcut = ("Change Focus", "Tab")
46+
47+
showHelpShortcut = ("Show Keyboard Shortcuts", "h")
48+
1549
---- BUTTON ALT TEXT ----
1650

17-
newProjectButtonAlt = "New Project (Ctrl+/)"
51+
scToAlt (actionStr, keyStr) = actionStr ++ " (" ++ keyStr ++ ")"
1852

19-
saveProjectButtonAlt = "Save Project (Ctrl+S)"
53+
newProjectButtonAlt = scToAlt newProjectShortcut
2054

21-
loadProjectButtonAlt = "Load Project (Ctrl+O)"
55+
saveProjectButtonAlt = scToAlt saveProjectShortcut
2256

23-
newNodeButtonAlt = "New Node (Ctrl+Return)"
57+
loadProjectButtonAlt = scToAlt loadProjectShortcut
2458

25-
renameNodeButtonAlt = "Rename Node (Return)"
59+
newNodeButtonAlt = scToAlt newNodeShortcut
2660

27-
toggleExpandedButtonAlt = "Toggle Expanded (Space)"
61+
renameNodeButtonAlt = scToAlt renameNodeShortcut
2862

29-
deleteNodeButtonAlt = "Delete Node (Del)"
63+
toggleExpandedButtonAlt = scToAlt toggleExpandedShortcut
3064

31-
moveNodeLeftButtonAlt = "Move Left (Ctrl+Left)"
65+
deleteNodeButtonAlt = scToAlt deleteNodeShortcut
3266

33-
moveNodeUpButtonAlt = "Move Up (Ctrl+Up)"
67+
moveNodeLeftButtonAlt = scToAlt moveNodeLeftShortcut
3468

35-
moveNodeDownButtonAlt = "Move Down (Ctrl+Down)"
69+
moveNodeUpButtonAlt = scToAlt moveNodeUpShortcut
3670

37-
moveNodeRightButtonAlt = "Move Right (Ctrl+Right)"
71+
moveNodeDownButtonAlt = scToAlt moveNodeDownShortcut
72+
73+
moveNodeRightButtonAlt = scToAlt moveNodeRightShortcut
3874

3975
collapseAllButtonAlt = "Collapse All"
4076

4177
expandAllButtonAlt = "Expand All"
4278

79+
showHelpButtonAlt = scToAlt showHelpShortcut
80+
4381
---- MISC ----
4482

4583
untitledSaveTitle = "untitled"

src/Planner/UI/Dialog.elm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ type alias Dialog event = {
1212
keyboardInputMap : List Int -> Model event -> event
1313
}
1414

15-
type Model event =
16-
ConfirmDialog { query : String, confirm : event, cancel : event, selectedOption : Int }
15+
type Model event
16+
= ConfirmDialog { query : String, confirm : event, cancel : event, selectedOption : Int }
17+
| KeyboardShortcutDialog { keyMap : List (String, String) }
1718

1819
type Action event
1920
= Show (Maybe (Dialog event))

src/Planner/UI/DialogBuilder.elm

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import Planner.UI.Dialog as Dialog
44
import Planner.Event as Event
55
import Planner.Event exposing (emptyEvent)
66
import Planner.UI.Context as Context
7+
import Planner.Component.Text as Text
78

89
import Html exposing (..)
910
import Html.Attributes exposing (..)
1011
import Html.Events exposing (..)
1112
import Maybe
13+
import List
1214

1315
---- CONFIRM DIALOG ----
1416

@@ -30,6 +32,40 @@ confirm query confirm cancel = let
3032
cancel <- Maybe.withDefault model.cancel cancel
3133
}
3234

35+
---- KEYBOARD SHORTCUT DIALOG ----
36+
37+
keyboardShortcutDialogModel : Dialog.Model Event.Event
38+
keyboardShortcutDialogModel = Dialog.KeyboardShortcutDialog {
39+
keyMap = [
40+
("FILE", ""),
41+
Text.newProjectShortcut,
42+
Text.saveProjectShortcut,
43+
Text.loadProjectShortcut,
44+
45+
("NODE OPERATIONS", ""),
46+
Text.newNodeShortcut,
47+
Text.renameNodeShortcut,
48+
Text.toggleExpandedShortcut,
49+
Text.deleteNodeShortcut,
50+
51+
("NODE MOVEMENT", ""),
52+
Text.moveNodeLeftShortcut,
53+
Text.moveNodeUpShortcut,
54+
Text.moveNodeDownShortcut,
55+
Text.moveNodeRightShortcut,
56+
57+
("SELECTION MOVEMENT", ""),
58+
Text.moveSelectionUpShortcut,
59+
Text.moveSelectionDownShortcut,
60+
61+
("CHANGING FOCUS", ""),
62+
Text.editTitleShortcut,
63+
Text.toggleFocusShortcut,
64+
65+
("HELP MENU", ""),
66+
Text.showHelpShortcut
67+
]
68+
}
3369
---- DIALOG CREATION ----
3470

3571
createDialog : Dialog.Model Event.Event -> Maybe (Dialog.Dialog Event.Event)
@@ -52,7 +88,7 @@ createDialog model =
5288
onClick address m'.cancel
5389
] [],
5490
div [
55-
class "confirm-dialog",
91+
class "dialog",
5692
style [("top", toString (h//2 - 167) ++ "px"), ("left", toString (w//2 - 257) ++ "px")]
5793
] [
5894
h2 [] [text m'.query],
@@ -80,4 +116,39 @@ createDialog model =
80116
[39] -> { emptyEvent | action <- Event.Dialog (Dialog.Custom (Dialog.ChangeSelection 1)) }
81117
_ -> emptyEvent
82118
}
119+
120+
Dialog.KeyboardShortcutDialog m -> Just {
121+
model = model,
122+
123+
update action dialModel = dialModel,
124+
125+
keyboardInputMap keypresses dialModel =
126+
case keypresses of
127+
[27] -> { emptyEvent | action <- Event.Dialog Dialog.Hide, setContext <- Just Context.Default }
128+
[72] -> { emptyEvent | action <- Event.Dialog Dialog.Hide, setContext <- Just Context.Default }
129+
_ -> emptyEvent,
130+
131+
view (w,h) address dialModel =
132+
let (Dialog.KeyboardShortcutDialog m') = dialModel
133+
in div [] [
134+
div [
135+
class "modal-background",
136+
onClick address { emptyEvent | action <- Event.Dialog Dialog.Hide, setContext <- Just Context.Default }
137+
] [],
138+
div [
139+
class "dialog keyboard-shortcuts",
140+
style [("top", toString ((toFloat h * 0.5) - (toFloat h * 0.8)/2) ++ "px"), ("left", toString (w//2 - 250) ++ "px"), ("height", toString (toFloat h * 0.8) ++ "px")]
141+
] [
142+
ul [] <|
143+
List.foldr (\(actionStr, keyStr) acc -> let
144+
color = (List.length acc) % 2
145+
tag = if keyStr == ""
146+
then li [class "heading"] [h4 [] [text actionStr]]
147+
else li [class <| "color-" ++ toString color] [div [class "left-side"] [text actionStr], div [class "right-side"] [text keyStr]]
148+
in tag :: acc
149+
) [] m'.keyMap
150+
]
151+
]
152+
}
153+
83154
_ -> Nothing

src/Planner/Update.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Planner.UI.Context as Context
66
import Planner.UI.Context exposing (..)
77
import Planner.Event as Event
88
import Planner.Event exposing (..)
9-
import Planner.Component.Event exposing (newProjectEvent, deleteNodeEvent)
9+
import Planner.Component.Event exposing (newProjectEvent, deleteNodeEvent, showHelpEvent)
1010
import Planner.UI.Dialog as Dialog
1111
import Planner.UI.DialogBuilder as DialogBuilder
1212
import Util.List exposing (takeWhile, dropWhile)
@@ -135,6 +135,7 @@ keyPressesToEvent keypresses state = case keypresses of
135135
[40] -> { emptyEvent | action <- MoveSelection Down }
136136
[27] -> { emptyEvent | setContext <- Just TitleInput }
137137
[9] -> { emptyEvent | setContext <- Just MainTextArea }
138+
[72] -> showHelpEvent
138139
_ -> emptyEvent
139140

140141
Context.Dialog ->

src/Planner/View.elm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Planner.Data.Tree exposing (Tree)
77
import Planner.Data.Tree as T
88
import Planner.Event as Event
99
import Planner.Event exposing (..)
10-
import Planner.Component.Event exposing (newProjectEvent, deleteNodeEvent)
10+
import Planner.Component.Event exposing (newProjectEvent, deleteNodeEvent, showHelpEvent)
1111
import Planner.Component.Text as Text
1212

1313
import Html exposing (..)
@@ -43,7 +43,6 @@ render address state (w, h) = let
4343
],
4444
div [class "options-bar", onClick address {emptyEvent | setContext <- Just Context.Default } ] [
4545
i [class "fa fa-file-text-o icon", onClick address newProjectEvent, alt Text.newProjectButtonAlt, title Text.newProjectButtonAlt] [],
46-
-- TODO : address was saveFile.address (fix wiring later)
4746
i [class "fa fa-download icon", onClick address { emptyEvent | action <- SaveProject }, alt Text.saveProjectButtonAlt, title Text.saveProjectButtonAlt] [],
4847
label [for "loadButton"] [
4948
Html.form [id "loadWrapperForm"] [
@@ -63,7 +62,8 @@ render address state (w, h) = let
6362
i [class "fa fa-arrow-right icon", onClick address { emptyEvent | action <- MoveNode T.Lower, setContext <- Just Context.Default }, alt Text.moveNodeRightButtonAlt, title Text.moveNodeRightButtonAlt ] [],
6463
div [class "divider"] [],
6564
i [class "fa fa-caret-square-o-up icon", onClick address { emptyEvent | action <- SetAllExpanded False, setContext <- Just Context.Default }, alt Text.collapseAllButtonAlt, title Text.collapseAllButtonAlt ] [],
66-
i [class "fa fa-caret-square-o-down icon", onClick address { emptyEvent | action <- SetAllExpanded True, setContext <- Just Context.Default }, alt Text.expandAllButtonAlt, title Text.expandAllButtonAlt ] []
65+
i [class "fa fa-caret-square-o-down icon", onClick address { emptyEvent | action <- SetAllExpanded True, setContext <- Just Context.Default }, alt Text.expandAllButtonAlt, title Text.expandAllButtonAlt ] [],
66+
i [class "fa fa-question-circle icon", style [("float","right")], onClick address showHelpEvent, alt Text.showHelpButtonAlt, title Text.showHelpButtonAlt] []
6767
],
6868
div [
6969
class "main-container",

styles/dialog.css

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
z-index: 10;
1010
}
1111

12-
/*CONFIRM DIALOG*/
13-
14-
.confirm-dialog {
12+
.dialog {
1513
position: absolute;
1614
top: 1em;
1715
width: 500px;
@@ -22,9 +20,56 @@
2220
border-radius: 1em;
2321
padding: 14px;
2422
text-align: center;
23+
overflow: auto;
24+
}
25+
26+
27+
/* KEYBOARD SHORTCUTS DIALOG */
28+
29+
.keyboard-shortcuts {
30+
width: 500px;
31+
/*height: 500px;*/
32+
padding: 0;
33+
text-align: center;
34+
background-color: #fff;
35+
}
36+
37+
.keyboard-shortcuts li {
38+
display: block;
39+
min-height: 2em;
40+
padding-top: 1em;
41+
}
42+
43+
.keyboard-shortcuts ul {
44+
list-style: none;
45+
padding: 0;
46+
margin: 0;
47+
}
48+
49+
.left-side {
50+
width: 50%;
51+
float: left;
52+
display: inline-block;
53+
text-align: center;
54+
}
55+
56+
.right-side {
57+
width: 50%;
58+
float: left;
59+
display: inline-block;
60+
text-align: center;
61+
}
62+
63+
.color-0 {
64+
background-color: rgba(10, 204, 222, 0.7);
2565
}
2666

27-
.confirm-dialog button {
67+
.color-1 {
68+
background-color: rgba(10, 204, 222, 0.3);
69+
}
70+
/*CONFIRM DIALOG*/
71+
72+
.dialog button {
2873
border-radius: 0.5em;
2974
padding: 0.5em 1.5em;
3075
font-size: 24px;
@@ -33,7 +78,7 @@
3378
cursor: pointer;
3479
}
3580

36-
.confirm-dialog h2 {
81+
.dialog h2 {
3782
padding-top: 2em;
3883
}
3984

@@ -43,7 +88,7 @@
4388
margin: 1em 1em 0 0;
4489
}
4590

46-
.confirm-dialog button.cancel-button {
91+
.dialog button.cancel-button {
4792
border: 1px solid #aaa;
4893
color: #999;
4994
margin: 1em 1em 0 0;
@@ -53,7 +98,7 @@
5398
background-color: #08bbcc;
5499
}
55100

56-
.confirm-dialog button.cancel-button:hover {
101+
.dialog button.cancel-button:hover {
57102
background-color: #ccc;
58103
color: black;
59104
border: 1px solid black;

0 commit comments

Comments
 (0)