PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llexternaleditor.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 105 lines | 28 code | 16 blank | 61 comment | 0 complexity | 85ddd4a05f283e28b43a558b3688f352 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llexternaleditor.h
  3. * @brief A convenient class to run external editor.
  4. *
  5. * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLEXTERNALEDITOR_H
  27. #define LL_LLEXTERNALEDITOR_H
  28. #include <llprocesslauncher.h>
  29. /**
  30. * Usage:
  31. * LLExternalEditor ed;
  32. * ed.setCommand("MY_EXTERNAL_EDITOR_VAR");
  33. * ed.run("/path/to/file1");
  34. * ed.run("/other/path/to/file2");
  35. */
  36. class LLExternalEditor
  37. {
  38. typedef std::vector<std::string> string_vec_t;
  39. public:
  40. typedef enum e_error_code {
  41. EC_SUCCESS, /// No error.
  42. EC_NOT_SPECIFIED, /// Editor path not specified.
  43. EC_PARSE_ERROR, /// Editor command parsing error.
  44. EC_BINARY_NOT_FOUND, /// Could find the editor binary (missing or not quoted).
  45. EC_FAILED_TO_RUN, /// Could not execute the editor binary.
  46. } EErrorCode;
  47. /**
  48. * Set editor command.
  49. *
  50. * @param env_var Environment variable of the same purpose.
  51. * @param override Optional override.
  52. *
  53. * First tries the override, then a predefined setting (sSetting),
  54. * then the environment variable.
  55. *
  56. * @return EC_SUCCESS if command is valid and refers to an existing executable,
  57. * EC_NOT_SPECIFIED or EC_FAILED_TO_RUNan on error.
  58. *
  59. * @see sSetting
  60. */
  61. EErrorCode setCommand(const std::string& env_var, const std::string& override = LLStringUtil::null);
  62. /**
  63. * Run the editor with the given file.
  64. *
  65. * @param file_path File to edit.
  66. * @return EC_SUCCESS on success, error code on error.
  67. */
  68. EErrorCode run(const std::string& file_path);
  69. /**
  70. * Get a meaningful error message for the given status code.
  71. */
  72. static std::string getErrorMessage(EErrorCode code);
  73. private:
  74. static std::string findCommand(
  75. const std::string& env_var,
  76. const std::string& override);
  77. static size_t tokenize(string_vec_t& tokens, const std::string& str);
  78. /**
  79. * Filename placeholder that gets replaced with an actual file name.
  80. */
  81. static const std::string sFilenameMarker;
  82. /**
  83. * Setting that can specify the editor command.
  84. */
  85. static const std::string sSetting;
  86. std::string mArgs;
  87. LLProcessLauncher mProcess;
  88. };
  89. #endif // LL_LLEXTERNALEDITOR_H