use of com.oxygenxml.git.view.event.FileGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class StagingPanel method treatEditorSavedEvent.
/**
* Treat editor saved event.
*
* @param editorLocation Editor URL.
*/
private void treatEditorSavedEvent(final URL editorLocation) {
File locateFile = null;
if ("file".equals(editorLocation.getProtocol())) {
locateFile = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().locateFile(editorLocation);
if (locateFile != null) {
String fileInWorkPath = locateFile.toString();
fileInWorkPath = FileUtil.rewriteSeparator(fileInWorkPath);
try {
String selectedRepositoryPath = GitAccess.getInstance().getWorkingCopy().getAbsolutePath();
selectedRepositoryPath = FileUtil.rewriteSeparator(selectedRepositoryPath);
if (fileInWorkPath.startsWith(selectedRepositoryPath)) {
if (gitActionsManager != null) {
gitActionsManager.refreshActionsStates();
}
updateToolbarsButtonsStates();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Notify " + fileInWorkPath);
LOGGER.debug("WC " + selectedRepositoryPath);
}
Collection<String> affectedFiles = Collections.singletonList(fileInWorkPath.substring(selectedRepositoryPath.length() + 1));
FileGitEventInfo changeEvent = new FileGitEventInfo(GitOperation.UNSTAGE, affectedFiles);
SwingUtilities.invokeLater(() -> unstagedChangesPanel.fileStatesChanged(changeEvent));
}
} catch (NoRepositorySelected e) {
LOGGER.debug(e.getMessage(), e);
}
}
}
}
use of com.oxygenxml.git.view.event.FileGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class GitAccess method addAll.
/**
* Adds multiple files to the staging area. Preparing the for commit
*
* @param files The files to be added.
*/
public void addAll(List<FileStatus> files) {
Collection<String> filePaths = getFilePaths(files);
try {
fireOperationAboutToStart(new FileGitEventInfo(GitOperation.STAGE, filePaths));
RmCommand removeCmd = null;
AddCommand addCmd = null;
for (FileStatus file : files) {
if (file.getChangeType() == GitChangeType.MISSING) {
if (removeCmd == null) {
removeCmd = git.rm().setCached(true);
}
removeCmd.addFilepattern(file.getFileLocation());
} else {
if (addCmd == null) {
addCmd = git.add();
}
addCmd.addFilepattern(file.getFileLocation());
}
}
if (addCmd != null) {
addCmd.call();
}
if (removeCmd != null) {
removeCmd.call();
}
fireOperationSuccessfullyEnded(new FileGitEventInfo(GitOperation.STAGE, filePaths));
} catch (GitAPIException e) {
fireOperationFailed(new FileGitEventInfo(GitOperation.STAGE, filePaths), e);
LOGGER.error(e.getMessage(), e);
}
}
use of com.oxygenxml.git.view.event.FileGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class GitAccess method abortMerge.
/**
* Abort merge.
*/
public void abortMerge() {
Set<String> conflictingFiles = getConflictingFiles();
fireOperationAboutToStart(new FileGitEventInfo(GitOperation.ABORT_MERGE, conflictingFiles));
GitOperationScheduler.getInstance().schedule(() -> {
try {
// Clear the merge state
Repository repository = getRepository();
repository.writeMergeCommitMsg(null);
repository.writeMergeHeads(null);
// Reset the index and work directory to HEAD
git.reset().setMode(ResetType.HARD).call();
fireOperationSuccessfullyEnded(new FileGitEventInfo(GitOperation.ABORT_MERGE, conflictingFiles));
} catch (GitAPIException | IOException | NoRepositorySelected e) {
fireOperationFailed(new FileGitEventInfo(GitOperation.ABORT_MERGE, conflictingFiles), e);
LOGGER.error(e.getMessage(), e);
}
});
}
use of com.oxygenxml.git.view.event.FileGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class GitAccess method resetAll.
/**
* Reset all the specified files from the staging area.
*
* @param files The list of file to be removed
*/
public void resetAll(List<FileStatus> files) {
Collection<String> filePaths = getFilePaths(files);
try {
fireOperationAboutToStart(new FileGitEventInfo(GitOperation.UNSTAGE, filePaths));
if (!files.isEmpty()) {
ResetCommand reset = git.reset();
for (FileStatus file : files) {
reset.addPath(file.getFileLocation());
}
reset.call();
}
fireOperationSuccessfullyEnded(new FileGitEventInfo(GitOperation.UNSTAGE, filePaths));
} catch (GitAPIException e) {
fireOperationFailed(new FileGitEventInfo(GitOperation.UNSTAGE, filePaths), e);
LOGGER.error(e.getMessage(), e);
}
}
use of com.oxygenxml.git.view.event.FileGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class StagingResourcesTreeModel method fileStatesChanged.
/**
* File states changed.
*
* @param eventInfo Event information.
*/
public void fileStatesChanged(GitEventInfo eventInfo) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Tree model for index: " + inIndex + " event " + eventInfo);
}
GitAccess gitAccess = GitAccess.getInstance();
switch(eventInfo.getGitOperation()) {
case STAGE:
if (inIndex) {
insertNodes(gitAccess.getStagedFile(((FileGitEventInfo) eventInfo).getAffectedFilePaths()));
} else {
deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
}
break;
case UNSTAGE:
if (inIndex) {
deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
} else {
// Things were taken out of the index / "staged" area.
// The same resource might be present in the Unstaged and Staged. Remove old states.
deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
insertNodes(gitAccess.getUnstagedFiles(((FileGitEventInfo) eventInfo).getAffectedFilePaths()));
}
break;
case COMMIT:
if (inIndex) {
clearModel();
}
break;
case DISCARD:
deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
break;
case MERGE_RESTART:
clearModel();
List<FileStatus> fileStatuses = inIndex ? gitAccess.getStagedFiles() : gitAccess.getUnstagedFiles();
insertNodes(fileStatuses);
break;
case ABORT_REBASE:
case CONTINUE_REBASE:
clearModel();
break;
case ABORT_MERGE:
deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
break;
default:
// Nothing
break;
}
fireTreeStructureChanged(this, null, null, null);
}
Aggregations