Ver código fonte

Implement customizable list of templates. Can't actually be used yet though.

git-svn-id: file:///var/svn/tigccpp/trunk@814 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 18 anos atrás
pai
commit
2c6600dca9
4 arquivos alterados com 445 adições e 5 exclusões
  1. 33 1
      ktigcc/preferences.cpp
  2. 4 0
      ktigcc/preferences.h
  3. 334 4
      ktigcc/preferencesdlg.ui
  4. 74 0
      ktigcc/preferencesdlg.ui.h

+ 33 - 1
ktigcc/preferences.cpp

@@ -33,6 +33,7 @@
 #include <qdom.h>
 #include <qcstring.h>
 #include <qdir.h>
+#include <qpair.h>
 #include <kconfig.h>
 #include "ktigcc.h"
 #include "preferences.h"
@@ -1710,7 +1711,29 @@ void loadPreferences(void)
   preferences.removeTrailingSpaces=pconfig->readBoolEntry("Remove Trailing Spaces",false);
 
   updateEditorPreferences();
-  
+
+  // Coding
+  if (pconfig->hasKey("Num Coding Templates")) {
+    unsigned numTemplates=pconfig->readUnsignedNumEntry("Num Coding Templates");
+    preferences.templates.clear();
+    for (unsigned i=0; i<numTemplates; i++) {
+      preferences.templates.append(qMakePair(
+        pconfig->readEntry(QString("Coding Template %1 Name").arg(i)),
+        pconfig->readEntry(QString("Coding Template %1 Text").arg(i))));
+    }
+  } else {
+    preferences.templates.clear();
+    // These are 7-bit ASCII, so either fromLatin1 or fromUtf8 will work.
+    // fromLatin1 is probably faster.
+    preferences.templates
+      << qMakePair(QString::fromLatin1("do"),QString::fromLatin1("do {\n\t|\n} while ();"))
+      << qMakePair(QString::fromLatin1("for"),QString::fromLatin1("for (|; ; ) {"))
+      << qMakePair(QString::fromLatin1("if"),QString::fromLatin1("if (|) {"))
+      << qMakePair(QString::fromLatin1("if else"),QString::fromLatin1("if (|) {\n} else {\n}"))
+      << qMakePair(QString::fromLatin1("switch"),QString::fromLatin1("switch (|) {\n\tcase:\n\t\tbreak;\n\n\tdefault:\n\t\tbreak;\n}"))
+      << qMakePair(QString::fromLatin1("while"),QString::fromLatin1("while (|) {"));
+  }
+
   // Syntax
   if (!loadSyntaxPreferences())
     defaultSynHighlight();
@@ -1751,6 +1774,15 @@ void savePreferences(void)
 
   updateEditorPreferences();
 
+  // Coding
+  unsigned i=0;
+  for (QValueList<QPair<QString,QString> >::ConstIterator it=preferences.templates.begin();
+       it!=preferences.templates.end(); ++it, i++) {
+    pconfig->writeEntry(QString("Coding Template %1 Name").arg(i),(*it).first);
+    pconfig->writeEntry(QString("Coding Template %1 Text").arg(i),(*it).second);
+  }
+  pconfig->writeEntry("Num Coding Templates",i);
+
   // Syntax, save to disk
   saveSyntaxPreferences();
 }

+ 4 - 0
ktigcc/preferences.h

@@ -22,6 +22,7 @@
 #include <qstring.h>
 #include <qstringlist.h>
 #include <qvaluelist.h>
+#include <qpair.h>
 #include <qcolor.h>
 #include <qfont.h>
 #include <ticables.h>
@@ -112,6 +113,9 @@ typedef struct
   Syn_SettingsForDoc synAsm;
   Syn_SettingsForDoc synQll;
 
+  // Coding
+  QValueList<QPair<QString,QString> > templates;
+
   // Used internally by the Preferences dialog
   bool haveA68k;
   bool haveQuill;

+ 334 - 4
ktigcc/preferencesdlg.ui

@@ -8,8 +8,8 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>458</width>
-            <height>392</height>
+            <width>440</width>
+            <height>419</height>
         </rect>
     </property>
     <property name="caption">
@@ -164,6 +164,23 @@
                             <string>Alt+U</string>
                         </property>
                     </widget>
