Remember separate default directories for opening and writing each of animations...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Thu, 24 Jan 2008 11:00:15 +0000 (11:00 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Thu, 24 Jan 2008 11:00:15 +0000 (11:00 +0000)
git-svn-id: http://svn.voria.com/code@1456 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-studio/trunk/src/gtkmm/app.cpp
synfig-studio/trunk/src/gtkmm/app.h
synfig-studio/trunk/src/gtkmm/canvasview.cpp
synfig-studio/trunk/src/gtkmm/instance.cpp
synfig-studio/trunk/src/gtkmm/render.cpp
synfig-studio/trunk/src/gtkmm/state_sketch.cpp
synfig-studio/trunk/src/gtkmm/widget_filename.cpp

index 6852023..29bf7df 100644 (file)
@@ -1535,8 +1535,10 @@ static OPENFILENAME ofn={};
 #endif
 
 bool
-App::dialog_open_file(const std::string &title, std::string &filename)
+App::dialog_open_file(const std::string &title, std::string &filename, std::string preference)
 {
+       info("App::dialog_open_file('%s', '%s', '%s')", title.c_str(), filename.c_str(), preference.c_str());
+
 #ifdef USE_WIN32_FILE_DIALOGS
        static TCHAR szFilter[] = TEXT ("All Files (*.*)\0*.*\0\0") ;
 
@@ -1581,26 +1583,36 @@ App::dialog_open_file(const std::string &title, std::string &filename)
 
 #else
        synfig::String prev_path;
-       if(!_preferences.get_value("curr_path",prev_path))
-               prev_path=".";
+
+       if(!_preferences.get_value(preference, prev_path))
+               prev_path = ".";
+
        prev_path = absolute_path(prev_path);
 
-    Gtk::FileChooserDialog *dialog=new Gtk::FileChooserDialog(title,Gtk::FILE_CHOOSER_ACTION_OPEN);
+    Gtk::FileChooserDialog *dialog = new Gtk::FileChooserDialog(title, Gtk::FILE_CHOOSER_ACTION_OPEN);
+
     dialog->set_current_folder(prev_path);
     dialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     dialog->add_button(Gtk::Stock::OPEN,   Gtk::RESPONSE_ACCEPT);
-    if(!filename.empty())
-               if (is_absolute_path(filename))
-                       dialog->set_filename(filename);
-               else
-                       dialog->set_filename(prev_path + ETL_DIRECTORY_SEPARATOR + filename);
-    if(dialog->run()==GTK_RESPONSE_ACCEPT) {
-        filename=dialog->get_filename();
+
+    if (filename.empty())
+               dialog->set_filename(prev_path);
+       else if (is_absolute_path(filename))
+               dialog->set_filename(filename);
+       else
+               dialog->set_filename(prev_path + ETL_DIRECTORY_SEPARATOR + filename);
+
+    if(dialog->run() == GTK_RESPONSE_ACCEPT) {
+        filename = dialog->get_filename();
+               info("Saving preference %s = '%s' in App::dialog_open_file()", preference.c_str(), dirname(filename).c_str());
+               _preferences.set_value(preference, dirname(filename));
         delete dialog;
         return true;
     }
+
     delete dialog;
     return false;
+
     /*
 
        GtkWidget *ok;
@@ -1635,7 +1647,7 @@ App::dialog_open_file(const std::string &title, std::string &filename)
        if(val==1)
        {
                filename=gtk_file_selection_get_filename(GTK_FILE_SELECTION(fileselection));
-               _preferences.set_value("curr_path",dirname(filename));
+               _preferences.set_value(preference,dirname(filename));
        }
        else
        {
@@ -1649,8 +1661,10 @@ App::dialog_open_file(const std::string &title, std::string &filename)
 }
 
 bool
-App::dialog_save_file(const std::string &title, std::string &filename)
+App::dialog_save_file(const std::string &title, std::string &filename, std::string preference)
 {
+       info("App::dialog_save_file('%s', '%s', '%s')", title.c_str(), filename.c_str(), preference.c_str());
+
 #if USE_WIN32_FILE_DIALOGS
        static TCHAR szFilter[] = TEXT ("All Files (*.*)\0*.*\0\0") ;
 
@@ -1689,27 +1703,34 @@ App::dialog_save_file(const std::string &title, std::string &filename)
        if(GetSaveFileName(&ofn))
        {
                filename=szFilename;
-               _preferences.set_value("curr_path",dirname(filename));
+               _preferences.set_value(preference,dirname(filename));
                return true;
        }
        return false;
 #else
        synfig::String prev_path;
-       if(!_preferences.get_value("curr_path",prev_path))
+
+       if(!_preferences.get_value(preference, prev_path))
                prev_path=".";
+
        prev_path = absolute_path(prev_path);
 
-    Gtk::FileChooserDialog *dialog=new Gtk::FileChooserDialog(title,Gtk::FILE_CHOOSER_ACTION_SAVE);
+    Gtk::FileChooserDialog *dialog = new Gtk::FileChooserDialog(title, Gtk::FILE_CHOOSER_ACTION_SAVE);
+
     dialog->set_current_folder(prev_path);
     dialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     dialog->add_button(Gtk::Stock::SAVE,   Gtk::RESPONSE_ACCEPT);
-    if(!filename.empty())
+
+    if (filename.empty())
+               dialog->set_filename(prev_path);
+    else
        {
                std::string full_path;
                if (is_absolute_path(filename))
                        full_path = filename;
                else
                        full_path = prev_path + ETL_DIRECTORY_SEPARATOR + filename;
+
                // select the file if it exists
                dialog->set_filename(full_path);
 
@@ -1718,15 +1739,17 @@ App::dialog_save_file(const std::string &title, std::string &filename)
                if(stat(full_path.c_str(),&s) == -1 && errno == ENOENT)
                        dialog->set_current_name(basename(filename));
        }
-    if(dialog->run()==GTK_RESPONSE_ACCEPT) {
-        filename=dialog->get_filename();
+
+    if(dialog->run() == GTK_RESPONSE_ACCEPT) {
+        filename = dialog->get_filename();
+               info("Saving preference %s = '%s' in App::dialog_save_file()", preference.c_str(), dirname(filename).c_str());
+               _preferences.set_value(preference, dirname(filename));
         delete dialog;
-               _preferences.set_value("curr_path",dirname(filename));
         return true;
     }
+
     delete dialog;
     return false;
-//     return dialog_open_file(title, filename);
 #endif
 }
 
@@ -1882,8 +1905,6 @@ App::open_as(std::string filename,std::string as)
                return false;
        }
 
-       _preferences.set_value("curr_path",dirname(as));
-
        return true;
 }
 
@@ -1920,7 +1941,7 @@ App::dialog_open()
 {
        string filename="*.sif";
 
-       while(dialog_open_file("Open", filename))
+       while(dialog_open_file("Open", filename, ANIMATION_DIR_PREFERENCE))
        {
                // If the filename still has wildcards, then we should
                // continue looking for the file we want
index a6d87cf..bd916aa 100644 (file)
 
 /* === M A C R O S ========================================================= */
 
+#define MISC_DIR_PREFERENCE                    "misc_dir"
+#define ANIMATION_DIR_PREFERENCE       "animation_dir"
+#define IMAGE_DIR_PREFERENCE           "image_dir"
+#define SKETCH_DIR_PREFERENCE          "sketch_dir"
+#define RENDER_DIR_PREFERENCE          "render_dir"
+
 /* === T Y P E D E F S ===================================================== */
 
 /* === C L A S S E S & S T R U C T S ======================================= */
@@ -307,8 +313,8 @@ public:
 
 //     static bool dialog_file(const std::string &title, std::string &filename);
 
-       static bool dialog_open_file(const std::string &title, std::string &filename);
-       static bool dialog_save_file(const std::string &title, std::string &filename);
+       static bool dialog_open_file(const std::string &title, std::string &filename, std::string preference);
+       static bool dialog_save_file(const std::string &title, std::string &filename, std::string preference);
 
        static void dialog_error_blocking(const std::string &title, const std::string &message);
 
index 4f6dec9..226848f 100644 (file)
@@ -3317,8 +3317,9 @@ CanvasView::toggle_duck_mask(Duckmatic::Type type)
 void
 CanvasView::image_import()
 {
-       String filename(dirname(get_canvas()->get_file_name()));
-       if(App::dialog_open_file(_("Import Image"), filename))
+       // String filename(dirname(get_canvas()->get_file_name()));
+       String filename("*.*");
+       if(App::dialog_open_file(_("Import Image"), filename, IMAGE_DIR_PREFERENCE))
                canvas_interface()->import(filename);
 }
 
index bb37c17..f0451ad 100644 (file)
@@ -225,7 +225,7 @@ studio::Instance::save()
 bool
 studio::Instance::dialog_save_as()
 {
-       string filename=basename(get_file_name());
+       string filename = get_file_name();
        Canvas::Handle canvas(get_canvas());
 
        {
@@ -255,16 +255,16 @@ studio::Instance::dialog_save_as()
        }
 
        // show the canvas' name if it has one, else its ID
-       while(App::dialog_save_file(_("Choose a Filename to Save As") +
-                                                               String(" (") +
-                                                               (canvas->get_name().empty()
-                                                                ? canvas->get_id()
-                                                                : canvas->get_name()) +
-                                                               ") ...", filename))
+       while (App::dialog_save_file((_("Choose a Filename to Save As") +
+                                                                 String(" (") +
+                                                                 (canvas->get_name().empty() ? canvas->get_id() : canvas->get_name()) +
+                                                                 ") ..."),
+                                                                filename, ANIMATION_DIR_PREFERENCE))
        {
                // If the filename still has wildcards, then we should
                // continue looking for the file we want
-               if(find(filename.begin(),filename.end(),'*')!=filename.end())
+               string base_filename = basename(filename);
+               if (find(base_filename.begin(),base_filename.end(),'*')!=base_filename.end())
                        continue;
 
                if (filename_extension(filename) == "")
index 6bb6d63..19d338e 100644 (file)
@@ -231,7 +231,7 @@ void
 RenderSettings::on_choose_pressed()
 {
        String filename=entry_filename.get_text();
-       if(App::dialog_save_file("Save Render As",filename))
+       if(App::dialog_save_file("Save Render As", filename, RENDER_DIR_PREFERENCE))
                entry_filename.set_text(filename);
 }
 
index 5a8ec15..2effb73 100644 (file)
@@ -154,7 +154,7 @@ StateSketch_Context::save_sketch()
 {
        synfig::String filename(basename(get_canvas()->get_file_name())+".sketch");
 
-       while(App::dialog_save_file(_("Save Sketch"), filename))
+       while(App::dialog_save_file(_("Save Sketch"), filename, SKETCH_DIR_PREFERENCE))
        {
                // If the filename still has wildcards, then we should
                // continue looking for the file we want
@@ -173,7 +173,7 @@ StateSketch_Context::load_sketch()
 {
        synfig::String filename(basename(get_canvas()->get_file_name())+".sketch");
 
-       while(App::dialog_open_file(_("Load Sketch"), filename))
+       while(App::dialog_open_file(_("Load Sketch"), filename, SKETCH_DIR_PREFERENCE))
        {
                // If the filename still has wildcards, then we should
                // continue looking for the file we want
index c88bf57..f0cc137 100644 (file)
@@ -110,6 +110,6 @@ Widget_Filename::on_button_choose_pressed()
        string filename=entry_filename->get_text();
        if(filename.empty())
                filename=".";
-       if(App::dialog_open_file(_("Choose File"),filename))
+       if(App::dialog_open_file(_("Choose File"), filename, MISC_DIR_PREFERENCE))
                entry_filename->set_text(filename);
 }