From d7a0d026b5986eedaadb875a685a4ba497f21d0f Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 31 Jul 2000 20:40:25 +0000 Subject: [PATCH] Added a Recent Executables menu. --- kdbg/dbgmainwnd.cpp | 28 ++++++++++++- kdbg/dbgmainwnd.h | 4 ++ kdbg/mainwndbase.cpp | 108 ++++++++++++++++++++++++++++++++++++--------------- kdbg/mainwndbase.h | 9 +++++ 4 files changed, 117 insertions(+), 32 deletions(-) diff --git a/kdbg/dbgmainwnd.cpp b/kdbg/dbgmainwnd.cpp index a463223..fe076bb 100644 --- a/kdbg/dbgmainwnd.cpp +++ b/kdbg/dbgmainwnd.cpp @@ -61,6 +61,8 @@ DebuggerMainWnd::DebuggerMainWnd(const char* name) : dw7->setCaption(i18n("Threads")); m_threads = new ThreadList(dw7, "threads"); + m_menuRecentExecutables = new QPopupMenu(); + initMenu(); initToolbar(); @@ -135,7 +137,8 @@ DebuggerMainWnd::DebuggerMainWnd(const char* name) : restoreSettings(kapp->getConfig()); -// dockManager->activate(); + connect(m_menuRecentExecutables, SIGNAL(activated(int)), SLOT(slotRecentExec(int))); + fillRecentExecMenu(); updateUI(); m_bpTable->updateUI(); @@ -165,6 +168,7 @@ void DebuggerMainWnd::initMenu() m_menuFile->insertItem(i18n("&Reload Source"), ID_FILE_RELOAD); m_menuFile->insertSeparator(); m_menuFile->insertItem(i18n("&Executable..."), ID_FILE_EXECUTABLE); + m_menuFile->insertItem(i18n("Recent E&xecutables"), m_menuRecentExecutables); m_menuFile->insertItem(i18n("&Settings..."), ID_FILE_PROG_SETTINGS); m_menuFile->insertItem(i18n("&Core dump..."), ID_FILE_COREFILE); m_menuFile->insertSeparator(); @@ -415,6 +419,7 @@ void DebuggerMainWnd::menuCallback(int item) else if (item == ID_FILE_EXECUTABLE) { // special: this may have changed m_lastDirectory m_filesWindow->setExtraDirectory(m_lastDirectory); + fillRecentExecMenu(); } else { // start timer to move window into background switch (item) { @@ -739,6 +744,27 @@ void DebuggerMainWnd::slotBackTimer() ::XLowerWindow(x11Display(), winId()); } +void DebuggerMainWnd::slotRecentExec(int item) +{ + if (item >= 0 && item < int(m_recentExecList.count())) { + QString exe = m_recentExecList.at(item); + if (debugProgramInteractive(exe)) { + addRecentExec(exe); + } else { + removeRecentExec(exe); + } + fillRecentExecMenu(); + } +} + +void DebuggerMainWnd::fillRecentExecMenu() +{ + m_menuRecentExecutables->clear(); + for (uint i = 0; i < m_recentExecList.count(); i++) { + m_menuRecentExecutables->insertItem(m_recentExecList.at(i)); + } +} + QString DebuggerMainWnd::makeSourceFilter() { QString f; diff --git a/kdbg/dbgmainwnd.h b/kdbg/dbgmainwnd.h index eb24d77..4b550a2 100644 --- a/kdbg/dbgmainwnd.h +++ b/kdbg/dbgmainwnd.h @@ -58,6 +58,8 @@ protected: QPopupMenu* m_menuBrkpt; QPopupMenu* m_menuWindow; + QPopupMenu* m_menuRecentExecutables; + QTimer m_backTimer; protected: @@ -77,6 +79,7 @@ protected: void intoBackground(); QString makeSourceFilter(); + void fillRecentExecMenu(); signals: void forwardMenuCallback(int item); @@ -99,6 +102,7 @@ public slots: void slotTermEmuExited(); void slotProgramStopped(); void slotBackTimer(); + void slotRecentExec(int item); }; #endif // DBGMAINWND_H diff --git a/kdbg/mainwndbase.cpp b/kdbg/mainwndbase.cpp index 3db8e19..bb96b5b 100644 --- a/kdbg/mainwndbase.cpp +++ b/kdbg/mainwndbase.cpp @@ -43,6 +43,8 @@ #include /* getpid, unlink etc. */ #endif +#define MAX_RECENT_FILES 4 + KStdAccel* keys = 0; @@ -139,6 +141,7 @@ DebuggerMainWndBase::DebuggerMainWndBase() : m_debugger(0) { m_statusActive = i18n("active"); + m_recentExecList.setAutoDelete(true); } DebuggerMainWndBase::~DebuggerMainWndBase() @@ -210,6 +213,8 @@ const char PreferencesGroup[] = "Preferences"; const char PopForeground[] = "PopForeground"; const char BackTimeout[] = "BackTimeout"; const char TabWidth[] = "TabWidth"; +const char FilesGroup[] = "Files"; +const char RecentExecutables[] = "RecentExecutables"; const char SourceFileFilter[] = "SourceFileFilter"; const char HeaderFileFilter[] = "HeaderFileFilter"; @@ -231,6 +236,9 @@ void DebuggerMainWndBase::saveSettings(KConfig* config) config->writeEntry(TabWidth, m_tabWidth); config->writeEntry(SourceFileFilter, m_sourceFilter); config->writeEntry(HeaderFileFilter, m_headerFilter); + + config->setGroup(FilesGroup); + config->writeEntry(RecentExecutables, m_recentExecList, ','); } void DebuggerMainWndBase::restoreSettings(KConfig* config) @@ -257,6 +265,9 @@ void DebuggerMainWndBase::restoreSettings(KConfig* config) m_tabWidth = config->readNumEntry(TabWidth, 0); m_sourceFilter = config->readEntry(SourceFileFilter, m_sourceFilter); m_headerFilter = config->readEntry(HeaderFileFilter, m_headerFilter); + + config->setGroup(FilesGroup); + config->readListEntry(RecentExecutables, m_recentExecList,','); } bool DebuggerMainWndBase::debugProgram(const QString& executable) @@ -304,37 +315,8 @@ bool DebuggerMainWndBase::handleCommand(int item) if (executable.isEmpty()) return true; - // check the file name - QFileInfo fi(executable); - m_lastDirectory = fi.dirPath(true); - - if (!fi.isFile()) { - QString msgFmt = i18n("`%s' is not a file or does not exist"); - SIZED_QString(msg, msgFmt.length() + executable.length() + 20); -#if QT_VERSION < 200 - msg.sprintf(msgFmt, executable.data()); - KMsgBox::message(dbgMainWnd(), kapp->appName(), - msg, - KMsgBox::STOP, - i18n("OK")); -#else - msg.sprintf(msgFmt, executable.latin1()); - KMessageBox::sorry(dbgMainWnd(), msg); -#endif - return true; - } - - if (!m_debugger->debugProgram(executable)) { - QString msg = i18n("Could not start the debugger process.\n" - "Please shut down KDbg and resolve the problem."); -#if QT_VERSION < 200 - KMsgBox::message(dbgMainWnd(), kapp->appName(), - msg, - KMsgBox::STOP, - i18n("OK")); -#else - KMessageBox::sorry(dbgMainWnd(), msg); -#endif + if (debugProgramInteractive(executable)) { + addRecentExec(executable); } } return true; @@ -728,5 +710,69 @@ void DebuggerMainWndBase::setDebuggerCmdStr(const QString& cmd) } } +void DebuggerMainWndBase::addRecentExec(const QString& executable) +{ + int pos = m_recentExecList.find(executable); + if (pos != 0) { + // move to top + if (pos > 0) + m_recentExecList.remove(pos); + // else entry is new + + // insert on top + m_recentExecList.insert(0, executable); + } // else pos == 0, which means we dont need to change the list + + // shorten list + while (m_recentExecList.count() > MAX_RECENT_FILES) { + m_recentExecList.remove(MAX_RECENT_FILES); + } +} + +void DebuggerMainWndBase::removeRecentExec(const QString& executable) +{ + int pos = m_recentExecList.find(executable); + if (pos >= 0) { + m_recentExecList.remove(pos); + } +} + +bool DebuggerMainWndBase::debugProgramInteractive(const QString& executable) +{ + // check the file name + QFileInfo fi(executable); + m_lastDirectory = fi.dirPath(true); + + if (!fi.isFile()) { + QString msgFmt = i18n("`%s' is not a file or does not exist"); + SIZED_QString(msg, msgFmt.length() + executable.length() + 20); +#if QT_VERSION < 200 + msg.sprintf(msgFmt, executable.data()); + KMsgBox::message(dbgMainWnd(), kapp->appName(), + msg, + KMsgBox::STOP, + i18n("OK")); +#else + msg.sprintf(msgFmt, executable.latin1()); + KMessageBox::sorry(dbgMainWnd(), msg); +#endif + return false; + } + + if (!m_debugger->debugProgram(executable)) { + QString msg = i18n("Could not start the debugger process.\n" + "Please shut down KDbg and resolve the problem."); +#if QT_VERSION < 200 + KMsgBox::message(dbgMainWnd(), kapp->appName(), + msg, + KMsgBox::STOP, + i18n("OK")); +#else + KMessageBox::sorry(dbgMainWnd(), msg); +#endif + } + return true; +} + #include "mainwndbase.moc" diff --git a/kdbg/mainwndbase.h b/kdbg/mainwndbase.h index d679d4b..e516ff4 100644 --- a/kdbg/mainwndbase.h +++ b/kdbg/mainwndbase.h @@ -84,6 +84,12 @@ public: QWidget* parent); /** invokes the global options dialog */ virtual void doGlobalOptions(); + /** add recent executable; moves it to top of list if present */ + void addRecentExec(const QString& executable); + /** remove recent executable */ + void removeRecentExec(const QString& executable); + /** start a new session; error popups appear on errors */ + bool debugProgramInteractive(const QString& executable); protected: // settings @@ -126,6 +132,9 @@ protected: QString m_sourceFilter; QString m_headerFilter; + // recent execs in File menu + QStrList m_recentExecList; + // the debugger proper QString m_debuggerCmdStr; KDebugger* m_debugger; -- 2.11.4.GIT