]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormGraphics.C
try this for distinguishing inner and outer tabs
[lyx.git] / src / frontends / xforms / FormGraphics.C
index 886e309ed6ee4d030ec552e68ce8e90635ffadc2..48838a712d3464d73d653074cc409db423b4e1c2 100644 (file)
@@ -2,13 +2,6 @@
  * FormGraphics Interface Class Implementation
  */
 
-/* TODO:
- *      * Handle the case when the buffer is read-only.
- *          Initial work is done, if we are read-only the ok/cancel are 
- *          disabled. Probably we need to find a better way to deal with it.
- *      
- */
-
 #include <config.h> 
 
 #ifdef __GNUG__
@@ -25,9 +18,9 @@
 
 #include "debug.h" // for lyxerr
 
-#include "support/lstrings.h" // for strToDbl & tostr
-#include "support/FileInfo.h" // for FileInfo
-#include "filedlg.h" // for LyXFileDlg
+#include "support/lstrings.h"  // for strToDbl & tostr
+#include "support/FileInfo.h"  // for FileInfo
+#include "xform_helpers.h"     // for browseFile
 #include "support/filetools.h" // for AddName
 #include "insets/insetgraphics.h"
 #include "insets/insetgraphicsParams.h"
 #include "support/LAssert.h"
 
 using std::endl;
-
+using std::make_pair;
 
 FormGraphics::FormGraphics(LyXView * lv, Dialogs * d)
-       : FormInset( lv, d, _("Graphics"), new NoRepeatedApplyReadOnlyPolicy ),
+       : FormInset(lv, d, _("Graphics"), new NoRepeatedApplyReadOnlyPolicy),
          dialog_(0), inset_(0),
          // The buttons c-tor values are the number of buttons we use
          // This is only to reduce memory waste.
@@ -62,7 +55,7 @@ FormGraphics::~FormGraphics()
        displayButtons.reset();
        
        // Free the form.
-       delete dialog_;
+       // delete dialog_;
 }
 
 
@@ -142,12 +135,24 @@ void FormGraphics::build()
        displayButtons.registerRadioButton(dialog_->radio_no_display,
                                           InsetGraphicsParams::NONE);
 
-        // manage the ok, apply and cancel/close buttons
+        // Manage the ok, apply, restore and cancel/close buttons
        bc_.setOK(dialog_->button_ok);
        bc_.setApply(dialog_->button_apply);
        bc_.setCancel(dialog_->button_cancel);
-       bc_.setUndoAll(0);
+       bc_.setUndoAll(dialog_->button_restore);
        bc_.refresh();
+
+       bc_.addReadOnly(dialog_->input_filename);
+       bc_.addReadOnly(dialog_->button_browse);
+       bc_.addReadOnly(dialog_->input_width);
+       bc_.addReadOnly(dialog_->input_height);
+       bc_.addReadOnly(dialog_->radio_button_group_width);
+       bc_.addReadOnly(dialog_->radio_button_group_height);
+       bc_.addReadOnly(dialog_->radio_button_group_display);
+       bc_.addReadOnly(dialog_->input_rotate_angle);
+       bc_.addReadOnly(dialog_->check_inline);
+       bc_.addReadOnly(dialog_->input_subcaption);
+       bc_.addReadOnly(dialog_->check_subcaption);
 }
 
 
@@ -173,7 +178,7 @@ void FormGraphics::showDialog(InsetGraphics * inset)
 
        inset_ = inset;
 
-       ih_ = inset_->hide.connect(slot(this, &FormGraphics::hide));
+       ih_ = inset_->hideDialog.connect(slot(this, &FormGraphics::hide));
        show();
 }
 
@@ -260,6 +265,9 @@ void FormGraphics::update()
        fl_set_button(dialog_->check_inline,
                      igp.inlineFigure);
 
+       // update the dialog's read only / read-write status
+       bc_.readOnly(lv_->buffer()->isReadonly());
+
        // Now make sure that the buttons are set correctly.
        input(0, 0);
 }
@@ -342,68 +350,31 @@ bool FormGraphics::checkInput()
 // We need these in the file browser.
 extern string system_lyxdir;
 extern string user_lyxdir;
-//extern string system_tempdir;
-
-
-// Need to move this to the form_graphics
-string FormGraphics::browseFile(string const & filename)
-{
-       if (! filename.empty() )
-               last_image_path = OnlyPath(filename);
-
-       // Does user clipart directory exist?
-       string bufclip = AddName (user_lyxdir, "clipart");
-       FileInfo fileInfo(bufclip);
-       if (!(fileInfo.isOK() && fileInfo.isDir()))
-               // No - bail out to system clipart directory
-               bufclip = AddName (system_lyxdir, "clipart");
-
-       LyXFileDlg fileDlg;
-       fileDlg.SetButton(0, _("Clipart"), bufclip);
-
-       bool error = false;
-       string buf;
-       do {
-               string p = fileDlg.Select(_("Graphics"),
-                                         last_image_path,
-                                         "*(ps|png)", filename);
-
-               if (p.empty()) return p;
-
-               last_image_path = OnlyPath(p);
-
-               if (p.find_first_of("#~$% ") != string::npos) {
-                       WriteAlert(_("Filename can't contain any "
-                                    "of these characters:"),
-                                  // xgettext:no-c-format
-                                  _("space, '#', '~', '$' or '%'."));
-                       error = true;
-               } else {
-                       error = false;
-                       buf = p;
-               }
-       } while (error);
-
-       return buf;
-}
-
 
 void FormGraphics::browse()
 {
        // Get the filename from the dialog
        string const filename = fl_get_input(dialog_->input_filename);
 
+       string const title = N_("Graphics");
+       string const pattern = "*(ps|png)";
+
+       // Does user clipart directory exist?
+       string clipdir = AddName (user_lyxdir, "clipart");
+       FileInfo fileInfo(clipdir);
+       if (!(fileInfo.isOK() && fileInfo.isDir()))
+               // No - bail out to system clipart directory
+               clipdir = AddName (system_lyxdir, "clipart");
+       pair<string, string> dir1(N_("Clipart"), clipdir);
+       
        // Show the file browser dialog
-       string const new_filename = browseFile(filename);
+       string const new_filename =
+               browseFile(filename, title, pattern, dir1,
+                          make_pair(string(), string()));
 
        // Save the filename to the dialog
-       if (new_filename != filename && ! new_filename.empty()) {
-               fl_set_input(dialog_->input_filename,
-                            new_filename.c_str());
-               // The above set input doesn't cause an input event so we do
-               // it manually. Otherwise the user needs to cause an input event
-               // to get the ok/apply buttons to be activated.
+       if (new_filename != filename && !new_filename.empty()) {
+               fl_set_input(dialog_->input_filename, new_filename.c_str());
                input(0, 0);
        }
-
 }