/// <summary>
        /// Create the appropriate designer control.
        /// </summary>
        public IDesignerControl CreateDesigner(IIde ide, IXmlStore store, IXmlModel model, IServiceProvider serviceProvider, IVsTextLines textBuffer)
        {
            var viewModel = new XmlMenuViewModel(store, model, serviceProvider, textBuffer);

            viewModel.Initialize();
            return(new XmlMenuDesignerControl(ide, serviceProvider, viewModel));
        }
Example #2
0
        /// <summary>
        /// Default ctor
        /// </summary>
        protected XmlViewModel(IXmlStore xmlStore, IXmlModel xmlModel, IServiceProvider provider, IVsTextLines buffer)
        {
            if (xmlModel == null)
                throw new ArgumentNullException("xmlModel");
            if (xmlStore == null)
                throw new ArgumentNullException("xmlStore");
            if (provider == null)
                throw new ArgumentNullException("provider");
            if (buffer == null)
                throw new ArgumentNullException("buffer");

            BufferDirty = false;
            DesignerDirty = false;

            serviceProvider = provider;
            this.buffer = buffer;
            textBufferSerializer = new TextBufferSerializer(buffer);

            this.xmlStore = xmlStore;
            // OnUnderlyingEditCompleted
            editingScopeCompletedHandler = OnUnderlyingEditCompleted;
            this.xmlStore.EditingScopeCompleted += editingScopeCompletedHandler;
            // OnUndoRedoCompleted
            undoRedoCompletedHandler = OnUndoRedoCompleted;
            this.xmlStore.UndoRedoCompleted += undoRedoCompletedHandler;

            this.xmlModel = xmlModel;
            // BufferReloaded
            bufferReloadedHandler += BufferReloaded;
            this.xmlModel.BufferReloaded += bufferReloadedHandler;
        }
Example #3
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                RegisterIndependentView(false);

                using (model)
                {
                    model = null;
                }
                using (store)
                {
                    store = null;
                }
            }
            base.Dispose(disposing);
        }
Example #4
0
        /// <summary>
        /// Default ctor
        /// </summary>
        protected XmlViewModel(IXmlStore xmlStore, IXmlModel xmlModel, IServiceProvider provider, IVsTextLines buffer)
        {
            if (xmlModel == null)
            {
                throw new ArgumentNullException("xmlModel");
            }
            if (xmlStore == null)
            {
                throw new ArgumentNullException("xmlStore");
            }
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            BufferDirty   = false;
            DesignerDirty = false;

            serviceProvider      = provider;
            this.buffer          = buffer;
            textBufferSerializer = new TextBufferSerializer(buffer);

            this.xmlStore = xmlStore;
            // OnUnderlyingEditCompleted
            editingScopeCompletedHandler         = OnUnderlyingEditCompleted;
            this.xmlStore.EditingScopeCompleted += editingScopeCompletedHandler;
            // OnUndoRedoCompleted
            undoRedoCompletedHandler         = OnUndoRedoCompleted;
            this.xmlStore.UndoRedoCompleted += undoRedoCompletedHandler;

            this.xmlModel = xmlModel;
            // BufferReloaded
            bufferReloadedHandler        += BufferReloaded;
            this.xmlModel.BufferReloaded += bufferReloadedHandler;
        }
Example #5
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public XmlResourceViewModel(IXmlStore xmlStore, IXmlModel xmlModel, IServiceProvider provider, IVsTextLines buffer)
     : base(xmlStore, xmlModel, provider, buffer)
 {
     serializer = new AppResourceSerializer();
 }
Example #6
0
        /// <summary>
        /// Called after the WindowPane has been sited with an IServiceProvider from the environment
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Create and initialize the editor
            #region Register with IOleComponentManager
            var componentManager = (IOleComponentManager)GetService(typeof(SOleComponentManager));
            if (this.componentId == 0 && componentManager != null)
            {
                var crinfo = new OLECRINFO[1];
                crinfo[0].cbSize            = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf            = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf          = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 100;
                int hr = componentManager.FRegisterComponent(this, crinfo, out this.componentId);
                ErrorHandler.Succeeded(hr);
            }
            #endregion

            var resources = new ComponentResourceManager(typeof(XmlEditorPane));

            #region Hook Undo Manager
            // Attach an IOleUndoManager to our WindowFrame. Merely calling QueryService
            // for the IOleUndoManager on the site of our IVsWindowPane causes an IOleUndoManager
            // to be created and attached to the IVsWindowFrame. The WindowFrame automaticall
            // manages to route the undo related commands to the IOleUndoManager object.
            // Thus, our only responsibilty after this point is to add IOleUndoUnits to the
            // IOleUndoManager (aka undo stack).
            undoManager = (IOleUndoManager)GetService(typeof(SOleUndoManager));

            // In order to use the IVsLinkedUndoTransactionManager, it is required that you
            // advise for IVsLinkedUndoClient notifications. This gives you a callback at
            // a point when there are intervening undos that are blocking a linked undo.
            // You are expected to activate your document window that has the intervening undos.
            if (undoManager != null)
            {
                IVsLinkCapableUndoManager linkCapableUndoMgr = (IVsLinkCapableUndoManager)undoManager;
                if (linkCapableUndoMgr != null)
                {
                    linkCapableUndoMgr.AdviseLinkedUndoClient(this);
                }
            }
            #endregion

            // hook up our
            var dteVersion       = Dot42Package.DteVersion;
            var xmlEditorService = XmlEditorServiceProvider.GetEditorService(this, dteVersion);
            if (xmlEditorService == null)
            {
                throw new InvalidOperationException("XmlEditorService required");
            }
            store             = xmlEditorService.CreateXmlStore();
            store.UndoManager = undoManager;

            model = store.OpenXmlModel(new Uri(_fileName));

            // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
            // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
            // the object returned by the Content property.
            //designerControl = new VsDesignerControl(new ViewModel(store, model, this, textBuffer));
            designerControl = context.CreateDesigner(thisPackage.Ide, store, model, this, textBuffer);
            base.Content    = designerControl;

            RegisterIndependentView(true);

            var mcs = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
            if (null != mcs)
            {
                // Now create one object derived from MenuCommnad for each command defined in
                // the CTC file and add it to the command service.

                // For each command we have to define its id that is a unique Guid/integer pair, then
                // create the OleMenuCommand object for this command. The EventHandler object is the
                // function that will be called when the user will select the command. Then we add the
                // OleMenuCommand to the menu service.  The addCommand helper function does all this for us.
                AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.NewWindow, OnNewWindow, OnQueryNewWindow);
                AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.ViewCode, OnViewCode, OnQueryViewCode);
            }
        }
 /// <summary>
 /// Create the appropriate designer control.
 /// </summary>
 public IDesignerControl CreateDesigner(IIde ide, IXmlStore store, IXmlModel model, IServiceProvider serviceProvider, IVsTextLines textBuffer)
 {
     var viewModel = new XmlMenuViewModel(store, model, serviceProvider, textBuffer);
     viewModel.Initialize();
     return new XmlMenuDesignerControl(ide, serviceProvider, viewModel);
 }
