Browse Source

Adapt to new KatePart signal API: Document::charactersInteractivelyInserted -> View::textInserted
Remove unused fileText in SourceFileWindow::current_view_textInserted and SourceFileWindow::current_view_newLineHook.
Use first line instead of entire fileText to get first character in MainWindow::current_view_textInserted and MainWindow::current_view_newLineHook.


git-svn-id: file:///var/svn/tigccpp/trunk@1058 9552661e-59e3-4036-b4f2-dbe53926924f

kevinkofler 17 years ago
parent
commit
3c9cda6281
4 changed files with 78 additions and 65 deletions
  1. 42 38
      ktigcc/mainform.cpp
  2. 6 1
      ktigcc/mainform.h
  3. 24 25
      ktigcc/srcfilewin.cpp
  4. 6 1
      ktigcc/srcfilewin.h

+ 42 - 38
ktigcc/mainform.cpp

@@ -1813,10 +1813,11 @@ void *MainForm::createView(const QString &fileName, const QString &fileText, Q3L
     8
   );
   connect(newView,SIGNAL(cursorPositionChanged()),this,SLOT(current_view_cursorPositionChanged()));
+  connect(newView,SIGNAL(textInserted(KTextEditor::View*,const KTextEditor::Cursor&,const QString&)),
+          this,SLOT(current_view_textInserted(KTextEditor::View*,const KTextEditor::Cursor&,const QString&)));
   connect(newView->document(),SIGNAL(textChanged()),this,SLOT(current_view_textChanged()));
   connect(newView->document(),SIGNAL(undoChanged()),this,SLOT(current_view_undoChanged()));
   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);
   newView->setCursorPosition(KTextEditor::Cursor(0,0));
   return newView;
@@ -1906,10 +1907,11 @@ void MainForm::adoptSourceFile(void *srcFile)
     8
   );
   connect(newView,SIGNAL(cursorPositionChanged()),this,SLOT(current_view_cursorPositionChanged()));
+  connect(newView,SIGNAL(textInserted(KTextEditor::View*,const KTextEditor::Cursor&,const QString&)),
+          this,SLOT(current_view_textInserted(KTextEditor::View*,const KTextEditor::Cursor&,const QString&)));
   connect(newView->document(),SIGNAL(textChanged()),this,SLOT(current_view_textChanged()));
   connect(newView->document(),SIGNAL(undoChanged()),this,SLOT(current_view_undoChanged()));
   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);
   // Mark project dirty.
   projectIsDirty=TRUE;
@@ -6015,42 +6017,43 @@ void MainForm::current_view_selectionChanged()
   }
 }
 
