11import std / [jsffi, jsconsole]
22import .. / common / ct_event
3- import types
3+ import types, lib
44import communication, dap
55import event_helpers
66
77# backend(dap) <-> middleware <-> view (self-contained, can be separate: 0, 1 or more components);
88
99when not defined (ctInExtension):
10+ import utils
11+
1012 proc dapInitializationHandler () =
1113 data.dapApi.sendCtRequest (DapConfigurationDone , js{})
1214 data.dapApi.sendCtRequest (DapLaunch , js{
@@ -19,6 +21,23 @@ when not defined(ctInExtension):
1921 inc data.status.operationCount
2022 viewsApi.emit (InternalStatusUpdate , data.status)
2123
24+ proc addToScratchpadHandler * (viewsApi: MediatorWithSubscribers , value: ValueWithExpression ) =
25+ # opens again or re-focuses scratchpad panel if needed
26+ let openNew = data.ui.componentMapping[Content .Scratchpad ].isNil or
27+ data.ui.componentMapping[Content .Scratchpad ].len == 0 or
28+ data.ui.componentMapping[Content .Scratchpad ].toJs[0 ].isUndefined or
29+ data.ui.componentMapping[Content .Scratchpad ][0 ].layoutItem.isNil
30+ if openNew:
31+ data.openLayoutTab (Content .Scratchpad )
32+
33+ if not data.ui.componentMapping[Content .Scratchpad ][0 ].layoutItem.parent.isNil:
34+ data.ui.componentMapping[Content .Scratchpad ][0 ].
35+ layoutItem.parent.setActiveContentItem (
36+ data.ui.componentMapping[Content .Scratchpad ][0 ].layoutItem)
37+ # if there is no parent, we assume it's a visible panel
38+ # with only tab scratchpad
39+ viewsApi.emit (InternalAddToScratchpad , value)
40+
2241proc setupMiddlewareApis * (dapApi: DapApi , viewsApi: MediatorWithSubscribers ) {.exportc .}=
2342 var lastCompleteMove: MoveState = nil
2443
@@ -75,7 +94,6 @@ proc setupMiddlewareApis*(dapApi: DapApi, viewsApi: MediatorWithSubscribers) {.e
7594 # if not dapApi.completeMoveFunction.isNil:
7695 # dapApi.completeMoveFunction(dapApi.editor, value, dapApi)
7796 # )
78- viewsApi.subscribe (InternalAddToScratchpad , proc (kind: CtEventKind , value: ValueWithExpression , sub: Subscriber ) = viewsApi.emit (InternalAddToScratchpad , value))
7997 viewsApi.subscribe (InternalAddToScratchpadFromExpression , proc (kind: CtEventKind , value: cstring , sub: Subscriber ) = viewsApi.emit (InternalAddToScratchpadFromExpression , value))
8098
8199 when not defined (ctInExtension):
@@ -84,6 +102,15 @@ proc setupMiddlewareApis*(dapApi: DapApi, viewsApi: MediatorWithSubscribers) {.e
84102 newOperationHandler (viewsApi, value)
85103 )
86104
105+ viewsApi.subscribe (InternalAddToScratchpad , proc (kind: CtEventKind , value: ValueWithExpression , sub: Subscriber ) =
106+ addToScratchpadHandler (viewsApi, value))
107+ else :
108+ # TODO : also in extension: opening again/focusing scratchpad and
109+ # sending to it, maybe using a handler that we pass to setupMiddlewareApis ?
110+ # or a global function?
111+ viewsApi.subscribe (InternalAddToScratchpad , proc (kind: CtEventKind , value: ValueWithExpression , sub: Subscriber ) = viewsApi.emit (InternalAddToScratchpad , value))
112+
113+
87114 viewsApi.subscribe (CtNotification , proc (kind: CtEventKind , value: Notification , sub: Subscriber ) = viewsApi.emit (CtNotification , value))
88115 viewsApi.subscribe (DapStepIn , proc (kind: CtEventKind , value: DapStepArguments , sub: Subscriber ) = dapApi.sendCtRequest (kind, value.toJs))
89116 viewsApi.subscribe (DapStepOut , proc (kind: CtEventKind , value: DapStepArguments , sub: Subscriber ) = dapApi.sendCtRequest (kind, value.toJs))
0 commit comments