Commit b3eb5723 authored by Dominik Haumann's avatar Dominik Haumann
Browse files

Initial integration of variable editor

parent d6f6f6cf
......@@ -32,6 +32,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/vimode
${CMAKE_CURRENT_SOURCE_DIR}/view
${CMAKE_CURRENT_SOURCE_DIR}/swapfile
${CMAKE_CURRENT_SOURCE_DIR}/variableeditor
${KDE4_KIO_INCLUDES}
)
......@@ -94,6 +95,13 @@ mode/katemodeconfigpage.cpp
mode/katemodemenu.cpp
mode/katewildcardmatcher.cpp
# modeline variable editor
variableeditor/variablelineedit.cpp
variableeditor/variablelistview.cpp
variableeditor/variableeditor.cpp
variableeditor/variableitem.cpp
# rendering stuff (katerenderer and helpers)
render/katerenderer.cpp
render/katerenderrange.cpp
......
......@@ -111,7 +111,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="KLineEdit" name="edtVariables">
<widget class="VariableLineEdit" name="edtVariables" native="true">
<property name="whatsThis">
<string>&lt;p&gt;This string allows to configure Kate's settings for the files selected by this mimetype using Kate variables. Almost any configuration option can be set, such as highlight, indent-mode, encoding, etc.&lt;/p&gt;&lt;p&gt;For a full list of known variables, see the manual.&lt;/p&gt;</string>
</property>
......@@ -266,6 +266,11 @@
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>VariableLineEdit</class>
<extends></extends>
<header>variablelineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
......
......@@ -93,7 +93,7 @@ ModeConfigPage::ModeConfigPage( QWidget *parent )
connect( ui->edtName, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
connect( ui->edtSection, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
connect( ui->edtVariables, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
connect( ui->edtVariables, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotChanged() ) );
connect( ui->edtFileExtensions, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
connect( ui->edtMimeTypes, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
connect( ui->sbPriority, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
......
......@@ -18,9 +18,13 @@
Boston, MA 02110-1301, USA.
*/
#include "testwidget.h"
#include "variablelineedit.h"
#include "variableitem.h"
#include "variablelistview.h"
#include "kateautoindent.h"
#include "katesyntaxmanager.h"
#include "kateschema.h"
#include <QtCore/QDebug>
#include <QtGui/QPushButton>
......@@ -30,37 +34,22 @@
#include <QtGui/QHBoxLayout>
#include <QtGui/QLineEdit>
TestWidget::TestWidget(QWidget* parent)
VariableLineEdit::VariableLineEdit(QWidget* parent)
: QWidget(parent)
{
m_listview = 0;
QHBoxLayout* hl = new QHBoxLayout();
hl->setMargin(0);
hl->setSpacing(0);
QVBoxLayout* vl = new QVBoxLayout(this);
vl->setMargin(30);
vl->setSpacing(6);
setLayout(vl);
hl->setSpacing(10);
setLayout(hl);
m_lineedit = new QLineEdit(this);
m_button= new QPushButton("Edit...", this);
QComboBox* test = new QComboBox(this);
test->addItem("Eintrag 1");
test->addItem("Eintrag 2");
test->addItem("Eintrag 3");
test->addItem("Eintrag 4");
test->addItem("Eintrag 5");
m_button= new QPushButton("Edit", this);
hl->addWidget(m_lineedit);
hl->addWidget(m_button);
vl->addLayout(hl);
vl->addWidget(test);
vl->addStretch();
m_popup = new QFrame(0, Qt::Popup);
m_popup->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
QVBoxLayout* l = new QVBoxLayout(m_popup);
......@@ -68,26 +57,24 @@ TestWidget::TestWidget(QWidget* parent)
l->setMargin(0);
m_popup->setLayout(l);
// forward text changed signal
connect(m_lineedit, SIGNAL(textChanged(const QString&)), this, SIGNAL(textChanged(const QString&)));
// open popup on button click
connect(m_button, SIGNAL(clicked()), this, SLOT(editVariables()));
}
TestWidget::~TestWidget()
VariableLineEdit::~VariableLineEdit()
{
}
void TestWidget::editVariables()
void VariableLineEdit::editVariables()
{
static VariableListView* listview = 0;
if (listview != 0) {
m_popup->layout()->removeWidget(listview);
delete listview;
}
listview = new VariableListView(m_lineedit->text(), m_popup);
addKateItems(listview);
connect(listview, SIGNAL(editingDone(const QString&)), m_lineedit, SLOT(setText(const QString&)));
connect(listview, SIGNAL(changed()), this, SLOT(somethingChanged()));
m_popup->layout()->addWidget(listview);
m_listview = new VariableListView(m_lineedit->text(), m_popup);
addKateItems(m_listview);
connect(m_listview, SIGNAL(aboutToHide()), this, SLOT(updateVariableLine()));
m_popup->layout()->addWidget(m_listview);
QPoint topLeft = mapToGlobal(m_lineedit->geometry().bottomLeft());
const int w = m_button->geometry().right() - m_lineedit->geometry().left();
......@@ -96,7 +83,17 @@ void TestWidget::editVariables()
m_popup->show();
}
void TestWidget::addKateItems(VariableListView* listview)
void VariableLineEdit::updateVariableLine()
{
QString variables = m_listview->variableLine();
m_lineedit->setText(variables);
m_popup->layout()->removeWidget(m_listview);
m_listview->deleteLater();
m_listview = 0;
}
void VariableLineEdit::addKateItems(VariableListView* listview)
{
VariableItem* item = 0;
......@@ -162,7 +159,13 @@ void TestWidget::addKateItems(VariableListView* listview)
item->setHelpText("Set the font of the document.");
listview->addItem(item);
item = new VariableStringListItem("syntax TODO", QStringList() << "C++", "C++");
/* Prepare list of highlighting modes */
int count = KateHlManager::self()->highlights();
QStringList hl;
for (int z=0;z<count;z++)
hl<<KateHlManager::self()->hlNameTranslated (z);
item = new VariableStringListItem("syntax", hl, hl.at(0));
item->setHelpText("Set the syntax highlighting.");
listview->addItem(item);
......@@ -174,7 +177,7 @@ void TestWidget::addKateItems(VariableListView* listview)
item->setHelpText("Enable the icon border in the editor view.");
listview->addItem(item);
item = new VariableStringListItem("indent-mode TODO", QStringList() << "none" <<"normal" << "cstyle" << "lisp" << "python" <<"lilypond" <<"lua" <<"haskell" <<"ruby"<<"xml style", "none");
item = new VariableStringListItem("indent-mode", KateAutoIndent::listModes(),"none");
item->setHelpText("Set the auto indentation style.");
listview->addItem(item);
......@@ -215,7 +218,9 @@ void TestWidget::addKateItems(VariableListView* listview)
item->setHelpText("Remove trailing spaces when saving the document.");
listview->addItem(item);
item = new VariableBoolItem("scheme TODO", false);
KateSchemaManager *schemaManager = new KateSchemaManager();
QStringList schemas = schemaManager->list();
item = new VariableStringListItem("scheme", schemas, schemas.at(0));
item->setHelpText("Set the color scheme.");
listview->addItem(item);
......@@ -263,8 +268,19 @@ void TestWidget::addKateItems(VariableListView* listview)
listview->addItem(item);
}
void TestWidget::somethingChanged()
void VariableLineEdit::setText(const QString &text)
{
m_lineedit->setText(text);
}
void VariableLineEdit::clear()
{
qDebug() << "list view changed";
m_lineedit->clear();
}
QString VariableLineEdit::text()
{
return m_lineedit->text();
}
// kate: indent-width 2; replace-tabs on;
......@@ -18,8 +18,8 @@
Boston, MA 02110-1301, USA.
*/
#ifndef TEST_WIDGET_H
#define TEST_WIDGET_H
#ifndef VARIABLE_LINE_EDIT_H
#define VARIABLE_LINE_EDIT_H
#include <QWidget>
#include <QFrame>
......@@ -28,24 +28,31 @@ class QLineEdit;
class QPushButton;
class VariableListView;
class TestWidget : public QWidget
class VariableLineEdit : public QWidget
{
Q_OBJECT
public:
TestWidget(QWidget* parent = 0);
virtual ~TestWidget();
VariableLineEdit(QWidget* parent = 0);
virtual ~VariableLineEdit();
void addKateItems(VariableListView* listview);
QString text();
public Q_SLOTS:
void editVariables();
void somethingChanged();
void setText(const QString &text);
void clear();
void updateVariableLine();
Q_SIGNALS:
void textChanged(const QString&);
private:
QFrame* m_popup;
QLineEdit* m_lineedit;
QPushButton* m_button;
VariableListView* m_listview;
};
#endif
......
......@@ -107,7 +107,7 @@ void VariableListView::resizeEvent(QResizeEvent* event)
void VariableListView::hideEvent(QHideEvent* event)
{
if (!event->spontaneous()) {
emit editingDone(variableLine());
emit aboutToHide();
}
QScrollArea::hideEvent(event);
}
......@@ -133,7 +133,9 @@ QString VariableListView::variableLine()
line += it.key() + ' ' + it.value() + ';';
++it;
}
}
line.prepend("kate: ");
return line;
}
......
......@@ -41,8 +41,8 @@ public:
QString variableLine();
Q_SIGNALS:
void editingDone(const QString& variableLine);
void changed();
void aboutToHide();
void changed(); // unused right now
protected:
virtual void resizeEvent(QResizeEvent* event);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment