Bläddra i källkod

Add support for opening a project from the command line.

git-svn-id: file:///var/svn/tigccpp/trunk@434 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 18 år sedan
förälder
incheckning
0ae27b7e88
3 ändrade filer med 26 tillägg och 5 borttagningar
  1. 17 0
      ktigcc/ktigcc.cpp
  2. 1 0
      ktigcc/ktigcc.h
  3. 8 5
      ktigcc/mainform.ui.h

+ 17 - 0
ktigcc/ktigcc.cpp

@@ -21,6 +21,7 @@
 #include <cstdio>
 #include <cstdlib>
 #include <unistd.h>
+#include <qstring.h>
 #include <kapplication.h>
 #include <kcmdlineargs.h>
 #include <kaboutdata.h>
@@ -31,11 +32,18 @@ using namespace std;
 void qCleanupImages_ktigcc();
 void qInitImages_ktigcc();
 
+static KCmdLineOptions options[] =
+{
+    { "+[file]", "Project or file to open at startup", 0 },
+    KCmdLineLastOption
+};
+
 const char *tigcc_base;
 char tempdir[]="/tmp/ktigccXXXXXX";
 char *quill_drv;
 KConfig *pconfig;
 KAboutData *pabout;
+const char *parg;
 
 int main( int argc, char *argv[] )
 {
@@ -59,6 +67,8 @@ int main( int argc, char *argv[] )
   "http://tigcc.ticalc.org/linux/", "Bugs@tigcc.ticalc.org");
   pabout=&about;
   KCmdLineArgs::init(argc,argv,&about);
+  KCmdLineArgs::addCmdLineOptions(options);
+  KApplication::addCmdLineOptions();
   KApplication app;
   // Readd the images KDE kindly removes...
   qCleanupImages_ktigcc();
@@ -139,6 +149,13 @@ int main( int argc, char *argv[] )
   
   if (!mkdtemp(tempdir)) exit(1);
   
+  KCmdLineArgs *args=KCmdLineArgs::parsedArgs();
+  
+  if (args->count())
+    parg=args->arg(0);
+  else
+    parg=NULL;
+
   MainForm mainForm;
   app.setMainWidget( &mainForm );
   mainForm.show();

+ 1 - 0
ktigcc/ktigcc.h

@@ -30,3 +30,4 @@ extern void delete_temp_file(const char *filename);
 extern void force_qt_assistant_page(int n);
 extern KConfig *pconfig;
 extern KAboutData *pabout;
+extern const char *parg;

+ 8 - 5
ktigcc/mainform.ui.h

@@ -482,11 +482,14 @@ void MainForm::init()
   projectFileName="";
   projectIsDirty=FALSE;
   pconfig->setGroup("Recent files");
-  QString mostrecent=pconfig->readEntry("Current project");
-  if (!mostrecent.isNull() && !mostrecent.isEmpty())
-    openProject(mostrecent);
-  else
-    updateRecent();
+  if (parg)
+    openProject(parg);
+  else {
+    QString mostrecent=pconfig->readEntry("Current project");
+    if (!mostrecent.isNull() && !mostrecent.isEmpty())
+      openProject(mostrecent);
+  }
+  updateRecent();
   startTimer(100);
 }