示例#1
0
        public void AdapterCreatedByCommandIsRemovedWhenLastInvokerRemoved()
        {
            WorkItem wi = new TestableRootWorkItem();
            ICommandAdapterMapService svc = wi.Services.Get <ICommandAdapterMapService>();

            svc.Register(typeof(Control), typeof(MockControlAdapter));

            Command cmd = wi.Commands.AddNew <Command>();

            Control invoker = new Control();

            cmd.AddInvoker(invoker, "GotFocus");

            MockControlAdapter adapter = (MockControlAdapter)cmd.Adapters[0];

            adapter.AddInvoker(invoker, "Click");

            cmd.RemoveInvoker(invoker, "GotFocus");

            Assert.IsFalse(adapter.IsDisposed);

            cmd.RemoveInvoker(invoker, "Click");

            Assert.IsTrue(adapter.IsDisposed);

            adapter.IsDisposed = false;

            cmd.Dispose();
            // Should not be disposed again as it shouldn't be contained at all in the command anymore.
            Assert.IsFalse(adapter.IsDisposed);
        }
        private void RegisterCommandAdapters()
        {
            ICommandAdapterMapService mapService = RootWorkItem.Services.Get <ICommandAdapterMapService>();

            mapService.Register(typeof(ToolStripItem), typeof(ToolStripItemCommandAdapter));
            mapService.Register(typeof(Control), typeof(ControlCommandAdapter));
        }
示例#3
0
        public void RemoveDisposesCommandAndUnplugsCommandAdapters()
        {
            TestableRootWorkItem parent = new TestableRootWorkItem();
            Command cmd = parent.Commands["TestCommand"];
            ICommandAdapterMapService mapService = parent.Services.Get <ICommandAdapterMapService>();

            mapService.Register(typeof(MockInvokerA), typeof(EventCommandAdapter <MockInvokerA>));

            MockInvokerA invoker = new MockInvokerA();

            cmd.AddInvoker(invoker, "Event");
            Assert.AreEqual(1, parent.Commands["TestCommand"].Adapters.Count);

            InstanceHandlerClass instance = new InstanceHandlerClass();

            parent.Items.Add(instance);

            invoker.DoInvokeEvent();
            Assert.AreEqual(1, instance.counter);


            parent.Commands.Remove(parent.Commands["TestCommand"]);
            GC.Collect(0);
            GC.WaitForPendingFinalizers();

            invoker.DoInvokeEvent();
            Assert.AreEqual(0, parent.Commands["TestCommand"].Adapters.Count);

            // Returns 2
            Assert.AreEqual(1, instance.counter);
        }
        private void RegisterCommandAdapters()
        {
            ICommandAdapterMapService mapService = RootWorkItem.Services.Get <ICommandAdapterMapService>();

            mapService.Register(typeof(BarItem), typeof(BarItemCommandAdapter));
            mapService.Register(typeof(NavBarItem), typeof(NavBarItemCommandAdapter));
            mapService.Register(typeof(DXMenuItem), typeof(DXMenuItemCommandAdapter));
            mapService.Register(typeof(RepositoryItemHyperLinkEdit), typeof(RepositoryItemHyperLinkEditCommandAdapter));
        }
示例#5
0
        public void RegisterCommandAdapter(Type invokerType, Type adapterType)
        {
            ICommandAdapterMapService camSrv = workItem.Services.Get <ICommandAdapterMapService>();

            if (camSrv != null)
            {
                camSrv.Register(invokerType, adapterType);
            }
        }
示例#6
0
        protected override void AfterShellCreated()
        {
            ////base.AfterShellCreated();

            AddClientService();
            //RootWorkItem.UIExtensionSites.RegisterSite("menu", Shell.menu);
            //RootWorkItem.UIExtensionSites.RegisterSite("toolbar", Shell.tools);
            //RootWorkItem.UIExtensionSites.RegisterSite("statusbar", Shell.status);

            ICommandAdapterMapService mapService = RootWorkItem.Services.Get <ICommandAdapterMapService>();

            mapService.Register(typeof(RepositoryItem), typeof(RepositoryItemCommandAdapter));

            ////TabbedMdiWorkspace wp = new TabbedMdiWorkspace(Shell);

            ////wp.SmartPartActivated += this.OnSmartPartActivated;

            ////wp.SmartPartClosing += this.OnSmartPartClosing;

            ////wp.SmartPartClosed += this.OnSmartPartClosed;


            ////RootWorkItem.Workspaces.Add(wp, "MainWorkspace");

            this.RootWorkItem.Activated += new EventHandler(RootWorkItem_Activated);


            //Program.SetInitialState(LocalData.IsEnglish ? "Load application module..." : "加载应用模块...");

            //下载模块信息
//            ClientPermission cp = new ClientPermission();
//            RootWorkItem.Services.Add<IModuleEnumerator>(cp);
//            foreach (UICommand command in cp.Commands)
//            {
//#if DEBUG
//                //#warning 此处极其危险,因为经常会以Debug环境编译dll并发布
//                //command.HasPermission = true;
//#endif
//                IElementBuilder builder = UIElementFactory.GetBuilder(command);
//                builder.BuildIn(RootWorkItem);
//            }
            //ShowPortal();

            //Program.IncreaseProgressBar(20);

            this.Shell.TopMost = true;
            this.Shell.TopMost = false;
        }
