1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "sourcefileswindow.h"
35 #include "debuggeractions.h"
36 #include "debuggerconstants.h"
37 #include "debuggercore.h"
38 #include "debuggerengine.h"
40 #include <utils/qtcassert.h>
41 #include <utils/savedaction.h>
43 #include <QtCore/QDebug>
44 #include <QtCore/QFileInfo>
46 #include <QtGui/QHeaderView>
47 #include <QtGui/QMenu>
48 #include <QtGui/QResizeEvent>
51 //////////////////////////////////////////////////////////////////
55 //////////////////////////////////////////////////////////////////
60 static DebuggerEngine *currentEngine()
62 return debuggerCore()->currentEngine();
65 SourceFilesWindow::SourceFilesWindow(QWidget *parent)
68 QAction *act = debuggerCore()->action(UseAlternatingRowColors);
70 setAttribute(Qt::WA_MacShowFocusRect, false);
71 setFrameStyle(QFrame::NoFrame);
72 setWindowTitle(tr("Source Files"));
73 setSortingEnabled(true);
74 setAlternatingRowColors(act->isChecked());
75 setRootIsDecorated(false);
76 setIconSize(QSize(10, 10));
77 //header()->setDefaultAlignment(Qt::AlignLeft);
79 connect(this, SIGNAL(activated(QModelIndex)),
80 SLOT(sourceFileActivated(QModelIndex)));
81 connect(act, SIGNAL(toggled(bool)),
82 SLOT(setAlternatingRowColorsHelper(bool)));
85 void SourceFilesWindow::sourceFileActivated(const QModelIndex &index)
87 DebuggerEngine *engine = currentEngine();
88 QTC_ASSERT(engine, return);
89 engine->gotoLocation(index.data().toString());
92 void SourceFilesWindow::contextMenuEvent(QContextMenuEvent *ev)
94 DebuggerEngine *engine = currentEngine();
95 QTC_ASSERT(engine, return);
96 QModelIndex index = indexAt(ev->pos());
97 index = index.sibling(index.row(), 0);
98 QString name = index.data().toString();
99 bool engineActionsEnabled = engine->debuggerActionsEnabled();
102 QAction *act1 = new QAction(tr("Reload Data"), &menu);
104 act1->setEnabled(engineActionsEnabled);
105 //act1->setCheckable(true);
107 if (name.isEmpty()) {
108 act2 = new QAction(tr("Open File"), &menu);
109 act2->setEnabled(false);
111 act2 = new QAction(tr("Open File \"%1\"'").arg(name), &menu);
112 act2->setEnabled(true);
115 menu.addAction(act1);
116 menu.addAction(act2);
118 menu.addAction(debuggerCore()->action(SettingsDialog));
120 QAction *act = menu.exec(ev->globalPos());
123 engine->reloadSourceFiles();
124 else if (act == act2)
125 engine->gotoLocation(name);
128 } // namespace Internal
129 } // namespace Debugger