Skip to content

Commit 7148b50

Browse files
committed
Merge branch 'master' of github.com:rstudio/rstudio
2 parents de9c2ae + 641a8e8 commit 7148b50

File tree

4 files changed

+117
-15
lines changed

4 files changed

+117
-15
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* ConsoleHistoryAddedEvent.java
3+
*
4+
* Copyright (C) 2009-16 by RStudio, Inc.
5+
*
6+
* Unless you have received this program directly from RStudio pursuant
7+
* to the terms of a commercial license agreement with RStudio, then
8+
* this program is licensed to you under the terms of version 3 of the
9+
* GNU Affero General Public License. This program is distributed WITHOUT
10+
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11+
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12+
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13+
*
14+
*/
15+
package org.rstudio.studio.client.workbench.views.console.events;
16+
17+
import org.rstudio.core.client.js.JavaScriptSerializable;
18+
import org.rstudio.studio.client.application.events.CrossWindowEvent;
19+
20+
import com.google.gwt.event.shared.EventHandler;
21+
import com.google.gwt.event.shared.GwtEvent;
22+
23+
@JavaScriptSerializable
24+
public class ConsoleHistoryAddedEvent
25+
extends CrossWindowEvent<ConsoleHistoryAddedEvent.Handler>
26+
{
27+
public static final GwtEvent.Type<ConsoleHistoryAddedEvent.Handler> TYPE =
28+
new GwtEvent.Type<ConsoleHistoryAddedEvent.Handler>();
29+
30+
public interface Handler extends EventHandler
31+
{
32+
void onConsoleHistoryAdded(ConsoleHistoryAddedEvent event);
33+
}
34+
35+
public ConsoleHistoryAddedEvent()
36+
{
37+
}
38+
39+
public ConsoleHistoryAddedEvent(String code)
40+
{
41+
code_ = code;
42+
}
43+
44+
public String getCode()
45+
{
46+
return code_;
47+
}
48+
49+
@Override
50+
public Type<ConsoleHistoryAddedEvent.Handler> getAssociatedType()
51+
{
52+
return TYPE;
53+
}
54+
55+
@Override
56+
protected void dispatch(Handler handler)
57+
{
58+
handler.onConsoleHistoryAdded(this);
59+
}
60+
61+
private String code_;
62+
}

src/gwt/src/org/rstudio/studio/client/workbench/views/console/shell/Shell.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363

6464
import java.util.ArrayList;
6565

66-
public class Shell implements ConsoleInputHandler,
66+
public class Shell implements ConsoleHistoryAddedEvent.Handler,
67+
ConsoleInputHandler,
6768
ConsoleWriteOutputHandler,
6869
ConsoleWriteErrorHandler,
6970
ConsoleWritePromptHandler,
@@ -135,6 +136,7 @@ public void execute(String value)
135136
view_.addCapturingKeyDownHandler(handler) ;
136137
view_.addKeyPressHandler(handler) ;
137138

139+
eventBus.addHandler(ConsoleHistoryAddedEvent.TYPE, this);
138140
eventBus.addHandler(ConsoleInputEvent.TYPE, this);
139141
eventBus.addHandler(ConsoleWriteOutputEvent.TYPE, this);
140142
eventBus.addHandler(ConsoleWriteErrorEvent.TYPE, this);
@@ -336,7 +338,7 @@ private void processCommandEntry()
336338
{
337339
String commandText = view_.processCommandEntry() ;
338340
if (addToHistory_ && (commandText.length() > 0))
339-
addToHistory(commandText);
341+
eventBus_.fireEvent(new ConsoleHistoryAddedEvent(commandText));
340342

341343
// fire event
342344
eventBus_.fireEvent(new ConsoleInputEvent(commandText, ""));
@@ -436,6 +438,15 @@ public void onError(ServerError error)
436438
});
437439
}
438440

441+
@Override
442+
public void onConsoleHistoryAdded(ConsoleHistoryAddedEvent event)
443+
{
444+
if (isBrowsePrompt())
445+
browseHistoryManager_.addToHistory(event.getCode());
446+
else
447+
historyManager_.addToHistory(event.getCode());
448+
}
449+
439450
private final class InputKeyDownHandler implements KeyDownHandler,
440451
KeyPressHandler
441452
{
@@ -580,14 +591,6 @@ private void resetHistoryPosition()
580591
browseHistoryManager_.resetPosition();
581592
}
582593

