Quellcode durchsuchen

Let the KatePart save the files. Remove no longer used saveFileText.

git-svn-id: file:///var/svn/tigccpp/trunk@1024 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler vor 17 Jahren
Ursprung
Commit
c38b3f7534
4 geänderte Dateien mit 8 neuen und 81 gelöschten Zeilen
  1. 6 43
      ktigcc/mainform.cpp
  2. 2 31
      ktigcc/srcfilewin.cpp
  3. 0 6
      ktigcc/tpr.cpp
  4. 0 1
      ktigcc/tpr.h

+ 6 - 43
ktigcc/mainform.cpp

@@ -1758,6 +1758,9 @@ void *MainForm::createView(const QString &fileName, const QString &fileText, Q3L
   if (!fileText.isNull()) {
     SET_TEXT_SAFE(doc,fileText);
     doc->setModified(FALSE);
+// FIXME
+//  newView->document()->clearUndo();
+//  newView->document()->clearRedo();
   }
   // Create View object.
   KTextEditor::View *newView = (KTextEditor::View *) doc->createView(widgetStack);
@@ -1800,9 +1803,6 @@ void *MainForm::createView(const QString &fileName, const QString &fileText, Q3L
   connect(newView->document(),SIGNAL(selectionChanged()),this,SLOT(current_view_selectionChanged()));
   connect(newView->document(),SIGNAL(charactersInteractivelyInserted(int,int,const QString&)),this,SLOT(current_view_charactersInteractivelyInserted(int,int,const QString&)));
   newView->setContextMenu(te_popup);
-// FIXME
-//  newView->document()->clearUndo();
-//  newView->document()->clearRedo();
   newView->setCursorPosition(KTextEditor::Cursor(0,0));
   return newView;
 }
@@ -2229,7 +2229,7 @@ void MainForm::fileSave_save(Q3ListViewItem *theItem)
   }
   else {
     KDirWatch::self()->removeFile(theFile->fileName);
-    if (saveFileText(theFile->fileName,theFile->kateView->document()->text())) {
+    if (!theFile->kateView->document()->save()) {
       KMessageBox::error(this,QString("Can't save to \'%1\'").arg(theFile->text(0)));
       KDirWatch::self()->addFile(theFile->fileName);
     }
@@ -2275,30 +2275,12 @@ void MainForm::fileSave_saveAs(Q3ListViewItem *theItem)
   if (!theFile->fileName.isEmpty() && theFile->fileName[0]=='/')
     KDirWatch::self()->removeFile(theFile->fileName);
   if (IS_EDITABLE_CATEGORY(category)
-      ?saveFileText(saveFileName,theFile->kateView->document()->text())
+      ?!theFile->kateView->document()->saveAs(saveFileName)
       :copyFile(theFile->fileName,saveFileName)) {
     KMessageBox::error(this,QString("Can't save to \'%1\'").arg(saveFileName));
     if (IS_EDITABLE_CATEGORY(category) && !theFile->fileName.isEmpty() && theFile->fileName[0]=='/')
       KDirWatch::self()->addFile(theFile->fileName);
   } else {
-    if (IS_EDITABLE_CATEGORY(category) && saveFileName.compare(theFile->fileName)) {
-      // Update the file name for printing.
-      int line,col;
-      QString fileText=theFile->kateView->document()->text();
-      KTextEditor::HighlightingInterface *hliface
-        =qobject_cast<KTextEditor::HighlightingInterface*>(theFile->kateView->document());
-      QString hlMode=hliface->highlighting();
-      theFile->kateView->cursorPosition().position(line,col);
-      theFile->kateView->document()->setModified(FALSE);
-      if (theFile->kateView->document()->openStream("text/plain",saveFileName))
-        theFile->kateView->document()->closeStream();
-      SET_TEXT_SAFE(theFile->kateView->document(),fileText);
-// FIXME
-//      theFile->kateView->document()->clearUndo();
-//      theFile->kateView->document()->clearRedo();
-      hliface->setHighlighting(hlMode);
-      theFile->kateView->setCursorPosition(KTextEditor::Cursor(line,col));
-    }
     theFile->fileName=saveFileName;
     if (IS_EDITABLE_CATEGORY(category)) {
       KDirWatch::self()->addFile(saveFileName);
@@ -2348,32 +2330,13 @@ void MainForm::fileSave_loadList(Q3ListViewItem *category,void *fileListV,const
           || (IS_EDITABLE_CATEGORY(category)
               && (theFile->kateView->document()->isModified() || theFile->isNew))) {
         if (IS_EDITABLE_CATEGORY(category)
-            ?saveFileText(tmpPath.path(),theFile->kateView->document()->text())
+            ?!theFile->kateView->document()->saveAs(tmpPath.path())
             :copyFile(theFile->fileName,tmpPath.path())) {
           KMessageBox::error(this,QString("Can't save to \'%1\'").arg(tmpPath.path()));
           if (IS_EDITABLE_CATEGORY(category) && !theFile->fileName.isEmpty() && theFile->fileName[0]=='/')
             KDirWatch::self()->addFile(theFile->fileName);
         } else {
           QString saveFileName=tmpPath.path();
-          if (IS_EDITABLE_CATEGORY(category) && saveFileName.compare(theFile->fileName)) {
-            // Update the file name for printing.
-            int line,col;
-            QString fileText=theFile->kateView->document()->text();
-            KTextEditor::HighlightingInterface *hliface
-              =qobject_cast<KTextEditor::HighlightingInterface*>(
-                theFile->kateView->document());
-            QString hlMode=hliface->highlighting();
-            theFile->kateView->cursorPosition().position(line,col);
-            theFile->kateView->document()->setModified(FALSE);
-            if (theFile->kateView->document()->openStream("text/plain",saveFileName))
-              theFile->kateView->document()->closeStream();
-            SET_TEXT_SAFE(theFile->kateView->document(),fileText);
-// FIXME
-//            theFile->kateView->document()->clearUndo();
-//            theFile->kateView->document()->clearRedo();
-            hliface->setHighlighting(hlMode);
-            theFile->kateView->setCursorPosition(KTextEditor::Cursor(line,col));
-          }
           theFile->fileName=saveFileName;
           if (IS_EDITABLE_CATEGORY(category)) {
             KDirWatch::self()->addFile(theFile->fileName);

+ 2 - 31
ktigcc/srcfilewin.cpp

@@ -102,12 +102,6 @@ enum {TIGCCOpenProjectFileFilter,TIGCCAddFilesFilter};
 #define CURRENT_VIEW (THIS->kateView)
 #define HL_MODE ((THIS->hlEnabled && *(THIS->hlEnabled))?THIS->hlMode:"None")
 
-#define SET_TEXT_SAFE(doc,text) do { \
-    disableViewEvents=TRUE; \
-    (doc)->setText((text)); \
-    disableViewEvents=FALSE; \
-  } while(0)
-
 // For some reason, this flag is not in the public ConfigFlags enum.
 #define CF_REMOVE_TRAILING_DYN 0x4000000
 
@@ -455,9 +449,6 @@ void *SourceFileWindow::createView(const QString &fileName, const QString &hlMod
   connect(newView->document(),SIGNAL(selectionChanged()),this,SLOT(current_view_selectionChanged()));
   connect(newView->document(),SIGNAL(charactersInteractivelyInserted(int,int,const QString&)),this,SLOT(current_view_charactersInteractivelyInserted(int,int,const QString&)));
   newView->setContextMenu(THIS->te_popup);
-// FIXME
-//  newView->document()->clearUndo();
-//  newView->document()->clearRedo();
   newView->setCursorPosition(KTextEditor::Cursor(0,0));
   return newView;
 }
@@ -497,7 +488,7 @@ void SourceFileWindow::removeTrailingSpacesFromView(void *view)
 void SourceFileWindow::fileSave()
 {
   THIS->dirWatch->removeFile(THIS->fileName);
-  if (saveFileText(THIS->fileName,CURRENT_VIEW->document()->text())) {
+  if (!CURRENT_VIEW->document()->save()) {
     KMessageBox::error(this,QString("Can't save to \'%1\'").arg(THIS->fileName));
     THIS->dirWatch->addFile(THIS->fileName);
   } else {
@@ -520,30 +511,10 @@ void SourceFileWindow::fileSaveAs()
   if (saveFileName.isEmpty())
     return;
   THIS->dirWatch->removeFile(THIS->fileName);
-  if (saveFileText(saveFileName,CURRENT_VIEW->document()->text())) {
+  if (!CURRENT_VIEW->document()->saveAs(saveFileName)) {
     KMessageBox::error(this,QString("Can't save to \'%1\'").arg(saveFileName));
     THIS->dirWatch->addFile(THIS->fileName);
   } else {
-    if (saveFileName.compare(THIS->fileName)) {
-      // Update the file name for printing.
-      int line,col;
-      QString fileText=CURRENT_VIEW->document()->text();
-      KTextEditor::HighlightingInterface *hliface
-        =qobject_cast<KTextEditor::HighlightingInterface*>(CURRENT_VIEW->document());
-      QString hlMode=hliface->highlighting();
-      CURRENT_VIEW->cursorPosition().position(line,col);
-      CURRENT_VIEW->document()->setModified(FALSE);
-      if (CURRENT_VIEW->document()->openStream("text/plain",saveFileName))
-        CURRENT_VIEW->document()->closeStream();
-      SET_TEXT_SAFE(CURRENT_VIEW->document(),fileText);
-// FIXME
-//      CURRENT_VIEW->document()->clearUndo();
-//      CURRENT_VIEW->document()->clearRedo();
-      hliface->setHighlighting(hlMode);
-      CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(line,col));
-      // Update the caption
-      setCaption(caption().left(caption().find('-')+2)+saveFileName);
-    }
     THIS->fileName=saveFileName;
     THIS->dirWatch->addFile(saveFileName);
     removeTrailingSpacesFromView(CURRENT_VIEW);

+ 0 - 6
ktigcc/tpr.cpp

@@ -1060,12 +1060,6 @@ int saveAndSplitFileText(const char *fileName, const QString &fileText,
   return 0;
 }
 
-int saveFileText(const char *fileName,const QString &fileText)
-{
-  return saveAndSplitFileText(fileName,fileText,FALSE,FALSE,FALSE,QString::null,
-                              static_cast<LineStartList *>(NULL));
-}
-
 void kurlNewFileName(KUrl &dir,const QString &newFileName)
 {
   if (!newFileName.isEmpty() && newFileName[0]=='/')

+ 0 - 1
ktigcc/tpr.h

@@ -176,7 +176,6 @@ int saveAndSplitFileText(const char *fileName, const QString &fileText,
                          bool split, bool addCLineDirective,
                          bool addASMLineDirective, const QString &origFileName,
                          LineStartList *pLineStartList);
-int saveFileText(const char *fileName,const QString &fileText);
 
 void kurlNewFileName(KUrl &dir,const QString &newFileName);
 int checkFileName(const QString &fileName,const QStringList &fileNameList);