Commit c964d64d authored by dt's avatar dt
Browse files

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

parents 7052cbd6 d5d7911f
......@@ -40,123 +40,45 @@
#include <QtGui/QCheckBox>
#include <QtGui/QPushButton>
Q_DECLARE_METATYPE(Core::IFile*);
using namespace Core;
using namespace Core::Internal;
FileItem::FileItem(QTreeWidget *tree, bool supportOpen, bool open, const QString &text)
: QTreeWidgetItem(tree)
{
m_saveCheckBox = createCheckBox(tree, 0);
m_saveCheckBox->setChecked(true);
QFileInfo fi(text);
QString name = fi.fileName();
if (open)
name.append(tr(" [ReadOnly]"));
if (supportOpen) {
m_sccCheckBox = createCheckBox(tree, 1);
m_sccCheckBox->setEnabled(open);
m_sccCheckBox->setChecked(open);
connect(m_saveCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(updateSCCCheckBox()));
setText(2, name);
setToolTip(2, text);
} else {
m_sccCheckBox = 0;
setText(2, name);
setToolTip(2, text);
}
}
QCheckBox *FileItem::createCheckBox(QTreeWidget *tree, int column)
{
QWidget *w = new QWidget();
QHBoxLayout *l = new QHBoxLayout(w);
l->setMargin(0);
l->setSpacing(0);
QCheckBox *box = new QCheckBox(w);
l->addWidget(box);
l->setAlignment(box, Qt::AlignCenter);
w->setLayout(l);
tree->setItemWidget(this, column, w);
return box;
}
void FileItem::updateSCCCheckBox()
{
if (!m_saveCheckBox->isChecked()) {
m_sccCheckBox->setEnabled(false);
m_sccCheckBox->setChecked(false);
} else {
m_sccCheckBox->setEnabled(true);
}
}
bool FileItem::shouldBeSaved() const
{
return m_saveCheckBox->isChecked();
}
void FileItem::setShouldBeSaved(bool s)
{
m_saveCheckBox->setChecked(s);
}
bool FileItem::shouldBeOpened() const
{
if (m_sccCheckBox)
return m_sccCheckBox->isChecked();
return false;
}
SaveItemsDialog::SaveItemsDialog(MainWindow *mainWindow,
QMap<IFile*, QString> items)
: QDialog(mainWindow)
SaveItemsDialog::SaveItemsDialog(QWidget *parent,
QList<IFile *> items)
: QDialog(parent)
{
m_ui.setupUi(this);
QPushButton *uncheckButton = m_ui.buttonBox->addButton(tr("Uncheck All"),
QDialogButtonBox::ActionRole);
QPushButton *discardButton = m_ui.buttonBox->addButton(tr("Discard All"),
QDialogButtonBox::DestructiveRole);
m_ui.buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
m_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus(Qt::TabFocusReason);
m_ui.treeWidget->header()->setMovable(false);
m_ui.treeWidget->setRootIsDecorated(false);
m_ui.treeWidget->setColumnCount(2);
QStringList headers;
headers << tr("Save") << tr("File Name");
const bool hasVersionControl = true;
if (hasVersionControl) {
m_ui.treeWidget->setColumnCount(3);
headers.insert(1, tr("Open with SCC"));
}
m_ui.treeWidget->setHeaderLabels(headers);
FileItem *itm;
QMap<IFile*, QString>::const_iterator it = items.constBegin();
while (it != items.constEnd()) {
QString directory = QFileInfo(it.key()->fileName()).absolutePath();
bool fileHasVersionControl = mainWindow->vcsManager()->findVersionControlForDirectory(directory) != 0;
itm = new FileItem(m_ui.treeWidget, fileHasVersionControl,
it.key()->isReadOnly(), it.value());
m_itemMap.insert(itm, it.key());
++it;
QPushButton *discardButton = m_ui.buttonBox->addButton(tr("Don't Save"), QDialogButtonBox::DestructiveRole);
m_ui.buttonBox->button(QDialogButtonBox::Save)->setDefault(true);
m_ui.buttonBox->button(QDialogButtonBox::Save)->setFocus(Qt::TabFocusReason);
m_ui.buttonBox->button(QDialogButtonBox::Save)->setMinimumWidth(130); // bad magic number to avoid resizing of button
foreach (IFile *file, items) {
QString visibleName;
QString directory;
QString fileName = file->fileName();
if (fileName.isEmpty()) {
visibleName = file->suggestedFileName();
} else {
QFileInfo info = QFileInfo(fileName);
directory = info.absolutePath();
visibleName = info.fileName();
}
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList()
<< visibleName << directory);
item->setData(0, Qt::UserRole, qVariantFromValue(file));
}
m_ui.treeWidget->resizeColumnToContents(0);
if (hasVersionControl)
m_ui.treeWidget->resizeColumnToContents(1);
m_ui.treeWidget->selectAll();
updateSaveButton();
connect(m_ui.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
connect(m_ui.buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()),
this, SLOT(collectItemsToSave()));
connect(uncheckButton, SIGNAL(clicked()), this, SLOT(uncheckAll()));
connect(discardButton, SIGNAL(clicked()), this, SLOT(discardAll()));
connect(m_ui.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(updateSaveButton()));
}
void SaveItemsDialog::setMessage(const QString &msg)
......@@ -164,24 +86,34 @@ void SaveItemsDialog::setMessage(const QString &msg)
m_ui.msgLabel->setText(msg);
}
void SaveItemsDialog::updateSaveButton()
{
int count = m_ui.treeWidget->selectedItems().count();
QPushButton *button = m_ui.buttonBox->button(QDialogButtonBox::Save);
if (count == m_ui.treeWidget->topLevelItemCount()) {
button->setEnabled(true);
button->setText(tr("Save All"));
} else if (count == 0) {
button->setEnabled(false);
button->setText(tr("Save"));
} else {
button->setEnabled(true);
button->setText(tr("Save Selected"));
}
}
void SaveItemsDialog::collectItemsToSave()
{
m_itemsToSave.clear();
m_itemsToOpen.clear();
QMap<FileItem*, IFile*>::const_iterator it = m_itemMap.constBegin();
while (it != m_itemMap.constEnd()) {
if (it.key()->shouldBeSaved())
m_itemsToSave << it.value();
if (it.key()->shouldBeOpened())
m_itemsToOpen.insert(it.value());
++it;
foreach (QTreeWidgetItem *item, m_ui.treeWidget->selectedItems()) {
m_itemsToSave.append(item->data(0, Qt::UserRole).value<IFile*>());
}
accept();
}
void SaveItemsDialog::discardAll()
{
uncheckAll();
m_ui.treeWidget->clearSelection();
collectItemsToSave();
}
......@@ -189,16 +121,3 @@ QList<IFile*> SaveItemsDialog::itemsToSave() const
{
return m_itemsToSave;
}
QSet<IFile*> SaveItemsDialog::itemsToOpen() const
{
return m_itemsToOpen;
}
void SaveItemsDialog::uncheckAll()
{
for (int i=0; i<m_ui.treeWidget->topLevelItemCount(); ++i) {
FileItem *item = static_cast<FileItem*>(m_ui.treeWidget->topLevelItem(i));
item->setShouldBeSaved(false);
}
}
......@@ -48,49 +48,26 @@ namespace Internal {
class MainWindow;
class FileItem : public QObject, public QTreeWidgetItem
{
Q_OBJECT
public:
FileItem(QTreeWidget *tree, bool supportOpen,
bool open, const QString &text);
bool shouldBeSaved() const;
void setShouldBeSaved(bool s);
bool shouldBeOpened() const;
private slots:
void updateSCCCheckBox();
private:
QCheckBox *createCheckBox(QTreeWidget *tree, int column);
QCheckBox *m_saveCheckBox;
QCheckBox *m_sccCheckBox;
};
class SaveItemsDialog : public QDialog
{
Q_OBJECT
public:
SaveItemsDialog(MainWindow *mainWindow,
QMap<Core::IFile*, QString> items);
SaveItemsDialog(QWidget *parent,
QList<Core::IFile *> items);
void setMessage(const QString &msg);
QList<Core::IFile*> itemsToSave() const;
QSet<Core::IFile*> itemsToOpen() const;
QList<Core::IFile *> itemsToSave() const;
private slots:
void collectItemsToSave();
void uncheckAll();
void discardAll();
void updateSaveButton();
private:
Ui::SaveItemsDialog m_ui;
QMap<FileItem*, Core::IFile*> m_itemMap;
QList<Core::IFile*> m_itemsToSave;
QSet<Core::IFile*> m_itemsToOpen;
};
} // namespace Internal
......
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SaveItemsDialog</class>
<widget class="QDialog" name="SaveItemsDialog" >
<property name="geometry" >
<widget class="QDialog" name="SaveItemsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<width>457</width>
<height>200</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Save Changes</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="msgLabel" >
<property name="text" >
<string>Save the changes of the following items:</string>
<widget class="QLabel" name="msgLabel">
<property name="text">
<string>The following files have unsaved changes:</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="treeWidget" />
<widget class="QTreeWidget" name="treeWidget">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="textElideMode">
<enum>Qt::ElideLeft</enum>
</property>
<property name="indentation">
<number>0</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
<property name="columnCount">
<number>2</number>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
<column>
<property name="text">
<string notr="true">2</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
......@@ -52,11 +79,11 @@
<receiver>SaveItemsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>199</x>
<y>174</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>199</x>
<y>99</y>
</hint>
......
......@@ -36,7 +36,6 @@
#include "icore.h"
#include "iversioncontrol.h"
#include "mimedatabase.h"
#include "saveitemsdialog.h"
#include "tabpositionindicator.h"
#include "vcsmanager.h"
......
......@@ -132,8 +132,7 @@ void EditorModel::addEntry(const Entry &entry)
if (previousIndex >= 0) {
if (entry.editor && m_editors.at(previousIndex).editor == 0) {
m_editors[previousIndex] = entry;
QModelIndex mindex = index(previousIndex, 0);
emit dataChanged(mindex, mindex);
connect(entry.editor, SIGNAL(changed()), this, SLOT(itemChanged()));
}
return;
}
......
......@@ -314,7 +314,8 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
(*cancelled) = false;
QList<IFile *> notSaved;
QMap<IFile*, QString> modifiedFiles;
QMap<IFile *, QString> modifiedFilesMap;
QList<IFile *> modifiedFiles;
foreach (IFile *file, files) {
if (file->isModified()) {
......@@ -324,17 +325,16 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
// There can be several FileInterfaces pointing to the same file
// Select one that is not readonly.
if (!(modifiedFiles.values().contains(name)
if (!(modifiedFilesMap.values().contains(name)
&& file->isReadOnly()))
modifiedFiles.insert(file, name);
modifiedFilesMap.insert(file, name);
}
}
modifiedFiles = modifiedFilesMap.keys();
if (!modifiedFiles.isEmpty()) {
QList<IFile *> filesToSave;
QSet<IFile *> filesToOpen;
if (silently) {
filesToSave = modifiedFiles.keys();
filesToSave = modifiedFiles;
} else {
SaveItemsDialog dia(m_mainWindow, modifiedFiles);
if (!message.isEmpty())
......@@ -342,16 +342,15 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
if (dia.exec() != QDialog::Accepted) {
if (cancelled)
(*cancelled) = true;
notSaved = modifiedFiles.keys();
notSaved = modifiedFiles;
return notSaved;
}
filesToSave = dia.itemsToSave();
filesToOpen = dia.itemsToOpen();
}
bool yestoall = false;
foreach (IFile *file, filesToSave) {
if (file->isReadOnly() && filesToOpen.contains(file)) {
if (file->isReadOnly()) {
QString directory = QFileInfo(file->fileName()).absolutePath();
IVersionControl *versionControl = m_mainWindow->vcsManager()->findVersionControlForDirectory(directory);
if (versionControl)
......
......@@ -92,7 +92,9 @@ WelcomeModePrivate::WelcomeModePrivate() :
m_projectHtmlTemplate(readFile(QLatin1String(":/core/html/recent_projects.html"))),
m_baseUrl(QUrl(QLatin1String("qrc:/core/html/welcome.html")))
{
#if !defined(QT_NO_WEBKIT)
m_webview->setContextMenuPolicy(Qt::NoContextMenu);
#endif
}
#if defined(QT_NO_WEBKIT)
......
......@@ -370,7 +370,7 @@ void CPPEditor::jumpToMethod(int)
if (! symbol)
return;
openEditorAt(symbol);
openCppEditorAt(linkToSymbol(symbol));
}
void CPPEditor::updateMethodBoxIndex()
......@@ -579,50 +579,65 @@ void CPPEditor::switchDeclarationDefinition()
declaration = symbols.first();
if (declaration)
openEditorAt(declaration);
openCppEditorAt(linkToSymbol(declaration));
} else if (lastSymbol->type()->isFunctionType()) {
if (Symbol *def = findDefinition(lastSymbol))
openEditorAt(def);
openCppEditorAt(linkToSymbol(def));
}
}
void CPPEditor::jumpToDefinition()
CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor)
{
Link link;
if (!m_modelManager)
return;
return link;
const Snapshot snapshot = m_modelManager->snapshot();
// Find the last symbol up to the cursor position
int line = 0, column = 0;
convertPosition(position(), &line, &column);
convertPosition(cursor.position(), &line, &column);
Document::Ptr doc = snapshot.value(file()->fileName());
if (!doc)
return;
return link;
QTextCursor tc = textCursor();
unsigned lineno = tc.blockNumber() + 1;
// Handle include directives
const unsigned lineno = cursor.blockNumber() + 1;
foreach (const Document::Include &incl, doc->includes()) {
if (incl.line() == lineno) {
if (openCppEditorAt(incl.fileName(), 0, 0))
return; // done
break;
link.fileName = incl.fileName();
link.pos = cursor.block().position();
link.length = cursor.block().length();
return link;
}
}
// Find the last symbol up to the cursor position
Symbol *lastSymbol = doc->findSymbolAt(line, column);
if (!lastSymbol)
return;
return link;
// Check whether we're at a name
const int endOfName = endOfNameAtPosition(cursor.position());
if (!characterAt(endOfName - 1).isLetterOrNumber())
return link;
// Remember the position and length of the name
QTextCursor tc = cursor;
tc.setPosition(endOfName);
tc.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
const int nameStart = tc.position();
const int nameLength = tc.anchor() - tc.position();
// Drop out if we're at a number
if (characterAt(nameStart).isNumber())
return link;
// Get the expression under the cursor
const int endOfName = endOfNameUnderCursor();
// Evaluate the type of the expression under the cursor
tc.setPosition(endOfName);
ExpressionUnderCursor expressionUnderCursor;
const QString expression = expressionUnderCursor(tc);
// Evaluate the type of the expression
TypeOfExpression typeOfExpression;
typeOfExpression.setSnapshot(m_modelManager->snapshot());
typeOfExpression.setSnapshot(snapshot);
QList<TypeOfExpression::Result> resolvedSymbols =
typeOfExpression(expression, doc, lastSymbol);
......@@ -633,10 +648,10 @@ void CPPEditor::jumpToDefinition()
if (!lastSymbol->isFunction())
def = findDefinition(symbol);
if (def)
openEditorAt(def);
else
openEditorAt(symbol);
link = linkToSymbol(def ? def : symbol);
link.pos = nameStart;
link.length = nameLength;
return link;
// This would jump to the type of a name
#if 0
......@@ -649,15 +664,25 @@ void CPPEditor::jumpToDefinition()
#endif
}
} else {
// Handle macro uses
foreach (const Document::MacroUse use, doc->macroUses()) {
if (use.contains(endOfName - 1)) {
const Macro &macro = use.macro();
const QString fileName = QString::fromUtf8(macro.fileName());
if (openCppEditorAt(fileName, macro.line(), 0))
return; // done
link.fileName = QString::fromUtf8(macro.fileName());
link.line = macro.line();
link.pos = use.begin();
link.length = use.end() - use.begin();
return link;
}
}
}
return link;
}
void CPPEditor::jumpToDefinition()
{
openCppEditorAt(findLinkAt(textCursor()));
}
Symbol *CPPEditor::findDefinition(Symbol *symbol)
......@@ -777,6 +802,78 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
delete menu;
}
void CPPEditor::mouseMoveEvent(QMouseEvent *e)
{
bool hasDestination = false;
Qt::CursorShape cursorShape;