Skip to content

Commit

Permalink
Merge pull request rstudio#3937 from rstudio/bugfix/theme-handler-reg…
Browse files Browse the repository at this point in the history
…istrations

clean up handler registrations on dismiss
  • Loading branch information
kevinushey authored Nov 26, 2018
2 parents 252bdff + 66d94d0 commit c407111
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
33 changes: 33 additions & 0 deletions src/gwt/src/org/rstudio/studio/client/common/Timers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Timers.java
*
* Copyright (C) 2009-18 by RStudio, Inc.
*
* 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.
*
*/
package org.rstudio.studio.client.common;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Timer;

public class Timers
{
public static final void singleShot(int delayMs, final Command command)
{
new Timer()
{
@Override
public void run()
{
command.execute();
}
}.schedule(delayMs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ public void initialize(final SourceDocument document,
extendedType_,
fileType_);

themeHelper_ = new TextEditingTargetThemeHelper(this, events_);
themeHelper_ = new TextEditingTargetThemeHelper(this, events_, releaseOnDismiss_);

docUpdateSentinel_ = new DocUpdateSentinel(
server_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,40 @@
*/
package org.rstudio.studio.client.workbench.views.source.editors.text;

import java.util.ArrayList;

import org.rstudio.core.client.dom.DomUtils;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.common.Timers;
import org.rstudio.studio.client.workbench.views.source.editors.text.events.EditorThemeChangedEvent;
import org.rstudio.studio.client.workbench.views.source.editors.text.events.EditorThemeStyleChangedEvent;

import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Widget;

public class TextEditingTargetThemeHelper
{
public TextEditingTargetThemeHelper(final TextEditingTarget editingTarget,
final EventBus eventBus)
final EventBus eventBus,
final ArrayList<HandlerRegistration> releaseOnDismiss)
{
// do an initial sync after 100ms (to allow initial render)
new Timer() {
@Override
public void run()
{
// do the sync
syncToEditorTheme(editingTarget);

// register for notification on subsquent changes
eventBus.addHandler(
EditorThemeChangedEvent.TYPE,
new EditorThemeChangedEvent.Handler()
{
@Override
public void onEditorThemeChanged(EditorThemeChangedEvent e)
{
syncToEditorTheme(editingTarget);
}
});
}
}.schedule(100);;
Timers.singleShot(100, () -> {

// do the sync
syncToEditorTheme(editingTarget);

// register for notification on subsquent changes
releaseOnDismiss.add(
eventBus.addHandler(
EditorThemeChangedEvent.TYPE,
(EditorThemeChangedEvent e) -> {
syncToEditorTheme(editingTarget);
}));
});
}

public HandlerRegistration addEditorThemeStyleChangedHandler(
Expand Down

0 comments on commit c407111

Please sign in to comment.