Преглед изворни кода

Keep track of current project separately from recent projects and reset the current project in fileNewProject. Also enter projects into the recent project list when saving.

git-svn-id: file:///var/svn/tigccpp/trunk@433 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler пре 18 година
родитељ
комит
6c5d829821
2 измењених фајлова са 32 додато и 22 уклоњено
  1. 5 4
      ktigcc/mainform.ui
  2. 27 18
      ktigcc/mainform.ui.h

+ 5 - 4
ktigcc/mainform.ui

@@ -1339,6 +1339,10 @@
     <slot>te_popup_aboutToShow()</slot>
     <slot>fileNewProject()</slot>
     <slot>fileOpen()</slot>
+    <slot>fileRecent1()</slot>
+    <slot>fileRecent2()</slot>
+    <slot>fileRecent3()</slot>
+    <slot>fileRecent4()</slot>
     <slot>fileSave()</slot>
     <slot>fileSaveAs()</slot>
     <slot>filePrint()</slot>
@@ -1371,10 +1375,6 @@
     <slot>m_view_cursorPositionChanged()</slot>
     <slot>m_view_textChanged()</slot>
     <slot>fileTreeItemRenamed( QListViewItem * item, int col, const QString &amp; newName )</slot>
-    <slot>fileRecent1()</slot>
-    <slot>fileRecent2()</slot>
-    <slot>fileRecent3()</slot>
-    <slot>fileRecent4()</slot>
 </slots>
 <functions>
     <function access="private" specifier="non virtual">clearProject()</function>
@@ -1382,6 +1382,7 @@
     <function returnType="QString">SGetFileName( int mode, const QString &amp; fileFilter, const QString &amp; caption, QWidget * parent )</function>
     <function returnType="QStringList">SGetFileName_Multiple( const QString &amp; fileFilter, const QString &amp; caption, QWidget * parent )</function>
     <function access="private" specifier="non virtual">updateRecent()</function>
+    <function access="private" specifier="non virtual">addRecent( const QString &amp; fileName )</function>
     <function access="private" specifier="non virtual" returnType="QListViewItem *">openFile( QListViewItem * category, QListViewItem * parent, const QString &amp; fileCaption, const QString &amp; fileName )</function>
     <function access="private" specifier="static" returnType="QListViewItem *">createFolder( QListViewItem * parent, const QString &amp; name )</function>
     <function access="private" specifier="non virtual">fileOpen_addList( QListViewItem * category, void * fileListV, void * dir, const QString &amp; open_file )</function>

+ 27 - 18
ktigcc/mainform.ui.h

@@ -482,8 +482,8 @@ void MainForm::init()
   projectFileName="";
   projectIsDirty=FALSE;
   pconfig->setGroup("Recent files");
-  QString mostrecent=pconfig->readEntry("Recent file 1");
-  if (!mostrecent.isNull())
+  QString mostrecent=pconfig->readEntry("Current project");
+  if (!mostrecent.isNull() && !mostrecent.isEmpty())
     openProject(mostrecent);
   else
     updateRecent();
@@ -575,6 +575,8 @@ void MainForm::clearProject()
 void MainForm::fileNewProject()
 {
   clearProject();
+  pconfig->setGroup("Recent files");
+  pconfig->writeEntry("Current project","");
 }
 
 QString MainForm::findFilter(unsigned short job)
@@ -692,6 +694,27 @@ void MainForm::updateRecent()
   }
 }
 
+void MainForm::addRecent(const QString &fileName)
+{
+  unsigned i,j;
+  pconfig->setGroup("Recent files");
+  // Find recent file to overwrite. If it isn't one of the first 3, by
+  // elimination, it is the last, thus the test only goes up to <4, not <=4.
+  for (i=1;i<4;i++) {
+    QString recenti=pconfig->readEntry(QString("Recent file %1").arg(i));
+    if (recenti.isNull() || !recenti.compare(fileName))
+      break;
+  }
+  // Move entries up
+  for (j=i;j>1;j--) {
+    pconfig->writeEntry(QString("Recent file %1").arg(j),pconfig->readEntry(QString("Recent file %1").arg(j-1)));
+  }
+  // The first recent file is the current project.
+  pconfig->writeEntry("Recent file 1",fileName);
+  pconfig->writeEntry("Current project",fileName);
+  updateRecent();
+}
+
 QListViewItem * MainForm::openFile(QListViewItem * category, QListViewItem * parent, const QString &fileCaption, const QString &fileName)
 {
   QListViewItem *item=NULL, *next=parent->firstChild();
@@ -819,22 +842,7 @@ void MainForm::openProject(const QString &fileName)
   libopts=TPRData.libopts;
   updateLeftStatusLabel();
   updateRightStatusLabel();
-  pconfig->setGroup("Recent files");
-  unsigned i,j;
-  // Find recent file to overwrite. If it isn't one of the first 3, by
-  // elimination, it is the last, thus the test only goes up to <4, not <=4.
-  for (i=1;i<4;i++) {
-    QString recenti=pconfig->readEntry(QString("Recent file %1").arg(i));
-    if (recenti.isNull() || !recenti.compare(fileName))
-      break;
-  }
-  // Move entries up
-  for (j=i;j>1;j--) {
-    pconfig->writeEntry(QString("Recent file %1").arg(j),pconfig->readEntry(QString("Recent file %1").arg(j-1)));
-  }
-  // The first recent file is the current project.
-  pconfig->writeEntry("Recent file 1",fileName);
-  updateRecent();
+  addRecent(fileName);
 }
 
 void MainForm::fileOpen()
@@ -1023,6 +1031,7 @@ void MainForm::fileSave_fromto(const QString &lastProj,const QString &nextProj)
   else {
     projectFileName=nextProj;
     projectIsDirty=FALSE;
+    addRecent(nextProj);
   }
   updateRightStatusLabel();
 }