Mercurial > hg > octave-lyh
changeset 14700:7623bece76df gui
Implemented logic for current directory bar.
* MainWindow: Changed current working directory line edit to combo box. Added various signals and slots.
* OctaveLink: Added signal that will be emitted whenever a current directory change occurs.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Tue, 29 May 2012 19:08:05 +0200 |
parents | 0bab96aeb995 |
children | 06abf71d9083 |
files | gui/src/MainWindow.cpp gui/src/MainWindow.h gui/src/backend/OctaveLink.cpp gui/src/backend/OctaveLink.h gui/src/backend/OctaveMainThread.cpp |
diffstat | 5 files changed, 97 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -131,7 +131,6 @@ // Set terminal font: QSettings *settings = ResourceManager::instance ()->settings (); QFont font = QFont(); - //font.setStyleHint(QFont::TypeWriter); font.setFamily(settings->value("terminal/fontName").toString()); font.setPointSize(settings->value("terminal/fontSize").toInt ()); m_terminal->setTerminalFont(font); @@ -144,6 +143,54 @@ } void +MainWindow::resetWindows () +{ + // TODO: Implement. +} + +void +MainWindow::updateCurrentWorkingDirectory (QString directory) +{ + if(m_currentDirectoryComboBox->findText (directory) < 0) + { + if (m_currentDirectoryComboBox->count () > 31) + { + m_currentDirectoryComboBox->removeItem (0); + } + m_currentDirectoryComboBox->addItem (directory); + int index = m_currentDirectoryComboBox->findText (directory); + m_currentDirectoryComboBox->setCurrentIndex (index); + } +} + +void +MainWindow::changeCurrentWorkingDirectory () +{ + QString selectedDirectory = + QFileDialog::getExistingDirectory(this, tr ("Set working direcotry")); + + if (!selectedDirectory.isEmpty ()) + { + m_terminal->sendText (QString ("cd \'%1\'\n").arg (selectedDirectory)); + m_terminal->setFocus (); + } +} + +void +MainWindow::changeCurrentWorkingDirectory (QString directory) +{ + m_terminal->sendText (QString ("cd \'%1\'\n").arg (directory)); + m_terminal->setFocus (); +} + +void +MainWindow::currentWorkingDirectoryUp () +{ + m_terminal->sendText ("cd ..\n"); + m_terminal->setFocus (); +} + +void MainWindow::showAboutOctave () { QString message = @@ -213,8 +260,11 @@ m_filesDockWidget->setStatusTip (tr ("Browse your files.")); m_statusBar = new QStatusBar (this); - m_currentDirectoryLineEdit = new QLineEdit (QDir::currentPath (), this); - m_currentDirectoryLineEdit->setFixedWidth (300); + m_currentDirectoryComboBox = new QComboBox (this); + m_currentDirectoryComboBox->setFixedWidth (300); + m_currentDirectoryComboBox->setEditable (true); + m_currentDirectoryComboBox->setInsertPolicy (QComboBox::InsertAtTop); + m_currentDirectoryComboBox->setMaxVisibleItems (14); m_currentDirectoryToolButton = new QToolButton (this); m_currentDirectoryToolButton->setIcon (style->standardIcon (QStyle::SP_DirOpenIcon)); @@ -223,7 +273,7 @@ m_currentDirectoryUpToolButton->setIcon (style->standardIcon (QStyle::SP_FileDialogToParent)); // Octave Terminal subwindow. - m_terminal = new QTerminal(this); + m_terminal = new QTerminal (this); m_terminal->setObjectName ("OctaveTerminal"); m_terminalDockWidget = new TerminalDockWidget (m_terminal, this); @@ -296,6 +346,9 @@ QAction *showEditorAction = windowMenu->addAction (tr ("Editor")); showEditorAction->setCheckable (true); + windowMenu->addSeparator (); + QAction *resetWindowsAction = windowMenu->addAction (tr ("Reset Windows")); + // Help menu QMenu *helpMenu = menuBar ()->addMenu (tr ("&Help")); QAction *reportBugAction = helpMenu->addAction (tr ("Report Bug")); @@ -316,7 +369,7 @@ mainToolBar->addAction (redoAction); mainToolBar->addSeparator (); mainToolBar->addWidget (new QLabel (tr ("Current Directory:"))); - mainToolBar->addWidget (m_currentDirectoryLineEdit); + mainToolBar->addWidget (m_currentDirectoryComboBox); mainToolBar->addWidget (m_currentDirectoryToolButton); mainToolBar->addWidget (m_currentDirectoryUpToolButton); @@ -341,7 +394,7 @@ connect (m_filesDockWidget, SIGNAL (activeChanged (bool)), showFileBrowserAction, SLOT (setChecked (bool))); connect (showEditorAction, SIGNAL (toggled (bool)), m_fileEditor, SLOT (setShown (bool))); connect (m_fileEditor, SIGNAL (activeChanged (bool)), showEditorAction, SLOT (setChecked (bool))); - + connect (resetWindowsAction, SIGNAL (triggered ()), this, SLOT (resetWindows ())); //connect (this, SIGNAL (settingsChanged ()), m_workspaceView, SLOT (noticeSettings ())); //connect (this, SIGNAL (settingsChanged ()), m_historyDockWidget, SLOT (noticeSettings ())); connect (this, SIGNAL (settingsChanged ()), m_filesDockWidget, SLOT (noticeSettings ())); @@ -354,8 +407,18 @@ connect (loadWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleLoadWorkspaceRequest ())); connect (clearWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleClearWorkspaceRequest ())); + connect (m_currentDirectoryToolButton, SIGNAL (clicked ()), + this, SLOT (changeCurrentWorkingDirectory ())); + connect (m_currentDirectoryUpToolButton, SIGNAL (clicked ()), + this, SLOT(currentWorkingDirectoryUp())); connect (copyAction, SIGNAL (triggered()), m_terminal, SLOT(copyClipboard ())); connect (pasteAction, SIGNAL (triggered()), m_terminal, SLOT(pasteClipboard ())); + + connect (OctaveLink::instance (), SIGNAL (workingDirectoryChanged (QString)), + this, SLOT (updateCurrentWorkingDirectory (QString))); + connect (m_currentDirectoryComboBox, SIGNAL (activated (QString)), + this, SLOT (changeCurrentWorkingDirectory (QString))); + setWindowTitle ("Octave"); setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks);
--- a/gui/src/MainWindow.h +++ b/gui/src/MainWindow.h @@ -29,6 +29,7 @@ #include <QMdiSubWindow> #include <QCloseEvent> #include <QToolButton> +#include <QComboBox> // Editor includes #include "FileEditorInterface.h" @@ -91,6 +92,11 @@ void showAboutOctave (); void noticeSettings (); void prepareForQuit (); + void resetWindows (); + void updateCurrentWorkingDirectory (QString directory); + void changeCurrentWorkingDirectory (); + void changeCurrentWorkingDirectory (QString directory); + void currentWorkingDirectoryUp (); protected: void closeEvent (QCloseEvent * closeEvent); @@ -113,7 +119,7 @@ // Toolbars. QStatusBar *m_statusBar; - QLineEdit *m_currentDirectoryLineEdit; + QComboBox *m_currentDirectoryComboBox; QToolButton *m_currentDirectoryToolButton; QToolButton *m_currentDirectoryUpToolButton;
--- a/gui/src/backend/OctaveLink.cpp +++ b/gui/src/backend/OctaveLink.cpp @@ -17,6 +17,7 @@ #include "OctaveLink.h" #include "load-path.h" +#include "oct-env.h" #include <QDir> #include <QApplication> @@ -24,7 +25,7 @@ { OctaveLink::instance ()->triggerUpdateHistoryModel (); OctaveLink::instance ()->buildSymbolInformation (); - QDir::setCurrent (load_path::get_command_line_path ().c_str ()); + OctaveLink::instance ()->updateCurrentWorkingDirectory (); return 0; } @@ -52,6 +53,7 @@ m_workspaceModel, SLOT (updateFromSymbolTable ())); _symbolInformationSemaphore = new QSemaphore (1); + _currentWorkingDirectory = ""; } OctaveLink::~OctaveLink () @@ -96,6 +98,18 @@ } void +OctaveLink::updateCurrentWorkingDirectory () +{ + QString _queriedWorkingDirectory = octave_env::get_current_directory ().c_str(); + if (_currentWorkingDirectory != _queriedWorkingDirectory) + { + _currentWorkingDirectory = _queriedWorkingDirectory; + QDir::setCurrent (_currentWorkingDirectory); + emit workingDirectoryChanged (_currentWorkingDirectory); + } +} + +void OctaveLink::acquireSymbolInformation () { _symbolInformationSemaphore->acquire (1);
--- a/gui/src/backend/OctaveLink.h +++ b/gui/src/backend/OctaveLink.h @@ -97,12 +97,16 @@ WorkspaceModel *workspaceModel (); void triggerUpdateHistoryModel (); + void updateCurrentWorkingDirectory (); void acquireSymbolInformation (); void releaseSymbolInformation (); void buildSymbolInformation (); const QList <SymbolInformation>& symbolInformation () const; +signals: + void workingDirectoryChanged (QString directory); + private: OctaveLink (); ~OctaveLink (); @@ -117,6 +121,7 @@ QSemaphore *_symbolInformationSemaphore; QList <SymbolInformation> _symbolInformation; + QString _currentWorkingDirectory; static OctaveLink m_singleton; }; #endif // OCTAVELINK_H