Пример #1
0
        private void timetableControl1_TimetableMouseClick(object sender, TimetableEventArgs e)
        {
            FindClickDetails(e);
            
            if (e.Button == MouseButtons.Right)
            {
                // no current timetable
                if (Timetable_ == null)
                {
                    findClassHereToolStripMenuItem.Enabled = false;
                    unavailabilityToolStripMenuItem.Enabled = false;
                    timeMenu.Show(timetableControl1, e.Location);
                }

                // right clicked empty space?
                else if (ClickSession_ == null && ClickUnavail_ == null)
                {
                    findClassHereToolStripMenuItem.DropDownItems.Clear();

                    // populate list of options at this time
                    List<ToolStripMenuItem> required = new List<ToolStripMenuItem>();
                    List<ToolStripMenuItem> ignored = new List<ToolStripMenuItem>();
                    foreach (Subject subject in Timetable_.SubjectList)
                    {
                        foreach (Type type in subject.Types)
                        {
                            for (int i = 0; i < type.UniqueStreams.Count; i++)
                            {
                                Stream stream = type.UniqueStreams[i];
                                bool atTime = false;
                                foreach (Session session in stream.Classes)
                                {
                                    if (ClickTime_ >= session.Start && ClickTime_ <= session.End)
                                    {
                                        atTime = true;
                                        break;
                                    }
                                }
                                if (!atTime)
                                    continue;

                                ToolStripMenuItem item = new ToolStripMenuItem(stream.Type.Subject.ToString() + " " + stream.ToString());
                                item.MouseEnter += delegate { timetableControl1.PreviewAlt(stream); };
                                item.MouseLeave += delegate { timetableControl1.EndPreviewStream(); };
                                item.Click += delegate
                                {
                                    if (!Timetable_.SelectStream(stream))
                                        return;
                                    MadeChanges(true);
                                };
                                if (!Timetable_.Fits(stream))
                                    item.ForeColor = Color.Gray;

                                if (type.Required)
                                    required.Add(item);
                                else
                                    ignored.Add(item);
                            }
                        }
                    }
                    if (required.Count > 0)
                    {
                        findClassHereToolStripMenuItem.DropDownItems.AddRange(required.ToArray());
                        if (ignored.Count > 0)
                            findClassHereToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator());
                    }
                    if (ignored.Count > 0)
                    {
                        findClassHereToolStripMenuItem.DropDownItems.AddRange(ignored.ToArray());
                    }
                    findClassHereToolStripMenuItem.Enabled = (required.Count > 0 || ignored.Count > 0);
                    unavailabilityToolStripMenuItem.Enabled = true;

                    timeMenu.Show(timetableControl1, e.Location);
                }

                // right clicked a session
                else if (ClickSession_ != null)
                {
                    alternativeToolStripMenuItem.DropDownItems.Clear();
                    equivalentToolStripMenuItem.DropDownItems.Clear();

                    timetableControl1.SetActive(ClickSession_.Stream);

                    // populate alternative options menu
                    // NOTE: lambda-style delegates do not work with foreach
                    int n = 0;
                    for (int i = 0; i < ClickSession_.Stream.Type.UniqueStreams.Count; i++)
                    {
                        Stream alt = ClickSession_.Stream.Type.UniqueStreams[i];
                        if (alt == ClickSession_.Stream || ClickSession_.Stream.Equivalent.Contains(alt))
                            continue;
                        ToolStripMenuItem item = new ToolStripMenuItem(alt.ToString());
                        item.MouseEnter += delegate { timetableControl1.PreviewAlt(alt); };
                        item.MouseLeave += delegate { timetableControl1.EndPreviewStream(); };
                        item.Click += delegate
                        {
                            if (!Timetable_.SelectStream(alt))
                                return;
                            MadeChanges(true);
                        };
                        if (!Timetable_.Fits(alt))
                            item.ForeColor = Color.Gray;

                        alternativeToolStripMenuItem.DropDownItems.Add(item);
                        n++;
                    }
                    alternativeToolStripMenuItem.Enabled = (n != 0);

                    // populate equivalent options menu
                    n = 0;
                    for (int i = 0; i < ClickSession_.Stream.Equivalent.Count; i++)
                    {
                        Stream equiv = ClickSession_.Stream.Equivalent[i];
                        ToolStripMenuItem item = new ToolStripMenuItem(equiv.ToString());
                        item.MouseEnter += delegate { timetableControl1.PreviewEquiv(equiv); };
                        item.MouseLeave += delegate { timetableControl1.EndPreviewStream(); };
                        item.Click += delegate
                        {
                            if (!Timetable_.SelectStream(equiv))
                                return;
                            MadeChanges(true);
                        };
                        equivalentToolStripMenuItem.DropDownItems.Add(item);
                        n++;
                    }
                    equivalentToolStripMenuItem.Enabled = (n != 0);

                    streamMenu.Show(timetableControl1, e.Location);
                }

                // right clicked an unavailability
                else
                {
                    timetableControl1.SetActive(ClickUnavail_);

                    unavailableMenu.Show(timetableControl1, e.Location);
                }
            }
            else if (e.Button == MouseButtons.Middle)
            {
            }
        }
Пример #2
0
 private void timetableControl1_TimetableMouseDoubleClick(object sender, TimetableEventArgs e)
 {
     // disable doucle click edit for now - conflicts with internal mouseup for dragging
     //FindClickDetails(e);
     //EditUnavailable();
 }
Пример #3
0
 private void FindClickDetails(TimetableEventArgs e)
 {
     ClickTime_ = e.Time;
     if (Timetable_ == null)
     {
         ClickSession_ = null;
         ClickUnavail_ = null;
     }
     else
     {
         ClickSession_ = Timetable_.FindClassAt(ClickTime_, true);
         ClickUnavail_ = Timetable_.FindUnavailableAt(ClickTime_);
     }
 }