예제 #1
0
        /// <summary>
        /// Updates the icon of the taskbar button
        /// </summary>
        public void UpdateIcon()
        {
            switch (DiscardCycle.DryRun(Program.GetDiscardDirectories().Select(i => new DirectoryInfo(i)), 0)
                    .DiscardFiles
                    .OrderBy(i => i.DaysLeft)
                    .FirstOrDefault()?
                    .DaysLeft ?? 3
                    )
            {
            case int n when n <= 0:
                _icon.Icon = Properties.Resources.DiscardError;
                _icon.Text = "One or more files are overdue for deletion";
                break;

            case 1:
                _icon.Icon = Properties.Resources.DiscardWarning;
                _icon.Text = "One or more files will be deleted tomorrow";
                break;

            default:
                _icon.Icon = Properties.Resources.DiscardOK;
#if DEBUG
                _icon.Text = "Discard (Debug Mode)";
#else
                _icon.Text = "Discard";
#endif
                break;
            }
        }
예제 #2
0
        /// <summary>
        /// Regenerates the menu
        /// </summary>
        /// <returns></returns>
        private ContextMenuStrip GenerateContext()
        {
            //Clear existing items
            _context.Items.Clear();

            /*
             * FILES
             */

            //Fetches discard files
            DiscardCycle cycle = DiscardCycle.DryRun(Program.GetDiscardDirectories().Select(i => new DirectoryInfo(i)), 0);

            /*
             * Add tracked files
             */
            IEnumerable <IGrouping <int, DiscardFile> > trackedFiles = cycle.DiscardFiles
                                                                       .Where(i => !i.Untracked)
                                                                       .GroupBy(i => i.DaysLeft)
                                                                       .OrderBy(i => i.Key);

            foreach (IGrouping <int, DiscardFile> group in trackedFiles)
            {
                //Day header
                _context.Items.Add("-");
                ToolStripMenuItem header = new ToolStripMenuItem(group.Key + (Math.Abs(group.Key) == 1 ? " day" : " days"))
                {
                    Font = _boldFont,
                };

                switch (group.Key)
                {
                case int i when(i <= 0):
                    header.ForeColor = Color.Red;

                    header.BackColor = Color.Pink;
                    break;

                case 1:
                    header.BackColor = Color.Wheat;
                    break;

                case int i when(i > Properties.Settings.Default.DefaultDays):
                    header.ForeColor = Color.FromArgb(75, 75, 75);

                    break;
                }

                _context.Items.Add(header);

                foreach (DiscardFile i in group)
                {
                    if (group.Count() >= 8)
                    {
                        header.DropDownItems.Add(CreateContextMenuForDiscardFile(i));
                    }
                    else
                    {
                        _context.Items.Add(CreateContextMenuForDiscardFile(i));
                    }
                }
            }

            /*
             * Add untracked files
             */
            IEnumerable <DiscardFile> untrackedFiles = cycle.DiscardFiles
                                                       .Where(i => i.Untracked);

            if (untrackedFiles.Any())
            {
                _context.Items.Add("-");

                ToolStripMenuItem header = new ToolStripMenuItem("Untracked")
                {
                    Font      = _boldFont,
                    ForeColor = Color.DodgerBlue,
                    BackColor = Color.LightSkyBlue
                };

                _context.Items.Add(header);

                foreach (DiscardFile i in untrackedFiles)
                {
                    if (untrackedFiles.Count() >= 8)
                    {
                        _context.Items.Add(CreateContextMenuForDiscardFile(i));
                    }
                    else
                    {
                        _context.Items.Add(CreateContextMenuForDiscardFile(i));
                    }
                }
            }



            /*
             * The other stuff
             */
            _context.Items.Add("-");
            _context.Items.Add("&Settings...", null, (s, e) => new Settings().ShowDialog());
            _context.Items.Add("&Create...", null, (s, e) => new CreateFileDialog().ShowDialog()).Enabled = Program.GetDiscardDirectories().Any();

            //Open button
            _context.Items.Add("&Open...", null).Enabled = Program.GetDiscardDirectories().Any();
            {
                ToolStripMenuItem last = (ToolStripMenuItem)_context.Items[_context.Items.Count - 1];
                foreach (string i in Program.GetDiscardDirectories())
                {
                    last.DropDownItems.Add(i, null, (s, e) => Process.Start(i));
                }
            }

            _context.Items.Add("-");
            _context.Items.Add("Exit", null, (s, e) => Application.Exit());

            return(_context);
        }