Mercurial > hg > octave-lyh
comparison gui/src/editor/FileEditor.cpp @ 14690:ca733a66be7a gui
Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
* MainWindow: Simplified opening file request calls.
* FileEditor: Added new slot that closes tabs without and index and made FileEditorTabs connect to it.
* FileEditorTab: Added QFileSystemWatcher and fixed bug with setting modified status on m_modified. Implemented message boxes for the cases that a file has been removed, renamed und modified from outside.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Fri, 25 May 2012 23:56:31 +0200 |
parents | 66ff321cb62e |
children |
comparison
equal
deleted
inserted
replaced
14689:dd19de736ee4 | 14690:ca733a66be7a |
---|---|
73 { | 73 { |
74 FileEditorTab *fileEditorTab = new FileEditorTab (this); | 74 FileEditorTab *fileEditorTab = new FileEditorTab (this); |
75 if (fileEditorTab) | 75 if (fileEditorTab) |
76 { | 76 { |
77 addFileEditorTab (fileEditorTab); | 77 addFileEditorTab (fileEditorTab); |
78 fileEditorTab->openFile (); | 78 if (!fileEditorTab->openFile ()) |
79 { | |
80 // If no file was loaded, remove the tab again. | |
81 m_tabWidget->removeTab (m_tabWidget->indexOf (fileEditorTab)); | |
82 } | |
79 } | 83 } |
80 } | 84 } |
81 | 85 |
82 void | 86 void |
83 FileEditor::requestOpenFile (QString fileName) | 87 FileEditor::requestOpenFile (QString fileName) |
84 { | 88 { |
89 if (!isVisible ()) | |
90 { | |
91 show (); | |
92 } | |
93 | |
85 FileEditorTab *fileEditorTab = new FileEditorTab (this); | 94 FileEditorTab *fileEditorTab = new FileEditorTab (this); |
86 if (fileEditorTab) | 95 if (fileEditorTab) |
87 { | 96 { |
88 addFileEditorTab (fileEditorTab); | 97 addFileEditorTab (fileEditorTab); |
89 fileEditorTab->loadFile (fileName); | 98 fileEditorTab->loadFile (fileName); |
230 delete fileEditorTab; | 239 delete fileEditorTab; |
231 } | 240 } |
232 } | 241 } |
233 | 242 |
234 void | 243 void |
244 FileEditor::handleTabCloseRequest () | |
245 { | |
246 FileEditorTab *fileEditorTab = dynamic_cast <FileEditorTab*> (sender ()); | |
247 if (fileEditorTab) | |
248 if (fileEditorTab->close ()) | |
249 { | |
250 m_tabWidget->removeTab (m_tabWidget->indexOf (fileEditorTab)); | |
251 delete fileEditorTab; | |
252 } | |
253 } | |
254 | |
255 void | |
235 FileEditor::activeTabChanged (int index) | 256 FileEditor::activeTabChanged (int index) |
236 { | 257 { |
237 Q_UNUSED (index); | 258 Q_UNUSED (index); |
238 handleEditorStateChanged (); | 259 handleEditorStateChanged (); |
239 } | 260 } |
259 | 280 |
260 m_menuBar = new QMenuBar (widget); | 281 m_menuBar = new QMenuBar (widget); |
261 m_toolBar = new QToolBar (widget); | 282 m_toolBar = new QToolBar (widget); |
262 m_tabWidget = new QTabWidget (widget); | 283 m_tabWidget = new QTabWidget (widget); |
263 m_tabWidget->setTabsClosable (true); | 284 m_tabWidget->setTabsClosable (true); |
264 //m_longTitle = settings->value ("editor/longWindowTitle",true).toBool (); | |
265 | 285 |
266 // Theme icons with QStyle icons as fallback | 286 // Theme icons with QStyle icons as fallback |
267 QAction *newAction = new QAction ( | 287 QAction *newAction = new QAction ( |
268 QIcon::fromTheme("document-new",style->standardIcon (QStyle::SP_FileIcon)), | 288 QIcon::fromTheme("document-new",style->standardIcon (QStyle::SP_FileIcon)), |
269 tr("&New File"), m_toolBar); | 289 tr("&New File"), m_toolBar); |
436 m_tabWidget->addTab (fileEditorTab, ""); | 456 m_tabWidget->addTab (fileEditorTab, ""); |
437 connect (fileEditorTab, SIGNAL (fileNameChanged(QString)), | 457 connect (fileEditorTab, SIGNAL (fileNameChanged(QString)), |
438 this, SLOT(handleFileNameChanged(QString))); | 458 this, SLOT(handleFileNameChanged(QString))); |
439 connect (fileEditorTab, SIGNAL (editorStateChanged ()), | 459 connect (fileEditorTab, SIGNAL (editorStateChanged ()), |
440 this, SLOT (handleEditorStateChanged ())); | 460 this, SLOT (handleEditorStateChanged ())); |
461 connect (fileEditorTab, SIGNAL (closeRequest ()), | |
462 this, SLOT (handleTabCloseRequest ())); | |
441 m_tabWidget->setCurrentWidget (fileEditorTab); | 463 m_tabWidget->setCurrentWidget (fileEditorTab); |
442 } | 464 } |
443 | 465 |
444 FileEditorTab * | 466 FileEditorTab * |
445 FileEditor::activeEditorTab () | 467 FileEditor::activeEditorTab () |