示例#7
0
        public void CommandDoesNotReuseAdpatersOnAddInvoker()
        {
            WorkItem wi = new TestableRootWorkItem();
            ICommandAdapterMapService svc = wi.Services.Get <ICommandAdapterMapService>();

            svc.Register(typeof(Control), typeof(MockControlAdapter));

            Command cmd = wi.Commands.AddNew <Command>();

            Control invoker = new Control();

            cmd.AddInvoker(invoker, "GotFocus");
            cmd.AddInvoker(invoker, "Click");

            Assert.AreEqual(2, cmd.Adapters.Count);
        }
示例#8
0
        public void DisposingCommandRemovesAllOfItsAdapters()
        {
            WorkItem wi = new TestableRootWorkItem();
            ICommandAdapterMapService svc = wi.Services.Get <ICommandAdapterMapService>();

            svc.Register(typeof(MockInvokerA), typeof(MockAdapter));
            Command cmd = wi.Commands.AddNew <Command>();

            cmd.AddInvoker(new MockInvokerA(), "Event");
            cmd.AddInvoker(new MockInvokerA(), "Event");
            cmd.AddInvoker(new MockInvokerA(), "Event");
            cmd.AddInvoker(new MockInvokerA(), "Event");

            Assert.AreEqual(4, cmd.Adapters.Count);
            cmd.Dispose();
            Assert.AreEqual(0, cmd.Adapters.Count);
        }
示例#9
0
        public void AdapterCratedByCommandIsDisposedWithCommand()
        {
            WorkItem wi = new TestableRootWorkItem();
            ICommandAdapterMapService svc = wi.Services.Get <ICommandAdapterMapService>();

            svc.Register(typeof(Control), typeof(MockControlAdapter));

            Command cmd = wi.Commands.AddNew <Command>();

            Control invoker = new Control();

            cmd.AddInvoker(invoker, "GotFocus");

            MockControlAdapter adapter = (MockControlAdapter)cmd.Adapters[0];

            cmd.Dispose();
            Assert.IsTrue(adapter.IsDisposed);
        }
        /// <summary>
        /// See <see cref="CabShellApplication{T,S}.AfterShellCreated"/>
        /// </summary>
        protected override void AfterShellCreated()
        {
            base.AfterShellCreated();

            // register the command adapters
            ICommandAdapterMapService mapService = this.RootWorkItem.Services.Get <ICommandAdapterMapService>();

            mapService.Register(typeof(ToolBase), typeof(ToolBaseCommandAdapter));
            mapService.Register(typeof(UltraExplorerBarItem), typeof(ExplorerBarCommandAdapter));
            mapService.Register(typeof(UltraStatusPanel), typeof(StatusPanelCommandAdapter));

            // register the uiadapter factories
            IUIElementAdapterFactoryCatalog catalog = this.RootWorkItem.Services.Get <IUIElementAdapterFactoryCatalog>();

            catalog.RegisterFactory(new ExplorerBarUIAdapterFactory());
            catalog.RegisterFactory(new StatusBarUIAdapterFactory());
            catalog.RegisterFactory(new ToolbarsManagerUIAdapterFactory());
        }
示例#11
0
        public void RemovingAllInvokersFromAdapterRemovesAdapterFromCommand()
        {
            TestableRootWorkItem      workItem = new TestableRootWorkItem();
            ICommandAdapterMapService svc      = workItem.Services.Get <ICommandAdapterMapService>();

            svc.Register(typeof(MockInvokerA), typeof(MockAdapter));

            Command command = new Command();

            workItem.Commands.Add(command);

            MockInvokerA invoker = new MockInvokerA();

            command.AddInvoker(invoker, "Event");
            Assert.AreEqual(1, command.Adapters.Count);

            command.RemoveInvoker(invoker, "Event");
            Assert.AreEqual(0, command.Adapters.Count);
        }
示例#12
0
        private void RegisterCommandAdapters()
        {
            ICommandAdapterMapService mapService = RootWorkItem.Services.Get <ICommandAdapterMapService>();

            mapService.Register(typeof(FrameworkElement), typeof(FrameworkElementCommandAdapter));
        }
示例#13
0
 public void Setup()
 {
     container = new TestableRootWorkItem();
     mapSvc    = container.Services.Get <ICommandAdapterMapService>(true);
 }