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

List:       quanta-devel
Subject:    [quanta-devel] [patch] toggle breakpoint
From:       Thiago Silva <thiago.silva () kdemail ! net>
Date:       2005-02-23 13:22:39
Message-ID: 200502231322.39754.thiago.silva () kdemail ! net
[Download RAW message or body]

-Enable toggling breakpoints through the editor icon margin
-When lines are inserted/removed from the text, keep the breakpoints 
synchronized with the editor breakpoint marks.

-- 
Thiago Silva

["toggle_bp.patch" (text/x-diff)]

Index: components/debugger/debuggerbreakpointlist.cpp
===================================================================
RCS file: /home/kde/kdewebdev/quanta/components/debugger/debuggerbreakpointlist.cpp,v
retrieving revision 1.4
diff -u -3 -p -u -p -r1.4 debuggerbreakpointlist.cpp
--- components/debugger/debuggerbreakpointlist.cpp	4 Nov 2004 22:12:09 -0000	1.4
+++ components/debugger/debuggerbreakpointlist.cpp	23 Feb 2005 15:22:39 -0000
@@ -44,9 +44,8 @@ void DebuggerBreakpointList::add(Debugge
   m_breakpointList->push_front(bp);
 }
 
-int DebuggerBreakpointList::remove(DebuggerBreakpoint* bp)
+void DebuggerBreakpointList::remove(DebuggerBreakpoint* bp)
 {
-  int count = 0;
   BreakpointList_t::iterator it;
   BreakpointList_t::iterator end = m_breakpointList->end();
 
@@ -63,15 +62,13 @@ int DebuggerBreakpointList::remove(Debug
       quantaApp->debugger()->UI()->deleteBreakpoint(*bp);
 
       // Remove editor markpoint if there is one...
-      quantaApp->debugger()->setMark(bp->filePath(), bp->line(), false, \
KTextEditor::MarkInterface::markType02); +      \
//quantaApp->debugger()->setMark(bp->filePath(), bp->line(), false, \
KTextEditor::MarkInterface::markType02);  
       it = m_breakpointList->remove(it);
       delete tmp;
-      count++;
+      break;
     }
   }
-
-  return count;
 }
 
 /*int DebuggerBreakpointList::remove(QString filePath, int line)
@@ -97,6 +94,22 @@ int DebuggerBreakpointList::remove(Debug
   return count;
 }*/
 
+DebuggerBreakpoint* DebuggerBreakpointList::retrieve(const QString& filePath, int \
line) +{
+  BreakpointList_t::iterator it;
+  BreakpointList_t::iterator end = m_breakpointList->end();
+
+  for(it = m_breakpointList->begin(); it != end; ++it)
+  {
+    if(((*it)->filePath() == filePath) &&
+        ((*it)->line()    == line))
+    {
+      return (*it);
+    }
+  }
+  return 0;
+}
+
 void DebuggerBreakpointList::clear()
 {
   BreakpointList_t::iterator it;
Index: components/debugger/debuggerbreakpointlist.h
===================================================================
RCS file: /home/kde/kdewebdev/quanta/components/debugger/debuggerbreakpointlist.h,v
retrieving revision 1.2
diff -u -3 -p -u -p -r1.2 debuggerbreakpointlist.h
--- components/debugger/debuggerbreakpointlist.h	20 May 2004 12:47:18 -0000	1.2
+++ components/debugger/debuggerbreakpointlist.h	23 Feb 2005 15:22:39 -0000
@@ -32,12 +32,14 @@ class DebuggerBreakpointList
     ~DebuggerBreakpointList();
 
     void add(DebuggerBreakpoint*);
-    int remove(DebuggerBreakpoint*);
+    void remove(DebuggerBreakpoint*);
     //int remove(QString filePath, int line);
     void clear();
     bool exists(DebuggerBreakpoint*);
     //bool exists(QString filePath, int line);
 
+    DebuggerBreakpoint* retrieve(const QString& filePath, int line);
+
     void rewind();
     DebuggerBreakpoint* next();
 
Index: components/debugger/debuggermanager.cpp
===================================================================
RCS file: /home/kde/kdewebdev/quanta/components/debugger/debuggermanager.cpp,v
retrieving revision 1.29
diff -u -3 -p -u -p -r1.29 debuggermanager.cpp
--- components/debugger/debuggermanager.cpp	31 Jan 2005 06:18:41 -0000	1.29
+++ components/debugger/debuggermanager.cpp	23 Feb 2005 15:22:39 -0000
@@ -461,6 +461,13 @@ void DebuggerManager::fileOpened(const Q
     }
   }
 
+  //lets keep the eye on toggling bp's through the editor margin
+  ::Document* qdoc = ViewManager::ref()->isOpened(file)->document();
+  if(qdoc)
+  {
+    connectBreakpointSignals(qdoc);
+  }
+
   // Also, if we have a debug-session, let the debugger know...
   if(m_client)
     m_client->fileOpened(file);
@@ -536,6 +543,8 @@ void DebuggerManager::setMark(const QStr
     ::Document* qdoc = ViewManager::ref()->isOpened(filename)->document();
     if(qdoc)
     {
+      disconnectBreakpointSignals(qdoc);
+
       KTextEditor::Document* doc = qdoc->doc();
       if(doc)
       {
@@ -548,10 +557,29 @@ void DebuggerManager::setMark(const QStr
             markIf->removeMark(line, mark);
         }
       }
+      connectBreakpointSignals(qdoc);
     }
   }
 }
 
+void DebuggerManager::connectBreakpointSignals(Document* qdoc)
+{
+  connect(qdoc, SIGNAL(breakpointMarked(Document*, int)),
+    this, SLOT(slotBreakpointMarked(Document*, int)));
+
+  connect(qdoc, SIGNAL(breakpointUnmarked(Document*, int)),
+    this, SLOT(slotBreakpointUnmarked(Document*, int)));
+}
+
+void DebuggerManager::disconnectBreakpointSignals(Document* qdoc)
+{
+  disconnect(qdoc, SIGNAL(breakpointMarked(Document*, int)),
+    this, SLOT(slotBreakpointMarked(Document*, int)));
+
+  disconnect(qdoc, SIGNAL(breakpointUnmarked(Document*, int)),
+    this, SLOT(slotBreakpointUnmarked(Document*, int)));
+}
+
 // Show a status message and optionally put it on the log
 bool DebuggerManager::showStatus(const QString& a_message, bool log)
 {
@@ -612,4 +640,28 @@ DebuggerBreakpoint *DebuggerManager::new
   return new DebuggerBreakpoint();
 }
 
+void DebuggerManager::slotBreakpointMarked(Document* qdoc, int line)
+{
+  DebuggerBreakpoint* br = new DebuggerBreakpoint(qdoc->url().prettyURL(0, \
KURL::StripFileProtocol), line); +  m_breakpointList->add(br);
+  if(m_client && m_client->isActive())
+  {
+    m_client->addBreakpoint(br);
+  }
+}
+
+void DebuggerManager::slotBreakpointUnmarked(Document* qdoc, int line)
+{
+  QString filePath = qdoc->url().prettyURL(0, KURL::StripFileProtocol);
+
+  DebuggerBreakpoint* br = m_breakpointList->retrieve(filePath, line);
+
+  if(m_client && m_client->isActive())
+  {
+    m_client->removeBreakpoint(br);
+  }
+
+  m_breakpointList->remove(br);
+}
+
 #include "debuggermanager.moc"
Index: components/debugger/debuggermanager.h
===================================================================
RCS file: /home/kde/kdewebdev/quanta/components/debugger/debuggermanager.h,v
retrieving revision 1.16
diff -u -3 -p -u -p -r1.16 debuggermanager.h
--- components/debugger/debuggermanager.h	10 Jan 2005 16:22:02 -0000	1.16
+++ components/debugger/debuggermanager.h	23 Feb 2005 15:22:40 -0000
@@ -28,6 +28,7 @@ class DebuggerUI;
 class DebuggerVariable;
 class DebuggerBreakpoint;
 class PathMapper;
+class Document;
 
 class DebuggerManager : public QObject
 {
@@ -44,6 +45,10 @@ class DebuggerManager : public QObject
     // Internal help functions
     void initActions();
     void initClientActions();
+
+    void connectBreakpointSignals(Document*);
+    void disconnectBreakpointSignals(Document*);
+
     QString m_currentFile;
     long m_currentLine;
 
@@ -102,6 +107,10 @@ class DebuggerManager : public QObject
     // Initiation
     void slotNewProjectLoaded(const QString &, const KURL &, const KURL &);
 
+  private slots:
+    void slotBreakpointMarked(Document*, int);
+    void slotBreakpointUnmarked(Document*, int);
+
   signals:
     void hideSplash();
 };
