Commit 2e5ce0ae authored by Kai Koehne's avatar Kai Koehne
Browse files

Merge branch 'master' of scm.dev.nokia.troll.no:creator/mainline

parents 2a425c7c eca7744e
......@@ -71,7 +71,7 @@ void FindUsages::operator()(Symbol *symbol)
_declSymbol = symbol;
_id = 0;
if (_declSymbol && 0 != & (_id = _declSymbol->identifier()))
if (_declSymbol && 0 != (_id = _declSymbol->identifier()))
_id = _doc->control()->findOrInsertIdentifier(_id->chars(), _id->size());
if (_id) {
......
......@@ -27,9 +27,10 @@
**
**************************************************************************/
#include "ObjectiveCTypeQualifiers.h"
#include "SimpleLexer.h"
#include "ObjectiveCTypeQualifiers.h"
#include <Lexer.h>
#include <Token.h>
#include <QtDebug>
......
......@@ -27,8 +27,9 @@
**
**************************************************************************/
#include "Overview.h"
#include "TypePrettyPrinter.h"
#include "Overview.h"
#include <FullySpecifiedType.h>
#include <Literals.h>
#include <CoreTypes.h>
......
......@@ -56,7 +56,6 @@
#include <QtDebug>
#include <algorithm>
#include <cctype>
namespace CPlusPlus {
......
......@@ -27,9 +27,10 @@
**
**************************************************************************/
#include "pp-macro-expander.h"
#include "pp.h"
#include "pp-cctype.h"
#include "pp-macro-expander.h"
#include <QDateTime>
namespace CPlusPlus {
......
......@@ -49,6 +49,7 @@
#ifndef PP_MACRO_EXPANDER_H
#define PP_MACRO_EXPANDER_H
#include "Macro.h"
#include "pp-scanner.h"
#include <QVector>
#include <QByteArray>
......
......@@ -255,6 +255,7 @@ ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(cons
MakeStep *cleanMakeStep = new MakeStep(bc);
bc->insertCleanStep(0, cleanMakeStep);
cleanMakeStep->setAdditionalArguments(QStringList() << "clean");
cleanMakeStep->setClean(true);
CMakeOpenProjectWizard copw(m_project->projectManager(),
......
......@@ -503,6 +503,7 @@ bool CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader
//TODO save arguments somewhere copw.arguments()
MakeStep *cleanMakeStep = new MakeStep(bc);
bc->insertCleanStep(0, cleanMakeStep);
cleanMakeStep->setAdditionalArguments(QStringList() << "clean");
cleanMakeStep->setClean(true);
addBuildConfiguration(bc);
......
......@@ -500,7 +500,6 @@ void OverrideableAction::addOverrideAction(QAction *action, const QList<int> &co
m_contextActionMap.insert(k, action);
}
}
action->setShortcut(OverrideableAction::action()->shortcut());
}
void OverrideableAction::actionChanged()
......@@ -530,14 +529,3 @@ bool OverrideableAction::isActive() const
{
return m_active;
}
void OverrideableAction::setKeySequence(const QKeySequence &key)
{
QMap<int, QPointer<QAction> >::const_iterator it = m_contextActionMap.constBegin();
QMap<int, QPointer<QAction> >::const_iterator itEnd = m_contextActionMap.constEnd();
while (it != itEnd) {
it.value()->setShortcut(key);
++it;
}
Action::setKeySequence(key);
}
......@@ -143,7 +143,6 @@ public:
bool setCurrentContext(const QList<int> &context);
void addOverrideAction(QAction *action, const QList<int> &context);
bool isActive() const;
void setKeySequence(const QKeySequence &key);
private slots:
void actionChanged();
......
......@@ -304,7 +304,11 @@ void OutputPaneManager::init()
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = am->registerAction(m_minMaxAction, "Coreplugin.OutputPane.minmax", globalcontext);
#ifdef Q_WS_MAC
cmd->setDefaultKeySequence(QKeySequence("Ctrl+9"));
#else
cmd->setDefaultKeySequence(QKeySequence("Alt+9"));
#endif
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
m_minMaxButton->setDefaultAction(cmd->action());
connect(m_minMaxAction, SIGNAL(triggered()), this, SLOT(slotMinMax()));
......
......@@ -39,6 +39,12 @@
#include <ASTPatternBuilder.h>
#include <ASTMatcher.h>
#include <Token.h>
#include <Type.h>
#include <CoreTypes.h>
#include <Symbol.h>
#include <Symbols.h>
#include <Name.h>
#include <Literals.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <QtDebug>
......@@ -899,6 +905,165 @@ private:
PostfixExpressionAST *qlatin1Call;
};
/*
Replace
a + b
With
a % b
If a and b are of string type.
*/
class UseFastStringConcatenation: public QuickFixOperation
{
public:
UseFastStringConcatenation()
{}
virtual QString description() const
{
return QLatin1String("Use fast string concatenation with %"); // ### tr?
}
virtual int match(const QList<AST *> &path)
{
if (path.isEmpty())
return -1;
// need to search 'up' too
int index = path.size() - 1;
if (BinaryExpressionAST *binary = asPlusNode(path[index])) {
while (0 != (binary = asPlusNode(binary->left_expression)))
_binaryExpressions.prepend(binary);
}
// search 'down'
for (index = path.size() - 1; index != -1; --index) {
AST *node = path.at(index);
if (BinaryExpressionAST *binary = asPlusNode(node)) {
_binaryExpressions.append(binary);
} else if (! _binaryExpressions.isEmpty()) {
break;
}
}
if (_binaryExpressions.isEmpty())
return -1;
// verify types of arguments
BinaryExpressionAST *prevBinary = 0;
foreach (BinaryExpressionAST *binary, _binaryExpressions) {
if (binary->left_expression != prevBinary) {
if (!hasCorrectType(binary->left_expression))
return -1;
}
if (binary->right_expression != prevBinary) {
if (!hasCorrectType(binary->right_expression))
return -1;
}
prevBinary = binary;
}
return index + _binaryExpressions.size();
}
virtual void createChangeSet()
{
// replace + -> %
foreach (BinaryExpressionAST *binary, _binaryExpressions)
replace(binary->binary_op_token, "%");
// wrap literals in QLatin1Literal
foreach (StringLiteralAST *literal, _stringLiterals) {
insert(startOf(literal), "QLatin1Literal(");
insert(endOf(literal), ")");
}
// replace QLatin1String/QString/QByteArray(literal) -> QLatin1Literal(literal)
foreach (PostfixExpressionAST *postfix, _incorrectlyWrappedLiterals) {
replace(postfix->base_expression, "QLatin1Literal");
}
}
BinaryExpressionAST *asPlusNode(AST *ast)
{
BinaryExpressionAST *binary = ast->asBinaryExpression();
if (binary && tokenAt(binary->binary_op_token).kind() == T_PLUS)
return binary;
return 0;
}
bool hasCorrectType(ExpressionAST *ast)
{
if (StringLiteralAST *literal = ast->asStringLiteral()) {
_stringLiterals += literal;
return true;
}
if (PostfixExpressionAST *postfix = ast->asPostfixExpression()) {
if (postfix->base_expression && postfix->postfix_expression_list
&& postfix->postfix_expression_list->value
&& !postfix->postfix_expression_list->next)
{
NameAST *name = postfix->base_expression->asName();
CallAST *call = postfix->postfix_expression_list->value->asCall();
if (name && call) {
QByteArray nameStr(name->name->identifier()->chars());
if ((nameStr == "QLatin1String"
|| nameStr == "QString"
|| nameStr == "QByteArray")
&& call->expression_list
&& call->expression_list->value
&& call->expression_list->value->asStringLiteral()
&& !call->expression_list->next)
{
_incorrectlyWrappedLiterals += postfix;
return true;
}
}
}
}
const QList<LookupItem> &lookup = typeOf(ast);
if (lookup.isEmpty())
return false;
return isQtStringType(lookup[0].type());
}
bool isBuiltinStringType(FullySpecifiedType type)
{
// char*
if (PointerType *ptrTy = type->asPointerType())
if (IntegerType *intTy = ptrTy->elementType()->asIntegerType())
if (intTy->kind() == IntegerType::Char)
return true;
return false;
}
bool isQtStringType(FullySpecifiedType type)
{
if (NamedType *nameTy = type->asNamedType()) {
if (!nameTy->name() || !nameTy->name()->identifier())
return false;
QByteArray name(nameTy->name()->identifier()->chars());
if (name == "QString"
|| name == "QByteArray"
|| name == "QLatin1String"
|| name == "QLatin1Literal"
|| name == "QStringRef"
|| name == "QChar"
)
return true;
}
return false;
}
private:
QList<BinaryExpressionAST *> _binaryExpressions;
QList<StringLiteralAST *> _stringLiterals;
QList<PostfixExpressionAST *> _incorrectlyWrappedLiterals;
};
} // end of anonymous namespace
......@@ -1211,6 +1376,7 @@ int CPPQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
QSharedPointer<FlipBinaryOp> flipBinaryOp(new FlipBinaryOp());
QSharedPointer<WrapStringLiteral> wrapStringLiteral(new WrapStringLiteral());
QSharedPointer<CStringToNSString> wrapCString(new CStringToNSString());
QSharedPointer<UseFastStringConcatenation> useFastStringConcat(new UseFastStringConcatenation());
QList<QuickFixOperationPtr> candidates;
candidates.append(rewriteLogicalAndOp);
......@@ -1223,6 +1389,7 @@ int CPPQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
candidates.append(flipBinaryOp);
candidates.append(wrapStringLiteral);
candidates.append(wrapCString);
candidates.append(useFastStringConcat);
QMap<int, QList<QuickFixOperationPtr> > matchedOps;
......
......@@ -37,7 +37,8 @@ const char * const CVS_SUBMIT_MIMETYPE = "application/vnd.nokia.text.cvs.submit"
const char * const CVSEDITOR = "CVS Editor";
const char * const CVSEDITOR_KIND = "CVS Editor";
const char * const CVSCOMMITEDITOR = "CVS Commit Editor";
const char * const CVSCOMMITEDITOR_KIND = "CVS Commit Editor";
const char * const CVSCOMMITEDITOR_ID = "CVS Commit Editor";
const char * const CVSCOMMITEDITOR_DISPLAY_NAME = QT_TRANSLATE_NOOP("VCS", "CVS Commit Editor");
const char * const SUBMIT_CURRENT = "CVS.SubmitCurrentLog";
const char * const DIFF_SELECTED = "CVS.DiffSelectedFilesInLog";
enum { debug = 0 };
......
......@@ -102,22 +102,26 @@ static const char * const CMD_ID_SEPARATOR4 = "CVS.Separator4";
static const VCSBase::VCSBaseEditorParameters editorParameters[] = {
{
VCSBase::RegularCommandOutput,
"CVS Command Log Editor", // kind
"CVS Command Log Editor", // id
QT_TRANSLATE_NOOP("VCS", "CVS Command Log Editor"), // display name
"CVS Command Log Editor", // context
"application/vnd.nokia.text.scs_cvs_commandlog",
"scslog"},
{ VCSBase::LogOutput,
"CVS File Log Editor", // kind
"CVS File Log Editor", // id
QT_TRANSLATE_NOOP("VCS", "CVS File Log Editor"), // display name
"CVS File Log Editor", // context
"application/vnd.nokia.text.scs_cvs_filelog",
"scsfilelog"},
{ VCSBase::AnnotateOutput,
"CVS Annotation Editor", // kind
"CVS Annotation Editor", // id
QT_TRANSLATE_NOOP("VCS", "CVS Annotation Editor"), // display name
"CVS Annotation Editor", // context
"application/vnd.nokia.text.scs_cvs_annotation",
"scsannotate"},
{ VCSBase::DiffOutput,
"CVS Diff Editor", // kind
"CVS Diff Editor", // id
QT_TRANSLATE_NOOP("VCS", "CVS Diff Editor"), // display name
"CVS Diff Editor", // context
"text/x-patch","diff"}
};
......@@ -146,7 +150,7 @@ Core::IEditor* locateEditor(const char *property, const QString &entry)
CVSPlugin *CVSPlugin::m_cvsPluginInstance = 0;
CVSPlugin::CVSPlugin() :
VCSBase::VCSBasePlugin(QLatin1String(CVS::Constants::CVSCOMMITEDITOR_KIND)),
VCSBase::VCSBasePlugin(QLatin1String(CVS::Constants::CVSCOMMITEDITOR_ID)),
m_addAction(0),
m_deleteAction(0),
m_revertAction(0),
......@@ -189,7 +193,8 @@ bool CVSPlugin::isCommitEditorOpen() const
static const VCSBase::VCSBaseSubmitEditorParameters submitParameters = {
CVS::Constants::CVS_SUBMIT_MIMETYPE,
CVS::Constants::CVSCOMMITEDITOR_KIND,
CVS::Constants::CVSCOMMITEDITOR_ID,
CVS::Constants::CVSCOMMITEDITOR_DISPLAY_NAME,
CVS::Constants::CVSCOMMITEDITOR
};
......@@ -478,7 +483,7 @@ void CVSPlugin::cvsDiff(const QString &workingDir, const QStringList &files)
CVSSubmitEditor *CVSPlugin::openCVSSubmitEditor(const QString &fileName)
{
Core::IEditor *editor = Core::EditorManager::instance()->openEditor(fileName, QLatin1String(Constants::CVSCOMMITEDITOR_KIND));
Core::IEditor *editor = Core::EditorManager::instance()->openEditor(fileName, QLatin1String(Constants::CVSCOMMITEDITOR_ID));
CVSSubmitEditor *submitEditor = qobject_cast<CVSSubmitEditor*>(editor);
QTC_ASSERT(submitEditor, /**/);
submitEditor->registerActions(m_submitUndoAction, m_submitRedoAction, m_submitCurrentLogAction, m_submitDiffAction);
......
......@@ -105,33 +105,8 @@ static inline QIcon designerIcon(const QString &iconName)
return icon;
}
// Create an action to activate a designer tool
static inline QAction *createEditModeAction(QActionGroup *ag,
const QList<int> &context,
Core::ActionManager *am,
Core::ActionContainer *medit,
const QString &actionName,
const QString &name,
int toolNumber,
const QString &iconName = QString(),
const QString &keySequence = QString())
{
QAction *rc = new QAction(actionName, ag);
rc->setCheckable(true);
if (!iconName.isEmpty())
rc->setIcon(designerIcon(iconName));
Core::Command *command = am->registerAction(rc, name, context);
if (!keySequence.isEmpty())
command->setDefaultKeySequence(QKeySequence(keySequence));
medit->addAction(command, Core::Constants::G_EDIT_OTHER);
rc->setData(toolNumber);
ag->addAction(rc);
return rc;
}
// Create a menu separato
static inline QAction * createSeparator(QObject *parent,
// Create a menu separator
static inline QAction *createSeparator(QObject *parent,
Core::ActionManager *am,
const QList<int> &context,
Core::ActionContainer *container,
......@@ -145,20 +120,6 @@ static inline QAction * createSeparator(QObject *parent,
return actSeparator;
}
// Create a tool action
static inline void addToolAction(QAction *a,
Core::ActionManager *am,
const QList<int> &context,
const QString &name,
Core::ActionContainer *c1,
const QString &keySequence = QString())
{
Core::Command *command = am->registerAction(a, name, context);
if (!keySequence.isEmpty())
command->setDefaultKeySequence(QKeySequence(keySequence));
c1->addAction(command);
}
using namespace Designer;
using namespace Designer::Internal;
using namespace Designer::Constants;
......@@ -237,7 +198,8 @@ FormEditorW::FormEditorW() :
m_actionPrint(0),
m_actionPreview(0),
m_actionGroupPreviewInStyle(0),
m_actionAboutPlugins(0)
m_actionAboutPlugins(0),
m_shortcutMapper(new QSignalMapper(this))
{
if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO;
......@@ -270,6 +232,8 @@ FormEditorW::FormEditorW() :
connect(m_core->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor *)),
this, SLOT(currentEditorChanged(Core::IEditor *)));
connect(m_shortcutMapper, SIGNAL(mapped(QObject *)),
this, SLOT(updateShortcut(QObject *)));
}
FormEditorW::~FormEditorW()
......@@ -397,20 +361,21 @@ void FormEditorW::setupActions()
mtools->addMenu(mformtools);
//overridden actions
am->registerAction(m_fwm->actionUndo(), Core::Constants::UNDO, m_context);
am->registerAction(m_fwm->actionRedo(), Core::Constants::REDO, m_context);
am->registerAction(m_fwm->actionCut(), Core::Constants::CUT, m_context);
am->registerAction(m_fwm->actionCopy(), Core::Constants::COPY, m_context);
am->registerAction(m_fwm->actionPaste(), Core::Constants::PASTE, m_context);
am->registerAction(m_fwm->actionSelectAll(), Core::Constants::SELECTALL, m_context);
bindShortcut(am->registerAction(m_fwm->actionUndo(), Core::Constants::UNDO, m_context), m_fwm->actionUndo());
bindShortcut(am->registerAction(m_fwm->actionRedo(), Core::Constants::REDO, m_context), m_fwm->actionRedo());
bindShortcut(am->registerAction(m_fwm->actionCut(), Core::Constants::CUT, m_context), m_fwm->actionCut());
bindShortcut(am->registerAction(m_fwm->actionCopy(), Core::Constants::COPY, m_context), m_fwm->actionCopy());
bindShortcut(am->registerAction(m_fwm->actionPaste(), Core::Constants::PASTE, m_context), m_fwm->actionPaste());
bindShortcut(am->registerAction(m_fwm->actionSelectAll(), Core::Constants::SELECTALL, m_context), m_fwm->actionSelectAll());
m_actionPrint = new QAction(this);
am->registerAction(m_actionPrint, Core::Constants::PRINT, m_context);
bindShortcut(am->registerAction(m_actionPrint, Core::Constants::PRINT, m_context), m_actionPrint);
connect(m_actionPrint, SIGNAL(triggered()), this, SLOT(print()));
//'delete' action
command = am->registerAction(m_fwm->actionDelete(), QLatin1String("FormEditor.Edit.Delete"), m_context);
command->setDefaultKeySequence(QKeySequence::Delete);
bindShortcut(command, m_fwm->actionDelete());
command->setAttribute(Core::Command::CA_Hide);
medit->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
......@@ -613,6 +578,7 @@ Core::ActionContainer *FormEditorW::createPreviewStyleMenu(Core::ActionManager *
}
name += data.toString();
Core::Command *command = am->registerAction(a, name, m_context);
bindShortcut(command, a);
if (isDeviceProfile) {
command->setAttribute(Core::Command::CA_UpdateText);
command->setAttribute(Core::Command::CA_NonConfigureable);
......@@ -642,6 +608,56 @@ void FormEditorW::critical(const QString &errorMessage)
QMessageBox::critical(m_core->mainWindow(), tr("Designer"), errorMessage);
}
// Apply the command shortcut to the action and connects to the command's keySequenceChanged signal
void FormEditorW::bindShortcut(Core::Command *command, QAction *action)
{
m_commandToDesignerAction.insert(command, action);
connect(command, SIGNAL(keySequenceChanged()),
m_shortcutMapper, SLOT(map()));
m_shortcutMapper->setMapping(command, command);
updateShortcut(command);
}
// Create an action to activate a designer tool
QAction *FormEditorW::createEditModeAction(QActionGroup *ag,
const QList<int> &context,
Core::ActionManager *am,
Core::ActionContainer *medit,
const QString &actionName,
const QString &name,
int toolNumber,
const QString &iconName,
const QString &keySequence)
{
QAction *rc = new QAction(actionName, ag);
rc->setCheckable(true);
if (!iconName.isEmpty())
rc->setIcon(designerIcon(iconName));
Core::Command *command = am->registerAction(rc, name, context);
if (!keySequence.isEmpty())
command->setDefaultKeySequence(QKeySequence(keySequence));
bindShortcut(command, rc);
medit->addAction(command, Core::Constants::G_EDIT_OTHER);
rc->setData(toolNumber);
ag->addAction(rc);
return rc;
}
// Create a tool action
void FormEditorW::addToolAction(QAction *a,
Core::ActionManager *am,
const QList<int> &context,
const QString &name,
Core::ActionContainer *c1,
const QString &keySequence)
{
Core::Command *command = am->registerAction(a, name, context);
if (!keySequence.isEmpty())
command->setDefaultKeySequence(QKeySequence(keySequence));
bindShortcut(command, a);
c1->addAction(command);
}
FormWindowEditor *FormEditorW::createFormWindowEditor(QWidget* parentWidget)
{
m_fwm->closeAllPreviews();
......@@ -673,6 +689,17 @@ void FormEditorW::editorDestroyed()
}
}
void FormEditorW::updateShortcut(QObject *command)
{
Core::Command *c = qobject_cast<Core::Command *>(command);
if (!c)
return;
QAction *a = m_commandToDesignerAction.value(c);
if (!a)
return;
a->setShortcut(c->action()->shortcut());
}
void FormEditorW::currentEditorChanged(Core::IEditor *editor)
{
if (Designer::Constants::Internal::debug)
......
......@@ -36,6 +36,7 @@
#include <QtCore/QObject>
#include <QtCore/QPointer>
#include <QtCore/QStringList>
#include <QtCore/QSignalMapper>
#include <QtGui/QAction>
#include "designerconstants.h"
......@@ -65,6 +66,7 @@ class ActionManager;
class ActionContainer;
class ICore;
class IEditor;
class Command;
}
namespace Designer {
......@@ -141,6 +143,7 @@ private slots: