Commit 35792c6f authored by Robert Knight's avatar Robert Knight

Use inline editing for the tab title formats.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=663372
parent 33e1a53c
......@@ -59,7 +59,6 @@ set(konsole_KDEINIT_SRCS
ColorScheme.cpp
ColorSchemeEditor.cpp
EditProfileDialog.cpp
EditTabTitleFormatDialog.cpp
Filter.cpp
HistorySizeDialog.cpp
IncrementalSearchBar.cpp
......@@ -81,6 +80,7 @@ set(konsole_KDEINIT_SRCS
Pty.cpp
Screen.cpp
Session.cpp
TabTitleFormatAction.cpp
TerminalDisplay.cpp
Vt102Emulation.cpp
Emulation.cpp
......@@ -100,7 +100,6 @@ set(konsole_KDEINIT_SRCS
kde4_add_ui_files(konsole_KDEINIT_SRCS
ColorSchemeEditor.ui
EditProfileDialog.ui
EditTabTitleFormatDialog.ui
KeyBindingEditor.ui
ManageProfilesDialog.ui
RemoteConnectionDialog.ui
......@@ -135,7 +134,6 @@ set(konsolepart_PART_SRCS
ColorScheme.cpp
ColorSchemeEditor.cpp
EditProfileDialog.cpp
EditTabTitleFormatDialog.cpp
Emulation.cpp
Filter.cpp
History.cpp
......@@ -158,6 +156,7 @@ set(konsolepart_PART_SRCS
ProfileListWidget.cpp
SessionManager.cpp
ManageProfilesDialog.cpp
TabTitleFormatAction.cpp
TerminalCharacterDecoder.cpp
TerminalDisplay.cpp
ViewContainer.cpp
......
......@@ -38,11 +38,11 @@
#include "ColorScheme.h"
#include "ColorSchemeEditor.h"
#include "ui_EditProfileDialog.h"
#include "EditTabTitleFormatDialog.h"
#include "KeyBindingEditor.h"
#include "KeyboardTranslator.h"
#include "SessionManager.h"
#include "ShellCommand.h"
#include "TabTitleFormatAction.h"
using namespace Konsole;
......@@ -168,14 +168,31 @@ void EditProfileDialog::setupGeneralPage(const Profile* info)
SLOT(tabTitleFormatChanged(const QString&)) );
connect(_ui->remoteTabTitleEdit , SIGNAL(textChanged(const QString&)) , this ,
SLOT(remoteTabTitleFormatChanged(const QString&)));
connect(_ui->tabTitleEditButton , SIGNAL(clicked()) , this ,
SLOT(editTabTitle()) );
connect(_ui->remoteTabTitleEditButton , SIGNAL(clicked()) , this ,
SLOT(editRemoteTabTitle()) );
// menus for local and remote tab title dynamic elements
TabTitleFormatAction* localTabTitleAction = new TabTitleFormatAction(this);
localTabTitleAction->setContext(Session::LocalTabTitle);
_ui->tabTitleEditButton->setMenu(localTabTitleAction->menu());
connect( localTabTitleAction , SIGNAL(dynamicElementSelected(const QString&)) ,
this , SLOT(insertTabTitleText(const QString&)) );
TabTitleFormatAction* remoteTabTitleAction = new TabTitleFormatAction(this);
remoteTabTitleAction->setContext(Session::RemoteTabTitle);
_ui->remoteTabTitleEditButton->setMenu(remoteTabTitleAction->menu());
connect( remoteTabTitleAction , SIGNAL(dynamicElementSelected(const QString&)) ,
this , SLOT(insertRemoteTabTitleText(const QString&)) );
connect(_ui->showMenuBarButton , SIGNAL(toggled(bool)) , this ,
SLOT(showMenuBar(bool)) );
}
void EditProfileDialog::insertTabTitleText(const QString& text)
{
_ui->tabTitleEdit->insert(text);
}
void EditProfileDialog::insertRemoteTabTitleText(const QString& text)
{
_ui->remoteTabTitleEdit->insert(text);
}
void EditProfileDialog::showMenuBar(bool show)
{
_tempProfile->setProperty(Profile::ShowMenuBar,show);
......@@ -192,28 +209,6 @@ void EditProfileDialog::showTabBarAsNeeded()
{
_tempProfile->setProperty(Profile::TabBarMode,Profile::ShowTabBarAsNeeded);
}
void EditProfileDialog::editTabTitle()
{
EditTabTitleFormatDialog dialog(this);
dialog.setContext(Session::LocalTabTitle);
dialog.setTabTitleFormat(_ui->tabTitleEdit->text());
if ( dialog.exec() == QDialog::Accepted )
{
_ui->tabTitleEdit->setText(dialog.tabTitleFormat());
}
}
void EditProfileDialog::editRemoteTabTitle()
{
EditTabTitleFormatDialog dialog(this);
dialog.setContext(Session::RemoteTabTitle);
dialog.setTabTitleFormat(_ui->remoteTabTitleEdit->text());
if ( dialog.exec() == QDialog::Accepted )
{
_ui->remoteTabTitleEdit->setText(dialog.tabTitleFormat());
}
}
void EditProfileDialog::tabTitleFormatChanged(const QString& format)
{
_tempProfile->setProperty(Profile::LocalTabTitleFormat,format);
......
......@@ -99,8 +99,8 @@ private slots:
void tabTitleFormatChanged(const QString& text);
void remoteTabTitleFormatChanged(const QString& text);
void editTabTitle();
void editRemoteTabTitle();
void insertTabTitleText(const QString& text);
void insertRemoteTabTitleText(const QString& text);
void showMenuBar(bool);
void alwaysHideTabBar();
......
......@@ -188,7 +188,7 @@
<string>Edit normal tab title format</string>
</property>
<property name="text" >
<string>Edit...</string>
<string>Insert</string>
</property>
</widget>
</item>
......@@ -215,7 +215,7 @@
<string>Edit tab title format used when executing remote commands</string>
</property>
<property name="text" >
<string>Edit..</string>
<string>Insert</string>
</property>
</widget>
</item>
......
<ui version="4.0" >
<class>EditTabTitleFormatDialog</class>
<widget class="QWidget" name="EditTabTitleFormatDialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>138</height>
</rect>
</property>
<property name="windowTitle" >
<string>Edit Tab Format</string>
</property>
<layout class="QGridLayout" >
<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 row="1" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Insert element:</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QComboBox" name="elementComboBox" />
</item>
<item row="2" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Tab title format:</string>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="KLineEdit" name="tabTitleFormatEdit" />
</item>
<item row="0" column="0" colspan="2" >
<widget class="QLabel" name="label_3" >
<property name="minimumSize" >
<size>
<width>380</width>
<height>0</height>
</size>
</property>
<property name="text" >
<string>Tab titles can contain a mixture of plain text and dynamic elements which update automatically as the programs running in the terminal change.</string>
</property>
<property name="wordWrap" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header location="global" >klineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -18,86 +18,84 @@
*/
// Own
#include "EditTabTitleFormatDialog.h"
#include "TabTitleFormatAction.h"
// Qt
#include <QList>
#include <QMenu>
// KDE
#include <KLocale>
// Konsole
#include "ui_EditTabTitleFormatDialog.h"
using namespace Konsole;
const EditTabTitleFormatDialog::Element EditTabTitleFormatDialog::_localElements[] =
const TabTitleFormatAction::Element TabTitleFormatAction::_localElements[] =
{
{ "%n" , i18n("Program Name") },
{ "%p" , i18n("Profile Name") },
{ "%d" , i18n("Current Directory (Short)") },
{ "%D" , i18n("Current Directory (Long)") }
};
const int EditTabTitleFormatDialog::_localElementCount = 4;
const EditTabTitleFormatDialog::Element EditTabTitleFormatDialog::_remoteElements[] =
const int TabTitleFormatAction::_localElementCount = 4;
const TabTitleFormatAction::Element TabTitleFormatAction::_remoteElements[] =
{
{ "%p" , i18n("Profile Name") },
{ "%u" , i18n("User Name") },
{ "%h" , i18n("Remote Host (Short)") },
{ "%H" , i18n("Remote Host (Long)") }
};
const int EditTabTitleFormatDialog::_remoteElementCount = 4;
const int TabTitleFormatAction::_remoteElementCount = 4;
EditTabTitleFormatDialog::EditTabTitleFormatDialog(QWidget* parent)
: KDialog(parent)
TabTitleFormatAction::TabTitleFormatAction(QObject* parent)
: QAction(parent)
, _context(Session::LocalTabTitle)
{
setCaption(i18n("Edit Tab Title Format"));
_ui = new Ui::EditTabTitleFormatDialog();
_ui->setupUi(mainWidget());
_ui->tabTitleFormatEdit->setClearButtonShown(true);
connect( _ui->elementComboBox , SIGNAL(activated(int)) , this , SLOT(insertElement(int)) );
}
EditTabTitleFormatDialog::~EditTabTitleFormatDialog()
{
delete _ui;
}
void EditTabTitleFormatDialog::insertElement(int index)
{
if ( _context == Session::LocalTabTitle )
_ui->tabTitleFormatEdit->insert( _localElements[index].element );
else if ( _context == Session::RemoteTabTitle )
_ui->tabTitleFormatEdit->insert( _remoteElements[index].element );
setMenu( new QMenu() );
connect( menu() , SIGNAL(triggered(QAction*)) , this , SLOT(fireElementSelected(QAction*)) );
}
void EditTabTitleFormatDialog::setTabTitleFormat(const QString& format)
TabTitleFormatAction::~TabTitleFormatAction()
{
_ui->tabTitleFormatEdit->setText(format);
_ui->tabTitleFormatEdit->selectAll();
menu()->deleteLater();
}
QString EditTabTitleFormatDialog::tabTitleFormat() const
void TabTitleFormatAction::fireElementSelected(QAction* action)
{
return _ui->tabTitleFormatEdit->text();
emit dynamicElementSelected(action->data().value<QString>());
}
void EditTabTitleFormatDialog::setContext(Session::TabTitleContext context)
void TabTitleFormatAction::setContext(Session::TabTitleContext context)
{
_context = context;
_ui->elementComboBox->clear();
menu()->clear();
QList<QAction*> list;
int count = 0;
const Element* array = 0;
QStringList list;
if ( context == Session::LocalTabTitle )
{
for ( int i = 0 ; i < _localElementCount ; i++ )
list << _localElements[i].description;
count = _localElementCount;
array = _localElements;
}
else if ( context == Session::RemoteTabTitle )
{
for ( int i = 0 ; i < _remoteElementCount ; i++ )
list << _remoteElements[i].description;
count = _remoteElementCount;
array = _remoteElements;
}
for ( int i = 0 ; i < count ; i++ )
{
QAction* action = new QAction(array[i].description,this);
action->setData(array[i].element);
list << action;
}
_ui->elementComboBox->addItems( list );
menu()->addActions(list);
}
Session::TabTitleContext TabTitleFormatAction::context() const
{
return _context;
}
#include "EditTabTitleFormatDialog.moc"
#include "TabTitleFormatAction.moc"
......@@ -17,43 +17,38 @@
02110-1301 USA.
*/
#ifndef EDITTABTITLEFORMATDIALOG_H
#define EDITTABTITLEFORMATDIALOG_H
#ifndef TABTITLEFORMATACTION_H
#define TABTITLEFORMATACTION_H
// KDE
#include <KDialog>
// Qt
#include <QAction>
// Konsole
#include "Session.h"
namespace Ui
{
class EditTabTitleFormatDialog;
}
namespace Konsole
{
class EditTabTitleFormatDialog : public KDialog
class TabTitleFormatAction : public QAction
{
Q_OBJECT
public:
EditTabTitleFormatDialog(QWidget* parent = 0);
virtual ~EditTabTitleFormatDialog();
TabTitleFormatAction(QObject* parent);
~TabTitleFormatAction();
void setContext(Session::TabTitleContext context);
Session::TabTitleContext context() const;
void setTabTitleFormat(const QString& format);
QString tabTitleFormat() const;
signals:
void dynamicElementSelected(const QString&);
private slots:
void insertElement(int index);
void fireElementSelected(QAction*);
private:
Ui::EditTabTitleFormatDialog* _ui;
Session::TabTitleContext _context;
struct Element
{
QString element;
......@@ -63,8 +58,9 @@ private:
static const int _localElementCount;
static const Element _remoteElements[];
static const int _remoteElementCount;
};
}
#endif // EDITTABTITLEFORMATDIALOG_H
#endif // TABTITLEFORMATACTION_H
Markdown is supported
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