# HG changeset patch # User Jacob Dawid # Date 1311084854 -7200 # Node ID 35ecb6063c7b389e9f904b786593656367f7cccf # Parent bace956a37249c8e3d372c6323bb1d86572da059 Made the view connect with the history model. diff --git a/gui/src/OctaveLink.cpp b/gui/src/OctaveLink.cpp --- a/gui/src/OctaveLink.cpp +++ b/gui/src/OctaveLink.cpp @@ -28,10 +28,9 @@ OctaveLink::m_singleton; -OctaveLink::OctaveLink ():QObject (), m_previousHistoryLength (0) +OctaveLink::OctaveLink ():QObject () { m_symbolTableSemaphore = new QSemaphore (1); - m_historySemaphore = new QSemaphore (1); m_historyModel = new QStringListModel (this); } @@ -136,22 +135,21 @@ void OctaveLink::updateHistoryModel () { - // TODO: Use the following code to update the history model. - /* - int currentLen = command_history::length (); - if (currentLen != m_previousHistoryLength) + // Determine the client's (our) history length and the one of the server. + int clientHistoryLength = m_history.length (); + int serverHistoryLength = command_history::length (); + + // If were behind the server, iterate through all new entries and add them to our history. + if (clientHistoryLength < serverHistoryLength) { - m_historySemaphore->acquire (); - for (int i = m_previousHistoryLength; i < currentLen; i++) + for (int i = clientHistoryLength; i < serverHistoryLength; i++) { - QString entry = QString(command_history::get_entry (i).c_str()); - if (!entry.startsWith ("#")) - m_historyBuffer.append (entry); + m_history.insert (0, QString (command_history::get_entry (i).c_str ())); } - m_historySemaphore->release (); - m_previousHistoryLength = currentLen; } - */ + + // Update the model by setting the new history. + m_historyModel->setStringList (m_history); } QStringListModel * diff --git a/gui/src/OctaveLink.h b/gui/src/OctaveLink.h --- a/gui/src/OctaveLink.h +++ b/gui/src/OctaveLink.h @@ -138,9 +138,8 @@ /** History related member variables. */ QStringListModel *m_historyModel; - QSemaphore *m_historySemaphore; - QStringList m_historyBuffer; - int m_previousHistoryLength; + QStringList m_history; + static OctaveLink m_singleton; }; #endif // OCTAVELINK_H