Commit 544a0811 authored by Robert Knight's avatar Robert Knight
Browse files

Start of dialog to edit key bindings.

svn path=/branches/work/konsole-split-view/; revision=660913
parent 2c6b36ac
......@@ -132,9 +132,11 @@ Application::~Application()
{
delete SessionManager::instance();
delete ColorSchemeManager::instance();
delete KeyboardTranslatorManager::instance();
SessionManager::setInstance(0);
ColorSchemeManager::setInstance(0);
KeyboardTranslatorManager::setInstance(0);
}
void Application::detachView(Session* session)
......
......@@ -64,6 +64,7 @@ set(konsole_KDEINIT_SRCS
HistorySizeDialog.cpp
IncrementalSearchBar.cpp
KeyboardTranslator.cpp
KeyBindingEditor.cpp
KeyTrans.cpp
Application.cpp
BookmarkHandler.cpp
......@@ -100,6 +101,7 @@ kde4_add_ui_files(konsole_KDEINIT_SRCS
ColorSchemeEditor.ui
EditProfileDialog.ui
EditTabTitleFormatDialog.ui
KeyBindingEditor.ui
ManageProfilesDialog.ui
RemoteConnectionDialog.ui
)
......@@ -138,7 +140,8 @@ set(konsolepart_PART_SRCS
Filter.cpp
History.cpp
HistorySizeDialog.cpp
IncrementalSearchBar.cpp
IncrementalSearchBar.cpp
KeyBindingEditor.cpp
KeyTrans.cpp
MainWindow.cpp
Part.cpp
......
......@@ -37,6 +37,8 @@
#include "ui_EditProfileDialog.h"
#include "EditProfileDialog.h"
#include "EditTabTitleFormatDialog.h"
#include "KeyBindingEditor.h"
#include "KeyboardTranslator.h"
#include "SessionManager.h"
#include "ShellCommand.h"
......@@ -372,9 +374,6 @@ void EditProfileDialog::showColorSchemeEditor(bool newScheme)
dialog->setMainWidget(editor);
editor->setup(colors);
if ( newScheme )
editor->setDescription(i18n("New Color Scheme"));
if ( dialog->exec() == QDialog::Accepted )
{
ColorScheme* newScheme = new ColorScheme(*editor->colorScheme());
......@@ -413,17 +412,141 @@ void EditProfileDialog::colorSchemeSelected()
_tempProfile->setProperty(Profile::ColorScheme,colors->name());
changeCheckedItem(model,selected.first());
}
}
void EditProfileDialog::setupKeyboardPage(const Profile* info)
{
// setup translator list
const QString& name = SessionManager::instance()->profile(_profileKey)->property(Profile::KeyBindings)
.value<QString>();
const KeyboardTranslator* currentTranslator = KeyboardTranslatorManager::instance()->findTranslator(name);
qDebug() << "Current translator = " << currentTranslator << ", name: " << name;
QStandardItemModel* model = new QStandardItemModel(this);
QList<QString> translatorNames = KeyboardTranslatorManager::instance()->allTranslators();
QListIterator<QString> iter(translatorNames);
while (iter.hasNext())
{
const QString& name = iter.next();
const KeyboardTranslator* translator = KeyboardTranslatorManager::instance()->findTranslator(name);
qDebug() << "Translator:" << translator << ", name = " << translator->name();
// TODO Use translator->description() here
QStandardItem* item = new QStandardItem(translator->name());
item->setData(QVariant::fromValue(translator),Qt::UserRole+1);
item->setFlags( item->flags() | Qt::ItemIsUserCheckable );
if ( translator == currentTranslator )
item->setCheckState( Qt::Checked );
else
item->setCheckState( Qt::Unchecked );
model->appendRow(item);
}
connect( _ui->keyBindingList , SIGNAL(doubleClicked(const QModelIndex&)) , this ,
SLOT(keyBindingSelected()) );
connect( _ui->selectKeyBindingsButton , SIGNAL(clicked()) , this ,
SLOT(keyBindingSelected()) );
connect( _ui->newKeyBindingsButton , SIGNAL(clicked()) , this ,
SLOT(newKeyBinding()) );
connect( _ui->editKeyBindingsButton , SIGNAL(clicked()) , this ,
SLOT(editKeyBinding()) );
connect( _ui->removeKeyBindingsButton , SIGNAL(clicked()) , this ,
SLOT(removeKeyBinding()) );
_ui->keyBindingList->setModel(model);
}
void EditProfileDialog::keyBindingSelected()
{
QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
if ( !selected.isEmpty() )
{
QAbstractItemModel* model = _ui->keyBindingList->model();
const KeyboardTranslator* translator = model->data(selected.first(),Qt::UserRole+1)
.value<const KeyboardTranslator*>();
_tempProfile->setProperty(Profile::KeyBindings,translator->name());
changeCheckedItem(model,selected.first());
}
}
void EditProfileDialog::changeCheckedItem( QAbstractItemModel* model , const QModelIndex& to )
{
// uncheck current active item
QModelIndexList list = model->match( model->index(0,0) , Qt::CheckStateRole , Qt::Checked );
Q_ASSERT( list.count() == 1 );
model->setData( list.first() , Qt::Unchecked , Qt::CheckStateRole );
// check new active item
model->setData( selected.first() , Qt::Checked , Qt::CheckStateRole );
model->setData( to , Qt::Checked , Qt::CheckStateRole );
}
void EditProfileDialog::removeKeyBinding()
{
QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
if ( !selected.isEmpty() )
{
const QString& name = selected.first().data(Qt::UserRole+1).value<const KeyboardTranslator*>()->name();
KeyboardTranslatorManager::instance()->deleteTranslator(name);
_ui->keyBindingList->model()->removeRow(selected.first().row());
}
}
void EditProfileDialog::showKeyBindingEditor(bool newTranslator)
{
QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
if ( !selected.isEmpty() )
{
QAbstractItemModel* model = _ui->keyBindingList->model();
QModelIndex index = selected.first();
const KeyboardTranslator* translator = model->data(index,
Qt::UserRole+1).value<const KeyboardTranslator*>();
KDialog* dialog = new KDialog(this);
if ( newTranslator )
dialog->setCaption(i18n("New Key Binding List"));
else
dialog->setCaption(i18n("Edit Key Binding List"));
KeyBindingEditor* editor = new KeyBindingEditor;
dialog->setMainWidget(editor);
editor->setup(translator);
if ( dialog->exec() == QDialog::Accepted )
{
KeyboardTranslator* newTranslator = new KeyboardTranslator(*editor->translator());
KeyboardTranslatorManager::instance()->addTranslator( newTranslator );
model->setData(index,QVariant::fromValue((const KeyboardTranslator*)newTranslator)
, Qt::UserRole+1);
model->setData(index,newTranslator->description(),Qt::DisplayRole);
const QString& currentTranslator = SessionManager::instance()->profile(_profileKey)
->property(Profile::KeyBindings).value<QString>();
if ( newTranslator->name() == currentTranslator )
{
_tempProfile->setProperty(Profile::KeyBindings,newTranslator->name());
}
}
}
}
void EditProfileDialog::setupKeyboardPage(const Profile* )
void EditProfileDialog::newKeyBinding()
{
showKeyBindingEditor(true);
}
void EditProfileDialog::editKeyBinding()
{
showKeyBindingEditor(false);
}
void EditProfileDialog::setupCombo( ComboOption* options , const Profile* profile )
{
......
......@@ -117,6 +117,12 @@ private slots:
void showScrollBarLeft();
void showScrollBarRight();
// keyboard page
void editKeyBinding();
void newKeyBinding();
void keyBindingSelected();
void removeKeyBinding();
// advanced page
void toggleBlinkingText(bool);
void toggleFlowControl(bool);
......@@ -138,6 +144,9 @@ private:
void setupAdvancedPage(const Profile* info);
void showColorSchemeEditor(bool newScheme);
void showKeyBindingEditor(bool newTranslator);
void changeCheckedItem( QAbstractItemModel* mode, const QModelIndex& to );
void preview(int property , QVariant value);
void unpreview(int property);
......
/*
Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
// Qt
#include <QHeaderView>
// Konsole
#include "KeyBindingEditor.h"
#include "ui_KeyBindingEditor.h"
#include "KeyboardTranslator.h"
using namespace Konsole;
KeyBindingEditor::KeyBindingEditor(QWidget* parent)
: QWidget(parent)
, _translator(0)
{
_ui = new Ui::KeyBindingEditor();
_ui->setupUi(this);
// key bindings table
_ui->keyBindingTable->setColumnCount(2);
QStringList labels;
labels << i18n("Key Combination") << i18n("Binding");
_ui->keyBindingTable->setHorizontalHeaderLabels(labels);
_ui->keyBindingTable->horizontalHeader()->setStretchLastSection(true);
_ui->keyBindingTable->verticalHeader()->hide();
}
KeyBindingEditor::~KeyBindingEditor()
{
delete _ui;
}
void KeyBindingEditor::setup(const KeyboardTranslator* translator)
{
if ( _translator )
delete _translator;
_translator = new KeyboardTranslator(*translator);
// setup description edit
_ui->descriptionEdit->setText(translator->description());
// setup key binding table
setupKeyBindingTable(translator);
}
KeyboardTranslator* KeyBindingEditor::translator() const
{
return _translator;
}
void KeyBindingEditor::setupKeyBindingTable(const KeyboardTranslator* translator)
{
QList<const KeyboardTranslator::Entry*> entries = translator->entries();
for ( int row = 0 ; row < entries.count() ; row++ )
{
const KeyboardTranslator::Entry* entry = entries.at(row);
QTableWidgetItem* keyItem = new QTableWidgetItem(QString::number(entry->keyCode()));
QTableWidgetItem* textItem = new QTableWidgetItem(entry->text());
_ui->keyBindingTable->setItem(row,0,keyItem);
_ui->keyBindingTable->setItem(row,1,textItem);
}
}
#include "KeyBindingEditor.moc"
/*
Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
#ifndef KEYBINDINGEDITOR_H
#define KEYBINDINGEDITOR_H
// Qt
#include <QWidget>
namespace Ui
{
class KeyBindingEditor;
};
namespace Konsole
{
class KeyboardTranslator;
class KeyBindingEditor : public QWidget
{
Q_OBJECT
public:
KeyBindingEditor(QWidget* parent = 0);
virtual ~KeyBindingEditor();
void setup(const KeyboardTranslator* translator);
KeyboardTranslator* translator() const;
private:
void setupKeyBindingTable(const KeyboardTranslator* translator);
Ui::KeyBindingEditor* _ui;
KeyboardTranslator* _translator;
};
};
#endif //KEYBINDINGEDITOR_H
<ui version="4.0" >
<class>KeyBindingEditor</class>
<widget class="QWidget" name="KeyBindingEditor" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QVBoxLayout" >
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="descriptionLabel" >
<property name="text" >
<string>Description:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="descriptionEdit" />
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="keyBindingTable" />
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -39,13 +39,16 @@ using namespace Konsole;
KeyboardTranslatorManager* KeyboardTranslatorManager::_instance = 0;
KeyboardTranslatorManager::KeyboardTranslatorManager()
: _haveLoadedAll(false)
{
}
QString KeyboardTranslatorManager::findTranslatorPath(const QString& name)
{
return KGlobal::dirs()->findResource("data","konsole/"+name+".keytab");
}
void KeyboardTranslatorManager::findTranslators()
{
Q_ASSERT( _translators.count() == 0 );
QStringList list = KGlobal::dirs()->findAllResources("data","konsole/*.keytab");
qDebug() << __FUNCTION__ << ": found " << list.count() << " keyboard translators.";
......@@ -59,46 +62,32 @@ void KeyboardTranslatorManager::findTranslators()
QString translatorPath = listIter.next();
QString name = QFileInfo(translatorPath).baseName();
_paths.insert(name,translatorPath);
_translators.insert(name,0);
if ( !_translators.contains(name) )
_translators.insert(name,0);
}
_haveLoadedAll = true;
}
const KeyboardTranslator* KeyboardTranslatorManager::findTranslator(const QString& name)
{
if ( _translators.contains(name) )
{
KeyboardTranslator* translator = _translators[name];
if ( _translators.contains(name) && _translators[name] != 0 )
return _translators[name];
// if the translator with this name has not yet been loaded, then load
// it first.
if ( translator == 0 )
{
translator = loadTranslator(name);
if ( translator )
_translators[name] = translator;
else
return 0; // an error occurred whilst loading the translator
}
KeyboardTranslator* translator = loadTranslator(name);
_translators[name] = translator;
return translator;
}
else
{
return 0;
}
return translator;
}
KeyboardTranslator* KeyboardTranslatorManager::loadTranslator(const QString& name)
{
Q_ASSERT( _paths.contains(name) );
Q_ASSERT( _translators.contains(name) && _translators[name] == 0 );
KeyboardTranslator* translator = new KeyboardTranslator(name);
QFile source(_paths[name]); // TODO get correct path here
const QString& path = findTranslatorPath(name);
QFile source(path); // TODO get correct path here
source.open(QIODevice::ReadOnly);
KeyboardTranslatorReader reader(&source);
......@@ -140,8 +129,13 @@ KeyboardTranslator* KeyboardTranslatorManager::loadTranslator(const QString& nam
QList<QString> KeyboardTranslatorManager::availableTranslators() const
QList<QString> KeyboardTranslatorManager::allTranslators()
{
if ( !_haveLoadedAll )
{
findTranslators();
}
return _translators.keys();
}
......@@ -181,6 +175,43 @@ KeyboardTranslator::KeyboardTranslator(const QString& name)
: _name(name)
{
}
KeyboardTranslator::KeyboardTranslator(const KeyboardTranslator& other)
: _name(other._name)
{
_description = other._description;
// TODO: Copy keyboard entries
}
void KeyboardTranslator::setDescription(const QString& description)
{
_description = description;
}
QString KeyboardTranslator::description() const
{
return _description;
}
QString KeyboardTranslator::name() const
{
return _name;
}
QList<const KeyboardTranslator::Entry*> KeyboardTranslator::entries() const
{
QList<const Entry*> list;
QHashIterator<int,QVarLengthArray<Entry> > iter(_entries);
while ( iter.hasNext() )
{
iter.next();
const QVarLengthArray<Entry>& array = _entries[iter.key()];
for ( int i = 0 ; i < array.size() ; i++ )
list << &array[i];
}
return list;
}
void KeyboardTranslator::addEntry(const Entry& entry)
{
......@@ -221,7 +252,14 @@ KeyboardTranslator::Entry* KeyboardTranslator::findEntry(int keyCode, Qt::Keyboa
return 0;
}
}
void KeyboardTranslatorManager::addTranslator(KeyboardTranslator* translator)
{
qWarning() << __FUNCTION__ << ": Not implemented";
}
void KeyboardTranslatorManager::deleteTranslator(const QString& name)
{
qWarning() << __FUNCTION__ << ": Not implemented";
}
void KeyboardTranslatorManager::setInstance(KeyboardTranslatorManager* instance)
{
_instance = instance;
......
......@@ -19,9 +19,13 @@
02110-1301 USA.
*/
#ifndef KEYBOARDTRANSLATOR_H
#define KEYBOARDTRANSLATOR_H
// Qt
#include <QHash>
#include <QList>
#include <QMetaType>
#include <QVarLengthArray>
class QIODevice;
......@@ -156,10 +160,18 @@ public:
/** Constructs a new keyboard translator with the given @p name */
KeyboardTranslator(const QString& name);
KeyboardTranslator(const KeyboardTranslator& other);
/** Returns the name of this keyboard translator */
QString name() const;
/** Returns the descriptive name of this keyboard translator */
QString description() const;
/** Sets the descriptive name of this keyboard translator */
void setDescription(const QString& description);
/**
* Looks for an entry in this keyboard translator which matches the given
* key code, keyboard modifiers and state flags.
......@@ -179,11 +191,15 @@ public:
*/
void addEntry(const Entry& entry);
/** Returns a list of all entries in the translator. */
QList<const Entry*> entries() const;
private:
QHash<int,QVarLengthArray<Entry> > _entries; // entries in this keyboard translation,
// entries are indexed according to
// their keycode
const QString _name;
QString _description;