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



commit 7df0fdad6438f21d72ca647bf6dc4c1133ae9677
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Sep 21 10:42:57 2009 +0200

    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.

 ChangeLog          |   10 ++++++++++
 glom/frame_glom.cc |    4 +++-
 glom/utils_ui.cc   |   27 +++++++++++++++++++++++++++
 glom/utils_ui.h    |    3 +++
 4 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index dc851c0..9c3eed2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 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 
 	when accessing the vector of vectors. Note that this check is 
 	already in the appropriate place in the import_csv_refactored branch.
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index c7ae069..35e8823 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -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;
 
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index b470100..b862bdc 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -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
diff --git a/glom/utils_ui.h b/glom/utils_ui.h
index 7eb9c6e..8b05ea0 100644
--- a/glom/utils_ui.h
+++ b/glom/utils_ui.h
@@ -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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]