* 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__
#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.
FormGraphics::~FormGraphics()
{
- free();
+ // Remove all associations for the radio buttons
+ widthButtons.reset();
+ heightButtons.reset();
+ displayButtons.reset();
+
+ // Free the form.
+ // delete dialog_;
}
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);
}
inset_ = inset;
- ih_ = inset_->hide.connect(slot(this, &FormGraphics::hide));
+ ih_ = inset_->hideDialog.connect(slot(this, &FormGraphics::hide));
show();
}
-void FormGraphics::free()
-{
- // Remove all associations for the radio buttons
- widthButtons.reset();
- heightButtons.reset();
- displayButtons.reset();
-
-
- // Free the form.
- delete dialog_;
- dialog_ = 0;
-}
-
-
void FormGraphics::apply()
{
Assert(inset_ != 0);
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);
}
// 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);
}
-
}