Skip to content

Commit

Permalink
Merge pull request #5874 from rstudio/feature/zoom-ide-columns
Browse files Browse the repository at this point in the history
add commands for zooming left/right UI columns
  • Loading branch information
gtritchie committed Dec 12, 2019
2 parents 82121af + 64b7f65 commit 5a3a39d
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 18 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -92,6 +92,7 @@
* Command to insert the full path and filename of current editor file into terminal
* Command in File pane to open a new terminal at File pane's current location
* Command in to change terminal to current RStudio working directory (#2363)
* Zoom Left/Right Column commands for keyboard users (#5874)

### Bugfixes

Expand Down
6 changes: 5 additions & 1 deletion src/gwt/src/org/rstudio/core/client/MathUtil.java
@@ -1,7 +1,7 @@
/*
* MathUtil.java
*
* Copyright (C) 2009-12 by RStudio, Inc.
* Copyright (C) 2009-19 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
Expand Down Expand Up @@ -47,4 +47,8 @@ public static boolean inRange(int value, int min, int max) {
return (value <= max) && (value >= min);
}

public static boolean isEqual(double d1, double d2, double threshold)
{
return Math.abs(d1 - d2) < threshold;
}
}
Expand Up @@ -270,7 +270,8 @@ well as menu structures (for main menu and popup menus).
<cmd refid="layoutConsoleOnLeft"/>
<cmd refid="layoutConsoleOnRight"/>
<separator/>
<cmd refid="paneLayout"/>
<cmd refid="layoutZoomLeftColumn"/>
<cmd refid="layoutZoomRightColumn"/>
<separator/>
<cmd refid="layoutZoomSource"/>
<cmd refid="layoutZoomConsole"/>
Expand All @@ -286,6 +287,8 @@ well as menu structures (for main menu and popup menus).
<cmd refid="layoutZoomTutorial"/>
<cmd refid="layoutZoomBuild"/>
<cmd refid="layoutZoomConnections"/>
<separator/>
<cmd refid="paneLayout"/>
</menu>

<separator/>
Expand Down Expand Up @@ -681,7 +684,7 @@ well as menu structures (for main menu and popup menus).
<shortcutgroup name="Panes">
<shortcut refid="switchFocusSourceConsole" value="Ctrl+X O|Ctrl+X Ctrl+O" disableModes="default,vim,sublime"/>
<shortcut refid="activateConsole" value="Alt+X" disableModes="default,vim,sublime"/>

<shortcut refid="activateSource" value="Ctrl+1"/>
<shortcut refid="activateConsole" value="Ctrl+2"/>
<shortcut refid="activateTerminal" value="Alt+Shift+T"/>
Expand Down Expand Up @@ -862,6 +865,8 @@ well as menu structures (for main menu and popup menus).
<shortcut refid="layoutZoomBuild" value="Ctrl+Shift+F2"/>
<shortcut refid="layoutZoomConnections" value="Ctrl+Shift+F5"/>
<shortcut refid="layoutZoomTutorial" value="Ctrl+Shift+F6"/>
<shortcut refid="layoutZoomLeftColumn" value="Ctrl+Alt+Shift+F12"/>
<shortcut refid="layoutZoomRightColumn" value="Ctrl+Alt+Shift+F11"/>
</shortcutgroup>

</shortcuts>
Expand Down Expand Up @@ -1450,10 +1455,20 @@ well as menu structures (for main menu and popup menus).
label="Console on Right"
menuLabel="Console on _Right"
windowMode="main"/>


<cmd id="layoutZoomLeftColumn"
checkable="true"
label="Zoom Left Column"
menuLabel="_Zoom Left Column"/>

<cmd id="layoutZoomRightColumn"
checkable="true"
label="Zoom Right Column"
menuLabel="Zoo_m Right Column"/>

<cmd id="paneLayout"
menuLabel="Pane Layo_ut..."
windowMode="main"/>
windowMode="main"/>

<cmd id="jumpTo"
label="Jump To..."
Expand Down
Expand Up @@ -608,7 +608,9 @@
public abstract AppCommand paneLayout();
public abstract AppCommand maximizeConsole();
public abstract AppCommand toggleEditorTokenInfo();

public abstract AppCommand layoutZoomLeftColumn();
public abstract AppCommand layoutZoomRightColumn();

// Main menu (server)
public abstract AppCommand showFileMenu();
public abstract AppCommand showEditMenu();
Expand Down
116 changes: 105 additions & 11 deletions src/gwt/src/org/rstudio/studio/client/workbench/ui/PaneManager.java
Expand Up @@ -30,6 +30,8 @@

import org.rstudio.core.client.Debug;
import org.rstudio.core.client.JsArrayUtil;
import org.rstudio.core.client.MathUtil;
import org.rstudio.core.client.StringUtil;
import org.rstudio.core.client.Triad;
import org.rstudio.core.client.command.AppCommand;
import org.rstudio.core.client.command.CommandBinder;
Expand Down Expand Up @@ -84,7 +86,10 @@ public enum Tab {
History, Files, Plots, Packages, Help, VCS, Tutorial, Build, Connections,
Presentation, Environment, Viewer, Source, Console
}


public static final String LEFT_COLUMN = "left";
public static final String RIGHT_COLUMN = "right";

class SelectedTabStateValue extends IntStateValue
{
SelectedTabStateValue(String name,
Expand Down Expand Up @@ -269,8 +274,8 @@ public PaneManager(Provider<MainSplitPanel> pSplitPanel,
int splitterSize = RStudioThemes.isFlat(userPrefs) ? 7 : 3;

panes_ = createPanes(config);
left_ = createSplitWindow(panes_.get(0), panes_.get(1), "left", 0.4, splitterSize);
right_ = createSplitWindow(panes_.get(2), panes_.get(3), "right", 0.6, splitterSize);
left_ = createSplitWindow(panes_.get(0), panes_.get(1), LEFT_COLUMN, 0.4, splitterSize);
right_ = createSplitWindow(panes_.get(2), panes_.get(3), RIGHT_COLUMN, 0.6, splitterSize);

panel_ = pSplitPanel.get();
panel_.initialize(left_, right_);
Expand Down Expand Up @@ -702,21 +707,27 @@ private void restoreFourPaneLayout()
// widgets to size themselves vertically.
for (LogicalWindow window : panes_)
window.onWindowStateChange(new WindowStateChangeEvent(WindowState.NORMAL, true));


restoreTwoColumnLayout();

}

private void restoreTwoColumnLayout()
{
double rightWidth = panel_.getWidgetSize(right_);
double panelWidth = panel_.getOffsetWidth();

double minThreshold = (2.0 / 5.0) * panelWidth;
double maxThreshold = (3.0 / 5.0) * panelWidth;

if (rightWidth <= minThreshold)
resizeHorizontally(rightWidth, minThreshold);
else if (rightWidth >= maxThreshold)
resizeHorizontally(rightWidth, maxThreshold);

invalidateSavedLayoutState(true);
}

private void restoreSavedLayout()
{
// Ensure that all windows are in the 'normal' state. This allows
Expand Down Expand Up @@ -885,7 +896,73 @@ public void zoomTab(Tab tab)

toggleWindowZoom(parentWindow, tab);
}


/**
* @return name of zoomed column, or null if no zoomed column; zoomed in this case means
* the splitter is dragged all the way to the left or right
*/
private String getZoomedColumn()
{
double currentColumnSize = panel_.getWidgetSize(right_);
if (MathUtil.isEqual(currentColumnSize, 0.0, 0.0001))
return LEFT_COLUMN;

double rightZoomPosition = panel_.getOffsetWidth();
if (MathUtil.isEqual(currentColumnSize, rightZoomPosition, 0.0001))
return RIGHT_COLUMN;

return null;
}

/**
* Zoom (or unzoom if invoked on an already-zoomed) column
*
* @param columnId
*/
public void zoomColumn(String columnId)
{
final double initialSize = panel_.getWidgetSize(right_);

String currentZoomedColumn = getZoomedColumn();
double targetSize;
boolean unZooming = false;

if (StringUtil.equals(currentZoomedColumn, columnId))
{
if (widgetSizePriorToZoom_ < 0)
{
// no prior position to restore to, just show defaults
restoreTwoColumnLayout();
return;
}
targetSize = widgetSizePriorToZoom_;
unZooming = true;
}
else if (StringUtil.equals(columnId, LEFT_COLUMN))
{
targetSize = 0;
}
else if (StringUtil.equals(columnId, RIGHT_COLUMN))
{
targetSize = panel_.getOffsetWidth();
}
else
{
Debug.logWarning("Unexpected column identifier: " + columnId);
return;
}

if (targetSize < 0)
targetSize = 0;

if (unZooming)
widgetSizePriorToZoom_ = -1;
else if (widgetSizePriorToZoom_ < 0)
widgetSizePriorToZoom_ = panel_.getWidgetSize(right_);

resizeHorizontally(initialSize, targetSize, () -> manageLayoutCommands());
}

public LogicalWindow getZoomedWindow()
{
return maximizedWindow_;
Expand Down Expand Up @@ -1144,9 +1221,26 @@ private void manageLayoutCommands()
{
commands_.layoutConsoleOnLeft().setVisible(false);
commands_.layoutConsoleOnRight().setVisible(false);
}
}

manageZoomColumnCommands();
}


private void manageZoomColumnCommands()
{
boolean zoomLeftChecked = false;
boolean zoomRightChecked = false;

String column = getZoomedColumn();
if (StringUtil.equals(column, LEFT_COLUMN))
zoomLeftChecked = true;
else if (StringUtil.equals(column, RIGHT_COLUMN))
zoomRightChecked = true;

commands_.layoutZoomLeftColumn().setChecked(zoomLeftChecked);
commands_.layoutZoomRightColumn().setChecked(zoomRightChecked);
}

private List<AppCommand> getLayoutCommands()
{
List<AppCommand> commands = new ArrayList<>();
Expand Down
Expand Up @@ -372,6 +372,12 @@ void onLayoutZoomHelp()
@Handler
void onLayoutZoomConnections() { paneManager_.zoomTab(Tab.Connections); }

@Handler
void onLayoutZoomLeftColumn() { paneManager_.zoomColumn(PaneManager.LEFT_COLUMN); }

@Handler
void onLayoutZoomRightColumn() { paneManager_.zoomColumn(PaneManager.RIGHT_COLUMN); }

@Handler
void onMacPreferences()
{
Expand Down
Expand Up @@ -17,6 +17,7 @@
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
import org.rstudio.core.client.ColorUtil;
import org.rstudio.core.client.MathUtil;
import org.rstudio.core.client.dom.DomUtils;

/**
Expand Down Expand Up @@ -85,7 +86,7 @@ public static String getFontFamily()

private static boolean doubleEqualish(double d1, double d2)
{
return Math.abs(d1 - d2) < 0.0001;
return MathUtil.isEqual(d1, d2, 0.0001);
}

public static double adjustFontSize(double size)
Expand Down

0 comments on commit 5a3a39d

Please sign in to comment.