コード例 #1
0
        private void Application_DeleteShapeEvent(Shape s) //Fired when a shape is deleted. Shape now no longer exists
        {
            if (s.Document.Template.Contains(Information.TemplateName))
            {
                try
                {
                    Log.Debug("shape deleted event for: " + s.Name);
                    if (s.CellExistsU[VisioFormulas.Cell_Stub, (short)VisExistsFlags.visExistsAnywhere] == Constants.CellExists)
                    {
                        return;
                    }
                    if (s.CellExistsU[VisioFormulas.Cell_RationallyType, (short)VisExistsFlags.visExistsAnywhere] == Constants.CellExists)
                    {
                        string rationallyType = s.CellsU[VisioFormulas.Cell_RationallyType].ResultStr[VisioFormulas.Value];

                        //mark the deleted shape as 'deleted' in the view tree
                        VisioShape deleted = View.GetComponentByShape(s);
                        if (deleted != null)
                        {
                            deleted.Deleted = true;
                        }
                        DeleteEventHandlerRegistry.HandleEvent(rationallyType, Model, s);
                    }
                    else
                    {
                        if (StartedUndoState == 0)
                        {
                            RebuildTree(s.ContainingPage.Document);
                        }
                    }
                    if ((StartedUndoState != 0) && (s.Name == LastDelete))
                    {
                        Log.Debug("ending undo scope");
                        Application.EndUndoScope(StartedUndoState, true);
                        StartedUndoState = 0;
                        LastDelete       = "";
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, ex);
#if DEBUG
                    throw;
#endif
                }
            }
        }
コード例 #2
0
ファイル: SuperSubscript.cs プロジェクト: sunjini/eZOffice
        /// <summary>
        /// 设置文本的上下标
        /// </summary>
        /// <param name="visioApp"></param>
        /// <param name="superOrSubscript">null 表示“正常”,true表示“上标”,false表示“下标”</param>
        public static void SetSuperOrSubScript(Application visioApp, bool?superOrSubscript)
        {
            int undoScopeID1 = visioApp.BeginUndoScope("设置文字上下标");

            try
            {
                SuperSubScript(visioApp, superOrSubscript);
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message + "\r\n\r\n" + ex.StackTrace;
                MessageBox.Show(errorMessage);
            }
            finally
            {
                visioApp.EndUndoScope(undoScopeID1, true);
            }
        }
コード例 #3
0
        public ExternalCommandResult Execute(Application visioApp, ref string errorMessage, ref object errorObj)
        {
            int undoScopeID1 = visioApp.BeginUndoScope("文字属性");

            try
            {
                visioApp.ShowChanges    = false;
                visioApp.ScreenUpdating = 0;
                DoSomething(visioApp);
                return(ExternalCommandResult.Succeeded);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + "\r\n\r\n" + ex.StackTrace;
                return(ExternalCommandResult.Failed);
            }
            finally
            {
                visioApp.ShowChanges    = true;
                visioApp.ScreenUpdating = 1;
                visioApp.EndUndoScope(undoScopeID1, true);
            }
        }
コード例 #4
0
        private void Application_MouseDown(int button, int keyButtonState, double x, double y, ref bool cancelDefault)
        {
            if (button != 1) //if other than the left mouse button was clicked
            {
                return;
            }

            PlanningContainer planningContainer = View.Children.FirstOrDefault(c => c is PlanningContainer) as PlanningContainer;
            //locate all checkbox elements in the view
            List <CheckBoxStateComponent> candidates = planningContainer?.Children //map all planning items to their checkbox child, and that checkbox to its state component
                                                       .Select(planningItemComponent => ((PlanningItemComponent)planningItemComponent).Children
                                                               .First(c => c is CheckBoxComponent)).Cast <CheckBoxComponent>()
                                                       .Select(checkBox => (CheckBoxStateComponent)checkBox.Children.First()).ToList();

            if (candidates == null)
            {
                return;
            }
            CheckBoxStateComponent stateComponent = null;

            //for all the candidates, check if the clicked location was within its bounds. Stop as soon as a match if found.
            foreach (CheckBoxStateComponent candidate in candidates)
            {
                if (candidate.WasClicked(x, y))
                {
                    int scopeId = Application.BeginUndoScope(Messages.Scope_CheckboxClick);
                    candidate.Toggle(); //actual changing of the clicked checkbox's state
                    Application.EndUndoScope(scopeId, true);
                    break;
                }
            }

            //locate parent of stateComponent
            //PlanningItemComponent toStrikeThrough = planningContainer?.Children.Cast<PlanningItemComponent>().First(item => (item.Children.First(c => c is CheckBoxComponent) as CheckBoxComponent).Children.Contains(stateComponent));
            //toStrikeThrough.Children.First(c => c is PlanningItemTextComponent).StrikeThrough = !toStrikeThrough.Children.First(c => c is PlanningItemTextComponent).StrikeThrough;
        }
コード例 #5
0
        private void Application_ShapeAddedEvent(Shape s)
        {
            Log.Debug("Shape added with name: " + s.Name);
            if (s.Document.Template.Contains(Information.TemplateName) && (s.CellExistsU[VisioFormulas.Cell_RationallyType, (short)VisExistsFlags.visExistsAnywhere] == Constants.CellExists) && !View.ExistsInTree(s))
            {
                try
                {
                    switch (s.CellsU[VisioFormulas.Cell_RationallyType].ResultStr[VisioFormulas.Value])
                    {
                    case "alternativeAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddAlternative);
                            s.Delete();
                            AlternativesContainer alternativesContainer = Globals.RationallyAddIn.View.Children.FirstOrDefault(ch => ch is AlternativesContainer) as AlternativesContainer;
                            alternativesContainer?.AddAlternative("Title", default(AlternativeState).GetName());

                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "forceAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddForce);
                            s.Delete();
                            MarkerEventHandlerRegistry.HandleEvent("forces.add", null, null);
                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "relatedDocumentAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddFile);
                            s.Delete();
                            MarkerEventHandlerRegistry.HandleEvent("relatedDocuments.addRelatedFile", null, null);
                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "relatedUrlAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddUrl);
                            s.Delete();
                            MarkerEventHandlerRegistry.HandleEvent("relatedDocuments.addRelatedUrl", null, null);
                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "stakeholderAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddStakeholder);
                            s.Delete();
                            StakeholdersContainer stakeholdersContainer = View.Children.FirstOrDefault(ch => ch is StakeholdersContainer) as StakeholdersContainer;
                            stakeholdersContainer?.AddStakeholder("<<name>>", "<<role>>");

                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "planningItemStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddPlanningItem);
                            s.Delete();
                            PlanningContainer planningContainer = View.Children.FirstOrDefault(ch => ch is PlanningContainer) as PlanningContainer;
                            planningContainer?.AddPlanningItem();

                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    default:
                        View.AddToTree(s, true);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, ex);
#if DEBUG
                    throw;
#endif
                }
            }
        }