[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kate] kate: use last location of open file dialog instead of home if current document has no valid 
From:       Christoph Cullmann <cullmann () kde ! org>
Date:       2016-09-07 19:00:39
Message-ID: E1bhi5P-0000Es-JU () code ! kde ! org
[Download RAW message or body]

Git commit 2daae41a3738cc319f5925a96d3938779b3bd09b by Christoph Cullmann.
Committed on 07/09/2016 at 18:59.
Pushed by cullmann into branch 'master'.

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

M  +24   -19   kate/kateviewmanager.cpp
M  +14   -9    kate/kateviewmanager.h

http://commits.kde.org/kate/2daae41a3738cc319f5925a96d3938779b3bd09b

diff --git a/kate/kateviewmanager.cpp b/kate/kateviewmanager.cpp
index afbf95b..cd4c135 100644
--- a/kate/kateviewmanager.cpp
+++ b/kate/kateviewmanager.cpp
@@ -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);
     }
 }
diff --git a/kate/kateviewmanager.h b/kate/kateviewmanager.h
index 44bc7e1..b22ea23 100644
--- a/kate/kateviewmanager.h
+++ b/kate/kateviewmanager.h
@@ -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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic