Procházet zdrojové kódy

Allow disabling syntax highlighting from the preferences.

git-svn-id: file:///var/svn/tigccpp/trunk@791 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler před 18 roky
rodič
revize
a98a0a1506

+ 26 - 21
ktigcc/mainform.ui.h

@@ -550,13 +550,13 @@ class DnDListView : public KListView {
               for (i=0; i<cnt; i++) {
                 if (!static_cast<ListViewFile *>(currItem)->kateView->getDoc()->hlModeName(i).compare(
                     (destCategory==qllFilesListItem?
-                       "TIGCC Quill":
+                       QLL_HL_MODE:
                      (destCategory==sFilesListItem||(destCategory==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]=='|'))?
-                       "TIGCC GNU As":
+                       S_HL_MODE:
                      (destCategory==asmFilesListItem||(destCategory==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]==';'))?
-                       "TIGCC A68k":
+                       ASM_HL_MODE:
                      (destCategory==cFilesListItem||destCategory==hFilesListItem)?
-                       "TIGCC C":
+                       C_HL_MODE:
                      "None"))) break;
               }
               if (i==cnt) i=0;
@@ -1610,13 +1610,13 @@ void *MainForm::createView(const QString &fileName, const QString &fileText, QLi
   for (i=0; i<cnt; i++) {
     if (!newView->getDoc()->hlModeName(i).compare(
         (category==qllFilesListItem?
-           "TIGCC Quill":
+           QLL_HL_MODE:
          (category==sFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]=='|'))?
-           "TIGCC GNU As":
+           S_HL_MODE:
          (category==asmFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]==';'))?
-           "TIGCC A68k":
+           ASM_HL_MODE:
          (category==cFilesListItem||category==hFilesListItem)?
-           "TIGCC C":
+           C_HL_MODE:
          "None"))) break;
   }
   if (i==cnt) i=0;
@@ -1716,13 +1716,13 @@ void MainForm::adoptSourceFile(void *srcFile)
   for (i=0; i<cnt; i++) {
     if (!newView->getDoc()->hlModeName(i).compare(
         (category==qllFilesListItem?
-           "TIGCC Quill":
+           QLL_HL_MODE:
          (category==sFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]=='|'))?
-           "TIGCC GNU As":
+           S_HL_MODE:
          (category==asmFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]==';'))?
-           "TIGCC A68k":
+           ASM_HL_MODE:
          (category==cFilesListItem||category==hFilesListItem)?
-           "TIGCC C":
+           C_HL_MODE:
          "None"))) break;
   }
   if (i==cnt) i=0;
@@ -1924,11 +1924,16 @@ bool MainForm::openProject(const QString &fileName)
               0);
     
     new SourceFile(this,fileName,fileText,
-                   (category==qllFilesListItem)?"TIGCC Quill":
-                   (type==2)?"TIGCC GNU As":
-                   (type==3)?"TIGCC A68k":
-                   (type==1)?"TIGCC C":
-                    "None",category,(type==1),(type>1),category==txtFilesListItem);
+                   (category==qllFilesListItem)?QLL_ENABLED_HL_MODE:
+                   (type==2)?S_ENABLED_HL_MODE:
+                   (type==3)?ASM_ENABLED_HL_MODE:
+                   (type==1)?C_ENABLED_HL_MODE:
+                   "None",
+                   (category==qllFilesListItem)?&(preferences.synQll.enabled):
+                   (type==2)?&(preferences.synS.enabled):
+                   (type==3)?&(preferences.synAsm.enabled):
+                   (type==1)?&(preferences.synC.enabled):
+                   NULL,category,(type==1),(type>1),category==txtFilesListItem);
     return FALSE;
   }
 }