+                    <spacer>
+                        <property name="name">
+                            <cstring>spacer10</cstring>
+                        </property>
+                        <property name="orientation">
+                            <enum>Vertical</enum>
+                        </property>
+                        <property name="sizeType">
+                            <enum>Expanding</enum>
+                        </property>
+                        <property name="sizeHint">
+                            <size>
+                                <width>20</width>
+                                <height>31</height>
+                            </size>
+                        </property>
+                    </spacer>
                 </vbox>
             </widget>
             <widget class="QWidget">
@@ -403,6 +420,23 @@
                                     </widget>
                                 </hbox>
                             </widget>
+                            <spacer>
+                                <property name="name">
+                                    <cstring>spacer12</cstring>
+                                </property>
+                                <property name="orientation">
+                                    <enum>Vertical</enum>
+                                </property>
+                                <property name="sizeType">
+                                    <enum>Expanding</enum>
+                                </property>
+                                <property name="sizeHint">
+                                    <size>
+                                        <width>20</width>
+                                        <height>31</height>
+                                    </size>
+                                </property>
+                            </spacer>
                         </vbox>
                     </widget>
                 </vbox>
@@ -725,6 +759,23 @@
                             <string>Alt+R</string>
                         </property>
                     </widget>
+                    <spacer>
+                        <property name="name">
+                            <cstring>spacer14</cstring>
+                        </property>
+                        <property name="orientation">
+                            <enum>Vertical</enum>
+                        </property>
+                        <property name="sizeType">
+                            <enum>Expanding</enum>
+                        </property>
+                        <property name="sizeHint">
+                            <size>
+                                <width>20</width>
+                                <height>20</height>
+                            </size>
+                        </property>
+                    </spacer>
                 </vbox>
             </widget>
             <widget class="QWidget">
@@ -877,7 +928,7 @@
                     </widget>
                     <widget class="QLayoutWidget">
                         <property name="name">
-                            <cstring>layout11</cstring>
+                            <cstring>layout19</cstring>
                         </property>
                         <hbox>
                             <property name="name">
@@ -931,7 +982,7 @@
                             </widget>
                             <widget class="QLayoutWidget">
                                 <property name="name">
-                                    <cstring>layout10</cstring>
+                                    <cstring>layout18</cstring>
                                 </property>
                                 <vbox>
                                     <property name="name">
@@ -973,12 +1024,203 @@
                                             <string>Alt+I</string>
                                         </property>
                                     </widget>
+                                    <spacer>
+                                        <property name="name">
+                                            <cstring>spacer15</cstring>
+                                        </property>
+                                        <property name="orientation">
+                                            <enum>Vertical</enum>
+                                        </property>
+                                        <property name="sizeType">
+                                            <enum>Expanding</enum>
+                                        </property>
+                                        <property name="sizeHint">
+                                            <size>
+                                                <width>20</width>
+                                                <height>21</height>
+                                            </size>
+                                        </property>
+                                    </spacer>
                                 </vbox>
                             </widget>
                         </hbox>
                     </widget>
                 </vbox>
             </widget>
