mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-02-16 02:30:51 +00:00
Add select vertex for default handler
This commit is contained in:
@@ -1059,6 +1059,9 @@ return res+"</datalist>";}
|
||||
BaseHandler.prototype.GetSelect2VertexMenu=function()
|
||||
{return"<span style=\"float:right\">"+
|
||||
this.GetSelectVertexMenu("Vertex1")+" → "+this.GetSelectVertexMenu("Vertex2")+"</span>";}
|
||||
BaseHandler.prototype.GetSelectOneVertexMenu=function()
|
||||
{return"<span style=\"float:right\">"+
|
||||
this.GetSelectVertexMenu("Vertex1")+"</span>";}
|
||||
BaseHandler.prototype.SelectFirstVertexMenu=function(vertex1Text,vertex)
|
||||
{}
|
||||
BaseHandler.prototype.UpdateFirstVertexMenu=function()
|
||||
@@ -1097,49 +1100,32 @@ g_DefaultWeightPreset+"';\" style=\"cursor: pointer\" class=\"defaultWeigth\">"+
|
||||
{var edgePreset=edgePresets[i];presetsStr+="<span onClick=\"document.getElementById('EdgeWeight').value='"+edgePreset+"'; document.getElementById('EdgeWeightSlider').value="+
|
||||
edgePreset+";\" style=\"cursor: pointer\" class=\"defaultWeigth\">"+edgePreset+"</span>";}
|
||||
document.getElementById("EdgesPresets").innerHTML=presetsStr;document.getElementById('EdgeLable').value=edgeObject.upText;$("#CheckSaveDefaultEdge").prop("checked",false);$("#defaultEdgeDialogBlock").hide();$("#addEdge").dialog({resizable:false,height:"auto",width:"auto",modal:true,title:g_editWeight,buttons:dialogButtons,dialogClass:'EdgeDialog',open:function(){$(handler).off('submit').on('submit',function(){return false;});}});}
|
||||
BaseHandler.prototype.GraphWaUpdated=function(){}
|
||||
doInclude([include("features/base_handler/index.js")])
|
||||
function DefaultHandler(app)
|
||||
{this.removeStack=true;BaseHandler.apply(this,arguments);this.message=g_textsSelectAndMove+" <span class=\"hidden-phone\">"+g_selectGroupText+"</span>"+" <span class=\"hidden-phone\">"+g_useContextMenuText+"</span>";this.selectedObjects=[];this.dragObject=null;this.selectedObject=null;this.prevPosition=null;this.groupingSelect=false;this.selectedLogRect=false;this.selectedLogCtrl=false;this.saveUndo=false;this.addContextMenu();}
|
||||
{this.removeStack=true;BaseHandler.apply(this,arguments);this.message=this.GetDefaultText();this.selectedObjects=[];this.dragObject=null;this.selectedObject=null;this.prevPosition=null;this.groupingSelect=false;this.selectedLogRect=false;this.selectedLogCtrl=false;this.saveUndo=false;this.addContextMenu();}
|
||||
DefaultHandler.prototype=Object.create(BaseHandler.prototype);DefaultHandler.prototype.pressed=false;DefaultHandler.prototype.curveValue=0.1;DefaultHandler.prototype.GetSelectedVertex=function()
|
||||
{return(this.selectedObject instanceof BaseVertex)?this.selectedObject:null;}
|
||||
DefaultHandler.prototype.MouseMove=function(pos)
|
||||
{if(this.dragObject)
|
||||
{if(!this.saveUndo)
|
||||
{this.app.PushToStack("Move");this.saveUndo=true;}
|
||||
{if(this.dragObject){if(!this.saveUndo){this.app.PushToStack("Move");this.saveUndo=true;}
|
||||
this.dragObject.position.x=pos.x;this.dragObject.position.y=pos.y;this.needRedraw=true;}
|
||||
else if(this.selectedObjects.length>0&&this.pressed&&!this.groupingSelect)
|
||||
{if(!this.saveUndo)
|
||||
{this.app.PushToStack("Move");this.saveUndo=true;}
|
||||
var offset=(new Point(pos.x,pos.y)).subtract(this.prevPosition);for(var i=0;i<this.selectedObjects.length;i++)
|
||||
{var object=this.selectedObjects[i];if(object instanceof BaseVertex)
|
||||
{object.position=object.position.add(offset);}}
|
||||
else if(this.selectedObjects.length>0&&this.pressed&&!this.groupingSelect){if(!this.saveUndo){this.app.PushToStack("Move");this.saveUndo=true;}
|
||||
var offset=(new Point(pos.x,pos.y)).subtract(this.prevPosition);for(var i=0;i<this.selectedObjects.length;i++){var object=this.selectedObjects[i];if(object instanceof BaseVertex){object.position=object.position.add(offset);}}
|
||||
this.prevPosition=pos;this.needRedraw=true;}
|
||||
else if(this.pressed)
|
||||
{if(this.groupingSelect)
|
||||
{var newPos=new Point(pos.x,pos.y);this.app.SetSelectionRect(new Rect(newPos.min(this.prevPosition),newPos.max(this.prevPosition)));this.SelectObjectInRect(this.app.GetSelectionRect());this.needRedraw=true;if(!this.selectedLogRect)
|
||||
{userAction("GroupSelected.SelectRect");this.selectedLogRect=true;}}
|
||||
else
|
||||
{this.app.onCanvasMove((new Point(pos.x,pos.y)).subtract(this.prevPosition).multiply(this.app.canvasScale));this.needRedraw=true;}}}
|
||||
else if(this.pressed){if(this.groupingSelect){var newPos=new Point(pos.x,pos.y);this.app.SetSelectionRect(new Rect(newPos.min(this.prevPosition),newPos.max(this.prevPosition)));this.SelectObjectInRect(this.app.GetSelectionRect());this.needRedraw=true;if(!this.selectedLogRect){userAction("GroupSelected.SelectRect");this.selectedLogRect=true;}}
|
||||
else{this.app.onCanvasMove((new Point(pos.x,pos.y)).subtract(this.prevPosition).multiply(this.app.canvasScale));this.needRedraw=true;}}}
|
||||
DefaultHandler.prototype.MouseDown=function(pos)
|
||||
{this.dragObject=null;var selectedObject=this.GetSelectedObject(pos);var severalSelect=g_ctrlPressed;if(selectedObject==null||(!severalSelect&&!this.selectedObjects.includes(selectedObject)))
|
||||
{this.selectedObject=null;this.selectedObjects=[];this.groupingSelect=g_ctrlPressed;}
|
||||
if((severalSelect||this.selectedObjects.includes(selectedObject))&&(this.selectedObjects.length>0||this.selectedObject!=null)&&selectedObject!=null)
|
||||
{if(this.selectedObjects.length==0)
|
||||
{this.selectedObjects.push(this.selectedObject);this.selectedObject=null;this.selectedObjects.push(selectedObject);}
|
||||
else if(!this.selectedObjects.includes(selectedObject))
|
||||
{this.selectedObjects.push(selectedObject);}
|
||||
else if(severalSelect&&this.selectedObjects.includes(selectedObject))
|
||||
{var index=this.selectedObjects.indexOf(selectedObject);this.selectedObjects.splice(index,1);}
|
||||
if(!this.selectedLogCtrl)
|
||||
{userAction("GroupSelected.SelectCtrl");this.selectedLogCtrl=true;}}
|
||||
{this.dragObject=null;var selectedObject=this.GetSelectedObject(pos);var severalSelect=g_ctrlPressed;if(selectedObject==null||(!severalSelect&&!this.selectedObjects.includes(selectedObject))){this.selectedObject=null;this.selectedObjects=[];this.groupingSelect=g_ctrlPressed;}
|
||||
if((severalSelect||this.selectedObjects.includes(selectedObject))&&(this.selectedObjects.length>0||this.selectedObject!=null)&&selectedObject!=null){if(this.selectedObjects.length==0){this.selectedObjects.push(this.selectedObject);this.selectedObject=null;this.selectedObjects.push(selectedObject);}
|
||||
else if(!this.selectedObjects.includes(selectedObject)){this.selectedObjects.push(selectedObject);}
|
||||
else if(severalSelect&&this.selectedObjects.includes(selectedObject)){var index=this.selectedObjects.indexOf(selectedObject);this.selectedObjects.splice(index,1);}
|
||||
if(!this.selectedLogCtrl){userAction("GroupSelected.SelectCtrl");this.selectedLogCtrl=true;}}
|
||||
else
|
||||
{if(selectedObject!=null)
|
||||
{this.selectedObject=selectedObject;}
|
||||
if((selectedObject instanceof BaseVertex)&&selectedObject!=null)
|
||||
{this.dragObject=selectedObject;this.message=g_moveCursorForMoving;}}
|
||||
{if(selectedObject!=null){this.selectedObject=selectedObject;}
|
||||
if((selectedObject instanceof BaseVertex)&&selectedObject!=null){this.dragObject=selectedObject;this.message=g_moveCursorForMoving;}}
|
||||
this.needRedraw=true;this.pressed=true;this.prevPosition=pos;this.app.canvas.style.cursor="move";}
|
||||
DefaultHandler.prototype.MouseUp=function(pos)
|
||||
{this.saveUndo=false;this.message=g_textsSelectAndMove+" <span class=\"hidden-phone\">"+g_selectGroupText+"</span>"+" <span class=\"hidden-phone\">"+g_useContextMenuText+"</span>";this.dragObject=null;this.pressed=false;this.app.canvas.style.cursor="auto";this.app.SetSelectionRect(null);this.groupingSelect=false;if(this.selectedObject!=null&&(this.selectedObject instanceof BaseVertex))
|
||||
{this.saveUndo=false;this.message=this.GetDefaultText();this.dragObject=null;this.pressed=false;this.app.canvas.style.cursor="auto";this.app.SetSelectionRect(null);this.groupingSelect=false;if(this.selectedObject!=null&&(this.selectedObject instanceof BaseVertex))
|
||||
{this.message=g_textsSelectAndMove
|
||||
+"<div style=\"float:right;position: relative;\">"
|
||||
+"<button type=\"button\" class=\"btn btn-outline-secondary dropdown-toggle btn-sm menu-text white-btn\" data-bs-toggle=\"dropdown\" aria-expanded=\"false\">"
|
||||
@@ -1213,6 +1199,16 @@ this.selectedObjects.push(vertices[i]);}
|
||||
var edges=this.app.graph.edges;for(var i=0;i<edges.length;i++)
|
||||
{var edge=edges[i];if(rect.isIn(edge.vertex1.position)&&rect.isIn(edge.vertex2.position)&&!this.selectedObjects.includes(edge))
|
||||
this.selectedObjects.push(edge);}}
|
||||
DefaultHandler.prototype.GetDefaultText=function()
|
||||
{return g_textsSelectAndMove+" <span class=\"hidden-phone\">"+g_selectGroupText+"</span>"+" <span class=\"hidden-phone\">"+g_useContextMenuText+"</span>"+
|
||||
this.GetSelectOneVertexMenu();}
|
||||
DefaultHandler.prototype.SelectFirstVertexMenu=function(vertex1Text,vertex)
|
||||
{this.selectedObject=vertex;this.MouseUp(new Point(0,0));}
|
||||
DefaultHandler.prototype.UpdateFirstVertexMenu=function(vertex1Text)
|
||||
{if(this.selectedObject)
|
||||
{vertex1Text.value=this.selectedObject.mainText;}}
|
||||
BaseHandler.prototype.GraphWasUpdated=function()
|
||||
{this.MouseUp(new Point(0,0));}
|
||||
doInclude([include("features/base_handler/index.js")])
|
||||
function AddGraphHandler(app)
|
||||
{this.removeStack=true;BaseHandler.apply(this,arguments);this.message=g_clickToAddVertex;this.addContextMenu();}
|
||||
@@ -1776,7 +1772,9 @@ Application.prototype.LoadGraphFromString=function(str)
|
||||
{var graph=new Graph();var userSettings={};graph.LoadFromXML(str,userSettings);if(userSettings.hasOwnProperty("data")&&userSettings["data"].length>0)
|
||||
this.LoadUserSettings(userSettings["data"]);this.SetDefaultTransformations();this.graph=graph;if(this.graph.isNeedReposition())
|
||||
{this.graph.VerticesReposition(new Point(this.GetRealWidth(),this.GetRealHeight()),this.graph.vertices);}
|
||||
this.AutoAdjustViewport();this.updateMessage();this.redrawGraph();}
|
||||
this.AutoAdjustViewport();if(this.handler!=null)
|
||||
{this.handler.GraphWasUpdated();this.handler.RestRedraw();}
|
||||
this.updateMessage();this.redrawGraph();}
|
||||
Application.prototype.LoadNewGraphFromString=function(str)
|
||||
{this.LoadGraphFromString(str);this.lastGraphName="";}
|
||||
Application.prototype.LoadGraphFromDisk=function(graphName)
|
||||
@@ -1841,7 +1839,9 @@ Application.prototype.PushToStack=function(actionName)
|
||||
Application.prototype.Undo=function()
|
||||
{let data=this.undoStack.Undo();if(data==null)
|
||||
return;this.graph=new Graph();var userSettings={};this.graph.LoadFromXML(data,userSettings);if(userSettings.hasOwnProperty("data")&&userSettings["data"].length>0)
|
||||
this.LoadUserSettings(userSettings["data"]);this.redrawGraph();if(this.undoStack.IsUndoStackEmpty())
|
||||
this.LoadUserSettings(userSettings["data"]);if(this.handler!=null)
|
||||
{this.handler.GraphWasUpdated();this.handler.RestRedraw();}
|
||||
this.redrawGraph();if(this.undoStack.IsUndoStackEmpty())
|
||||
document.getElementById('GraphUndo').style.display='none';}
|
||||
Application.prototype.SaveUserSettings=function()
|
||||
{return"{"+this.style.Save()+"}";}
|
||||
|
||||
Reference in New Issue
Block a user