Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Diff of /cmajor++/CmDevEnv/DevEnv/MainForm.cs [r570] .. [r571] Maximize Restore

  Switch to side-by-side view

--- a/cmajor++/CmDevEnv/DevEnv/MainForm.cs
+++ b/cmajor++/CmDevEnv/DevEnv/MainForm.cs
@@ -26,49 +26,57 @@
     {
         public MainForm()
         {
-            Application.AddMessageFilter(this);
-            progressChars = "|/-\\";
-            progressIndex = 0;
-            InitializeComponent();
-            editorTabControl = new XTabControl();
-            editorTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
-            editorTabControl.Location = new System.Drawing.Point(0, 0);
-            editorTabControl.Name = "editorTabControl";
-            editorTabControl.SelectedIndex = 0;
-            editorTabControl.Size = new System.Drawing.Size(1046, 325);
-            editorTabControl.TabIndex = 0;
-            editorTabControl.TabClosing += editorTabControl_TabClosing;
-            editorSplitContainer.Panel1.Controls.Add(editorTabControl);
-            configComboBox.SelectedIndex = 0;
-            backEndComboBox.SelectedIndex = 0;
-            SetMenuItemStatus();
-            string[] args = Environment.GetCommandLineArgs();
-            solutionExplorerTreeView.Sorted = true;
-            compiler = new Compiler();
-            compiler.CmcPath = Configuration.Instance.CmcPath;
-            compiler.CmcaPath = Configuration.Instance.CmcaPath;
-            compilerToUse = UseCompiler.cmc;
-            compiler.SetWriteMethod(this, WriteOutputLine);
-            compiler.SetHandleCompileResultMethod(this, HandleCompileResult);
-            executor = new Executor();
-            executor.SetWriteMethod(this, WriteToConsole);
-            executor.SetExecuteReadyMethod(this, ProjectRun);
-            debugger = new Debugger();
-            debugger.SetWriteToConsoleMethod(this, WriteToConsole);
-            debugger.SetWriteToDebuggerLogMethod(this, WriteToDebuggerLog);
-            console = new ConsoleWindow(executor, debugger);
-            consoleTabPage.Controls.Add(console);
-            processRunning = false;
-            buildInProgress = false;
-            compileAborted = false;
-            cmajorAppDataDirectory = Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), "Cmajor");
-            debuggerExecutionMode = DebuggerExecutionMode.continuousExececutionMode;
-            cmdbLogFileName = "C:/Temp/cmdb.log";
-            callStackReply = null;
-            toggleLibraryDebuggingStatusCommandEnabled = true;
-            if (args.Length > 1)
-            {
-                OpenProjectOrSolution(args[1]);
+            try
+            {
+                Application.AddMessageFilter(this);
+                progressChars = "|/-\\";
+                progressIndex = 0;
+                InitializeComponent();
+                editorTabControl = new XTabControl();
+                editorTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
+                editorTabControl.Location = new System.Drawing.Point(0, 0);
+                editorTabControl.Name = "editorTabControl";
+                editorTabControl.SelectedIndex = 0;
+                editorTabControl.Size = new System.Drawing.Size(1046, 325);
+                editorTabControl.TabIndex = 0;
+                editorTabControl.TabClosing += editorTabControl_TabClosing;
+                editorSplitContainer.Panel1.Controls.Add(editorTabControl);
+                configComboBox.SelectedIndex = 0;
+                backEndComboBox.SelectedIndex = 0;
+                SetMenuItemStatus();
+                string[] args = Environment.GetCommandLineArgs();
+                solutionExplorerTreeView.Sorted = true;
+                compiler = new Compiler();
+                compiler.CmcPath = Configuration.Instance.CmcPath;
+                compiler.CmcaPath = Configuration.Instance.CmcaPath;
+                compilerToUse = UseCompiler.cmc;
+                compiler.SetWriteMethod(this, WriteOutputLine);
+                compiler.SetHandleCompileResultMethod(this, HandleCompileResult);
+                executor = new Executor();
+                executor.SetWriteMethod(this, WriteToConsole);
+                executor.SetExecuteReadyMethod(this, ProjectRun);
+                debugger = new Debugger();
+                debugger.SetWriteToConsoleMethod(this, WriteToConsole);
+                debugger.SetWriteToDebuggerLogMethod(this, WriteToDebuggerLog);
+                console = new ConsoleWindow(executor, debugger);
+                consoleTabPage.Controls.Add(console);
+                processRunning = false;
+                buildInProgress = false;
+                compileAborted = false;
+                cmajorAppDataDirectory = Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), "Cmajor");
+                debuggerExecutionMode = DebuggerExecutionMode.continuousExececutionMode;
+                cmdbLogFileName = "C:/Temp/cmdb.log";
+                callStackReply = null;
+                toggleLibraryDebuggingStatusCommandEnabled = true;
+                toggleBreakOnThrowStatusCommandEnabled = true;
+                if (args.Length > 1)
+                {
+                    OpenProjectOrSolution(args[1]);
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message);
             }
         }
         private void SetState(State state)
@@ -107,60 +115,95 @@
         }
         private void MainForm_Shown(object sender, EventArgs e)
         {
-            SetState(State.editing);
-            Top = Math.Max(0, Configuration.Instance.FormTop);
-            Left = Math.Max(0, Configuration.Instance.FormLeft);
-            Width = Math.Max(0, Configuration.Instance.FormSizeX);
-            Height = Math.Max(0, Configuration.Instance.FormSizeY);
-            if (Configuration.Instance.ToolColWidth != 0) toolColumnHeader.Width = Configuration.Instance.ToolColWidth;
-            if (Configuration.Instance.CodeColWidth != 0) codeColumnHeader.Width = Configuration.Instance.CodeColWidth;
-            if (Configuration.Instance.DescriptionColWidth != 0) descriptionColumnHeader.Width = Configuration.Instance.DescriptionColWidth;
-            if (Configuration.Instance.FunctionColWidth != 0) funColumnHeader.Width = Configuration.Instance.FunctionColWidth;
-            if (Configuration.Instance.FileColWidth != 0) fileColumnHeader.Width = Configuration.Instance.FileColWidth;
-            if (Configuration.Instance.LineColWidth != 0) lineColumnHeader.Width = Configuration.Instance.LineColWidth;
-            if (Configuration.Instance.ColumnColWidth != 0) colColumnHeader.Width = Configuration.Instance.ColumnColWidth;
-            if (Configuration.Instance.ProjectColWidth != 0) projectColumnHeader.Width = Configuration.Instance.ProjectColWidth;
-            if (Configuration.Instance.FindFileColWidth != 0) findFileColumnHeader.Width = Configuration.Instance.FindFileColWidth;
-            if (Configuration.Instance.FindLineColWidth != 0) findLineColumnHeader.Width = Configuration.Instance.FindLineColWidth;
-            if (Configuration.Instance.FindProjectColWidth != 0) findProjectColumnHeader.Width = Configuration.Instance.FindProjectColWidth;
-            if (Configuration.Instance.FindTextColWidth != 0) findTextColumnHeader.Width = Configuration.Instance.FindTextColWidth;
-            if (Configuration.Instance.CallStackFrameColWidth != 0) callStackFrameColumnHeader.Width = Configuration.Instance.CallStackFrameColWidth;
-            if (Configuration.Instance.CallStackFunColWidth != 0) callStackFunColumnHeader.Width = Configuration.Instance.CallStackFunColWidth;
-            if (Configuration.Instance.CallStackFileColWidth != 0) callStackFileColumnHeader.Width = Configuration.Instance.CallStackFileColWidth;
-            if (Configuration.Instance.CallStackLineColWidth != 0) callStackLineColumnHeader.Width = Configuration.Instance.CallStackLineColWidth;
-            //editorSplitContainer.SplitterDistance = Configuration.Instance.HorizontalSplitterPos;
-            solutionExplorerTreeView.Width = 10;
-            //editorSplitContainer.SplitterMoved += editorSplitContainer_SplitterMoved;
-            splitter1.SplitPosition = Configuration.Instance.VerticalSplitterPos;
-            string windowState = Configuration.Instance.WindowState;
-            WindowState = windowState == "Normal" ? FormWindowState.Normal : windowState == "Maximized" ? FormWindowState.Maximized : FormWindowState.Normal;
-            Resize += new EventHandler(MainForm_Resize);
-            Move += new EventHandler(MainForm_Move);
-            SetupRecentProjectMenu();
-            infoTimer.Interval = 1000 * Configuration.Instance.InfoDelaySecs;
-            infoTimer.Tick += infoTimer_Tick;
+            try
+            {
+                SetState(State.editing);
+                Top = Math.Max(0, Configuration.Instance.FormTop);
+                Left = Math.Max(0, Configuration.Instance.FormLeft);
+                Width = Math.Max(0, Configuration.Instance.FormSizeX);
+                Height = Math.Max(0, Configuration.Instance.FormSizeY);
+                if (Configuration.Instance.ToolColWidth != 0) toolColumnHeader.Width = Configuration.Instance.ToolColWidth;
+                if (Configuration.Instance.CodeColWidth != 0) codeColumnHeader.Width = Configuration.Instance.CodeColWidth;
+                if (Configuration.Instance.DescriptionColWidth != 0) descriptionColumnHeader.Width = Configuration.Instance.DescriptionColWidth;
+                if (Configuration.Instance.FunctionColWidth != 0) funColumnHeader.Width = Configuration.Instance.FunctionColWidth;
+                if (Configuration.Instance.FileColWidth != 0) fileColumnHeader.Width = Configuration.Instance.FileColWidth;
+                if (Configuration.Instance.LineColWidth != 0) lineColumnHeader.Width = Configuration.Instance.LineColWidth;
+                if (Configuration.Instance.ColumnColWidth != 0) colColumnHeader.Width = Configuration.Instance.ColumnColWidth;
+                if (Configuration.Instance.ProjectColWidth != 0) projectColumnHeader.Width = Configuration.Instance.ProjectColWidth;
+                if (Configuration.Instance.FindFileColWidth != 0) findFileColumnHeader.Width = Configuration.Instance.FindFileColWidth;
+                if (Configuration.Instance.FindLineColWidth != 0) findLineColumnHeader.Width = Configuration.Instance.FindLineColWidth;
+                if (Configuration.Instance.FindProjectColWidth != 0) findProjectColumnHeader.Width = Configuration.Instance.FindProjectColWidth;
+                if (Configuration.Instance.FindTextColWidth != 0) findTextColumnHeader.Width = Configuration.Instance.FindTextColWidth;
+                if (Configuration.Instance.CallStackFrameColWidth != 0) callStackFrameColumnHeader.Width = Configuration.Instance.CallStackFrameColWidth;
+                if (Configuration.Instance.CallStackFunColWidth != 0) callStackFunColumnHeader.Width = Configuration.Instance.CallStackFunColWidth;
+                if (Configuration.Instance.CallStackFileColWidth != 0) callStackFileColumnHeader.Width = Configuration.Instance.CallStackFileColWidth;
+                if (Configuration.Instance.CallStackLineColWidth != 0) callStackLineColumnHeader.Width = Configuration.Instance.CallStackLineColWidth;
+                //editorSplitContainer.SplitterDistance = Configuration.Instance.HorizontalSplitterPos;
+                solutionExplorerTreeView.Width = 10;
+                //editorSplitContainer.SplitterMoved += editorSplitContainer_SplitterMoved;
+                splitter1.SplitPosition = Configuration.Instance.VerticalSplitterPos;
+                string windowState = Configuration.Instance.WindowState;
+                WindowState = windowState == "Normal" ? FormWindowState.Normal : windowState == "Maximized" ? FormWindowState.Maximized : FormWindowState.Normal;
+                Resize += new EventHandler(MainForm_Resize);
+                Move += new EventHandler(MainForm_Move);
+                SetupRecentProjectMenu();
+                infoTimer.Interval = 1000 * Configuration.Instance.InfoDelaySecs;
+                infoTimer.Tick += infoTimer_Tick;
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message);
+            }
         }
         private async void configComboBox_SelectedIndexChanged(object sender, EventArgs e)
         {
-            SetMenuItemStatus();
-            if (!readingSolutionConfig)
-            {
-                doNotChangeActiveConfig = true;
-                ReadWriteSolutionConfig();
-                doNotChangeActiveConfig = false;
-            }
-            await RetrieveLibraryInformation();
+            try
+            {
+                SetMenuItemStatus();
+                if (!readingSolutionConfig)
+                {
+                    doNotChangeActiveConfig = true;
+                    ReadWriteSolutionConfig();
+                    doNotChangeActiveConfig = false;
+                }
+                await RetrieveLibraryInformation();
+                if (solution != null && solution.ActiveProject != null)
+                {
+                    readingProjectSettings = true;
+                    ProjectConfig config = ProjectConfigurations.Instance.GetProjectConfig(solution.ActiveProject.GetConfigurationFilePath());
+                    breakOnThrowCheckBox.Checked = config.BreakOnThrow(configComboBox.Text + "." + backEndComboBox.Text.ToLower());
+                    readingProjectSettings = false;
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message);
+            }
         }
         private async void backEndComboBox_SelectedIndexChanged(object sender, EventArgs e)
         {
-            SetMenuItemStatus();
-            if (!readingSolutionConfig)
-            {
-                doNotChangeActiveConfig = true;
-                ReadWriteSolutionConfig();
-                doNotChangeActiveConfig = false;
-            }
-            await RetrieveLibraryInformation();
+            try
+            {
+                SetMenuItemStatus();
+                if (!readingSolutionConfig)
+                {
+                    doNotChangeActiveConfig = true;
+                    ReadWriteSolutionConfig();
+                    doNotChangeActiveConfig = false;
+                }
+                await RetrieveLibraryInformation();
+                if (solution != null && solution.ActiveProject != null)
+                {
+                    readingProjectSettings = true;
+                    ProjectConfig config = ProjectConfigurations.Instance.GetProjectConfig(solution.ActiveProject.GetConfigurationFilePath());
+                    breakOnThrowCheckBox.Checked = config.BreakOnThrow(configComboBox.Text + "." + backEndComboBox.Text.ToLower());
+                    readingProjectSettings = false;
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message);
+            }
         }
         void infoTimer_Tick(object sender, EventArgs e)
         {
@@ -321,6 +364,7 @@
             stepIntoToolStripMenuItem.Enabled = startContinueDebuggingPossible;
             stepOutToolStripMenuItem.Enabled = startContinueDebuggingPossible;
             inspectToolStripMenuItem.Enabled = startContinueDebuggingPossible;
+            breakOnThrowCheckBox.Enabled = backend == "c" && configComboBox.Text == "debug";
         }
         private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
         {
@@ -1418,6 +1462,10 @@
                 await SetupSolutionExplorer(null);
                 SetMenuItemStatus();
                 ReadWriteSolutionConfig();
+                readingProjectSettings = true;
+                ProjectConfig config = ProjectConfigurations.Instance.GetProjectConfig(solution.ActiveProject.GetConfigurationFilePath());
+                breakOnThrowCheckBox.Checked = config.BreakOnThrow(configComboBox.Text + "." + backEndComboBox.Text.ToLower());
+                readingProjectSettings = false;
             }
             catch (Exception ex)
             {
@@ -2302,6 +2350,20 @@
                 }
             }
         }
+        private async Task SetBreakOnThrowStatus()
+        {
+            bool breakOnThrow = breakOnThrowCheckBox.Checked;
+            DebuggerReply reply = await debugger.SetBreakOnThrowStatusAsync(breakOnThrow);
+            if (reply is BreakOnThrowStatusReply)
+            {
+                BreakOnThrowStatusReply status = (BreakOnThrowStatusReply)reply;
+                bool value = status.Enabled;
+            }
+            else if (reply is ErrorReply)
+            {
+                throw new Exception(reply.Text);
+            }
+        }
         private async Task StartDebugging()
         {
             console.Clear();
@@ -2323,6 +2385,7 @@
             {
                 await SetBreakpoints();
                 await SetDebugLibraryStatus();
+                await SetBreakOnThrowStatus();
             }
             EnableDebugCommands();
             if (reply is StartReply)
@@ -2493,7 +2556,7 @@
                 {
                     throw new Exception("Cannot toggle breakpoint while program is being run in continuous execution mode.");
                 }
-                DisableDebugCommands(false, true, false);
+                DisableDebugCommands(false, true, false, false);
                 Breakpoint oldBp = null;
                 Breakpoint newBp = null;
                 TabPage editorTabPage = editorTabControl.SelectedTab;
@@ -2772,9 +2835,9 @@
         }
         private void DisableDebugCommands()
         {
-            DisableDebugCommands(true, false, false);
-        }
-        private void DisableDebugCommands(bool invalidateCallStack, bool toggleBpCommand, bool toggleLibraryDebuggingStatusCommand)
+            DisableDebugCommands(true, false, false, false);
+        }
+        private void DisableDebugCommands(bool invalidateCallStack, bool toggleBpCommand, bool toggleLibraryDebuggingStatusCommand, bool toggleBreakOnThrowStatusCommand)
         {
             debugCommandRunning = true;
             startContinueButton.Enabled = false;
@@ -2793,6 +2856,10 @@
             if (!toggleLibraryDebuggingStatusCommand && debuggerExecutionMode == DebuggerExecutionMode.continuousExececutionMode)
             {
                 toggleLibraryDebuggingStatusCommandEnabled = false;
+            }
+            if (!toggleBreakOnThrowStatusCommand && debuggerExecutionMode == DebuggerExecutionMode.continuousExececutionMode)
+            {
+                toggleBreakOnThrowStatusCommandEnabled = false;
             }
             if (invalidateCallStack)
             {
@@ -2814,6 +2881,7 @@
             inspectToolStripMenuItem.Enabled = true;
             BpState.Instance.EnableTogglingBreakpoints();
             toggleLibraryDebuggingStatusCommandEnabled = true;
+            toggleBreakOnThrowStatusCommandEnabled = true;
         }
         private void ReadWriteSolutionConfig()
         {
@@ -2946,7 +3014,7 @@
                 {
                     ListViewItem selectedItem = callStackListView.SelectedItems[0];
                     int frameNumber = int.Parse(selectedItem.SubItems[0].Text);
-                    DisableDebugCommands(false, false, false);
+                    DisableDebugCommands(false, false, false, false);
                     DebuggerReply reply = await debugger.FrameAsync(frameNumber);
                     EnableDebugCommands();
                     if (reply is FrameReply)
@@ -3048,7 +3116,7 @@
                                 librariesListView.Items.Clear();
                                 ParserRepository.Instance.CmdbFileParser.Parse(File.ReadAllText(cmdbFilePath), 0, cmdbFilePath, solution.DebugInfo);
                                 ProjectConfig config = ProjectConfigurations.Instance.GetProjectConfig(project.GetConfigurationFilePath());
-                                Array<StringField> disabledLibraries = config.GetDisabledLibraries(configComboBox.Text);
+                                Array<StringField> disabledLibraries = config.GetDisabledLibraries(configComboBox.Text + "." + backEndComboBox.Text.ToLower());
                                 foreach (StringField disabledLibrary in disabledLibraries)
                                 {
                                     string disabledLibraryName = disabledLibrary.Value;
@@ -3152,7 +3220,7 @@
                         lib.Enabled = e.Item.Checked;
                         Project activeProject = solution.ActiveProject;
                         ProjectConfig config = ProjectConfigurations.Instance.GetProjectConfig(activeProject.GetConfigurationFilePath());
-                        Array<StringField> disabledLibraries = config.GetDisabledLibraries(configComboBox.Text);
+                        Array<StringField> disabledLibraries = config.GetDisabledLibraries(configComboBox.Text + "." + backEndComboBox.Text.ToLower());
                         disabledLibraries.Clear();
                         foreach (DebugLibrary debugLib in solution.DebugInfo.DebugLibraries)
                         {
@@ -3166,7 +3234,16 @@
                         ProjectConfigurations.Instance.SaveProjectConfig(activeProject.GetConfigurationFilePath(), config);
                         if (state == State.debugging)
                         {
-                            DebuggerReply reply = await debugger.SetDebugLibraryStatusAsync(lib.Name, lib.Enabled);
+                            DisableDebugCommands(false, false, true, false);
+                            DebuggerReply reply = null;
+                            try
+                            {
+                                reply = await debugger.SetDebugLibraryStatusAsync(lib.Name, lib.Enabled);
+                            }
+                            finally
+                            {
+                                EnableDebugCommands();
+                            }
                             if (reply is DebugLibraryStatusReply)
                             {
                                 DebugLibraryStatusReply debugLibraryStatusReply = (DebugLibraryStatusReply)reply;
@@ -3185,6 +3262,60 @@
                 {
                     e.Item.Checked = !e.Item.Checked;
                     cancelingLibraryDebuggingStatusChange = false;
+                }
+                MessageBox.Show(ex.Message);
+            }
+        }
+        private async void breakOnThrowCheckBox_CheckedChanged(object sender, EventArgs e)
+        {
+            try
+            {
+                if (!readingProjectSettings)
+                {
+                    if (!cancelingBreakOnThrowStatusChanged)
+                    {
+                        if (!toggleBreakOnThrowStatusCommandEnabled)
+                        {
+                            cancelingBreakOnThrowStatusChanged = true;
+                            throw new Exception("Cannot change break on throw status while program is being run in continuous execution mode.");
+                        }
+                        if (solution != null && solution.ActiveProject != null)
+                        {
+                            ProjectConfig config = ProjectConfigurations.Instance.GetProjectConfig(solution.ActiveProject.GetConfigurationFilePath());
+                            config.SetBreakOnThrow(configComboBox.Text + "." + backEndComboBox.Text.ToLower(), breakOnThrowCheckBox.Checked);
+                            ProjectConfigurations.Instance.SaveProjectConfig(solution.ActiveProject.GetConfigurationFilePath(), config);
+                            if (state == State.debugging)
+                            {
+                                DisableDebugCommands(false, false, false, true);
+                                DebuggerReply reply = null;
+                                try
+                                {
+                                    reply = await debugger.SetBreakOnThrowStatusAsync(breakOnThrowCheckBox.Checked);
+                                }
+                                finally
+                                {
+                                    EnableDebugCommands();
+                                }
+                                if (reply is BreakOnThrowStatusReply)
+                                {
+                                    BreakOnThrowStatusReply status = (BreakOnThrowStatusReply)reply;
+                                    bool enabled = status.Enabled;
+                                }
+                                else if (reply is ErrorReply)
+                                {
+                                    throw new Exception(reply.Text);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                if (cancelingBreakOnThrowStatusChanged)
+                {
+                    breakOnThrowCheckBox.Checked = !breakOnThrowCheckBox.Checked;
+                    cancelingBreakOnThrowStatusChanged = false;
                 }
                 MessageBox.Show(ex.Message);
             }
@@ -3232,6 +3363,9 @@
         private bool debugCommandRunning;
         private bool toggleLibraryDebuggingStatusCommandEnabled;
         private bool cancelingLibraryDebuggingStatusChange;
+        private bool toggleBreakOnThrowStatusCommandEnabled;
+        private bool cancelingBreakOnThrowStatusChanged;
+        private bool readingProjectSettings;
     }
 
     public static class KeyboardUtil