Example #1
0
        private void AddMenu(MenuDef def)
        {
            var menu = new RootMenu(def);

            if (menu.MenuTag is Sce.Atf.Applications.StandardMenu)
            {
                m_toolbars.Add(menu);
            }
            else
            {
                m_toolbars.Insert(m_toolbars.Count - 2, menu); // insert custom menus before Window, Help
            }
        }
Example #2
0
        private void AddMenu(MenuDef def)
        {
            var menu = new RootMenu(def);

            menu.RefreshRequested += (s, e) => RebuildMenu((Menu)s);

            if (menu.MenuTag is Sce.Atf.Applications.StandardMenu)
            {
                m_menus.Add(menu);
            }
            else
            {
                m_menus.Insert(m_menus.Count - 2, menu); // insert custom menus before Window, Help
            }
        }
        private IList <MenuDef> ReMarkMenuTree(MenuDef t2, IList <MenuDef> data)
        {
            var             t3 = data.Where(x => x.ParentKey == t2.Key);
            IList <MenuDef> s  = new List <MenuDef>();

            if (!t3.Any())
            {
                return(s);
            }

            foreach (var t4 in t3)
            {
                t4.sub = ReMarkMenuTree(t4, data);
            }
            return(t3.ToList());
        }
Example #4
0
        public override MenuDef GetMenu(esriE2MenuType menuType, object menuArgs)
        {
            if (menuType == esriE2MenuType.ResultContextMenu)
            {
                // GetMenu for a ResultContextMenu is only called on the TaskUI which created the result
                // in the first place, and can be used to add any additional context menu items to the
                // standard menu.
                if (_mainMenu == null)
                {
                    // For the main context menu, support one simple item.
                    _mainMenu = new MenuDef();
                }
                return this._mainMenu;
            }
            else if (menuType == esriE2MenuType.ResultSendToMenu)
            {
                // GetMenu for a ResultSentToMenu is called for any result, regardless of which TaskUI
                // first created the result. Here, the TaskUI should decide if it supports working with
                // the menuArgs passed in.
                // For the send to menu, support all PlaceResults with Point geometries.
                // Checking the category means we do not present the context menu for failed executions,
                // only for results where we successfully set the Category property.
                ResultInfo resInfo = menuArgs as ResultInfo;
                PlaceResult chosenRes = resInfo.ChosenResult as PlaceResult;
                if ((chosenRes != null) && (chosenRes.Geometry is Point))
                {
                    if (this._sendToMenu == null)
                    {
                        // Create the menu if required.
                        _sendToMenu = new MenuDef();
                        _sendToMenu.AddItem("StreetViewer", "StreetViewer", false, false, 361); //361 is arbitrary could be any number

                    }
                    return this._sendToMenu;
                }
            }
            // For all other cases, do not provide a menu.
            return null;
        }
        public async Task <IHttpActionResult> GetMenuQuery()
        {
            if (UserId == null)
            {
                return(null);
            }

            ObjectCache cache        = MemoryCache.Default;
            string      cache_name   = "m." + UserId;
            string      json_context = (string)cache[cache_name];
            string      path         = System.Web.Hosting.HostingEnvironment.MapPath(string.Format("/_code/cache/m.{0}.json", UserId));

            if (json_context == null)
            {
                #region data access
                db0 = getDB0();
                IList <MenuDef> m1    = new List <MenuDef>();
                var             menus = await db0.Menu.Where(x => x.is_use == true).ToListAsync();

                foreach (var menu in menus)
                {
                    var  menu_roles = menu.AspNetRoles.Select(x => x.Id).ToList();
                    bool exits;
                    if (UserRoles.Any(x => x == "7b556351-4072-465b-8cf1-f02fa28ba3ca"))
                    {
                        exits = true;
                    }
                    else
                    {
                        exits = menu_roles.Intersect(UserRoles).Any(); //檢查 User roles是否與 menu roles是否有交集
                    }

                    if (exits)
                    {
                        var o = new MenuDef();
                        o.Area       = menu.area == null ? string.Empty : menu.area;
                        o.Controller = menu.controller == null ? string.Empty : menu.controller;
                        o.Action     = menu.action == null ? string.Empty : menu.action;

                        o.Title     = menu.menu_name;
                        o.Clickable = !menu.is_folder;
                        o.Key       = menu.menu_id;
                        o.ParentKey = menu.parent_menu_id;
                        o.sort      = menu.sort;
                        o.Checked   = false;
                        o.IconClass = menu.icon_class;
                        m1.Add(o);
                    }
                }
                db0.Dispose();
                #endregion

                //樹狀處理
                //var t1 = m1.Where(x => x.ParentKey == 0).OrderBy(x => x.sort);
                //foreach (var t2 in t1)
                //{
                //    t2.sub = ReMarkMenuTree(t2, m1);
                //}
                var result_obj = m1.OrderBy(x => x.sort);

                json_context = JsonConvert.SerializeObject(result_obj,
                                                           new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                }
                                                           );
                File.WriteAllText(path, json_context);

                IList <string> paths = new List <string>();
                paths.Add(path);

                CacheItemPolicy policy = new CacheItemPolicy();
                policy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(1);
                policy.ChangeMonitors.Add(new HostFileChangeMonitor(paths));
                cache.Set(cache_name, json_context, policy);

                return(Ok(result_obj));
            }
            else
            {
                var result_obj = JsonConvert.DeserializeObject <IList <MenuDef> >(json_context);
                return(Ok(result_obj));
            }
        }
Example #6
0
 public RootMenu(MenuDef def)
     : base(null, def.MenuTag, null, def.Text, def.Description)
 {
 }
Example #7
0
 public MenuItem(int skullX, int skullY, MenuDef next)
 {
     this.skullX = skullX;
     this.skullY = skullY;
     this.next   = next;
 }
Example #8
0
        public void DoIt()
        {
            //create window menus
            var _windowDefs = GetWindowDefs();

            var windowMaps    = new List <WindowMapping>();
            var menuDefs      = new List <MenuDef>();
            var toolStripDefs = new List <ToolStripDef>();

            var menuDefMapping = new Dictionary <Type, MenuDef>();
            var tstDefMapping  = new Dictionary <Type, ToolStripDef>();


            //create window manager
            WindowManager wm = new WindowManager(_form, _form.dockPanel);
            //register window manager
            var autofacBuilder = new ContainerBuilder();

            autofacBuilder.RegisterInstance(wm).As <IWindowManager>();
            autofacBuilder.RegisterInstance <MainForm>(_form);
            autofacBuilder.Update(_container);


            foreach (var def in _windowDefs)
            {
                var window = CreateWindow(def, _resourceManager, _container);

                //menudef
                var m = new MenuDef()
                {
                    ParentID = 0,
                    MenuType = MenuType.Command,
                    Image    = def.ButtonImage,
                    Name     = "menu" + def.ButtonName,
                    Text     = def.MenuText,
                    SizeH    = 200,
                    SizeV    = 22,
                    //Command = new DelegateCommand(()=>_wm.ShowWindow(def.Type))
                };
                menuDefs.Add(m);
                menuDefMapping.Add(def.ViewType, m);

                //ToolstripDef
                var tsd = new ToolStripDef()
                {
                    Image   = def.ButtonImage,
                    Name    = "tst" + def.ButtonName,
                    SizeH   = 23,
                    SizeV   = 22,
                    ToolTip = def.ButtonTooltip,
                    Text    = def.ButtonText,
                    //Command = new DelegateCommand(() => _wm.ShowWindow(def.Type))
                };
                toolStripDefs.Add(tsd);
                tstDefMapping.Add(def.ViewType, tsd);

                windowMaps.Add(window);
            }


            //documents
            var docTypeList = new List <Type>();
            var _docDefs    = GetDocumentDefs();

            foreach (var def in _docDefs)
            {
                if (def.ViewType == null)
                {
                    def.ViewType = Type.GetType(string.Format("{0}, {1}", def.ClassName, def.AssemblyName));
                }

                docTypeList.Add(def.ViewType);
            }


            //register the windows
            wm.Init(new AutofacResolver(_container), windowMaps, docTypeList);
            _form.SetWindowmanager(wm);



            //Menus & toolstrip
            foreach (var m in menuDefMapping)
            {
                var type = m.Key;
                m.Value.Command = new DelegateCommand(() => wm.ShowWindow(type));
            }
            foreach (var m in tstDefMapping)
            {
                var type = m.Key;
                m.Value.Command = new DelegateCommand(() => wm.ShowWindow(type));
            }

            //Insert the menus into the main form

            MenuBuilder.InsertSubItems(_form.menuItemView, _resourceManager, menuDefs, 0);

            ToolStripBuilder.AppendItems(_form.toolBar, toolStripDefs, _resourceManager);


            RenderMenus();
        }