Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Commit 08d1616

Browse files
authored
Merge pull request #202 from unisonweb/add-workspace-item-menu-items
WorkspaceItem: Add hash, namespace menu items
2 parents a10f587 + 2b8436f commit 08d1616

File tree

7 files changed

+164
-66
lines changed

7 files changed

+164
-66
lines changed

src/Definition/Info.elm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import List.Nonempty as NEL
1515

1616
type alias Info =
1717
{ name : String
18-
, namespace : Maybe String
18+
, namespace : Maybe FQN
1919
, otherNames : List FQN
2020
}
2121

@@ -33,7 +33,7 @@ makeInfo name_ allFqns =
3333
-- Helpers
3434

3535

36-
namespaceAndOtherNames : String -> NEL.Nonempty FQN -> ( Maybe String, List FQN )
36+
namespaceAndOtherNames : String -> NEL.Nonempty FQN -> ( Maybe FQN, List FQN )
3737
namespaceAndOtherNames suffixName fqns =
3838
let
3939
fqnWithin =
@@ -46,4 +46,4 @@ namespaceAndOtherNames suffixName fqns =
4646
|> NEL.toList
4747
|> ListE.filterNot (FQN.equals fqnWithin)
4848
in
49-
( FQN.namespaceOf suffixName fqnWithin, fqnsWithout )
49+
( FQN.namespace fqnWithin, fqnsWithout )

src/FullyQualifiedName.elm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module FullyQualifiedName exposing
1111
, isSuffixOf
1212
, isValidSegmentChar
1313
, isValidUrlSegmentChar
14+
, namespace
1415
, namespaceOf
1516
, segments
1617
, toString
@@ -21,6 +22,7 @@ module FullyQualifiedName exposing
2122
)
2223

2324
import Json.Decode as Decode
25+
import List.Extra as ListE
2426
import List.Nonempty as NEL
2527
import String.Extra as StringE
2628
import Url
@@ -144,6 +146,19 @@ unqualifiedName (FQN nameParts) =
144146
NEL.last nameParts
145147

146148

149+
namespace : FQN -> Maybe FQN
150+
namespace (FQN segments_) =
151+
case segments_ |> NEL.toList |> ListE.init of
152+
Nothing ->
153+
Nothing
154+
155+
Just [] ->
156+
Nothing
157+
158+
Just segments__ ->
159+
Just (fromList segments__)
160+
161+
147162
equals : FQN -> FQN -> Bool
148163
equals a b =
149164
toString a == toString b

src/UI/Icon.elm

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import Svg.Attributes as Attrs
1414
, r
1515
, rx
1616
, stroke
17+
, strokeLinecap
18+
, strokeLinejoin
1719
, strokeWidth
1820
, viewBox
1921
, width
@@ -232,17 +234,25 @@ chevronUp =
232234
folder : Icon msg
233235
folder =
234236
Icon
235-
"folder"
237+
"folder "
236238
[]
237-
[ path [ stroke "currentColor", d "M.5 3V2a.5.5 0 01.5-.5h4a.5.5 0 01.4.2l.9 1.2.4-.3-.4.3a1.5 1.5 0 001.2.6H13a.5.5 0 01.5.5v8a.5.5 0 01-.5.5H1a.5.5 0 01-.5-.5V3z" ] [] ]
239+
[ path [ fill "currentColor", fillRule "evenodd", d "M2 2C1.44772 2 1 2.44772 1 3V11.5C1 12.0523 1.44772 12.5 2 12.5H12C12.5523 12.5 13 12.0523 13 11.5V4.5C13 3.94772 12.5523 3.5 12 3.5H7.83333C7.61696 3.5 7.40643 3.42982 7.23333 3.3L5.76667 2.2C5.59357 2.07018 5.38304 2 5.16667 2H4.5H2Z" ] [] ]
240+
241+
242+
folderOutlined : Icon msg
243+
folderOutlined =
244+
Icon
245+
"folder-outlined"
246+
[]
247+
[ path [ fill "currentColor", fillRule "evenodd", d "M2 2C1.44772 2 1 2.44772 1 3V11.5C1 12.0523 1.44772 12.5 2 12.5H12C12.5523 12.5 13 12.0523 13 11.5V4.5C13 3.94772 12.5523 3.5 12 3.5H7.83333C7.61696 3.5 7.40643 3.42982 7.23333 3.3L5.76667 2.2C5.59357 2.07018 5.38304 2 5.16667 2H4.5H2ZM2.5 4.5C2.22386 4.5 2 4.72386 2 5V11C2 11.2761 2.22386 11.5 2.5 11.5H11.5C11.7761 11.5 12 11.2761 12 11V5C12 4.72386 11.7761 4.5 11.5 4.5H2.5Z" ] [] ]
238248

