From e0b7042afd7279b442c7b375cb1a8ac39f89d6d5 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Tue, 29 Nov 2011 17:50:36 -0800 Subject: [PATCH 1/4] Same fix for SVN review pane (needs refactor) --- .../vcs/svn/dialog/SVNReviewPresenter.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/gwt/src/org/rstudio/studio/client/workbench/views/vcs/svn/dialog/SVNReviewPresenter.java b/src/gwt/src/org/rstudio/studio/client/workbench/views/vcs/svn/dialog/SVNReviewPresenter.java index b82ddb02fec..adb45c6c79f 100644 --- a/src/gwt/src/org/rstudio/studio/client/workbench/views/vcs/svn/dialog/SVNReviewPresenter.java +++ b/src/gwt/src/org/rstudio/studio/client/workbench/views/vcs/svn/dialog/SVNReviewPresenter.java @@ -25,6 +25,7 @@ import com.google.gwt.user.client.ui.HasValue; import com.google.gwt.user.client.ui.IsWidget; import com.google.gwt.user.client.ui.Widget; +import com.google.gwt.view.client.RowCountChangeEvent; import com.google.gwt.view.client.SelectionChangeEvent; import com.google.inject.Inject; import org.rstudio.core.client.Invalidation; @@ -218,6 +219,20 @@ public void onSelectionChange(SelectionChangeEvent event) updateDiff(); } }); + view_.getChangelistTable().addRowCountChangeHandler(new RowCountChangeEvent.Handler() + { + @Override + public void onRowCountChange(RowCountChangeEvent event) + { + // This is necessary because during initial load, the selection + // model has its selection set before any items are loaded into + // the table (so therefore view_.getSelectedPaths().size() is always + // 0, and the files commands are not enabled until selection changes + // again). By updating the files commands' enabled state on row + // count change as well, we can make sure they get enabled. + view_.setFilesCommandsEnabled(view_.getSelectedPaths().size() > 0); + } + }); view_.getChangelistTable().addContextMenuHandler(new ContextMenuHandler() { @@ -243,8 +258,8 @@ public void onClick(ClickEvent event) globalDisplay_.showYesNoMessage( GlobalDisplay.MSG_WARNING, "Revert Changes", - "Changes to the selected " + noun + " will be lost, including " + - "staged changes.\n\nAre you sure you want to continue?", + "Changes to the selected " + noun + " will be lost.\n\nAre " + + "you sure you want to continue?", new Operation() { @Override @@ -271,7 +286,7 @@ public void onClick(ClickEvent event) String which = view_.getLineTableDisplay() .getSelectedLines() .size() == 0 - ? "All unstaged" + ? "All " : "The selected"; globalDisplay.showYesNoMessage( GlobalDisplay.MSG_WARNING, From 4ecc62ef3f8f6830f0a2e00a3ac1d0da8ae83cd3 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Wed, 30 Nov 2011 10:02:47 -0800 Subject: [PATCH 2/4] Fix null pointer exception --- .../client/workbench/views/source/editors/text/AceEditor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/AceEditor.java b/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/AceEditor.java index d0598ead284..4859035f8a2 100644 --- a/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/AceEditor.java +++ b/src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/AceEditor.java @@ -268,7 +268,7 @@ public void onClick(AceClickEvent event) private void indentPastedRange(Range range) { - if (!fileType_.canAutoIndent()) + if (fileType_ == null || !fileType_.canAutoIndent()) return; String firstLinePrefix = getSession().getTextRange( From 1cd4094d26e36ec830e68ab3e7a05d509ea89b94 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Wed, 30 Nov 2011 10:40:54 -0800 Subject: [PATCH 3/4] Revert "enable filtering of the set of commands supported by the shortcut manager (for satellite windows)" This reverts commit 8306a5275d1f75f4f7bfe33a10a6b8ad9bd5874f. --- .../core/client/command/ShortcutManager.java | 28 ++----------------- .../common/satellite/SatelliteWindow.java | 19 +++++++++++-- .../client/vcs/ui/VCSApplicationWindow.java | 13 +-------- 3 files changed, 20 insertions(+), 40 deletions(-) diff --git a/src/gwt/src/org/rstudio/core/client/command/ShortcutManager.java b/src/gwt/src/org/rstudio/core/client/command/ShortcutManager.java index ceb0543d786..691a9341b1d 100644 --- a/src/gwt/src/org/rstudio/core/client/command/ShortcutManager.java +++ b/src/gwt/src/org/rstudio/core/client/command/ShortcutManager.java @@ -20,9 +20,7 @@ import org.rstudio.core.client.events.NativeKeyDownEvent; import org.rstudio.core.client.events.NativeKeyDownHandler; -import java.util.ArrayList; import java.util.HashMap; -import java.util.Map.Entry; public class ShortcutManager implements NativePreviewHandler, NativeKeyDownHandler @@ -60,22 +58,6 @@ public void close() } }; } - - // instruct the shortcut manager to support only a subset of the commands - // in the system -- this is here for satellite windows who don't want - // keystrokes they aren't concerned with handled (and thus commands with - // no handlers executed) but still want some subset of commands to have - // active keyboard shortcuts - public void setActiveCommands(ArrayList commands) - { - activeCommands_ = new HashMap(); - - for (Entry entry : commands_.entrySet()) - { - if (commands.contains(entry.getValue())) - activeCommands_.put(entry.getKey(), entry.getValue()); - } - } public void register(int modifiers, int keyCode, AppCommand command) { @@ -110,16 +92,11 @@ public void onPreviewNativeEvent(NativePreviewEvent event) private boolean handleKeyDown(NativeEvent e) { - // determine which group of commands to do the lookup in -- either - // the default set or (if specified) a subset of active commands - HashMap commands = - activeCommands_ != null ? activeCommands_ : commands_; - int modifiers = KeyboardShortcut.getModifierValue(e); KeyboardShortcut shortcut = new KeyboardShortcut(modifiers, e.getKeyCode()); - AppCommand command = commands.get(shortcut); + AppCommand command = commands_.get(shortcut); if (command != null) { boolean enabled = isEnabled() && command.isEnabled(); @@ -141,6 +118,5 @@ private boolean handleKeyDown(NativeEvent e) private int disableCount_ = 0; private final HashMap commands_ = new HashMap(); - - private HashMap activeCommands_ = null; + } diff --git a/src/gwt/src/org/rstudio/studio/client/common/satellite/SatelliteWindow.java b/src/gwt/src/org/rstudio/studio/client/common/satellite/SatelliteWindow.java index c54631609e8..5be708fa313 100644 --- a/src/gwt/src/org/rstudio/studio/client/common/satellite/SatelliteWindow.java +++ b/src/gwt/src/org/rstudio/studio/client/common/satellite/SatelliteWindow.java @@ -12,10 +12,14 @@ */ package org.rstudio.studio.client.common.satellite; + +import org.rstudio.core.client.command.AppCommand; import org.rstudio.core.client.widget.FontSizer; +import org.rstudio.studio.client.application.Desktop; import org.rstudio.studio.client.application.events.ChangeFontSizeEvent; import org.rstudio.studio.client.application.events.ChangeFontSizeHandler; import org.rstudio.studio.client.application.events.EventBus; +import org.rstudio.studio.client.workbench.commands.Commands; import org.rstudio.studio.client.workbench.ui.FontSizeManager; import com.google.gwt.core.client.JavaScriptObject; @@ -33,11 +37,13 @@ public abstract class SatelliteWindow extends Composite ProvidesResize { public SatelliteWindow(Provider pEventBus, - Provider pFontSizeManager) + Provider pFontSizeManager, + Provider pCommands) { // save references pEventBus_ = pEventBus; pFontSizeManager_ = pFontSizeManager; + pCommands_ = pCommands; // occupy full client area of the window Window.enableScrolling(false); @@ -53,7 +59,15 @@ public SatelliteWindow(Provider pEventBus, // show the satellite window (subclasses shouldn't override this method, // rather they should override the abstract onInitialize method) public void show(JavaScriptObject params) - { + { + // allow Ctrl+W to propagate to the browser if close doc is disabled + if (!Desktop.isDesktop()) + { + AppCommand closeSourceDoc = pCommands_.get().closeSourceDoc(); + closeSourceDoc.setEnabled(false); + closeSourceDoc.setPreventShortcutWhenDisabled(false); + } + // react to font size changes EventBus eventBus = pEventBus_.get(); eventBus.addHandler(ChangeFontSizeEvent.TYPE, new ChangeFontSizeHandler() @@ -87,5 +101,6 @@ protected LayoutPanel getMainPanel() private final Provider pEventBus_; private final Provider pFontSizeManager_; + private final Provider pCommands_; private LayoutPanel mainPanel_; } diff --git a/src/gwt/src/org/rstudio/studio/client/vcs/ui/VCSApplicationWindow.java b/src/gwt/src/org/rstudio/studio/client/vcs/ui/VCSApplicationWindow.java index 85377cbd759..f088ebe56f3 100644 --- a/src/gwt/src/org/rstudio/studio/client/vcs/ui/VCSApplicationWindow.java +++ b/src/gwt/src/org/rstudio/studio/client/vcs/ui/VCSApplicationWindow.java @@ -15,8 +15,6 @@ import java.util.ArrayList; -import org.rstudio.core.client.command.AppCommand; -import org.rstudio.core.client.command.ShortcutManager; import org.rstudio.studio.client.application.events.EventBus; import org.rstudio.studio.client.common.satellite.SatelliteWindow; import org.rstudio.studio.client.common.vcs.StatusAndPath; @@ -52,7 +50,7 @@ public VCSApplicationWindow(Provider pVCSCore, Provider pFontSizeManager, Session session) { - super(pEventBus, pFontSizeManager); + super(pEventBus, pFontSizeManager, pCommands); pVCSCore_ = pVCSCore; pReviewPresenter_ = pReviewPresenter; pHistoryPresenter_ = pHistoryPresenter; @@ -68,15 +66,6 @@ protected void onInitialize(LayoutPanel mainPanel, // set our window title Window.setTitle("Review Changes"); - // inform the shortcut manager of the subset of commands we want - // shortcuts active for - Commands commands = pCommands_.get(); - ArrayList activeCommands = new ArrayList(); - activeCommands.add(commands.vcsRefresh()); - activeCommands.add(commands.vcsPull()); - activeCommands.add(commands.vcsPush()); - ShortcutManager.INSTANCE.setActiveCommands(activeCommands); - // make sure vcs core is initialized if (session_.getSessionInfo().getVcsName().equalsIgnoreCase("git")) pVCSCore_.get(); From 5aafa0a4d244c95043d4ee50725dc6c885f41c8f Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Wed, 30 Nov 2011 11:10:04 -0800 Subject: [PATCH 4/4] preventShortcutWhenDisabled across windows --- .../core/rebind/command/CommandBundleGenerator.java | 4 +++- .../studio/client/workbench/commands/Commands.cmd.xml | 4 +++- .../studio/client/workbench/views/source/Source.java | 8 -------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/gwt/src/org/rstudio/core/rebind/command/CommandBundleGenerator.java b/src/gwt/src/org/rstudio/core/rebind/command/CommandBundleGenerator.java index 2638b2583b8..c592b5aa305 100644 --- a/src/gwt/src/org/rstudio/core/rebind/command/CommandBundleGenerator.java +++ b/src/gwt/src/org/rstudio/core/rebind/command/CommandBundleGenerator.java @@ -311,6 +311,8 @@ private void emitCommandInitializers(SourceWriter writer, setPropertyBool(writer, name, props.get(name), "visible"); setPropertyBool(writer, name, props.get(name), "enabled"); + setPropertyBool(writer, name, props.get(name), + "preventShortcutWhenDisabled"); if (images.hasImage(name)) { @@ -374,7 +376,7 @@ private void setPropertyBool(SourceWriter writer, String setter = "set" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); writer.println(name + "_." + setter - + "(" + Boolean.valueOf(value).toString() + ");"); + + "(" + value + ");"); } private ImageResourceInfo generateImageBundle() diff --git a/src/gwt/src/org/rstudio/studio/client/workbench/commands/Commands.cmd.xml b/src/gwt/src/org/rstudio/studio/client/workbench/commands/Commands.cmd.xml index 26d9f509259..ee394b0a607 100644 --- a/src/gwt/src/org/rstudio/studio/client/workbench/commands/Commands.cmd.xml +++ b/src/gwt/src/org/rstudio/studio/client/workbench/commands/Commands.cmd.xml @@ -372,7 +372,9 @@ well as menu structures (for main menu and popup menus). menuLabel="Save with Encoding..." desc="Save the current file with a different encoding"/> + menuLabel="_Close" + enabled="false" + preventShortcutWhenDisabled="org.rstudio.studio.client.application.Desktop.isDesktop()"/>