From fc78ae272ba38e4374b775fa9fa608e09d41ae0a Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Mon, 11 May 2009 13:21:59 +0200
Subject: [PATCH] debugger: use short paths by default for setting breakpoints

---
 src/plugins/debugger/breakhandler.cpp | 24 +++++++++++++++++++++++-
 src/plugins/debugger/breakhandler.h   |  1 +
 src/plugins/debugger/breakwindow.cpp  |  8 ++++++++
 src/plugins/debugger/gdbengine.cpp    | 23 ++++++-----------------
 4 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp
index 7629b0ff087..07fd6c4b5be 100644
--- a/src/plugins/debugger/breakhandler.cpp
+++ b/src/plugins/debugger/breakhandler.cpp
@@ -154,6 +154,13 @@ BreakpointData::BreakpointData(BreakHandler *handler)
     marker = 0;
     markerLineNumber = 0;
     bpMultiple = false;
+//#if defined(Q_OS_MAC)
+//    // full names do not work on Mac/MI
+    useFullPath = false; 
+//#else
+//    //where = m_manager->shortName(data->fileName);
+//    useFullPath = true; 
+//#endif
 }
 
 BreakpointData::~BreakpointData()
@@ -326,6 +333,8 @@ void BreakHandler::saveBreakpoints()
             map["ignorecount"] = data->ignoreCount;
         if (!data->enabled)
             map["disabled"] = "1";
+        if (data->useFullPath)
+            map["usefullpath"] = "1";
         list.append(map);
     }
     setSessionValueRequested("Breakpoints", list);
@@ -347,6 +356,7 @@ void BreakHandler::loadBreakpoints()
         data->ignoreCount = map["ignorecount"].toString();
         data->funcName = map["funcname"].toString();
         data->enabled = !map["disabled"].toInt();
+        data->useFullPath = bool(map["usefullpath"].toInt());
         data->markerFileName = data->fileName;
         data->markerLineNumber = data->lineNumber.toInt();
         append(data);
@@ -427,8 +437,13 @@ QVariant BreakHandler::data(const QModelIndex &mi, int role) const
                 str = QFileInfo(str).fileName();
                 //if (data->bpMultiple && str.isEmpty() && !data->markerFileName.isEmpty())
                 //    str = data->markerFileName;
-                return str.isEmpty() ? empty : str;
+                str = str.isEmpty() ? empty : str;
+                if (data->useFullPath)
+                    str = "/.../" + str; 
+                return str;
             }
+            if (role == Qt::UserRole)
+                return data->useFullPath;
             break;
         case 3:
             if (role == Qt::DisplayRole) {
@@ -480,6 +495,13 @@ bool BreakHandler::setData(const QModelIndex &mi, const QVariant &value, int rol
             }
             return true;
         }
+        case 2: {
+            if (data->useFullPath != value.toBool()) {
+                data->useFullPath = value.toBool();
+                dataChanged(mi, mi);
+            }
+            return true;
+        }
         case 4: {
             QString val = value.toString();
             if (val != data->condition) {
diff --git a/src/plugins/debugger/breakhandler.h b/src/plugins/debugger/breakhandler.h
index f4f7470ef58..4c8a9203ee1 100644
--- a/src/plugins/debugger/breakhandler.h
+++ b/src/plugins/debugger/breakhandler.h
@@ -78,6 +78,7 @@ public:
     QString ignoreCount;    // ignore count associated with breakpoint
     QString lineNumber;     // line in source file
     QString funcName;       // name of containing function
+    bool useFullPath;       // should we use the full path when setting the bp?
 
     // this is what gdb produced in response
     QString bpNumber;       // breakpoint number assigned by the debugger engine
diff --git a/src/plugins/debugger/breakwindow.cpp b/src/plugins/debugger/breakwindow.cpp
index 0f4fe90d6d2..6e5f3a6226d 100644
--- a/src/plugins/debugger/breakwindow.cpp
+++ b/src/plugins/debugger/breakwindow.cpp
@@ -82,6 +82,7 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
     const QModelIndex index = indexAt(ev->pos());
     const bool indexIsValid = index.isValid();
     const QModelIndex index0 = index.sibling(index.row(), 0);
+    const QModelIndex index2 = index.sibling(index.row(), 2);
     QAction *act0 = new QAction(tr("Delete breakpoint"), &menu);
     act0->setEnabled(indexIsValid);
     QAction *act1 = new QAction(tr("Adjust column widths to contents"), &menu);
@@ -94,10 +95,14 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
     bool enabled = indexIsValid && model()->data(index0, Qt::UserRole).toBool();
     QString str = enabled ? tr("Disable breakpoint") : tr("Enable breakpoint");
     QAction *act5 = new QAction(str, &menu);
+    bool fullpath = indexIsValid && model()->data(index2, Qt::UserRole).toBool();
+    QString str1 = fullpath ? tr("Use short path") : tr("Use full path");
+    QAction *act6 = new QAction(str1, &menu);
 
     menu.addAction(act0);
     menu.addAction(act3);
     menu.addAction(act5);
+    menu.addAction(act6);
     menu.addSeparator();
     menu.addAction(act1);
     menu.addAction(act2);
@@ -120,6 +125,9 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
     else if (act == act5) {
         model()->setData(index0, !enabled);
         emit breakpointSynchronizationRequested();
+    } else if (act == act6) {
+        model()->setData(index2, !fullpath);
+        emit breakpointSynchronizationRequested();
     }
 }
 
diff --git a/src/plugins/debugger/gdbengine.cpp b/src/plugins/debugger/gdbengine.cpp
index 4dc8bb1192a..6cd9d9bc20b 100644
--- a/src/plugins/debugger/gdbengine.cpp
+++ b/src/plugins/debugger/gdbengine.cpp
@@ -1821,23 +1821,12 @@ void GdbEngine::sendInsertBreakpoint(int index)
     const BreakpointData *data = qq->breakHandler()->at(index);
     QString where;
     if (data->funcName.isEmpty()) {
-#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
-        where = data->fileName;
-#endif
-#if defined(Q_OS_MAC)
-        // full names do not work on Mac/MI
-        QFileInfo fi(data->fileName);
-        where = fi.fileName();
-        //where = fi.absoluteFilePath();
-#endif
-#if defined(Q_OS_WIN)
-        // full names do not work on Mac/MI
-        QFileInfo fi(data->fileName);
-        where = fi.fileName();
-    //where = m_manager->shortName(data->fileName);
-        //if (where.isEmpty())
-        //    where = data->fileName;
-#endif
+        if (data->useFullPath) {
+            where = data->fileName;
+        } else {
+            QFileInfo fi(data->fileName);
+            where = fi.fileName();
+        }
         // The argument is simply a C-quoted version of the argument to the
         // non-MI "break" command, including the "original" quoting it wants.
         where = _("\"\\\"") + GdbMi::escapeCString(where) + _("\\\":") + data->lineNumber + _c('"');
-- 
GitLab