Skip to content

Commit f88d0f5

Browse files
authored
Merge pull request #25 from unisonweb/settings-menu
Move settings from window menu into the app
2 parents bc4e591 + b69439b commit f88d0f5

File tree

10 files changed

+102
-29
lines changed

10 files changed

+102
-29
lines changed

elm-git.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"git-dependencies": {
33
"direct": {
4-
"https://github.com/unisonweb/ui-core": "6b84c5a4df3a1c5f48f12f1414af11974f5f8e0e"
4+
"https://github.com/unisonweb/ui-core": "b172cbdb17eba02f64edfef92a4e4e3d117ea636"
55
},
66
"indirect": {}
77
}

elm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"elm/parser": "1.1.0",
1818
"elm/regex": "1.0.0",
1919
"elm/svg": "1.0.1",
20+
"elm/time": "1.0.0",
2021
"elm/url": "1.0.0",
2122
"elm-community/html-extra": "3.4.0",
2223
"elm-community/json-extra": "4.3.0",
@@ -36,7 +37,6 @@
3637
"elm/bytes": "1.0.8",
3738
"elm/file": "1.0.5",
3839
"elm/random": "1.0.0",
39-
"elm/time": "1.0.0",
4040
"elm/virtual-dom": "1.0.3",
4141
"fredcy/elm-parseint": "2.0.1"
4242
}

src/Ucm/WelcomeScreen.elm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ view appContext model =
230230
|> Window.withTitlebarRight
231231
[ Button.iconThenLabel_ Link.docs Icon.graduationCap "Unison Docs"
232232
|> Button.small
233-
|> Button.outlined
233+
|> Button.subdued
234234
|> Button.view
235235
, Button.iconThenLabel_ Link.share Icon.browse "Find libraries on Unison Share"
236236
|> Button.small
237-
|> Button.outlined
237+
|> Button.subdued
238238
|> Button.view
239239
]
240240
|> Window.withoutTitlebarBorder

src/Ucm/WindowMenu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ async function init(appSettings: AppSettings.AppSettings): Promise<Menu> {
4444
action: async (_) => window.location.reload()
4545
}),
4646
await MenuItem.new({
47-
id: "clear-app-settings",
48-
text: "Clear App Settings",
47+
id: "reset-to-factory-settings",
48+
text: "Reset to factory settings",
4949
action: async (_) => {
5050
await AppSettings.clear();
5151
window.location.reload();

src/Ucm/WorkspaceScreen.elm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type alias Model =
3939
, switchBranch : SwitchBranch.Model
4040
, modal : WorkspaceScreenModal
4141
, sidebarVisible : Bool
42+
, settingsMenuVisible : Bool
4243
, keyboardShortcut : KeyboardShortcut.Model
4344
}
4445

@@ -64,6 +65,7 @@ init appContext workspaceContext =
6465
, switchBranch = SwitchBranch.init
6566
, modal = NoModal
6667
, sidebarVisible = True
68+
, settingsMenuVisible = False
6769
, keyboardShortcut = KeyboardShortcut.init appContext.operatingSystem
6870
}
6971
, Cmd.batch

src/Window.elm

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Window exposing (..)
1+
port module Window exposing (..)
22

33
import Browser
44
import Html
@@ -15,7 +15,12 @@ import Html
1515
import Html.Attributes exposing (attribute, class, classList, id)
1616
import SplitPane.SplitPane as SplitPane
1717
import UI
18+
import UI.ActionMenu as ActionMenu
19+
import UI.Button as Button
20+
import UI.Click as Click
21+
import UI.Icon as Icon
1822
import UI.Modal as Modal exposing (Modal)
23+
import Ucm.Link as Link
1924

2025

2126

@@ -24,6 +29,7 @@ import UI.Modal as Modal exposing (Modal)
2429

2530
type alias Model =
2631
{ splitPane : SplitPane.State
32+
, isSettingsMenuOpen : Bool
2733
}
2834

2935

@@ -32,6 +38,7 @@ init =
3238
{ splitPane =
3339
SplitPane.init SplitPane.Horizontal
3440
|> SplitPane.configureSplitter (SplitPane.px 256 Nothing)
41+
, isSettingsMenuOpen = False
3542
}
3643

3744

@@ -41,6 +48,10 @@ init =
4148

4249
type Msg
4350
= SplitPaneMsg SplitPane.Msg
51+
| ToggleSettingsMenu
52+
| ChangeTheme String
53+
| ReloadApp
54+
| ResetToFactorySettings
4455

4556

4657
update : Msg -> Model -> ( Model, Cmd Msg )
@@ -56,6 +67,31 @@ update msg model =
5667
, Cmd.none
5768
)
5869

