Fix file viewer glitch with empty output
The file viewer was seeing zero-length formatted output and assuming that it was the result of zero-length input. This is a problem because the code disables the format options when there's nothing to format. This resulted in the strange behavior noted in issue #14. Now the "is source empty" value is passed explicitly, and we display a different message when the formatter fails.
This commit is contained in:
parent
9f0640142d
commit
549342b3d9
|
@ -266,7 +266,22 @@ static void DumpBitmapInfo(HBITMAP hBitmap)
|
||||||
LOGD(" bmPits = 0x%p", info.bmBits);
|
LOGD(" bmPits = 0x%p", info.bmBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewFilesDialog::DisplayText(const WCHAR* fileName)
|
bool ViewFilesDialog::IsSourceEmpty(const GenericEntry* pEntry,
|
||||||
|
ReformatHolder::ReformatPart part)
|
||||||
|
{
|
||||||
|
switch (part) {
|
||||||
|
case ReformatHolder::ReformatPart::kPartData:
|
||||||
|
return pEntry->GetDataForkLen() == 0;
|
||||||
|
case ReformatHolder::ReformatPart::kPartRsrc:
|
||||||
|
return pEntry->GetRsrcForkLen() == 0;
|
||||||
|
case ReformatHolder::ReformatPart::kPartCmmt:
|
||||||
|
return !pEntry->GetHasNonEmptyComment();
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewFilesDialog::DisplayText(const WCHAR* fileName, bool zeroSourceLen)
|
||||||
{
|
{
|
||||||
CWaitCursor wait; // streaming of big files can take a little while
|
CWaitCursor wait; // streaming of big files can take a little while
|
||||||
bool errFlg;
|
bool errFlg;
|
||||||
|
@ -404,10 +419,14 @@ void ViewFilesDialog::DisplayText(const WCHAR* fileName)
|
||||||
if (fpOutput->GetOutputKind() == ReformatOutput::kOutputRTF)
|
if (fpOutput->GetOutputKind() == ReformatOutput::kOutputRTF)
|
||||||
streamFormat = SF_RTF;
|
streamFormat = SF_RTF;
|
||||||
if (fpOutput->GetTextLen() == 0) {
|
if (fpOutput->GetTextLen() == 0) {
|
||||||
textBuf = "(file is empty)";
|
if (zeroSourceLen) {
|
||||||
|
textBuf = "(file is empty)";
|
||||||
|
EnableFormatSelection(FALSE);
|
||||||
|
} else {
|
||||||
|
textBuf = "(converted output is empty)";
|
||||||
|
}
|
||||||
textLen = strlen(textBuf);
|
textLen = strlen(textBuf);
|
||||||
emptyFlg = true;
|
emptyFlg = true;
|
||||||
EnableFormatSelection(FALSE);
|
|
||||||
}
|
}
|
||||||
if (fpOutput->GetOutputKind() == ReformatOutput::kOutputErrorMsg)
|
if (fpOutput->GetOutputKind() == ReformatOutput::kOutputErrorMsg)
|
||||||
EnableFormatSelection(FALSE);
|
EnableFormatSelection(FALSE);
|
||||||
|
@ -638,7 +657,8 @@ void ViewFilesDialog::OnFviewNext(void)
|
||||||
id = ConfigureFormatSel(part);
|
id = ConfigureFormatSel(part);
|
||||||
Reformat(pSelEntry->GetEntry(), part, id);
|
Reformat(pSelEntry->GetEntry(), part, id);
|
||||||
|
|
||||||
DisplayText(pSelEntry->GetEntry()->GetDisplayName());
|
DisplayText(pSelEntry->GetEntry()->GetDisplayName(),
|
||||||
|
IsSourceEmpty(pSelEntry->GetEntry(), part));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewFilesDialog::OnFviewPrev(void)
|
void ViewFilesDialog::OnFviewPrev(void)
|
||||||
|
@ -681,7 +701,7 @@ void ViewFilesDialog::OnFviewPrev(void)
|
||||||
id = ConfigureFormatSel(part);
|
id = ConfigureFormatSel(part);
|
||||||
Reformat(pEntry, part, id);
|
Reformat(pEntry, part, id);
|
||||||
|
|
||||||
DisplayText(pEntry->GetDisplayName());
|
DisplayText(pEntry->GetDisplayName(), IsSourceEmpty(pEntry, part));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewFilesDialog::ConfigurePartButtons(const GenericEntry* pEntry)
|
void ViewFilesDialog::ConfigurePartButtons(const GenericEntry* pEntry)
|
||||||
|
@ -936,7 +956,7 @@ void ViewFilesDialog::OnFormatSelChange(void)
|
||||||
id = (ReformatHolder::ReformatID) pCombo->GetItemData(pCombo->GetCurSel());
|
id = (ReformatHolder::ReformatID) pCombo->GetItemData(pCombo->GetCurSel());
|
||||||
Reformat(pEntry, part, id);
|
Reformat(pEntry, part, id);
|
||||||
|
|
||||||
DisplayText(pEntry->GetDisplayName());
|
DisplayText(pEntry->GetDisplayName(), IsSourceEmpty(pEntry, part));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewFilesDialog::OnFviewData(void)
|
void ViewFilesDialog::OnFviewData(void)
|
||||||
|
@ -969,7 +989,7 @@ void ViewFilesDialog::ForkSelectCommon(ReformatHolder::ReformatPart part)
|
||||||
id = ConfigureFormatSel(part);
|
id = ConfigureFormatSel(part);
|
||||||
|
|
||||||
Reformat(pEntry, part, id);
|
Reformat(pEntry, part, id);
|
||||||
DisplayText(pEntry->GetDisplayName());
|
DisplayText(pEntry->GetDisplayName(), IsSourceEmpty(pEntry, part));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewFilesDialog::OnFviewFmtBest(void)
|
void ViewFilesDialog::OnFviewFmtBest(void)
|
||||||
|
|
|
@ -120,15 +120,23 @@ private:
|
||||||
//void StretchControl(int id, int deltaX, int deltaY);
|
//void StretchControl(int id, int deltaX, int deltaY);
|
||||||
void NewFontSelected(bool resetBold);
|
void NewFontSelected(bool resetBold);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Determines whether the specified part is an empty fork/comment.
|
||||||
|
*/
|
||||||
|
bool IsSourceEmpty(const GenericEntry* pEntry,
|
||||||
|
ReformatHolder::ReformatPart part);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display a buffer of text in the RichEdit control.
|
* Display a buffer of text in the RichEdit control.
|
||||||
*
|
*
|
||||||
* The RichEdit dialog will hold its own copy of the data, so "pHolder" can
|
* The RichEdit dialog will hold its own copy of the data, so "pHolder" can
|
||||||
* be safely destroyed after this returns.
|
* be safely destroyed after this returns.
|
||||||
*
|
*
|
||||||
* "fileName" is for display only.
|
* "fileName" is for display only. "zeroSourceLen" allows the function to
|
||||||
|
* tell the difference between an empty file and a non-empty file that
|
||||||
|
* generated empty output.
|
||||||
*/
|
*/
|
||||||
void DisplayText(const WCHAR* fileName);
|
void DisplayText(const WCHAR* fileName, bool zeroSourceLen);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the fpHolder. Does not reformat the data, just loads the source
|
* Set up the fpHolder. Does not reformat the data, just loads the source
|
||||||
|
|
Loading…
Reference in New Issue