Persisting users diff formatting preferences

When a user changes diff formatting preferences and clicks the
Update button the preferences will then be persisted in the database.
This way a user doesn't have to adjust the diff formatting
preferences each time it switches to the next file diff.

Bug: issue 579
Change-Id: I52cd1dcf702ed04046b236228f994fb9042243d9
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
This commit is contained in:
Sasa Zivkov
2010-06-14 15:00:05 +02:00
committed by Shawn O. Pearce
parent 5a00b3161d
commit 077b2c5dd0
25 changed files with 512 additions and 154 deletions

View File

@@ -52,6 +52,10 @@ import java.sql.Timestamp;
* <li>{@link StarredChange}: user has starred the change, tracking
* notifications of updates on that change, or just book-marking it for faster
* future reference. One record per starred change.</li>
*
* <li>{@link AccountDiffPreference}: user's preferences for rendering side-to-side
* and unified diff</li>
*
* </ul>
*/
public final class Account {

View File

@@ -0,0 +1,175 @@
// Copyright (C) 2010 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.reviewdb;
import com.google.gwtorm.client.Column;
/** Diff formatting preferences of an account */
public class AccountDiffPreference {
/** Default number of lines of context. */
public static final short DEFAULT_CONTEXT = 10;
/** Context setting to display the entire file. */
public static final short WHOLE_FILE_CONTEXT = -1;
/** Typical valid choices for the default context setting. */
public static final short[] CONTEXT_CHOICES =
{3, 10, 25, 50, 75, 100, WHOLE_FILE_CONTEXT};
public static enum Whitespace implements CodedEnum {
IGNORE_NONE('N'), //
IGNORE_SPACE_AT_EOL('E'), //
IGNORE_SPACE_CHANGE('S'), //
IGNORE_ALL_SPACE('A');
private final char code;
private Whitespace(final char c) {
code = c;
}
public char getCode() {
return code;
}
public static Whitespace forCode(final char c) {
for (final Whitespace s : Whitespace.values()) {
if (s.code == c) {
return s;
}
}
return null;
}
}
public static AccountDiffPreference createDefault(Account.Id accountId) {
AccountDiffPreference p = new AccountDiffPreference(accountId);
p.setIgnoreWhitespace(Whitespace.IGNORE_NONE);
p.setTabSize(8);
p.setLineLength(100);
p.setSyntaxHighlighting(true);
p.setShowWhitespaceErrors(true);
p.setIntralineDifference(true);
p.setShowTabs(true);
p.setContext(DEFAULT_CONTEXT);
return p;
}
@Column(id = 1, name = Column.NONE)
protected Account.Id accountId;
@Column(id = 2)
protected char ignoreWhitespace;
@Column(id = 3)
protected int tabSize;
@Column(id = 4)
protected int lineLength;
@Column(id = 5)
protected boolean syntaxHighlighting;
@Column(id = 6)
protected boolean showWhitespaceErrors;
@Column(id = 7)
protected boolean intralineDifference;
@Column(id = 8)
protected boolean showTabs;
/** Number of lines of context when viewing a patch. */
@Column(id = 9)
protected short context;
protected AccountDiffPreference() {
}
public AccountDiffPreference(Account.Id accountId) {
this.accountId = accountId;
}
public Account.Id getAccountId() {
return accountId;
}
public Whitespace getIgnoreWhitespace() {
return Whitespace.forCode(ignoreWhitespace);
}
public void setIgnoreWhitespace(Whitespace ignoreWhitespace) {
this.ignoreWhitespace = ignoreWhitespace.getCode();
}
public int getTabSize() {
return tabSize;
}
public void setTabSize(int tabSize) {
this.tabSize = tabSize;
}
public int getLineLength() {
return lineLength;
}
public void setLineLength(int lineLength) {
this.lineLength = lineLength;
}
public boolean isSyntaxHighlighting() {
return syntaxHighlighting;
}
public void setSyntaxHighlighting(boolean syntaxHighlighting) {
this.syntaxHighlighting = syntaxHighlighting;
}
public boolean isShowWhitespaceErrors() {
return showWhitespaceErrors;
}
public void setShowWhitespaceErrors(boolean showWhitespaceErrors) {
this.showWhitespaceErrors = showWhitespaceErrors;
}
public boolean isIntralineDifference() {
return intralineDifference;
}
public void setIntralineDifference(boolean intralineDifference) {
this.intralineDifference = intralineDifference;
}
public boolean isShowTabs() {
return showTabs;
}
public void setShowTabs(boolean showTabs) {
this.showTabs = showTabs;
}
/** Get the number of lines of context when viewing a patch. */
public short getContext() {
return context;
}
/** Set the number of lines of context when viewing a patch. */
public void setContext(final short s) {
context = s;
}
}

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2010 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.reviewdb;
import com.google.gwtorm.client.Access;
import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.PrimaryKey;
public interface AccountDiffPreferenceAccess extends Access<AccountDiffPreference, Account.Id> {
@PrimaryKey("accountId")
AccountDiffPreference get(Account.Id key) throws OrmException;
}

View File

@@ -18,15 +18,6 @@ import com.google.gwtorm.client.Column;
/** Preferences about a single user. */
public final class AccountGeneralPreferences {
/** Default number of lines of context. */
public static final short DEFAULT_CONTEXT = 10;
/** Context setting to display the entire file. */
public static final short WHOLE_FILE_CONTEXT = -1;
/** Typical valid choices for the default context setting. */
public static final short[] CONTEXT_CHOICES =
{3, 10, 25, 50, 75, 100, WHOLE_FILE_CONTEXT};
/** Default number of items to display per page. */
public static final short DEFAULT_PAGESIZE = 25;
@@ -44,10 +35,6 @@ public final class AccountGeneralPreferences {
REPO_DOWNLOAD, PULL, CHECKOUT, CHERRY_PICK, FORMAT_PATCH;
}
/** Default number of lines of context when viewing a patch. */
@Column(id = 1)
protected short defaultContext;
/** Number of changes to show in a screen. */
@Column(id = 2)
protected short maximumPageSize;
@@ -75,16 +62,6 @@ public final class AccountGeneralPreferences {
public AccountGeneralPreferences() {
}
/** Get the default number of lines of context when viewing a patch. */
public short getDefaultContext() {
return defaultContext;
}
/** Set the number of lines of context when viewing a patch. */
public void setDefaultContext(final short s) {
defaultContext = s;
}
public short getMaximumPageSize() {
return maximumPageSize;
}
@@ -148,7 +125,6 @@ public final class AccountGeneralPreferences {
}
public void resetToDefaults() {
defaultContext = DEFAULT_CONTEXT;
maximumPageSize = DEFAULT_PAGESIZE;
showSiteHeader = true;
useFlashClipboard = true;

View File

@@ -75,6 +75,9 @@ public interface ReviewDb extends Schema {
@Relation
AccountGroupAgreementAccess accountGroupAgreements();
@Relation
AccountDiffPreferenceAccess accountDiffPreferences();
@Relation
StarredChangeAccess starredChanges();