ChangeScreen2: Add preference to open side-by-side or unified diff view

A new user preference is added by which the user can decide which diff
screen (CodeMirror Side-by-Side or Unified Diff) is opened when
clicking on a file in ChangeScreen2. This preference doesn't apply to
the old change screen.

Bug: issue 2071
Change-Id: Ia1c7762c5559e383ad91ff0b8888c782b8134ef0
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2013-08-21 15:29:55 +02:00
parent 4f12a405f2
commit 41ec3ef831
9 changed files with 92 additions and 2 deletions

View File

@ -80,6 +80,7 @@ import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DiffView;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch;
@ -603,6 +604,18 @@ public class Dispatcher {
baseId //
);
} else if ("cm".equals(panel)) {
if (Gerrit.isSignedIn()
&& DiffView.UNIFIED_DIFF.equals(Gerrit.getUserAccount()
.getGeneralPreferences().getDiffView())) {
return new PatchScreen.Unified( //
id, //
patchIndex, //
patchSetDetail, //
patchTable, //
top, //
baseId //
);
}
return new SideBySide2(baseId, id.getParentKey(), id.get());
}
}

View File

@ -26,6 +26,7 @@ public interface AccountConstants extends Constants {
String accountId();
String commentVisibilityLabel();
String diffViewLabel();
String maximumPageSizeFieldLabel();
String dateFormatLabel();
String contextWholeFile();

View File

@ -12,6 +12,7 @@ reversePatchSetOrder = Display Patch Sets In Reverse Order
showUsernameInReviewCategory = Display Person Name In Review Category
maximumPageSizeFieldLabel = Maximum Page Size:
commentVisibilityLabel = Comment Visibility:
diffViewLabel = Diff View (ChangeScreen2 only):
dateFormatLabel = Date/Time Format:
contextWholeFile = Whole File
buttonSaveChanges = Save Changes

View File

@ -48,6 +48,7 @@ public class MyPreferencesScreen extends SettingsScreen {
private ListBox dateFormat;
private ListBox timeFormat;
private ListBox commentVisibilityStrategy;
private ListBox diffView;
private Button save;
@Override
@ -82,6 +83,16 @@ public class MyPreferencesScreen extends SettingsScreen {
AccountGeneralPreferences.CommentVisibilityStrategy.EXPAND_ALL.name()
);
diffView = new ListBox();
diffView.addItem(
com.google.gerrit.client.changes.Util.C.sideBySide(),
AccountGeneralPreferences.DiffView.SIDE_BY_SIDE.name()
);
diffView.addItem(
com.google.gerrit.client.changes.Util.C.unifiedDiff(),
AccountGeneralPreferences.DiffView.UNIFIED_DIFF.name()
);
Date now = new Date();
dateFormat = new ListBox();
for (AccountGeneralPreferences.DateFormat fmt : AccountGeneralPreferences.DateFormat
@ -118,7 +129,7 @@ public class MyPreferencesScreen extends SettingsScreen {
relativeDateInChangeTable = new CheckBox(Util.C.showRelativeDateInChangeTable());
final Grid formGrid = new Grid(9, 2);
final Grid formGrid = new Grid(10, 2);
int row = 0;
formGrid.setText(row, labelIdx, "");
@ -157,6 +168,10 @@ public class MyPreferencesScreen extends SettingsScreen {
formGrid.setWidget(row, fieldIdx, commentVisibilityStrategy);
row++;
formGrid.setText(row, labelIdx, Util.C.diffViewLabel());
formGrid.setWidget(row, fieldIdx, diffView);
row++;
add(formGrid);
save = new Button(Util.C.buttonSaveChanges());
@ -180,6 +195,7 @@ public class MyPreferencesScreen extends SettingsScreen {
e.listenTo(timeFormat);
e.listenTo(relativeDateInChangeTable);
e.listenTo(commentVisibilityStrategy);
e.listenTo(diffView);
}
@Override
@ -203,6 +219,7 @@ public class MyPreferencesScreen extends SettingsScreen {
timeFormat.setEnabled(on);
relativeDateInChangeTable.setEnabled(on);
commentVisibilityStrategy.setEnabled(on);
diffView.setEnabled(on);
}
private void display(final AccountGeneralPreferences p) {
@ -220,6 +237,9 @@ public class MyPreferencesScreen extends SettingsScreen {
setListBox(commentVisibilityStrategy,
AccountGeneralPreferences.CommentVisibilityStrategy.EXPAND_RECENT,
p.getCommentVisibilityStrategy());
setListBox(diffView,
AccountGeneralPreferences.DiffView.SIDE_BY_SIDE,
p.getDiffView());
}
private void setListBox(final ListBox f, final short defaultValue,
@ -287,6 +307,9 @@ public class MyPreferencesScreen extends SettingsScreen {
p.setCommentVisibilityStrategy(getListBox(commentVisibilityStrategy,
CommentVisibilityStrategy.EXPAND_RECENT,
CommentVisibilityStrategy.values()));
p.setDiffView(getListBox(diffView,
AccountGeneralPreferences.DiffView.SIDE_BY_SIDE,
AccountGeneralPreferences.DiffView.values()));
enable(false);
save.setEnabled(false);

View File

@ -126,6 +126,9 @@ public interface ChangeConstants extends Constants {
String messageCollapseAll();
String messageNeedsRebaseOrHasDependency();
String sideBySide();
String unifiedDiff();
String patchSetInfoAuthor();
String patchSetInfoCommitter();
String patchSetInfoDownload();

View File

@ -104,6 +104,9 @@ messageExpandAll = Expand All
messageCollapseAll = Collapse All
messageNeedsRebaseOrHasDependency = Need Rebase or Has Dependency
sideBySide = Side by Side
unifiedDiff = Unified Diff
patchSetInfoAuthor = Author
patchSetInfoCommitter = Committer
patchSetInfoDownload = Download

View File

@ -72,6 +72,11 @@ public final class AccountGeneralPreferences {
EXPAND_ALL;
}
public static enum DiffView {
SIDE_BY_SIDE,
UNIFIED_DIFF
}
public static enum TimeFormat {
/** 12-hour clock: 1:15 am, 2:13 pm */
HHMM_12("h:mm a"),
@ -136,6 +141,9 @@ public final class AccountGeneralPreferences {
@Column(id = 13, length = 20, notNull = false)
protected String commentVisibilityStrategy;
@Column(id = 14, length = 20, notNull = false)
protected String diffView;
public AccountGeneralPreferences() {
}
@ -259,6 +267,17 @@ public final class AccountGeneralPreferences {
commentVisibilityStrategy = strategy.name();
}
public DiffView getDiffView() {
if (diffView == null) {
return DiffView.SIDE_BY_SIDE;
}
return DiffView.valueOf(diffView);
}
public void setDiffView(DiffView diffView) {
this.diffView = diffView.name();
}
public void resetToDefaults() {
maximumPageSize = DEFAULT_PAGESIZE;
showSiteHeader = true;
@ -271,5 +290,6 @@ public final class AccountGeneralPreferences {
dateFormat = null;
timeFormat = null;
relativeDateInChangeTable = false;
diffView = null;
}
}

View File

@ -32,7 +32,7 @@ import java.util.List;
/** A version of the database schema. */
public abstract class SchemaVersion {
/** The current schema version. */
public static final Class<Schema_82> C = Schema_82.class;
public static final Class<Schema_83> C = Schema_83.class;
public static class Module extends AbstractModule {
@Override

View File

@ -0,0 +1,26 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.schema;
import com.google.inject.Inject;
import com.google.inject.Provider;
public class Schema_83 extends SchemaVersion {
@Inject
Schema_83(Provider<Schema_82> prior) {
super(prior);
}
}