forked from qt-creator/qt-creator
Fixes: React to desktop file manager drop events.
Task: 238143
This commit is contained in:
@@ -77,6 +77,7 @@
|
|||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
#include <QtCore/QtPlugin>
|
#include <QtCore/QtPlugin>
|
||||||
|
#include <QtCore/QUrl>
|
||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QCloseEvent>
|
#include <QtGui/QCloseEvent>
|
||||||
@@ -103,10 +104,9 @@ extern "C" void handleSigInt(int sig)
|
|||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Core::Internal;
|
using namespace Core::Internal;
|
||||||
|
|
||||||
namespace {
|
static const char *uriListMimeFormatC = "text/uri-list";
|
||||||
enum { debugMainWindow = 0 };
|
|
||||||
}
|
|
||||||
|
|
||||||
|
enum { debugMainWindow = 0 };
|
||||||
|
|
||||||
MainWindow::MainWindow() :
|
MainWindow::MainWindow() :
|
||||||
QMainWindow(),
|
QMainWindow(),
|
||||||
@@ -157,15 +157,15 @@ MainWindow::MainWindow() :
|
|||||||
QCoreApplication::setOrganizationName(QLatin1String("Nokia"));
|
QCoreApplication::setOrganizationName(QLatin1String("Nokia"));
|
||||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||||
QString baseName = qApp->style()->objectName();
|
QString baseName = qApp->style()->objectName();
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
if (baseName == "windows") {
|
if (baseName == QLatin1String("windows")) {
|
||||||
// Sometimes we get the standard windows 95 style as a fallback
|
// Sometimes we get the standard windows 95 style as a fallback
|
||||||
// e.g. if we are running on a KDE4 desktop
|
// e.g. if we are running on a KDE4 desktop
|
||||||
QByteArray desktopEnvironment = qgetenv("DESKTOP_SESSION");
|
QByteArray desktopEnvironment = qgetenv("DESKTOP_SESSION");
|
||||||
if (desktopEnvironment == "kde")
|
if (desktopEnvironment == "kde")
|
||||||
baseName = "plastique";
|
baseName = QLatin1String("plastique");
|
||||||
else
|
else
|
||||||
baseName = "cleanlooks";
|
baseName = QLatin1String("cleanlooks");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
qApp->setStyle(new ManhattanStyle(baseName));
|
qApp->setStyle(new ManhattanStyle(baseName));
|
||||||
@@ -202,6 +202,7 @@ MainWindow::MainWindow() :
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
statusBar()->setProperty("p_styled", true);
|
statusBar()->setProperty("p_styled", true);
|
||||||
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setSidebarVisible(bool visible)
|
void MainWindow::setSidebarVisible(bool visible)
|
||||||
@@ -361,6 +362,55 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for desktop file manager file drop events
|
||||||
|
|
||||||
|
static bool isDesktopFileManagerDrop(const QMimeData *d, QStringList *files = 0)
|
||||||
|
{
|
||||||
|
if (files)
|
||||||
|
files->clear();
|
||||||
|
// Extract dropped files from Mime data.
|
||||||
|
if (!d->hasFormat(QLatin1String(uriListMimeFormatC)))
|
||||||
|
return false;
|
||||||
|
const QList<QUrl> urls = d->urls();
|
||||||
|
if (urls.empty())
|
||||||
|
return false;
|
||||||
|
// Try to find local files
|
||||||
|
bool hasFiles = false;
|
||||||
|
const QList<QUrl>::const_iterator cend = urls.constEnd();
|
||||||
|
for (QList<QUrl>::const_iterator it = urls.constBegin(); it != cend; ++it) {
|
||||||
|
const QString fileName = it->toLocalFile();
|
||||||
|
if (!fileName.isEmpty()) {
|
||||||
|
hasFiles = true;
|
||||||
|
if (files) {
|
||||||
|
files->push_back(fileName);
|
||||||
|
} else {
|
||||||
|
break; // No result list, sufficient for checking
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
if (isDesktopFileManagerDrop(event->mimeData())) {
|
||||||
|
event->accept();
|
||||||
|
} else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
QStringList files;
|
||||||
|
if (isDesktopFileManagerDrop(event->mimeData(), &files)) {
|
||||||
|
event->accept();
|
||||||
|
openFiles(files);
|
||||||
|
} else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IContext *MainWindow::currentContextObject() const
|
IContext *MainWindow::currentContextObject() const
|
||||||
{
|
{
|
||||||
return m_activeContext;
|
return m_activeContext;
|
||||||
|
@@ -139,8 +139,10 @@ public slots:
|
|||||||
void showOptionsDialog(const QString &category = QString(), const QString &page = QString());
|
void showOptionsDialog(const QString &category = QString(), const QString &page = QString());
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void changeEvent(QEvent *e);
|
virtual void changeEvent(QEvent *e);
|
||||||
void closeEvent(QCloseEvent *event);
|
virtual void closeEvent(QCloseEvent *event);
|
||||||
|
virtual void dragEnterEvent(QDragEnterEvent *event);
|
||||||
|
virtual void dropEvent(QDropEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void openFile();
|
void openFile();
|
||||||
|
@@ -150,6 +150,7 @@ WelcomeMode::WelcomeMode() :
|
|||||||
updateWelcomePage(welcomePageData);
|
updateWelcomePage(welcomePageData);
|
||||||
|
|
||||||
l->addWidget(m_d->m_webview);
|
l->addWidget(m_d->m_webview);
|
||||||
|
m_d->m_webview->setAcceptDrops(false);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
m_d->m_label->setWordWrap(true);
|
m_d->m_label->setWordWrap(true);
|
||||||
|
Reference in New Issue
Block a user