FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/session/modules/SessionAuthoring.cpp at master · pearsonca/rstudio · GitHub
pearsonca
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
session
/
modules
/
SessionAuthoring.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
238 lines (187 loc) · 6.24 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
session
/
modules
/
SessionAuthoring.cpp
Copy path
File metadata and controls
238 lines (187 loc) · 6.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
* SessionAuthoring.cpp
*
* Copyright (C) 2009-12 by RStudio, PBC
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
"
SessionAuthoring.hpp
"
#
include
<
string
>
#
include
<
boost/regex.hpp
>
#
include
<
core/Log.hpp
>
#
include
<
shared_core/Error.hpp
>
#
include
<
shared_core/FilePath.hpp
>
#
include
<
core/Exec.hpp
>
#
include
<
shared_core/SafeConvert.hpp
>
#
include
<
core/BrowserUtils.hpp
>
#
include
<
core/json/JsonRpc.hpp
>
#
include
<
r/RExec.hpp
>
#
include
<
r/RRoutines.hpp
>
#
include
<
session/SessionModuleContext.hpp
>
#
include
<
session/projects/SessionProjects.hpp
>
#
include
"
tex/SessionCompilePdf.hpp
"
#
include
"
tex/SessionRnwWeave.hpp
"
#
include
"
tex/SessionPdfLatex.hpp
"
#
include
"
tex/SessionCompilePdf.hpp
"
#
include
"
tex/SessionCompilePdfSupervisor.hpp
"
#
include
"
tex/SessionSynctex.hpp
"
#
include
"
tex/SessionViewPdf.hpp
"
using
namespace
rstudio
::core
;
namespace
rstudio
{
namespace
session
{
namespace
modules
{
namespace
authoring
{
namespace
{
FilePath
pdfFilePath
(
const
FilePath& texFilePath)
{
return
texFilePath.
getParent
().
completePath
(texFilePath.
getStem
() +
"
.pdf
"
);
}
void
viewPdfExternal
(
const
FilePath& texPath)
{
module_context::showFile
(
pdfFilePath
(texPath),
"
_rstudio_compile_pdf
"
);
}
Error
getTexCapabilities
(
const
core::json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
pResponse->
setResult
(
authoring::texCapabilitiesAsJson
());
return
Success
();
}
Error
getChunkOptions
(
const
json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
std::string weaveType;
Error error =
json::readParams
(request.
params
, &weaveType);
if
(error)
return
error;
pResponse->
setResult
(
tex::rnw_weave::chunkOptions
(weaveType));
return
Success
();
}
Error
isTexInstalled
(
const
json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
pResponse->
setResult
(
tex::pdflatex::isInstalled
());
return
Success
();
}
Error
compilePdf
(
const
json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
//
read params
std::string targetFile, encoding, completedAction;
json::Object sourceLocation;
Error error =
json::readParams
(request.
params
,
&targetFile,
&encoding,
&sourceLocation,
&completedAction);
if
(error)
return
error;
//
determine compilation target
FilePath targetFilePath =
module_context::resolveAliasedPath
(targetFile);
//
initialize the completed function
boost::function<
void
()> completedFunction;
if
(completedAction ==
"
view_external
"
)
completedFunction =
boost::bind
(viewPdfExternal, targetFilePath);
//
attempt to kickoff the compile
bool
started =
tex::compile_pdf::startCompile
(targetFilePath,
encoding,
sourceLocation,
completedFunction);
//
return true
pResponse->
setResult
(started);
return
Success
();
}
Error
isCompilePdfRunning
(
const
json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
pResponse->
setResult
(
tex::compile_pdf::compileIsRunning
());
return
Success
();
}
Error
terminateCompilePdf
(
const
json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
pResponse->
setResult
(
tex::compile_pdf::terminateCompile
());
return
Success
();
}
Error
compilePdfClosed
(
const
json::JsonRpcRequest& request,
json::JsonRpcResponse* pResponse)
{
tex::compile_pdf::notifyTabClosed
();
return
Success
();
}
SEXP
rs_rnwTangle
(
SEXP
filePathSEXP,
SEXP
encodingSEXP,
SEXP
rnwWeaveSEXP)
{
try
{
modules::tex::rnw_weave::runTangle
(
r::sexp::asString
(filePathSEXP),
r::sexp::asString
(encodingSEXP),
r::sexp::asString
(rnwWeaveSEXP));
}
catch
(
const
r::exec::RErrorException& e)
{
r::exec::error
(e.
message
());
}
CATCH_UNEXPECTED_EXCEPTION
return
R_NilValue;
}
}
//
anonymous namespace
json::Array
supportedRnwWeaveTypes
()
{
return
tex::rnw_weave::supportedTypes
();
}
json::Array
supportedLatexProgramTypes
()
{
return
tex::pdflatex::supportedTypes
();
}
json::Object
texCapabilitiesAsJson
()
{
json::Object obj;
obj[
"
tex_installed
"
] =
tex::pdflatex::isInstalled
();
tex::rnw_weave::getTypesInstalledStatus
(&obj);
return
obj;
}
bool
hasRunningChildren
()
{
return
tex::compile_pdf_supervisor::hasRunningChildren
();
}
json::Object
compilePdfStateAsJson
()
{
return
tex::compile_pdf::currentStateAsJson
();
}
Error
initialize
()
{
//
register tanble function
RS_REGISTER_CALL_METHOD
(rs_rnwTangle);
//
install rpc methods
using
boost::bind;
using
namespace
module_context
;
ExecBlock initBlock ;
initBlock.
addFunctions
()
(
bind
(sourceModuleRFile,
"
SessionAuthoring.R
"
))
(tex::compile_pdf::initialize)
(tex::compile_pdf_supervisor::initialize)
(tex::synctex::initialize)
(tex::view_pdf::initialize)
(
bind
(registerRpcMethod,
"
is_tex_installed
"
, isTexInstalled))
(
bind
(registerRpcMethod,
"
get_tex_capabilities
"
, getTexCapabilities))
(
bind
(registerRpcMethod,
"
get_chunk_options
"
, getChunkOptions))
(
bind
(registerRpcMethod,
"
compile_pdf
"
, compilePdf))
(
bind
(registerRpcMethod,
"
is_compile_pdf_running
"
, isCompilePdfRunning))
(
bind
(registerRpcMethod,
"
terminate_compile_pdf
"
, terminateCompilePdf))
(
bind
(registerRpcMethod,
"
compile_pdf_closed
"
, compilePdfClosed))
;
return
initBlock.
execute
();
}
}
//
namespace authoring
}
//
namespace modules
}
//
namespace session
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL