vcs: add option in settings to enable partial changelists

This commit is contained in:
Aleksey Pivovarov
2018-02-08 16:13:38 +03:00
parent 3b0e08eb9e
commit 009b59cc8d
8 changed files with 74 additions and 40 deletions
@@ -135,7 +135,8 @@ action.name.show.difference=Show Difference
dialog.title.diff.for.range=Diff for Range
diff.content.title.up.to.date=Base revision
diff.content.title.current.range=Current
settings.filter.update.project.info.by.scope = Filter Update Project information by scope
settings.filter.update.project.info.by.scope=Filter Update Project information by scope
settings.partial.changelists.enable.checkbox=Track changed blocks in text files separately
#file view
action.name.show.files.as.tree=Show as Tree
@@ -471,9 +471,8 @@ vcs.root.detector.folder.depth.description=How deep should the IDE scan the file
vcs.push.all.with.commits=false
vcs.push.all.with.commits.description=Preselect all repositories with commits to be pushed by default.
vcs.enable.partial.changelists=false
vcs.enable.partial.changelists=true
vcs.enable.partial.changelists.description=Allow to have one file in multiple changelists (tracking blocks of modified lines)
vcs.enable.partial.changelists.restartRequired=true
vcs.enable.partial.changelists.persist.file.contents=false
vcs.enable.partial.changelists.persist.file.contents.description=Persist file contents on disk to restore partial changes for files modified while IDE is closed
@@ -70,6 +70,7 @@ public final class VcsConfiguration implements PersistentStateComponent<VcsConfi
public boolean LOCAL_CHANGES_DETAILS_PREVIEW_SHOWN = false;
public boolean SHELVE_DETAILS_PREVIEW_SHOWN = false;
public boolean RELOAD_CONTEXT = true;
public boolean ENABLE_PARTIAL_CHANGELISTS = false;
@XCollection(elementName = "path", propertyElementName = "ignored-roots")
public List<String> IGNORED_UNREGISTERED_ROOTS = ContainerUtil.newArrayList();
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.vcs.changes.conflicts.ChangelistConflictConfigurable">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="346"/>
<xy x="20" y="20" width="854" height="412"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="4d345" class="javax.swing.JCheckBox" binding="myEnableCheckBox">
<component id="4d345" class="javax.swing.JCheckBox" binding="myEnableConflictTrackingCheckBox">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Enable changelist conflict tracking"/>
@@ -19,7 +19,7 @@
<grid id="31c09" binding="myOptionsPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="2" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="2" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -91,9 +91,17 @@
</grid>
<vspacer id="523f5">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="10c41" class="javax.swing.JCheckBox" binding="myEnablePartialChangelists">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/VcsBundle" key="settings.partial.changelists.enable.checkbox"/>
</properties>
</component>
</children>
</grid>
</form>
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.vcs.changes.conflicts;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
@@ -22,7 +23,9 @@ import com.intellij.openapi.options.binding.BindControl;
import com.intellij.openapi.options.binding.BindableConfigurable;
import com.intellij.openapi.options.binding.ControlBinder;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsConfiguration;
import com.intellij.openapi.vcs.changes.ChangeListManagerImpl;
import com.intellij.openapi.vcs.impl.LineStatusTrackerSettingListener;
import com.intellij.ui.components.JBList;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ui.UIUtil;
@@ -43,7 +46,7 @@ public class ChangelistConflictConfigurable extends BindableConfigurable impleme
private JPanel myOptionsPanel;
@BindControl("TRACKING_ENABLED")
private JCheckBox myEnableCheckBox;
private JCheckBox myEnableConflictTrackingCheckBox;
@BindControl("SHOW_DIALOG")
private JCheckBox myShowDialogCheckBox;
@@ -56,16 +59,19 @@ public class ChangelistConflictConfigurable extends BindableConfigurable impleme
private JBList myIgnoredFiles;
private JButton myClearButton;
private JCheckBox myEnablePartialChangelists;
private boolean myIgnoredFilesCleared;
private final ChangelistConflictTracker myConflictTracker;
private final VcsConfiguration myVcsConfiguration;
public ChangelistConflictConfigurable(ChangeListManagerImpl manager) {
super(new ControlBinder(manager.getConflictTracker().getOptions()));
myEnableCheckBox.addActionListener(new ActionListener() {
myVcsConfiguration = VcsConfiguration.getInstance(manager.getProject());
myEnableConflictTrackingCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
UIUtil.setEnabled(myOptionsPanel, myEnableCheckBox.isSelected(), true);
UIUtil.setEnabled(myOptionsPanel, myEnableConflictTrackingCheckBox.isSelected(), true);
}
});
myConflictTracker = manager.getConflictTracker();
@@ -89,10 +95,12 @@ public class ChangelistConflictConfigurable extends BindableConfigurable impleme
@Override
public void reset() {
super.reset();
myEnablePartialChangelists.setSelected(myVcsConfiguration.ENABLE_PARTIAL_CHANGELISTS);
Collection<String> conflicts = myConflictTracker.getIgnoredConflicts();
myIgnoredFiles.setListData(ArrayUtil.toStringArray(conflicts));
myClearButton.setEnabled(!conflicts.isEmpty());
UIUtil.setEnabled(myOptionsPanel, myEnableCheckBox.isSelected(), true);
UIUtil.setEnabled(myOptionsPanel, myEnableConflictTrackingCheckBox.isSelected(), true);
}
@Override
@@ -103,17 +111,23 @@ public class ChangelistConflictConfigurable extends BindableConfigurable impleme
conflict.ignored = false;
}
}
if (myEnablePartialChangelists.isSelected() != myVcsConfiguration.ENABLE_PARTIAL_CHANGELISTS) {
myVcsConfiguration.ENABLE_PARTIAL_CHANGELISTS = myEnablePartialChangelists.isSelected();
ApplicationManager.getApplication().getMessageBus().syncPublisher(LineStatusTrackerSettingListener.TOPIC).settingsUpdated();
}
myConflictTracker.optionsChanged();
}
@Override
public boolean isModified() {
return super.isModified() || myIgnoredFiles.getModel().getSize() != myConflictTracker.getIgnoredConflicts().size();
return super.isModified() ||
myIgnoredFiles.getModel().getSize() != myConflictTracker.getIgnoredConflicts().size() ||
myEnablePartialChangelists.isSelected() != myVcsConfiguration.ENABLE_PARTIAL_CHANGELISTS;
}
@Nls
public String getDisplayName() {
return "Changelist Conflicts";
return "Changelists";
}
@Override
@@ -84,7 +84,7 @@ class LineStatusTrackerManager(
private val trackers = HashMap<Document, TrackerData>()
private val forcedDocuments = HashMap<Document, Multiset<Any>>()
private val partialChangeListsEnabled = Registry.`is`("vcs.enable.partial.changelists")
private var partialChangeListsEnabled = VcsConfiguration.getInstance(project).ENABLE_PARTIAL_CHANGELISTS && Registry.`is`("vcs.enable.partial.changelists")
private val documentsInDefaultChangeList = HashSet<Document>()
private val filesWithDamagedInactiveRanges = HashSet<VirtualFile>()
@@ -115,14 +115,14 @@ class LineStatusTrackerManager(
val editorFactory = EditorFactory.getInstance()
editorFactory.addEditorFactoryListener(MyEditorFactoryListener(), disposable)
if (partialChangeListsEnabled) editorFactory.eventMulticaster.addDocumentListener(MyDocumentListener(), disposable)
editorFactory.eventMulticaster.addDocumentListener(MyDocumentListener(), disposable)
changeListManager.addChangeListListener(MyChangeListListener())
val virtualFileManager = VirtualFileManager.getInstance()
virtualFileManager.addVirtualFileListener(MyVirtualFileListener(), disposable)
if (partialChangeListsEnabled) CommandProcessor.getInstance().addCommandListener(MyCommandListener(), disposable)
CommandProcessor.getInstance().addCommandListener(MyCommandListener(), disposable)
}
}
@@ -376,6 +376,29 @@ class LineStatusTrackerManager(
}
}
private fun updateTrackingModes() {
synchronized(LOCK) {
if (isDisposed) return
val mode = getTrackingMode()
val trackers = trackers.values.map { it.tracker }
for (tracker in trackers) {
val document = tracker.document
val virtualFile = tracker.virtualFile
val isPartialTrackerExpected = canCreatePartialTrackerFor(virtualFile)
val isPartialTracker = tracker is PartialLocalLineStatusTracker
if (isPartialTrackerExpected == isPartialTracker) {
tracker.mode = mode
}
else {
releaseTracker(document)
installTracker(virtualFile, document)
}
}
}
}
private fun getTrackingMode(): LineStatusTracker.Mode {
val settings = VcsApplicationSettings.getInstance()
if (!settings.SHOW_LST_GUTTER_MARKERS) return LineStatusTracker.Mode.SILENT
@@ -590,6 +613,8 @@ class LineStatusTrackerManager(
private inner class MyDocumentListener : DocumentListener {
override fun documentChanged(event: DocumentEvent) {
if (!partialChangeListsEnabled) return
val document = event.document
if (documentsInDefaultChangeList.contains(document)) return
@@ -622,27 +647,9 @@ class LineStatusTrackerManager(
private inner class MyLineStatusTrackerSettingListener : LineStatusTrackerSettingListener {
override fun settingsUpdated() {
synchronized(LOCK) {
val mode = getTrackingMode()
for (data in trackers.values) {
val tracker = data.tracker
val document = tracker.document
val virtualFile = tracker.virtualFile
partialChangeListsEnabled = VcsConfiguration.getInstance(project).ENABLE_PARTIAL_CHANGELISTS && Registry.`is`("vcs.enable.partial.changelists")
if (tracker.mode == mode) continue
val isPartialTrackerExpected = canCreatePartialTrackerFor(virtualFile)
val isPartialTracker = tracker is PartialLocalLineStatusTracker
if (isPartialTrackerExpected == isPartialTracker) {
tracker.mode = mode
}
else {
releaseTracker(document)
installTracker(virtualFile, document)
}
}
}
updateTrackingModes()
}
}
@@ -662,6 +669,8 @@ class LineStatusTrackerManager(
private inner class MyCommandListener : CommandListener {
override fun commandFinished(event: CommandEvent?) {
if (!partialChangeListsEnabled) return
if (CommandProcessor.getInstance().currentCommand == null &&
!filesWithDamagedInactiveRanges.isEmpty()) {
showInactiveRangesDamagedNotification()
@@ -71,6 +71,8 @@ public class VcsOptionsUsagesCollector extends AbstractProjectsUsagesCollector {
usages.add(getBooleanUsage("include.text.into.shelf", configuration.INCLUDE_TEXT_INTO_SHELF));
usages.add(getBooleanUsage("check.conflicts.in.background", configuration.CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND));
usages.add(getBooleanUsage("enable.partial.changelists", configuration.ENABLE_PARTIAL_CHANGELISTS));
return usages;
}
}
+1 -1
View File
@@ -438,6 +438,6 @@ public class GitVcs extends AbstractVcs<CommittedChangeList> {
@Override
public boolean arePartialChangelistsSupported() {
return Registry.is("vcs.enable.partial.changelists");
return true;
}
}