/// <summary> /// Go to a specific variable instance in a file /// </summary> /// <param name="var">variable to go to</param> public void GotoVariable(ISledVarBaseType var) { if (var == null) return; if (var.Locations.Count <= 0) return; if (var.Locations.Count == 1) { // Go to this specific one GotoLineWord( var.Locations[0].File, var.Name, var.Locations[0].Line, var.Locations[0].Occurence, false); } else { var dictLocations = new Dictionary<string, List<SledVarLocationType>>(StringComparer.CurrentCultureIgnoreCase); // Go through all locations grouping by file foreach (var loc in var.Locations) { List<SledVarLocationType> lstLocs; if (dictLocations.TryGetValue(loc.File, out lstLocs)) { // Add to existing key lstLocs.Add(loc); } else { // Create new key/value pair lstLocs = new List<SledVarLocationType> {loc}; dictLocations.Add(loc.File, lstLocs); } } if (dictLocations.Count <= 0) return; // Create variable goto form var form = new SledVarGotoForm(); // Create one syntax editor for all the iterations using (var sec = TextEditorFactory.CreateSyntaxHighlightingEditor()) { // Go through each file pulling out locations foreach (var kv in dictLocations) { StreamReader reader = null; try { // Open the file reader = new StreamReader(kv.Key, true); if (reader != StreamReader.Null) { // Read entire file contents into SyntaxEditor sec.Text = reader.ReadToEnd(); // Go through populating form foreach (var loc in kv.Value) { try { // Add location to the form form.AddLocation(loc, sec.GetLineText(loc.Line).Trim()); } catch (Exception ex2) { SledOutDevice.OutLine( SledMessageType.Info, SledUtil.TransSub(Localization.SledGotoVariableError1, loc.Line, kv.Key, ex2.Message)); } } } } catch (Exception ex1) { SledOutDevice.OutLine( SledMessageType.Info, SledUtil.TransSub(Localization.SledGotoVariableError2, kv.Key, ex1.Message)); } finally { // Close up reader if everything went well if ((reader != null) && (reader != StreamReader.Null)) { reader.Close(); reader.Dispose(); } } } } if (form.ShowDialog(m_mainForm) == DialogResult.OK) { // Go to this one GotoLineWord( form.SelectedLocation.File, var.Name, form.SelectedLocation.Line, form.SelectedLocation.Occurence, false); } form.Dispose(); } }
/// <summary> /// Go to a specific variable instance in a file /// </summary> /// <param name="var">variable to go to</param> public void GotoVariable(ISledVarBaseType var) { if (var == null) { return; } if (var.Locations.Count <= 0) { return; } if (var.Locations.Count == 1) { // Go to this specific one GotoLineWord( var.Locations[0].File, var.Name, var.Locations[0].Line, var.Locations[0].Occurence, false); } else { var dictLocations = new Dictionary <string, List <SledVarLocationType> >(StringComparer.CurrentCultureIgnoreCase); // Go through all locations grouping by file foreach (var loc in var.Locations) { List <SledVarLocationType> lstLocs; if (dictLocations.TryGetValue(loc.File, out lstLocs)) { // Add to existing key lstLocs.Add(loc); } else { // Create new key/value pair lstLocs = new List <SledVarLocationType> { loc }; dictLocations.Add(loc.File, lstLocs); } } if (dictLocations.Count <= 0) { return; } // Create variable goto form var form = new SledVarGotoForm(); // Create one syntax editor for all the iterations using (var sec = TextEditorFactory.CreateSyntaxHighlightingEditor()) { // Go through each file pulling out locations foreach (var kv in dictLocations) { StreamReader reader = null; try { // Open the file reader = new StreamReader(kv.Key, true); if (reader != StreamReader.Null) { // Read entire file contents into SyntaxEditor sec.Text = reader.ReadToEnd(); // Go through populating form foreach (var loc in kv.Value) { try { // Add location to the form form.AddLocation(loc, sec.GetLineText(loc.Line).Trim()); } catch (Exception ex2) { SledOutDevice.OutLine( SledMessageType.Info, SledUtil.TransSub(Localization.SledGotoVariableError1, loc.Line, kv.Key, ex2.Message)); } } } } catch (Exception ex1) { SledOutDevice.OutLine( SledMessageType.Info, SledUtil.TransSub(Localization.SledGotoVariableError2, kv.Key, ex1.Message)); } finally { // Close up reader if everything went well if ((reader != null) && (reader != StreamReader.Null)) { reader.Close(); reader.Dispose(); } } } } if (form.ShowDialog(m_mainForm) == DialogResult.OK) { // Go to this one GotoLineWord( form.SelectedLocation.File, var.Name, form.SelectedLocation.Line, form.SelectedLocation.Occurence, false); } form.Dispose(); } }