+            <widget class="QWidget">
+                <property name="name">
+                    <cstring>TabPage</cstring>
+                </property>
+                <attribute name="title">
+                    <string>Co&amp;ding</string>
+                </attribute>
+                <vbox>
+                    <property name="name">
+                        <cstring>unnamed</cstring>
+                    </property>
+                    <widget class="QGroupBox">
+                        <property name="name">
+                            <cstring>groupBox1</cstring>
+                        </property>
+                        <property name="title">
+                            <string>Code templates</string>
+                        </property>
+                        <vbox>
+                            <property name="name">
+                                <cstring>unnamed</cstring>
+                            </property>
+                            <widget class="KListBox">
+                                <property name="name">
+                                    <cstring>templateListBox</cstring>
+                                </property>
+                                <property name="sizePolicy">
+                                    <sizepolicy>
+                                        <hsizetype>7</hsizetype>
+                                        <vsizetype>7</vsizetype>
+                                        <horstretch>0</horstretch>
+                                        <verstretch>1</verstretch>
+                                    </sizepolicy>
+                                </property>
+                                <property name="selectionMode">
+                                    <enum>Extended</enum>
+                                </property>
+                            </widget>
+                            <widget class="QLayoutWidget">
+                                <property name="name">
+                                    <cstring>layout16</cstring>
+                                </property>
+                                <grid>
+                                    <property name="name">
+                                        <cstring>unnamed</cstring>
+                                    </property>
+                                    <widget class="KTextEdit" row="1" column="1">
+                                        <property name="name">
+                                            <cstring>templateCode</cstring>
+                                        </property>
+                                        <property name="sizePolicy">
+                                            <sizepolicy>
+                                                <hsizetype>7</hsizetype>
+                                                <vsizetype>7</vsizetype>
+                                                <horstretch>0</horstretch>
+                                                <verstretch>1</verstretch>
+                                            </sizepolicy>
+                                        </property>
+                                        <property name="textFormat">
+                                            <enum>PlainText</enum>
+                                        </property>
+                                        <property name="linkUnderline">
+                                            <bool>false</bool>
+                                        </property>
+                                        <property name="wordWrap">
+                                            <enum>NoWrap</enum>
+                                        </property>
+                                        <property name="autoFormatting">
+                                            <set>AutoNone</set>
+                                        </property>
+                                    </widget>
+                                    <widget class="KLineEdit" row="0" column="1">
+                                        <property name="name">
+                                            <cstring>templateIdentifier</cstring>
+                                        </property>
+                                    </widget>
+                                    <widget class="QLabel" row="1" column="0">
+                                        <property name="name">
+                                            <cstring>textLabel2</cstring>
+                                        </property>
+                                        <property name="text">
+                                            <string>Code</string>
+                                        </property>
+                                        <property name="alignment">
+                                            <set>AlignTop</set>
+                                        </property>
+                                    </widget>
+                                    <widget class="QLabel" row="0" column="0">
+                                        <property name="name">
+                                            <cstring>textLabel1</cstring>
+                                        </property>
+                                        <property name="text">
+                                            <string>Identifier</string>
+                                        </property>
+                                        <property name="alignment">
+                                            <set>AlignTop</set>
+                                        </property>
+                                    </widget>
+                                </grid>
+                            </widget>
+                            <widget class="QLayoutWidget">
+                                <property name="name">
+                                    <cstring>layout17</cstring>
+                                </property>
+                                <hbox>
+                                    <property name="name">
+                                        <cstring>unnamed</cstring>
+                                    </property>
+                                    <spacer>
+                                        <property name="name">
+                                            <cstring>spacer8</cstring>
+                                        </property>
+                                        <property name="orientation">
+                                            <enum>Horizontal</enum>
+                                        </property>
+                                        <property name="sizeType">
+                                            <enum>Expanding</enum>
+                                        </property>
+                                        <property name="sizeHint">
+                                            <size>
+                                                <width>151</width>
+                                                <height>20</height>
+                                            </size>
+                                        </property>
+                                    </spacer>
+                                    <widget class="KPushButton">
+                                        <property name="name">
+                                            <cstring>clearSelectionButton</cstring>
+                                        </property>
+                                        <property name="enabled">
+                                            <bool>false</bool>
+                                        </property>
+                                        <property name="text">
+                                            <string>Clear selection</string>
+                                        </property>
+                                    </widget>
+                                    <widget class="KPushButton">
+                                        <property name="name">
+                                            <cstring>applyButton</cstring>
+                                        </property>
+                                        <property name="enabled">
+                                            <bool>false</bool>
+                                        </property>
+                                        <property name="text">
+                                            <string>Apply</string>
+                                        </property>
+                                    </widget>
+                                </hbox>
+                            </widget>
+                        </vbox>
+                    </widget>
+                    <widget class="QGroupBox">
+                        <property name="name">
+                            <cstring>groupBox2</cstring>
+                        </property>
+                        <property name="title">
+                            <string>Code completion</string>
+                        </property>
+                        <vbox>
+                            <property name="name">
+                                <cstring>unnamed</cstring>
+                            </property>
+                            <widget class="KPushButton">
+                                <property name="name">
+                                    <cstring>kPushButton21</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Open the completion editor</string>
+                                </property>
+                            </widget>
+                        </vbox>
+                    </widget>
+                </vbox>
+            </widget>
         </widget>
         <widget class="QLayoutWidget">
             <property name="name">
@@ -1164,7 +1406,84 @@
         <receiver>Preferences</receiver>
         <slot>syntaxEnabled_toggled(bool)</slot>
     </connection>
