Skip to content

Commit 9ed85e0

Browse files
authored
Merge updated export handling for document modules
2 parents 79cea90 + e98959b commit 9ed85e0

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

Rubberduck.Core/UI/CodeExplorer/Commands/ExportCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public bool PromptFileNameAndExport(QualifiedModuleName qualifiedModule)
100100
var component = ProjectsProvider.Component(qualifiedModule);
101101
try
102102
{
103-
component.Export(dialog.FileName);
103+
var path = System.IO.Path.GetDirectoryName(dialog.FileName);
104+
component.ExportAsSourceFile(path, false, true); // skipped optional parameters interfere with mock setup
104105
}
105106
catch (Exception ex)
106107
{

Rubberduck.Core/UI/Command/ComCommands/ExportAllCommand.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,9 @@ private void Export(IVBProject project)
107107

108108
// If .GetDirectoryName is passed an empty string for a RootFolder,
109109
// it defaults to the Documents library (Win 7+) or equivalent.
110-
var path = string.Empty;
111-
if (!string.IsNullOrWhiteSpace(project.FileName))
112-
{
113-
path = Path.GetDirectoryName(project.FileName);
114-
}
110+
var path = string.IsNullOrWhiteSpace(project.FileName)
111+
? string.Empty
112+
: Path.GetDirectoryName(project.FileName);
115113

116114
using (var _folderBrowser = _factory.CreateFolderBrowser(desc, true, path))
117115
{

Rubberduck.VBEEditor/SafeComWrappers/VB/Abstract/IVBComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public interface IVBComponent : ISafeComWrapper, IEquatable<IVBComponent>
2020
IWindow DesignerWindow();
2121
void Activate();
2222
void Export(string path);
23-
string ExportAsSourceFile(string folder, bool tempFile = false, bool specialCaseDocumentModules = true);
23+
string ExportAsSourceFile(string folder, bool isTempFile = false, bool specialCaseDocumentModules = true);
2424
int FileCount { get; }
2525
string GetFileName(short index);
2626
IVBProject ParentProject { get; }

Rubberduck.VBEditor.VB6/SafeComWrappers/VB/VBComponent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ public bool HasDesigner
123123
/// Exports the component to the folder. The file name matches the component name and file extension is based on the component's type.
124124
/// </summary>
125125
/// <param name="folder">Destination folder for the resulting source file.</param>
126-
/// <param name="tempFile">True if a unique temp file name should be generated. WARNING: filenames generated with this flag are not persisted.</param>
127-
/// <param name="specialCaseDocumentModules">If reimpot of a document file is required later, it has to receive special treatment.</param>
128-
public string ExportAsSourceFile(string folder, bool tempFile = false, bool specialCaseDocumentModules = true)
126+
/// <param name="isTempFile">True if a unique temp file name should be generated. WARNING: filenames generated with this flag are not persisted.</param>
127+
/// <param name="specialCaseDocumentModules">If reimport of a document file is required later, it has to receive special treatment.</param>
128+
public string ExportAsSourceFile(string folder, bool isTempFile = false, bool specialCaseDocumentModules = true)
129129
{
130130
throw new NotSupportedException("Export as source file is not supported in VB6");
131131
}

Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBComponent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ public bool HasDesigner
9595
/// Exports the component to the folder. The file name matches the component name and file extension is based on the component's type.
9696
/// </summary>
9797
/// <param name="folder">Destination folder for the resulting source file.</param>
98-
/// <param name="tempFile">True if a unique temp file name should be generated. WARNING: filenames generated with this flag are not persisted.</param>
98+
/// <param name="isTempFile">True if a unique temp file name should be generated. WARNING: filenames generated with this flag are not persisted.</param>
9999
/// <param name="specialCaseDocumentModules">If reimport of a document file is required later, it has to receive special treatment.</param>
100-
public string ExportAsSourceFile(string folder, bool tempFile = false, bool specialCaseDocumentModules = true)
100+
public string ExportAsSourceFile(string folder, bool isTempFile = false, bool specialCaseDocumentModules = true)
101101
{
102102
//TODO: this entire thign needs to be reworked. IO is not the class' concern.
103103
//We probably need to leverage IPersistancePathProvider? ITempSourceFileHandler?
104104
//Just not here.
105-
var fullPath = tempFile
105+
var fullPath = isTempFile
106106
? Path.Combine(folder, Path.GetRandomFileName())
107107
: Path.Combine(folder, SafeName + Type.FileExtension());
108108

@@ -160,7 +160,7 @@ private void ExportUserFormModule(string path)
160160

161161
var tempFile = ExportToTempFile();
162162
var tempFilePath = Directory.GetParent(tempFile).FullName;
163-
var fileEncoding = System.Text.Encoding.Default; //We use the current ANSI codepage because that is what the VBE does.
163+
var fileEncoding = Encoding.Default; //We use the current ANSI codepage because that is what the VBE does.
164164
var contents = File.ReadAllLines(tempFile, fileEncoding);
165165
var nonAttributeLines = contents.TakeWhile(line => !line.StartsWith("Attribute")).Count();
166166
var attributeLines = contents.Skip(nonAttributeLines).TakeWhile(line => line.StartsWith("Attribute")).Count();

RubberduckTests/CodeExplorer/CodeExplorerViewModelTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,14 +1847,17 @@ public void ReplaceProjectContentsFromFiles_Cancel()
18471847
[Test]
18481848
public void ExportModule_ExpectExecution()
18491849
{
1850-
const string path = @"C:\Users\Rubberduck\Desktop\StdModule1.bas";
1850+
const string folder = @"C:\Users\Rubberduck\Desktop";
1851+
const string filename = "StdModule1.bas";
1852+
var path = Path.Combine(folder, filename);
18511853

18521854
using (var explorer = new MockedCodeExplorer(ProjectType.HostProject)
18531855
.ConfigureSaveDialog(path, DialogResult.OK)
18541856
.SelectFirstModule())
18551857
{
1858+
explorer.VbComponent.Setup(c => c.ExportAsSourceFile(folder, It.IsAny<bool>(), It.IsAny<bool>()));
18561859
explorer.ExecuteExportCommand();
1857-
explorer.VbComponent.Verify(c => c.Export(path), Times.Once);
1860+
explorer.VbComponent.Verify(c => c.ExportAsSourceFile(folder, false, true), Times.Once);
18581861
}
18591862
}
18601863

@@ -1868,8 +1871,11 @@ public void ExportModule_CancelPressed_ExpectNoExecution()
18681871
.ConfigureSaveDialog(path, DialogResult.Cancel)
18691872
.SelectFirstModule())
18701873
{
1874+
explorer.VbComponent.Setup(c => c.Export(path));
1875+
explorer.VbComponent.Setup(c => c.ExportAsSourceFile(path, It.IsAny<bool>(), It.IsAny<bool>()));
18711876
explorer.ExecuteExportCommand();
18721877
explorer.VbComponent.Verify(c => c.Export(path), Times.Never);
1878+
explorer.VbComponent.Verify(c => c.ExportAsSourceFile(path, It.IsAny<bool>(), It.IsAny<bool>()), Times.Never);
18731879
}
18741880
}
18751881

0 commit comments

Comments
 (0)