Пример #1
0
        private void TabbedUI_FormClosing(object sender, FormClosingEventArgs e)
        {
            cancelling = false;
            if (!cancelling)
            {
                int index = 0;
                foreach (TabPage page in tabControl1.TabPages)
                {
                    tabControl1.SelectedIndex = index;
                    foreach (Control control in page.Controls)
                    {
                        if (control.Name == "EDITORCONTROL")
                        {
                            EditorControl castAsEditor = (EditorControl)control;
                            if (castAsEditor.HasChanges == true)
                            {
                                DialogResult dr = MessageBox.Show(string.Format("{0} has unsaved changes. Would you like to save them?", Path.GetFileName(castAsEditor.CurrentFile)),
                                                                  "BasicScriptingLanguage Editor",
                                                                  MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
                                if (dr == System.Windows.Forms.DialogResult.Yes)
                                {
                                    //save
                                    if (castAsEditor.CurrentFile == "New Document")
                                    {
                                        if (SaveAs() == DialogResult.Cancel)
                                        {
                                            e.Cancel = true;
                                        }
                                        else
                                        {
                                            e.Cancel = false;
                                        }
                                    }
                                    else
                                    {
                                        if (File.Exists(castAsEditor.CurrentFile))
                                        {
                                            castAsEditor.SaveFile(castAsEditor.CurrentFile);
                                            e.Cancel = false;
                                        }
                                        else
                                        if (SaveAs() == DialogResult.Cancel)
                                        {
                                            e.Cancel = true;
                                        }
                                        else
                                        {
                                            e.Cancel = false;
                                        }
                                    }
                                }
                                else if (dr == System.Windows.Forms.DialogResult.No)
                                {
                                    e.Cancel = false;
                                }
                                else if (dr == System.Windows.Forms.DialogResult.Cancel)
                                {
                                    e.Cancel   = true;
                                    cancelling = true;
                                }
                            }
                            //
                        }
                        //
                    }
                    index++;
                }
            }
            int           index2            = 0;
            List <string> FilesToBeReopened = new List <string>();

            foreach (var page in tabControl1.TabPages)
            {
                tabControl1.SelectedIndex = index2;
                EditorControl tabControlsEditor = (EditorControl)tabControl1.TabPages[tabControl1.SelectedIndex].Controls.Find("EDITORCONTROL", true)[0];

                if (tabControlsEditor.CurrentFile != "New Document")
                {
                    FilesToBeReopened.Add(tabControlsEditor.CurrentFile);
                }

                index2++;
            }
            string built = "";

            for (int i = 0; i < FilesToBeReopened.Count(); i++)
            {
                if (i == (FilesToBeReopened.Count() - 1))
                {
                    built += "\"" + FilesToBeReopened[i] + "\"";
                }
                else
                {
                    built += "\"" + FilesToBeReopened[i] + "\",";
                }
            }
            if (built != "")
            {
                MainSettingsManager.MainIniFile.WriteValue("Settings", "AlreadyOpenFiles", built);
            }
            //
        }
Пример #2
0
        //close tab
        private void menuItem18_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex != -1)
            {
                int newSelected = tabControl1.SelectedIndex - 1;

                if (newSelected == -1)
                {
                    newSelected = 0;
                }

                EditorControl editor       = (EditorControl)tabControl1.TabPages[tabControl1.SelectedIndex].Controls.Find("EDITORCONTROL", false)[0];
                bool          isCancelling = false;

                if (editor.HasChanges)
                {
                    DialogResult dr = MessageBox.Show(Path.GetFileName(editor.CurrentFile) + " has unsaved changes, do you wish to save them before exiting?",
                                                      "BasicScriptingLanguage Editor",
                                                      MessageBoxButtons.YesNoCancel,
                                                      MessageBoxIcon.Information);
                    if (dr == System.Windows.Forms.DialogResult.Yes)
                    {
                        if (editor.CurrentFile == "New Document")
                        {
                            if (SaveAs() == System.Windows.Forms.DialogResult.Cancel)
                            {
                                isCancelling = true;
                            }
                            else
                            {
                                isCancelling = false;
                            }
                        }
                        else
                        {
                            if (File.Exists(editor.CurrentFile))
                            {
                                editor.SaveFile(editor.CurrentFile);
                            }
                        }
                    }
                    else if (dr == System.Windows.Forms.DialogResult.No)
                    {
                        isCancelling = false;
                    }
                    else if (dr == System.Windows.Forms.DialogResult.Cancel)
                    {
                        isCancelling = true;
                    }
                    ;
                }

                if (!isCancelling)
                {
                    tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex);
                    try
                    {
                        tabControl1.SelectedIndex = newSelected;
                    }
                    catch
                    { /*nothing*/ }
                }

                if (tabControl1.TabPages.Count == 0)
                {
                    tabControl1.Visible = false;
                }
            }
        }