Bug 101966 - remember the line after closing a file
Summary: remember the line after closing a file
Status: RESOLVED FIXED
Alias: None
Product: quanta
Classification: Miscellaneous
Component: general (show other bugs)
Version: 3.3.2
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: András Manţia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-20 10:07 UTC by Mike Massonnet
Modified: 2006-03-03 17:39 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Massonnet 2005-03-20 10:07:32 UTC
Version:           3.3.2 (using KDE 3.3.2,  (3.1))
Compiler:          gcc version 3.3.5 (Debian 1:3.3.5-6)
OS:                Linux (i686) release 2.6.10-1-k7

Hello,
I have a little suggestion. Actually it could be very nice to remember the line of the file when we close it. So after opening it again, we just catch this line and place the cursor at this position. 
For instance we could add an item in the webproject file and name it lastline or editedline. So we just need to parse it to retrive the line.
Well, I hope you find my idea nice enough to add it into the next releases. Sorry but currently I don't really know where and how to hack Quanta otherwise I could made a patch for testing.
Bye :)
Comment 1 András Manţia 2006-03-03 17:39:44 UTC
SVN commit 515400 by amantia:

Remember cursor position for project documents.
Make highlighting workaround work again (was broken by previous commit).

BUG: 101966

 M  +1 -0      ChangeLog  
 M  +66 -0     project/project.cpp  
 M  +6 -1      project/project.h  
 M  +6 -0      project/projectprivate.cpp  
 M  +1 -0      src/quantadoc.cpp  
 M  +2 -0      src/quantaview.cpp  
 M  +1 -1      src/viewmanager.cpp  


--- branches/KDE/3.5/kdewebdev/quanta/ChangeLog #515399:515400
@@ -14,6 +14,7 @@
         - open dropped files [#102605]
         - don't try to remove an empty, unmodified buffer, if it is the last
           opened one [#111599]
+        - remember cursor position for project documents [#101966]
 
 
 Version 3.5.1 (Release date: 23-01-2006; Started 30-11-2005):
--- branches/KDE/3.5/kdewebdev/quanta/project/project.cpp #515399:515400
@@ -42,6 +42,9 @@
 #include <kurlrequester.h>
 #include <kurlrequesterdlg.h>
 
+#include <ktexteditor/markinterface.h>
+#include <ktexteditor/viewcursorinterface.h>
+
 // application headers
 #include "copyto.h"
 #include "document.h"
@@ -1320,5 +1323,68 @@
   }
 }
 
+void Project::loadCursorPosition(const KURL &url, KTextEditor::ViewCursorInterface *viewCursorIf)
+{
+  if (!viewCursorIf || !hasProject() || !contains(url))
+    return;
+  QDomNodeList nl = d->m_sessionDom.elementsByTagName("item");
+  QDomElement el;
+  KURL u = QExtFileInfo::toRelative(url, d->baseURL);
+  for ( uint i = 0; i < nl.count(); i++ )
+  {
+    el = nl.item(i).toElement();
+    if ( el.attribute("url") == QuantaCommon::qUrl(u) )
+    {
+      QString s = el.attribute("line");      
+      uint line, col;
+      bool ok;
+      line = s.toUInt(&ok, 10);
+      if (ok)
+      {
+        s = el.attribute("column");
+        col = s.toUInt(&ok, 10);
+        if (ok)
+         viewCursorIf->setCursorPositionReal(line, col);
+      }
+    }
+    KURL u2 = d->baseURL;
+    QuantaCommon::setUrl(u2, el.attribute("url"));
+    if (!contains(u2))
+    {
+      el.parentNode().removeChild(el);
+    }
+  }
+}
 
+void Project::saveCursorPosition(const KURL &url, KTextEditor::ViewCursorInterface *viewCursorIf)
+{
+  if (!viewCursorIf || !hasProject() || !contains(url))
+    return;
+  QDomNodeList nl = d->m_sessionDom.elementsByTagName("item");
+  QDomElement el;
+  KURL u = QExtFileInfo::toRelative(url, d->baseURL);
+  uint line, col;
+  viewCursorIf->cursorPosition(&line, &col);
+  bool found = false;
+  for ( uint i = 0; i < nl.count(); i++ )
+  {
+    el = nl.item(i).toElement();
+    if ( el.attribute("url") == QuantaCommon::qUrl(u) )
+    {
+      el.setAttribute("line", line);
+      el.setAttribute("column", col);
+      found = true;
+      break;
+    }
+  }
+  if (!found)
+  {
+    el = d->m_sessionDom.createElement("item");
+    el.setAttribute("column", col);
+    el.setAttribute("line", line);
+    el.setAttribute("url", QuantaCommon::qUrl(u));
+    QDomNode no = d->m_sessionDom.firstChild().firstChild().namedItem("itemcursorpositions");
+    no.appendChild(el);   
+  }
+}
 #include "project.moc"
--- branches/KDE/3.5/kdewebdev/quanta/project/project.h #515399:515400
@@ -19,13 +19,16 @@
 #define PROJECT_H
 
 #include <qobject.h>
-#include <ktexteditor/markinterface.h>
 
 #include "projecturl.h"
 
 class QDom;
 class ProjectPrivate;
 class ProjectList;
+namespace KTextEditor{
+  class MarkInterface;
+  class ViewCursorInterface;
+};
 struct EventAction;
 typedef  QMap<QString, QValueList<EventAction> > EventActions;
 
@@ -145,6 +148,8 @@
   void saveBookmarks(const KURL &url, KTextEditor::MarkInterface *markIf);
   /** Loads the bookmarks for the url from the project file and sets them in the view*/
   void loadBookmarks(const KURL &url, KTextEditor::MarkInterface *markIf);
+  void saveCursorPosition(const KURL &url, KTextEditor::ViewCursorInterface *viewCursorIf);
+  void loadCursorPosition(const KURL &url, KTextEditor::ViewCursorInterface *viewCursorIf);
 
 public slots:
 
--- branches/KDE/3.5/kdewebdev/quanta/project/projectprivate.cpp #515399:515400
@@ -416,6 +416,12 @@
     sessionNode.toElement().setAttribute("previewPrefix", previewPrefix.url());
     sessionNode.toElement().setAttribute("usePersistentBookmarks", m_persistentBookmarks ? "1" : "0");
   }
