Mercurial > hg > octave-lyh
comparison gui/src/MainWindow.cpp @ 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 | 79c9a6d06590 |
children | 06abf71d9083 |
comparison
equal
deleted
inserted
replaced
14699:0bab96aeb995 | 14700:7623bece76df |
---|---|
129 MainWindow::noticeSettings () | 129 MainWindow::noticeSettings () |
130 { | 130 { |
131 // Set terminal font: | 131 // Set terminal font: |
132 QSettings *settings = ResourceManager::instance ()->settings (); | 132 QSettings *settings = ResourceManager::instance ()->settings (); |
133 QFont font = QFont(); | 133 QFont font = QFont(); |
134 //font.setStyleHint(QFont::TypeWriter); | |
135 font.setFamily(settings->value("terminal/fontName").toString()); | 134 font.setFamily(settings->value("terminal/fontName").toString()); |
136 font.setPointSize(settings->value("terminal/fontSize").toInt ()); | 135 font.setPointSize(settings->value("terminal/fontSize").toInt ()); |
137 m_terminal->setTerminalFont(font); | 136 m_terminal->setTerminalFont(font); |
138 } | 137 } |
139 | 138 |
140 void | 139 void |
141 MainWindow::prepareForQuit () | 140 MainWindow::prepareForQuit () |
142 { | 141 { |
143 writeSettings (); | 142 writeSettings (); |
143 } | |
144 | |
145 void | |
146 MainWindow::resetWindows () | |
147 { | |
148 // TODO: Implement. | |
149 } | |
150 | |
151 void | |
152 MainWindow::updateCurrentWorkingDirectory (QString directory) | |
153 { | |
154 if(m_currentDirectoryComboBox->findText (directory) < 0) | |
155 { | |
156 if (m_currentDirectoryComboBox->count () > 31) | |
157 { | |
158 m_currentDirectoryComboBox->removeItem (0); | |
159 } | |
160 m_currentDirectoryComboBox->addItem (directory); | |
161 int index = m_currentDirectoryComboBox->findText (directory); | |
162 m_currentDirectoryComboBox->setCurrentIndex (index); | |
163 } | |
164 } | |
165 | |
166 void | |
167 MainWindow::changeCurrentWorkingDirectory () | |
168 { | |
169 QString selectedDirectory = | |
170 QFileDialog::getExistingDirectory(this, tr ("Set working direcotry")); | |
171 | |
172 if (!selectedDirectory.isEmpty ()) | |
173 { | |
174 m_terminal->sendText (QString ("cd \'%1\'\n").arg (selectedDirectory)); | |
175 m_terminal->setFocus (); | |
176 } | |
177 } | |
178 | |
179 void | |
180 MainWindow::changeCurrentWorkingDirectory (QString directory) | |
181 { | |
182 m_terminal->sendText (QString ("cd \'%1\'\n").arg (directory)); | |
183 m_terminal->setFocus (); | |
184 } | |
185 | |
186 void | |
187 MainWindow::currentWorkingDirectoryUp () | |
188 { | |
189 m_terminal->sendText ("cd ..\n"); | |
190 m_terminal->setFocus (); | |
144 } | 191 } |
145 | 192 |
146 void | 193 void |
147 MainWindow::showAboutOctave () | 194 MainWindow::showAboutOctave () |
148 { | 195 { |
211 m_historyDockWidget->setStatusTip (tr ("Browse and search the command history.")); | 258 m_historyDockWidget->setStatusTip (tr ("Browse and search the command history.")); |
212 m_filesDockWidget = new FilesDockWidget (this); | 259 m_filesDockWidget = new FilesDockWidget (this); |
213 m_filesDockWidget->setStatusTip (tr ("Browse your files.")); | 260 m_filesDockWidget->setStatusTip (tr ("Browse your files.")); |
214 m_statusBar = new QStatusBar (this); | 261 m_statusBar = new QStatusBar (this); |
215 | 262 |
216 m_currentDirectoryLineEdit = new QLineEdit (QDir::currentPath (), this); | 263 m_currentDirectoryComboBox = new QComboBox (this); |
217 m_currentDirectoryLineEdit->setFixedWidth (300); | 264 m_currentDirectoryComboBox->setFixedWidth (300); |
265 m_currentDirectoryComboBox->setEditable (true); | |
266 m_currentDirectoryComboBox->setInsertPolicy (QComboBox::InsertAtTop); | |
267 m_currentDirectoryComboBox->setMaxVisibleItems (14); | |
218 | 268 |
219 m_currentDirectoryToolButton = new QToolButton (this); | 269 m_currentDirectoryToolButton = new QToolButton (this); |
220 m_currentDirectoryToolButton->setIcon (style->standardIcon (QStyle::SP_DirOpenIcon)); | 270 m_currentDirectoryToolButton->setIcon (style->standardIcon (QStyle::SP_DirOpenIcon)); |
221 | 271 |
222 m_currentDirectoryUpToolButton = new QToolButton (this); | 272 m_currentDirectoryUpToolButton = new QToolButton (this); |
223 m_currentDirectoryUpToolButton->setIcon (style->standardIcon (QStyle::SP_FileDialogToParent)); | 273 m_currentDirectoryUpToolButton->setIcon (style->standardIcon (QStyle::SP_FileDialogToParent)); |
224 | 274 |
225 // Octave Terminal subwindow. | 275 // Octave Terminal subwindow. |
226 m_terminal = new QTerminal(this); | 276 m_terminal = new QTerminal (this); |
227 m_terminal->setObjectName ("OctaveTerminal"); | 277 m_terminal->setObjectName ("OctaveTerminal"); |
228 m_terminalDockWidget = new TerminalDockWidget (m_terminal, this); | 278 m_terminalDockWidget = new TerminalDockWidget (m_terminal, this); |
229 | 279 |
230 QWidget *dummyWidget = new QWidget (); | 280 QWidget *dummyWidget = new QWidget (); |
231 dummyWidget->setObjectName ("CentralDummyWidget"); | 281 dummyWidget->setObjectName ("CentralDummyWidget"); |
294 QAction *showFileBrowserAction = windowMenu->addAction (tr ("Current Directory")); | 344 QAction *showFileBrowserAction = windowMenu->addAction (tr ("Current Directory")); |
295 showFileBrowserAction->setCheckable (true); | 345 showFileBrowserAction->setCheckable (true); |
296 QAction *showEditorAction = windowMenu->addAction (tr ("Editor")); | 346 QAction *showEditorAction = windowMenu->addAction (tr ("Editor")); |
297 showEditorAction->setCheckable (true); | 347 showEditorAction->setCheckable (true); |
298 | 348 |
349 windowMenu->addSeparator (); | |
350 QAction *resetWindowsAction = windowMenu->addAction (tr ("Reset Windows")); | |
351 | |
299 // Help menu | 352 // Help menu |
300 QMenu *helpMenu = menuBar ()->addMenu (tr ("&Help")); | 353 QMenu *helpMenu = menuBar ()->addMenu (tr ("&Help")); |
301 QAction *reportBugAction = helpMenu->addAction (tr ("Report Bug")); | 354 QAction *reportBugAction = helpMenu->addAction (tr ("Report Bug")); |
302 QAction *agoraAction = helpMenu->addAction (tr ("Visit Agora")); | 355 QAction *agoraAction = helpMenu->addAction (tr ("Visit Agora")); |
303 QAction *octaveForgeAction = helpMenu->addAction (tr ("Visit Octave Forge")); | 356 QAction *octaveForgeAction = helpMenu->addAction (tr ("Visit Octave Forge")); |
314 mainToolBar->addAction (pasteAction); | 367 mainToolBar->addAction (pasteAction); |
315 mainToolBar->addAction (undoAction); | 368 mainToolBar->addAction (undoAction); |
316 mainToolBar->addAction (redoAction); | 369 mainToolBar->addAction (redoAction); |
317 mainToolBar->addSeparator (); | 370 mainToolBar->addSeparator (); |
318 mainToolBar->addWidget (new QLabel (tr ("Current Directory:"))); | 371 mainToolBar->addWidget (new QLabel (tr ("Current Directory:"))); |
319 mainToolBar->addWidget (m_currentDirectoryLineEdit); | 372 mainToolBar->addWidget (m_currentDirectoryComboBox); |
320 mainToolBar->addWidget (m_currentDirectoryToolButton); | 373 mainToolBar->addWidget (m_currentDirectoryToolButton); |
321 mainToolBar->addWidget (m_currentDirectoryUpToolButton); | 374 mainToolBar->addWidget (m_currentDirectoryUpToolButton); |
322 | 375 |
323 connect (qApp, SIGNAL(aboutToQuit ()), this, SLOT (prepareForQuit ())); | 376 connect (qApp, SIGNAL(aboutToQuit ()), this, SLOT (prepareForQuit ())); |
324 | 377 |
339 connect (m_historyDockWidget, SIGNAL (activeChanged (bool)), showHistoryAction, SLOT (setChecked (bool))); | 392 connect (m_historyDockWidget, SIGNAL (activeChanged (bool)), showHistoryAction, SLOT (setChecked (bool))); |
340 connect (showFileBrowserAction, SIGNAL (toggled (bool)), m_filesDockWidget, SLOT (setShown (bool))); | 393 connect (showFileBrowserAction, SIGNAL (toggled (bool)), m_filesDockWidget, SLOT (setShown (bool))); |
341 connect (m_filesDockWidget, SIGNAL (activeChanged (bool)), showFileBrowserAction, SLOT (setChecked (bool))); | 394 connect (m_filesDockWidget, SIGNAL (activeChanged (bool)), showFileBrowserAction, SLOT (setChecked (bool))); |
342 connect (showEditorAction, SIGNAL (toggled (bool)), m_fileEditor, SLOT (setShown (bool))); | 395 connect (showEditorAction, SIGNAL (toggled (bool)), m_fileEditor, SLOT (setShown (bool))); |
343 connect (m_fileEditor, SIGNAL (activeChanged (bool)), showEditorAction, SLOT (setChecked (bool))); | 396 connect (m_fileEditor, SIGNAL (activeChanged (bool)), showEditorAction, SLOT (setChecked (bool))); |
344 | 397 connect (resetWindowsAction, SIGNAL (triggered ()), this, SLOT (resetWindows ())); |
345 //connect (this, SIGNAL (settingsChanged ()), m_workspaceView, SLOT (noticeSettings ())); | 398 //connect (this, SIGNAL (settingsChanged ()), m_workspaceView, SLOT (noticeSettings ())); |
346 //connect (this, SIGNAL (settingsChanged ()), m_historyDockWidget, SLOT (noticeSettings ())); | 399 //connect (this, SIGNAL (settingsChanged ()), m_historyDockWidget, SLOT (noticeSettings ())); |
347 connect (this, SIGNAL (settingsChanged ()), m_filesDockWidget, SLOT (noticeSettings ())); | 400 connect (this, SIGNAL (settingsChanged ()), m_filesDockWidget, SLOT (noticeSettings ())); |
348 connect (this, SIGNAL (settingsChanged ()), this, SLOT (noticeSettings ())); | 401 connect (this, SIGNAL (settingsChanged ()), this, SLOT (noticeSettings ())); |
349 | 402 |
352 connect (m_historyDockWidget, SIGNAL (commandDoubleClicked (QString)), this, SLOT (handleCommandDoubleClicked (QString))); | 405 connect (m_historyDockWidget, SIGNAL (commandDoubleClicked (QString)), this, SLOT (handleCommandDoubleClicked (QString))); |
353 connect (saveWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleSaveWorkspaceRequest ())); | 406 connect (saveWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleSaveWorkspaceRequest ())); |
354 connect (loadWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleLoadWorkspaceRequest ())); | 407 connect (loadWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleLoadWorkspaceRequest ())); |
355 connect (clearWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleClearWorkspaceRequest ())); | 408 connect (clearWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleClearWorkspaceRequest ())); |
356 | 409 |
410 connect (m_currentDirectoryToolButton, SIGNAL (clicked ()), | |
411 this, SLOT (changeCurrentWorkingDirectory ())); | |
412 connect (m_currentDirectoryUpToolButton, SIGNAL (clicked ()), | |
413 this, SLOT(currentWorkingDirectoryUp())); | |
357 connect (copyAction, SIGNAL (triggered()), m_terminal, SLOT(copyClipboard ())); | 414 connect (copyAction, SIGNAL (triggered()), m_terminal, SLOT(copyClipboard ())); |
358 connect (pasteAction, SIGNAL (triggered()), m_terminal, SLOT(pasteClipboard ())); | 415 connect (pasteAction, SIGNAL (triggered()), m_terminal, SLOT(pasteClipboard ())); |
416 | |
417 connect (OctaveLink::instance (), SIGNAL (workingDirectoryChanged (QString)), | |
418 this, SLOT (updateCurrentWorkingDirectory (QString))); | |
419 connect (m_currentDirectoryComboBox, SIGNAL (activated (QString)), | |
420 this, SLOT (changeCurrentWorkingDirectory (QString))); | |
421 | |
359 setWindowTitle ("Octave"); | 422 setWindowTitle ("Octave"); |
360 | 423 |
361 setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks); | 424 setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks); |
362 | 425 |
363 addDockWidget (Qt::LeftDockWidgetArea, m_workspaceView); | 426 addDockWidget (Qt::LeftDockWidgetArea, m_workspaceView); |