+    <connection>
+        <sender>templateListBox</sender>
+        <signal>selectionChanged()</signal>
+        <receiver>Preferences</receiver>
+        <slot>templateListBox_selectionChanged()</slot>
+    </connection>
+    <connection>
+        <sender>templateListBox</sender>
+        <signal>currentChanged(QListBoxItem*)</signal>
+        <receiver>Preferences</receiver>
+        <slot>templateListBox_currentChanged(QListBoxItem*)</slot>
+    </connection>
+    <connection>
+        <sender>templateIdentifier</sender>
+        <signal>textChanged(const QString&amp;)</signal>
+        <receiver>Preferences</receiver>
+        <slot>templateIdentifier_textChanged(const QString&amp;)</slot>
+    </connection>
+    <connection>
+        <sender>clearSelectionButton</sender>
+        <signal>clicked()</signal>
+        <receiver>Preferences</receiver>
+        <slot>clearSelectionButton_clicked()</slot>
+    </connection>
+    <connection>
+        <sender>applyButton</sender>
+        <signal>clicked()</signal>
+        <receiver>Preferences</receiver>
+        <slot>applyButton_clicked()</slot>
+    </connection>
 </connections>
+<tabstops>
+    <tabstop>tabWidget</tabstop>
+    <tabstop>stopAtFirstError</tabstop>
+    <tabstop>jumpToError</tabstop>
+    <tabstop>successMessage</tabstop>
+    <tabstop>deleteAsmFiles</tabstop>
+    <tabstop>deleteObjFiles</tabstop>
+    <tabstop>splitSourceFiles</tabstop>
+    <tabstop>allowImplicitDeclaration</tabstop>
+    <tabstop>autoSave</tabstop>
+    <tabstop>downloadHeadlines</tabstop>
+    <tabstop>deleteOverwrittenErrors</tabstop>
+    <tabstop>useSystemIcons</tabstop>
+    <tabstop>targetNone</tabstop>
+    <tabstop>port1</tabstop>
+    <tabstop>grayLink</tabstop>
+    <tabstop>tabWidthC</tabstop>
+    <tabstop>tabWidthAsm</tabstop>
+    <tabstop>useBgColor</tabstop>
+    <tabstop>bgColorChange</tabstop>
+    <tabstop>editorFontChange</tabstop>
+    <tabstop>useCalcCharset</tabstop>
+    <tabstop>lazyLoading</tabstop>
+    <tabstop>autoBlocks</tabstop>
+    <tabstop>removeTrailingSpaces</tabstop>
+    <tabstop>syntaxLanguage</tabstop>
+    <tabstop>syntaxEnabled</tabstop>
+    <tabstop>resetButton</tabstop>
+    <tabstop>numberColorButton</tabstop>
+    <tabstop>numberStyleButton</tabstop>
+    <tabstop>symbolColorButton</tabstop>
+    <tabstop>symbolStyleButton</tabstop>
+    <tabstop>parenthesisColorsButton</tabstop>
+    <tabstop>parenthesisStyleButton</tabstop>
+    <tabstop>syntaxListView</tabstop>
+    <tabstop>newStyleButton</tabstop>
+    <tabstop>newListButton</tabstop>
+    <tabstop>editButton</tabstop>
+    <tabstop>templateListBox</tabstop>
+    <tabstop>templateIdentifier</tabstop>
+    <tabstop>templateCode</tabstop>
+    <tabstop>clearSelectionButton</tabstop>
+    <tabstop>applyButton</tabstop>
+    <tabstop>kPushButton21</tabstop>
+    <tabstop>okButton</tabstop>
+    <tabstop>cancelButton</tabstop>
+</tabstops>
 <includes>
     <include location="local" impldecl="in implementation">preferencesdlg.ui.h</include>
 </includes>
@@ -1191,6 +1510,11 @@
     <slot>editButton_clicked()</slot>
     <slot>editDialog_colorButton_clicked()</slot>
     <slot>editDialog_styleButton_clicked()</slot>
+    <slot>clearSelectionButton_clicked()</slot>
+    <slot>applyButton_clicked()</slot>
+    <slot>templateListBox_selectionChanged()</slot>
+    <slot>templateListBox_currentChanged( QListBoxItem * item )</slot>
+    <slot>templateIdentifier_textChanged( const QString &amp; text )</slot>
 </slots>
 <pixmapinproject/>
 <layoutdefaults spacing="6" margin="11"/>
