Merge pull request #4854 from Beep6581/fix-saveasdlg
Fix wrong suffix in `SaveAsDialog` (#4446)
This commit is contained in:
commit
2a9d3896bb
@ -363,15 +363,12 @@ void BatchQueuePanel::pathFolderButtonPressed ()
|
|||||||
// since these settings are shared with editorpanel :
|
// since these settings are shared with editorpanel :
|
||||||
void BatchQueuePanel::pathFolderChanged ()
|
void BatchQueuePanel::pathFolderChanged ()
|
||||||
{
|
{
|
||||||
|
|
||||||
options.savePathFolder = outdirFolder->get_filename();
|
options.savePathFolder = outdirFolder->get_filename();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchQueuePanel::formatChanged (Glib::ustring f)
|
void BatchQueuePanel::formatChanged(const Glib::ustring& format)
|
||||||
{
|
{
|
||||||
|
|
||||||
options.saveFormatBatch = saveFormatPanel->getFormat();
|
options.saveFormatBatch = saveFormatPanel->getFormat();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BatchQueuePanel::handleShortcutKey (GdkEventKey* event)
|
bool BatchQueuePanel::handleShortcutKey (GdkEventKey* event)
|
||||||
|
@ -72,7 +72,7 @@ public:
|
|||||||
void saveOptions ();
|
void saveOptions ();
|
||||||
void pathFolderChanged ();
|
void pathFolderChanged ();
|
||||||
void pathFolderButtonPressed ();
|
void pathFolderButtonPressed ();
|
||||||
void formatChanged (Glib::ustring f);
|
void formatChanged(const Glib::ustring& format) override;
|
||||||
void updateTab (int qsize, int forceOrientation = 0); // forceOrientation=0: base on options / 1: horizontal / 2: vertical
|
void updateTab (int qsize, int forceOrientation = 0); // forceOrientation=0: base on options / 1: horizontal / 2: vertical
|
||||||
|
|
||||||
bool handleShortcutKey (GdkEventKey* event);
|
bool handleShortcutKey (GdkEventKey* event);
|
||||||
|
@ -16,15 +16,36 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
|
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include "saveasdlg.h"
|
#include "saveasdlg.h"
|
||||||
#include "multilangmgr.h"
|
|
||||||
#include "guiutils.h"
|
#include "guiutils.h"
|
||||||
|
#include "multilangmgr.h"
|
||||||
#include "rtimage.h"
|
#include "rtimage.h"
|
||||||
|
|
||||||
#include "../rtengine/utils.h"
|
#include "../rtengine/utils.h"
|
||||||
|
|
||||||
extern Options options;
|
extern Options options;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
Glib::ustring getCurrentFilename(const Gtk::FileChooserWidget* fchooser)
|
||||||
|
{
|
||||||
|
Glib::ustring res = fchooser->get_filename();
|
||||||
|
|
||||||
|
// NB: There seem to be a bug in Gtkmm2.22 / FileChooserWidget : if you suppress the filename entry and
|
||||||
|
// click on a folder in the list, the filename field is empty but get_filename will return the folder's path :/
|
||||||
|
if (Glib::file_test(res, Glib::FILE_TEST_IS_DIR)) {
|
||||||
|
res = fchooser->get_current_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
SaveAsDialog::SaveAsDialog (const Glib::ustring &initialDir, Gtk::Window* parent)
|
SaveAsDialog::SaveAsDialog (const Glib::ustring &initialDir, Gtk::Window* parent)
|
||||||
: Gtk::Dialog (M("GENERAL_SAVE"), *parent)
|
: Gtk::Dialog (M("GENERAL_SAVE"), *parent)
|
||||||
{
|
{
|
||||||
@ -219,13 +240,7 @@ SaveFormat SaveAsDialog::getFormat ()
|
|||||||
|
|
||||||
void SaveAsDialog::okPressed ()
|
void SaveAsDialog::okPressed ()
|
||||||
{
|
{
|
||||||
fname = fchooser->get_filename();
|
fname = getCurrentFilename(fchooser);
|
||||||
|
|
||||||
// NB: There seem to be a bug in Gtkmm2.22 / FileChooserWidget : if you suppress the filename entry and
|
|
||||||
// click on a folder in the list, the filename field is empty but get_filename will return the folder's path :/
|
|
||||||
if (Glib::file_test(fname, Glib::FILE_TEST_IS_DIR)) {
|
|
||||||
fname = fchooser->get_current_name();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checking if the filename field is empty. The user have to click Cancel if he don't want to specify a filename
|
// Checking if the filename field is empty. The user have to click Cancel if he don't want to specify a filename
|
||||||
if (fname.empty()) {
|
if (fname.empty()) {
|
||||||
@ -246,9 +261,18 @@ void SaveAsDialog::okPressed ()
|
|||||||
// Extension is either empty or unfamiliar
|
// Extension is either empty or unfamiliar
|
||||||
fname += '.' + formatOpts->getFormat().format;
|
fname += '.' + formatOpts->getFormat().format;
|
||||||
} else if (
|
} else if (
|
||||||
!rtengine::hasJpegExtension(fname)
|
(
|
||||||
|
formatOpts->getFormat().format == "jpg"
|
||||||
|
&& !rtengine::hasJpegExtension(fname)
|
||||||
|
)
|
||||||
|
|| (
|
||||||
|
formatOpts->getFormat().format == "tif"
|
||||||
&& !rtengine::hasTiffExtension(fname)
|
&& !rtengine::hasTiffExtension(fname)
|
||||||
|
)
|
||||||
|
|| (
|
||||||
|
formatOpts->getFormat().format == "png"
|
||||||
&& !rtengine::hasPngExtension(fname)
|
&& !rtengine::hasPngExtension(fname)
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
// Create dialog to warn user that the filename may have two extensions on the end
|
// Create dialog to warn user that the filename may have two extensions on the end
|
||||||
Gtk::MessageDialog msgd(
|
Gtk::MessageDialog msgd(
|
||||||
@ -283,15 +307,42 @@ void SaveAsDialog::cancelPressed ()
|
|||||||
response (Gtk::RESPONSE_CANCEL);
|
response (Gtk::RESPONSE_CANCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveAsDialog::formatChanged (Glib::ustring f)
|
void SaveAsDialog::formatChanged(const Glib::ustring& format)
|
||||||
{
|
{
|
||||||
|
const auto sanitize_suffix =
|
||||||
|
[this, format](const std::function<bool (const Glib::ustring&)>& has_suffix)
|
||||||
|
{
|
||||||
|
const Glib::ustring name = getCurrentFilename(fchooser);
|
||||||
|
|
||||||
if (f == "jpg") {
|
if (!has_suffix(name)) {
|
||||||
|
fchooser->set_current_name(removeExtension(Glib::path_get_basename(name)) + '.' + format);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (format == "jpg") {
|
||||||
fchooser->set_filter (filter_jpg);
|
fchooser->set_filter (filter_jpg);
|
||||||
} else if (f == "png") {
|
sanitize_suffix(
|
||||||
|
[](const Glib::ustring& filename)
|
||||||
|
{
|
||||||
|
return rtengine::hasJpegExtension(filename);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else if (format == "png") {
|
||||||
fchooser->set_filter (filter_png);
|
fchooser->set_filter (filter_png);
|
||||||
} else if (f == "tif") {
|
sanitize_suffix(
|
||||||
|
[](const Glib::ustring& filename)
|
||||||
|
{
|
||||||
|
return rtengine::hasPngExtension(filename);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else if (format == "tif") {
|
||||||
fchooser->set_filter (filter_tif);
|
fchooser->set_filter (filter_tif);
|
||||||
|
sanitize_suffix(
|
||||||
|
[](const Glib::ustring& filename)
|
||||||
|
{
|
||||||
|
return rtengine::hasTiffExtension(filename);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public:
|
|||||||
|
|
||||||
void okPressed ();
|
void okPressed ();
|
||||||
void cancelPressed ();
|
void cancelPressed ();
|
||||||
void formatChanged (Glib::ustring f);
|
void formatChanged(const Glib::ustring& format) override;
|
||||||
bool keyPressed (GdkEventKey* event);
|
bool keyPressed (GdkEventKey* event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ class FormatChangeListener
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~FormatChangeListener () {}
|
virtual ~FormatChangeListener() = default;
|
||||||
virtual void formatChanged (Glib::ustring f) {}
|
virtual void formatChanged(const Glib::ustring& format) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SaveFormatPanel : public Gtk::Grid, public AdjusterListener
|
class SaveFormatPanel : public Gtk::Grid, public AdjusterListener
|
||||||
|
Loading…
x
Reference in New Issue
Block a user