70+
ToggleSettingsMenu ->
71+
( { model | isSettingsMenuOpen = not model.isSettingsMenuOpen }, Cmd.none )
72+
73+
ChangeTheme theme ->
74+
( model, saveTheme theme )
75+
76+
ReloadApp ->
77+
( model, reloadApp () )
78+
79+
ResetToFactorySettings ->
80+
( model, clearSettings () )
81+
82+
83+
84+
-- PORTS
85+
86+
87+
port saveTheme : String -> Cmd msg
88+
89+
90+
port reloadApp : () -> Cmd msg
91+
92+
93+
port clearSettings : () -> Cmd msg
94+
5995

6096

6197
-- SUBSCRIPTIONS
@@ -395,8 +431,8 @@ windowControls =
395431
-- VIEW
396432

397433

398-
viewWindowTitlebar : String -> WindowTitlebar msg -> Html msg
399-
viewWindowTitlebar id_ titlebar_ =
434+
viewWindowTitlebar : Html msg -> String -> WindowTitlebar msg -> Html msg
435+
viewWindowTitlebar settingsMenu id_ titlebar_ =
400436
let
401437
{ left, center, right, transparent, border } =
402438
case titlebar_ of
@@ -411,15 +447,15 @@ viewWindowTitlebar id_ titlebar_ =
411447
WindowTitlebar cfg ->
412448
{ left = cfg.left
413449
, center = cfg.center
414-
, right = cfg.right
450+
, right = cfg.right ++ [ settingsMenu ]
415451
, transparent = False
416452
, border = cfg.border
417453
}
418454

