Ejemplo n.º 1
0
 // used internally for the base undo manager (parent for all others)
 private void GetUndoManager()
 {
     if (oleUndoManagerInstance == null)
     {
         Interop.IOleServiceProvider serviceProvider = _editor.GetActiveDocument(false) as Interop.IOleServiceProvider;
         Guid   undoManagerGuid  = typeof(Interop.IOleUndoManager).GUID;
         Guid   undoManagerGuid2 = typeof(Interop.IOleUndoManager).GUID;
         IntPtr undoManagerPtr;
         int    hr = serviceProvider.QueryService(ref undoManagerGuid2, ref undoManagerGuid, out undoManagerPtr);
         if ((hr == Interop.S_OK) && (undoManagerPtr != Interop.NullIntPtr))
         {
             oleUndoManagerInstance = (Interop.IOleUndoManager)Marshal.GetObjectForIUnknown(undoManagerPtr);
             Debug.WriteLine(oleUndoManagerInstance.GetHashCode(), "MANAGER INSTANCE");
             Marshal.Release(undoManagerPtr);
         }
         else
         {
             throw new ExecutionEngineException("Component threw an internal exception creating Undo manager.");
         }
     }
 }
Ejemplo n.º 2
0
        private bool RegisterNamespaceWithEditor(string namespaceName)
        {
            if (_namespaceTable == null)
            {
                Interop.IOleServiceProvider interop_IOleServiceProvider = _editor.GetActiveDocument(true) as Interop.IOleServiceProvider;
                Guid   guid1 = typeof(Interop.IElementNamespaceTable).GUID;
                Guid   guid2 = guid1;
                IntPtr i;
                if (interop_IOleServiceProvider != null && interop_IOleServiceProvider.QueryService(ref guid1, ref guid2, out i) == 0 && i != Interop.NullIntPtr)
                {
                    _namespaceTable = (Interop.IElementNamespaceTable)Marshal.GetObjectForIUnknown(i);
                    Marshal.Release(i);
                }
                else
                {
                    // cannot register, document not ready
                    return(false);
                }
            }
            if (_namespaceTable == null)
            {
                return(false);
            }
            object local = this;

            try
            {
                _namespaceTable.AddNamespace(namespaceName, null, 2, ref local);
                return(true);
            }
            catch (Exception)
            {
                bool flag = false;
                return(flag);
            }
        }