void EndAndStartCtrlConnection(Guid nodeId, int portIndex, PortType portType) { if (portType == PortType.Output) { return; // Only handle ctrl connections if selected port is an input port } if (firstStartPort == null || activeStartPorts == null || activeStartPorts.Count() <= 0) { return; } var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } PortModel portModel = node.InPorts[portIndex]; var models = GetConnectorsToAddAndDelete(portModel, activeStartPorts[0]); WorkspaceModel.RecordModelsForUndo(models, CurrentWorkspace.UndoRecorder); activeStartPorts = new PortModel[] { firstStartPort }; }
void CancelConnections() { CurrentWorkspace.DeleteSavedModels(); activeStartPorts = null; firstStartPort = null; return; }
/// <summary> /// Update which windows are associated to the current virtual desktop. /// </summary> public void UpdateWindowAssociations() { ThrowExceptionIfDisposed(); // The desktop needs to be visible in order to update window associations. if (!CurrentWorkspace.IsVisible) { return; } // Update window associations for the currently open desktop. CurrentWorkspace.AddWindows(GetNewWindows()); CurrentWorkspace.RemoveWindows(CurrentWorkspace.WindowSnapshots.Where(w => !IsValidWindow(w)).ToList()); CurrentWorkspace.WindowSnapshots.ForEach(w => w.Update()); // Remove destroyed windows from places where they are cached. var destroyedWindows = _invalidWindows.Where(w => w.IsDestroyed()).ToList(); foreach (var w in destroyedWindows) { lock ( _invalidWindows ) { _invalidWindows.Remove(w); } } }
void EndShiftReconnections(Guid nodeId, int portIndex, PortType portType) { if (portType == PortType.Input) { return; //only handle multiple connections when the port selected is an output port } if (activeStartPorts == null || activeStartPorts.Count() <= 0) { return; } var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } PortModel selectedPort = node.OutPorts[portIndex]; var firstModel = GetConnectorsToAddAndDelete(selectedPort, activeStartPorts[0]); for (int i = 1; i < activeStartPorts.Count(); i++) { var models = GetConnectorsToAddAndDelete(selectedPort, activeStartPorts[i]); foreach (var m in models) { firstModel.Add(m.Key, m.Value); } } WorkspaceModel.RecordModelsForUndo(firstModel, CurrentWorkspace.UndoRecorder); activeStartPorts = null; return; }
void SelectModelImpl(SelectModelCommand command) { // Empty ModelGuid means clear selection. if (command.ModelGuid == Guid.Empty) { DynamoSelection.Instance.ClearSelection(); return; } foreach (var guid in command.ModelGuids) { ModelBase model = CurrentWorkspace.GetModelInternal(guid); if (!model.IsSelected) { if (!command.Modifiers.HasFlag(ModifierKeys.Shift) && command.ModelGuids.Count() == 1) { DynamoSelection.Instance.ClearSelection(); } DynamoSelection.Instance.Selection.AddUnique(model); } else { if (command.Modifiers.HasFlag(ModifierKeys.Shift)) { DynamoSelection.Instance.Selection.Remove(model); } } } }
void SelectModelImpl(SelectModelCommand command) { // Empty ModelGuid means clear selection. if (command.ModelGuid == Guid.Empty) { DynamoSelection.Instance.ClearSelection(); return; } ModelBase model = CurrentWorkspace.GetModelInternal(command.ModelGuid); if (false == model.IsSelected) { if (!command.Modifiers.HasFlag(ModifierKeys.Shift)) { DynamoSelection.Instance.ClearSelection(); } if (!DynamoSelection.Instance.Selection.Contains(model)) { DynamoSelection.Instance.Selection.Add(model); } } else { if (command.Modifiers.HasFlag(ModifierKeys.Shift)) { DynamoSelection.Instance.Selection.Remove(model); } } }
/// <summary> /// Handle the file configuration change notification /// </summary> /// <param name="newSettings"></param> /// <param name="oldSettings"></param> /// <param name="eventContext"></param> public async Task HandleDidChangeConfigurationNotification( SqlToolsSettings newSettings, SqlToolsSettings oldSettings, EventContext eventContext) { bool oldEnableIntelliSense = oldSettings.SqlTools.IntelliSense.EnableIntellisense; bool?oldEnableDiagnostics = oldSettings.SqlTools.IntelliSense.EnableErrorChecking; // update the current settings to reflect any changes CurrentSettings.Update(newSettings); // if script analysis settings have changed we need to clear the current diagnostic markers if (oldEnableIntelliSense != newSettings.SqlTools.IntelliSense.EnableIntellisense || oldEnableDiagnostics != newSettings.SqlTools.IntelliSense.EnableErrorChecking) { // if the user just turned off diagnostics then send an event to clear the error markers if (!newSettings.IsDiagnositicsEnabled) { ScriptFileMarker[] emptyAnalysisDiagnostics = new ScriptFileMarker[0]; foreach (var scriptFile in WorkspaceService <SqlToolsSettings> .Instance.Workspace.GetOpenedFiles()) { await DiagnosticsHelper.PublishScriptDiagnostics(scriptFile, emptyAnalysisDiagnostics, eventContext); } } // otherwise rerun diagnostic analysis on all opened SQL files else { await this.RunScriptDiagnostics(CurrentWorkspace.GetOpenedFiles(), eventContext); } } }
void BeginConnection(Guid nodeId, int portIndex, PortType portType) { bool isInPort = portType == PortType.Input; var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } PortModel portModel = isInPort ? node.InPorts[portIndex] : node.OutPorts[portIndex]; // Test if port already has a connection, if so grab it and begin connecting // to somewhere else (we don't allow the grabbing of the start connector). if (portModel.Connectors.Count > 0 && portModel.Connectors[0].Start != portModel) { activeStartPort = portModel.Connectors[0].Start; // Disconnect the connector model from its start and end ports // and remove it from the connectors collection. This will also // remove the view model. ConnectorModel connector = portModel.Connectors[0]; if (CurrentWorkspace.Connectors.Contains(connector)) { var models = new List <ModelBase> { connector }; CurrentWorkspace.RecordAndDeleteModels(models); connector.Delete(); } } else { activeStartPort = portModel; } }
private void BeginDuplicateConnection(Guid nodeId, int portIndex, PortType portType) { // If the port clicked is an output port, begin connection as per normal if (portType == PortType.Output) { BeginConnection(nodeId, portIndex, portType); return; } // Otherwise, if the port is an input port, check if the port already has a connection. // If it does, duplicate the existing connection. var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } var portModel = node.InPorts[portIndex]; if (portModel.Connectors.Count == 0) { // If the port doesn't have any existing connections, begin connection as per normal BeginConnection(nodeId, portIndex, portType); return; } // Duplicate the existing connection activeStartPorts = new PortModel[] { portModel.Connectors[0].Start }; firstStartPort = portModel.Connectors[0].Start; }
void SendModelEventImpl(ModelEventCommand command) { foreach (var guid in command.ModelGuids) { CurrentWorkspace.SendModelEvent(guid, command.EventName, command.Value); } }
void EndConnection(Guid nodeId, int portIndex, PortType portType) { // Check if the node from which the connector starts is valid and has not been deleted if (activeStartPorts == null || activeStartPorts.Count() <= 0 || activeStartPorts[0].Owner == null) { return; } var startNode = CurrentWorkspace.GetModelInternal(activeStartPorts[0].Owner.GUID); if (startNode == null) { return; } var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } bool isInPort = portType == PortType.Input; PortModel portModel = isInPort ? node.InPorts[portIndex] : node.OutPorts[portIndex]; var models = GetConnectorsToAddAndDelete(portModel, activeStartPorts[0]); WorkspaceModel.RecordModelsForUndo(models, CurrentWorkspace.UndoRecorder); activeStartPorts = null; firstStartPort = null; }
/// <summary> /// Paste all windows on the clipboard on the currently open desktop. /// </summary> public void PasteWindows() { ThrowExceptionIfDisposed(); UpdateWindowAssociations(); // There might be newly added windows of which the z-order isn't known yet, so update associations first. CurrentWorkspace.AddWindows(WindowClipboard.ToList()); }
private void CreateAnnotationImpl(CreateAnnotationCommand command) { AnnotationModel annotationModel = currentWorkspace.AddAnnotation( command.AnnotationText, command.AnnotationDescriptionText, command.ModelGuid); CurrentWorkspace.RecordCreatedModel(annotationModel); }
private void ConvertNodesToCodeImpl(ConvertNodesToCodeCommand command) { var libServices = new LibraryCustomizationServices(pathManager); var namingProvider = new NamingProvider(EngineController.LibraryServices.LibraryManagementCore, libServices); CurrentWorkspace.ConvertNodesToCodeInternal(EngineController, namingProvider); CurrentWorkspace.HasUnsavedChanges = true; }
void CreateNodeImpl(CreateNodeCommand command) { var node = command.Node; if (node == null) { if (command.NodeXml != null) { // command was deserialized, we must create the node directly node = NodeFactory.CreateNodeFromXml(command.NodeXml, SaveContext.File); } else { // legacy command, hold on to your butts var name = command.Name; var nodeId = command.NodeId; Guid customNodeId; // To be used in the event it's a custom node we're making. // Then, we have to figure out what kind of node to make, based on the name. // First, we check for a DSFunction by looking for a FunctionDescriptor var functionItem = LibraryServices.GetFunctionDescriptor(name); if (functionItem != null) { node = (functionItem.IsVarArg) ? new DSVarArgFunction(functionItem) as NodeModel : new DSFunction(functionItem); node.GUID = nodeId; } // If that didn't work, let's try using the NodeFactory else if (NodeFactory.CreateNodeFromTypeName(name, out node)) { node.GUID = nodeId; } // And if that didn't work, then it must be a custom node. else if (Guid.TryParse(name, out customNodeId)) { node = CustomNodeManager.CreateCustomNodeInstance(customNodeId); node.GUID = nodeId; } // We're out of ideas, log an error. else { Logger.LogError("Could not create instance of node with name: " + name); return; } } } node.X = command.X; node.Y = command.Y; AddNodeToCurrentWorkspace(node, centered: command.DefaultPosition); CurrentWorkspace.RecordCreatedModel(node); }
private void ConvertNodesToCodeImpl(ConvertNodesToCodeCommand command) { CurrentWorkspace.ConvertNodesToCodeInternal( command.NodeId, EngineController, DebugSettings.VerboseLogging); CurrentWorkspace.HasUnsavedChanges = true; }
//Add private void Button_Click_3(object sender, RoutedEventArgs e) { if (!string.IsNullOrWhiteSpace(NewFileNameText.Text)) { if (SelectedFileType == NewFileType.Window) { if (!NewFileNameText.Text.Contains(".xaml")) { NewFileNameText.Text += ".xaml"; } File.WriteAllText(Path.Combine(CurrentSolution.SourceDirectory, NewFileNameText.Text), Constants.CreateNewXamlWindowFile(CurrentSolution, NewFileNameText.Text)); File.WriteAllText(Path.Combine(CurrentSolution.SourceDirectory, NewFileNameText.Text + ".cs"), Constants.CreateNewXamlCsFile(CurrentSolution, NewFileNameText.Text)); CurrentSolution.AddProjectFile(NewFileNameText.Text, false); CurrentSolution.AddProjectFile(NewFileNameText.Text + ".cs"); CurrentWorkspace.AddProjectFile(NewFileNameText.Text); CurrentWorkspace.AddProjectFile(NewFileNameText.Text + ".cs"); CurrentSolution.Save(); this.Close(); } else if (SelectedFileType == NewFileType.UserControl) { if (!NewFileNameText.Text.Contains(".xaml")) { NewFileNameText.Text += ".xaml"; } File.WriteAllText(Path.Combine(CurrentSolution.SourceDirectory, NewFileNameText.Text), Constants.CreateNewXamlControlFile(CurrentSolution, NewFileNameText.Text)); File.WriteAllText(Path.Combine(CurrentSolution.SourceDirectory, NewFileNameText.Text + ".cs"), Constants.CreateNewXamlCsFile(CurrentSolution, NewFileNameText.Text, true)); CurrentSolution.AddProjectFile(NewFileNameText.Text, false); CurrentSolution.AddProjectFile(NewFileNameText.Text + ".cs"); CurrentWorkspace.AddProjectFile(NewFileNameText.Text); CurrentWorkspace.AddProjectFile(NewFileNameText.Text + ".cs"); CurrentSolution.Save(); this.Close(); } else if (SelectedFileType == NewFileType.Class) { if (!NewFileNameText.Text.Contains(".cs")) { NewFileNameText.Text += ".cs"; } File.WriteAllText(Path.Combine(CurrentSolution.SourceDirectory, NewFileNameText.Text), Constants.CreateNewClass(CurrentSolution, NewFileNameText.Text)); CurrentSolution.AddProjectFile(NewFileNameText.Text); CurrentWorkspace.AddProjectFile(NewFileNameText.Text); CurrentSolution.Save(); this.Close(); } else { MessageBox.Show("You must select a new file type.", "Need User Input", MessageBoxButton.OK); } } else { MessageBox.Show("You must select a new file type.", "Need User Input", MessageBoxButton.OK); } }
public void SetActiveWorkspace(WorkspaceViewModel workspace) { if (CurrentWorkspace != null) { CurrentWorkspace.Dispose(); CurrentWorkspace.RequestClose -= workspace_RequestClose; } CurrentWorkspace = workspace; CurrentWorkspace.RequestClose += workspace_RequestClose; }
protected override void SwitchToWorkspaceInner(VirtualDesktop desktop) { UpdateWindowAssociations(); // Hide windows for current desktop and show those from the new desktop. // TODO: Refactor so that one can not forget to call 'SetHideBehavior'. CurrentWorkspace.SetHideBehavior(wi => _hideBehavior(new Window(wi), this).Select(w => w.WindowInfo).ToList()); CurrentWorkspace.Hide(); desktop.Show(); }
private void command_ExistingAnalysisSelected(object sender, OpenAnalysisArgs e) { // Load ... if (ExistingAnalysisSelected != null) { ExistingAnalysisSelected(sender, e); } CurrentWorkspace.AddAnalysis(e.AnalysisData); SaveWorkSpace(); }
void CreateNoteImpl(CreateNoteCommand command) { NoteModel noteModel = CurrentWorkspace.AddNote( command.DefaultPosition, command.X, command.Y, command.NoteText, command.NodeId); CurrentWorkspace.RecordCreatedModel(noteModel); }
void UndoRedoImpl(UndoRedoCommand command) { if (command.CmdOperation == UndoRedoCommand.Operation.Undo) { CurrentWorkspace.Undo(); } else if (command.CmdOperation == UndoRedoCommand.Operation.Redo) { CurrentWorkspace.Redo(); } }
void UngroupModelImpl(UngroupModelCommand command) { var modelsToUngroup = new List <ModelBase>(); if (command.ModelGuid != Guid.Empty) { modelsToUngroup.Add(CurrentWorkspace.GetModelInternal(command.ModelGuid)); } UngroupModel(modelsToUngroup); }
void EndConnection(Guid nodeId, int portIndex, PortType portType) { bool isInPort = portType == PortType.INPUT; NodeModel node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel; if (node == null) { return; } PortModel portModel = isInPort ? node.InPorts[portIndex] : node.OutPorts[portIndex]; ConnectorModel connectorToRemove = null; // Remove connector if one already exists if (portModel.Connectors.Count > 0 && portModel.PortType == PortType.INPUT) { connectorToRemove = portModel.Connectors[0]; CurrentWorkspace.Connectors.Remove(connectorToRemove); portModel.Disconnect(connectorToRemove); var startPort = connectorToRemove.Start; startPort.Disconnect(connectorToRemove); } // We could either connect from an input port to an output port, or // another way around (in which case we swap first and second ports). PortModel firstPort, second; if (portModel.PortType != PortType.INPUT) { firstPort = portModel; second = activeStartPort; } else { // Create the new connector model firstPort = activeStartPort; second = portModel; } ConnectorModel newConnectorModel = CurrentWorkspace.AddConnection(firstPort.Owner, second.Owner, firstPort.Index, second.Index, PortType.INPUT); // Record the creation of connector in the undo recorder. var models = new Dictionary <ModelBase, UndoRedoRecorder.UserAction>(); if (connectorToRemove != null) { models.Add(connectorToRemove, UndoRedoRecorder.UserAction.Deletion); } models.Add(newConnectorModel, UndoRedoRecorder.UserAction.Creation); CurrentWorkspace.RecordModelsForUndo(models); activeStartPort = null; }
void AddToGroupImpl(AddModelToGroupCommand command) { if (command.ModelGuid == Guid.Empty) { return; } var modelsToGroup = command.ModelGuids.Select(guid => CurrentWorkspace.GetModelInternal(guid)).ToList(); AddToGroup(modelsToGroup); }
void UngroupModelImpl(UngroupModelCommand command) { if (command.ModelGuid == Guid.Empty) { return; } var modelsToUngroup = command.ModelGuids.Select(guid => CurrentWorkspace.GetModelInternal(guid)).ToList(); UngroupModel(modelsToUngroup); }
void AddToGroupImpl(AddModelToGroupCommand command) { var modelsToUngroup = new List <ModelBase>(); if (command.ModelGuid != Guid.Empty) { modelsToUngroup.Add(CurrentWorkspace.GetModelInternal(command.ModelGuid)); } AddToGroup(modelsToUngroup); }
void CreateNodeImpl(CreateNodeCommand command) { NodeModel nodeModel = CurrentWorkspace.AddNode( command.NodeId, command.NodeName, command.X, command.Y, command.DefaultPosition, command.TransformCoordinates); CurrentWorkspace.RecordCreatedModel(nodeModel); }
void SwitchWorkspace(IWorkspace newWorkspace) { if (CurrentWorkspace != null) { CurrentWorkspace.Activate(false); } CurrentWorkspace = newWorkspace; CurrentWorkspace.Activate(true); EventManager.TriggerEvent(new EventOnWorkspaceSwitched(CurrentWorkspace)); }
/// <summary> /// This method assumes that there exists an undo-redo action group already /// that can be used to record creation and deletion of models. /// </summary> /// <param name="command"></param> private void CreateAndConnectNodeImplWithUndoGroup(CreateAndConnectNodeCommand command) { var newNode = CreateNodeFromNameOrType(command.ModelGuid, command.NewNodeName); if (newNode == null) { return; } newNode.X = command.X; newNode.Y = command.Y; var existingNode = CurrentWorkspace.GetModelInternal(command.ModelGuids.ElementAt(1)) as NodeModel; if (existingNode == null) { return; } AddNodeToCurrentWorkspace(newNode, false, command.AddNewNodeToSelection); CurrentWorkspace.UndoRecorder.RecordCreationForUndo(newNode); PortModel inPortModel, outPortModel; if (command.CreateAsDownstreamNode) { // Connect output port of Existing Node to input port of New node outPortModel = existingNode.OutPorts[command.OutputPortIndex]; inPortModel = newNode.InPorts[command.InputPortIndex]; } else { // Connect output port of New Node to input port of existing node outPortModel = newNode.OutPorts[command.OutputPortIndex]; inPortModel = existingNode.InPorts[command.InputPortIndex]; } var models = GetConnectorsToAddAndDelete(inPortModel, outPortModel); foreach (var modelPair in models) { switch (modelPair.Value) { case UndoRedoRecorder.UserAction.Creation: CurrentWorkspace.UndoRecorder.RecordCreationForUndo(modelPair.Key); break; case UndoRedoRecorder.UserAction.Deletion: CurrentWorkspace.UndoRecorder.RecordDeletionForUndo(modelPair.Key); break; } } }