[PC-BSD Commits] r20100 - users/ken/EasyPBI2

svn at pcbsd.org svn at pcbsd.org
Wed Oct 31 18:06:31 PDT 2012


Author: kenmoore
Date: 2012-11-01 01:06:31 +0000 (Thu, 01 Nov 2012)
New Revision: 20100

Modified:
   users/ken/EasyPBI2/mainGUI.cpp
   users/ken/EasyPBI2/mainGUI.h
   users/ken/EasyPBI2/mainGUI.ui
Log:
Get the Scripts tab working completely for EasyPBI2. Might need a bit of refining icon-wise.



Modified: users/ken/EasyPBI2/mainGUI.cpp
===================================================================
--- users/ken/EasyPBI2/mainGUI.cpp	2012-10-31 19:53:49 UTC (rev 20099)
+++ users/ken/EasyPBI2/mainGUI.cpp	2012-11-01 01:06:31 UTC (rev 20100)
@@ -80,8 +80,8 @@
 	// -- Scripts tab --
 	ui->push_scripts_save->setIcon(Backend::icon("save"));
 	ui->push_scripts_create->setIcon(Backend::icon("new"));
-	ui->push_scripts_remove->setIcon(Backend::icon(""));
-	ui->list_scripts_file->addItems(QStringList() << "Installation Scripts" << "pre-portmake.sh" << "post-portmake.sh" << "pre-install.sh" << "post-install.sh" << "pre-remove.sh" );
+	ui->list_scripts_file->addItems(QStringList() << " ---"+tr("Installation Scripts")+"---" << "pre-portmake.sh" << "post-portmake.sh" << "pre-install.sh" << "post-install.sh" << "pre-remove.sh" );
+	connect(ui->list_scripts_file, SIGNAL(currentIndexChanged(int)), this, SLOT(slotScriptChanged(int)) );
 	// -- External links tab --
 	ui->push_el_files->setIcon(Backend::icon("left"));
 	menu_binList.addAction("No Binaries Detected");
@@ -300,7 +300,37 @@
   }
   //------SCRIPTS-----
   if( doall || doeditor || (item == "scripts")){
-    //nothing to make visible/invisible here
+    //Update the list of available scripts and determine if one needs to be read
+    bool loadScript = FALSE;
+    QString path = currentModule->path()+"/scripts/";
+    int currentIndex = ui->list_scripts_file->currentIndex();
+    for(int i=1; i< ui->list_scripts_file->count(); i++){ //Skip the first item (is nothing)
+      if( QFile::exists( path+ui->list_scripts_file->itemText(i) ) ){
+        if(i == currentIndex){ loadScript = TRUE; }
+        ui->list_scripts_file->setItemIcon(i,Backend::icon("file"));
+      }else{
+        ui->list_scripts_file->setItemIcon(i,Backend::icon("new"));
+      }
+    }
+    //Update the GUI appropriately
+    if(loadScript){
+      //Read and display the script
+      QStringList contents = ModBuild::readFile(path+ui->list_scripts_file->currentText());
+      ui->text_scripts_edit->setPlainText(contents.join("\n"));
+      //Setup display items
+      ui->push_scripts_create->setVisible(FALSE);
+      ui->push_scripts_remove->setVisible(TRUE);
+      ui->push_scripts_save->setVisible(TRUE);
+      ui->text_scripts_edit->setVisible(TRUE);
+    }else{
+      //Setup display items
+      ui->push_scripts_create->setVisible(TRUE);
+      ui->push_scripts_remove->setVisible(FALSE);
+      ui->push_scripts_save->setVisible(FALSE);
+      ui->text_scripts_edit->setVisible(FALSE);
+    }
+    if(currentIndex == 0){ ui->push_scripts_create->setVisible(FALSE); }
+    
   }
   //------EXTERNAL-LINKS------
   if( doall || doeditor || (item == "external-links")){
@@ -1056,4 +1086,37 @@
    SCRIPTS EDITOR OPTIONS
   -------------------------------------------------
 */
+void MainGUI::slotScriptChanged(int index){
+  refreshGUI("scripts");
+}
 
+void MainGUI::on_push_scripts_create_clicked(){
+  //Setup display items
+  ui->push_scripts_create->setVisible(FALSE);
+  ui->push_scripts_remove->setVisible(FALSE);
+  ui->push_scripts_save->setVisible(TRUE);
+  ui->text_scripts_edit->setVisible(TRUE);
+  ui->text_scripts_edit->clear();
+}
+
+void MainGUI::on_push_scripts_remove_clicked(){
+  //Get the current file
+  QString filename = ui->list_scripts_file->currentText();
+  //Remove the file
+  QDir dir(currentModule->path()+"/scripts");
+  dir.remove(filename);
+  //refresh the UI
+  refreshGUI("scripts");
+}
+
+void MainGUI::on_push_scripts_save_clicked(){
+  //Get the current file text
+  QStringList contents = ui->text_scripts_edit->toPlainText().split("\n");
+  //get the current file
+  QString filename = currentModule->path() + "/scripts/"+ui->list_scripts_file->currentText();
+  //Save the file
+  bool ok = ModBuild::createFile(filename,contents);
+  //Now refresh the UI
+  refreshGUI("scripts");
+}
+

Modified: users/ken/EasyPBI2/mainGUI.h
===================================================================
--- users/ken/EasyPBI2/mainGUI.h	2012-10-31 19:53:49 UTC (rev 20099)
+++ users/ken/EasyPBI2/mainGUI.h	2012-11-01 01:06:31 UTC (rev 20100)
@@ -66,6 +66,11 @@
     void on_push_xdg_remove_clicked();
     void on_push_xdg_savechanges_clicked();
     void on_push_xdg_savenew_clicked();
+    //Scripts functions
+    void slotScriptChanged(int);
+    void on_push_scripts_create_clicked();
+    void on_push_scripts_remove_clicked();
+    void on_push_scripts_save_clicked();
 
 
 private:

Modified: users/ken/EasyPBI2/mainGUI.ui
===================================================================
(Binary files differ)



More information about the Commits mailing list