Skip to content

Commit b0a6334

Browse files
committed
Merge pull request #654 from Hosch250/next
Fix reorder/remove bug
2 parents d13c186 + 853cd29 commit b0a6334

File tree

8 files changed

+46
-17
lines changed

8 files changed

+46
-17
lines changed

RetailCoder.VBE/Refactorings/RemoveParameters/RemoveParametersRefactoring.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private void RemoveParameters()
6969
{
7070
if (_model.TargetDeclaration == null) { throw new NullReferenceException("Parameter is null."); }
7171

72-
AdjustReferences(_model.TargetDeclaration.References.OrderByDescending(item => item.Selection.StartLine), _model.TargetDeclaration);
72+
AdjustReferences(_model.TargetDeclaration.References, _model.TargetDeclaration);
7373
AdjustSignatures();
7474
}
7575

@@ -139,7 +139,10 @@ var param in
139139
}
140140

141141
module.ReplaceLine(paramList.Start.Line, newContent);
142-
module.DeleteLines(paramList.Start.Line + 1, lineCount - 1);
142+
for (var line = paramList.Start.Line + 1; line < paramList.Start.Line + lineCount; line++)
143+
{
144+
module.ReplaceLine(line, "");
145+
}
143146
}
144147

145148
private string GetOldSignature(Declaration target)
@@ -261,7 +264,7 @@ private void AdjustSignatures()
261264
{
262265
foreach (var reference in _model.Declarations.FindEventProcedures(withEvents))
263266
{
264-
AdjustReferences(reference.References.OrderByDescending(item => item.Selection.StartLine), reference);
267+
AdjustReferences(reference.References, reference);
265268
AdjustSignatures(reference);
266269
}
267270
}
@@ -271,7 +274,7 @@ private void AdjustSignatures()
271274
item.IdentifierName == _model.TargetDeclaration.ComponentName + "_" + _model.TargetDeclaration.IdentifierName);
272275
foreach (var interfaceImplentation in interfaceImplementations)
273276
{
274-
AdjustReferences(interfaceImplentation.References.OrderByDescending(item => item.Selection.StartLine), interfaceImplentation);
277+
AdjustReferences(interfaceImplentation.References, interfaceImplentation);
275278
AdjustSignatures(interfaceImplentation);
276279
}
277280
}
@@ -322,7 +325,10 @@ private void RemoveSignatureParameters(Declaration target, VBAParser.ArgListCont
322325
var lineNum = paramList.GetSelection().LineCount;
323326

324327
module.ReplaceLine(paramList.Start.Line, signature);
325-
module.DeleteLines(paramList.Start.Line + 1, lineNum - 1);
328+
for (var line = paramList.Start.Line + 1; line < paramList.Start.Line + lineNum; line++)
329+
{
330+
module.ReplaceLine(line, "");
331+
}
326332
}
327333
}
328334
}

RetailCoder.VBE/Refactorings/ReorderParameters/ReorderParametersRefactoring.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void Refactor()
3737
return;
3838
}
3939

40-
AdjustReferences(_model.TargetDeclaration.References.OrderByDescending(item => item.Selection.StartLine));
40+
AdjustReferences(_model.TargetDeclaration.References);
4141
AdjustSignatures();
4242
}
4343

@@ -140,7 +140,11 @@ private void RewriteCall(VBAParser.ArgsCallContext paramList, CodeModule module)
140140
}
141141

142142
module.ReplaceLine(paramList.Start.Line, newContent);
143-
module.DeleteLines(paramList.Start.Line + 1, lineCount - 1);
143+
144+
for (var line = paramList.Start.Line + 1; line < paramList.Start.Line + lineCount; line++)
145+
{
146+
module.ReplaceLine(line, "");
147+
}
144148
}
145149

146150
private void AdjustSignatures()
@@ -177,7 +181,7 @@ private void AdjustSignatures()
177181
{
178182
foreach (var reference in _model.Declarations.FindEventProcedures(withEvents))
179183
{
180-
AdjustReferences(reference.References.OrderByDescending(item => item.Selection.StartLine));
184+
AdjustReferences(reference.References);
181185
AdjustSignatures(reference);
182186
}
183187
}
@@ -187,7 +191,7 @@ private void AdjustSignatures()
187191
item.IdentifierName == _model.TargetDeclaration.ComponentName + "_" + _model.TargetDeclaration.IdentifierName);
188192
foreach (var interfaceImplentation in interfaceImplementations)
189193
{
190-
AdjustReferences(interfaceImplentation.References.OrderByDescending(item => item.Selection.StartLine));
194+
AdjustReferences(interfaceImplentation.References);
191195
AdjustSignatures(interfaceImplentation);
192196
}
193197
}
@@ -239,7 +243,11 @@ private void RewriteSignature(Declaration target, VBAParser.ArgListContext param
239243
}
240244

241245
module.ReplaceLine(paramList.Start.Line, newContent);
242-
module.DeleteLines(paramList.Start.Line + 1, lineNum - 1);
246+
247+
for (var line = paramList.Start.Line + 1; line < paramList.Start.Line + lineNum; line++)
248+
{
249+
module.ReplaceLine(line, "");
250+
}
243251
}
244252

245253
private string GetOldSignature(Declaration target)

RetailCoder.VBE/Settings/ConfigurationLoader.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Reflection;
6+
using System.Text;
67
using System.Windows.Forms;
78
using Rubberduck.Inspections;
89
using Rubberduck.ToDoItems;
@@ -69,9 +70,21 @@ protected override Configuration HandleIOException(IOException ex)
6970

7071
protected override Configuration HandleInvalidOperationException(InvalidOperationException ex)
7172
{
72-
var message = string.Format(RubberduckUI.PromptLoadDefaultConfig, ex.Message, ex.InnerException.Message, ConfigFile);
73+
var folder = Path.GetDirectoryName(ConfigFile);
74+
var newFilePath = folder + "\\rubberduck.config." + DateTime.UtcNow.ToString().Replace('/', '.').Replace(':', '.') + ".bak";
75+
76+
var message = string.Format(RubberduckUI.PromptLoadDefaultConfig, ex.Message, ex.InnerException.Message, ConfigFile, newFilePath);
7377
MessageBox.Show(message, RubberduckUI.LoadConfigError, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
7478

79+
using (var fs = File.Create(@newFilePath))
80+
{
81+
using (var reader = new StreamReader(folder + "\\rubberduck.config"))
82+
using (var writer = new StreamWriter(fs, Encoding.UTF8))
83+
{
84+
writer.Write(reader.ReadToEnd());
85+
}
86+
}
87+
7588
var config = GetDefaultConfiguration();
7689
SaveConfiguration(config);
7790
return config;

RetailCoder.VBE/Settings/ToDoMarkers.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public override string ToString()
5959

6060
public override bool Equals(object obj)
6161
{
62-
var other = (ToDoMarker)obj;
62+
var other = obj as ToDoMarker;
63+
64+
if (other == null) { return false; }
6365

6466
// no need to check PriorityLabel as it soley relies on Priority - if one is wrong, the other has to be too
6567
return Text == other.Text &&

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.fr.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@
435435
{2}
436436

437437
Restaurer les configurations par défaut?
438-
Attention: les valeurs personnalisées seront perdues.</value>
438+
Attention: les valeurs personnalisées seront perdues. Le fichier original sera enregistré sous '{3}'.</value>
439439
</data>
440440
<data name="ResolutionProgress" xml:space="preserve">
441441
<value>Résolution de '{0}'...</value>

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@
431431
{2}
432432

433433
Would you like to restore default configuration?
434-
Warning: All customized settings will be lost.</value>
434+
Warning: All customized settings will be lost. Your old file will be saved in '{3}'.</value>
435435
</data>
436436
<data name="ResolutionProgress" xml:space="preserve">
437437
<value>Resolving '{0}'...</value>

RetailCoder.VBE/UI/RubberduckUI.sv.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@
440440
{2}
441441

442442
Vill du återställa standardinställningarna?
443-
Varning: Alla anpassade inställningar kommer att försvinna.</value>
443+
Varning: Alla anpassade inställningar kommer att försvinna. Din gamla fil kommer att bli sparad i '{3}'.</value>
444444
</data>
445445
<data name="ResolutionProgress" xml:space="preserve">
446446
<value>Löser '{0}'...</value>
@@ -1099,4 +1099,4 @@ Varning: Alla anpassade inställningar kommer att försvinna.</value>
10991099
<data name="TodoSettings_Text" xml:space="preserve">
11001100
<value>Text</value>
11011101
</data>
1102-
</root>
1102+
</root>

0 commit comments

Comments
 (0)