Skip to content

Commit

Permalink
Add diagnostic tools to get/set Ace contents
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Jan 6, 2012
1 parent 06ad436 commit 3bd0adc
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public HashSet<AppCommand> getSupportedCommands(Commands commands)
results.add(commands.findReplace());
results.add(commands.setWorkingDirToActiveDoc());
results.add(commands.debugForceTopsToZero());
results.add(commands.debugDumpContents());
results.add(commands.debugImportDump());
return results;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ well as menu structures (for main menu and popup menus).
<cmd refid="showRequestLog"/>
<separator/>
<cmd refid="debugForceTopsToZero"/>
<cmd refid="debugDumpContents"/>
<cmd refid="debugImportDump"/>
<!--
<cmd refid="raiseException"/>
- <cmd refid="raiseException2"/>
Expand Down Expand Up @@ -833,6 +835,10 @@ well as menu structures (for main menu and popup menus).
menuLabel="Log focused element"/>
<cmd id="debugForceTopsToZero"
menuLabel="Reset editor top value"/>
<cmd id="debugDumpContents"
menuLabel="Dump the raw contents of the editor"/>
<cmd id="debugImportDump"
menuLabel="Imports the raw contents of another editor"/>

<cmd id="quitSession"
menuLabel="_Quit R..."/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@
public abstract AppCommand showRequestLog();
public abstract AppCommand logFocusedElement();
public abstract AppCommand debugForceTopsToZero();
public abstract AppCommand debugDumpContents();
public abstract AppCommand debugImportDump();

// Application
public abstract AppCommand quitSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ public Source(Commands commands,
dynamicCommands_.add(commands.goToFunctionDefinition());
dynamicCommands_.add(commands.setWorkingDirToActiveDoc());
dynamicCommands_.add(commands.debugForceTopsToZero());
dynamicCommands_.add(commands.debugDumpContents());
dynamicCommands_.add(commands.debugImportDump());
dynamicCommands_.add(commands.goToLine());
for (AppCommand command : dynamicCommands_)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,18 @@ public void debug_forceTopsToZero()
widget_.getEditor().getRenderer().debug_forceTopsToZero();
}

@Override
public String debug_getDocumentDump()
{
return widget_.getEditor().getSession().getDocument().getDocumentDump();
}

@Override
public void debug_setSessionValueDirectly(String s)
{
widget_.getEditor().getSession().setValue(s);
}

public void setSelection(InputEditorSelection selection)
{
AceInputEditorPosition start = (AceInputEditorPosition)selection.getStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ DocDisplay.AnchoredSelection createAnchoredSelection(Position start,
String getLine(int row);

void debug_forceTopsToZero();
String debug_getDocumentDump();
void debug_setSessionValueDirectly(String s);
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public interface Display extends TextDisplay, HasEnsureVisibleHandlers
boolean isAttached();

void debug_forceTopsToZero();
void debug_dumpContents();
void debug_importDump();
}

private class SaveProgressIndicator implements ProgressIndicator
Expand Down Expand Up @@ -1058,6 +1060,18 @@ void onDebugForceTopsToZero()
view_.debug_forceTopsToZero();
}

@Handler
void onDebugDumpContents()
{
view_.debug_dumpContents();
}

@Handler
void onDebugImportDump()
{
view_.debug_importDump();
}

@Handler
void onReopenSourceDocWithEncoding()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.ResizeComposite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.*;
import org.rstudio.core.client.events.EnsureVisibleEvent;
import org.rstudio.core.client.events.EnsureVisibleHandler;
import org.rstudio.core.client.layout.RequiresVisibilityChanged;
import org.rstudio.core.client.theme.res.ThemeResources;
import org.rstudio.core.client.widget.Toolbar;
import org.rstudio.core.client.widget.ToolbarButton;
import org.rstudio.core.client.widget.ToolbarPopupMenu;
import org.rstudio.core.client.widget.InfoBar;
import org.rstudio.core.client.widget.*;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.common.filetypes.TextFileType;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.prefs.model.UIPrefs;
import org.rstudio.studio.client.workbench.views.edit.ui.EditDialog;
import org.rstudio.studio.client.workbench.views.source.PanelWithToolbars;
import org.rstudio.studio.client.workbench.views.source.editors.EditingTargetToolbar;
import org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget.Display;
Expand Down Expand Up @@ -234,6 +229,49 @@ public void debug_forceTopsToZero()
editor_.debug_forceTopsToZero();
}

@Override
public void debug_dumpContents()
{
String dump = editor_.debug_getDocumentDump();
new EditDialog(dump, false, false, new ProgressOperationWithInput<String>()
{
@Override
public void execute(String input, ProgressIndicator indicator)
{
indicator.onCompleted();
}
}).showModal();
}

@Override
public void debug_importDump()
{
new EditDialog("", false, false, new ProgressOperationWithInput<String>()
{
@Override
public void execute(String input, ProgressIndicator indicator)
{
indicator.onCompleted();
if (input == null)
return;

input = input.replaceAll("[ \\r\\n]+", " ");
String[] chars = input.split(" ");

StringBuilder sb = new StringBuilder();
for (String s : chars)
{
if (s.equals("."))
sb.append('\n');
else
sb.append((char)Integer.parseInt(s));
}

editor_.debug_setSessionValueDirectly(sb.toString());
}
}).showModal();
}

public HandlerRegistration addEnsureVisibleHandler(EnsureVisibleHandler handler)
{
return addHandler(handler, EnsureVisibleEvent.TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,22 @@ public native final String getLine(int row) /*-{
public native final int getLength() /*-{
return this.getLength();
}-*/;

public final String getDocumentDump()
{
StringBuilder output = new StringBuilder();
for (int i = 0; i < getLength(); i++)
{
String line = getLine(i);
for (int j = 0; j < line.length(); j++)
{
char c = line.charAt(j);
output.append((int)c);
output.append(' ');
}

output.append(". \n");
}
return output.toString();
}
}

0 comments on commit 3bd0adc

Please sign in to comment.