You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
6.7 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file eda_doc.cpp
  26. */
  27. #include <pgm_base.h>
  28. #include <confirm.h>
  29. #include <gestfich.h>
  30. #include <settings/common_settings.h>
  31. #include <wx/mimetype.h>
  32. #include <wx/tokenzr.h>
  33. #include <wx/filename.h>
  34. #include <wx/uri.h>
  35. #include <wx/filedlg.h>
  36. void PGM_BASE::ReadPdfBrowserInfos()
  37. {
  38. SetPdfBrowserName( GetCommonSettings()->m_System.pdf_viewer_name );
  39. m_use_system_pdf_browser = GetCommonSettings()->m_System.use_system_pdf_viewer;
  40. }
  41. void PGM_BASE::WritePdfBrowserInfos()
  42. {
  43. GetCommonSettings()->m_System.pdf_viewer_name = GetPdfBrowserName();
  44. GetCommonSettings()->m_System.use_system_pdf_viewer = m_use_system_pdf_browser;
  45. }
  46. // Mime type extensions (PDF files are not considered here)
  47. static wxMimeTypesManager* mimeDatabase;
  48. static const wxFileTypeInfo EDAfallbacks[] =
  49. {
  50. wxFileTypeInfo( wxT( "text/html" ),
  51. wxT( "wxhtml %s" ),
  52. wxT( "wxhtml %s" ),
  53. wxT( "html document (from KiCad)" ),
  54. wxT( "htm" ),
  55. wxT( "html" ),wxNullPtr ),
  56. wxFileTypeInfo( wxT( "application/sch" ),
  57. wxT( "eeschema %s" ),
  58. wxT( "eeschema -p %s" ),
  59. wxT( "sch document (from KiCad)" ),
  60. wxT( "sch" ),
  61. wxT( "SCH" ), wxNullPtr ),
  62. // must terminate the table with this!
  63. wxFileTypeInfo()
  64. };
  65. bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, PROJECT* aProject )
  66. {
  67. SEARCH_STACK* aPaths = nullptr;
  68. wxString docname;
  69. wxString fullfilename;
  70. wxString msg;
  71. wxString command;
  72. bool success = false;
  73. #if defined(EESCHEMA)
  74. SEARCH_STACK* aPaths = aProject ? aProject->SchSearchS() : nullptr;
  75. #endif
  76. // Is an internet url
  77. static const wxChar* url_header[] = {
  78. wxT( "http:" ),
  79. wxT( "https:" ),
  80. wxT( "ftp:" ),
  81. wxT( "www." ),
  82. wxT( "file:" )
  83. };
  84. // Replace before resolving as we might have a URL in a variable
  85. docname = ResolveUriByEnvVars( aDocName, aProject );
  86. for( const wxString& proc : url_header)
  87. {
  88. if( docname.First( proc ) == 0 ) // looks like an internet url
  89. {
  90. wxURI uri( docname );
  91. wxLaunchDefaultBrowser( uri.BuildURI() );
  92. return true;
  93. }
  94. }
  95. #ifdef __WINDOWS__
  96. docname.Replace( UNIX_STRING_DIR_SEP, WIN_STRING_DIR_SEP );
  97. #else
  98. docname.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
  99. #endif
  100. /* Compute the full file name */
  101. if( wxIsAbsolutePath( docname ) || aPaths == NULL )
  102. fullfilename = docname;
  103. /* If the file exists, this is a trivial case: return the filename
  104. * "as this". the name can be an absolute path, or a relative path
  105. * like ./filename or ../<filename>
  106. */
  107. else if( wxFileName::FileExists( docname ) )
  108. fullfilename = docname;
  109. else
  110. fullfilename = aPaths->FindValidPath( docname );
  111. wxString mask( wxT( "*" ) ), extension;
  112. #ifdef __WINDOWS__
  113. mask += wxT( ".*" );
  114. extension = wxT( ".*" );
  115. #endif
  116. if( wxIsWild( fullfilename ) )
  117. {
  118. fullfilename = EDA_FILE_SELECTOR( _( "Doc Files" ),
  119. wxPathOnly( fullfilename ),
  120. fullfilename,
  121. extension,
  122. mask,
  123. aParent,
  124. wxFD_OPEN,
  125. true,
  126. wxPoint( -1, -1 ) );
  127. if( fullfilename.IsEmpty() )
  128. return false;
  129. }
  130. if( !wxFileExists( fullfilename ) )
  131. {
  132. msg.Printf( _( "Doc File \"%s\" not found" ), GetChars( docname ) );
  133. DisplayError( aParent, msg );
  134. return false;
  135. }
  136. wxFileName currentFileName( fullfilename );
  137. wxString file_ext = currentFileName.GetExt();
  138. if( file_ext.Lower() == wxT( "pdf" ) )
  139. {
  140. success = OpenPDF( fullfilename );
  141. return success;
  142. }
  143. /* Try to launch some browser (useful under linux) */
  144. wxFileType* filetype;
  145. wxString type;
  146. filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( file_ext );
  147. if( !filetype ) // 2nd attempt.
  148. {
  149. mimeDatabase = new wxMimeTypesManager;
  150. mimeDatabase->AddFallbacks( EDAfallbacks );
  151. filetype = mimeDatabase->GetFileTypeFromExtension( file_ext );
  152. delete mimeDatabase;
  153. mimeDatabase = NULL;
  154. }
  155. if( filetype )
  156. {
  157. wxFileType::MessageParameters params( fullfilename, type );
  158. success = filetype->GetOpenCommand( &command, params );
  159. delete filetype;
  160. if( success )
  161. success = ProcessExecute( command );
  162. }
  163. if( !success )
  164. {
  165. msg.Printf( _( "Unknown MIME type for doc file \"%s\"" ), GetChars( fullfilename ) );
  166. DisplayError( aParent, msg );
  167. }
  168. return success;
  169. }
  170. bool KeywordMatch( const wxString& aKeys, const wxString& aDatabase )
  171. {
  172. if( aKeys.IsEmpty() )
  173. return false;
  174. wxStringTokenizer keyTokenizer( aKeys, wxT( ", \t\n\r" ), wxTOKEN_STRTOK );
  175. while( keyTokenizer.HasMoreTokens() )
  176. {
  177. wxString key = keyTokenizer.GetNextToken();
  178. // Search for key in aDatabase:
  179. wxStringTokenizer dataTokenizer( aDatabase, wxT( ", \t\n\r" ), wxTOKEN_STRTOK );
  180. while( dataTokenizer.HasMoreTokens() )
  181. {
  182. if( dataTokenizer.GetNextToken() == key )
  183. return true;
  184. }
  185. }
  186. // keyword not found
  187. return false;
  188. }