diff 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
line wrap: on
line diff
--- a/gui/src/editor/FileEditor.cpp	Fri May 25 20:54:36 2012 +0200
+++ b/gui/src/editor/FileEditor.cpp	Fri May 25 23:56:31 2012 +0200
@@ -75,13 +75,22 @@
   if (fileEditorTab)
     {
       addFileEditorTab (fileEditorTab);
-      fileEditorTab->openFile ();
+      if (!fileEditorTab->openFile ())
+        {
+          // If no file was loaded, remove the tab again.
+          m_tabWidget->removeTab (m_tabWidget->indexOf (fileEditorTab));
+        }
     }
 }
 
 void
 FileEditor::requestOpenFile (QString fileName)
 {
+  if (!isVisible ())
+    {
+      show ();
+    }
+
   FileEditorTab *fileEditorTab = new FileEditorTab (this);
   if (fileEditorTab)
     {
@@ -232,6 +241,18 @@
 }
 
 void
+FileEditor::handleTabCloseRequest ()
+{
+  FileEditorTab *fileEditorTab = dynamic_cast <FileEditorTab*> (sender ());
+  if (fileEditorTab)
+    if (fileEditorTab->close ())
+      {
+        m_tabWidget->removeTab (m_tabWidget->indexOf (fileEditorTab));
+        delete fileEditorTab;
+      }
+}
+
+void
 FileEditor::activeTabChanged (int index)
 {
   Q_UNUSED (index);
@@ -261,7 +282,6 @@
   m_toolBar = new QToolBar (widget);
   m_tabWidget = new QTabWidget (widget);
   m_tabWidget->setTabsClosable (true);
-  //m_longTitle = settings->value ("editor/longWindowTitle",true).toBool ();
 
   // Theme icons with QStyle icons as fallback
   QAction *newAction = new QAction (
@@ -438,6 +458,8 @@
            this, SLOT(handleFileNameChanged(QString)));
   connect (fileEditorTab, SIGNAL (editorStateChanged ()),
            this, SLOT (handleEditorStateChanged ()));
+  connect (fileEditorTab, SIGNAL (closeRequest ()),
+           this, SLOT (handleTabCloseRequest ()));
   m_tabWidget->setCurrentWidget (fileEditorTab);
 }