forked from qt-creator/qt-creator
Refactor: add userResourcePath() accessor to ICore.
Access to the users private resource path (derived from the settings path) has been used in quite some places, so it's worth moving it to the core interface centrally. Reviewed-By: Thorbjorn Lindeijer
This commit is contained in:
@@ -175,6 +175,22 @@ QString CoreImpl::resourcePath() const
|
|||||||
return QDir::cleanPath(QCoreApplication::applicationDirPath() + QLatin1String(SHARE_PATH));
|
return QDir::cleanPath(QCoreApplication::applicationDirPath() + QLatin1String(SHARE_PATH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CoreImpl::userResourcePath() const
|
||||||
|
{
|
||||||
|
// Create qtcreator dir if it doesn't yet exist
|
||||||
|
const QString configDir = QFileInfo(settings(QSettings::UserScope)->fileName()).path();
|
||||||
|
const QString urp = configDir + "/qtcreator";
|
||||||
|
|
||||||
|
QFileInfo fi(urp + QLatin1Char('/'));
|
||||||
|
if (!fi.exists()) {
|
||||||
|
QDir dir;
|
||||||
|
if (!dir.mkpath(urp))
|
||||||
|
qWarning() << "could not create" << url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return urp;
|
||||||
|
}
|
||||||
|
|
||||||
IContext *CoreImpl::currentContextObject() const
|
IContext *CoreImpl::currentContextObject() const
|
||||||
{
|
{
|
||||||
return m_mainwindow->currentContextObject();
|
return m_mainwindow->currentContextObject();
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ public:
|
|||||||
QPrinter *printer() const;
|
QPrinter *printer() const;
|
||||||
|
|
||||||
QString resourcePath() const;
|
QString resourcePath() const;
|
||||||
|
QString userResourcePath() const;
|
||||||
|
|
||||||
IContext *currentContextObject() const;
|
IContext *currentContextObject() const;
|
||||||
|
|
||||||
|
|||||||
@@ -94,11 +94,7 @@ HelpManager* HelpManager::instance()
|
|||||||
|
|
||||||
QString HelpManager::collectionFilePath()
|
QString HelpManager::collectionFilePath()
|
||||||
{
|
{
|
||||||
const QFileInfo fi(Core::ICore::instance()->settings()->fileName());
|
return QDir::cleanPath(Core::ICore::instance()->userResourcePath() + QLatin1String("/helpcollection.qhc"));
|
||||||
const QDir directory(fi.absolutePath() + QLatin1String("/qtcreator"));
|
|
||||||
if (!directory.exists())
|
|
||||||
directory.mkpath(directory.absolutePath());
|
|
||||||
return QDir::cleanPath(directory.absolutePath() + QLatin1String("/helpcollection.qhc"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpManager::registerDocumentation(const QStringList &files)
|
void HelpManager::registerDocumentation(const QStringList &files)
|
||||||
|
|||||||
@@ -233,6 +233,16 @@
|
|||||||
the place, since e.g. on Mac the resources are part of the application bundle.
|
the place, since e.g. on Mac the resources are part of the application bundle.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QString ICore::userResourcePath() const
|
||||||
|
\brief Returns the absolute path in the users directory that is used for
|
||||||
|
resources like project templates.
|
||||||
|
|
||||||
|
Use this method for finding the place for resources that the user may
|
||||||
|
write to, e.g. to allow for custom palettes or templates.
|
||||||
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn QMainWindow *ICore::mainWindow() const
|
\fn QMainWindow *ICore::mainWindow() const
|
||||||
\brief Returns the main application window.
|
\brief Returns the main application window.
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ public:
|
|||||||
virtual QPrinter *printer() const = 0;
|
virtual QPrinter *printer() const = 0;
|
||||||
|
|
||||||
virtual QString resourcePath() const = 0;
|
virtual QString resourcePath() const = 0;
|
||||||
|
virtual QString userResourcePath() const = 0;
|
||||||
|
|
||||||
virtual QMainWindow *mainWindow() const = 0;
|
virtual QMainWindow *mainWindow() const = 0;
|
||||||
virtual QStatusBar *statusBar() const = 0;
|
virtual QStatusBar *statusBar() const = 0;
|
||||||
|
|||||||
@@ -985,7 +985,7 @@ QStringList SessionManager::sessions() const
|
|||||||
|
|
||||||
QString SessionManager::sessionNameToFileName(const QString &session)
|
QString SessionManager::sessionNameToFileName(const QString &session)
|
||||||
{
|
{
|
||||||
return QFileInfo(m_core->settings()->fileName()).path() + "/qtcreator/" + session + ".qws";
|
return m_core->userResourcePath() + '/' + session + ".qws";
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionManager::createAndLoadNewDefaultSession()
|
void SessionManager::createAndLoadNewDefaultSession()
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ using namespace TextEditor::Internal;
|
|||||||
|
|
||||||
static QString customStylesPath()
|
static QString customStylesPath()
|
||||||
{
|
{
|
||||||
QString path = QFileInfo(Core::ICore::instance()->settings()->fileName()).path();
|
QString path = Core::ICore::instance()->userResourcePath();
|
||||||
path.append(QLatin1String("/qtcreator/styles/"));
|
path.append(QLatin1String("/styles/"));
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user