extern FD_form_table * fd_form_table;
extern FD_form_figure * fd_form_figure;
extern FD_form_screen * fd_form_screen;
-extern FD_form_toc * fd_form_toc;
extern FD_form_ref * fd_form_ref;
extern FD_form_bullet * fd_form_bullet;
int RunLinuxDoc(BufferView *, int, string const &);
int RunDocBook(int, string const &);
void MenuWrite(Buffer * buf);
-void MenuWriteAs(Buffer * buffer);
+bool MenuWriteAs(Buffer * buffer);
void MenuReload(Buffer * buf);
void MenuLayoutSave();
// should be moved to BufferView.C
// Half of this func should be in LyXView, the rest in BufferView.
-void MenuWriteAs(Buffer * buffer)
+bool MenuWriteAs(Buffer * buffer)
{
// Why do we require BufferView::text to be able to write a
// document? I see no point in that. (Lgb)
if (!IsLyXFilename(fname))
fname += ".lyx";
- fname = fileDlg.Select(_("Enter Filename to Save Document as"),
- OnlyPath(fname),
- "*.lyx",
- OnlyFilename(fname));
+ if (buffer->isUnnamed()) {
+ fname = fileDlg.Select(_("Enter Filename to Save Document as"),
+ "",
+ "*.lyx",
+ "");
+ } else {
+ fname = fileDlg.Select(_("Enter Filename to Save Document as"),
+ OnlyPath(fname),
+ "*.lyx",
+ OnlyFilename(fname));
+ }
AllowInput(current_view);
if (fname.empty()) {
- return;
+ return false;
}
// Make sure the absolute filename ends with appropriate suffix
string s = MakeAbsPath(fname);
if (!AskQuestion(_("Same name as document already has:"),
MakeDisplayPath(s, 50),
_("Save anyway?")))
- return;
+ return false;
// Falls through to name change and save
}
// No, but do we have another file with this name open?
ShowMessage(buffer, _("Document renamed to '"),
MakeDisplayPath(s), _("', but not saved..."));
}
- return;
+ return false;
} // Check whether the file exists
else {
FileInfo myfile(s);
if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
MakeDisplayPath(s, 50),
_("Replace file?")))
- return;
+ return false;
}
// Ok, change the name of the buffer
buffer->fileName(s);
buffer->markDirty();
+ buffer->setUnnamed(false);
// And save
// Small bug: If the save fails, we have irreversible changed the name
// of the document.
MenuWrite(buffer);
+ return true;
}
}
// HTML
else if (extyp == "html") {
- MenuMakeHTML(buffer);
- }
- // HTML from linuxdoc
- else if (extyp == "html-linuxdoc") {
- MenuMakeHTML_LinuxDoc(buffer);
- }
- // HTML from docbook
- else if (extyp == "html-docbook") {
- MenuMakeHTML_DocBook(buffer);
+ if (buffer->isLinuxDoc())
+ MenuMakeHTML_LinuxDoc(buffer);
+ else if (buffer->isDocBook())
+ MenuMakeHTML_DocBook(buffer);
+ else
+ MenuMakeHTML(buffer);
}
else {
ShowMessage(buffer, _("Unknown export type: ") + extyp);
if (!bv->available())
return;
- if (bv->buffer()->isBakClean()
- || bv->buffer()->isReadonly()) {
+ if (bv->buffer()->isBakClean() ||
+ bv->buffer()->isReadonly() || bv->buffer()->isUnnamed()) {
// We don't save now, but we'll try again later
bv->owner()->resetAutosaveTimer();
return;
ifs.unsetf(ios::skipws);
istream_iterator<char> ii(ifs);
istream_iterator<char> end;
+#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
+ // We use this until the compilers get better...
+ vector<char> tmp;
+ copy(ii, end, back_inserter(tmp));
+ string tmpstr(tmp.begin(), tmp.end());
+#else
+ // This is what we want to use and what we will use once the
+ // compilers get good enough.
//string tmpstr(ii, end); // yet a reason for using std::string
// alternate approach to get the file into a string:
string tmpstr;
copy(ii, end, back_inserter(tmpstr));
+#endif
// insert the string
current_view->hideCursor();
}
-void MenuShowTableOfContents()
-{
- static int ow = -1, oh;
-
- TocUpdateCB(0, 0);
- if (fd_form_toc->form_toc->visible) {
- fl_raise_form(fd_form_toc->form_toc);
- } else {
- fl_show_form(fd_form_toc->form_toc,
- FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
- _("Table Of Contents"));
- if (ow < 0) {
- ow = fd_form_toc->form_toc->w;
- oh = fd_form_toc->form_toc->h;
- }
- fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
- }
-}
-
-
void MenuInsertLabel(char const * arg)
{
string label = arg;
}
}
if (!label.empty()) {
- InsetLabel * new_inset = new InsetLabel;
- new_inset->setContents(label);
- current_view->insertInset(new_inset);
+ InsetCommandParams p( "label", label );
+ InsetLabel * inset = new InsetLabel( p );
+ current_view->insertInset( inset );
}
AllowInput(current_view);
}
}
-//
-// Table of Contents
-//
-
-static vector<Buffer::TocItem> toclist;
-
-
-extern "C" void TocSelectCB(FL_OBJECT * ob, long)
-{
- if (!current_view->available())
- return;
-
- TocUpdateCB(0, 0);
- unsigned int choice = fl_get_browser(ob);
- if (0 < choice && choice - 1 < toclist.size()) {
- current_view->beforeChange();
- current_view->text->SetCursor(current_view, toclist[choice-1].par, 0);
- current_view->text->sel_cursor =
- current_view->text->cursor;
- current_view->update(BufferView::SELECT|BufferView::FITCUR);
- } else {
- WriteAlert(_("Error"),
- _("Couldn't find this label"),
- _("in current document."));
- }
-}
-
-
-extern "C" void TocCancelCB(FL_OBJECT *, long)
-{
- fl_hide_form(fd_form_toc->form_toc);
-}
-
-
-extern "C"
-void TocUpdateCB(FL_OBJECT *, long)
-{
- if (!current_view->available()) {
- toclist.clear();
- fl_clear_browser(fd_form_toc->browser_toc);
- fl_add_browser_line(fd_form_toc->browser_toc,
- _("*** No Document ***"));
- return;
- }
-
- vector<vector<Buffer::TocItem> > tmp =
- current_view->buffer()->getTocList();
- int type = fl_get_choice(fd_form_toc->toctype)-1;
- //if (toclist == tmp[type])
- // return;
- if (toclist.size() == tmp[type].size()) {
- // Check if all elements are the same.
- unsigned int i = 0;
- for (; i < toclist.size(); ++i) {
- if (toclist[i] != tmp[type][i])
- break;
- }
- if (i >= toclist.size()) return;
- }
-
- toclist = tmp[type];
-
- static Buffer * buffer = 0;
- int topline = 0;
- int line = 0;
- if (buffer == current_view->buffer()) {
- topline = fl_get_browser_topline(fd_form_toc->browser_toc);
- line = fl_get_browser(fd_form_toc->browser_toc);
- } else
- buffer = current_view->buffer();
-
- fl_clear_browser(fd_form_toc->browser_toc);
- fl_hide_object(fd_form_toc->browser_toc);
-
- for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
- it != toclist.end(); ++it)
- fl_add_browser_line(fd_form_toc->browser_toc,
- (string(4*(*it).depth,' ')+
- (*it).str).c_str());
-
- fl_set_browser_topline(fd_form_toc->browser_toc, topline);
- fl_select_browser_line(fd_form_toc->browser_toc, line);
- fl_show_object(fd_form_toc->browser_toc);
-}
-
-
/* callbacks for form form_ref */
extern "C" void RefSelectCB(FL_OBJECT *, long data)
{
return;
}
- static string const commands[5]
- = { "\\ref", "\\pageref", "\\vref", "\\vpageref",
- "\\prettyref"};
- string t = commands[data];
-
+ static string const cmdname[5]
+ = { "ref", "pageref", "vref", "vpageref", "prettyref"};
+ InsetCommandParams p( cmdname[data] );
+ p.setContents( s );
+
if (current_view->buffer()->isSGML())
- t += "[" + u + "]" + "{" + s + "}";
- else
- t += "{" + s + "}";
+ p.setOptions( u );
- Inset * new_inset =
- new InsetRef(t, current_view->buffer());
- current_view->insertInset(new_inset);
+ Inset * inset = new InsetRef( p, current_view->buffer() );
+ current_view->insertInset( inset );
}