239249

240250
hash : Icon msg
241251
hash =
242252
Icon
243253
"hash"
244254
[]
245-
[ path [ fill "currentColor", d "M7.629 9.197L7.082 12h.978l.546-2.803h1.723v-.936H8.784l.472-2.42h1.586v-.95H9.44l.561-2.844h-.978l-.56 2.844H6.658l.56-2.844h-.977l-.56 2.844H3.732v.95h1.764l-.472 2.42H3.213v.936h1.634L4.3 12h.977l.547-2.803H7.63zm-1.627-.936l.472-2.42h1.804l-.471 2.42H6.002z" ] [] ]
255+
[ path [ fill "currentColor", d "M6.55414 9.62088C7.18994 9.62088 7.66431 10.2064 7.53237 10.8284L7.23223 12.2432C7.14954 12.633 7.44684 13 7.84532 13C8.14133 13 8.39698 12.7929 8.45841 12.5033L8.90178 10.4134C8.99979 9.95133 9.4077 9.62088 9.88001 9.62088H10.7634C11.0752 9.62088 11.328 9.36812 11.328 9.05632C11.328 8.74452 11.0752 8.49176 10.7634 8.49176H10.4215C9.84528 8.49176 9.41532 7.96113 9.53478 7.39741L9.75316 6.36686C9.8511 5.90474 10.2591 5.57418 10.7314 5.57418H11.4272C11.7435 5.57418 12 5.31772 12 5.00137C12 4.68502 11.7435 4.42857 11.4272 4.42857H11.1789C10.6561 4.42857 10.2664 3.94653 10.3759 3.43535L10.7355 1.75773C10.819 1.36775 10.5217 1 10.1229 1C9.82752 1 9.57227 1.20635 9.51037 1.49518L9.05112 3.63812C8.95231 4.09918 8.54485 4.42857 8.07332 4.42857H7.75314C7.11649 4.42857 6.64193 3.84154 6.77534 3.21902L7.08851 1.75773C7.17208 1.36775 6.8748 1 6.47596 1C6.18057 1 5.92531 1.20635 5.86341 1.49518L5.40417 3.63812C5.30536 4.09918 4.8979 4.42857 4.42637 4.42857H3.25381C2.93746 4.42857 2.681 4.68502 2.681 5.00137C2.681 5.31772 2.93746 5.57418 3.25381 5.57418H3.75871C4.39443 5.57418 4.86878 6.15958 4.73698 6.78149L4.54253 7.69907C4.4446 8.1612 4.03665 8.49176 3.56426 8.49176H2.56456C2.25276 8.49176 2 8.74452 2 9.05632C2 9.36812 2.25276 9.62088 2.56456 9.62088H2.95846C3.56785 9.62088 4.02252 10.1821 3.89605 10.7782L3.58528 12.2432C3.50258 12.633 3.79989 13 4.19837 13C4.49438 13 4.75003 12.7929 4.81146 12.5033L5.25482 10.4134C5.35284 9.95133 5.76075 9.62088 6.23305 9.62088H6.55414ZM6.89004 8.49176C6.25432 8.49176 5.77997 7.90635 5.91176 7.28445L6.10621 6.36686C6.20414 5.90474 6.6121 5.57418 7.08449 5.57418H7.40566C8.04138 5.57418 8.51573 6.15958 8.38394 6.78149L8.18949 7.69907C8.09156 8.1612 7.6836 8.49176 7.21121 8.49176H6.89004Z" ] [] ]
246256

247257

248258
plus : Icon msg
@@ -286,3 +296,22 @@ list =
286296
, rect [ Attrs.x "3", y "6.5", width "8", height "1", rx "0.5", fill "currentColor" ] []
287297
, rect [ Attrs.x "3", y "3.5", width "8", height "1", rx "0.5", fill "currentColor" ] []
288298
]
299+
300+
301+
tags : Icon msg
302+
tags =
303+
Icon "tags"
304+
[]
305+
[ path [ fill "currentColor", fillRule "evenodd", d "M0.5 2.5V6.33693C0.5 6.61411 0.615047 6.87886 0.817682 7.06798L6.32182 12.2052C6.73954 12.595 7.39844 12.5563 7.76752 12.1201L11.3047 7.93974C11.6499 7.53182 11.6134 6.9246 11.2218 6.561L6.05924 1.76721C5.87428 1.59545 5.6312 1.5 5.37879 1.5H1.5C0.947714 1.5 0.5 1.94772 0.5 2.5ZM3.13574 5.45362C3.86358 5.45362 4.45361 4.86359 4.45361 4.13575C4.45361 3.40791 3.86358 2.81788 3.13574 2.81788C2.4079 2.81788 1.81787 3.40791 1.81787 4.13575C1.81787 4.86359 2.4079 5.45362 3.13574 5.45362Z" ] []
306+
, path [ fill "transparent", stroke "currentColor", d "M9 2.5L13.2987 6.3688C13.6924 6.72318 13.7415 7.32313 13.4106 7.73679L10 12", strokeLinecap "round", strokeLinejoin "round" ] []
307+
]
308+
309+
310+
tagsOutlined : Icon msg
311+
tagsOutlined =
312+
Icon "tags-outlined"
313+
[]
314+
[ path [ fill "currentColor", fillRule "evenodd", d "M2 2.5C1.72386 2.5 1.5 2.72386 1.5 3V6.11965C1.5 6.25824 1.55752 6.39062 1.65884 6.48518L6.62037 11.1159C6.82923 11.3109 7.15868 11.2915 7.34322 11.0734L10.2329 7.65828C10.4055 7.45432 10.3872 7.15071 10.1915 6.96891L5.52267 2.6336C5.43019 2.54773 5.30865 2.5 5.18244 2.5H2ZM0.5 2.5V6.33693C0.5 6.61411 0.615047 6.87886 0.817682 7.06798L6.32182 12.2052C6.73954 12.595 7.39844 12.5563 7.76752 12.1201L11.3047 7.93974C11.6499 7.53181 11.6134 6.9246 11.2218 6.561L6.05924 1.76721C5.87428 1.59545 5.6312 1.5 5.37879 1.5H1.5C0.947714 1.5 0.5 1.94772 0.5 2.5Z" ] []
315+
, path [ fill "currentColor", fillRule "evenodd", d "M8.62836 2.16552C8.81309 1.96026 9.12923 1.94362 9.33449 2.12835L13.6332 5.99715C14.2238 6.52872 14.2974 7.42865 13.801 8.04914L10.3904 12.3123C10.2179 12.528 9.90329 12.5629 9.68766 12.3904C9.47203 12.2179 9.43707 11.9033 9.60957 11.6877L13.0201 7.42444C13.1856 7.21761 13.1611 6.91763 12.9642 6.74045L8.66552 2.87165C8.46027 2.68692 8.44363 2.37077 8.62836 2.16552Z" ] []
316+
, circle [ cx "4", cy "5", r "1.5", stroke "currentColor", fill "transparent" ] []
317+
]