+  no = sessionNode.namedItem("itemcursorpositions");
+  if (no.isNull())
+  {
+    el = m_sessionDom.createElement("itemcursorpositions");
+    sessionNode.appendChild(el);
+  } 
   m_eventsEnabled = projectNode.toElement().attribute("enableEvents", "true") == "true";
   m_defaultEncoding = projectNode.toElement().attribute("encoding");
   if (m_defaultEncoding.isEmpty())
--- branches/KDE/3.5/kdewebdev/quanta/src/quantadoc.cpp #515399:515400
@@ -242,6 +242,7 @@
   if (url.isLocalFile())
     quantaApp->debugger()->fileOpened(url.prettyURL(0, KURL::StripFileProtocol));
   quantaApp->slotNewStatus();
+  Project::ref()->loadCursorPosition(w->url(), dynamic_cast<KTextEditor::ViewCursorInterface*>(w->view()));
   emit eventHappened("after_open", url.url(), QString::null);
   
   bool flag = TagActionManager::canIndentDTD(w->defaultDTD()->name);
--- branches/KDE/3.5/kdewebdev/quanta/src/quantaview.cpp #515399:515400
@@ -157,6 +157,8 @@
         fileWatcher->removeFile(url.path());
 //        kdDebug(24000) << "removeFile[mayRemove]: " << url.path() << endl;
       }
+      Project::ref()->saveCursorPosition(url, dynamic_cast<KTextEditor::ViewCursorInterface*>(m_document->view()));
+    
       quantaApp->menuBar()->activateItemAt(-1);
       quantaApp->guiFactory()->removeClient(m_document->view());
       emit eventHappened("after_close", url.url(), QString::null);
--- branches/KDE/3.5/kdewebdev/quanta/src/viewmanager.cpp #515399:515400
@@ -162,7 +162,7 @@
       if (noOfViews > 1)
         break;
     }
-    if (noOfViews == 1 && view->document()->isUntitled() && !view->document()->isModified())
+    if (noOfViews == 1 && view->document()->isUntitled() && !view->document()->isModified() && createNew)
       return true;
     bool mayRemove = view->mayRemove();
     if (mayRemove)