context: // **********************************************************************
  //
  // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
  //
  // This copy of Ice is licensed to you under the terms described in the
  // ICE_LICENSE file included in this distribution.
  //
  // **********************************************************************
  
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.IO;
  using System.Text;
  using System.Windows.Forms;
  using System.Globalization;
  using EnvDTE;
  
  namespace Ice.VisualStudio
  {
      public partial class IceCppConfigurationDialog : Form, IceConfigurationDialog
      {
          public IceCppConfigurationDialog(Project project)
          {
              InitializeComponent();            
              _project = project;
  
              outputDirView.init(this, _project);
              includePathView.init(this, _project);
              extraCompilerOptions.init(this, project);
              
              //
              // Set the toolTip messages.
              //
              
              toolTip.SetToolTip(chkStreaming, "Generate marshaling support for stream API (--stream).");
              toolTip.SetToolTip(chkChecksum, "Generate checksums for Slice definitions (--checksum).");
              toolTip.SetToolTip(chkIcePrefix, "Permit Ice prefixes (--ice).");
  
              if(_project != null)
              {
                  this.Text = "Ice Configuration - Project: " + _project.Name;
                  bool enabled = Util.isSliceBuilderEnabled(project);
                  setEnabled(enabled);
                  chkEnableBuilder.Checked = enabled;
                  load();
                  _initialized = true;
              }
              chkEnableBuilder.Focus();
          }
  
  #region IceConfigurationDialog interface
          public bool editingIncludeDir()
          {
              return includePathView.editingIncludeDir();
          }
  
          public void endEditIncludeDir(bool saveChanges)
          {
              includePathView.endEditIncludeDir(saveChanges);
          }
  
          public void needSave()
          {
              if(_initialized)
              {
                  btnApply.Enabled = hasUnsavedChanges();
              }
          }
  
          public void unsetCancelButton()
          {
              CancelButton = null;
          }
  
          public void setCancelButton()
          {
              CancelButton = btnCancel;
          }
  #endregion IceConfigurationDialog interface
          
          private void load()
          {
              if(_project == null)
              {
                  return;
              }
              Cursor = Cursors.WaitCursor;
  
              outputDirView.load();
              extraCompilerOptions.load();
  
              chkIcePrefix.Checked = Util.getProjectPropertyAsBool(_project, Util.PropertyIcePrefix);
  
              chkStreaming.Checked = Util.getProjectPropertyAsBool(_project, Util.PropertyIceStreaming);
              chkChecksum.Checked = Util.getProjectPropertyAsBool(_project, Util.PropertyIceChecksum);
  
              comboBoxVerboseLevel.SelectedIndex = Util.getVerboseLevel(_project);
  
              includePathView.load();
  
              loadComponents();
              txtDllExportSymbol.Text = Util.getProjectProperty(_project, Util.PropertyIceDllExport);
  
              btnApply.Enabled = false;
              Cursor = Cursors.Default;
          }
  
          private void loadComponents()
          {
              ComponentList selectedComponents = Util.getIceCppComponents(_project);
              foreach(String s in Util.getCppNames())
              {
                  if(selectedComponents.Contains(s))
                  {
                      checkComponent(s, true);
                  }
                  else
                  {
                      checkComponent(s, false);
                  }
              }
          }
  
          private void checkComponent(String component, bool check)
          {
              if(editingIncludeDir())
              {
                  endEditIncludeDir(true);
              }
              switch(component)
              {
                  case "Freeze":
                  {
                      chkFreeze.Checked = check;
                      break;
                  }
                  case "Glacier2":
                  {
                      chkGlacier2.Checked = check;
                      break;
                  }
                  case "IceBox":
                  {
                      chkIceBox.Checked = check;
                      break;
                  }
                  case "IceGrid":
                  {
                      chkIceGrid.Checked = check;
                      break;
                  }
                  case "IcePatch2":
                  {
                      chkIcePatch2.Checked = check;
                      break;
                  }
                  case "IceSSL":
                  {
                      chkIceSSL.Checked = check;
                      break;
                  }
                  case "IceStorm":
                  {
                      chkIceStorm.Checked = check;
                      break;
                  }
                  default:
                  {
                      break;
                  }
              }
          }
          
          private void chkEnableBuilder_CheckedChanged(object sender, EventArgs e)
          {
              try
              {
                  Cursor = Cursors.WaitCursor;
                  if(editingIncludeDir())
                  {
                      endEditIncludeDir(true);
                  }
                  if(_initialized)
                  {
                      _initialized = false;
                      setEnabled(chkEnableBuilder.Checked);
                      ComponentList components;
                      if(chkEnableBuilder.Checked)
                      {
                          //
                          // Enable the components that were previously enabled if any.
                          //
                          components = 
                              new ComponentList(Util.getProjectProperty(_project, Util.PropertyIceComponents));
  
                          //
                          // If there isn't a previous set of componets, we enable the default components.
                          //
                          if(components.Count == 0)
                          {
                              components.Add("Ice");
                              components.Add("IceUtil");
                          }
                          for(int i = 0; i < components.Count; ++i)
                          {
                              checkComponent(components[i], true);
                          }
                      }
                      else
                      {
                          components = iceComponents();
                      }
  
                      //
                      // Enable / Disable the given set of components
                      //
                      for(int i = 0; i < components.Count; ++i)
                      {
                          checkComponent(components[i], chkEnableBuilder.Checked);
                      }
  
                      chkEnableBuilder.Enabled = true;
                      _initialized = true;
                      needSave();
                  }
                  Cursor = Cursors.Default;
              }
              catch(Exception ex)
              {
                  Cursor = Cursors.Default;
                  Util.unexpectedExceptionWarning(ex);
                  throw;
              }
          }
          
          private void setEnabled(bool enabled)
          {
              outputDirView.setEnabled(enabled);
              chkIcePrefix.Enabled = enabled;
              chkStreaming.Enabled = enabled;
              chkChecksum.Enabled = enabled;
  
              comboBoxVerboseLevel.Enabled = enabled;
              includePathView.setEnabled(enabled);
  
              extraCompilerOptions.setEnabled(enabled);
  
              chkFreeze.Enabled = enabled;
              chkGlacier2.Enabled = enabled;
              chkIceBox.Enabled = enabled;
              chkIceGrid.Enabled = enabled;
              chkIcePatch2.Enabled = enabled;
              chkIceSSL.Enabled = enabled;
              chkIceStorm.Enabled = enabled;
              txtDllExportSymbol.Enabled = enabled;
          }
          
          private void formClosing(object sender, FormClosingEventArgs e)
          {
              try
              {
                  if(editingIncludeDir())
                  {
                      endEditIncludeDir(false);
                  }
  
                  if(hasUnsavedChanges())
                  {
                      if(!Util.warnUnsavedChanges(this))
                      {
                          e.Cancel = true;
                          return;
                      }
                  }
  
                  Cursor = Cursors.WaitCursor;
                  if(_changed && Util.isSliceBuilderEnabled(_project))
                  {
                      Util.rebuildProject(_project);
                  }
                  Cursor = Cursors.Default;
              }
              catch(Exception ex)
              {
                  Cursor = Cursors.Default;
                  Util.unexpectedExceptionWarning(ex);
                  throw;
              }
          }
  
          private void component_Changed(object sender, EventArgs e)
          {
              try
              {
                  Cursor = Cursors.WaitCursor;
                  if(editingIncludeDir())
                  {
                      endEditIncludeDir(true);
                  }
                  needSave();
                  Cursor = Cursors.Default;
              }
              catch(Exception ex)
              {
                  Cursor = Cursors.Default;
                  Util.unexpectedExceptionWarning(ex);
                  throw;
              }
          }
  
          private void txtDllExportSymbol_Focus(object sender, EventArgs e)
          {
              try
              {
                  Cursor = Cursors.WaitCursor;
                  if(includePathView.editingIncludeDir())
                  {
                      includePathView.endEditIncludeDir(true);
                  }
                  Cursor = Cursors.Default;
              }
              catch(Exception ex)
              {
                  Cursor = Cursors.Default;
                  Util.unexpectedExceptionWarning(ex);
                  throw;
              }
          }
          
          private void txtDllExportSymbol_Changed(object sender, EventArgs e)
          {
              try
              {
                  Cursor = Cursors.WaitCursor;
                  needSave();
                  Cursor = Cursors.Default;
              }
              catch(Exception ex)
              {
                  Cursor = Cursors.Default;
                  Util.unexpectedExceptionWarning(ex);
                  throw;
              }
          }
  
          private void btnOk_Click(object sender, EventArgs e)
          {
              try
              {
                  Cursor = Cursors.WaitCursor;
                  if(apply())
                  {
                      Close();
                  }
                  Cursor = Cursors.Default;
              }
              catch(Exception ex)
              {
                  Cursor = Cursors.Default;
                  Util.unexpectedExceptionWarning(ex);
                  throw;
              }
          }
  
          private void btnApply_Click(object sender, EventArgs e)
          {
              try
              {
                  Cursor = Cursors.WaitCursor;
                  apply();
                  Cursor = Cursors.Default;
              }
              catch(Exception ex)
              {
                  Cursor = Cursors.Default;
                  Util.unexpectedExceptionWarning(ex);
                  throw;
              }
          }
  
          private void btnCancel_Click(object sender, EventArgs e)
          {
              try
              {
                  Close();
              }
              catch(Exception ex)
              {
                  Util.unexpectedExceptionWarning(ex);
                  throw;
              }
          }
  
          private ComponentList iceComponents()
          {
  
gt:             ComponentList components = new ComponentList();