Skip to content

Commit

Permalink
ensure documents are synchronized with the source database on popout/in
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcphers committed Aug 20, 2015
1 parent bcfc7e6 commit aab0b6b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
Expand Up @@ -1618,8 +1618,26 @@ public void onPopoutDocInitiated(final PopoutDocInitiatedEvent event)
@Override
public void execute(EditingTarget editor)
{
events_.fireEvent(new PopoutDocEvent(event,
editor.currentPosition()));
// if this is a text editor, ensure that its content is
// synchronized with the server before we pop it out
if (editor instanceof TextEditingTarget)
{
final TextEditingTarget textEditor = (TextEditingTarget)editor;
textEditor.withSavedDoc(new Command()
{
@Override
public void execute()
{
events_.fireEvent(new PopoutDocEvent(event,
textEditor.currentPosition()));
}
});
}
else
{
events_.fireEvent(new PopoutDocEvent(event,
editor.currentPosition()));
}
}
});
}
Expand Down
Expand Up @@ -2809,35 +2809,55 @@ void onPopoutDoc()
{
if (docUpdateSentinel_ != null)
{
// sync doc contents before popping it out
SourceWindowManager manager =
RStudioGinjector.INSTANCE.getSourceWindowManager();
JsArray<SourceDocument> docs = manager.getSourceDocs();
for (int i = 0; i < docs.length(); i++)
// ensure doc is synchronized with source database before popping it
// out
docUpdateSentinel_.withSavedDoc(new Command()
{
if (docs.get(i).getId() == getId())
@Override
public void execute()
{
docs.get(i).setContents(docUpdateSentinel_.getContents());
docs.get(i).setDirty(dirtyState_.getValue());
break;
// push the new doc state into the source database that the
// new window will inherit
SourceWindowManager manager =
RStudioGinjector.INSTANCE.getSourceWindowManager();
JsArray<SourceDocument> docs = manager.getSourceDocs();
for (int i = 0; i < docs.length(); i++)
{
if (docs.get(i).getId() == getId())
{
docs.get(i).setContents(docDisplay_.getCode());
docs.get(i).setDirty(dirtyState_.getValue());
break;
}
}

// fire popout event (this triggers a close in the current window
// and the creation of a new window with the doc)
events_.fireEvent(new PopoutDocEvent(getId(),
currentPosition()));
}
}

// fire popout event (this triggers a close in the current window
// and the creation of a new window with the doc)
events_.fireEvent(new PopoutDocEvent(getId(), currentPosition()));
});
}
}


@Handler
void onReturnDocToMain()
{
// ensure doc is synchronized with source database before returning it
if (!SourceWindowManager.isMainSourceWindow() &&
docUpdateSentinel_ != null)
{
events_.fireEventToMainWindow(new DocWindowChangedEvent(
getId(), SourceWindowManager.getSourceWindowId(), "",
DocTabDragParams.create(getId(), currentPosition()), 0));
docUpdateSentinel_.withSavedDoc(new Command()
{
@Override
public void execute()
{
events_.fireEventToMainWindow(new DocWindowChangedEvent(
getId(), SourceWindowManager.getSourceWindowId(), "",
DocTabDragParams.create(getId(), currentPosition()), 0));
}
});
}
}

Expand Down

0 comments on commit aab0b6b

Please sign in to comment.