Example #8
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public XmlResourceViewModel(IXmlStore xmlStore, IXmlModel xmlModel, IServiceProvider provider, IVsTextLines buffer)
     : base(xmlStore, xmlModel, provider, buffer)
 {
     serializer = new AppResourceSerializer();
 }
Example #9
0
        /// <summary>
        /// Called after the WindowPane has been sited with an IServiceProvider from the environment
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Create and initialize the editor
            #region Register with IOleComponentManager
            var componentManager = (IOleComponentManager)GetService(typeof(SOleComponentManager));
            if (this.componentId == 0 && componentManager != null)
            {
                var crinfo = new OLECRINFO[1];
                crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 100;
                int hr = componentManager.FRegisterComponent(this, crinfo, out this.componentId);
                ErrorHandler.Succeeded(hr);
            }
            #endregion

            var resources = new ComponentResourceManager(typeof(XmlEditorPane));

            #region Hook Undo Manager
            // Attach an IOleUndoManager to our WindowFrame. Merely calling QueryService
            // for the IOleUndoManager on the site of our IVsWindowPane causes an IOleUndoManager
            // to be created and attached to the IVsWindowFrame. The WindowFrame automaticall
            // manages to route the undo related commands to the IOleUndoManager object.
            // Thus, our only responsibilty after this point is to add IOleUndoUnits to the
            // IOleUndoManager (aka undo stack).
            undoManager = (IOleUndoManager)GetService(typeof(SOleUndoManager));

            // In order to use the IVsLinkedUndoTransactionManager, it is required that you
            // advise for IVsLinkedUndoClient notifications. This gives you a callback at
            // a point when there are intervening undos that are blocking a linked undo.
            // You are expected to activate your document window that has the intervening undos.
            if (undoManager != null)
            {
                IVsLinkCapableUndoManager linkCapableUndoMgr = (IVsLinkCapableUndoManager)undoManager;
                if (linkCapableUndoMgr != null)
                {
                    linkCapableUndoMgr.AdviseLinkedUndoClient(this);
                }
            }
            #endregion

            // hook up our
            var dteVersion = Dot42Package.DteVersion;
            var xmlEditorService = XmlEditorServiceProvider.GetEditorService(this, dteVersion);
            if (xmlEditorService == null)
                throw new InvalidOperationException("XmlEditorService required");
            store = xmlEditorService.CreateXmlStore();
            store.UndoManager = undoManager;

            model = store.OpenXmlModel(new Uri(_fileName));

            // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
            // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
            // the object returned by the Content property.
            //designerControl = new VsDesignerControl(new ViewModel(store, model, this, textBuffer));
            designerControl = context.CreateDesigner(thisPackage.Ide, store, model, this, textBuffer);
            base.Content = designerControl;

            RegisterIndependentView(true);

            var mcs = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
            if (null != mcs)
            {
                // Now create one object derived from MenuCommnad for each command defined in
                // the CTC file and add it to the command service.

                // For each command we have to define its id that is a unique Guid/integer pair, then
                // create the OleMenuCommand object for this command. The EventHandler object is the
                // function that will be called when the user will select the command. Then we add the
                // OleMenuCommand to the menu service.  The addCommand helper function does all this for us.
                AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.NewWindow, OnNewWindow, OnQueryNewWindow);
                AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSConstants.VSStd97CmdID.ViewCode, OnViewCode, OnQueryViewCode);
            }
        }
Example #10
0
        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                RegisterIndependentView(false);

                using (model)
                {
                    model = null;
                }
                using (store)
                {
                    store = null;
                }
            }
            base.Dispose(disposing);
        }