Beispiel #1
0
        internal void UpdateCurrent(ProjectModule newValue)
        {
            ToolboxModule newCurrent = null;

            foreach (ToolboxDrawer drawer in drawers)
            {
                foreach (ToolboxItem rawItem in drawer.GetContents())
                {
                    ToolboxModule item = rawItem as ToolboxModule;
                    if (item != null && item.Module == newValue)
                    {
                        newCurrent = item;
                    }
                }
            }

            ToolboxModule oldCurrent = currentModule;

            if (oldCurrent != newCurrent)
            {
                if (oldCurrent != null && oldCurrent.Name.EndsWith("*"))
                {
                    oldCurrent.SetName(oldCurrent.Name.Substring(0, oldCurrent.Name.Length - 1));
                    OnToolboxChanged(ToolboxChangedArgs.ChangeTypes.ItemRenamed, oldCurrent);
                }
                if (newCurrent != null)
                {
                    newCurrent.SetName(newCurrent.Name + "*");
                    OnToolboxChanged(ToolboxChangedArgs.ChangeTypes.ItemRenamed, newCurrent);
                }
                currentModule = newCurrent;
            }
        }
Beispiel #2
0
        public ToolboxModel(WindowModel window)
        {
            this.window = window;

            Transaction    xn   = new Transaction();
            IProjectAccess proj = xn.RequestReadAccess(window.Project);

            using (xn.Start()) {
                foreach (ProjectModule mod in proj.GetModules())
                {
                    string        modName = proj.GetModuleName(mod);
                    ToolboxModule toAdd   = new ToolboxModule(mod, modName);
                    if (mod == window.CurrentModule)
                    {
                        toAdd.SetName(toAdd.Name + "*");
                        currentModule = toAdd;
                    }
                    modules.Add(toAdd);
                }
            }
            window.Project.ProjectModifiedEvent += RefreshModules;

            List <ToolboxItem> builtins = new List <ToolboxItem>();

            Component[] masters =
            {
                new AndGate(),
                new OrGate(),
                new NotGate(),
                new ToggleSwitch(),
                new Led(),
                new Pin(),
                new PinOut()
            };
            foreach (Component master in masters)
            {
                builtins.Add(new ToolboxComponent(master));
            }

            List <ToolboxDrawer> drawers = new List <ToolboxDrawer>();

            drawers.Add(new ToolboxDrawer("Project", modules.AsReadOnly()));
            drawers.Add(new ToolboxDrawer("Built-Ins", builtins.AsReadOnly()));
            this.drawers = drawers.AsReadOnly();
        }
Beispiel #3
0
        public override void LoadModules()
        {
            ErrorListModule errorModule = _container.Resolve <ErrorListModule>();

            errorModule.Initialize();


            ToolboxModule toolboxModule = _container.Resolve <ToolboxModule>();

            toolboxModule.Initialize();


            //Load properties

            //Load project explorer
            ProjectExplorerModule projectExplorerModule = _container.Resolve <ProjectExplorerModule>();

            projectExplorerModule.Initialize();
        }
Beispiel #4
0
        private void RefreshModules(object src, ProjectModifiedArgs args)
        {
            ProjectModule changedModule = args.ChangedModule;
            ToolboxItem   changedItem   = null;
            ProjectModule currentModule = window.CurrentModule;

            Transaction    xn   = new Transaction();
            IProjectAccess proj = xn.RequestReadAccess(window.Project);

            using (xn.Start()) {
                Dictionary <ProjectModule, ToolboxModule> oldItems = new Dictionary <ProjectModule, ToolboxModule>();
                List <ToolboxModule> newModules = new List <ToolboxModule>();
                foreach (ToolboxModule item in modules)
                {
                    oldItems[item.Module] = item;
                    if (item.Module == changedModule)
                    {
                        changedItem = item;
                    }
                }
                foreach (ProjectModule mod in proj.GetModules())
                {
                    string curName = proj.GetModuleName(mod);
                    if (mod == currentModule)
                    {
                        curName = curName + "*";
                    }
                    ToolboxModule nextItem;
                    if (oldItems.TryGetValue(mod, out nextItem))
                    {
                        if (nextItem.Name != curName)
                        {
                            nextItem.SetName(curName);
                        }
                    }
                    else
                    {
                        nextItem = new ToolboxModule(mod, curName);
                    }
                    newModules.Add(nextItem);
                    if (nextItem.Module == changedModule)
                    {
                        changedItem = nextItem;
                    }
                }
                this.modules.Clear();
                foreach (ToolboxModule item in newModules)
                {
                    this.modules.Add(item);
                }
            }

            if (changedItem != null)
            {
                ToolboxChangedArgs.ChangeTypes changeType;
                bool found = true;
                switch (args.ChangeType)
                {
                case ProjectModifiedArgs.ChangeTypes.ModuleAdded:
                    changeType = ToolboxChangedArgs.ChangeTypes.ItemAdded;
                    break;

                case ProjectModifiedArgs.ChangeTypes.ModuleRemoved:
                    changeType = ToolboxChangedArgs.ChangeTypes.ItemRemoved;
                    break;

                case ProjectModifiedArgs.ChangeTypes.ModuleRenamed:
                    changeType = ToolboxChangedArgs.ChangeTypes.ItemRenamed;
                    break;

                default:
                    changeType = ToolboxChangedArgs.ChangeTypes.ItemAdded; // unused value to trick compiler
                    found      = false;
                    break;
                }
                if (found)
                {
                    OnToolboxChanged(changeType, changedItem);
                }
            }
        }