forked from qt-creator/qt-creator
Editors: Add an option to enable/disable the camel case navigation.
The user can change the setting in Option->Text Editor->Behavior. Reviewer's note: We do have alternative ways to disable camel-case operations through the shortcuts. Nevertheless, this particular option has been quite requested since it disables every camel-case based operation at once. In addition, it seems that the shortcuts are still not "visible" or "expected" for many users. Change-Id: I04364760f4b43123fd9e06c0c52ba9e6a5688e2c Merge-request: 392 Reviewed-on: http://codereview.qt-project.org/6419 Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com> Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
This commit is contained in:
committed by
Leandro T. C. Melo
parent
14d9328072
commit
7fc4de0b65
@@ -1498,9 +1498,9 @@ bool BaseTextEditorWidget::cursorMoveKeyEvent(QKeyEvent *e)
|
||||
bool visualNavigation = cursor.visualNavigation();
|
||||
cursor.setVisualNavigation(true);
|
||||
|
||||
if (op == QTextCursor::WordRight) {
|
||||
if (camelCaseNavigationEnabled() && op == QTextCursor::WordRight) {
|
||||
camelCaseRight(cursor, mode);
|
||||
} else if (op == QTextCursor::WordLeft) {
|
||||
} else if (camelCaseNavigationEnabled() && op == QTextCursor::WordLeft) {
|
||||
camelCaseLeft(cursor, mode);
|
||||
} else {
|
||||
cursor.movePosition(op, mode);
|
||||
@@ -1643,7 +1643,10 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
|
||||
e->accept();
|
||||
QTextCursor c = textCursor();
|
||||
int pos = c.position();
|
||||
camelCaseLeft(c, QTextCursor::MoveAnchor);
|
||||
if (camelCaseNavigationEnabled())
|
||||
camelCaseLeft(c, QTextCursor::MoveAnchor);
|
||||
else
|
||||
c.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
|
||||
int targetpos = c.position();
|
||||
forever {
|
||||
handleBackspaceKey();
|
||||
@@ -1656,13 +1659,19 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
|
||||
} else if (!ro && e == QKeySequence::DeleteStartOfWord && !textCursor().hasSelection()) {
|
||||
e->accept();
|
||||
QTextCursor c = textCursor();
|
||||
camelCaseLeft(c, QTextCursor::KeepAnchor);
|
||||
if (camelCaseNavigationEnabled())
|
||||
camelCaseLeft(c, QTextCursor::KeepAnchor);
|
||||
else
|
||||
c.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
|
||||
c.removeSelectedText();
|
||||
return;
|
||||
} else if (!ro && e == QKeySequence::DeleteEndOfWord && !textCursor().hasSelection()) {
|
||||
e->accept();
|
||||
QTextCursor c = textCursor();
|
||||
camelCaseRight(c, QTextCursor::KeepAnchor);
|
||||
if (camelCaseNavigationEnabled())
|
||||
camelCaseRight(c, QTextCursor::KeepAnchor);
|
||||
else
|
||||
c.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
||||
c.removeSelectedText();
|
||||
return;
|
||||
} else switch (e->key()) {
|
||||
@@ -2308,6 +2317,16 @@ bool BaseTextEditorWidget::constrainTooltips() const
|
||||
return d->m_behaviorSettings.m_constrainTooltips;
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::setCamelCaseNavigationEnabled(bool b)
|
||||
{
|
||||
d->m_behaviorSettings.m_camelCaseNavigation = b;
|
||||
}
|
||||
|
||||
bool BaseTextEditorWidget::camelCaseNavigationEnabled() const
|
||||
{
|
||||
return d->m_behaviorSettings.m_camelCaseNavigation;
|
||||
}
|
||||
|
||||
void BaseTextEditorWidget::setRevisionsVisible(bool b)
|
||||
{
|
||||
d->m_revisionsVisible = b;
|
||||
|
||||
@@ -205,6 +205,9 @@ public:
|
||||
void setConstrainTooltips(bool b);
|
||||
bool constrainTooltips() const;
|
||||
|
||||
void setCamelCaseNavigationEnabled(bool b);
|
||||
bool camelCaseNavigationEnabled() const;
|
||||
|
||||
void setRevisionsVisible(bool b);
|
||||
bool revisionsVisible() const;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
static const char mouseNavigationKey[] = "MouseNavigation";
|
||||
static const char scrollWheelZoomingKey[] = "ScrollWheelZooming";
|
||||
static const char constrainTooltips[] = "ConstrainTooltips";
|
||||
static const char camelCaseNavigationKey[] = "CamelCaseNavigation";
|
||||
static const char groupPostfix[] = "BehaviorSettings";
|
||||
|
||||
namespace TextEditor {
|
||||
@@ -47,7 +48,8 @@ namespace TextEditor {
|
||||
BehaviorSettings::BehaviorSettings() :
|
||||
m_mouseNavigation(true),
|
||||
m_scrollWheelZooming(true),
|
||||
m_constrainTooltips(false)
|
||||
m_constrainTooltips(false),
|
||||
m_camelCaseNavigation(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -67,6 +69,7 @@ void BehaviorSettings::toMap(const QString &prefix, QVariantMap *map) const
|
||||
map->insert(prefix + QLatin1String(mouseNavigationKey), m_mouseNavigation);
|
||||
map->insert(prefix + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming);
|
||||
map->insert(prefix + QLatin1String(constrainTooltips), m_constrainTooltips);
|
||||
map->insert(prefix + QLatin1String(camelCaseNavigationKey), m_camelCaseNavigation);
|
||||
}
|
||||
|
||||
void BehaviorSettings::fromMap(const QString &prefix, const QVariantMap &map)
|
||||
@@ -77,6 +80,8 @@ void BehaviorSettings::fromMap(const QString &prefix, const QVariantMap &map)
|
||||
map.value(prefix + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming).toBool();
|
||||
m_constrainTooltips =
|
||||
map.value(prefix + QLatin1String(constrainTooltips), m_constrainTooltips).toBool();
|
||||
m_camelCaseNavigation =
|
||||
map.value(prefix + QLatin1String(camelCaseNavigationKey), m_camelCaseNavigation).toBool();
|
||||
}
|
||||
|
||||
bool BehaviorSettings::equals(const BehaviorSettings &ds) const
|
||||
@@ -84,6 +89,7 @@ bool BehaviorSettings::equals(const BehaviorSettings &ds) const
|
||||
return m_mouseNavigation == ds.m_mouseNavigation
|
||||
&& m_scrollWheelZooming == ds.m_scrollWheelZooming
|
||||
&& m_constrainTooltips == ds.m_constrainTooltips
|
||||
&& m_camelCaseNavigation == ds.m_camelCaseNavigation
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
bool m_mouseNavigation;
|
||||
bool m_scrollWheelZooming;
|
||||
bool m_constrainTooltips;
|
||||
bool m_camelCaseNavigation;
|
||||
};
|
||||
|
||||
inline bool operator==(const BehaviorSettings &t1, const BehaviorSettings &t2) { return t1.equals(t2); }
|
||||
|
||||
@@ -99,6 +99,8 @@ BehaviorSettingsWidget::BehaviorSettingsWidget(QWidget *parent)
|
||||
this, SLOT(slotBehaviorSettingsChanged()));
|
||||
connect(d->m_ui.constrainTooltips, SIGNAL(clicked()),
|
||||
this, SLOT(slotBehaviorSettingsChanged()));
|
||||
connect(d->m_ui.camelCaseNavigation, SIGNAL(clicked()),
|
||||
this, SLOT(slotBehaviorSettingsChanged()));
|
||||
connect(d->m_ui.utf8BomBox, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(slotExtraEncodingChanged()));
|
||||
connect(d->m_ui.encodingBox, SIGNAL(currentIndexChanged(int)),
|
||||
@@ -176,6 +178,7 @@ void BehaviorSettingsWidget::setAssignedBehaviorSettings(const BehaviorSettings
|
||||
d->m_ui.mouseNavigation->setChecked(behaviorSettings.m_mouseNavigation);
|
||||
d->m_ui.scrollWheelZooming->setChecked(behaviorSettings.m_scrollWheelZooming);
|
||||
d->m_ui.constrainTooltips->setChecked(behaviorSettings.m_constrainTooltips);
|
||||
d->m_ui.camelCaseNavigation->setChecked(behaviorSettings.m_camelCaseNavigation);
|
||||
}
|
||||
|
||||
void BehaviorSettingsWidget::assignedBehaviorSettings(BehaviorSettings *behaviorSettings) const
|
||||
@@ -183,6 +186,7 @@ void BehaviorSettingsWidget::assignedBehaviorSettings(BehaviorSettings *behavior
|
||||
behaviorSettings->m_mouseNavigation = d->m_ui.mouseNavigation->isChecked();
|
||||
behaviorSettings->m_scrollWheelZooming = d->m_ui.scrollWheelZooming->isChecked();
|
||||
behaviorSettings->m_constrainTooltips = d->m_ui.constrainTooltips->isChecked();
|
||||
behaviorSettings->m_camelCaseNavigation = d->m_ui.camelCaseNavigation->isChecked();
|
||||
}
|
||||
|
||||
void BehaviorSettingsWidget::setAssignedExtraEncodingSettings(
|
||||
@@ -216,6 +220,7 @@ QString BehaviorSettingsWidget::collectUiKeywords() const
|
||||
<< sep << d->m_ui.mouseNavigation->text()
|
||||
<< sep << d->m_ui.scrollWheelZooming->text()
|
||||
<< sep << d->m_ui.constrainTooltips->text()
|
||||
<< sep << d->m_ui.camelCaseNavigation->text()
|
||||
<< sep << d->m_ui.groupBoxStorageSettings->title()
|
||||
<< sep << d->m_ui.groupBoxEncodings->title()
|
||||
<< sep << d->m_ui.groupBoxMouse->title();
|
||||
|
||||
@@ -314,7 +314,7 @@ Specifies how backspace interacts with indentation.
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBoxMouse">
|
||||
<property name="title">
|
||||
<string>Mouse</string>
|
||||
<string>Mouse and Keyboard</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
@@ -338,6 +338,13 @@ Specifies how backspace interacts with indentation.
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="camelCaseNavigation">
|
||||
<property name="text">
|
||||
<string>Enable built-in camel case &navigation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user