Skip to content

Commit

Permalink
Add IsSaveSupported() function
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Sep 26, 2023
1 parent 276b466 commit 5a7d8aa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/WinIMerge/WinIMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
case ID_FILE_SAVE:
m_pImgMergeWindow->SaveImages();
for (int pane = 0; pane < m_pImgMergeWindow->GetPaneCount(); ++pane)
{
if (m_pImgMergeWindow->IsSaveSupported(pane))
{
if (!m_pImgMergeWindow->SaveImage(pane))
{
SaveImageAs(hWnd, pane);
}
}
else
SaveImageAs(hWnd, pane);
}
break;
case ID_FILE_SAVE_LEFT_AS:
SaveImageAs(hWnd, 0);
Expand Down
5 changes: 5 additions & 0 deletions src/WinIMergeLib/ImgMergeBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ class CImgMergeBuffer : public CImgDiffBuffer
m_undoRecords.set_savepoint(pane, pos);
}

bool IsSaveSupported(int pane) const
{
return !m_imgConverter[pane].isValid() && m_imgOrig[pane].isSaveSupported();
}

bool SaveImage(int pane)
{
if (pane < 0 || pane >= m_nImages)
Expand Down
5 changes: 5 additions & 0 deletions src/WinIMergeLib/ImgMergeWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,11 @@ class CImgMergeWindow : public IImgMergeWindow
m_buffer.SetSavePoint(pane, pos);
}

bool IsSaveSupported(int pane) const override
{
return m_buffer.IsSaveSupported(pane);
}

private:

ATOM MyRegisterClass(HINSTANCE hInstance)
Expand Down
1 change: 1 addition & 0 deletions src/WinIMergeLib/WinIMergeLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ struct IImgMergeWindow
virtual void SetVerticalFlip(int pane, bool flip) = 0;
virtual DIFF_ALGORITHM GetDiffAlgorithm() const = 0;
virtual void SetDiffAlgorithm(DIFF_ALGORITHM diffAlgorithm) = 0;
virtual bool IsSaveSupported(int pane) const = 0;
};

struct IImgToolWindow
Expand Down
1 change: 1 addition & 0 deletions src/WinIMergeLib/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class Image
return image_.convertTo8Bits() && image_.convertTo32Bits();
}
bool load(const std::wstring& filename) { return !!image_.loadU(filename.c_str()); }
bool isSaveSupported() const { return FreeImage_FIFSupportsWriting(image_.getFIF()); }
bool save(const std::wstring& filename)
{
#ifdef _WIN32
Expand Down

0 comments on commit 5a7d8aa

Please sign in to comment.