-void MainForm::current_view_charactersInteractivelyInserted(int line, int col, const QString &characters)
+void MainForm::current_view_textInserted(KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text)
 {
-  if (CURRENT_VIEW) {
-    if (preferences.autoBlocks && characters=="{"
-        && col==CURRENT_VIEW->document()->lineLength(line)-1) {
-      KTextEditor::Document *doc=CURRENT_VIEW->document();
-      CATEGORY_OF(category,currentListItem);
-      QString fileText=doc->text();
-      // Only for C files.
-      if (category==cFilesListItem||category==qllFilesListItem
-          ||(category==hFilesListItem&&(fileText.isNull()||fileText.isEmpty()||(fileText[0]!='|'&&fileText[0]!=';')))) {
-        QString indent=doc->line(line);
-        // Only if the line was all whitespace, otherwise wait for Enter to be
-        // pressed (prevents annoying the user while typing a string or something).
-        if (indent.contains(QRegExp("^\\s*\\{$"))) {
-          indent=indent.remove('{');
-          QString cursorLine=indent+"\t";
-          doc->startEditing();
-          doc->insertLine(line+1,cursorLine);
-          doc->insertLine(line+2,indent+"}");
-          doc->endEditing();
-          CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(line+1,cursorLine.length()));
-        }
+  int line,col;
+  position.position(line,col);
+  if (preferences.autoBlocks && text=="{"
+      && col==view->document()->lineLength(line)-1) {
+    KTextEditor::Document *doc=view->document();
+    CATEGORY_OF(category,currentListItem);
+    QString firstLine=doc->line(0);
+    // Only for C files.
+    if (category==cFilesListItem||category==qllFilesListItem
+        || (category==hFilesListItem && !firstLine.isEmpty()
+            && firstLine[0]!='|' && firstLine[0]!=';')) {
+      QString indent=doc->line(line);
+      // Only if the line was all whitespace, otherwise wait for Enter to be
+      // pressed (prevents annoying the user while typing a string or something).
+      if (indent.contains(QRegExp("^\\s*\\{$"))) {
+        indent=indent.remove('{');
+        QString cursorLine=indent+"\t";
+        doc->startEditing();
+        doc->insertLine(line+1,cursorLine);
+        doc->insertLine(line+2,indent+"}");
+        doc->endEditing();
+        view->setCursorPosition(KTextEditor::Cursor(line+1,cursorLine.length()));
       }
     }
-    if (IS_FILE(currentListItem)
-        && CURRENT_VIEW==static_cast<ListViewFile *>(currentListItem)->kateView
-        && characters=="(") {
-      QString fileText=CURRENT_VIEW->document()->text();
-      CATEGORY_OF(category,currentListItem);
-      // Completion only operates on C files.
-      if (category==cFilesListItem || category==qllFilesListItem
-          || (category==hFilesListItem && !fileText.isEmpty()
-              && fileText[0]!='|' && fileText[0]!=';')) {
-        new ArgHintPopup(CURRENT_VIEW,pathInProject(currentListItem),this);
-      }
+  }
+  if (IS_FILE(currentListItem)
+      && view==static_cast<ListViewFile *>(currentListItem)->kateView
+      && text=="(") {
+    QString firstLine=view->document()->line(0);
+    CATEGORY_OF(category,currentListItem);
+    // Completion only operates on C files.
+    if (category==cFilesListItem || category==qllFilesListItem
+        || (category==hFilesListItem && !firstLine.isEmpty()
+            && firstLine[0]!='|' && firstLine[0]!=';')) {
+      new ArgHintPopup(view,pathInProject(currentListItem),this);
     }
   }
 }
@@ -6062,10 +6065,11 @@ void MainForm::current_view_newLineHook()
   KTextEditor::Document *doc=CURRENT_VIEW->document();
   if (preferences.autoBlocks && line && doc->line(line-1).endsWith("{")) {
     CATEGORY_OF(category,currentListItem);
-    QString fileText=doc->text();
+    QString firstLine=doc->line(0);
     // Only for C files.
-    if (category==cFilesListItem||category==qllFilesListItem
-        ||(category==hFilesListItem&&(fileText.isNull()||fileText.isEmpty()||(fileText[0]!='|'&&fileText[0]!=';')))) {
+    if (category==cFilesListItem || category==qllFilesListItem
+        || (category==hFilesListItem && !firstLine.isEmpty()
+            && firstLine[0]!='|' && firstLine[0]!=';')) {
       QString indent=doc->line(line-1);
       // Remove everything starting from the first non-whitespace character.
       indent=indent.remove(QRegExp("(?!\\s).*$"));

+ 6 - 1
ktigcc/mainform.h

@@ -24,6 +24,11 @@
 
 #include "tiemu.h"
 
+namespace KTextEditor {
+  class View;
+  class Cursor;
+}
+
 class MainForm : public QMainWindow, public Ui::MainForm
 {
     Q_OBJECT
@@ -143,7 +148,7 @@ public slots:
     virtual void current_view_textChanged();
     virtual void current_view_undoChanged();
     virtual void current_view_selectionChanged();
-    virtual void current_view_charactersInteractivelyInserted( int line, int col, const QString & characters );
+    virtual void current_view_textInserted(KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text);
     virtual void clipboard_dataChanged();
     virtual void fileTreeItemRenamed( Q3ListViewItem * item, const QString & newName, int col );
     virtual void KDirWatch_dirty( const QString & fileName );

+ 24 - 25
ktigcc/srcfilewin.cpp

@@ -459,10 +459,11 @@ void *SourceFileWindow::createView(const QString &fileName, const QString &hlMod
   }
   setTabWidth(newView,tabWidth);
   connect(newView,SIGNAL(cursorPositionChanged()),this,SLOT(current_view_cursorPositionChanged()));
+  connect(newView,SIGNAL(textInserted(KTextEditor::View*,const KTextEditor::Cursor&,const QString&)),
+          this,SLOT(current_view_textInserted(KTextEditor::View*,const KTextEditor::Cursor&,const QString&)));
   connect(newView->document(),SIGNAL(textChanged()),this,SLOT(current_view_textChanged()));
   connect(newView->document(),SIGNAL(undoChanged()),this,SLOT(current_view_undoChanged()));
   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);
   newView->setCursorPosition(KTextEditor::Cursor(0,0));
   return newView;
@@ -1235,33 +1236,32 @@ void SourceFileWindow::current_view_selectionChanged()
   }
 }
 
-void SourceFileWindow::current_view_charactersInteractivelyInserted(int line, int col, const QString &characters)
+void SourceFileWindow::current_view_textInserted(KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text)
 {
-  if (CURRENT_VIEW) {
-    if (preferences.autoBlocks && characters=="{"
-        && col==CURRENT_VIEW->document()->lineLength(line)-1) {
-      KTextEditor::Document *doc=CURRENT_VIEW->document();
-      QString fileText=doc->text();
-      // Only for C files.
-      if (THIS->isCFile) {
-        QString indent=doc->line(line);
-        // Only if the line was all whitespace, otherwise wait for Enter to be
-        // pressed (prevents annoying the user while typing a string or something).
-        if (indent.contains(QRegExp("^\\s*\\{$"))) {
-          indent=indent.remove('{');
-          QString cursorLine=indent+"\t";
-          doc->startEditing();
-          doc->insertLine(line+1,cursorLine);
-          doc->insertLine(line+2,indent+"}");
-          doc->endEditing();
-          CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(line+1,cursorLine.length()));
-        }
+  int line,col;
+  position.position(line,col);
+  if (preferences.autoBlocks && text=="{"
+      && col==view->document()->lineLength(line)-1) {
+    KTextEditor::Document *doc=view->document();
+    // Only for C files.
+    if (THIS->isCFile) {
+      QString indent=doc->line(line);
+      // Only if the line was all whitespace, otherwise wait for Enter to be
+      // pressed (prevents annoying the user while typing a string or something).
+      if (indent.contains(QRegExp("^\\s*\\{$"))) {
+        indent=indent.remove('{');
+        QString cursorLine=indent+"\t";
+        doc->startEditing();
+        doc->insertLine(line+1,cursorLine);
+        doc->insertLine(line+2,indent+"}");
+        doc->endEditing();
+        view->setCursorPosition(KTextEditor::Cursor(line+1,cursorLine.length()));
       }
     }
-    // Completion only operates on C files.
-    if (characters=="(" && THIS->isCFile)
-      new ArgHintPopup(CURRENT_VIEW,THIS->fileName,THIS->mainForm);
   }
+  // Completion only operates on C files.
+  if (text=="(" && THIS->isCFile)
+    new ArgHintPopup(view,THIS->fileName,THIS->mainForm);
 }
 
 void SourceFileWindow::current_view_newLineHook()
@@ -1270,7 +1270,6 @@ void SourceFileWindow::current_view_newLineHook()
   CURRENT_VIEW->cursorPosition().position(line,col);
   KTextEditor::Document *doc=CURRENT_VIEW->document();
   if (preferences.autoBlocks && line && doc->line(line-1).endsWith("{")) {
-    QString fileText=doc->text();
     // Only for C files.
     if (THIS->isCFile) {
       QString indent=doc->line(line-1);

+ 6 - 1
ktigcc/srcfilewin.h

@@ -22,6 +22,11 @@
 
 #include "ui_srcfilewin.h"
 
+namespace KTextEditor {
+  class View;
+  class Cursor;
+}
+
 class SourceFileWindow : public QMainWindow, public Ui::SourceFileWindow
 {
     Q_OBJECT
@@ -81,7 +86,7 @@ public slots:
     virtual void current_view_textChanged();
     virtual void current_view_undoChanged();
     virtual void current_view_selectionChanged();
-    virtual void current_view_charactersInteractivelyInserted( int line, int col, const QString & characters );
+    virtual void current_view_textInserted(KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text);
     virtual void clipboard_dataChanged();
     virtual void KDirWatch_dirty( const QString & fileName );
     virtual void completionPopup_closed();