Index: src/document.cpp
===================================================================
RCS file: /home/kde/kdewebdev/quanta/src/document.cpp,v
retrieving revision 1.367
diff -u -3 -p -u -p -r1.367 document.cpp
--- src/document.cpp	22 Feb 2005 13:30:28 -0000	1.367
+++ src/document.cpp	23 Feb 2005 15:22:44 -0000
@@ -146,11 +146,11 @@ Document::Document(KTextEditor::Document
   a = m_view->actionCollection()->action("view_border");
   if (a)
     a->setShortcut(Qt::SHIFT + Qt::Key_F9);
-  
+
   a = m_view->actionCollection()->action("view_folding_markers");
   if (a)
     a->setShortcut(Qt::SHIFT + Qt::Key_F11);
-  
+
   KActionMenu *bookmarkAction = \
dynamic_cast<KActionMenu*>(m_view->actionCollection()->action( "bookmarks" ));  if \
(bookmarkAction)  {
@@ -158,7 +158,7 @@ Document::Document(KTextEditor::Document
     //kdDebug(24000) << "Bookmarks found!" << endl;
     //bookmarkAction->insert(quantaApp->actionCollection()->action( "file_quit" ));
   }
- 
+
   editIf = dynamic_cast<KTextEditor::EditInterface *>(m_doc);
   editIfExt = dynamic_cast<KTextEditor::EditInterfaceExt *>(m_doc);
   selectionIf = dynamic_cast<KTextEditor::SelectionInterface *>(m_doc);
@@ -178,7 +178,7 @@ Document::Document(KTextEditor::Document
 
   // FIXME: This is allows user to set breakpoints and bookmarks by clicking or \
rightclicking on the icon border. However, it needs some additional code to  // work \
                for breakpoints and has been disabled to prevent confusion.
-  //iface->setMarksUserChangable(KTextEditor::MarkInterface::markType01 + \
KTextEditor::MarkInterface::markType02); +  \
iface->setMarksUserChangable(KTextEditor::MarkInterface::markType01 + \
KTextEditor::MarkInterface::markType02);  
   tempFile = 0;
   m_tempFileName = QString::null;
@@ -208,6 +208,8 @@ Document::Document(KTextEditor::Document
   connect(m_view, SIGNAL(gotFocus(Kate::View*)), SIGNAL(editorGotFocus()));
 
   connect(fileWatcher, SIGNAL(dirty(const QString&)), SLOT(slotFileDirty(const \
QString&))); +
+  connect(m_doc, SIGNAL(marksChanged()), this, SLOT(slotMarksChanged()));
 }
 
 Document::~Document()
@@ -371,10 +373,10 @@ void Document::selectText(int x1, int y1
 
 void Document::replaceSelected(const QString &s)
 {
-  if (selectionIf) 
+  if (selectionIf)
   {
     unsigned int line, col;
-    
+
     viewCursorIf->cursorPositionReal(&line, &col);
     reparseEnabled = false;
     selectionIf->removeSelectedText();
@@ -1384,12 +1386,12 @@ QValueList<KTextEditor::CompletionEntry>
 {
   QValueList<KTextEditor::CompletionEntry> *completions = 0L;
   QMap<QString, KTextEditor::CompletionEntry> completionMap;
-      
+
   //first search for entities defined in the document
   const DTDStruct *dtdDTD = DTDs::ref()->find("dtd");
   if (dtdDTD)
   {
-    StructTreeGroup group;    
+    StructTreeGroup group;
     for (uint j = 0; j < dtdDTD->structTreeGroups.count(); j++)
     {
       group = dtdDTD->structTreeGroups[j];
@@ -1410,10 +1412,10 @@ QValueList<KTextEditor::CompletionEntry>
       }
     }
   }
-  
+
   if (!completions)
     completions = new QValueList<KTextEditor::CompletionEntry>();
-  
+
   KTextEditor::CompletionEntry completion;
   completion.type = "charCompletion";
   //add the entities from the tag files
@@ -1433,7 +1435,7 @@ QValueList<KTextEditor::CompletionEntry>
       }
     }
   }
-  
+
   QValueList<KTextEditor::CompletionEntry> *completions2 = new \
QValueList<KTextEditor::CompletionEntry>();  for (QMap<QString, \
KTextEditor::CompletionEntry>::ConstIterator it = completionMap.constBegin(); it != \
completionMap.constEnd(); ++it)  {
@@ -1457,7 +1459,7 @@ QValueList<KTextEditor::CompletionEntry>
       completions->append( completion );
     }
   }
-    
+
   return completions;
 }
 
@@ -1612,7 +1614,7 @@ bool Document::scriptAutoCompletion(int 
  if (s[i] == completionDTD->tagSeparator)
  {
   while (i > 0 && s[i] != completionDTD->tagAutoCompleteAfter)
-    i--;  
+    i--;
   s = s.left(i + 1);
  }
 
@@ -1686,9 +1688,9 @@ bool Document::scriptAutoCompletion(int 
      }
    }
  }