@@ -2387,13 +2392,13 @@ void MainForm::filePreferences()
           for (i=0; i<cnt; i++) {
             if (!kateView->getDoc()->hlModeName(i).compare(
                 (category==qllFilesListItem?
-                   "TIGCC Quill":
+                   QLL_HL_MODE:
                  (category==sFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]=='|'))?
-                   "TIGCC GNU As":
+                   S_HL_MODE:
                  (category==asmFilesListItem||(category==hFilesListItem&&!fileText.isNull()&&!fileText.isEmpty()&&fileText[0]==';'))?
-                   "TIGCC A68k":
+                   ASM_HL_MODE:
                  (category==cFilesListItem||category==hFilesListItem)?
-                   "TIGCC C":
+                   C_HL_MODE:
                  "None"))) break;
           }
           if (i==cnt) i=0;

+ 9 - 0
ktigcc/preferences.h

@@ -128,3 +128,12 @@ void savePreferences(void);
 int showPreferencesDialog(QWidget *parent, bool haveA68k, bool haveQuill);
 
 extern TIGCCPrefs preferences;
+
+#define C_ENABLED_HL_MODE ("TIGCC C")
+#define S_ENABLED_HL_MODE ("TIGCC GNU As")
+#define ASM_ENABLED_HL_MODE ("TIGCC A68k")
+#define QLL_ENABLED_HL_MODE ("TIGCC Quill")
+#define C_HL_MODE (preferences.synC.enabled?C_ENABLED_HL_MODE:"None")
+#define S_HL_MODE (preferences.synS.enabled?S_ENABLED_HL_MODE:"None")
+#define ASM_HL_MODE (preferences.synAsm.enabled?ASM_ENABLED_HL_MODE:"None")
+#define QLL_HL_MODE (preferences.synQll.enabled?QLL_ENABLED_HL_MODE:"None")

+ 7 - 0
ktigcc/preferencesdlg.ui

@@ -1172,6 +1172,12 @@
         <receiver>Preferences</receiver>
         <slot>syntaxListView_itemRenamed(QListViewItem*,const QString&amp;,int)</slot>
     </connection>
+    <connection>
+        <sender>syntaxEnabled</sender>
+        <signal>toggled(bool)</signal>
+        <receiver>Preferences</receiver>
+        <slot>syntaxEnabled_toggled(bool)</slot>
+    </connection>
 </connections>
 <includes>
     <include location="local" impldecl="in implementation">preferencesdlg.ui.h</include>
@@ -1183,6 +1189,7 @@
     <slot>bgColorChange_pressed()</slot>
     <slot>editorFontChange_pressed()</slot>
     <slot>syntaxLanguage_activated( int index )</slot>
+    <slot>syntaxEnabled_toggled( bool on )</slot>
     <slot>resetButton_clicked()</slot>
     <slot>numberColorButton_clicked()</slot>
     <slot>numberStyleButton_clicked()</slot>

+ 20 - 1
ktigcc/preferencesdlg.ui.h

@@ -260,6 +260,7 @@ void Preferences::syntaxLanguage_activated(int index)
     preferences.syn=&preferences.tempSynC;
   }
 
+  syntaxEnabled->setChecked(preferences.syn->enabled);
   QListViewItem *rootListItem=syntaxListView->firstChild();
   QListViewItem *item, *nextItem;
   QListViewItem *customStylesItem=rootListItem->firstChild();
@@ -286,6 +287,23 @@ void Preferences::syntaxLanguage_activated(int index)
   }
 }
 
