private IRibbonViewModel BuildViewModel(string ribbonType, object viewInstance, object viewContext)
        {
            var viewModelType = ribbonTypeLookup[ribbonType];

            VstoContribLog.Info(_ => _("Building ViewModel of type {1} for ribbon {1} with context {2}",
                                       viewModelType.Name, ribbonType, viewContext.ToLogFormat()));
            var ribbonViewModel = vstoContribContext.ViewModelFactory.Resolve(viewModelType);

            ribbonViewModel.VstoFactory = vstoContribContext.VstoFactory;

            if (ribbonUiLookup.ContainsKey(ribbonType))
            {
                var ribbonUi = ribbonUiLookup[ribbonType];
                VstoContribLog.Debug(_ => _("Setting RibbonUi [{0}] for ViewModel", ribbonUi.ToLogFormat()));
                ribbonViewModel.RibbonUi = ribbonUi;
            }
            else if (ribbonUiLookup.ContainsKey(DefaultRibbon))
            {
                var ribbonUi = ribbonUiLookup[DefaultRibbon];
                VstoContribLog.Info(_ => _("Ribbon type was not found, but default was. Setting RibbonUi [{0}] for ViewModel", ribbonUi.ToLogFormat()));
                ribbonViewModel.RibbonUi = ribbonUi;
            }


            ribbonViewModel.CurrentView = viewInstance;
            ListenForINotifyPropertyChanged(ribbonViewModel);
            ribbonViewModel.Initialised(viewContext == NullContext.Instance ? null : viewContext);

            return(ribbonViewModel);
        }
        private void CleanupViewModel(object context)
        {
            VstoContribLog.Debug(_ => _("Cleaning up viewmodel for context: {0}", context.ToLogFormat()));
            if (!contextToViewModelLookup.ContainsKey(context))
            {
                VstoContribLog.Warn(_ => _("Cannot find ViewModel to cleanup: {0}", context.ToLogFormat()));
                return;
            }

            var viewModelInstance = contextToViewModelLookup[context];

            VstoContribLog.Info(_ => _("ViewModel is {0}", viewModelInstance.ToLogFormat()));

            var notifyOfPropertyChanged = viewModelInstance as INotifyPropertyChanged;

            if (notifyOfPropertyChanged != null)
            {
                notifyOfPropertyChanged.PropertyChanged -= NotifiesOfPropertyChangedPropertyChanged;
            }

            viewModelInstance.Cleanup();
            vstoContribContext.ViewModelFactory.Release(viewModelInstance);
            customTaskPaneRegister.CleanupViewModel(viewModelInstance);
            contextToViewModelLookup.Remove(context);
        }
Ejemplo n.º 3
0
        // ReSharper restore InconsistentNaming

        /// <summary>
        /// Gets the custom UI.
        /// </summary>
        /// <param name="ribbonId">The ribbon id.</param>
        /// <returns></returns>
        public string GetCustomUI(string ribbonId)
        {
            VstoContribLog.Info(_ => _("Office called GetCustomUI({0})", ribbonId));
            var customUI = ribbonFactoryController.GetCustomUI(ribbonId);

            VstoContribLog.Debug(_ => _("Provided ribbon xml for ribbonId {0}:\r\n\r\n{1}", ribbonId, customUI));
            return(customUI);
        }
Ejemplo n.º 4
0
        void WordApplicationWindowActivate(Document doc, Window wn)
        {
            VstoContribLog.Info(_ => _("Application.WindowActivate raised, Document: {0}, Window: {1}",
                                       doc.ToLogFormat(), wn.ToLogFormat()));
            if (!documents.ContainsKey(doc))
            {
                documents.Add(doc, new List <Window>());
                var documentWrapper = new DocumentWrapper(doc);
                documentWrapper.Closed += DocumentClosed;
                documentWrappers.Add(doc, documentWrapper);
            }

            //Check if we have this window registered
            if (documents[doc].Any(window => window == wn))
            {
                return;
            }

            documents[doc].Add(wn);
            NewView(this, new NewViewEventArgs(wn, doc, WordRibbonType.WordDocument.GetEnumDescription()));
        }