419455
TextWindowTitlebar cfg ->
420456
{ left = []
421457
, center = [ text cfg.label ]
422-
, right = []
458+
, right = [ settingsMenu ]
423459
, transparent = False
424460
, border = cfg.border
425461
}
@@ -460,6 +496,27 @@ viewWindowFooter id_ footer_ =
460496
view : (Msg -> msg) -> Model -> Window msg -> Browser.Document msg
461497
view toMsg model win =
462498
let
499+
settingsMenu =
500+
ActionMenu.items
501+
(ActionMenu.titleItem "Theme")
502+
[ ActionMenu.optionItem Icon.computer "System" (Click.onClick (ChangeTheme "system"))
503+
, ActionMenu.optionItem Icon.sun "Unison Light" (Click.onClick (ChangeTheme "unison-light"))
504+
, ActionMenu.optionItem Icon.moon "Unison Dark" (Click.onClick (ChangeTheme "unison-dark"))
505+
, ActionMenu.dividerItem
506+
, ActionMenu.titleItem "Resources"
507+
, ActionMenu.optionItem Icon.graduationCap "Unison Docs" Link.docs
508+
, ActionMenu.optionItem Icon.browse "Unison Share" Link.share
509+
, ActionMenu.dividerItem
510+
, ActionMenu.titleItem "Debug"
511+
, ActionMenu.optionItem Icon.refresh "Reload" (Click.onClick ReloadApp)
512+
, ActionMenu.optionItem Icon.x "Reset to factory settings" (Click.onClick ResetToFactorySettings)
513+
]
514+
|> ActionMenu.fromIconButton ToggleSettingsMenu Icon.cog
515+
|> ActionMenu.withButtonColor Button.Subdued
516+
|> ActionMenu.shouldBeOpen model.isSettingsMenuOpen
517+
|> ActionMenu.view
518+
|> Html.map toMsg
519+
463520
mainContent =
464521
case win.leftSidebar of
465522
NoWindowSidebar ->
@@ -509,9 +566,9 @@ view toMsg model win =
509566
Nothing ->
510567
UI.nothing
511568
in
512-
{ title = "UCM"
569+
{ title = "Unison Codebase Manager"
513570
, body =
514-
[ viewWindowTitlebar win.id win.titlebar
571+
[ viewWindowTitlebar settingsMenu win.id win.titlebar
515572
, mainContent
516573
, viewWindowFooter win.id win.footer
517574
, modal

src/css/unison-dark.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ body.unison-dark {
206206
--u-shadow: var(--color-gray-darken-30-20pct);
207207
}
208208

209+
.unison-dark .button.subdued {
210+
--color-button-default-text: var(--u-color_text);
211+
}
212+
209213
/* TODO: these component overwrites shouldn't be needed... */
210214
.unison-dark .definition-doc {
211215
--color-doc-bg: transparent;
@@ -224,3 +228,6 @@ body.unison-dark {
224228
--c-color_anchored-overlay_sheet_border: var(--u-color_border);
225229
}
226230

231+
.unison-dark .action-menu {
232+
--c-color_action-menu_sheet_border: var(--u-color_border);
233+
}

src/css/unison-light.css

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,28 @@ body.unison-light {
206206
--u-shadow: var(--color-gray-darken-30-20pct);
207207
}
208208

209+
.unison-light .button.subdued {
210+
--color-button-default-text: var(--u-color_text);
211+
}
212+
209213
/* TODO: these component overwrites shouldn't be needed... */
210-
.unison-dark .definition-doc {
214+
.unison-light .definition-doc {
211215
--color-doc-bg: transparent;
212216
--color-doc-focus-bg: transparent;
213217
}
214218

215-
.unison-dark .definition-doc .copyable-source .copy-on-click {
219+
.unison-light .definition-doc .copyable-source .copy-on-click {
216220
background: transparent;
217221
}
218222

219-
.unison-dark .tooltip {
223+
.unison-light .tooltip {
220224
--color-tooltip-border: var(--u-color_border);
221225
}
222226

223-
.unison-dark .anchored-overlay {
227+
.unison-light .anchored-overlay {
224228
--c-color_anchored-overlay_sheet_border: var(--u-color_border);
225229
}
226230

231+
.unison-light .action-menu {
232+
--c-color_action-menu_sheet_border: var(--u-color_border);
233+
}

src/css/window.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ body:has(.window-footer) {
5555
padding-left: calc(calc(4rem - 1px) + 0.75rem);
5656
}
5757

58-
.windows .window-titlebar,
59-
.linux .window-titlebar {
60-
/* 5rem is the distance of the left edge of the traffic control to the very
61-
* right edge of the window. The 1px accounts for the border), and 0.75 is the
62-
* spacing between the traffic controls and other titlebar controls. */
63-
padding-right: calc(calc(5rem - 1px) + 0.75rem);
64-
}
65-
6658
.window-titlebar.window-titlebar_transparent {
6759
border: 0;
6860
background: transparent;

src/main.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ try {
2929

3030
// -- AppSettings -----------------------------------------------------------
3131
const appSettings = await AppSettings.init();
32+
const operatingSystem = detectOs(window.navigator);
3233

3334
// -- WindowMenu ------------------------------------------------------------
34-
const menu = await WindowMenu.init(appSettings);
35-
WindowMenu.mount(menu);
35+
if (operatingSystem && operatingSystem === "macOS") {
36+
const menu = await WindowMenu.init(appSettings);
37+
WindowMenu.mount(menu);
38+
}
3639

3740
// -- Elm -------------------------------------------------------------------
3841
const flags = {
39-
operatingSystem: detectOs(window.navigator),
42+
operatingSystem: operatingSystem,
4043
basePath: "",
4144
apiUrl: "http://127.0.0.1:5858/codebase/api",
4245
workspaceContext: appSettings.workspaceContexts[0],
@@ -54,9 +57,14 @@ try {
5457
app.ports.saveTheme?.subscribe(async (theme: Theme.Theme) => {
5558
appSettings.theme = theme
5659
AppSettings.save(appSettings);
60+
Theme.mount(theme);
5761
});
5862

59-
app.ports.clearSettings?.subscribe(AppSettings.clear);
63+
app.ports.reloadApp?.subscribe((_: unknown) => window.location.reload());
64+
app.ports.clearSettings?.subscribe((_: unknown) => {
65+
AppSettings.clear();
66+
window.location.reload();
67+
});
6068
}
6169

6270
// -- CSS env classes -------------------------------------------------------

0 commit comments

Comments
 (0)