@@ -1213,6 +1537,12 @@
     <includehint>kpushbutton.h</includehint>
     <includehint>kpushbutton.h</includehint>
     <includehint>kpushbutton.h</includehint>
+    <includehint>klistbox.h</includehint>
+    <includehint>ktextedit.h</includehint>
+    <includehint>klineedit.h</includehint>
+    <includehint>kpushbutton.h</includehint>
+    <includehint>kpushbutton.h</includehint>
+    <includehint>kpushbutton.h</includehint>
     <includehint>kpushbutton.h</includehint>
     <includehint>kpushbutton.h</includehint>
 </includehints>

+ 74 - 0
ktigcc/preferencesdlg.ui.h

@@ -46,6 +46,7 @@
 #include <klistview.h>
 #include <klineedit.h>
 #include <keditlistbox.h>
+#include <klistbox.h>
 #include "ktigcc.h"
 #include "selectstyle.h"
 #include "selectcolors.h"
@@ -75,6 +76,18 @@ class RenamableKListViewItem : public KListViewItem {
   }
 };
 
+class ListBoxTextPair : public QListBoxText {
+  public:
+    ListBoxTextPair(QListBox *listbox, const QString &text,
+                    const QString &data)
+      : QListBoxText(listbox,text), m_data(data) {}
+    virtual ~ListBoxTextPair() {}
+    void setData(const QString &data) {m_data=data;}
+    QString data() {return m_data;}
+  private:
+    QString m_data;
+};
+
 void Preferences::init()
 {
   // General
@@ -180,6 +193,13 @@ void Preferences::init()
   syntaxListViewAccel->insertItem(Key_Delete,0);
   connect(syntaxListViewAccel,SIGNAL(activated(int)),
           this,SLOT(syntaxListViewAccel_activated(int)));
+
+  // Coding
+  templateListBox->clear();
+  for (QValueList<QPair<QString,QString> >::ConstIterator it=preferences.templates.begin();
+       it!=preferences.templates.end(); ++it)
+    new ListBoxTextPair(templateListBox,(*it).first,(*it).second);
+  templateListBox->sort();
 }
 
 void Preferences::destroy()
@@ -228,6 +248,13 @@ void Preferences::destroy()
     preferences.synS=preferences.tempSynS;
     preferences.synAsm=preferences.tempSynAsm;
     preferences.synQll=preferences.tempSynQll;
+
+    // Coding
+    preferences.templates.clear();
+    for (QListBoxItem *item=templateListBox->firstItem(); item;
+         item=item->next())
+      preferences.templates.append(qMakePair(item->text(),
+        static_cast<ListBoxTextPair *>(item)->data()));
   }
 }
 
@@ -640,3 +667,50 @@ void Preferences::editDialog_styleButton_clicked()
     }
   }
 }
+
+void Preferences::clearSelectionButton_clicked()
+{
+  QListBoxItem *next;
+  for (QListBoxItem *item=templateListBox->firstItem(); item;
+       item=next) {
+    next=item->next();
+    if (item->isSelected()) delete item;
+  }
+}
+
+void Preferences::applyButton_clicked()
+{
+  QString identifier=templateIdentifier->text();
+  QListBoxItem *item=templateListBox->findItem(identifier,Qt::ExactMatch);
+  if (item) {
+    static_cast<ListBoxTextPair *>(item)->setData(templateCode->text());
+  } else {
+    new ListBoxTextPair(templateListBox,identifier,templateCode->text());
+    templateListBox->sort();
+  }
+}
+
+void Preferences::templateListBox_selectionChanged()
+{
+  for (QListBoxItem *item=templateListBox->firstItem(); item;
+       item=item->next()) {
+    if (item->isSelected()) {
+      clearSelectionButton->setEnabled(TRUE);
+      return;
+    }
+  }
+  clearSelectionButton->setEnabled(FALSE);
+}
+
+void Preferences::templateListBox_currentChanged(QListBoxItem *item)
+{
+  if (item) {
+    templateIdentifier->setText(item->text());
+    templateCode->setText(static_cast<ListBoxTextPair *>(item)->data());
+  }
+}
+
+void Preferences::templateIdentifier_textChanged(const QString &text)
+{
+  applyButton->setEnabled(!text.isEmpty());
+}