Skip to content

Commit 34a401b

Browse files
committed
Reverted directory for New document
1 parent aae8893 commit 34a401b

5 files changed

Lines changed: 19 additions & 16 deletions

File tree

kdevplatform/interfaces/idocumentcontroller.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ class KDEVPLATFORMINTERFACES_EXPORT IDocumentController: public QObject {
103103
*/
104104
virtual KTextEditor::View* activeTextDocumentView() const = 0;
105105

106-
virtual QUrl nextEmptyDocumentUrl() const = 0;
107106
virtual void updateDirectoryHint(const QString&) = 0;
108107

109108
public Q_SLOTS:

kdevplatform/shell/documentcontroller.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,10 @@ QStringList DocumentController::documentTypes() const
10041004

10051005
static const QRegularExpression& emptyDocumentPattern()
10061006
{
1007-
static const QRegularExpression pattern(QStringLiteral("^/(.+/)?%1(?:\\s\\((\\d+)\\))?$").arg(EMPTY_DOCUMENT_URL));
1007+
/* A hack that binds empty document to directory tree.
1008+
* It must be always bound to root dir, otherwise it may clash with existing
1009+
* files. */
1010+
static const QRegularExpression pattern(QStringLiteral("^/%1(?:\\s\\((\\d+)\\))?$").arg(EMPTY_DOCUMENT_URL));
10081011
return pattern;
10091012
}
10101013

@@ -1021,11 +1024,13 @@ void DocumentController::updateDirectoryHint(const QString& path)
10211024
QString DocumentController::currentDirectory() const
10221025
{
10231026
if ( activeDocument() ) {
1024-
QUrl url = activeDocument()->url().adjusted(
1025-
QUrl::RemoveScheme |
1026-
QUrl::RemoveFilename |
1027-
QUrl::StripTrailingSlash);
1028-
return url.toString();
1027+
QUrl url = activeDocument()->url();
1028+
if (!isEmptyDocumentUrl(url)) {
1029+
return url.adjusted(
1030+
QUrl::RemoveScheme |
1031+
QUrl::RemoveFilename |
1032+
QUrl::StripTrailingSlash).toString();
1033+
}
10291034
}
10301035
if (!d->directoryHint.isEmpty()) {
10311036
return d->directoryHint;
@@ -1036,7 +1041,7 @@ QString DocumentController::currentDirectory() const
10361041
return QString();
10371042
}
10381043

1039-
QUrl DocumentController::nextEmptyDocumentUrl() const
1044+
QUrl DocumentController::nextEmptyDocumentUrl()
10401045
{
10411046
int nextEmptyDocNumber = 0;
10421047
const auto& pattern = emptyDocumentPattern();
@@ -1054,9 +1059,9 @@ QUrl DocumentController::nextEmptyDocumentUrl() const
10541059

10551060
QUrl url;
10561061
if (nextEmptyDocNumber > 0)
1057-
url = QUrl::fromLocalFile(currentDirectory() + '/' + QStringLiteral("%1 (%2)").arg(EMPTY_DOCUMENT_URL).arg(nextEmptyDocNumber));
1062+
url = QUrl::fromLocalFile(QStringLiteral("/%1 (%2)").arg(EMPTY_DOCUMENT_URL).arg(nextEmptyDocNumber));
10581063
else
1059-
url = QUrl::fromLocalFile(currentDirectory() + '/' + EMPTY_DOCUMENT_URL);
1064+
url = QUrl::fromLocalFile('/' + EMPTY_DOCUMENT_URL);
10601065
return url;
10611066
}
10621067

kdevplatform/shell/documentcontroller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class KDEVPLATFORMSHELL_EXPORT DocumentController: public IDocumentController {
102102

103103
/**checks that url is an url of empty document*/
104104
static bool isEmptyDocumentUrl(const QUrl &url);
105-
QUrl nextEmptyDocumentUrl() const override;
105+
static QUrl nextEmptyDocumentUrl();
106106
void updateDirectoryHint(const QString& path) override;
107107
QString currentDirectory() const;
108108

kdevplatform/shell/mainwindow_actions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ void MainWindowPrivate::toggleFullScreen(bool fullScreen)
187187

188188
void MainWindowPrivate::fileNew()
189189
{
190-
auto doc = Core::self()->documentControllerInternal();
191-
doc->openDocument(doc->nextEmptyDocumentUrl());
190+
Core::self()->documentControllerInternal()->openDocument(DocumentController::nextEmptyDocumentUrl());
192191
}
193192

194193
void MainWindowPrivate::viewAddNewToolView()

kdevplatform/shell/tests/test_documentcontroller.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ QUrl TestDocumentController::createFile(const QTemporaryDir& dir, const QString&
176176

177177
void TestDocumentController::testEmptyUrl()
178178
{
179-
const auto first = m_subject->nextEmptyDocumentUrl();
179+
const auto first = DocumentController::nextEmptyDocumentUrl();
180180
QVERIFY(DocumentController::isEmptyDocumentUrl(first));
181-
QCOMPARE(m_subject->nextEmptyDocumentUrl(), first);
181+
QCOMPARE(DocumentController::nextEmptyDocumentUrl(), first);
182182

183183
auto doc = m_subject->openDocumentFromText(QString());
184184
QCOMPARE(doc->url(), first);
185185

186-
const auto second = m_subject->nextEmptyDocumentUrl();
186+
const auto second = DocumentController::nextEmptyDocumentUrl();
187187
QVERIFY(first != second);
188188
QVERIFY(DocumentController::isEmptyDocumentUrl(second));
189189

0 commit comments

Comments
 (0)