mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Fixed Inset->File as inside insets (InsetTabular/InsetText) (fix #257).
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3658 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
94d9db8ba7
commit
1ec8e312f4
@ -1,5 +1,7 @@
|
||||
2002-03-04 Juergen Vigna <jug@sad.it>
|
||||
|
||||
* lyx_cb.C (getContentsOfAsciiFile): new helper function.
|
||||
|
||||
* tabular.C (calculate_width_of_column_NMC): fixed to use also the
|
||||
last column of multicolumn cells.
|
||||
(SetWidthOfMulticolCell): recalculate NMC and real columns.
|
||||
|
@ -1,3 +1,9 @@
|
||||
2002-03-04 Juergen Vigna <jug@sad.it>
|
||||
|
||||
* insettabular.C (localDispatch): inserted handling of
|
||||
LFUN_FILE_INSERT_ASCII_PARA and LFUN_FILE_INSERT_ASCII.
|
||||
(insertAsciiString): new helper function.
|
||||
|
||||
2002-03-04 Jose Abilio Oliveira Matos <jamatos@novalis.fc.up.pt>
|
||||
|
||||
* insetinclude.C (linuxdoc, docbook): deal correctly with the niceFile
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "insettabular.h"
|
||||
|
||||
#include "lyx_cb.h"
|
||||
#include "buffer.h"
|
||||
#include "commandtags.h"
|
||||
#include "lyxfunc.h"
|
||||
@ -1104,6 +1105,20 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
|
||||
if (!tabularFeatures(bv, arg))
|
||||
result = UNDISPATCHED;
|
||||
break;
|
||||
// insert file functions
|
||||
case LFUN_FILE_INSERT_ASCII_PARA:
|
||||
case LFUN_FILE_INSERT_ASCII:
|
||||
{
|
||||
string tmpstr = getContentsOfAsciiFile(bv, arg, false);
|
||||
if (tmpstr.empty())
|
||||
break;
|
||||
if (insertAsciiString(bv, tmpstr, false))
|
||||
updateLocal(bv, INIT, true);
|
||||
else
|
||||
result = UNDISPATCHED;
|
||||
break;
|
||||
}
|
||||
// cut and paste functions
|
||||
case LFUN_CUT:
|
||||
if (!copySelection(bv))
|
||||
break;
|
||||
@ -1122,9 +1137,9 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
|
||||
case LFUN_PASTESELECTION:
|
||||
{
|
||||
string const clip(bv->getClipboard());
|
||||
|
||||
if (clip.empty())
|
||||
if (clip.empty())
|
||||
break;
|
||||
#if 0
|
||||
if (clip.find('\t') != string::npos) {
|
||||
int cols = 1;
|
||||
int rows = 1;
|
||||
@ -1178,7 +1193,11 @@ InsetTabular::localDispatch(BufferView * bv, kb_action action,
|
||||
// check for the last cell if there is no trailing '\n'
|
||||
if ((cell < cells) && (op < len))
|
||||
paste_tabular->GetCellInset(cell)->setText(clip.substr(op, len-op));
|
||||
} else {
|
||||
} else
|
||||
#else
|
||||
if (!insertAsciiString(bv, clip, true))
|
||||
#endif
|
||||
{
|
||||
// so that the clipboard is used and it goes on
|
||||
// to default
|
||||
// and executes LFUN_PASTESELECTION in insettext!
|
||||
@ -2768,3 +2787,88 @@ bool InsetTabular::forceDefaultParagraphs(Inset const * in) const
|
||||
// if we're here there is really something strange going on!!!
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
|
||||
bool usePaste)
|
||||
{
|
||||
if (buf.find('\t') == string::npos)
|
||||
return false;
|
||||
|
||||
int cols = 1;
|
||||
int rows = 1;
|
||||
int maxCols = 1;
|
||||
string::size_type len = buf.length();
|
||||
string::size_type p = 0;
|
||||
|
||||
while (p < len &&
|
||||
((p = buf.find_first_of("\t\n", p)) != string::npos))
|
||||
{
|
||||
switch (buf[p]) {
|
||||
case '\t':
|
||||
++cols;
|
||||
break;
|
||||
case '\n':
|
||||
if ((p+1) < len)
|
||||
++rows;
|
||||
maxCols = max(cols, maxCols);
|
||||
cols = 1;
|
||||
break;
|
||||
}
|
||||
++p;
|
||||
}
|
||||
maxCols = max(cols, maxCols);
|
||||
LyXTabular * loctab;
|
||||
int cell = 0;
|
||||
int ocol = 0;
|
||||
int row = 0;
|
||||
if (usePaste) {
|
||||
delete paste_tabular;
|
||||
paste_tabular = new LyXTabular(bv->buffer()->params,
|
||||
this, rows, maxCols);
|
||||
loctab = paste_tabular;
|
||||
cols = 0;
|
||||
} else {
|
||||
loctab = tabular.get();
|
||||
cell = actcell;
|
||||
ocol = actcol;
|
||||
row = actrow;
|
||||
}
|
||||
string::size_type op = 0;
|
||||
int cells = loctab->GetNumberOfCells();
|
||||
p = 0;
|
||||
cols = ocol;
|
||||
rows = loctab->rows();
|
||||
int const columns = loctab->columns();
|
||||
while ((cell < cells) && (p < len) && (row < rows) &&
|
||||
(p = buf.find_first_of("\t\n", p)) != string::npos)
|
||||
{
|
||||
if (p >= len)
|
||||
break;
|
||||
switch (buf[p]) {
|
||||
case '\t':
|
||||
// we can only set this if we are not too far right
|
||||
if (cols < columns) {
|
||||
loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
|
||||
++cols;
|
||||
++cell;
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
// we can only set this if we are not too far right
|
||||
if (cols < columns)
|
||||
loctab->GetCellInset(cell)->setText(buf.substr(op, p-op));
|
||||
cols = ocol;
|
||||
++row;
|
||||
if (row < rows)
|
||||
cell = loctab->GetCellNumber(row, cols);
|
||||
break;
|
||||
}
|
||||
++p;
|
||||
op = p;
|
||||
}
|
||||
// check for the last cell if there is no trailing '\n'
|
||||
if ((cell < cells) && (op < len))
|
||||
loctab->GetCellInset(cell)->setText(buf.substr(op, len-op));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -311,7 +311,9 @@ private:
|
||||
int & srow, int & erow) const;
|
||||
///
|
||||
string selectNextWordInt(BufferView *, float & value) const;
|
||||
|
||||
///
|
||||
bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
|
||||
|
||||
//
|
||||
// Private structures and variables
|
||||
///
|
||||
|
48
src/lyx_cb.C
48
src/lyx_cb.C
@ -351,11 +351,35 @@ Buffer * NewLyxFile(string const & filename)
|
||||
// Insert ascii file (if filename is empty, prompt for one)
|
||||
void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
|
||||
{
|
||||
string fname = f;
|
||||
|
||||
if (!bv->available())
|
||||
return;
|
||||
|
||||
|
||||
string const tmpstr = getContentsOfAsciiFile(bv, f, asParagraph);
|
||||
if (tmpstr.empty())
|
||||
return;
|
||||
|
||||
// insert the string
|
||||
bv->hideCursor();
|
||||
|
||||
// clear the selection
|
||||
bool flag = (bv->text == bv->getLyXText());
|
||||
if (flag)
|
||||
bv->beforeChange(bv->text);
|
||||
if (!asParagraph)
|
||||
bv->getLyXText()->insertStringAsLines(bv, tmpstr);
|
||||
else
|
||||
bv->getLyXText()->insertStringAsParagraphs(bv, tmpstr);
|
||||
if (flag)
|
||||
bv->update(bv->text,
|
||||
BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
||||
}
|
||||
|
||||
|
||||
// Insert ascii file (if filename is empty, prompt for one)
|
||||
string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagraph)
|
||||
{
|
||||
string fname = f;
|
||||
|
||||
if (fname.empty()) {
|
||||
FileDialog fileDlg(bv->owner(), _("Select file to insert"),
|
||||
(asParagraph) ? LFUN_FILE_INSERT_ASCII_PARA : LFUN_FILE_INSERT_ASCII);
|
||||
@ -363,12 +387,12 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
|
||||
FileDialog::Result result = fileDlg.Select(bv->owner()->buffer()->filePath());
|
||||
|
||||
if (result.first == FileDialog::Later)
|
||||
return;
|
||||
return string();
|
||||
|
||||
fname = result.second;
|
||||
|
||||
if (fname.empty())
|
||||
return;
|
||||
return string();
|
||||
}
|
||||
|
||||
FileInfo fi(fname);
|
||||
@ -376,14 +400,14 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
|
||||
if (!fi.readable()) {
|
||||
Alert::err_alert(_("Error! Specified file is unreadable: "),
|
||||
MakeDisplayPath(fname, 50));
|
||||
return;
|
||||
return string();
|
||||
}
|
||||
|
||||
ifstream ifs(fname.c_str());
|
||||
if (!ifs) {
|
||||
Alert::err_alert(_("Error! Cannot open specified file: "),
|
||||
MakeDisplayPath(fname, 50));
|
||||
return;
|
||||
return string();
|
||||
}
|
||||
|
||||
ifs.unsetf(ios::skipws);
|
||||
@ -402,16 +426,8 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
|
||||
string tmpstr;
|
||||
copy(ii, end, back_inserter(tmpstr));
|
||||
#endif
|
||||
// insert the string
|
||||
bv->hideCursor();
|
||||
|
||||
// clear the selection
|
||||
bv->beforeChange(bv->text);
|
||||
if (!asParagraph)
|
||||
bv->text->insertStringAsLines(bv, tmpstr);
|
||||
else
|
||||
bv->text->insertStringAsParagraphs(bv, tmpstr);
|
||||
bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,6 +31,8 @@ Buffer * NewLyxFile(string const & filename);
|
||||
///
|
||||
void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph);
|
||||
///
|
||||
string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagraph);
|
||||
///
|
||||
void MenuInsertLabel(BufferView * bv, string const & arg);
|
||||
///
|
||||
void Reconfigure(BufferView * bv);
|
||||
|
Loading…
Reference in New Issue
Block a user