src/Workspace/WorkspaceItem.elm

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import Definition.AbilityConstructor exposing (AbilityConstructor(..), AbilityCo
55
import Definition.Category as Category exposing (Category)
66
import Definition.DataConstructor exposing (DataConstructor(..), DataConstructorDetail, DataConstructorSource(..))
77
import Definition.Doc as Doc exposing (Doc(..), DocFoldToggles)
8-
import Definition.Info as Info
8+
import Definition.Info as Info exposing (Info)
99
import Definition.Reference as Reference exposing (Reference(..))
1010
import Definition.Source as Source
1111
import Definition.Term as Term exposing (Term(..), TermCategory, TermDetail, TermSignature(..), TermSource(..))
1212
import Definition.Type as Type exposing (Type(..), TypeCategory, TypeDetail, TypeSource(..))
1313
import FullyQualifiedName as FQN exposing (FQN)
14-
import Hash
14+
import Hash exposing (Hash)
1515
import HashQualified as HQ exposing (HashQualified(..))
16-
import Html exposing (Attribute, Html, a, div, h3, header, section, span, strong, text)
16+
import Html exposing (Attribute, Html, a, div, h3, header, label, section, span, strong, text)
1717
import Html.Attributes exposing (class, classList, id, title)
1818
import Html.Events exposing (onClick)
1919
import Http
@@ -22,7 +22,7 @@ import List.Nonempty as NEL
2222
import Maybe.Extra as MaybeE
2323
import String.Extra exposing (pluralize)
2424
import UI
25-
import UI.Icon as Icon
25+
import UI.Icon as Icon exposing (Icon)
2626
import UI.Tooltip as Tooltip
2727
import Util
2828
import Workspace.Zoom exposing (Zoom(..))
@@ -136,22 +136,18 @@ viewBuiltin item =
136136
UI.nothing
137137

138138

139-
{-| TODO: Some of this that isn't Workspace specific might be moved into Definition.Info
140-
-}
141-
viewNames :
142-
msg
143-
-> { a | name : String, namespace : Maybe String, otherNames : List FQN }
144-
-> Category
145-
-> Html msg
146-
viewNames onClick_ info category =
139+
viewMenuItem : Icon msg -> String -> Html msg
140+
viewMenuItem icon label_ =
141+
div [ class "menu-item" ] [ Icon.view icon, label [] [ text label_ ] ]
142+
143+
144+
viewMenuItems : Hash -> Info -> Html msg
145+
viewMenuItems hash_ info =
147146
let
148147
namespace =
149148
case info.namespace of
150149
Just ns ->
151-
div [ class "namespace" ]
152-
[ span [ class "separator in" ] [ text "in" ]
153-
, text ns
154-
]
150+
viewMenuItem Icon.folderOutlined (FQN.toString ns)
155151

156152
Nothing ->
157153
UI.nothing
@@ -166,21 +162,35 @@ viewNames onClick_ info category =
166162
div [] (List.map (\n -> div [] [ text (FQN.toString n) ]) info.otherNames)
167163

168164
otherNamesLabel =
169-
text (pluralize "other name..." "other names..." numOtherNames)
165+
pluralize "other name..." "other names..." numOtherNames
170166
in
171-
div []
172-
[ span [ class "separator" ] [ text "" ]
173-
, span [ class "other-names" ] [ Tooltip.tooltip otherNamesLabel otherNamesTooltipContent |> Tooltip.withArrow Tooltip.TopLeft |> Tooltip.view ]
174-
]
167+
Tooltip.tooltip (viewMenuItem Icon.tagsOutlined otherNamesLabel) otherNamesTooltipContent
168+
|> Tooltip.withArrow Tooltip.TopLeft
169+
|> Tooltip.view
175170

176171
else
177172
UI.nothing
173+
174+
formatHash h =
175+
h |> Hash.toString |> String.dropLeft 1 |> String.left 8
176+
177+
hash =
178+
Tooltip.tooltip (viewMenuItem Icon.hash (formatHash hash_)) (text (Hash.toString hash_))
179+
|> Tooltip.withArrow Tooltip.TopLeft
180+
|> Tooltip.view
178181
in
179-
div [ class "names", onClick onClick_ ]
180-
[ Icon.view Icon.caretRight
181-
, Icon.view (Category.icon category)
182-
, h3 [ class "name" ] [ text info.name ]
183-
, div [ class "info" ] [ namespace, otherNames ]
182+
div [ class "menu-items" ] [ hash, namespace, otherNames ]
183+
184+
185+
viewInfo : msg -> Hash -> Info -> Category -> Html msg
186+
viewInfo onClick_ hash info category =
187+
div [ class "info" ]
188+
[ a [ class "toggle-zoom", onClick onClick_ ]
189+
[ Icon.view Icon.caretRight
190+
, Icon.view (Category.icon category)
191+
, h3 [ class "name" ] [ text info.name ]
192+
]
193+
, viewMenuItems hash info
184194
]
185195

186196

@@ -267,44 +277,44 @@ viewItem closeMsg toOpenReferenceMsg toUpdateZoomMsg toggleFoldMsg ref data isFo
267277
|> Maybe.withDefault UI.nothing
268278
in
269279
case data.item of
270-
TermItem (Term _ category detail) ->
280+
TermItem (Term h category detail) ->
271281
viewClosableRow
272282
closeMsg
273283
ref
274284
attrs
275-
(viewNames docZoomMsg detail.info (Category.Term category))
285+
(viewInfo docZoomMsg h detail.info (Category.Term category))
276286
[ ( UI.nothing, viewDoc_ detail.doc )
277287
, ( UI.nothing, viewBuiltin data.item )
278288
, viewSource toOpenReferenceMsg data.item
279289
]
280290

281-
TypeItem (Type _ category detail) ->
291+
TypeItem (Type h category detail) ->
282292
viewClosableRow
283293
closeMsg
284294
ref
285295
attrs
286-
(viewNames docZoomMsg detail.info (Category.Type category))
296+
(viewInfo docZoomMsg h detail.info (Category.Type category))
287297
[ ( UI.nothing, viewDoc_ detail.doc )
288298
, ( UI.nothing, viewBuiltin data.item )
289299
, viewSource toOpenReferenceMsg data.item
290300
]
291301

292-
DataConstructorItem (DataConstructor _ detail) ->
302+
DataConstructorItem (DataConstructor h detail) ->
293303
viewClosableRow
294304
closeMsg
295305
ref
296306
attrs
297-
(viewNames docZoomMsg detail.info (Category.Type Type.DataType))
307+
(viewInfo docZoomMsg h detail.info (Category.Type Type.DataType))
298308
[ ( UI.nothing, viewBuiltin data.item )
299309
, viewSource toOpenReferenceMsg data.item
300310
]
301311

302-
AbilityConstructorItem (AbilityConstructor _ detail) ->
312+
AbilityConstructorItem (AbilityConstructor h detail) ->
303313
viewClosableRow
304314
closeMsg
305315
ref
306316
attrs
307-
(viewNames docZoomMsg detail.info (Category.Type Type.AbilityType))
317+
(viewInfo docZoomMsg h detail.info (Category.Type Type.AbilityType))
308318
[ ( UI.nothing, viewBuiltin data.item )
309319
, viewSource toOpenReferenceMsg data.item
310320
]

src/css/themes/unison/light.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
--color-workspace-item-link: var(--color-blue-1);
6666
--color-workspace-item-link-active: var(--color-pink-1);
6767
--color-workspace-item-link-hover: var(--color-pink-2);
68-
--color-workspace-item-subtle-fg: var(--color-gray-lighten-40);
68+
--color-workspace-item-subtle-fg: var(--color-gray-lighten-30);
6969
--color-workspace-item-subtle-fg-em: var(--color-gray-lighten-20);
7070
--color-workspace-item-subtle-bg: var(--color-gray-lighten-60);
7171
--color-workspace-item-em-bg: var(--color-gray-lighten-55);

0 commit comments

Comments
 (0)