aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker2011-02-14 10:20:40 (EST)
committerMathias Kinzler2011-02-14 10:20:40 (EST)
commit6683e6188f255ec0246aff61a986cf98278c935e (patch)
tree2b08c14c8c53679a7809b8adfc309597ff66863e
parent41c89d1e28712d34add7550917e8723be3f5d4a5 (diff)
downloadegit-6683e6188f255ec0246aff61a986cf98278c935e.zip
egit-6683e6188f255ec0246aff61a986cf98278c935e.tar.gz
egit-6683e6188f255ec0246aff61a986cf98278c935e.tar.bz2
Add tab for configuring repository settingsrefs/changes/72/2472/4
In the Git configuration preference page, there's now a tab for configuring repository settings. The repository can be selected from a drop-down list. Bug: 336415 Change-Id: I0cdbdf8620316357bb9a684fcc31714437499934
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/ConfigurationEditorComponent.java12
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GlobalConfigurationPreferencePage.java145
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties7
4 files changed, 168 insertions, 5 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
index b991f53..93408fd 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
@@ -1612,6 +1612,15 @@ public class UIText extends NLS {
public static String GlobalConfigurationPreferencePage_userSettingTabTitle;
/** */
+ public static String GlobalConfigurationPreferencePage_repositorySettingTabTitle;
+
+ /** */
+ public static String GlobalConfigurationPreferencePage_repositorySettingRepositoryLabel;
+
+ /** */
+ public static String GlobalConfigurationPreferencePage_repositorySettingNoRepositories;
+
+ /** */
public static String ConfigureRemoteWizard_WizardTitle_Change;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/ConfigurationEditorComponent.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/ConfigurationEditorComponent.java
index 2dd9ca6..14f92c6 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/ConfigurationEditorComponent.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/ConfigurationEditorComponent.java
@@ -92,6 +92,8 @@ public class ConfigurationEditorComponent {
private final boolean useDialogFont;
+ private Composite contents;
+
private Text valueText;
private Button changeValue;
@@ -401,7 +403,15 @@ public class ConfigurationEditorComponent {
});
initControlsFromConfig();
- return main;
+ contents = main;
+ return contents;
+ }
+
+ /**
+ * @return the composite containing all the controls
+ */
+ public Composite getContents() {
+ return contents;
}
private boolean isWriteable(final File f) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GlobalConfigurationPreferencePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GlobalConfigurationPreferencePage.java
index e860d5d..9c937bf 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GlobalConfigurationPreferencePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GlobalConfigurationPreferencePage.java
@@ -10,19 +10,36 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.preferences;
+import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.egit.core.RepositoryCache;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.SWTUtils;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.SystemReader;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.IWorkbench;
@@ -42,6 +59,14 @@ public class GlobalConfigurationPreferencePage extends PreferencePage implements
private FileBasedConfig sysConfig;
+ private StackLayout repoConfigStackLayout;
+
+ private List<Repository> repositories;
+
+ private Map<Repository, ConfigurationEditorComponent> repoConfigEditors = new HashMap<Repository, ConfigurationEditorComponent>();
+
+ private Set<Repository> dirtyRepositories = new HashSet<Repository>();
+
private boolean userIsDirty;
private boolean sysIsDirty;
@@ -50,6 +75,8 @@ public class GlobalConfigurationPreferencePage extends PreferencePage implements
private ConfigurationEditorComponent sysConfigEditor;
+ private Composite repoConfigComposite;
+
@Override
protected Control createContents(Composite parent) {
@@ -86,12 +113,52 @@ public class GlobalConfigurationPreferencePage extends PreferencePage implements
TabItem userTabItem = new TabItem(tabFolder, SWT.FILL);
userTabItem.setControl(result);
userTabItem.setText(UIText.GlobalConfigurationPreferencePage_userSettingTabTitle);
+
result = sysConfigEditor.createContents();
Dialog.applyDialogFont(result);
TabItem sysTabItem = new TabItem(tabFolder, SWT.FILL);
sysTabItem.setControl(result);
sysTabItem.setText(UIText.GlobalConfigurationPreferencePage_systemSettingTabTitle);
- return result;
+
+ Composite repoTab = new Composite(tabFolder, SWT.NONE);
+ repoTab.setLayout(new GridLayout(1, false));
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(repoTab);
+ Composite repositoryComposite = new Composite(repoTab, SWT.NONE);
+ repositoryComposite.setLayout(new GridLayout(2, false));
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(
+ repositoryComposite);
+ Label repoLabel = new Label(repositoryComposite, SWT.NONE);
+ repoLabel
+ .setText(UIText.GlobalConfigurationPreferencePage_repositorySettingRepositoryLabel);
+
+ Combo repoCombo = new Combo(repositoryComposite, SWT.READ_ONLY);
+ repoCombo.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ Combo combo = (Combo) e.widget;
+ showRepositoryConfiguration(combo.getSelectionIndex());
+ }
+ });
+ repoCombo.setItems(getRepositoryComboItems());
+
+ repoConfigComposite = new Composite(repoTab, SWT.NONE);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(repoConfigComposite);
+ repoConfigStackLayout = new StackLayout();
+ repoConfigComposite.setLayout(repoConfigStackLayout);
+
+ TabItem repoTabItem = new TabItem(tabFolder, SWT.FILL);
+ repoTabItem.setControl(repoTab);
+ repoTabItem.setText(UIText.GlobalConfigurationPreferencePage_repositorySettingTabTitle);
+
+ if (repoCombo.getItemCount() > 0) {
+ repoCombo.select(0);
+ showRepositoryConfiguration(0);
+ } else {
+ repoCombo.setItems(new String[] {UIText.GlobalConfigurationPreferencePage_repositorySettingNoRepositories});
+ repoCombo.select(0);
+ repoCombo.setEnabled(false);
+ }
+
+ return composite;
}
@Override
@@ -104,7 +171,7 @@ public class GlobalConfigurationPreferencePage extends PreferencePage implements
@Override
protected void updateApplyButton() {
if (getApplyButton() != null)
- getApplyButton().setEnabled(userIsDirty || sysIsDirty);
+ getApplyButton().setEnabled(userIsDirty || sysIsDirty || !dirtyRepositories.isEmpty());
}
@Override
@@ -126,6 +193,15 @@ public class GlobalConfigurationPreferencePage extends PreferencePage implements
ok = false;
}
}
+ for (Repository repository : dirtyRepositories) {
+ ConfigurationEditorComponent editor = repoConfigEditors.get(repository);
+ try {
+ editor.save();
+ } catch (IOException e) {
+ Activator.handleError(e.getMessage(), e, true);
+ ok = false;
+ }
+ }
return ok;
}
@@ -134,6 +210,10 @@ public class GlobalConfigurationPreferencePage extends PreferencePage implements
try {
userConfigEditor.restore();
sysConfigEditor.restore();
+ for (ConfigurationEditorComponent editor : repoConfigEditors.values()) {
+ editor.restore();
+ }
+
} catch (IOException e) {
Activator.handleError(e.getMessage(), e, true);
}
@@ -145,5 +225,66 @@ public class GlobalConfigurationPreferencePage extends PreferencePage implements
sysConfig = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED);
if (userConfig == null)
userConfig = SystemReader.getInstance().openUserConfig(null, FS.DETECTED); // no inherit here!
+ if (repositories == null) {
+ repositories = new ArrayList<Repository>();
+ List<String> repoPaths = Activator.getDefault().getRepositoryUtil().getConfiguredRepositories();
+ RepositoryCache repositoryCache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();
+ for (String repoPath : repoPaths) {
+ try {
+ Repository repository = repositoryCache.lookupRepository(new File(repoPath));
+ repositories.add(repository);
+ } catch (IOException e) {
+ continue;
+ }
+ }
+ }
+ }
+
+ private String[] getRepositoryComboItems() {
+ List<String> items = new ArrayList<String>();
+ for (Repository repository : repositories) {
+ String repoName = repository.getDirectory().getParentFile().getName();
+ items.add(repoName);
+ }
+ return items.toArray(new String[items.size()]);
+ }
+
+ private void showRepositoryConfiguration(int index) {
+ Repository repository = repositories.get(index);
+ ConfigurationEditorComponent editor = repoConfigEditors.get(repository);
+ if (editor == null) {
+ editor = createConfigurationEditor(repository);
+ repoConfigEditors.put(repository, editor);
+ }
+ repoConfigStackLayout.topControl = editor.getContents();
+ repoConfigComposite.layout();
+ }
+
+ private ConfigurationEditorComponent createConfigurationEditor(final Repository repository) {
+ StoredConfig repositoryConfig;
+ if (repository.getConfig() instanceof FileBasedConfig) {
+ File configFile = ((FileBasedConfig) repository.getConfig()).getFile();
+ repositoryConfig = new FileBasedConfig(configFile, repository
+ .getFS());
+ } else {
+ repositoryConfig = repository.getConfig();
+ }
+ ConfigurationEditorComponent editorComponent = new ConfigurationEditorComponent(repoConfigComposite, repositoryConfig, true) {
+ @Override
+ protected void setErrorMessage(String message) {
+ GlobalConfigurationPreferencePage.this.setErrorMessage(message);
+ }
+
+ @Override
+ protected void setDirty(boolean dirty) {
+ if (dirty)
+ dirtyRepositories.add(repository);
+ else
+ dirtyRepositories.remove(repository);
+ updateApplyButton();
+ }
+ };
+ editorComponent.createContents();
+ return editorComponent;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
index 211a15f..8c6bc64 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
@@ -917,8 +917,11 @@ ContinueRebaseCommand_CancelDialogMessage=The Abort operation was canceled
ContinueRebaseCommand_JobName=Continuing Rebase
MixedResetToRevisionAction_mixedReset=Mixed Reset
-GlobalConfigurationPreferencePage_systemSettingTabTitle=System setting
-GlobalConfigurationPreferencePage_userSettingTabTitle=User setting
+GlobalConfigurationPreferencePage_systemSettingTabTitle=&System setting
+GlobalConfigurationPreferencePage_userSettingTabTitle=&User setting
+GlobalConfigurationPreferencePage_repositorySettingTabTitle=&Repository setting
+GlobalConfigurationPreferencePage_repositorySettingRepositoryLabel=R&epository:
+GlobalConfigurationPreferencePage_repositorySettingNoRepositories=No repositories configured
UIIcons_errorDeterminingIconBase=Can't determine icon base.
UIIcons_errorLoadingPluginImage=Can't load plugin image.