Exemplo n.º 1
0
        /// <summary>
        /// Command handler to add file to SVN
        /// </summary>
        public static void Add(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var debugHost = host.GetSharedExportedValue <IDebugHost>();

            try
            {
                var filePath   = ((Envoy)parameter.Parameter).GetFilePath();
                var svnManager = host.GetSharedExportedValue <SvnManagerPlugin>();
                var success    = svnManager.Add(filePath);
                if (success)
                {
                    var envoy       = ((Envoy)parameter.Parameter);
                    var projectItem = envoy.GetProjectItemViewModel(site);
                    if (null != projectItem)
                    {
                        projectItem.RefreshIcon();
                    }
                    debugHost.LogMessage(new DebugMessage("Viewpoint.Svn", DebugMessageSeverity.Information, $"Add {filePath}"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                debugHost.LogMessage(new DebugMessage("Viewpoint.Svn", DebugMessageSeverity.Error, $"Failed to Add {e.Message}"));
                const string caption = "Error SVN";
                var          result  = MessageBox.Show(e.Message, caption,
                                                       MessageBoxButtons.OK,
                                                       MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Highlights a collection of elements with a slight delay between the start of the highlight animation.
        /// </summary>
        /// <param name="site">The current document edit site</param>
        /// <param name="elements">The elements to highlight</param>
        /// <returns>The task to await on</returns>
        private static async Task SlowlyHighlightElementsAsync(DocumentEditSite site, IEnumerable <Element> elements)
        {
            foreach (var element in elements)
            {
                var findOptions = new FindViewModelOptions();
                findOptions.Highlight = true;
                await site.FindViewModelForModelElementAsync(element, findOptions);

                await Task.Delay(100);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// This is the command enabler for the multiple by 10 command.  Command enablers are called when the state of the editor changes
 /// The enable can update the state of the command based on the current state of the editor (what is selected, is something running, ...)
 /// </summary>
 public static bool CanMultiplyBy10(ICommandParameter parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
 {
     // This command is always enabled
     return(true);
 }
        private static void LaunchChannelBrowser(ICommandParameter parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
        {
            _uiSdfBrowsePopup = new ChannelPopup
            {
                ShowWaveforms = false,
                Name          = "UI_SDFBrowsePopup",
                IsOpen        = false,
                Placement     = Placement.BelowCenter
            };
            // Register the property changed callback for the popup window
            WeakEventManager <ChannelPopup, PropertyChangedEventArgs> .AddHandler(_uiSdfBrowsePopup, "PropertyChanged", ChannelNamePropertyChanged);

            // Show Popup window with Channels.
            _currentSelection = selection.ToList();
            _uiSdfBrowsePopup.PlacementTarget = (UIElement)parameter.AssociatedVisual;
            _uiSdfBrowsePopup.Channel         = _settingFrequency ? ((PulseWidthModulationControlModel)_currentSelection.First().Model).FrequencyChannel : ((PulseWidthModulationControlModel)_currentSelection.First().Model).DutyCycleChannel;
            _uiSdfBrowsePopup.ShowSdfBrowser(host, true, false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Command handler which shows the data type of the selected terminal
        /// </summary>
        public static void OnShowTerminalType(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var viewModel = parameter.QueryService <NodeTerminalViewModel>().FirstOrDefault();

            if (viewModel != null)
            {
                NIMessageBox.Show("The terminal type is: " + viewModel.DataType.ToString());
            }
        }
        private static void SelectChannels(ICommandParameter parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
        {
            IEnumerable <string> frequencyChannels = selection.Select(item => item.Model)
                                                     .OfType <PulseWidthModulationControlModel>()
                                                     .Select(model => model.FrequencyChannel)
                                                     .Where(channel => !string.IsNullOrEmpty(channel))
                                                     .ToList();
            IEnumerable <string> dutyCycleChannels = selection.Select(item => item.Model)
                                                     .OfType <PulseWidthModulationControlModel>()
                                                     .Select(model => model.DutyCycleChannel)
                                                     .Where(channel => !string.IsNullOrEmpty(channel))
                                                     .ToList();
            var systemDefinitionPalette = SystemDefinitionPaletteControl.Activate(site);

            systemDefinitionPalette.SelectNodes(dutyCycleChannels.Concat(frequencyChannels));
        }
Exemplo n.º 7
0
 public static bool CanHistory(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
 {
     return(true);
 }
        public static void OnOpenInNotepad(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var text     = (site.EditControl.Document.Envoy.ReferenceDefinition as TextDocumentDefinition).Text;
            var fileName = Path.GetTempFileName();

            File.WriteAllText(fileName, text);
            Process.Start("Notepad.exe", fileName);
        }
Exemplo n.º 9
0
 private static bool HandleCanAddLockTunnel(ICommandParameter parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
 {
     return(selection.OfType <StructureViewModel>().Any());
 }
Exemplo n.º 10
0
        /// <summary>
        /// This command merges the last created merge script onto the active editor.  It better match the formats since we are
        /// not checking.
        /// </summary>
        public static void OnMergeCapturedMergeScript(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            if (string.IsNullOrEmpty(_lastMergeScript))
            {
                return;
            }
            // The root element is the root of what ever the active editor is editing.  This would be things like the BlockDiagram
            // or FrontPanel of a VI.
            var rootElement = site.ActiveDocumentEditor?.EditorInfo?.RootElement;

            if (rootElement != null)
            {
                // Always perform modifications from within a transaction
                // Here we are creating a user transaction which means it is undoable
                using (var transaction = rootElement.TransactionManager.BeginTransaction("Merge", TransactionPurpose.User))
                {
                    var mergeScript = MergeScript.FromString(_lastMergeScript, host);
                    var resolver    = new MergeScriptResolver(mergeScript, host);
                    resolver.Merge(rootElement);
                    // Don't forget to commit the transaction
                    transaction.Commit();
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// This command adds our example "tag" attached property on all of the selected elements
        /// </summary>
        public static void OnTagSelection(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var selectedModels = site.ActiveSelection.Select(vm => vm.Model).OfType <Element>();

            if (!selectedModels.Any())
            {
                return;
            }
            // When setting a tag we are modifying the model so we must set the tags in a transaction.  Since all of the models are in
            // the same file we can set all of the tags in a single transaction.
            using (var transaction = selectedModels.First().TransactionManager.BeginTransaction("Tag Selection", TransactionPurpose.User))
            {
                foreach (var element in selectedModels)
                {
                    ExampleAttachedProperties.SetTag(element, "Tagged");
                }
                transaction.Commit();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Command handler which adds a new gtype to the project that is derived from the gtype currently being edited
        /// </summary>
        public static void OnAddNewDerviedType(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            // Check to see that the user is currently editing a type and if not do nothing.
            // The edit site provides access to the state of the editor.  Here we are checking to see of the active document
            // is a gtype by looking at the definition that is being edited.  The definition is the model of the object being
            // edited
            var gType = (GTypeDefinition)site?.ActiveDocument?.Envoy?.ReferenceDefinition;

            if (gType == null)
            {
                return;
            }
            // Get the project being edited
            var project = host.GetSharedExportedValue <IDocumentManager>().ActiveProject;
            // Setup the create info for a gtype.
            var createInfo = EnvoyCreateInfo.CreateForNew(GTypeDefinition.ModelDefinitionTypeString, new QualifiedName("New Derived Type.gtype"));
            // The LockedSourceFile is an object which holds a document in memory
            ILockedSourceFile lockSourceFile;

            // Always perform modifications from within a transaction
            // Here we are creating a user transaction which means it is undoable
            using (var transaction = project.TransactionManager.BeginTransaction("Add A Type", TransactionPurpose.User))
            {
                lockSourceFile = project.CreateNewFile(null, createInfo);
                transaction.Commit();
            }
            // Here we are setting the base type based on the type that is currently being edited.
            using (var transaction = lockSourceFile.Envoy.ReferenceDefinition.TransactionManager.BeginTransaction("Make Type A Class", TransactionPurpose.NonUser))
            {
                ((GTypeDefinition)lockSourceFile.Envoy.ReferenceDefinition).BaseTypeQualifiedName = gType.Name;
                transaction.Commit();
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// This command create a merge script string from the selection of the active editor.  Merge scripts are what are used
        /// for the clipboard, palette entries, and drag drop.  Merge scripts are basically mini versions of our persisted source
        /// file format.  Merge scripts are also useful for scripting use cases where merge scripts can be pased onto a diagram,
        /// wired together and modified.  Using merge scripts as templates is easier than writing a bunch on scripting code by hand.
        /// </summary>
        public static void OnCreateMergeScriptFromSelection(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var selection = site.ActiveSelection.OfType <IElementViewModel>();

            if (!selection.Any())
            {
                return;
            }
            // Create an Element selection is which a selection model for the selected view models
            var elementSelection = SelectionToolViewModel.CreateElementSelection(selection, true);

            // Get the text from the merge script
            _lastMergeScript = elementSelection.CopyMergeScript(host, true);
            Clipboard.SetText(_lastMergeScript);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Command handler which adds a new gtype to the project
        /// </summary>
        public static void OnAddNewType(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var project    = host.GetSharedExportedValue <IDocumentManager>().ActiveProject;
            var createInfo = EnvoyCreateInfo.CreateForNew(GTypeDefinition.ModelDefinitionTypeString, new QualifiedName("New Type.gtype"));
            ILockedSourceFile lockSourceFile;

            using (var transaction = project.TransactionManager.BeginTransaction("Add A Type", TransactionPurpose.User))
            {
                lockSourceFile = project.CreateNewFile(null, createInfo);
                lockSourceFile.Envoy.UpdateStoragePath("Classes\\New Member VI.gvi");
                transaction.Commit();
            }
            // To create a class we need to set the base type to whatever we want.  The default base type for a class is GObject
            // We don't point to the base directly and instead we set the QualifiedName of the base class we want.  The linker will then
            // find the base type by name and hook everything up based on the project configuration.
            using (var transaction = lockSourceFile.Envoy.ReferenceDefinition.TransactionManager.BeginTransaction("Make Type A Class", TransactionPurpose.NonUser))
            {
                ((GTypeDefinition)lockSourceFile.Envoy.ReferenceDefinition).BaseTypeQualifiedName = TargetCommonTypes.GObjectQualifiedName;
                transaction.Commit();
            }
            lockSourceFile?.Envoy?.Edit();

            // After editing dispose our lock in the file
            lockSourceFile?.Dispose();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Command handler which adds a new member VI to the gtype that is currently being edited
        /// </summary>
        public static void OnAddNewMemberVI(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            // Check to see that the user is currently editing a type and if not do nothing.
            var gTypeEnvoy = site?.ActiveDocument?.Envoy;
            var gType      = (GTypeDefinition)gTypeEnvoy?.ReferenceDefinition;

            if (gType == null)
            {
                return;
            }

            var               project     = host.GetSharedExportedValue <IDocumentManager>().ActiveProject;
            var               createInfo  = EnvoyCreateInfo.CreateForNew(VirtualInstrument.VIModelDefinitionType, "New Member VI.gvi");
            Envoy             createdItem = null;
            ILockedSourceFile createdFile = null;

            // Always perform modifications from within a transaction
            // Here we are creating a user transaction which means it is undoable
            using (var transaction = gType.TransactionManager.BeginTransaction("Add A VI", TransactionPurpose.User))
            {
                createdFile = project.CreateNewFile(gType.Scope, createInfo);
                createdFile.Envoy.UpdateStoragePath("Members\\New Member VI.gvi");
                createdItem = createdFile.Envoy;
                transaction.Commit();
            }

            // Lets add a terminal to the member data
            // First we query for the merge script provider from our gtype.  Merge scripts are snippets of code that can be
            // merged into diagrams / panels / ...
            // The gtype will provide a merge script that can be used to add data item (control / terminal) to a VI and
            // many other things
            string mergeScriptText = string.Empty;
            var    dataProviders   = gTypeEnvoy.QueryService <IProvideMergeScriptData>();

            foreach (var dataProvider in dataProviders)
            {
                foreach (var script in dataProvider.MergeScriptData)
                {
                    if (script.ClipboardDataFormat == VIDiagramControl.ClipboardDataFormat)
                    {
                        // Found the merge script for a VI diagram, we are done
                        mergeScriptText = script.MergeText;
                        break;
                    }
                }
            }
            // Now merge the script onto the diagram of the VI we just created
            if (!string.IsNullOrEmpty(mergeScriptText))
            {
                var vi = (VirtualInstrument)createdItem.ReferenceDefinition;
                // Always perform modifications from within a transaction
                // We are making this transaction a non user so that it cannot be undone it is just the initial state of the VI
                using (var transaction = vi.TransactionManager.BeginTransaction("Add A VI", TransactionPurpose.NonUser))
                {
                    var mergeScript = MergeScript.FromString(mergeScriptText, host);
                    var resolver    = new MergeScriptResolver(mergeScript, host);
                    resolver.Merge(vi.BlockDiagram);
                    // Don't forget to commit the transaction or it will cancel.
                    transaction.Commit();
                }
            }
            // Now edit the memeber VI that was just created, and this time let's edit starting on the diagram
            EditDocumentInfo editInfo = new EditDocumentInfo();

            editInfo.EditorType = typeof(VIDiagramControl);
            createdItem?.Edit(editInfo);

            // After editing dispose our lock in the file
            createdFile?.Dispose();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Command handler which adds a new VI to the project (under the default target)
        /// </summary>
        public static void OnAddNewVI(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var               project     = host.GetSharedExportedValue <IDocumentManager>().ActiveProject;
            var               createInfo  = EnvoyCreateInfo.CreateForNew(VirtualInstrument.VIModelDefinitionType, new QualifiedName("New VI.gvi"));
            Envoy             createdItem = null;
            ILockedSourceFile createdFile = null;

            // Always perform modifications from within a transaction
            // Here we are creating a user transaction which means it is undoable
            using (var transaction = project.TransactionManager.BeginTransaction("Add A VI", TransactionPurpose.User))
            {
                createdFile = project.CreateNewFile(null, createInfo);
                createdItem = createdFile?.Envoy;
                transaction.Commit();
            }
            // edit the newly created VI
            createdItem?.Edit();

            // After editing dispose our lock in the file
            createdFile?.Dispose();
        }
Exemplo n.º 17
0
        /// <summary>
        /// This is the command handler that will add the code to multiple the output of the random number primitive by 10
        /// This is called when the user presses the Multiply By 10 button
        /// </summary>
        /// <param name="parameter">The command parameter associated with instance of the command</param>
        /// <param name="selection">The current selection</param>
        /// <param name="host">The Composition host for the session</param>
        /// <param name="site">The document edit site which is managing the edit session</param>
        public static void OnMultipleBy10(ICommandParameter parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
        {
            // The selected item will be the random number node since we only add this command for random numbers
            var node = selection.First().Model as Node;

            if (node == null)
            {
                return;
            }

            // Start a transaction and add content to multiply the output by 10
            using (var transaction = node.TransactionManager.BeginTransaction("Multiple By 10", TransactionPurpose.User))
            {
                // Create a multiple node, position it nicely to the right ot the random number, and add it to the same diagram
                var multiply = Multiply.Create(ElementCreateInfo.ForNew);
                multiply.TopLeft = new SMPoint(node.Bounds.Right + StockDiagramGeometries.StandardNodeWidth, node.Top + (2 * StockDiagramGeometries.GridSize));
                node.Diagram.AddNode(multiply);

                // Wire the random number output to the first input on the multiple node
                node.Diagram.WireWithin((NodeTerminal)node.OutputTerminals.First(), (NodeTerminal)multiply.InputTerminals.First());

                // Create a Double Numeric Constant with an initial value of 10.0
                var literalBuilder = LiteralBuilder.GetLiteralBuilder(host);
                var context        = new CreateLiteralContext(PFTypes.Double, 10.0);
                var literal        = literalBuilder.CreateLiteral(context);

                // Position the constant nicely and add it to the diagram
                literal.TopLeft = new SMPoint(node.Left + StockDiagramGeometries.TinyNodeWidth, node.Bounds.Bottom + (2 * StockDiagramGeometries.GridSize));
                node.Diagram.AddNode(literal);

                // Wire the constant to the multiply node
                node.Diagram.WireWithin(literal.OutputTerminal, (NodeTerminal)multiply.InputTerminals.ElementAt(1));

                // Commit the transaction to finish the operation
                transaction.Commit();
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// This command finds all current model elements that have the example "tag" set and highlights the first element
        /// </summary>
        public static void OnFindTaggedElements(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var rootElement = site.ActiveDocumentEditor?.EditorInfo?.RootElement;

            if (rootElement != null)
            {
                List <Element> taggedElements = new List <Element>();
                foreach (var element in rootElement.GetSelfAndDescendantsBreadthFirst((e) => true))
                {
                    if (ExampleAttachedProperties.GetTag(element) == "Tagged")
                    {
                        taggedElements.Add(element);
                    }
                }
                if (taggedElements.Any())
                {
                    // If we found tagged elements highlight all of them with a slight delay for a fun effect.
                    // Note the usage of .IgnoreAwait().  This is a convention we use to ensure that any unhandled exceptions
                    // are dealt with.
                    SlowlyHighlightElementsAsync(site, taggedElements).IgnoreAwait();
                }
            }
        }
        /// <summary>
        /// Revert changes
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="host"></param>
        /// <param name="site"></param>
        public static void Revert(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var debugHost = host.GetSharedExportedValue <IDebugHost>();

            try
            {
                var filePath   = ((Envoy)parameter.Parameter).GetFilePath();
                var svnManager = host.GetSharedExportedValue <SvnManagerPlugin>();
                var success    = svnManager.Revert(filePath);

                if (success)
                {
                    var envoy       = ((Envoy)parameter.Parameter);
                    var projectItem = envoy.GetProjectItemViewModel(site);
                    if (null != projectItem)
                    {
                        projectItem.RefreshIcon();
                    }

                    //TODO: needs to be addressed before go live
                    //This will revert a file once, but you have to close and reopen in order to revert the same file a second time.
                    //If open, you also have to manually close the file and reopen to see the reversion.
                    var referencedFile = envoy.GetReferencedFileService();
                    referencedFile.RefreshReferencedFileAsync();

                    debugHost.LogMessage(new DebugMessage("Viewpoint.Svn", DebugMessageSeverity.Information, $"Revert {filePath}"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                debugHost.LogMessage(new DebugMessage("Viewpoint.Svn", DebugMessageSeverity.Error, $"Failed to Revert {e.Message}"));
                const string caption = "Error SVN";
                var          result  = MessageBox.Show(e.Message, caption,
                                                       MessageBoxButtons.OK,
                                                       MessageBoxIcon.Error);
            }
        }
Exemplo n.º 20
0
 private static bool HandleCanAddUnwrapOptionTunnel(ICommandParameter parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
 {
     return(selection.OfType <FlatSequenceEditor>().Any());
 }
Exemplo n.º 21
0
        /// <summary>
        /// Override to disable or hide any menu command. Can also change it's text.
        /// </summary>
        /// <param name="command">The command. We usually identify by the UniqueId, though they are defined all over the place.</param>
        /// <param name="sender">generally unused</param>
        /// <param name="commandParameter">The commandParameter, usually casted to ICommandParameter to do work</param>
        /// <param name="editSite">The DocumentEditSite</param>
        /// <param name="handled">set to true if you handle(prevent further processing)</param>
        /// <returns>true if the command can execute. Returning false will show it as disabled</returns>
        public override bool CanExecuteCommand(ICommandEx command, object sender, object commandParameter, DocumentEditSite editSite, ref bool handled)
        {
            if (ExamplePreferencePageController.HideEditor)
            {
                if (commandParameter is ICommandParameter parameter &&
                    !_allowedCommands.Contains(command.UniqueId))
                {
                    parameter.Visible = false;
                    return(false);
                }
            }

            return(base.CanExecuteCommand(command, sender, commandParameter, editSite, ref handled));
        }
Exemplo n.º 22
0
 private static bool HandleCanExecuteBorrowMutableCommand(ICommandParameter parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
 {
     selection.CheckAllBorrowModesMatch <BorrowTunnel>(parameter, BorrowMode.Mutable);
     return(true);
 }
Exemplo n.º 23
0
        private static void HandleAddLockTunnel(object parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
        {
            var structureViewModels = selection.OfType <StructureViewModel>().WhereNotNull();

            if (structureViewModels.Any())
            {
                using (var transaction = structureViewModels.First().TransactionManager.BeginTransaction("Add Lock Tunnels", TransactionPurpose.User))
                {
                    foreach (var structureViewModel in structureViewModels)
                    {
                        SMRect leftRect, rightRect;
                        BorderNodeViewModelHelpers.FindBorderNodePositions(structureViewModel, out leftRect, out rightRect);
                        Structure model = (Structure)structureViewModel.Model;

                        LockTunnel lockTunnel = model.MakeTunnel <LockTunnel>(model.PrimaryNestedDiagram, model.NestedDiagrams.First());
                        FlatSequenceTerminateLifetimeTunnel flatSequenceTerminateLifetimeTunnel = model.MakeTunnel <FlatSequenceTerminateLifetimeTunnel>(model.AncestorDiagram, model.NestedDiagrams.First());
                        lockTunnel.TerminateLifetimeTunnel = flatSequenceTerminateLifetimeTunnel;
                        flatSequenceTerminateLifetimeTunnel.BeginLifetimeTunnel = lockTunnel;
                        // Set both as rules were not consistently picking right one to adjust to other.
                        lockTunnel.Top  = leftRect.Y;
                        lockTunnel.Left = leftRect.X;
                        flatSequenceTerminateLifetimeTunnel.Top  = lockTunnel.Top;
                        flatSequenceTerminateLifetimeTunnel.Left = rightRect.X;
                    }
                    transaction.Commit();
                }
            }
        }
 private static bool CanSelectChannel(ICommandParameter parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
 {
     return(host.GetSharedExportedValue <VeriStandHelper>().IsSystemDefinitionValid);
 }
Exemplo n.º 25
0
        private static void HandleAddUnwrapOptionTunnel(object parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
        {
            var flatSequenceStructureViewModels = selection.OfType <StructureViewModel>().WhereNotNull();

            if (flatSequenceStructureViewModels.Any())
            {
                using (var transaction = flatSequenceStructureViewModels.First().TransactionManager.BeginTransaction("Add Unwrap Option Tunnels", TransactionPurpose.User))
                {
                    foreach (var structureViewModel in flatSequenceStructureViewModels)
                    {
                        Structure model = (Structure)structureViewModel.Model;
                        SMRect    leftRect, rightRect;
                        BorderNodeViewModelHelpers.FindBorderNodePositions(structureViewModel, out leftRect, out rightRect);
                        UnwrapOptionTunnel unwrapOptionTunnel = model.MakeTunnel <UnwrapOptionTunnel>(model.AncestorDiagram, model.NestedDiagrams.First());
                        unwrapOptionTunnel.Top  = leftRect.Y;
                        unwrapOptionTunnel.Left = leftRect.X;
                    }
                    transaction.Commit();
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// SVN Commit
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="host"></param>
        /// <param name="site"></param>
        public static void Commit(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var debugHost = host.GetSharedExportedValue <IDebugHost>();

            try
            {
                var filePath = ((Envoy)parameter.Parameter).GetFilePath();
                //moved up here, after ShowDialog() envoy returns null
                var envoy       = ((Envoy)parameter.Parameter);
                var projectItem = envoy.GetProjectItemViewModel(site);

                //note - no built in service to manage creating view/viewmodels, done by hand
                var commitViewModel = new CommitViewModel();
                commitViewModel.FilePath = filePath;
                var commitView = new CommitView(commitViewModel);
                commitView.Owner = (Window)site.RootVisual;
                commitView.ShowDialog();

                if (commitViewModel.OkButtonClicked)
                {
                    var svnManager = host.GetSharedExportedValue <SvnManagerPlugin>();
                    var success    = svnManager.Commit(filePath, commitViewModel.CommitMessage);

                    if (success)
                    {
                        //if uncommented and done here null ref
                        //var envoy = ((Envoy)parameter.Parameter);
                        //var projectItem = envoy.GetProjectItemViewModel(site);
                        if (null != projectItem)
                        {
                            projectItem.RefreshIcon();
                        }

                        debugHost.LogMessage(new DebugMessage("Svn", DebugMessageSeverity.Information, $"Commit {filePath}"));
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                debugHost.LogMessage(new DebugMessage("Svn", DebugMessageSeverity.Error, $"Failed to Commit {e.Message}"));

                const string caption = "Error SVN";
                var          result  = MessageBox.Show(e.Message, caption,
                                                       MessageBoxButtons.OK,
                                                       MessageBoxIcon.Error);
            }
        }
Exemplo n.º 27
0
 private static void HandleExecuteBorrowMutableCommand(ICommandParameter parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
 {
     selection.GetBorrowTunnels <BorrowTunnel>().SetBorrowTunnelsMode(BorrowMode.Mutable);
 }
Exemplo n.º 28
0
        /// <summary>
        /// Command handler which writes the active definition to a temporary merge script and opens that script in notepad.
        /// </summary>
        public static void OnOpenInNotepad(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
        {
            var activeDefinition = site?.EditControl?.Document?.Envoy?.ReferenceDefinition;

            if (activeDefinition != null)
            {
                var fileName = Path.GetTempFileName();
                File.WriteAllText(fileName, MergeScriptBuilder.Create(activeDefinition.ToEnumerable(), host).ToString());
                Process.Start("Notepad.exe", fileName);
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// Command handler to view history
 /// </summary>
 public static void ViewHistory(ICommandParameter parameter, ICompositionHost host, DocumentEditSite site)
 {
     try
     {
         var historyToolWindow = site.ShowToolWindow(new Guid("b7e7ce66-d3fa-4c19-a7c9-8834e91a31f3"), true);
         ((HistoryViewModel)(historyToolWindow.DataContext)).FilePath = ((Envoy)parameter.Parameter).GetFilePath();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         var debugHost = host.GetSharedExportedValue <IDebugHost>();
         debugHost.LogMessage(new DebugMessage("Viewpoint.Svn", DebugMessageSeverity.Error, $"View History {e.Message}"));
         const string caption = "Error SVN";
         var          result  = MessageBox.Show(e.Message, caption,
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
     }
 }
 /// <summary>
 /// This can execute method is run periodically by the command to determine whether it should be enabled or disabled.
 /// </summary>
 private static bool CanLaunchChannelBrowser(ICommandParameter parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site)
 {
     return(selection.All(s => s.Model is PulseWidthModulationControlModel));
 }