Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rstudio/rstudio
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Nov 30, 2011
2 parents 41da5bb + 5aafa0a commit fcf77b3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 54 deletions.
28 changes: 2 additions & 26 deletions src/gwt/src/org/rstudio/core/client/command/ShortcutManager.java
Expand Up @@ -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
Expand Down Expand Up @@ -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<AppCommand> commands)
{
activeCommands_ = new HashMap<KeyboardShortcut, AppCommand>();

for (Entry<KeyboardShortcut,AppCommand> entry : commands_.entrySet())
{
if (commands.contains(entry.getValue()))
activeCommands_.put(entry.getKey(), entry.getValue());
}
}

public void register(int modifiers, int keyCode, AppCommand command)
{
Expand Down Expand Up @@ -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<KeyboardShortcut, AppCommand> 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();
Expand All @@ -141,6 +118,5 @@ private boolean handleKeyDown(NativeEvent e)
private int disableCount_ = 0;
private final HashMap<KeyboardShortcut, AppCommand> commands_
= new HashMap<KeyboardShortcut, AppCommand>();

private HashMap<KeyboardShortcut, AppCommand> activeCommands_ = null;

}
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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()
Expand Down
Expand Up @@ -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;
Expand All @@ -33,11 +37,13 @@ public abstract class SatelliteWindow extends Composite
ProvidesResize
{
public SatelliteWindow(Provider<EventBus> pEventBus,
Provider<FontSizeManager> pFontSizeManager)
Provider<FontSizeManager> pFontSizeManager,
Provider<Commands> pCommands)
{
// save references
pEventBus_ = pEventBus;
pFontSizeManager_ = pFontSizeManager;
pCommands_ = pCommands;

// occupy full client area of the window
Window.enableScrolling(false);
Expand All @@ -53,7 +59,15 @@ public SatelliteWindow(Provider<EventBus> 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()
Expand Down Expand Up @@ -87,5 +101,6 @@ protected LayoutPanel getMainPanel()

private final Provider<EventBus> pEventBus_;
private final Provider<FontSizeManager> pFontSizeManager_;
private final Provider<Commands> pCommands_;
private LayoutPanel mainPanel_;
}
Expand Up @@ -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;
Expand Down Expand Up @@ -52,7 +50,7 @@ public VCSApplicationWindow(Provider<GitPresenterCore> pVCSCore,
Provider<FontSizeManager> pFontSizeManager,
Session session)
{
super(pEventBus, pFontSizeManager);
super(pEventBus, pFontSizeManager, pCommands);
pVCSCore_ = pVCSCore;
pReviewPresenter_ = pReviewPresenter;
pHistoryPresenter_ = pHistoryPresenter;
Expand All @@ -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<AppCommand> activeCommands = new ArrayList<AppCommand>();
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();
Expand Down
Expand Up @@ -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"/>
<cmd id="closeSourceDoc"
menuLabel="_Close"/>
menuLabel="_Close"
enabled="false"
preventShortcutWhenDisabled="org.rstudio.studio.client.application.Desktop.isDesktop()"/>
<cmd id="closeAllSourceDocs"
menuLabel="Close All"/>
<cmd id="printSourceDoc"
Expand Down
Expand Up @@ -210,14 +210,6 @@ public Source(Commands commands,
commands.findReplace().setShortcut(new KeyboardShortcut(mod, 'F'));
commands.goToFunctionDefinition().setShortcut(new KeyboardShortcut(113));


// allow Ctrl+W to propagate to the browser if close doc is disabled
if (!Desktop.isDesktop())
{
AppCommand closeSourceDoc = commands_.closeSourceDoc();
closeSourceDoc.setPreventShortcutWhenDisabled(false);
}

events.addHandler(ShowContentEvent.TYPE, this);
events.addHandler(ShowDataEvent.TYPE, this);

Expand Down
Expand Up @@ -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(
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit fcf77b3

Please sign in to comment.