Explorar el Código

ENH: Paths are now expanded for environment variables and made absolute.
The binary directory is created if it doesn't exist.

Luis Ibanez hace 24 años
padre
commit
d0614d75ea

+ 2 - 2
Source/FLTKDialog/CMakeSetupGUI.cxx

@@ -126,8 +126,8 @@ void CMakeSetupGUI::BrowseForBinaryPath(void) {
 void CMakeSetupGUI::Show(void) {
 }
 
-void CMakeSetupGUI::SetBinaryPath(const char *) {
+bool CMakeSetupGUI::SetBinaryPath(const char *) {
 }
 
-void CMakeSetupGUI::SetSourcePath(const char *) {
+bool CMakeSetupGUI::SetSourcePath(const char *) {
 }

+ 4 - 4
Source/FLTKDialog/CMakeSetupGUI.fl

@@ -25,7 +25,7 @@ class CMakeSetupGUI {open
       }
       Fl_Input binaryPathTextInput {
         label {Where do you want to build the binaries: }
-        callback {SetBinaryPath( binaryPathTextInput->value() );}
+        callback {SetBinaryPath( binaryPathTextInput->value() );} selected
         xywh {219 50 200 20} labelsize 11 when 8 textsize 11
       }
       Fl_Button {} {
@@ -50,7 +50,7 @@ class CMakeSetupGUI {open
           label {Cache Values} open
           xywh {40 98 485 190} type BOTH_ALWAYS box DOWN_FRAME labelsize 11 align 5 when 1 resizable
         } {
-          Fl_Pack propertyListPack {selected
+          Fl_Pack propertyListPack {
             xywh {40 99 485 185} resizable
           } {}
         }
@@ -72,8 +72,8 @@ class CMakeSetupGUI {open
   } {}
   Function {Show(void)} {return_type {virtual void}
   } {}
-  Function {SetBinaryPath(const char *)} {return_type {virtual void}
+  Function {SetBinaryPath(const char *)} {return_type {virtual bool}
   } {}
-  Function {SetSourcePath(const char *)} {return_type {virtual void}
+  Function {SetSourcePath(const char *)} {return_type {virtual bool}
   } {}
 } 

+ 2 - 2
Source/FLTKDialog/CMakeSetupGUI.h

@@ -41,7 +41,7 @@ public:
   virtual void BrowseForSourcePath(void);
   virtual void BrowseForBinaryPath(void);
   virtual void Show(void);
-  virtual void SetBinaryPath(const char *);
-  virtual void SetSourcePath(const char *);
+  virtual bool SetBinaryPath(const char *);
+  virtual bool SetSourcePath(const char *);
 };
 #endif

+ 92 - 39
Source/FLTKDialog/CMakeSetupGUIImplementation.cxx

@@ -21,10 +21,9 @@ CMakeSetupGUIImplementation
 {
   m_BuildPathChanged = false;
   char fname[1024];
-  //::GetModuleFileName(NULL,fname,1023);
+  //::GetModuleFileName(NULL,fname,1023);  // Didn't found this method. (?)
   m_PathToExecutable = cmSystemTools::GetProgramPath(fname).c_str();
   m_PathToExecutable += "/cmake.exe";
-  std::cout << "Path to executable = " << m_PathToExecutable << std::endl;
 }
 
 
@@ -122,89 +121,142 @@ CMakeSetupGUIImplementation
 /**
  * Set the source path
  */
-void
+bool
 CMakeSetupGUIImplementation
 ::SetSourcePath( const char * path )
 {
-  if( VerifySourcePath( path ) )
+
+  if( !path || strlen(path)==0 )
+  {
+    fl_alert("Please select the path to the sources");
+    return false; 
+  }
+
+  string expandedAbsolutePath = ExpandPathAndMakeItAbsolute( path );
+  
+  sourcePathTextInput->value( expandedAbsolutePath.c_str() );
+    
+  if( VerifySourcePath( expandedAbsolutePath ) )
   {
-    m_WhereSource = path;
-    sourcePathTextInput->value( path );
+    m_WhereSource = expandedAbsolutePath;
+    return true;
   }
 
+  return false;
+
 }
 
 
 
 
 /**
- * Set the binary path
+ * Expand environment variables in the path and make it absolute
  */
-void
+string
 CMakeSetupGUIImplementation
-::SetBinaryPath( const char * path )
+::ExpandPathAndMakeItAbsolute( const string & inputPath ) const
 {
 
-  if( VerifyBinaryPath( path ) )
-  {
-    if( m_WhereBuild != path )
-    {
-      m_BuildPathChanged = true;
-      m_WhereBuild = path;
-    }
-    binaryPathTextInput->value( path );
-  }
+  char expandedPath[3000];
+  filename_expand( expandedPath, inputPath.c_str() );
 
-  LoadCacheFromDiskToGUI();
+  char absolutePath[3000];
+  filename_absolute( absolutePath, expandedPath );
+  
+  string expandedAbsolutePath = absolutePath;
 
+  return expandedAbsolutePath;
+    
 }
 
 
-
 /**
- * Verify the path to binaries
+ * Set the binary path
  */
 bool
 CMakeSetupGUIImplementation
-::VerifyBinaryPath( const char * path )
+::SetBinaryPath( const char * path )
 {
 
   if( !path || strlen(path)==0 )
   {
     fl_alert("Please select the path to the binaries");
-    return false; 
+    return false;
   }
 
+  string expandedAbsolutePath = ExpandPathAndMakeItAbsolute( path );
+  
+  binaryPathTextInput->value( expandedAbsolutePath.c_str() );
+
+  if( !VerifyBinaryPath( expandedAbsolutePath.c_str() ) )
+  {
+    return false;
+  }
 
-  if( !filename_isdir( path ) )
+  if( m_WhereBuild != expandedAbsolutePath )
   {
-    fl_alert("%s \n Doesn't exist or is not a directory",path);
-    return false; 
+    m_BuildPathChanged = true;
+    m_WhereBuild = expandedAbsolutePath;
   }
+  
+  LoadCacheFromDiskToGUI();
 
   return true;
+
 }
 
 
 
 /**
- * Verify the path to sources
+ * Verify the path to binaries
  */
 bool
 CMakeSetupGUIImplementation
-::VerifySourcePath( const char * path )
+::VerifyBinaryPath( const string & path ) const
 {
 
-  if( !path || strlen(path)==0 )
+  bool pathIsOK = false;
+
+  if( filename_isdir( path.c_str() ) )
   {
-    fl_alert("Please select the path to the sources");
-    return false; 
+    pathIsOK = true;
+  }
+  else
+  {
+    int userWantsToCreateDirectory = 
+      fl_ask("The directory \n %s \n Doesn't exist. Do you want to create it ?",
+              path.c_str() );
+    
+    if( userWantsToCreateDirectory  )
+    {
+      string command = "mkdir ";
+      command += path;
+      system( command.c_str() );
+      pathIsOK = true;
+    }
+    else
+    {
+      pathIsOK = false; 
+    }
   }
 
+  return pathIsOK;
 
-  if( !filename_isdir( path ) )
+}
+
+
+
+/**
+ * Verify the path to sources
+ */
+bool
+CMakeSetupGUIImplementation
+::VerifySourcePath( const string & path ) const
+{
+
+  if( !filename_isdir( path.c_str() ) )
   {
-    fl_alert("%s \n Doesn't exist or is not a directory",path);
+    fl_alert("The Source directory \n %s \n Doesn't exist or is not a directory", path.c_str() );
     return false; 
   }
 
@@ -222,17 +274,18 @@ CMakeSetupGUIImplementation
 ::BuildProjectFiles( void )
 {
 
-  // Verify that source path is a valid directory
-  if( !VerifySourcePath( sourcePathTextInput->value() ) )
+  // Take and verify the source path from the GUI
+  if( !SetSourcePath( sourcePathTextInput->value() ) )
   { 
     return;
   }
-
-  // Verify that binary path is a valid directory
-  if( !VerifyBinaryPath( binaryPathTextInput->value() ) )
-  { 
+  
+  // Take and verify the binary path from the GUI
+  if( !SetBinaryPath( binaryPathTextInput->value() ) )
+  {
     return;
   }
+  
 
   SaveCacheFromGUI();
   

+ 7 - 4
Source/FLTKDialog/CMakeSetupGUIImplementation.h

@@ -26,15 +26,18 @@ public:
   virtual void BuildProjectFiles( void );
   virtual void BrowseForBinaryPath( void );
   virtual void BrowseForSourcePath( void );
-  virtual void SetBinaryPath( const char * path );
-  virtual void SetSourcePath( const char * path );
-  virtual bool VerifyBinaryPath( const char * path );
-  virtual bool VerifySourcePath( const char * path );
+  virtual bool SetBinaryPath( const char * path );
+  virtual bool SetSourcePath( const char * path );
   virtual void SaveCacheFromGUI( void );
   virtual void LoadCacheFromDiskToGUI( void );
   virtual void FillCacheGUIFromCacheManager( void );
   virtual void FillCacheManagerFromCacheGUI( void );
 
+private:  
+  virtual bool VerifyBinaryPath( const string & path ) const;
+  virtual bool VerifySourcePath( const string & path ) const;
+  virtual string ExpandPathAndMakeItAbsolute( const string & inputPath ) const;
+
 private:
   fltk::PropertyList   m_CacheEntriesList;
   std::string          m_WhereBuild;

+ 2 - 1
Source/FLTKDialog/FLTKPropertyItemRow.cxx

@@ -26,7 +26,8 @@ PropertyItemRow::PropertyItemRow( PropertyItem * pItem )
  
   Fl_Tile * group = new Fl_Tile(0,0,nameWidth+textWidth,rowHeight,"");
 
-  group->parent()->size( nameWidth + textWidth , 100 );
+  // Make the parent Fl_Pack widget at least a row wide.
+  group->parent()->size( nameWidth + textWidth , rowHeight );
 
   Fl_Button * name = new 
                 Fl_Button( firstColumn, 0, nameWidth, rowHeight,