Commit 7df0fdad authored by Murray Cumming's avatar Murray Cumming
Browse files

xport: Use .csv file extension to match the filter when importing.

* glom/utils_ui.[h]cc]: Added get_filepath_with_extension() to add
(if necessary) a specified file extension to a filepath.
* glom/frame_glom.cc: on_menu_file_export(): Add a .csv file
extension if not already specified, so we automatically see the
export file in the file chooser when importing.
parent 183b6f2b
2009-09-21 Murray Cumming <murrayc@murrayc.com>
Export: Use .csv file extension to match the filter when importing.
* glom/utils_ui.[h]cc]: Added get_filepath_with_extension() to add
(if necessary) a specified file extension to a filepath.
* glom/frame_glom.cc: on_menu_file_export(): Add a .csv file
extension if not already specified, so we automatically see the
export file in the file chooser when importing.
2009-09-21 Murray Cumming <murrayc@murrayc.com>
 
* glom/dialog_import_csv.cc: get_data(): Avoid out-of-bounds crashes
......
......@@ -593,10 +593,12 @@ void Frame_Glom::on_menu_file_export()
if((response == Gtk::RESPONSE_CANCEL) || (response == Gtk::RESPONSE_DELETE_EVENT))
return;
const std::string filepath = dialog.get_filename();
std::string filepath = dialog.get_filename();
if(filepath.empty())
return;
filepath = Utils::get_filepath_with_extension(filepath, "csv");
dialog.get_layout_groups(mapGroupSequence);
//std::cout << "DEBUG 0: mapGroupSequence.size()=" << mapGroupSequence.size() << std::endl;
......
......@@ -319,4 +319,31 @@ Glib::RefPtr<Gdk::Pixbuf> Utils::get_pixbuf_for_gda_value(const Gnome::Gda::Valu
return result;
}
std::string Utils::get_filepath_with_extension(const std::string& filepath, const std::string& extension)
{
std::string result = filepath;
bool add_ext = false;
const std::string str_ext = "." + extension;
if(result.size() < str_ext.size()) //It can't have the ext already if it's not long enough.
{
add_ext = true; //It isn't there already.
}
else
{
const Glib::ustring strEnd = result.substr(result.size() - str_ext.size());
if(strEnd != str_ext) //If it doesn't already have the extension
add_ext = true;
}
//Add extension if necessay.
if(add_ext)
result += str_ext;
//TODO: Do not replace existing extensions, so it could be e.g. 'something.blah.theext'
return result;
}
} //namespace Glom
......@@ -66,6 +66,9 @@ Glib::ustring bold_message(const Glib::ustring& message);
Glib::RefPtr<Gdk::Pixbuf> get_pixbuf_for_gda_value(const Gnome::Gda::Value& value);
/// Add the @a extension if no extension is there already:
std::string get_filepath_with_extension(const std::string& filepath, const std::string& extension);
} //namespace Utils
} //namespace Glom
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment