private void setupParentForm() { Form parentForm = this.FindForm(); if (parentForm != null) { if (this.CreateMainMenu) { // show this menu in the MainForm MenuWithHandler[] mainMenu = MenuResource.LoadMenuDefinition("SDI Menu", true, cadFrame); #region DebuggerPlayground, you can remove this region // in the following lines a "DebuggerPlayground" object is created via reflection. This class is a playground to write testcode // which is not included in the sources. This is why it is constructed via reflection, there is no need to have this class in the project. Type dbgplygnd = Type.GetType("CADability.Forms.DebuggerPlayground", false); if (dbgplygnd != null) { MethodInfo connect = dbgplygnd.GetMethod("Connect"); if (connect != null) { mainMenu = connect.Invoke(null, new object[] { cadFrame, mainMenu }) as MenuWithHandler[]; } } #endregion DebuggerPlayground parentForm.Menu = MenuManager.MakeMainMenu(mainMenu); cadFrame.FormMenu = parentForm.Menu; } parentForm.KeyPreview = true; // used to filter the escape key (and maybe some more?) parentForm.FormClosed += ParentForm_FormClosed; } }
private void GenerateHeader(MenuResource resource, TextWriter writer) { // Calcula la llista de comandes // commands = MenuUtils.GetCommandList(resource); writer.WriteLine("/*************************************************************************"); writer.WriteLine(" *"); writer.WriteLine(" * Archivo generado desde un archivo de recursos"); writer.WriteLine(" * No modificar!"); writer.WriteLine(" *"); writer.WriteLine(" * Fecha de generaciĆ³n : {0}", DateTime.Now); writer.WriteLine(" * Nombre del generador : {0}", "EosResourceCompiler"); writer.WriteLine(" * Version del generador: {0}", version); writer.WriteLine(" *"); writer.WriteLine(" ************************************************************************/"); writer.WriteLine(); writer.WriteLine(); for (int i = 0; i < commands.Count; i++) { writer.WriteLine("#define {0} {1}", commands[i], 100 + i); } writer.WriteLine(); writer.WriteLine(); writer.WriteLine("extern const unsigned char menu{0}[];", resource.Id); }
private async Task <MenuAndSubMenuDto> CreateMenuAsync(MenuResource menuResource, List <MenuResource> res, string userName, string roleName) { var toAdd = new MenuAndSubMenuDto { Menu = menuResource }; var childs = await _context.MenuResources.AsNoTracking().Where(x => x.ParentMenuId == menuResource.Id).OrderBy(x => x.Order).ToListAsync();; foreach (var child in childs) { var added = await CreateMenuAsync(child, res, userName, roleName); if (added != null) { toAdd.Childs.Add(added); } } var access = await _mediator.Send(new CheckUserAccess(userName, menuResource.Id)); if ((access && menuResource.PageId is not null) || (toAdd.Childs.Any())) { if (menuResource.PageId is not null) { toAdd.Menu.Page = await _context.PageResources.AsNoTracking().SingleAsync(x => x.Id == menuResource.PageId); } return(toAdd); } return(null); }
private void GenerateSource(MenuResource menuResource, TextWriter writer) { // Calcula els offsets al elements del menu // itemOffsets = MenuUtils.GetOffsetDictionary(menuResource); writer.WriteLine("/*************************************************************************"); writer.WriteLine(" *"); writer.WriteLine(" * Archivo generado desde un archivo de recursos"); writer.WriteLine(" * No modificar!"); writer.WriteLine(" *"); writer.WriteLine(" * Fecha de generaciĆ³n : {0}", DateTime.Now); writer.WriteLine(" * Nombre del generador : {0}", "EosResourceCompiler"); writer.WriteLine(" * Version del generador: {0}", version); writer.WriteLine(" *"); writer.WriteLine(" ************************************************************************/"); writer.WriteLine(); writer.WriteLine(); writer.WriteLine("#include \"{0}.h\"", menuResource.Id); writer.WriteLine(); writer.WriteLine(); writer.WriteLine("const unsigned char menu{0}[] = {{", menuResource.Id); writer.WriteLine(); GenerateMenu(writer, menuResource.Menu); writer.WriteLine("};"); }
public CadForm(string[] args) { InitializeComponent(); // makes the cadCanvas and the propertiesExplorer KeyPreview = true; // used to filter the escape key (and maybe some more?) cadFrame = new CadFrame(propertiesExplorer, cadCanvas, this); cadFrame.ProgressAction = (show, percent, title) => { this.ProgressForm.ShowProgressBar(show, percent, title); }; cadCanvas.Frame = cadFrame; propertiesExplorer.Frame = cadFrame; // show this menu in the MainForm MenuWithHandler[] mainMenu = MenuResource.LoadMenuDefinition("SDI Menu", true, cadFrame); #region DebuggerPlayground, you can remove this region // in the following lines a "DebuggerPlayground" object is created via reflection. This class is a playground to write testcode // which is not included in the sources. This is why it is constructed via reflection, there is no need to have this class in the project. Type dbgplygnd = Type.GetType("CADability.Forms.DebuggerPlayground", false); if (dbgplygnd != null) { MethodInfo connect = dbgplygnd.GetMethod("Connect"); if (connect != null) { mainMenu = connect.Invoke(null, new object[] { cadFrame, mainMenu }) as MenuWithHandler[]; } } #endregion DebuggerPlayground Menu = MenuManager.MakeMainMenu(mainMenu); cadFrame.FormMenu = Menu; // open an existing Project or create a new one ToolBars.CreateOrRestoreToolbars(topToolStripContainer, cadFrame); Application.Idle += new EventHandler(OnIdle); // update the toolbars (menus are updated when they popup) }
private static void ScrapeMenu(StringBuilder language, StringBuilder normal, MenuResource menuRes) { int previousLanguageLength = language.Length; string headerComment = Comment; switch (menuRes.Template) { case MenuTemplate menu: ScrapeMenuItems(language, normal, menu.MenuItems, 0); headerComment += "MENU"; break; case MenuExTemplate menuEx: ScrapeMenuItems(language, normal, menuEx.MenuItems, 0); headerComment += "MENUEX"; break; } headerComment += $" : {menuRes.Name}{Environment.NewLine}{Environment.NewLine}"; if (normal.Length != 0) { normal.Insert(0, headerComment); } if (language.Length != previousLanguageLength) { language.Insert(previousLanguageLength, headerComment); language.Insert(previousLanguageLength, Environment.NewLine); } }
/// <summary> /// Compila el recurs. /// </summary> /// <param name="resource">Recurs del menu.</param> /// <param name="outputPath">Carpeta del fitxer de sortida.</param> /// <param name="parameters">Parametres de compilacio.</param> /// public void Compile(MenuResource resource, string outputPath, CompilerParameters parameters) { TextWriter writer; string fileName, path; if (resource == null) { throw new ArgumentNullException(nameof(resource)); } string outputBaseFileName = resource.Id; string outputExtension = defOutputExtension; string outputHeaderExtension = defOutputHeaderExtension; if (parameters != null) { if (parameters.Exists("output-extension")) { outputExtension = parameters["output-extension"]; } if (parameters.Exists("output-header-extension")) { outputHeaderExtension = parameters["output-header-extension"]; } } fileName = String.Format("{0}.{1}", outputBaseFileName, outputExtension); path = Path.Combine(outputPath, fileName); writer = new StreamWriter( new FileStream( path, FileMode.Create, FileAccess.Write, FileShare.None)); try { GenerateSource(resource, writer); } finally { writer.Close(); } fileName = String.Format("{0}.{1}", outputBaseFileName, outputHeaderExtension); path = Path.Combine(outputPath, fileName); writer = new StreamWriter( new FileStream( path, FileMode.Create, FileAccess.Write, FileShare.None)); try { GenerateHeader(resource, writer); } finally { writer.Close(); } }
public static IDictionary <Item, int> GetOffsetDictionary(MenuResource resource) { Dictionary <Item, int> offsets = new Dictionary <Item, int>(); OffsetVisitor visitor = new OffsetVisitor(offsets); visitor.Visit(resource.Menu); return(offsets); }
public static IList <string> GetCommandList(MenuResource resource) { List <string> commands = new List <string>(); CommandVisitor visitor = new CommandVisitor(commands); visitor.Visit(resource.Menu); return(commands); }
public override void Visit(MenuResource resource) { writer.WriteStartElement("menuResource"); writer.WriteAttributeString("resourceId", resource.Id); writer.WriteAttributeString("language", resource.Languaje); base.Visit(resource); writer.WriteEndElement(); }
/// <summary> /// Make a ToolStrip, which contains all the provided <paramref name="menuIds"/> and uses the provided <paramref name="commandHandler"/> /// </summary> /// <param name="menuIds">menu ids to display in thei toolstrip</param> /// <param name="commandHandler">command handler to handle the clicks on the buttons</param> /// <returns></returns> public static ToolStrip MakeToolStrip(string[] menuIds, string name, ICommandHandler commandHandler) { // there are two kinds of buttons: simple buttons (ToolStripButton), which immediately execute the command when clicked and // combo buttons (ToolStripSplitButton), which show a popup menu when clicked. The latter also may change their image to // display the last clicked menu item: if so, on click, they execute the last clicked menu item, if not, the show the popup menu. ToolStrip res = new ToolStrip(); res.Name = name; for (int i = 0; i < menuIds.Length; i++) { int ImageIndex = MenuResource.FindImageIndex(menuIds[i]); if (MenuResource.IsPopup(menuIds[i])) // this is a popup menu id. On click, we show the popup menu (sub menu) { ToolStripSplitButton btn = new ToolStripSplitButton(); TagInfo tagInfo = new TagInfo(menuIds[i], commandHandler, btn, true); btn.Tag = tagInfo; if (ImageIndex >= 0) { btn.DisplayStyle = ToolStripItemDisplayStyle.Image; btn.ImageScaling = ToolStripItemImageScaling.None; btn.Image = ButtonImages.ButtonImageList.Images[ImageIndex]; } else { btn.DisplayStyle = ToolStripItemDisplayStyle.Text; } btn.Name = StringTable.GetString(menuIds[i]); // not sure, what the name is used for btn.Size = new System.Drawing.Size(24, 24); btn.Text = StringTable.GetString(menuIds[i]); btn.Click += tagInfo.ButtonClicked; res.Items.Add(btn); } else { ToolStripButton btn = new ToolStripButton(); TagInfo tagInfo = new TagInfo(menuIds[i], commandHandler, btn); btn.Tag = tagInfo; if (ImageIndex >= 0) { btn.DisplayStyle = ToolStripItemDisplayStyle.Image; btn.ImageScaling = ToolStripItemImageScaling.None; btn.Image = ButtonImages.ButtonImageList.Images[ImageIndex]; } else { btn.DisplayStyle = ToolStripItemDisplayStyle.Text; } btn.Name = StringTable.GetString(menuIds[i]); btn.Size = new System.Drawing.Size(24, 24); btn.Text = StringTable.GetString(menuIds[i]); // will be shown as a tooltip btn.Click += tagInfo.ButtonClicked; res.Items.Add(btn); } } return(res); }
private string Handler_MenuRegex_Match(Match theMatch) { MenuResource aR = new MenuResource(); aR.Text = theMatch.Groups[2].Value; aR.ID = theMatch.Groups[4].Value; if (!myResourceDict.ContainsKey(aR.ID)) { myResourceDict.Add(aR.ID, aR); } return("MENUITEM" + theMatch.Groups[1].Value + "\"f\"," + theMatch.Groups[3].Value + aR.ID); }
bool ICommandHandler.OnCommand(string MenuId) { // ToolStripSplitButton create a popup menu, which is directed to this tag. // The ToolStripSplitButton contains the icon of the last selected menu item of the sub menu, // which will be used, when the button (and not the drop down part) of the ToolStripSplitButton is clicked. if (showLastSubMenu) { lastSubMenuId = MenuId; int ImageIndex = MenuResource.FindImageIndex(MenuId); if (ImageIndex >= 0) { parent.Image = ButtonImages.ButtonImageList.Images[ImageIndex]; } } return(commandHandler.OnCommand(MenuId)); }
public async Task Can_RoleAccess_To_Menu() { using (var ctx = await TestDbContext.Create(nameof(Can_RoleAccess_To_Menu))) { var mapper = new MapperConfiguration(cfg => cfg.AddProfile(new MappingProfile())); var menu = new MenuResource { Title = "someMenu", Icon = "", Name = "Mn1", Order = 1, }; var page = new PageResource { Link = "http://abc", Name = "p1", Title = "Some", }; menu.Page = page; ctx.MenuResources.Add(menu); ctx.PageResources.Add(page); await ctx.SaveChangesAsync(); Application.Access.GenericRoleToResourceHandler genericRoleToResourceHandler = new Application.Access.GenericRoleToResourceHandler(ctx, mapper.CreateMapper()); var mediator = new Mock <IMediator>(); mediator .Setup(m => m.Send(It.IsAny <RoleAccessToPage>(), It.IsAny <CancellationToken>())) .ReturnsAsync(true) .Verifiable(); var model = new AssignRoleToResourceDto("Role1", menu.Id, DotNetAccessControl.domain.enums.Permission.Allow); var handler = new AssignRoleToMenuHandler(genericRoleToResourceHandler, ctx, mediator.Object); var result = await handler.Handle(new RoleAccessToMenu(model, true), CancellationToken.None); var saved = await ctx.AccessControls.OfType <RoleAccessControl>().SingleAsync(x => x.ResourceId == menu.Id); Assert.Equal(model.RoleName, saved.RoleName); mediator.Verify(x => x.Send(It.IsAny <RoleAccessToPage>(), It.IsAny <CancellationToken>()), Times.Once); } }
internal void ButtonClicked(object sender, EventArgs e) { if (sender is ToolStripSplitButton) { ToolStripSplitButton btn = sender as ToolStripSplitButton; if (!btn.ButtonPressed || lastSubMenuId == "") { // clicked on the dropdown button, or first time click in the button ContextMenuWithHandler cm = MenuManager.MakeContextMenu(MenuResource.LoadMenuDefinition(menuId, false, this)); Control btnParent = parent.GetCurrentParent(); System.Drawing.Point pnt; if (!btnParent.Visible) { pnt = btnParent.PointToScreen(new System.Drawing.Point(btn.Bounds.Left, btn.Bounds.Bottom)); btnParent = Application.OpenForms[0]; pnt = btnParent.PointToClient(pnt); } else { pnt = new System.Drawing.Point(btn.Bounds.Left, btn.Bounds.Bottom); } cm.Show(btnParent, pnt); // if a menu item will be selected, the tagInfo.lastSubMenuId will be set to the selected menu item // and next time, tagInfo.lastSubMenuId will be executed imediately } else { // tagInfo.lastSubMenuId contains the menu id of the last selected menu item. This will be executed bool ok = commandHandler.OnCommand(lastSubMenuId); // if not ok, the command has not been handled } } else { bool ok = commandHandler.OnCommand(menuId); // if not ok, the command has not been handled } }
public static void Dump(MenuResource rc) { Console.WriteLine(rc.ToString()); }
public override void Visit(MenuResource resource) { MenuResourceCompiler compiler = new MenuResourceCompiler(); compiler.Compile(resource, outputFolder, parameters); }