1530 lines
61 KiB
C#
1530 lines
61 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.ComponentModel;
|
||
using System.Windows.Forms;
|
||
using System.Data;
|
||
using System.Xml;
|
||
using System.IO;
|
||
using Microsoft.Win32;
|
||
using System.Diagnostics;
|
||
using System.Resources;
|
||
using System.Text;
|
||
using System.Runtime.InteropServices;
|
||
using System.Collections.Generic;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading;
|
||
using System.Globalization;
|
||
using System.Drawing;
|
||
using System.Reflection;
|
||
|
||
namespace Ubi.Tools.GearConfigTool
|
||
{
|
||
/// <summary>
|
||
/// Summary description for GearMain.
|
||
/// This class contains all the callback from the GUI and is making the bridge between the UI and the Model.
|
||
/// This is the controller according to the architectural paradigm MVC
|
||
///
|
||
/// The View is located in GUI/MainViewer.cs
|
||
/// The Controller is located in this file
|
||
/// The Model is located in Core/CoreModel.cs
|
||
///
|
||
/// To explain the normal data flow, we'll take the example when button click is pressed.
|
||
/// First, the open button is encapsulated in mainViewer with the name of MnuFileOpen.
|
||
///
|
||
/// Secondly, in this class we register the event in the function AddEventHandlers() like this :
|
||
/// m_gui.MnuFileOpen.Click += new System.EventHandler(this.menuItemFile_Open_Click);
|
||
/// menuItemFile_Open_Click is a function in MainController which takes the same parameters as the Click delegate.
|
||
///
|
||
/// Thirdly, when the user click on open, the function menuItemFile_Open_Click is called in this class.
|
||
///
|
||
/// Fourthly, it will use Tools.IO.OpenFile to do it's operations which needs to be done when open is clicked.
|
||
/// The classes in Tools are helpers for the MainController, the OpenFile in Tools.IO is not the same as
|
||
/// the one in FileIO.cs.
|
||
///
|
||
/// Fifthly, if the file is opened, the model will be updated with the data into it.
|
||
///
|
||
/// m_gui is the reference to the view for the controller and is widely used in this file.
|
||
/// The model is a singleton so you can access it with Core.CoreModel.YourDataOrFunction
|
||
///
|
||
/// </summary>
|
||
public class MainController
|
||
{
|
||
#region Variables
|
||
|
||
GUI.MainViewer m_gui;
|
||
|
||
//UI related
|
||
private ValidationWindow m_validationWindow;
|
||
|
||
public ValidationWindow ValidationWindow
|
||
{
|
||
get { return m_validationWindow; }
|
||
set { m_validationWindow = value; }
|
||
}
|
||
|
||
private bool m_initSuccessful = false;
|
||
private bool m_StartedFromCommand = false;
|
||
private ApplicationSettings m_appSettings = new ApplicationSettings();
|
||
private string m_filename = null;
|
||
private bool m_lockEvent = false; //variable used to lock ui events !
|
||
|
||
private List<int> m_SearchResult = null;
|
||
private int m_CurrentSearchIndex = 0;
|
||
|
||
private LegendWindow m_LegendWindow = null;
|
||
|
||
private GEARRow m_LastRow = null;
|
||
|
||
public bool InitSuccessful
|
||
{
|
||
get { return m_initSuccessful; }
|
||
set { m_initSuccessful = value; }
|
||
}
|
||
|
||
public bool m_startedFromCommand
|
||
{
|
||
get { return m_StartedFromCommand; }
|
||
set { m_StartedFromCommand = value; }
|
||
}
|
||
|
||
public ApplicationSettings AppSettings
|
||
{
|
||
get { return m_appSettings; }
|
||
set { m_appSettings = value; }
|
||
}
|
||
|
||
public string Filename
|
||
{
|
||
get { return m_filename; }
|
||
set
|
||
{
|
||
m_filename = value;
|
||
if (m_filename != null)
|
||
{
|
||
m_gui.Text = Path.GetFileName(m_filename) + " - Gear Configuration Tool";
|
||
}
|
||
else
|
||
{
|
||
m_gui.Text = "Gear Configuration Tool";
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
public MainController(bool bStartedFromCommandLine, GUI.MainViewer gui)
|
||
{
|
||
//Set the application running as en-US for float and double validation.
|
||
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
|
||
|
||
this.m_startedFromCommand = bStartedFromCommandLine;
|
||
|
||
m_gui = gui;
|
||
if(!bStartedFromCommandLine)
|
||
{
|
||
m_gui.ShowSplash();
|
||
m_gui.SplashScreen.SplashDone += new EventHandler(splashScreen_SplashDone);
|
||
}
|
||
|
||
m_validationWindow = new ValidationWindow(this);
|
||
m_gui.InitializeCustomControl();
|
||
AddEventHandlers();
|
||
|
||
if (!this.m_appSettings.LoadAppSettings())
|
||
{
|
||
if (this.m_startedFromCommand)
|
||
{
|
||
GUI.MainViewer.OutputMessage("There was an error while loading configuration file : " + ".//GearCT.ini -> file missing or corrupted. Using default configuration.", "Loading Configuration", MessageBoxButtons.OK, MessageBoxIcon.Warning, m_StartedFromCommand);
|
||
}
|
||
ClearConfig();
|
||
}
|
||
|
||
UpdateSettings(m_appSettings);
|
||
|
||
this.m_lockEvent = true;
|
||
m_gui.UpdateRecentFilesMenu(m_appSettings);
|
||
this.m_lockEvent = false;
|
||
|
||
m_gui.SetAllControls(false);
|
||
|
||
Tools.XML xmlLoad = new Tools.XML();
|
||
|
||
Tools.OutputMessage del = GUI.MainViewer.OutputMessage;
|
||
InitSuccessful = xmlLoad.LoadCompanionFileAndBuildTree(m_appSettings, m_gui.MirrorTreeView, m_StartedFromCommand, del);
|
||
|
||
CoreModel.Indexes.Reset();
|
||
}
|
||
|
||
#region Profile Management functions
|
||
|
||
public Profile AddProfile(String addProfileName, String addProfilePlatform, String addProfileTarget, Profile oSourceProfile, List<string> vTargetAliases)
|
||
{
|
||
Profile myProfile;
|
||
String formatedString=addProfileName.Replace(" " , "");
|
||
myProfile= new Profile(formatedString);
|
||
if (vTargetAliases != null)
|
||
{
|
||
myProfile.TargetAliases = vTargetAliases;
|
||
}
|
||
|
||
myProfile.ProfilePlatform = addProfilePlatform;
|
||
myProfile.ProfileCompileMode = CoreModel.TargetsAlias[addProfileTarget.ToLower()];
|
||
myProfile.ProfileTarget = addProfileTarget;
|
||
myProfile.DisplayConfigurationGlobally = true;
|
||
|
||
myProfile.SubSystems = (SubSystemCollection)(CoreModel.SubSystemList.Clone());
|
||
myProfile.ResetProfile();
|
||
myProfile.UpdateSpecificInCreatedProfile(true);
|
||
Application.DoEvents();
|
||
|
||
if (oSourceProfile != null)
|
||
{
|
||
//convert profile
|
||
Dictionary<string, List<Configuration>> vConflicts = myProfile.CopyFromProfile(oSourceProfile);
|
||
|
||
if (vConflicts.Count > 0)
|
||
{
|
||
ConfigurationConflict frmConfigurationConflict = new ConfigurationConflict();
|
||
frmConfigurationConflict.Message = "The Gear Configuration tool detected that some configuration(s) were manually changed in the source profile: <" + oSourceProfile.ToString() + "> from which you are trying to copy your new profile <" + myProfile.ToString() + ">. These configuration(s) values may conflict depending on your new profile: <" + myProfile.ToString() + "> platform and/or compile.";
|
||
frmConfigurationConflict.Message += "\n\nYou can see the list of all configurations where these conflicts may happens below. The first and second columns represent the configuration name. The third column represents your source profile from which you are copying from with the custom value assigned {this column cannot be edited}. The fourth column represents your new profile with their default configuration value.";
|
||
frmConfigurationConflict.Message += "\n\nYou can: \n";
|
||
frmConfigurationConflict.Message += " - Manually edit the configuration of your new profile and set a value corresponding to your needs. \n";
|
||
frmConfigurationConflict.Message += " - Select one/all configuration(s) and propagate the source profile < " + oSourceProfile.ToString() + " > value to your new profile < " + myProfile.ToString() + ">. \n";
|
||
|
||
frmConfigurationConflict.LoadConflict(oSourceProfile, vConflicts);
|
||
frmConfigurationConflict.ShowDialog();
|
||
}
|
||
}
|
||
|
||
CoreModel.Indexes.ModuleIndex = -1;
|
||
CoreModel.Indexes.ProfileIndex = CoreModel.CurrentConfiguration.ProfileList.Add(myProfile);
|
||
|
||
CoreModel.CurrentConfiguration.FileChanged = true;
|
||
|
||
if(!m_startedFromCommand)
|
||
m_gui.SetAllControls(true);
|
||
|
||
return myProfile;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Event Handling
|
||
/* Pako: Dans cette r<>gion(Event Handling) le nom des m<>thodes sont suffisaments explicites pour que tu comprennes bien.
|
||
* <20>videmment, si tu as besoin d'un <20>v<EFBFBD>nement dans le GUI, le handling se passe ici.
|
||
*/
|
||
|
||
/// <summary>
|
||
/// In this function, the class is registering to all the events in the view
|
||
/// </summary>
|
||
private void AddEventHandlers()
|
||
{
|
||
m_gui.MnuFileNew.Click += new System.EventHandler(this.menuItemFile_New_Click);
|
||
m_gui.MnuFileOpen.Click += new System.EventHandler(this.menuItemFile_Open_Click);
|
||
m_gui.MnuFileSaveAs.Click += new System.EventHandler(this.menuItemFile_SaveAs_Click);
|
||
m_gui.MnuFileSave.Click += new System.EventHandler(this.menuItemFile_Save_Click);
|
||
m_gui.MnuFileExit.Click += new System.EventHandler(this.menuItemFile_Exit_Click);
|
||
m_gui.ClientSectionToolStripMenuItem.Click += new System.EventHandler(this.clientSectionToolStripMenuItem_Click);
|
||
m_gui.EditMenuSettings.Click += new System.EventHandler(this.menuItemSettings_Click);
|
||
m_gui.EditMenuExpandAll.Click += new System.EventHandler(this.menuItemExpandAll_Click);
|
||
m_gui.EditMenuCollapseAll.Click += new System.EventHandler(this.menuItemCollapseAll_Click);
|
||
|
||
m_gui.MnuProfilesAddNew.Click += new System.EventHandler(this.menuItemProfiles_Add_Click);
|
||
m_gui.ButtonProfilesAddNew.Click += new System.EventHandler(this.menuItemProfiles_Add_Click);
|
||
|
||
m_gui.MnuProfilesManage.Click += new System.EventHandler(this.menuItemProfiles_Manage_Click);
|
||
m_gui.MnuValidateProfiles.Click += new System.EventHandler(this.validateToolStripMenuItem_Click);
|
||
m_gui.MnuHelpQuick.Click += new System.EventHandler(this.menuItemHelpConfig_Activate);
|
||
m_gui.MnuHelpGear.Click += new System.EventHandler(this.menuItemHelp_Click);
|
||
m_gui.MnuHelpAbout.Click += new System.EventHandler(this.menuItemAbout_Click);
|
||
m_gui.DisplayAllProfilesMenuItem.Click += new System.EventHandler(this.AllProfileMenuItem_CheckedChanged);
|
||
m_gui.ButtonAddProfile.Click += new System.EventHandler(this.menuItemProfiles_Add_Click);
|
||
m_gui.KeyDown += new System.Windows.Forms.KeyEventHandler(this.GearMain_KeyDown);
|
||
m_gui.MergeConfigutationFileToolStripMenuItem.Click += new System.EventHandler(mergeConfigutationFileToolStripMenuItem_Click);
|
||
m_gui.OnClosingGUI +=new Ubi.Tools.GearConfigTool.GUI.MainViewer.OnClosingDelegate(OnClosingGUI);
|
||
m_gui.OnAddMenuItem += new Ubi.Tools.GearConfigTool.GUI.MainViewer.OnAddMenuItemDelegate(m_gui_OnAddMenuItem);
|
||
|
||
m_gui.DragEnter += this.OnDragEnter;
|
||
m_gui.DragDrop += this.OnDragDrop;
|
||
|
||
m_gui.BottomPanel1.GetExternalButton().Click += new EventHandler(buttonBrowseEXT_Click);
|
||
m_gui.BottomPanel1.GetExternalTextBox().TextChanged += new EventHandler(textBoxPathEXT_TextChanged);
|
||
m_gui.BottomPanel1.GetExternalCheckbox().CheckedChanged += new EventHandler(checkBoxUseEXT_CheckedChanged);
|
||
m_gui.ClearConfig +=new Ubi.Tools.GearConfigTool.GUI.MainViewer.ClearConfigDelegate(ClearConfig);
|
||
m_gui.ResetApplication +=new Ubi.Tools.GearConfigTool.GUI.MainViewer.ResetApplicationDelegate(ResetApplication);
|
||
m_gui.SetCurrentConfigurationFile +=new Ubi.Tools.GearConfigTool.GUI.MainViewer.SetCurrentConfigurationFileDelegate(SetCurrentConfigurationFile);
|
||
m_gui.OnOpenRecentFiles += new Ubi.Tools.GearConfigTool.GUI.MainViewer.OnOpenRecentFilesDelegate(m_gui_OnOpenRecentFiles);
|
||
|
||
m_gui.DisplayConfigurationMenuItem.ButtonClick += new System.EventHandler(DisplayConfigurationMenuItem_ButtonClick);
|
||
|
||
// Show only tool strip menu
|
||
m_gui.ShowOnlySelectedToolStripButton.Click += new System.EventHandler(this.ShowOnlySelectedModule);
|
||
m_gui.ShowOnlyManuallyToolStripButton.Click += new System.EventHandler(this.ShowOnlyManuallySelectedModule);
|
||
m_gui.ShowOnlyDifferentToolStripButton.Click += new System.EventHandler(this.ShowOnlyDifferentConfiguration);
|
||
//m_gui.ResetShowOnlyToolStripMenuItem.Click += new EventHandler(this.ResetShowOnlyToolStripMenuItem);
|
||
|
||
// Search functionality.
|
||
m_gui.ToolStripTextToSearch.TextChanged += new EventHandler(this.ToolStripTextToSearchTextChanged);
|
||
m_gui.ToolStripClearSearch.Click += new EventHandler(this.ToolStripClearSearchClick);
|
||
m_gui.ToolStripNextHit.Click += new EventHandler(this.ToolStripNextHitClick);
|
||
m_gui.ToolStripPreviousHit.Click += new EventHandler(this.ToolStripPreviousHitClick);
|
||
|
||
// Legend window.
|
||
m_gui.ToolStripLegend.Click += new EventHandler(this.ToolStripLegendClick);
|
||
|
||
m_gui.MnuGeneratePerPlatformFiles.Click += new EventHandler(this.MnuGeneratePerPlatformFilesClick);
|
||
|
||
m_gui.DataGridView.UpdateProfileListEvent += new GEARDataGridView.UpdateProfileListHandler(this.UpdateProfileListEvent);
|
||
m_gui.DataGridView.SelectionChanged += new EventHandler(DataGridView_SelectionChanged);
|
||
}
|
||
|
||
private void m_gui_OnOpenRecentFiles(ToolStripMenuItem mnuNew)
|
||
{
|
||
mnuNew.Click += new System.EventHandler(OnOpenRecentFiles);
|
||
}
|
||
|
||
// When an item menu is added in the view, we want to be notified to add an handler on it.
|
||
private void m_gui_OnAddMenuItem(ToolStripMenuItem oMenuItem)
|
||
{
|
||
oMenuItem.Click += new EventHandler(oMenuItem_CheckedChanged);
|
||
//oMenuItem.CheckedChanged += new EventHandler(oMenuItem_CheckedChanged);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Making the gui calls when the open button is clicked, sets the operation until the open is done loading.
|
||
/// </summary>
|
||
/// <param name="sender">Not used in this function</param>
|
||
/// <param name="e">Not used in this function</param>
|
||
private void menuItemFile_Open_Click(object sender, System.EventArgs e)
|
||
{
|
||
// Ask for a file to open...
|
||
OpenFile("");
|
||
}
|
||
|
||
private void menuItemFile_Save_Click(object sender, System.EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
m_gui.DataGridView.CommitCurrentCellValue();
|
||
|
||
String savedfilename = Tools.IO.SaveFile(CoreModel.CurrentConfiguration, true, m_appSettings, m_validationWindow, Filename, CoreModel.PerPlatformFile);
|
||
if (savedfilename.Length > 0)
|
||
this.Filename = savedfilename;
|
||
}
|
||
finally
|
||
{
|
||
m_gui.UpdateRecentFilesMenu(m_appSettings);
|
||
}
|
||
}
|
||
|
||
private void menuItemFile_SaveAs_Click(object sender, System.EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
m_gui.DataGridView.CommitCurrentCellValue();
|
||
|
||
String savedfilename = Tools.IO.SaveFile(CoreModel.CurrentConfiguration, m_appSettings, m_validationWindow, Filename, CoreModel.PerPlatformFile);
|
||
if (savedfilename.Length > 0)
|
||
this.Filename = savedfilename;
|
||
}
|
||
finally
|
||
{
|
||
m_gui.UpdateRecentFilesMenu(m_appSettings);
|
||
}
|
||
}
|
||
|
||
private void menuItemFile_Exit_Click(object sender, System.EventArgs e)
|
||
{
|
||
OnExitApplication();
|
||
}
|
||
|
||
private void menuItemFile_New_Click(object sender, System.EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if( Tools.IO.CheckIfSaveRequired(m_appSettings, m_validationWindow, Filename, CoreModel.PerPlatformFile) )
|
||
{
|
||
AddProfileDlg addProfileDlg = menuItemProfilesAdd(true);
|
||
|
||
if (addProfileDlg.Result)
|
||
{
|
||
ResetApplication();
|
||
|
||
m_gui.UpdateRecentFilesMenu(m_appSettings);
|
||
CoreModel.CurrentConfiguration.FileChanged = false;
|
||
addProfile(addProfileDlg);
|
||
m_gui.UpdateContextMenu(m_gui.DisplayConfigurationMenuItem);
|
||
|
||
m_gui.DataGridView.UpdateProfileList();
|
||
|
||
// Reset the state of the Show Only functionality and collapse the tree.
|
||
ResetShowOnly();
|
||
m_gui.DataGridView.CollapseAllRows();
|
||
}
|
||
}
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
ClearConfig();
|
||
}
|
||
}
|
||
|
||
|
||
private void menuItemProfiles_Add_Click(object sender, System.EventArgs e)
|
||
{
|
||
AddProfileDlg addProfileDlg = menuItemProfilesAdd(false);
|
||
|
||
if( addProfileDlg.Result )
|
||
{
|
||
addProfile(addProfileDlg);
|
||
}
|
||
|
||
m_gui.UpdateContextMenu(m_gui.DisplayConfigurationMenuItem);
|
||
}
|
||
|
||
private void menuItemProfiles_Manage_Click(object sender, System.EventArgs e)
|
||
{
|
||
ManageProfiles manageProfileDlg = new ManageProfiles(this);
|
||
|
||
manageProfileDlg.Owner = m_gui;
|
||
manageProfileDlg.ShowDialog();
|
||
|
||
if (manageProfileDlg.ProfileListChanged)
|
||
{
|
||
//BUG? Try to overcome the loss of the current profile...
|
||
CoreModel.Indexes.ProfileIndex = CoreModel.CurrentConfiguration.ProfileCount - 1;
|
||
|
||
CoreModel.CurrentConfiguration.FileChanged = true;
|
||
}
|
||
|
||
// Update the gui in case the Profile.DisplayConfigurationGlobally did change...
|
||
m_gui.UpdateContextMenu(m_gui.DisplayConfigurationMenuItem);
|
||
m_gui.DataGridView.UpdateProfileList();
|
||
UpdateShowOnlyStates();
|
||
}
|
||
|
||
private void menuItemExpandAll_Click(object sender, System.EventArgs e)
|
||
{
|
||
this.m_gui.DataGridView.ExpandAllRows();
|
||
}
|
||
|
||
private void menuItemCollapseAll_Click(object sender, System.EventArgs e)
|
||
{
|
||
this.m_gui.DataGridView.CollapseAllRows();
|
||
}
|
||
|
||
private void menuItemSettings_Click(object sender, System.EventArgs e)
|
||
{
|
||
m_gui.DisplaySettings(m_appSettings);
|
||
|
||
UpdateSettings(m_appSettings);
|
||
}
|
||
|
||
private void menuItemAbout_Click(object sender, System.EventArgs e)
|
||
{
|
||
AboutDlg aboutDlg = new AboutDlg();
|
||
aboutDlg.ShowDialog(m_gui);
|
||
}
|
||
|
||
private void menuItemHelp_Click(object sender, System.EventArgs e)
|
||
{
|
||
// Change the content of \\ubisoft.org\Projects\TechGroup\Public\Official-Releases\Gear\HTML\GearConfigurationTool.html
|
||
// whenever the Confluence Documentation Space changes
|
||
System.Diagnostics.Process.Start("http://tgpublic/Official-Releases/Gear/HTML/GearConfigurationTool.html");
|
||
}
|
||
|
||
/// <summary>
|
||
/// Receiving this call from the View by a delegate.
|
||
/// </summary>
|
||
/// <param name="e">If the user cancel the operation, it's gonna be put in this variable</param>
|
||
|
||
private void OnClosingGUI(CancelEventArgs e)
|
||
{
|
||
e.Cancel = !OnExitApplication();
|
||
}
|
||
|
||
|
||
private void checkBoxUseEXT_CheckedChanged(object sender, System.EventArgs e)
|
||
{
|
||
if (!m_lockEvent)
|
||
{
|
||
GEARRow currentRow = m_gui.DataGridView.GetSelectedRow();
|
||
|
||
if (currentRow.Type == RowType.RowModule)
|
||
{
|
||
Profile profile = m_gui.DataGridView.GetSelectedProfile();
|
||
if (profile == null)
|
||
return;
|
||
|
||
Module module = profile.SubSystems[currentRow.SubSystemIndex].Modules[currentRow.ModuleIndex];
|
||
|
||
CheckBox chkbox = m_gui.BottomPanel1.GetExternalCheckbox();
|
||
TextBox txtbox = m_gui.BottomPanel1.GetExternalTextBox();
|
||
Button btn = m_gui.BottomPanel1.GetExternalButton();
|
||
|
||
module.ModuleIsExternal = chkbox.Checked;
|
||
txtbox.Enabled = module.ModuleIsExternal;
|
||
txtbox.Text = module.ModuleExternalFile;
|
||
btn.Enabled = module.ModuleIsExternal;
|
||
|
||
CoreModel.CurrentConfiguration.FileChanged = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void textBoxPathEXT_TextChanged(object sender, System.EventArgs e)
|
||
{
|
||
if (!m_lockEvent)
|
||
{
|
||
GEARRow currentRow = m_gui.DataGridView.GetSelectedRow();
|
||
|
||
if (currentRow.Type == RowType.RowModule)
|
||
{
|
||
Profile profile = m_gui.DataGridView.GetSelectedProfile();
|
||
if (profile == null)
|
||
return;
|
||
|
||
Module module = profile.SubSystems[currentRow.SubSystemIndex].Modules[currentRow.ModuleIndex];
|
||
|
||
CheckBox chkbox = m_gui.BottomPanel1.GetExternalCheckbox();
|
||
TextBox txtbox = m_gui.BottomPanel1.GetExternalTextBox();
|
||
Button btn = m_gui.BottomPanel1.GetExternalButton();
|
||
|
||
module.ModuleIsExternal = chkbox.Checked;
|
||
txtbox.Enabled = module.ModuleIsExternal;
|
||
btn.Enabled = module.ModuleIsExternal;
|
||
module.ModuleExternalFile = txtbox.Text;
|
||
|
||
CoreModel.CurrentConfiguration.FileChanged = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void buttonBrowseEXT_Click(object sender, System.EventArgs e)
|
||
{
|
||
OpenFileDialog openDlg = new OpenFileDialog();
|
||
openDlg.Filter = "Header File(.h)|*.h";
|
||
openDlg.RestoreDirectory = true;
|
||
if (openDlg.ShowDialog() == DialogResult.OK)
|
||
{
|
||
string strGearPath = Tools.Tools.ExtractGearPath(openDlg.FileName);
|
||
|
||
if (strGearPath == openDlg.FileName)
|
||
{
|
||
m_gui.BottomPanel1.GetExternalTextBox().Text = openDlg.FileName;
|
||
}
|
||
else
|
||
{
|
||
m_gui.BottomPanel1.GetExternalTextBox().Text = Tools.Tools.GetRelativePath(strGearPath, Path.GetFullPath(openDlg.FileName));
|
||
}
|
||
}
|
||
}
|
||
|
||
private void menuItemHelpConfig_Activate(object sender, System.EventArgs e)
|
||
{
|
||
m_gui.ShowHelpDialog(m_appSettings);
|
||
}
|
||
|
||
|
||
internal void control_SelectedValueChanged(object sender, System.EventArgs e)
|
||
{
|
||
}
|
||
|
||
|
||
private void splashScreen_SplashDone(object sender, EventArgs e)
|
||
{
|
||
m_gui.SplashScreen.Hide();
|
||
m_gui.RestoreMainWindow();
|
||
|
||
if (m_appSettings.ShowHelpOnStartup)
|
||
{
|
||
m_gui.ShowHelpDialog(m_appSettings);
|
||
}
|
||
}
|
||
|
||
private void clientSectionToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
ClientSection oClientSection = new ClientSection();
|
||
|
||
oClientSection.ClientSectionTopText = CoreModel.CurrentConfiguration.ClientSectionTop;
|
||
oClientSection.ClientSectionBottomText = CoreModel.CurrentConfiguration.ClientSectionBottom;
|
||
|
||
oClientSection.ShowDialog();
|
||
|
||
if (oClientSection.ClientSectionChanged)
|
||
{
|
||
CoreModel.CurrentConfiguration.ClientSectionTop = oClientSection.ClientSectionTopText.Replace("\n", "\r\n");
|
||
CoreModel.CurrentConfiguration.ClientSectionBottom = oClientSection.ClientSectionBottomText.Replace("\n", "\r\n");
|
||
CoreModel.CurrentConfiguration.FileChanged = true;
|
||
}
|
||
|
||
CoreModel.CurrentConfiguration.ClientSectionTop += Environment.NewLine;
|
||
if(CoreModel.CurrentConfiguration.ClientSectionBottom != "")
|
||
CoreModel.CurrentConfiguration.ClientSectionBottom += Environment.NewLine;
|
||
}
|
||
|
||
private void oMenuItem_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (!this.m_lockEvent)
|
||
{
|
||
ToolStripMenuItem oMenuItem = (ToolStripMenuItem)sender;
|
||
|
||
if (oMenuItem.Tag is Profile)
|
||
{
|
||
Profile oProfile = (Profile)oMenuItem.Tag;
|
||
|
||
if (oMenuItem.OwnerItem == m_gui.DisplayConfigurationMenuItem)
|
||
{
|
||
oProfile.DisplayConfigurationGlobally = !oProfile.DisplayConfigurationGlobally;
|
||
|
||
m_gui.DataGridView.UpdateProfileList();
|
||
UpdateShowOnlyStates();
|
||
}
|
||
|
||
this.m_lockEvent = true;
|
||
oMenuItem.Checked = true;
|
||
this.m_lockEvent = false;
|
||
}
|
||
|
||
this.m_lockEvent = true;
|
||
m_gui.UpdateContextMenuChecked((ToolStripSplitButton)oMenuItem.OwnerItem);
|
||
this.m_lockEvent = false;
|
||
}
|
||
}
|
||
|
||
private void AllProfileMenuItem_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (!this.m_lockEvent)
|
||
{
|
||
ToolStripMenuItem oMenuItem = (ToolStripMenuItem)sender;
|
||
|
||
bool bChecked = oMenuItem.Checked;
|
||
|
||
for (int i = 0; i < CoreModel.CurrentConfiguration.ProfileCount; i++)
|
||
{
|
||
if (oMenuItem.OwnerItem == m_gui.DisplayConfigurationMenuItem)
|
||
{
|
||
CoreModel.CurrentConfiguration.GetProfile(i).DisplayConfigurationGlobally = bChecked;
|
||
}
|
||
}
|
||
|
||
if (oMenuItem.OwnerItem == m_gui.DisplayConfigurationMenuItem)
|
||
{
|
||
CoreModel.DisplayAllProfilesConfiguration = bChecked;
|
||
}
|
||
|
||
this.m_lockEvent = true;
|
||
m_gui.UpdateContextMenuChecked((ToolStripSplitButton)oMenuItem.OwnerItem);
|
||
this.m_lockEvent = false;
|
||
|
||
// Forcing a refresh of the grid at this point prevent a bug we have with the Profile.DisplayConfigurationGlobally
|
||
// property. Its value get reset to false for a short moment and it gets set to the right value right here. So
|
||
// by doing an UpdateProfileList() here, we redisplay the correct state for all the profile.
|
||
m_gui.DataGridView.UpdateProfileList();
|
||
UpdateShowOnlyStates();
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* Manage the keyboard shortcuts.
|
||
*/
|
||
private void GearMain_KeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
/*
|
||
* Search Function:
|
||
*
|
||
* F3 Start a search/Go to the next match.
|
||
* Shift + F3 Go to the previous search match.
|
||
* Escape Terminate the current search.
|
||
*
|
||
*/
|
||
|
||
// Search shortcuts
|
||
if (CoreModel.CurrentConfiguration.ProfileCount > 0)
|
||
{
|
||
if (e.Shift && e.KeyCode == Keys.F3)
|
||
{
|
||
if(m_SearchResult != null)
|
||
ToolStripPreviousHitClick(null, null);
|
||
}
|
||
else if (e.KeyCode == Keys.F3)
|
||
{
|
||
if (m_SearchResult == null)
|
||
m_gui.ToolStripTextToSearch.Focus();
|
||
else
|
||
ToolStripNextHitClick(null, null);
|
||
}
|
||
else if(e.KeyCode == Keys.Escape)
|
||
{
|
||
if (m_SearchResult != null)
|
||
ToolStripClearSearchClick(null, null);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
private void validateToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
m_validationWindow.ValidateProfiles();
|
||
|
||
if (!m_validationWindow.Visible)
|
||
m_validationWindow.Show();
|
||
}
|
||
|
||
|
||
private void mergeConfigutationFileToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
ConfigurationMerge frmConfigurationMerge = new ConfigurationMerge();
|
||
if (frmConfigurationMerge.ShowDialog() == DialogResult.OK)
|
||
{
|
||
SetCurrentConfigurationFile(frmConfigurationMerge.NewConfigurationFile, false);
|
||
|
||
if (frmConfigurationMerge.SaveConfiguration)
|
||
{
|
||
try
|
||
{
|
||
Tools.IO.SaveFile(CoreModel.CurrentConfiguration, m_appSettings, m_validationWindow, Filename, CoreModel.PerPlatformFile);
|
||
}
|
||
finally
|
||
{
|
||
m_gui.UpdateRecentFilesMenu(m_appSettings);
|
||
}
|
||
}
|
||
|
||
m_gui.SetAllControls(true);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* Method called at the start of the application and after the Settings dialog have been closed.
|
||
*
|
||
* Used to reflect the what's in the ApplicationSettings to the running application
|
||
*/
|
||
private void UpdateSettings(ApplicationSettings settings)
|
||
{
|
||
//CoreModel.PerPlatformFile = settings.PerPlatformFile;
|
||
}
|
||
|
||
|
||
public void OnOpenRecentFiles(object sender, System.EventArgs e)
|
||
{
|
||
ToolStripMenuItem mnuRecentFile = sender as ToolStripMenuItem;
|
||
if (mnuRecentFile != null)
|
||
OpenFile(mnuRecentFile.Text);
|
||
}
|
||
|
||
|
||
private void DisplayConfigurationMenuItem_ButtonClick(object sender, EventArgs e)
|
||
{
|
||
menuItemProfiles_Manage_Click(sender, e);
|
||
}
|
||
|
||
private void HandleShowOnlySelection(bool selected, bool manuallySelected)
|
||
{
|
||
// We have a profile
|
||
if (CoreModel.CurrentConfiguration.ProfileList.Count > 0)
|
||
{
|
||
bool click = false; // will become true if a menu item has been clicked
|
||
|
||
// Manually checker
|
||
if (manuallySelected && m_gui.ShowOnlyManuallyToolStripButton.Checked)
|
||
{
|
||
click = true;
|
||
|
||
m_gui.ShowOnlySelectedToolStripButton.Checked = false;
|
||
}
|
||
// Selected
|
||
else if (m_gui.ShowOnlySelectedToolStripButton.Checked)
|
||
{
|
||
click = true;
|
||
|
||
// If manually selected was checked: uncheck it and show all row before because
|
||
// we don't have any way of knowing the row to show for they are already hidden by the
|
||
// preceding option.
|
||
if (m_gui.ShowOnlyManuallyToolStripButton.Checked)
|
||
{
|
||
m_gui.DataGridView.ShowManuallySelectedModule = false;
|
||
m_gui.DataGridView.UpdateShowHideAllRow();
|
||
}
|
||
|
||
m_gui.ShowOnlyManuallyToolStripButton.Checked = false;
|
||
}
|
||
|
||
// Put the DataGridView variable to true of false
|
||
m_gui.DataGridView.ShowSelectedModule = selected && click;
|
||
m_gui.DataGridView.ShowManuallySelectedModule = manuallySelected && click;
|
||
|
||
// Update
|
||
m_gui.DataGridView.UpdateShowHideAllRow();
|
||
}
|
||
else
|
||
{
|
||
m_gui.ShowOnlyDifferentToolStripButton.Checked = false;
|
||
m_gui.ShowOnlySelectedToolStripButton.Checked = false;
|
||
m_gui.ShowOnlyManuallyToolStripButton.Checked = false;
|
||
}
|
||
|
||
// Set the SearchBox to the right state.
|
||
UpdateShowOnlyStates();
|
||
}
|
||
|
||
private void ShowOnlySelectedModule(object sender, EventArgs e)
|
||
{
|
||
m_gui.ShowOnlySelectedToolStripButton.Checked = !m_gui.ShowOnlySelectedToolStripButton.Checked;
|
||
|
||
m_gui.DataGridView.CollapseAllRows();
|
||
HandleShowOnlySelection(true, false);
|
||
}
|
||
|
||
private void ShowOnlyManuallySelectedModule(object sender, EventArgs e)
|
||
{
|
||
m_gui.ShowOnlyManuallyToolStripButton.Checked = !m_gui.ShowOnlyManuallyToolStripButton.Checked;
|
||
|
||
m_gui.DataGridView.CollapseAllRows();
|
||
HandleShowOnlySelection(false, true);
|
||
}
|
||
|
||
private void ShowOnlyDifferentConfiguration(object sender, EventArgs e)
|
||
{
|
||
m_gui.ShowOnlyDifferentToolStripButton.Checked = !m_gui.ShowOnlyDifferentToolStripButton.Checked;
|
||
// We have a profile
|
||
if(CoreModel.CurrentConfiguration.ProfileList.Count > 0)
|
||
{
|
||
// We have at least 2 profile
|
||
if (CoreModel.CurrentConfiguration.ProfileList.Count > 1)
|
||
{
|
||
m_gui.DataGridView.ShowDifferentConfig = m_gui.ShowOnlyDifferentToolStripButton.Checked;
|
||
|
||
// If selected or manually selected where checked: uncheck it and show all row before because
|
||
// we don't have any way of knowing the row to show for they are already hidden by the
|
||
// preceding option.
|
||
if (m_gui.DataGridView.ShowSelectedModule || m_gui.DataGridView.ShowManuallySelectedModule)
|
||
{
|
||
// All to false: show all
|
||
m_gui.DataGridView.ShowSelectedModule = false;
|
||
m_gui.DataGridView.ShowManuallySelectedModule = false;
|
||
|
||
m_gui.DataGridView.UpdateShowHideAllRow();
|
||
|
||
// Put back option
|
||
m_gui.DataGridView.ShowSelectedModule = m_gui.ShowOnlySelectedToolStripButton.Checked;
|
||
m_gui.DataGridView.ShowManuallySelectedModule = m_gui.ShowOnlyManuallyToolStripButton.Checked;
|
||
}
|
||
|
||
// update
|
||
m_gui.DataGridView.UpdateShowHideAllRow();
|
||
}
|
||
else
|
||
{
|
||
m_gui.ShowOnlyDifferentToolStripButton.Checked = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// Uncheck all
|
||
m_gui.ShowOnlyDifferentToolStripButton.Checked = false;
|
||
m_gui.ShowOnlySelectedToolStripButton.Checked = false;
|
||
m_gui.ShowOnlyManuallyToolStripButton.Checked = false;
|
||
}
|
||
// Set the SearchBox to the right state.
|
||
UpdateShowOnlyStates();
|
||
}
|
||
|
||
|
||
private void ResetShowOnly()
|
||
{
|
||
// All to false: show all
|
||
m_gui.DataGridView.ShowSelectedModule = false;
|
||
m_gui.DataGridView.ShowManuallySelectedModule = false;
|
||
m_gui.DataGridView.ShowDifferentConfig = false;
|
||
|
||
m_gui.DataGridView.UpdateShowHideAllRow();
|
||
|
||
// Put back option
|
||
m_gui.ShowOnlySelectedToolStripButton.Checked = false;
|
||
m_gui.ShowOnlyManuallyToolStripButton.Checked = false;
|
||
m_gui.ShowOnlyDifferentToolStripButton.Checked = false;
|
||
|
||
HandleShowOnlySelection(false, false);
|
||
|
||
// Set the SearchBox to the right state.
|
||
UpdateShowOnlyStates();
|
||
}
|
||
|
||
|
||
/****************************************************************************************
|
||
* Search functionality
|
||
*/
|
||
private void ToolStripTextToSearchTextChanged(object sender, EventArgs e)
|
||
{
|
||
ToolStripTextBox txtbox = sender as ToolStripTextBox;
|
||
|
||
if (txtbox.Text.Length == 0)
|
||
{
|
||
// Reset the search when the textbox is empty
|
||
ToolStripClearSearchClick(null, null);
|
||
}
|
||
else
|
||
{
|
||
m_SearchResult = m_gui.DataGridView.Search(txtbox.Text);
|
||
|
||
if (m_SearchResult.Count > 0)
|
||
{
|
||
txtbox.BackColor = Color.White;
|
||
// Highlight all the row that match the search and select the first match.
|
||
m_gui.DataGridView.HighlightRows(m_SearchResult, Color.Blue);
|
||
m_gui.DataGridView.SelectARow(m_SearchResult[0]);
|
||
}
|
||
else
|
||
{
|
||
txtbox.BackColor = Color.LightPink;
|
||
m_gui.DataGridView.ResetHighlight();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
private void ToolStripClearSearchClick(object sender, EventArgs e)
|
||
{
|
||
if(m_gui.ToolStripTextToSearch.Enabled)
|
||
m_gui.ToolStripTextToSearch.BackColor = Color.White;
|
||
else
|
||
m_gui.ToolStripTextToSearch.BackColor = Color.LightGray;
|
||
|
||
m_gui.ToolStripTextToSearch.Text = "";
|
||
|
||
// Reset the search result in the grid.
|
||
m_SearchResult = null;
|
||
m_CurrentSearchIndex = 0;
|
||
|
||
m_gui.DataGridView.ResetHighlight();
|
||
}
|
||
|
||
|
||
private void ToolStripNextHitClick(object sender, EventArgs e)
|
||
{
|
||
// We don't do anything if there is no search result...
|
||
if(m_SearchResult == null)
|
||
return;
|
||
|
||
if (m_SearchResult.Count > 0)
|
||
{
|
||
// Adjust the search result depending on the currently selected row.
|
||
int currentrowindex = m_gui.DataGridView.SelectedCells[0].RowIndex;
|
||
if (currentrowindex < m_SearchResult[0])
|
||
{
|
||
m_gui.DataGridView.SelectARow(m_SearchResult[0]);
|
||
}
|
||
else if(currentrowindex < m_SearchResult[m_SearchResult.Count - 1])
|
||
{
|
||
foreach (int row in m_SearchResult)
|
||
{
|
||
if (currentrowindex <= row)
|
||
{
|
||
m_CurrentSearchIndex = m_SearchResult.IndexOf(row);
|
||
|
||
// Adjust if we are not directly on the selection...
|
||
if (currentrowindex < row)
|
||
m_CurrentSearchIndex--;
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (m_CurrentSearchIndex < m_SearchResult.Count - 1)
|
||
m_CurrentSearchIndex++;
|
||
|
||
m_gui.DataGridView.SelectARow(m_SearchResult[m_CurrentSearchIndex]);
|
||
}
|
||
}
|
||
|
||
m_gui.ToolStripTextToSearch.Focus();
|
||
}
|
||
|
||
|
||
private void ToolStripPreviousHitClick(object sender, EventArgs e)
|
||
{
|
||
// We don't do anything if there is no search result...
|
||
if (m_SearchResult == null)
|
||
return;
|
||
|
||
if (m_SearchResult.Count > 0)
|
||
{
|
||
// Adjust the search result depending on the currently selected row.
|
||
int currentrowindex = m_gui.DataGridView.SelectedCells[0].RowIndex;
|
||
if (currentrowindex > m_SearchResult[m_SearchResult.Count - 1])
|
||
{
|
||
m_gui.DataGridView.SelectARow(m_SearchResult[m_SearchResult.Count - 1]);
|
||
}
|
||
else if(currentrowindex > m_SearchResult[0])
|
||
{
|
||
for (int i = m_SearchResult.Count - 1; i >= 0; i--)
|
||
{
|
||
int row = m_SearchResult[i];
|
||
if (currentrowindex >= row)
|
||
{
|
||
m_CurrentSearchIndex = m_SearchResult.IndexOf(row);
|
||
|
||
// Adjust if we are not directly on the selection...
|
||
if (currentrowindex > row)
|
||
m_CurrentSearchIndex++;
|
||
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (m_CurrentSearchIndex > 0)
|
||
m_CurrentSearchIndex--;
|
||
|
||
m_gui.DataGridView.SelectARow(m_SearchResult[m_CurrentSearchIndex]);
|
||
}
|
||
}
|
||
|
||
m_gui.ToolStripTextToSearch.Focus();
|
||
}
|
||
|
||
private void ToolStripLegendClick(object sender, EventArgs e)
|
||
{
|
||
if (m_LegendWindow == null)
|
||
{
|
||
m_LegendWindow = new LegendWindow(m_gui);
|
||
m_LegendWindow.Owner = m_gui;
|
||
}
|
||
|
||
if (!m_LegendWindow.Visible)
|
||
{
|
||
m_LegendWindow.Show();
|
||
}
|
||
else
|
||
{
|
||
m_LegendWindow.Hide();
|
||
}
|
||
}
|
||
|
||
|
||
//This function is used to fill the list views of the dependencies and such
|
||
//this is NOT the method used to fill the listviewEx that allows the client to enable/disable modules and configs
|
||
private void FillListView(ListView oListView, List<Module> oList)
|
||
{
|
||
ClearListView(oListView);
|
||
|
||
Module oModule;
|
||
ListViewItem oItem;
|
||
Profile oCurrentProfile = CoreModel.CurrentConfiguration.GetProfile(CoreModel.Indexes.ProfileIndex);
|
||
|
||
for (int i = 0; i < oList.Count; i++)
|
||
{
|
||
oModule = oList[i];
|
||
oItem = new ListViewItem(oModule.ModuleName);
|
||
oItem.ImageIndex = CoreModel.GetModuleIndex(oCurrentProfile, oModule);
|
||
oItem.Tag = oModule.Index;
|
||
oListView.Items.Add(oItem);
|
||
}
|
||
|
||
//after all the item have been added, sort them
|
||
oListView.Sort();
|
||
oListView.Invalidate();
|
||
}
|
||
|
||
|
||
//this function is actually used to fill the list view of the modules currently depending on the selected module
|
||
//this is NOT the method used to fill the listviewEx that allows the client to enable/disable modules and configs
|
||
private void FillListViewCurrentReference(ListView oListView, Module oModule)
|
||
{
|
||
|
||
ClearListView(oListView);
|
||
|
||
Module oCurrentModule = null;
|
||
ListViewItem oItem;
|
||
Profile oCurrentProfile = CoreModel.CurrentConfiguration.GetProfile(CoreModel.Indexes.ProfileIndex);
|
||
|
||
if (oModule.ModuleIsEnabled)
|
||
{
|
||
for (int i = 0; i < oModule.DirectReferences.Count; i++)
|
||
{
|
||
oCurrentModule = oModule.DirectReferences[i];
|
||
|
||
if (oCurrentModule.DependenciesCounter > 0)
|
||
{
|
||
oItem = new ListViewItem(oCurrentModule.ModuleName);
|
||
oItem.ImageIndex = CoreModel.GetModuleIndex(oCurrentProfile, oCurrentModule);
|
||
oItem.Tag = oCurrentModule.Index;
|
||
oListView.Items.Add(oItem);
|
||
}
|
||
}
|
||
|
||
//after all the item have been added, sort them
|
||
oListView.Sort();
|
||
oListView.Invalidate();
|
||
}
|
||
}
|
||
|
||
|
||
internal void EnableDisableExternalPanel(bool bEnabled, bool bExternal, string strText)
|
||
{
|
||
m_gui.BottomPanel1.GetExternalGroupBox().Enabled = bEnabled;
|
||
m_gui.BottomPanel1.GetExternalCheckbox().Enabled = bEnabled;
|
||
|
||
m_gui.BottomPanel1.GetExternalCheckbox().Checked = bExternal;
|
||
m_gui.BottomPanel1.GetExternalTextBox().Enabled = bExternal;
|
||
|
||
if (strText != null)
|
||
m_gui.BottomPanel1.GetExternalTextBox().Text = strText;
|
||
else
|
||
m_gui.BottomPanel1.GetExternalTextBox().Text = "";
|
||
|
||
m_gui.BottomPanel1.GetExternalButton().Enabled = bExternal;
|
||
}
|
||
|
||
|
||
internal void DisplayConfigInfo(Configuration oConfig)
|
||
{
|
||
ResourceManager rm = new ResourceManager("Ubi.Tools.GearConfigTool.HtmlTemplates", GetType().Assembly);
|
||
|
||
string strTemplate = rm.GetObject("Configuration") as string;
|
||
|
||
string strMinimumValue;
|
||
string strMaximumValue;
|
||
string strDefaultValue;
|
||
|
||
if (oConfig.Type == ConfigurationType.DOUBLE || oConfig.Type == ConfigurationType.FLOAT || oConfig.Type == ConfigurationType.INT || oConfig.Type == ConfigurationType.UINT || oConfig.Type == ConfigurationType.POWEROFTWO)
|
||
{
|
||
strMinimumValue = oConfig.MinimumValue == "" ? oConfig.GetDefaultMinValue().ToString() : oConfig.MinimumValue;
|
||
strMaximumValue = oConfig.MaximumValue == "" ? oConfig.GetDefaultMaxValue().ToString() : oConfig.MaximumValue;
|
||
}
|
||
else
|
||
{
|
||
strMinimumValue = "n/a";
|
||
strMaximumValue = "n/a";
|
||
}
|
||
|
||
if (oConfig.DefaultValue == "" && oConfig.Type != ConfigurationType.STRING)
|
||
{
|
||
strDefaultValue = "n/a";
|
||
}
|
||
else
|
||
{
|
||
strDefaultValue = oConfig.DefaultValue;
|
||
}
|
||
|
||
string strAlignment = oConfig.Alignment == "" ? "n/a" : oConfig.Alignment;
|
||
string runtime = oConfig.RunTime ? "runtime " : "";
|
||
string appendToDescription = oConfig.RunTime ? "<br><br>To manipulate this configuration, use " +
|
||
"<strong>GEAR_SET_RT_CONFIG( " + oConfig.Tag + ", <i>value</i> );</strong>" : "";
|
||
|
||
strTemplate = strTemplate.Replace("{0}", oConfig.Name);
|
||
strTemplate = strTemplate.Replace("{1}", oConfig.Description + appendToDescription);
|
||
strTemplate = strTemplate.Replace("{2}", strMinimumValue);
|
||
strTemplate = strTemplate.Replace("{3}", strMaximumValue);
|
||
strTemplate = strTemplate.Replace("{4}", strAlignment);
|
||
strTemplate = strTemplate.Replace("{5}", runtime + oConfig.Type.ToString().ToLower());
|
||
strTemplate = strTemplate.Replace("{6}", strDefaultValue);
|
||
|
||
m_gui.BottomPanel1.GetConfigDescription().DocumentText = strTemplate;
|
||
}
|
||
|
||
|
||
internal void DisplayModuleInfo(Module oModule) //, int theSubSystemIndex, int theModuleIndex)
|
||
{
|
||
if (oModule == null)
|
||
return;
|
||
|
||
ResourceManager rm = new ResourceManager("Ubi.Tools.GearConfigTool.HtmlTemplates", GetType().Assembly);
|
||
|
||
string strTemplate = rm.GetObject("Module") as string;
|
||
|
||
strTemplate = strTemplate.Replace("{0}", oModule.ModuleName);
|
||
strTemplate = strTemplate.Replace("{1}", oModule.ModuleDescription);
|
||
|
||
FillListView(m_gui.BottomPanel1.GetListViewDirect(), oModule.DirectDependencies);
|
||
FillListView(m_gui.BottomPanel1.GetListViewOptional(), oModule.OptionalDependencies);
|
||
FillListView(m_gui.BottomPanel1.GetListViewDepending(), oModule.DirectReferences);
|
||
FillListViewCurrentReference(m_gui.BottomPanel1.GetListViewCurDepending(), oModule);
|
||
|
||
m_gui.BottomPanel1.GetModuleDescription().DocumentText = strTemplate;
|
||
m_gui.BottomPanel1.GetConfigDescription().DocumentText = "";
|
||
}
|
||
|
||
|
||
private void ClearListView(ListView oListView)
|
||
{
|
||
oListView.Items.Clear();
|
||
oListView.Clear();
|
||
}
|
||
|
||
|
||
internal void ClearModuleInfo()
|
||
{
|
||
ClearListView(m_gui.BottomPanel1.GetListViewDirect());
|
||
ClearListView(m_gui.BottomPanel1.GetListViewOptional());
|
||
ClearListView(m_gui.BottomPanel1.GetListViewDepending());
|
||
ClearListView(m_gui.BottomPanel1.GetListViewCurDepending());
|
||
|
||
m_gui.BottomPanel1.GetModuleDescription().DocumentText = "";
|
||
m_gui.BottomPanel1.GetConfigDescription().DocumentText = "";
|
||
}
|
||
|
||
|
||
private void DataGridView_SelectionChanged(object sender, EventArgs e)
|
||
{
|
||
GEARRow row = m_gui.DataGridView.GetSelectedRow();
|
||
|
||
// Always use the first profile if there is not current profile... to get the description...
|
||
Profile profile = m_gui.DataGridView.GetSelectedProfile();
|
||
if (profile == null)
|
||
profile = CoreModel.CurrentConfiguration.ProfileList[0];
|
||
|
||
// If we are still on the last row, we only want to update the external panel.
|
||
if (row != null && row == m_LastRow)
|
||
{
|
||
if(row.Type == RowType.RowModule)
|
||
{
|
||
Module module = profile.SubSystems[row.SubSystemIndex].Modules[row.ModuleIndex];
|
||
|
||
EnableDisableExternalPanel(
|
||
module.ModuleAvailable && !module.ModuleIsMandatory && module.ModuleIsEnabled,
|
||
module.ModuleIsExternal,
|
||
module.ModuleExternalFile);
|
||
}
|
||
return;
|
||
}
|
||
m_LastRow = row;
|
||
|
||
bool searchboxfocused = m_gui.ToolStripTextToSearch.Focused;
|
||
|
||
if ((row == null) || (CoreModel.CurrentConfiguration.ProfileList.Count == 0))
|
||
{
|
||
EnableDisableExternalPanel(false, false, "");
|
||
return;
|
||
}
|
||
|
||
//if node is a subsystem
|
||
if (row.Type == RowType.RowSubSystem)
|
||
{
|
||
ClearModuleInfo();
|
||
EnableDisableExternalPanel(false, false, "");
|
||
}
|
||
else if (row.Type == RowType.RowModule)
|
||
{
|
||
Module oModule = profile.SubSystems[row.SubSystemIndex].Modules[row.ModuleIndex];
|
||
|
||
DisplayModuleInfo(oModule);
|
||
|
||
// If not on a module description or module dependencies (index is 2 or more)
|
||
// and we are not on the External Module tab (index is 3) we change the selected index to be the
|
||
// module description (index 0) but only if the searchbox doesn't have focus.
|
||
if (!m_gui.ToolStripTextToSearch.Focused)
|
||
{
|
||
if ((m_gui.BottomPanel1.GetTabControl().SelectedIndex > 1) && (m_gui.BottomPanel1.GetTabControl().SelectedIndex != 3))
|
||
m_gui.BottomPanel1.GetTabControl().SelectedIndex = 0; // Set to module description.
|
||
}
|
||
}
|
||
else if (row.Type == RowType.RowConfiguration)
|
||
{
|
||
Module oModule = CoreModel.CurrentConfiguration.ProfileList[0].SubSystems[row.SubSystemIndex].Modules[row.ModuleIndex];
|
||
DisplayModuleInfo(oModule);
|
||
|
||
Configuration oConfiguration = oModule.Configurations[row.ConfigurationIndex];
|
||
DisplayConfigInfo(oConfiguration);
|
||
|
||
EnableDisableExternalPanel(false, false, "");
|
||
|
||
// If not on a configuration description (index is different than 2) and the searchbox doesn't have focus.
|
||
if (!m_gui.ToolStripTextToSearch.Focused)
|
||
{
|
||
if (m_gui.BottomPanel1.GetTabControl().SelectedIndex != 2)
|
||
m_gui.BottomPanel1.GetTabControl().SelectedIndex = 2; // Set to configuration description
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//node is unknown, do nothing for now
|
||
ClearModuleInfo();
|
||
EnableDisableExternalPanel(false, false, "");
|
||
}
|
||
|
||
// The SearchBox or the DataGridview as lost is focus because of us playing with the BottomPanel,
|
||
// focus the previously focused control.
|
||
if (searchboxfocused)
|
||
m_gui.ToolStripTextToSearch.Focus();
|
||
else
|
||
{
|
||
m_gui.DataGridView.Focus();
|
||
}
|
||
}
|
||
|
||
|
||
private void OnDragEnter(object sender, DragEventArgs e)
|
||
{
|
||
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||
{
|
||
e.Effect = DragDropEffects.Copy;
|
||
}
|
||
else
|
||
{
|
||
e.Effect = DragDropEffects.None;
|
||
}
|
||
}
|
||
|
||
private void OnDragDrop(object sender, DragEventArgs e)
|
||
{
|
||
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||
{
|
||
string[] filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop));
|
||
if( filePaths.Length == 1 )
|
||
{
|
||
if (File.Exists(filePaths[0]))
|
||
{
|
||
OpenFile(filePaths[0]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* Set the state of the Search TextBox to be enabled or not.
|
||
*
|
||
* Look at the row count and the state of the ShowOnly functionality to set the state...
|
||
*/
|
||
private void UpdateShowOnlyStates()
|
||
{
|
||
if ((m_gui.DataGridView.Rows.Count > 0) &&
|
||
!m_gui.ShowOnlyManuallyToolStripButton.Checked &&
|
||
!m_gui.ShowOnlySelectedToolStripButton.Checked &&
|
||
!m_gui.ShowOnlyDifferentToolStripButton.Checked)
|
||
{
|
||
m_gui.ToolStripTextToSearch.Enabled = true;
|
||
m_gui.EditMenuExpandAll.Enabled = true;
|
||
m_gui.EditMenuCollapseAll.Enabled = true;
|
||
}
|
||
else
|
||
{
|
||
m_gui.ToolStripTextToSearch.Enabled = false;
|
||
m_gui.EditMenuExpandAll.Enabled = false;
|
||
m_gui.EditMenuCollapseAll.Enabled = false;
|
||
}
|
||
|
||
ToolStripClearSearchClick(null, null);
|
||
}
|
||
|
||
/**
|
||
* Support changing the PerPlatformFile of CoreModel.
|
||
*/
|
||
private void MnuGeneratePerPlatformFilesClick(object sender, EventArgs e)
|
||
{
|
||
m_gui.MnuGeneratePerPlatformFiles.Checked = !m_gui.MnuGeneratePerPlatformFiles.Checked;
|
||
|
||
CoreModel.PerPlatformFile = m_gui.MnuGeneratePerPlatformFiles.Checked;
|
||
}
|
||
|
||
private void UpdateProfileListEvent(object sender, EventArgs e)
|
||
{
|
||
UpdateShowOnlyStates();
|
||
ToolStripClearSearchClick(null, null);
|
||
|
||
// Enable/Disable the relevant control depending on the profile count.
|
||
bool statetoset = false;
|
||
if(CoreModel.CurrentConfiguration.ProfileList.Count > 0)
|
||
statetoset = true;
|
||
else
|
||
statetoset = false;
|
||
|
||
m_gui.ShowOnlySelectedToolStripButton.Enabled = statetoset;
|
||
m_gui.ShowOnlyManuallyToolStripButton.Enabled = statetoset;
|
||
m_gui.DisplayConfigurationMenuItem.Enabled = statetoset;
|
||
|
||
if (!(statetoset && (CoreModel.CurrentConfiguration.ProfileList.Count > 1)))
|
||
statetoset = false;
|
||
|
||
m_gui.ShowOnlyDifferentToolStripButton.Enabled = statetoset;
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
/**
|
||
* Open filename if it is set. If filename is "", show the OpenFileDialog that ask for which file to open.
|
||
*/
|
||
public void OpenFile(String filename)
|
||
{
|
||
bool loadStatus = false;
|
||
ProgressWindow pbWindow = null;
|
||
|
||
try
|
||
{
|
||
// If no file name was provided, we ask the user for the wanted file name.
|
||
if (filename.Length == 0)
|
||
{
|
||
OpenFileDialog openDlg = Tools.IO.GetOpenFileDlg(m_appSettings, m_validationWindow, Filename, loadStatus, CoreModel.PerPlatformFile);
|
||
if (openDlg.ShowDialog() == DialogResult.OK)
|
||
filename = openDlg.FileName;
|
||
else
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
if (!File.Exists(filename))
|
||
{
|
||
MessageBox.Show("File does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
}
|
||
|
||
// Show a progress window and load the file!
|
||
pbWindow = m_gui.StartLoadConfigGUI(m_StartedFromCommand);
|
||
loadStatus = Tools.IO.OpenFile(filename, !m_StartedFromCommand, m_appSettings);
|
||
|
||
m_gui.LoadConfigGUI(m_StartedFromCommand, Filename, loadStatus, m_appSettings, pbWindow);
|
||
|
||
if (loadStatus)
|
||
{
|
||
|
||
// Save the loaded file name for the Save As function...
|
||
this.Filename = filename;
|
||
|
||
// Add the file to the recent file menu...
|
||
try
|
||
{
|
||
Tools.IO.AddToHistory(filename, m_appSettings);
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
ClearConfig();
|
||
}
|
||
|
||
// Make sure that if we loaded a config file that was set to be PerPlatform, we reflect that in the menu.
|
||
m_gui.MnuGeneratePerPlatformFiles.Checked = CoreModel.PerPlatformFile;
|
||
|
||
// Reset the state of the Show Only functionality and collapse the tree.
|
||
ResetShowOnly();
|
||
m_gui.DataGridView.CollapseAllRows();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||
version = version.Substring(0, version.LastIndexOf("."));
|
||
string boxTitle = "Gear Configuration Tool v" + version;
|
||
MessageBox.Show(ex.Message, boxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
pbWindow.Close();
|
||
return;
|
||
}
|
||
}
|
||
|
||
#region Private functions
|
||
|
||
private void ResetApplication()
|
||
{
|
||
CoreModel.CurrentConfiguration = new ConfigurationFile();
|
||
CoreModel.Indexes.ProfileIndex = 0;
|
||
|
||
m_gui.ResetGui();
|
||
|
||
CoreModel.Indexes.Reset();
|
||
this.Filename = null;
|
||
}
|
||
|
||
private void SetCurrentConfigurationFile(ConfigurationFile oFile, bool bSilentLoad)
|
||
{
|
||
CoreModel.CurrentConfiguration = oFile;
|
||
|
||
if (!bSilentLoad)
|
||
{
|
||
m_gui.SetConfigurationFile();
|
||
}
|
||
|
||
this.Filename = oFile.Filename;
|
||
}
|
||
|
||
private void ClearConfig()
|
||
{
|
||
m_appSettings.RecentFiles.Clear();
|
||
m_appSettings.SaveAppSettings();
|
||
m_gui.UpdateRecentFilesMenu(m_appSettings);
|
||
}
|
||
|
||
// Return if the profile has been added.
|
||
private AddProfileDlg menuItemProfilesAdd(bool bReset)
|
||
{
|
||
AddProfileDlg addProfileDlg = new AddProfileDlg(bReset);
|
||
|
||
//if( bReset )
|
||
//{
|
||
// addProfileDlg.OnBOk_Click += new AddProfileDlg.OnBOk_ClickDelegate(addProfileDlg_OnBOk_Click);
|
||
//}
|
||
addProfileDlg.ShowDialog();
|
||
|
||
return addProfileDlg;
|
||
}
|
||
|
||
private void addProfileDlg_OnBOk_Click()
|
||
{
|
||
ResetApplication();
|
||
}
|
||
|
||
private void addProfile(AddProfileDlg addProfileDlg)
|
||
{
|
||
addProfileDlg.Hide();
|
||
AddProfile(addProfileDlg.ProfileName, addProfileDlg.SelectedPlatform, addProfileDlg.Target, addProfileDlg.SourceProfile, addProfileDlg.Aliases);
|
||
CoreModel.CurrentConfiguration.FileChanged = true;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Internal functions
|
||
internal bool OnExitApplication()
|
||
{
|
||
bool bExit = true;
|
||
|
||
if (CoreModel.CurrentConfiguration.FileChanged)
|
||
{
|
||
DialogResult saveResult = MessageBox.Show("Changes have been made. Save Changes ?\n", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
||
|
||
if (saveResult == DialogResult.Yes)
|
||
{
|
||
string filename = Tools.IO.SaveFile(CoreModel.CurrentConfiguration, m_appSettings, m_validationWindow, Filename, CoreModel.PerPlatformFile);
|
||
|
||
// An error occurred is filename is empty
|
||
if (filename.Equals(""))
|
||
bExit = false;
|
||
else
|
||
m_gui.UpdateRecentFilesMenu(m_appSettings);
|
||
}
|
||
else if (saveResult == DialogResult.Cancel)
|
||
{
|
||
bExit = false;
|
||
}
|
||
}
|
||
|
||
if (bExit)
|
||
{
|
||
if (m_LegendWindow != null)
|
||
m_LegendWindow.Dispose();
|
||
|
||
m_appSettings.SaveAppSettings();
|
||
Application.Exit();
|
||
}
|
||
|
||
return bExit;
|
||
}
|
||
|
||
internal void SetSelection(GearReference oReference)
|
||
{
|
||
CoreModel.Indexes.ConfigIndex = oReference.GetIndex(GearReference.ReferenceType.ConfigIndex);
|
||
CoreModel.Indexes.ModuleIndex = oReference.GetIndex(GearReference.ReferenceType.ModuleIndex);
|
||
CoreModel.Indexes.SubSystemIndex = oReference.GetIndex(GearReference.ReferenceType.SubSystemIndex);
|
||
CoreModel.Indexes.ProfileIndex = oReference.GetIndex(GearReference.ReferenceType.ProfileIndex);
|
||
|
||
}
|
||
#endregion
|
||
|
||
|
||
}
|
||
}
|