Commit 2daae41a authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

use last location of open file dialog instead of home if current document has...

use last location of open file dialog instead of home if current document has no valid url (e.g. untitled)

Bug 364128 - Open without an active document uses home location instead of last open/file location

fixes btw. open of file without name, as toLocalFile() needs a guard

BUG: 364128
parent 7d016cab
......@@ -222,37 +222,42 @@ void KateViewManager::slotDocumentNew()
void KateViewManager::slotDocumentOpen()
{
KTextEditor::View *cv = activeView();
if (!cv) {
return;
// try to start dialog in useful dir: either dir of current doc or last used one
KTextEditor::View * const cv = activeView();
QUrl startUrl = cv ? cv->document()->url() : QUrl();
if (startUrl.isValid()) {
m_lastOpenDialogUrl = startUrl;
} else {
startUrl = m_lastOpenDialogUrl;
}
const QList<QUrl> urls = QFileDialog::getOpenFileUrls(m_mainWindow, i18n("Open File"), startUrl);
KateDocumentInfo docInfo;
docInfo.openedByUser = true;
QString fileList;
const QList<QUrl> urls = QFileDialog::getOpenFileUrls(m_mainWindow, i18n("Open File"), cv->document()->url());
/**
* emit size warning, for local files
*/
QString fileListWithTooLargeFiles;
Q_FOREACH(const QUrl & url, urls) {
qint64 size = QFile(url.toLocalFile()).size();
if (!url.isLocalFile()) {
continue;
}
const auto size = QFile(url.toLocalFile()).size();
if (size > FileSizeAboveToAskUserIfProceedWithOpen) {
fileList += QString::fromLatin1("<li>%1 (%2MB)</li>").arg(url.fileName()).arg(size / 1024 / 1024);
fileListWithTooLargeFiles += QString::fromLatin1("<li>%1 (%2MB)</li>").arg(url.fileName()).arg(size / 1024 / 1024);
}
}
if (!fileList.isEmpty()) {
QString text = i18n("<p>You are attempting to open one or more large files:</p><ul>%1</ul><p>Do you want to proceed?</p><p><strong>Beware that kate may stop responding for some time when opening large files.</strong></p>");
int ret = KMessageBox::warningYesNo(this, text.arg(fileList), i18n("Opening Large File"), KStandardGuiItem::cont(), KStandardGuiItem::stop());
if (!fileListWithTooLargeFiles.isEmpty()) {
const QString text = i18n("<p>You are attempting to open one or more large files:</p><ul>%1</ul><p>Do you want to proceed?</p><p><strong>Beware that kate may stop responding for some time when opening large files.</strong></p>");
const auto ret = KMessageBox::warningYesNo(this, text.arg(fileListWithTooLargeFiles), i18n("Opening Large File"), KStandardGuiItem::cont(), KStandardGuiItem::stop());
if (ret == KMessageBox::No) {
return;
}
}
KTextEditor::Document *lastID = openUrls(urls, QString(), false, docInfo);
if (lastID) {
// activate view of last opened document
KateDocumentInfo docInfo;
docInfo.openedByUser = true;
if (KTextEditor::Document *lastID = openUrls(urls, QString(), false, docInfo)) {
activateView(lastID);
}
}
......
......@@ -155,7 +155,7 @@ private Q_SLOTS:
*
* note that the batch can be interrupted in the middle and only some
* of the documents may be actually deleted. See documentsDeleted() signal.
*
*
* @param documents documents we want to delete, may not be deleted
*/
void aboutToDeleteDocuments(const QList<KTextEditor::Document *> &documents);
......@@ -167,7 +167,7 @@ private Q_SLOTS:
* @param documents the documents that weren't deleted after all
*/
void documentsDeleted(const QList<KTextEditor::Document *> &documents);
public Q_SLOTS:
/**
* Splits a KateViewSpace into two in the following steps:
......@@ -240,12 +240,12 @@ public Q_SLOTS:
/** closes every view but the active one */
void slotCloseOtherViews();
/** hide every view but the active one */
void slotHideOtherViews(bool hideOthers);
void reactivateActiveView();
/**
* Toogle the orientation of current split view
*/
......@@ -309,24 +309,24 @@ private:
, activityResource(Q_NULLPTR)
{
}
/**
* view active?
*/
bool active;
/**
* lru age of the view
* important: smallest age ==> latest used view
*/
qint64 lruAge;
/**
* activity resource for the view
*/
KActivities::ResourceInstance *activityResource;
};
/**
* central storage of all views known in the view manager
* maps the view to meta data
......@@ -337,11 +337,16 @@ private:
* current minimal age
*/
qint64 m_minAge;
/**
* the view that is ATM merged to the xml gui factory
*/
QPointer<KTextEditor::View> m_guiMergedView;
/**
* last url of open file dialog, used if current document has no valid url
*/
QUrl m_lastOpenDialogUrl;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment