Пример #1
0
        private void ReLoadIssueMenu(ToolStripMenuItem menu, DTO.WorkDatas.Issue issue)
        {
            this.Utils.Safe(this.MainMenu, () =>
            {
                menu.Text  = $"{issue.Key} :: {issue.Summary}";
                menu.Image = (Recursos.Get <Icon>($"Priority{issue.Priority}") ?? Resources.refresh).ToBitmap();

                // Ver
                if (!menu.SubMenus(p => p.Text == "Ver").Any())
                {
                    menu.DropDownItems.Add(new ToolStripMenuItem("Ver", Resources.scroll_view.ToBitmap(), (sender, e) => this.Utils.Action.OpenIssue(sender.GetTag <DTO.WorkDatas.Issue>())).Do(m => m.Tag = issue));
                }

                // Cargar Horas
                if (!menu.SubMenus(p => p.Text == "Registrar Trabajo").Any())
                {
                    menu.DropDownItems.Add(new ToolStripMenuItem("Registrar Trabajo", Resources.stopwatch.ToBitmap(), (sender, e) =>
                                                                 this.Utils.Safe(this.Utils.MainForm, () => { new Forms.Tools.RegisterWork(sender.GetTag <string>()).ShowDialog(); })).Do(m => m.Tag = issue.Key)
                                           );
                }

                // Abrir en Explorador
                if (!menu.SubMenus(p => p.Text == "Abrir en Explorador").Any())
                {
                    menu.DropDownItems.Add(this.Utils.Menu.CreateOpenUrlMenu("Abrir en Explorador", BLL.Factory.Jira.Config.GetIssueUrl(issue.Key)));
                }

                // Adjuntos (index:1)
                var mAdjuntos = menu.SubMenus(p => p.Text == "Adjuntos").SingleOrDefault();
                if (mAdjuntos == null)
                {
                    menu.DropDownItems.Add(mAdjuntos = new ToolStripMenuItem("Adjuntos", Resources.books.ToBitmap()));
                }
                mAdjuntos.Visible = issue.Adjuntos.Count > 0;

                if (issue.Adjuntos.Count > 0)
                {
                    mAdjuntos.RemoveMenus(p => !issue.Adjuntos.Select(a => a.Filename).Contains(((DTO.WorkDatas.Attachment)p.Tag).Filename));   // elimino los menús de archivos que ya no están mas

                    foreach (var adj in issue.Adjuntos.Where(p => !mAdjuntos.SubMenus().Select(a => ((DTO.WorkDatas.Attachment)a.Tag).Filename).Contains(p.Filename)))
                    {
                        mAdjuntos.DropDownItems.Add(
                            this.Utils.Menu.CreateOpenUrlMenu(adj.Filename, adj.Content, Recursos.GetImageForFile(adj.Filename, adj.MimeType)).Do(m => m.Tag = adj)
                            );
                    }
                }

                // Transiciones (index:2)
                var mTransicion = menu.SubMenus(p => p.Text == "Mover").SingleOrDefault();
                if (mTransicion == null)
                {
                    menu.DropDownItems.Add(mTransicion = new ToolStripMenuItem("Mover", Resources.navigate_right.ToBitmap()));
                }
                mTransicion.Visible = (issue.Transitions?.Count ?? 0) > 0;

                if ((issue.Transitions?.Count ?? 0) > 0)
                {
                    foreach (var m in mTransicion.SubMenus())   // oculto todos los submenús
                    {
                        m.Visible = false;
                    }

                    foreach (var tran in issue.Transitions)
                    {
                        var mExists = mTransicion.SubMenus(m => ((DTO.WorkDatas.Transition)m.GetTag <dynamic>().tran).Id == tran.Id).SingleOrDefault();

                        if (mExists != null)
                        {
                            mExists.Visible = true;
                        }
                        else
                        {
                            mTransicion.DropDownItems.Add(this.Utils.Menu.CreateTransitionMenu(issue, tran));
                        }
                    }
                }
            });
        }