public void ProfileTabSelectedHandler(ProfileViewControl sender, ProfileTabSelectAction action)
 {
     if (null != ProfileTabSelect)
     {
         ProfileTabSelect(sender, action);                           // Fire event
     }
 }
Exemple #2
0
        private void ProfileTabSelect(object sender, ProfileTabControl.ProfileTabSelectAction action)
        {
            if (!Ready)
            {
                return;
            }

            ProfileViewControl pvc_sender = (ProfileViewControl)sender;

            switch (action)
            {
            case ProfileTabControl.ProfileTabSelectAction.Selecting:
                UpdateDuration();
                profs.SaveProfile(SelectedProfileInfo);     // save current tab's profile
                break;

            case ProfileTabControl.ProfileTabSelectAction.Created:
                pvc_sender.SetProfileList(profs.GetProfileList(), null);
                succession.SuccessionList.Add(new SuccessionEntry());     // Adds new succession entry without profile selection
                succession.ActiveIndex = ptc.IndexOf(pvc_sender);
                break;

            case ProfileTabControl.ProfileTabSelectAction.Selected:
                profs.LoadProfile(pvc_sender.ProfileInfo.ProfileName, pvc_sender.ProfileInfo);
                succession.ActiveIndex = ptc.IndexOf(pvc_sender);
                break;

            case ProfileTabControl.ProfileTabSelectAction.Deleting:
                UpdateDuration();
                succession.SuccessionList.RemoveAt(ptc.IndexOf(pvc_sender));
                break;

            default: break;
            }
        }
 /// <summary>
 /// Fetches the tab index of the given object
 /// </summary>
 /// <param name="pvc">Object to search for</param>
 /// <returns>-1 on failure, otherwise tab index</returns>
 public int IndexOf(ProfileViewControl pvc)
 {
     for (int i = 0; i < TabPages.Count; i++)
     {
         if ((ProfileViewControl)TabPages[i].Controls["pvc"] == pvc)
         {
             return(i);
         }
     }
     return(-1);
 }
Exemple #4
0
        private void SelectedProfileChanged(object sender, ProfileViewControl.SelectedProfileChangedCauseType cause)
        {
            UpdateDuration();

            ProfileViewControl pvc_sender = (ProfileViewControl)sender;

            if (cause != ProfileViewControl.SelectedProfileChangedCauseType.Delete)
            {
                profs.SaveProfile(pvc_sender.ProfileInfo); // save currently selected profile
            }
            profs.LoadProfile(pvc_sender.SelectedProfile, pvc_sender.ProfileInfo);
            succession.SuccessionList[ptc.IndexOf(pvc_sender)].ProfileSelected = pvc_sender.SelectedProfile;
        }
        /// <summary>
        /// Creates a new ProfileViewControl in a new tab.
        /// Reminder: If the tab is not selected after creation, the control's initialization is postponed!
        ///           "Controls contained in a TabPage are not created until the tab page is shown,
        ///           and any data bindings in these controls are not activated until the tab page is shown."
        ///           Microsoft - https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.tabpage?view=netframework-4.8
        /// </summary>
        /// <returns>Created instance</returns>
        public ProfileViewControl ProfileTabCreate()
        {
            // Workaround: TabPage size calculation incorrect...
            //   - first tab when created programmatically during Form init uses wrong TabPage size
            //   - one can see then halting with debugger at next code line that tab sizes are different
            //   - selected tab has correct size, info from: https://stackoverflow.com/questions/56242122/c-sharp-winforms-tabpage-size-and-clientsize-wrong
            //   (same issue:) https://stackoverflow.com/questions/29939232/anchor-failed-with-tab-page
            //   (same issue:) https://social.msdn.microsoft.com/Forums/en-US/6fa5e92a-8ab1-41cb-a348-23a8f3bad48c/problem-with-anchor-in-a-inherited-user-control?forum=netfxcompact
            // Solution here: force Size of all tabs to be equal when creating a new one
            //   (from: https://stackoverflow.com/questions/56242122/c-sharp-winforms-tabpage-size-and-clientsize-wrong )
            System.Drawing.Size same = SelectedTab.Size;
            for (int i = TabPages.Count - 1; 0 <= i; i--)
            {
                TabPages[i].Size = same;
            }

            for (int i = TabPages.Count - 1; 0 <= i; i--)
            {
                if (TabPages[i].Text.Equals("+")) // Search for "New" tab
                {
                    Control template = TabPages[i - 1].Controls["pvc"];

                    // Reuse the "New" tab for the actual new page and create an new "New" tab (skips tab selection)
                    TabPages[i].Text = (i + 1).ToString();

                    // Fill controls of the tab
                    ProfileViewControl pvc_new = new ProfileViewControl();
                    pvc_new.Anchor   = template.Anchor;
                    pvc_new.Location = template.Location;
                    pvc_new.Name     = "pvc";
                    pvc_new.Size     = template.Size;
                    pvc_new.TabIndex = 0;
                    pvc_new.ProfileInfo.ProfileChanged += PVC_ProfileChangedHandler;
                    pvc_new.SelectedProfileChanged     += PVC_SelectedProfileChangedHandler;
                    pvc_new.UpdateDarkMode();

                    TabPages[i].Controls.Add(pvc_new);
                    TabPages.Insert(i + 1, "+");
                    TabPages[i + 1].ToolTipText = TabPages[i].ToolTipText;
                    TabPages[i].ToolTipText     = null;

                    ProfileTabSelectedHandler(pvc_new, ProfileTabSelectAction.Created);
                    return(pvc_new);
                }
            }

            return(null);
        }
        public void TabSelectingHandler(object sender, TabControlCancelEventArgs e)
        {
            if (e.TabPage.Text.Equals("-")) // Switch to tab?
            {
                e.Cancel = true;            // "Delete" tab cannot be selected
                return;
            }

            if (e.TabPage.Text.Equals("+")) // Create new tab?
            {
                if (ReadOnlyMode)
                {
                    System.Media.SystemSounds.Beep.Play();
                    e.Cancel = true; // control not editable
                    return;
                }

                if (!SuccessionActive && InitDone) // Show initial warning message only when succession is not already active (and not during initialization)
                {
                    DialogResult result = MessageBox.Show(
                        "Opening further tabs combine multiple profiles into one run. " +
                        "Best known as a trilogy run for Dark Souls 1 to 3.\n\n" +
                        "There is a separate attempts counter. All profiles' attempts counters are paused.\n\n" +
                        "Please BE AWARE the Reset and PB buttons/hotkeys will apply to ALL open profiles! " +
                        "For example, pressing reset will reset all the selected profiles of all available tabs!\n\n" +
                        "OK = I understand, continue using tabs\n" +
                        "Cancel = Ups, I better stick with one tab only",
                        "Succession", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    if (result != DialogResult.OK)
                    {
                        e.Cancel = true; // Action aborted
                        return;
                    }
                }

                ProfileTabSelectedHandler(null, ProfileTabSelectAction.Selecting);
                SelectedProfileViewControl = ProfileTabCreate(); // Create and redirect interaction to selected tab
            }
            else
            {
                ProfileTabSelectedHandler(null, ProfileTabSelectAction.Selecting);
                SelectedProfileViewControl = (ProfileViewControl)e.TabPage.Controls["pvc"]; // redirect interaction to selected tab
            }

            ProfileTabSelectedHandler(SelectedProfileViewControl, ProfileTabSelectAction.Selected);
        }