583-
private void addToHistory(String commandText)
584-
{
585-
if (isBrowsePrompt())
586-
browseHistoryManager_.addToHistory(commandText);
587-
else
588-
historyManager_.addToHistory(commandText);
589-
}
590-
591594
private String getHistoryEntry(int offset)
592595
{
593596
if (isBrowsePrompt())

src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/EditingTargetCodeExecution.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,24 @@ public void executeLastCode()
209209
String code = lastExecutedCode_.getValue();
210210
if (code != null && code.trim().length() > 0)
211211
{
212-
events_.fireEvent(new SendToConsoleEvent(code, true));
212+
// if in notebook mode, we want to execute the code inside the
213+
// chunk rather than at the console
214+
Scope scope = null;
215+
if (docDisplay_.showChunkOutputInline())
216+
{
217+
scope = docDisplay_.getCurrentChunk(
218+
lastExecutedCode_.getRange().getStart());
219+
}
220+
221+
if (scope == null)
222+
{
223+
events_.fireEvent(new SendToConsoleEvent(code, true));
224+
}
225+
else
226+
{
227+
events_.fireEvent(new SendToChunkConsoleEvent(docId_,
228+
scope, code));
229+
}
213230
}
214231
}
215232
}

src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/rmd/TextEditingTargetNotebook.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.rstudio.studio.client.workbench.model.Session;
5353
import org.rstudio.studio.client.workbench.prefs.model.UIPrefs;
5454
import org.rstudio.studio.client.workbench.views.console.ConsoleResources;
55+
import org.rstudio.studio.client.workbench.views.console.events.ConsoleHistoryAddedEvent;
5556
import org.rstudio.studio.client.workbench.views.console.events.ConsoleWriteInputEvent;
5657
import org.rstudio.studio.client.workbench.views.console.events.ConsoleWriteInputHandler;
5758
import org.rstudio.studio.client.workbench.views.console.model.ConsoleServerOperations;
@@ -652,8 +653,7 @@ public void onSendToChunkConsole(final SendToChunkConsoleEvent event)
652653
public void onResponseReceived(RmdChunkOptions options)
653654
{
654655
// execute the input
655-
console_.consoleInput(event.getCode(), chunkDef.getChunkId(),
656-
new VoidServerRequestCallback());
656+
executeCodeChunk(event.getCode(), chunkDef.getChunkId());
657657
}
658658
@Override
659659
public void onError(ServerError error)
@@ -1241,8 +1241,7 @@ public void onResponseReceived(RmdChunkOptions options)
12411241
{
12421242
outputs_.get(unit.chunkId).setOptions(options);
12431243
}
1244-
console_.consoleInput(unit.code, unit.chunkId,
1245-
new VoidServerRequestCallback());
1244+
executeCodeChunk(unit.code, unit.chunkId);
12461245
}
12471246
}
12481247

@@ -1824,6 +1823,27 @@ public void run()
18241823
}
18251824
};
18261825

1826+
private void executeCodeChunk(final String code, final String chunkId)
1827+
{
1828+
console_.consoleInput(code, chunkId,
1829+
new ServerRequestCallback<Void>()
1830+
{
1831+
@Override
1832+
public void onResponseReceived(Void v)
1833+
{
1834+
// add the code into the history once it's been successfully
1835+
// sent to the server
1836+
events_.fireEvent(new ConsoleHistoryAddedEvent(code));
1837+
}
1838+
1839+
@Override
1840+
public void onError(ServerError error)
1841+
{
1842+
Debug.logError(error);
1843+
}
1844+
});
1845+
}
1846+
18271847
private JsArray<ChunkDefinition> initialChunkDefs_;
18281848
private HashMap<String, ChunkOutputUi> outputs_;
18291849
private LinkedList<ChunkExecQueueUnit> chunkExecQueue_;

0 commit comments

Comments
 (0)