theodore-norvell / PLAAY

Senior Design Project PLAAY (Programming Language for Adults And Youth)
2 stars 0 forks source link

Context menu during editing. #24

Open theodore-norvell opened 7 years ago

theodore-norvell commented 7 years ago

On the edit screen, a left click on a node or drop zone should allow one to apply a number of edits. For example, a left click on a drop zone should allow one to insert a new template. A left click on a node should allow one to replace it with a template. A left click on a variable node should allow one to rename the variable.

cem1kilic commented 7 years ago

What exactly is a template?

theodore-norvell commented 7 years ago

This issue is badly named. It should be right-clicks, not left-clicks. Will rename.

Templates are defined on the Trello board as Template: A template represents a fragment of tree that can be inserted. There is more on the Trello board under editing requirements. Basically a Template is a sequence of 1 or more trees (pnodes) together (optionally) with an indication of a location in the template where nodes can be inserted. For example a template for an if-expression might consist of a sequence of one node [ if( PH() seq() seq() ) ] together with an "engulfing spot" of (0, 1, 0), i.e. position 0 under the second node of the first node in the sequence. The template also optionally indicates a set of nodes to be the new selection. We can picture this as [ if( !PH()$ seq( ^ ) seq() ) ]. The ^ here represents the engulfing spot and $ and ! indicate the new selection

The idea is that if a template is applied to an empty location, then the tree is simply inserted there. For example suppose the current selection is

seq(  var[a]  !$  var[b]  var[c] )

(The ! and $ indicate the anchor and focus). Then applying the example template to this selection gives a new selection of

seq(  var[a]  if( !PH()$  seq( )   seq() )  var[b]  var[c] )

But suppose we apply the template to a nonempty selection, say

 seq(  var[a]  !var[b]  var[c]$ )

Then applying the template can mean one of three things. We would pick the first one that is valid. The three choice are

Engulf all nodes in the selection

 seq(  var[a]  if( !PH()$  seq(  var[b]  var[c] )   seq() ) )

Engulf just the first

 seq(  var[a]  if( !PH()$  seq(  var[b]  )   seq() ) )

Engulf none

 seq(  var[a]  if( !PH()$  seq( )   seq() ) )

Note that the first example where there were no selected nodes is just a special case of engulfing all the selected nodes.

Currently there is no class to represent templates.

If we has a class to represent templates then it could have a method that returns an Edit object for applying the template. This method can be written to create three Edit objects and combine them with the alt function from the edit module.

From a UI point of view, templates can be applied in a number of ways.

The third of these is what this issue is about.

theodore-norvell commented 6 years ago

A lot has changed since this issue was created. I do think a context menu would be useful, but right click does not work with touch events. Instead, I'd like a context menu to pop up depending on the current selection. For example, a type menu when a type or notype node is selected, an expression menu when an expression or noexp node is selected or there is an empty selection at a drop-zone that allows expressions. Etc.