- if ( !handled && !argHintVisible && 
-      (completionRequested || 
-       (s[i] == completionDTD->tagAutoCompleteAfter && (insertedString == " " || \
insertedString[0] == completionDTD->tagAutoCompleteAfter)) ||  + if ( !handled && \
!argHintVisible && +      (completionRequested ||
+       (s[i] == completionDTD->tagAutoCompleteAfter && (insertedString == " " || \
insertedString[0] == completionDTD->tagAutoCompleteAfter)) ||  \
completionDTD->tagAutoCompleteAfter == '\1' || \
(!completionDTD->memberAutoCompleteAfter.pattern().isEmpty() && \
completionDTD->memberAutoCompleteAfter.searchRev(s) != -1))  )
  {
@@ -1847,7 +1849,7 @@ void Document::codeCompletionRequested()
   completionRequested = true;
   completionInProgress = false;
   argHintVisible = false;
-  hintRequested = false; 
+  hintRequested = false;
   handleCodeCompletion();
   completionRequested = false;
 }
@@ -1909,7 +1911,7 @@ void Document::codeCompletionHintRequest
 //    int pos = textLine.findRev("(");
 //    int pos2 = textLine.findRev(")");
     //if (pos > pos2 )
-    hintRequested = true; 
+    hintRequested = true;
     scriptAutoCompletion(line, col - 1, "");
   }
   completionRequested = false;
@@ -2828,6 +2830,76 @@ void Document::slotFileDirty(const QStri
   }
 }
 
+void Document::slotMarksChanged()
+{
+  QPtrList<KTextEditor::Mark> marks = markIf->marks();
+
+  QValueList<KTextEditor::Mark>::iterator it;
+  KTextEditor::Mark* mark;
+
+  //delete all modified/removed marks
+  bool found = false;
+  for (it = m_breakpointMarks.begin(); it != m_breakpointMarks.end(); ++it)
+  {
+    //see if this mark was removed
+    for (mark = marks.first(); mark; mark = marks.next())
+    {
+      //skip if is not a breakpoint mark
+      if(!((*it).type & KTextEditor::MarkInterface::markType02))
+      {
+        continue;
+      }
+
+      if (mark->line == (*it).line)
+      {
+        found = true;
+        break;
+      }
+    }
+
+    //mark doesn't exists anymore, inform everyone
+    if (!found)
+    {
+      emit breakpointUnmarked(this, (*it).line);
+    }
+
+    found = false;
+  }
+
+  //inform everyone about new/modified breakpoints
+  found = false;
+  for (mark = marks.first(); mark; mark = marks.next())
+  {
+    //skip if is not a breakpoint mark
+    if(!(mark->type & KTextEditor::MarkInterface::markType02))
+    {
+      continue;
+    }
+
+    for (it = m_breakpointMarks.begin(); it != m_breakpointMarks.end(); ++it)
+    {
+      if ((*it).line == mark->line)
+      {
+        found = true;
+        break;
+      }
+    }
+
+    if (!found)
+    {
+      emit breakpointMarked(this, mark->line);
+    }
+    found = false;
+  }
+
+  //load the new marks
+  m_breakpointMarks.clear();
+  for (mark = marks.first(); mark; mark = marks.next())
+  {
+    m_breakpointMarks.append(*mark);
+  }
+}
+
 void Document::resetDTEPs()
 {
   m_DTEPList.clear();
Index: src/document.h
===================================================================
RCS file: /home/kde/kdewebdev/quanta/src/document.h,v
retrieving revision 1.127
diff -u -3 -p -u -p -r1.127 document.h
--- src/document.h	19 Feb 2005 13:08:34 -0000	1.127
+++ src/document.h	23 Feb 2005 15:22:45 -0000
@@ -56,6 +56,7 @@ namespace KTextEditor
   class SelectionInterfaceExt;
   class View;
   class ViewCursorInterface;
+  class Mark;
 }
 
 class Document : public QWidget{
@@ -237,7 +238,11 @@ signals:
   void editorGotFocus();
   void openingFailed(const KURL &url);
   void openingCompleted(const KURL &url);
-  
+
+  void breakpointMarked(Document*, int);
+  void breakpointUnmarked(Document*, int);
+
+
 private slots:
   void slotReplaceChar();
   void slotOpeningCompleted();
@@ -245,6 +250,7 @@ private slots:
   /** Called when a file on the disk has changed. */
   void slotFileDirty(const QString& fileName);
 
+  void slotMarksChanged();
 private:
 
   QString untitledUrl;
@@ -284,6 +290,8 @@ private:
   int m_lastLine, m_lastCol;
   QValueList<KTextEditor::CompletionEntry>* m_lastCompletionList;
 
+  QValueList<KTextEditor::Mark> m_breakpointMarks;
+
   /** Get list of possibile variable name completions */
   QValueList<KTextEditor::CompletionEntry>* getGroupCompletions(Node *node, const \
StructTreeGroup& groupName, int line, int col);  /** Get list of possibile tag name \
completions */



_______________________________________________
quanta-devel mailing list
quanta-devel@kde.org
https://mail.kde.org/mailman/listinfo/quanta-devel


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

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