Parcourir la source

Implement slot for KDirWatch: the reload prompt fully works now.

git-svn-id: file:///var/svn/tigccpp/trunk@460 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler il y a 18 ans
Parent
commit
a1853ab7a0
2 fichiers modifiés avec 52 ajouts et 1 suppressions
  1. 2 1
      ktigcc/mainform.ui
  2. 50 0
      ktigcc/mainform.ui.h

+ 2 - 1
ktigcc/mainform.ui

@@ -1523,6 +1523,7 @@
     <slot>fileSave()</slot>
     <slot>fileSaveAs()</slot>
     <slot>filePrint()</slot>
+    <slot>filePrintQuickly()</slot>
     <slot>filePreferences()</slot>
     <slot>editClear()</slot>
     <slot>editUndo()</slot>
@@ -1572,7 +1573,7 @@
     <slot>m_view_cursorPositionChanged()</slot>
     <slot>m_view_textChanged()</slot>
     <slot>fileTreeItemRenamed( QListViewItem * item, int col, const QString &amp; newName )</slot>
-    <slot>filePrintQuickly()</slot>
+    <slot>KDirWatch_dirty( const QString &amp; fileName )</slot>
 </slots>
 <functions>
     <function access="private" specifier="non virtual">clearProject()</function>

+ 50 - 0
ktigcc/mainform.ui.h

@@ -490,6 +490,9 @@ void MainForm::init()
   lastDirectory=TIGCCProjectDirectory;
   projectFileName="";
   projectIsDirty=FALSE;
+  connect(KDirWatch::self(),SIGNAL(created(const QString &)),this,SLOT(KDirWatch_dirty(const QString &)));
+  connect(KDirWatch::self(),SIGNAL(dirty(const QString &)),this,SLOT(KDirWatch_dirty(const QString &)));
+  KDirWatch::self()->startScan();
   pconfig->setGroup("Recent files");
   if (parg)
     openProject(parg);
@@ -2121,5 +2124,52 @@ void MainForm::closeEvent(QCloseEvent *e)
   }
 }
 
+void MainForm::KDirWatch_dirty(const QString &fileName)
+{
+  QListViewItem *item=rootListItem->firstChild(),*next;
+  QStringList allFiles;
+  while (item) {
+    if (IS_FOLDER(item)) {
+      next=item->firstChild();
+      if (next) {
+        item=next;
+        continue;
+      }
+    }
+    if (IS_FILE(item)) {
+      if (!fileName.compare(static_cast<ListViewFile *>(item)->fileName)) {
+        if (KMessageBox::questionYesNo(this,
+              QString("The file \'%1\' has been changed by another program. "
+                      "Do you want to reload it?").arg(fileName),"File Changed")
+              ==KMessageBox::Yes) {
+          QString fileText=loadFileText(fileName);
+          if (fileText.isNull()) {
+            KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
+            return;
+          }
+          if (item==currentListItem)
+            m_view->getDoc()->setText(fileText);
+          else
+            static_cast<ListViewFile *>(item)->textBuffer=fileText;
+        }
+        return;
+      }
+    }
+    next=item->nextSibling();
+    while (!next) {
+      next=item->parent();
+      if (next==rootListItem||!next) {
+        puts("Warning: KDirWatch_dirty called for file not in project tree");
+        return;
+      }
+      item=next;
+      next=item->nextSibling();
+    }
+    item=next;
+  }
+  puts("Warning: KDirWatch_dirty called for file not in project tree");
+  return;
+}
+
 // Yes, this is an ugly hack... Any better suggestions?
 #define QListView DnDListView