Exemple #1
0
Fichier : panel.go Projet : kego/ke
func addNewFile(ctx context.Context, app *stores.App, all bool) {

	var types []*system.Type
	if all {
		rt := reflect.TypeOf((*system.ObjectInterface)(nil)).Elem()
		typesAll := system.GetAllTypesThatImplementReflectInterface(ctx, rt)

		// TODO: Work out a more elegant way of doing this!
		rule := reflect.TypeOf((*system.RuleInterface)(nil)).Elem()
		for _, t := range typesAll {
			if t.Id.Package == "kego.io/system" {
				// none of the system types should be added as a global
				continue
			}
			if t.Implements(ctx, rule) {
				// rules should never be added as a global
				continue
			}
			types = append(types, t)
		}

	} else {
		syscache := sysctx.FromContext(ctx)
		t, ok := syscache.GetType("kego.io/system", "type")
		if !ok {
			panic(kerr.New("NNFSJEXNKF", "Can't find system:type in sys ctx").Error())
		}
		types = []*system.Type{t.(*system.Type)}
	}

	app.Dispatch(&actions.OpenAddPopup{
		Types: types,
	})

}
Exemple #2
0
func nullEditor(ctx context.Context, n *node.Node, app *stores.App) *EditorView {
	add := func(e *vecty.Event) {
		types := n.Rule.PermittedTypes()
		if len(types) == 1 {
			// if only one type is compatible, don't show the
			// popup, just add it.
			app.Dispatch(&actions.Add{
				Undoer: &actions.Undoer{},
				Parent: n.Parent,
				Node:   n,
				Key:    n.Key,
				Type:   types[0],
			})
			return
		}
		app.Dispatch(&actions.OpenAddPopup{
			Parent: n.Parent,
			Node:   n,
			Types:  types,
		})
	}
	return NewEditorView(ctx, n).Icons(
		func() vecty.MarkupOrComponentOrHTML {
			return elem.Anchor(
				prop.Href("#"),
				event.Click(add).PreventDefault(),
				elem.Italic(
					prop.Class("editor-icon editor-icon-after glyphicon glyphicon-plus-sign"),
				),
			)
		},
	).Dropdown(
		func() vecty.MarkupOrComponentOrHTML {
			return elem.ListItem(
				elem.Anchor(
					prop.Href("#"),
					vecty.Text("Add"),
					event.Click(add).PreventDefault(),
				),
			)
		},
	)
}