Skip to content

Commit

Permalink
Duplicate metadata into workspace options and pass to reflection requ…
Browse files Browse the repository at this point in the history
…ests (#2)
  • Loading branch information
rogchap authored Sep 7, 2020
1 parent 090d517 commit f752a4b
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ clean-moc:
find ./internal -name 'moc*' -delete

clean:
rm rcc.cpp rcc.qrc rcc_cgo_darwin_darwin_amd64.go
rm rcc.cpp rcc.qrc rcc_cgo_darwin_darwin_amd64.go rcc_cgo_linux_linux_amd64.go

define make_icns
mkdir _temp.iconset
Expand Down
13 changes: 12 additions & 1 deletion internal/app/input_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,19 @@ func (c *inputController) with(store *db.Store, workspace *db.Workspace) *inputC

func (c *inputController) processReflectionAPI(conn *grpc.ClientConn) error {

meta := make(map[string]string)
for _, kv := range c.MetadataListModel().List() {
if kv.Key() == "" {
continue
}
meta[kv.Key()] = kv.Val()
}
if c.workspace != nil {
c.workspace.Metadata = meta
}

var err error
c.pbSource, err = pb.GetSourceFromReflectionAPI(conn)
c.pbSource, err = pb.GetSourceFromReflectionAPI(conn, meta)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/app/output_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func marshalKnownFieldText(b *indentBuffer, fd *desc.FieldDescriptor, v interfac
if group {
return b.WriteByte('}')
}
_, err := b.WriteString("<span class='bkt'>&gt;</span>")
_, err = b.WriteString("<span class='bkt'>&gt;</span>")
return err
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/app/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ func (c *workspaceController) connect(addr string) error {
ctx, c.cancelCtxFunc = context.WithCancel(context.Background())

go func() {
defer func() {
// TODO(rogchap) Should be a better way than swallowing this panic?
recover()
}()

for {
if c.grpcConn == nil {
c.SetConnState(connectivity.Shutdown.String())
Expand Down
1 change: 1 addition & 0 deletions internal/model/keyval_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/therecipe/qt/core"
)

// The roles for the KeyvalList
const (
KeyvalKeyRole = int(core.Qt__UserRole) + 1<<iota
KeyvalValRole
Expand Down
6 changes: 4 additions & 2 deletions internal/pb/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/jhump/protoreflect/desc/protoparse"
"github.com/jhump/protoreflect/grpcreflect"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
)

Expand Down Expand Up @@ -91,13 +92,14 @@ func GetSourceFromProtoFiles(importPaths, protoPaths []string) (Source, error) {
}

// GetSourceFromReflectionAPI uses the Reflection API to parse the RPC stubs available to a server
func GetSourceFromReflectionAPI(conn *grpc.ClientConn) (Source, error) {
func GetSourceFromReflectionAPI(conn *grpc.ClientConn, meta map[string]string) (Source, error) {
if conn == nil {
return nil, errors.New("pb: no connection available")
}

stub := rpb.NewServerReflectionClient(conn)
ctx := context.WithValue(context.Background(), "ctxInternal", struct{}{})
ctx := metadata.NewOutgoingContext(context.Background(), metadata.New(meta))
ctx = context.WithValue(ctx, "ctxInternal", struct{}{})
client := grpcreflect.NewClient(ctx, stub)
defer client.Reset()

Expand Down
39 changes: 18 additions & 21 deletions qml/controls/CrossButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,31 @@ AbstractButton {
id: control

property color color
property alias rotation: canvas.rotation

focusPolicy: Qt.NoFocus

height: 16
width: 16

Canvas {
id: canvas
x: 2
y: 2
width: 12
height: 12
contextType: "2d"

onPaint: {
context.reset()
context.lineWidth = 2
context.strokeStyle = color
context.moveTo(0, height / 2);
context.lineTo(width, height/2);
context.moveTo(width / 2, 0)
context.lineTo(width / 2, height)
context.stroke();
height: 17
width: 17

Label {
id: label

anchors.top: control.top
anchors.left: control.left
anchors.topMargin: -6
anchors.leftMargin: 1


color: control.color
text: "×"
font {
weight: Font.DemiBold
pointSize: 22
}
}

background: Rectangle {
rotation: control.rotation - 90
color: control.down ? Style.bgColor2 : Style.bgColor
}
}
19 changes: 3 additions & 16 deletions qml/controls/Modal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,9 @@ Popup {
font.pointSize: 16
}

AbstractButton {
text: "×"
font {
weight: Font.DemiBold
pointSize: 22
}
anchors {
right: parent.right
top: parent.top
topMargin: -5
}

contentItem: Label {
text: parent.text
}

CrossButton{
anchors.right: parent.right
color: Style.bgColor3
onClicked: control.close()
}
}
Expand Down
1 change: 1 addition & 0 deletions qml/views/DelegateRepeatedField.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Item {
CrossButton {
text: qsTr("add")
color: Style.greenColor
rotation: 45
onClicked: {
valueListModel.addValue()
}
Expand Down
5 changes: 0 additions & 5 deletions qml/views/MessageFields.qml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ ListView {

CrossButton {
color: Style.bgColor3
rotation: 45
onClicked: valueListModel.remove(index)
}
}
Expand All @@ -103,7 +102,6 @@ ListView {

CrossButton {
color: Style.bgColor3
rotation: 45
onClicked: valueListModel.remove(index)
anchors.verticalCenter: parent.verticalCenter
}
Expand All @@ -130,7 +128,6 @@ ListView {

CrossButton {
color: Style.bgColor3
rotation: 45
onClicked: valueListModel.remove(index)
}

Expand All @@ -156,7 +153,6 @@ ListView {

CrossButton {
color: Style.bgColor3
rotation: 45
onClicked: valueListModel.remove(index)
}

Expand All @@ -181,7 +177,6 @@ ListView {

CrossButton {
color: Style.bgColor3
rotation: 45
onClicked: valueListModel.remove(index)
}

Expand Down
1 change: 0 additions & 1 deletion qml/views/Metadata.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Pane {
anchors.verticalCenter: parent.verticalCenter

color: Style.bgColor3
rotation: 45
onClicked: root.model.removeAt(index)
visible: lv.count > 1
}
Expand Down
6 changes: 6 additions & 0 deletions qml/views/WorkspaceOptions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Modal {
TabButton {
text: qsTr("TLS")
}

TabButton {
text: qsTr("Metadata")
}
}

Rectangle {
Expand All @@ -48,6 +52,8 @@ Modal {

WorkspaceOptionsTls {}

Metadata {}

}

Rectangle {
Expand Down

0 comments on commit f752a4b

Please sign in to comment.