예제 #1
0
        // We need this to handle pasting - when objects are pasted the transitions have the old GUIDs but
        // visio may have assigned new ones to the pasted objects.  We stash the old GUIDs in OnWindowSelectionChange
        // and we make use of them here to get everyone in sync
        private void OnExitScope(Microsoft.Office.Interop.Visio.Application application, string moreInformation)
        {
            // moreInformation is a standard ;-delimited string from the scope events that contains what we need

            // 1344 is the Microsoft Scope Id for GotoPage
            if (moreInformation.StartsWith("1344"))
            {
                string pageName = visioControl.Document.Application.ActivePage.Name;
                int    index    = visioControl.Document.Pages[pageName].Index;
                gotoPageComboBox.SelectedIndex = index - 1;
            }
            // 1022 is the Microsoft Scope Id for Paste
            // 1024 is the Microsoft Scope Id for Duplicate
            else if (moreInformation.StartsWith(((int)VisUICmds.visCmdUFEditPaste).ToString()) ||
                     moreInformation.StartsWith(((int)VisUICmds.visCmdUFEditDuplicate).ToString()))
            {
                // first make a map of old GUIDs to new
                Dictionary <string, string> oldGUIDToNewGUIDMap = new Dictionary <string, string>();
                foreach (Shape shape in visioControl.Document.Application.ActiveWindow.Selection)
                {
                    string oldUID = Common.GetCellString(shape, Strings.CutCopyPasteTempCellName);
                    string newUID = shape.get_UniqueID((short)VisUniqueIDArgs.visGetOrMakeGUID);
                    oldGUIDToNewGUIDMap.Add(oldUID, newUID);
                }

                // now call each shadow to fix itself
                foreach (Shape shape in visioControl.Document.Application.ActiveWindow.Selection)
                {
                    Shadow s = PathMaker.LookupShadowByShape(shape);
                    if (s == null)
                    {
                        continue;
                    }
                    s.FixUIDReferencesAfterPaste(oldGUIDToNewGUIDMap);
                }

                // because we halt this when pasting, we now need to go fix all the ones that were pasted
                foreach (Shape s in visioControl.Document.Application.ActiveWindow.Selection)
                {
                    string uid = s.get_UniqueID((short)VisUniqueIDArgs.visGetOrMakeGUID);
                    Common.SetCellString(s, Strings.CutCopyPasteTempCellName, uid);
                }
            }
        }