]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiTabularCreate.cpp
Initialize TabularCreate dialog enabled.
[lyx.git] / src / frontends / qt4 / GuiTabularCreate.cpp
index be59c0bec9b90e89a04ae1465bd313ab1ff47b27..1f5e36ec4d25779c8c98405cf8ef0a6305676f8b 100644 (file)
 #include "EmptyTable.h"
 #include "FuncRequest.h"
 
+#include "support/debug.h"
 #include "support/convert.h"
+#include "support/filetools.h"
+#include "support/gettext.h"
+#include "support/lstrings.h"
+#include "support/qstring_helpers.h"
+#include "support/Package.h"
 
-#include <QCloseEvent>
+#include <QDirIterator>
 #include <QSpinBox>
 #include <QPushButton>
 
-using std::string;
-
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 namespace frontend {
 
-GuiTabularCreate::GuiTabularCreate(LyXView & lv)
-       : GuiDialog(lv, "tabularcreate"), Controller(this)
+void GuiTabularCreate::getFiles()
+{
+       // We look for lyx files in the subdirectory dir of
+       //   1) user_lyxdir
+       //   2) build_lyxdir (if not empty)
+       //   3) system_lyxdir
+       // in this order. Files with a given sub-hierarchy will
+       // only be listed once.
+       // We also consider i18n subdirectories and store them separately.
+       QStringList dirs;
+
+       // The three locations to look at.
+       string const user = addPath(package().user_support().absFileName(), "tabletemplates");
+       string const build = addPath(package().build_support().absFileName(), "tabletemplates");
+       string const system = addPath(package().system_support().absFileName(), "tabletemplates");
+
+       dirs << toqstr(user)
+            << toqstr(build)
+            << toqstr(system);
+
+       for (int i = 0; i < dirs.size(); ++i) {
+               QString const dir = dirs.at(i);
+               QDirIterator it(dir, QDir::Files, QDirIterator::Subdirectories);
+               while (it.hasNext()) {
+                       QString fn = QFileInfo(it.next()).fileName();
+                       if (!fn.endsWith(".lyx") || fn.contains("_1x"))
+                               continue;
+                       QString data = fn.left(fn.lastIndexOf(".lyx"));
+                       QString guiname = data;
+                       guiname = toqstr(translateIfPossible(qstring_to_ucs4(guiname.replace('_', ' '))));
+                       QString relpath = toqstr(makeRelPath(qstring_to_ucs4(fn),
+                                                            qstring_to_ucs4(dir)));
+                       if (styleCO->findData(data) == -1)
+                               styleCO->addItem(guiname, data);
+               }
+       }
+}
+
+GuiTabularCreate::GuiTabularCreate(GuiView & lv)
+       : GuiDialog(lv, "tabularcreate", qt_("Insert Table"))
 {
        setupUi(this);
-       setViewTitle(_("Insert Table"));
-       setController(this, false);
 
        rowsSB->setValue(5);
        columnsSB->setValue(5);
+       table->setMinimumSize(100, 100);
 
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
+       connect(table, SIGNAL(rowsChanged(int)),
+               rowsSB, SLOT(setValue(int)));
+       connect(table, SIGNAL(colsChanged(int)),
+               columnsSB, SLOT(setValue(int)));
+       connect(rowsSB, SIGNAL(valueChanged(int)),
+               table, SLOT(setNumberRows(int)));
+       connect(columnsSB, SIGNAL(valueChanged(int)),
+               table, SLOT(setNumberColumns(int)));
+
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
 
        connect(rowsSB, SIGNAL(valueChanged(int)),
                this, SLOT(rowsChanged(int)));
        connect(columnsSB, SIGNAL(valueChanged(int)),
                this, SLOT(columnsChanged(int)));
 
-       bc().setPolicy(ButtonPolicy::IgnorantPolicy);
-       bc().setOK(okPB);
-       bc().setCancel(closePB);
+       bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
+       bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
+       bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
+       bc().setValid(isValid());
+
+       // Fill styles combo
+       styleCO->addItem(qt_("Default"), toqstr("default"));
+       getFiles();
+}
+
+
+void GuiTabularCreate::on_styleCO_activated(int i)
+{
+       style_ = styleCO->itemData(i).toString();
+       changed();
 }
 
 
@@ -65,8 +130,8 @@ void GuiTabularCreate::rowsChanged(int)
 
 void GuiTabularCreate::applyView()
 {
-       params_.first = rowsSB->value();
-       params_.second = columnsSB->value();
+       params_.first = ulong(rowsSB->value());
+       params_.second = ulong(columnsSB->value());
 }
 
 
@@ -74,6 +139,8 @@ bool GuiTabularCreate::initialiseParams(string const &)
 {
        params_.first  = 5;
        params_.second = 5;
+       style_ = styleCO->itemData(styleCO->currentIndex()).toString();
+       changed();
        return true;
 }
 
@@ -87,12 +154,24 @@ void GuiTabularCreate::clearParams()
 
 void GuiTabularCreate::dispatchParams()
 {
-       string const data = convert<string>(params().first) + ' ' + convert<string>(params().second);
-       dispatch(FuncRequest(getLfun(), data));
+       string sdata;
+       if (style_ != "default")
+               sdata = fromqstr(style_) + ' ';
+       sdata += convert<string>(params().first) + ' ' + convert<string>(params().second);
+       dispatch(FuncRequest(getLfun(), sdata));
+}
+
+
+FuncCode GuiTabularCreate::getLfun() const
+{
+       if (style_.isEmpty() || style_ == "default")
+               return  LFUN_TABULAR_INSERT;
+       
+       return LFUN_TABULAR_STYLE_INSERT;
 }
 
 
-Dialog * createGuiTabularCreate(LyXView & lv)
+Dialog * createGuiTabularCreate(GuiView & lv)
 {
        return new GuiTabularCreate(lv);
 }
@@ -101,4 +180,4 @@ Dialog * createGuiTabularCreate(LyXView & lv)
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiTabularCreate_moc.cpp"
+#include "moc_GuiTabularCreate.cpp"