+void Preferences::syntaxEnabled_toggled(bool on)
+{
+  preferences.syn->enabled=on;
+  resetButton->setEnabled(on);
+  numberColorButton->setEnabled(on);
+  numberStyleButton->setEnabled(on);
+  symbolColorButton->setEnabled(on);
+  symbolStyleButton->setEnabled(on);
+  parenthesisColorsButton->setEnabled(on);
+  parenthesisStyleButton->setEnabled(on);
+  syntaxListView->setEnabled(on);
+  newStyleButton->setEnabled(on);
+  newListButton->setEnabled(on);
+  QListViewItem *selectedItem=syntaxListView->selectedItem();
+  editButton->setEnabled(on&&selectedItem&&selectedItem->rtti()==0x716CC8);
+}
+
 void Preferences::resetButton_clicked()
 {
 
@@ -324,7 +342,8 @@ void Preferences::parenthesisStyleButton_clicked()
 void Preferences::syntaxListView_selectionChanged()
 {
   QListViewItem *selectedItem=syntaxListView->selectedItem();
-  editButton->setEnabled(selectedItem&&selectedItem->rtti()==0x716CC8);
+  editButton->setEnabled(syntaxEnabled->isChecked()
+                         && selectedItem && selectedItem->rtti()==0x716CC8);
 }
 
 #define unused_col col __attribute__((unused))

+ 5 - 2
ktigcc/srcfile.h

@@ -40,9 +40,11 @@ class FunctionDialog;
 
 struct SourceFile : public SourceFileWindow {
   SourceFile(MainForm *mainfrm, const QString &fn, const QString &ft,
-             const QString &hlm, void *cat, bool isc, bool isasm, bool istxt) :
+             const QString &hlm, const bool *hle, void *cat,
+             bool isc, bool isasm, bool istxt) :
     SourceFileWindow(), mainForm(mainfrm), fileName(fn), fileText(ft),
-    hlMode(hlm), category(cat), isCFile(isc), isASMFile(isasm), isTextFile(istxt)
+    hlMode(hlm), hlEnabled(hle), category(cat),
+    isCFile(isc), isASMFile(isasm), isTextFile(istxt)
   {
     initBase(); // We can do this only after initializing the variables here.
     show();
@@ -52,6 +54,7 @@ struct SourceFile : public SourceFileWindow {
   QString fileName;
   QString fileText;
   QString hlMode;
+  const bool *hlEnabled;
   void *category;
   bool isCFile;
   bool isASMFile;

+ 4 - 3
ktigcc/srcfilewin.ui.h

@@ -91,6 +91,7 @@ enum {TIGCCOpenProjectFileFilter,TIGCCAddFilesFilter};
 
 #define THIS (static_cast<SourceFile *>(this))
 #define CURRENT_VIEW (THIS->kateView)
+#define HL_MODE ((THIS->hlEnabled && *(THIS->hlEnabled))?THIS->hlMode:"None")
 
 #define LOAD_ICON(name) (QIconSet(KGlobal::iconLoader()->loadIcon((name),KIcon::Small),KGlobal::iconLoader()->loadIcon((name),KIcon::MainToolbar)))
 #define SYSICON(sysname,name) (preferences.useSystemIcons?KGlobal::iconLoader()->loadIcon((sysname),KIcon::Small):QPixmap::fromMimeSource((name)))
@@ -171,8 +172,8 @@ void SourceFileWindow::initBase()
   THIS->kfinddialog = static_cast<KFindDialog *>(NULL);
   THIS->kreplace = static_cast<KReplaceWithSelectionS *>(NULL);
   THIS->kateView=static_cast<Kate::View *>(NULL);
-  THIS->kateView=reinterpret_cast<Kate::View *>(createView(THIS->fileName,THIS->fileText,THIS->hlMode,
-  THIS->isASMFile?preferences.tabWidthAsm:THIS->isCFile?preferences.tabWidthC:8));
+  THIS->kateView=reinterpret_cast<Kate::View *>(createView(THIS->fileName,THIS->fileText,HL_MODE,
+    THIS->isASMFile?preferences.tabWidthAsm:THIS->isCFile?preferences.tabWidthC:8));
   THIS->fileText=QString::null;
   int rightStatusSize=size().width();
   unsigned int line, col;
@@ -537,7 +538,7 @@ void SourceFileWindow::applyPreferences()
     // Kate seems really insisting on making it a pain to update syntax highlighting settings.
     unsigned cnt=kateView->getDoc()->hlModeCount(), i;
     for (i=0; i<cnt; i++) {
-      if (kateView->getDoc()->hlModeName(i)==THIS->hlMode) break;
+      if (kateView->getDoc()->hlModeName(i)==HL_MODE) break;
     }
     if (i==cnt) i=0;
     kateView->getDoc()->setHlMode(0);