use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class HistoryViewContextualMenuPresenter method createOpenFileAction.
/**
* Creates an action to open a file at a given revision.
*
* @param revisionID Revision ID.
* @param fileStatus File path, relative to the working copy.
* @param addFileName <code>true</code> to append the name of the file to the name of the action.
*
* @return The action that will open the file when invoked.
*/
private Action createOpenFileAction(String revisionID, FileStatus fileStatus, boolean addFileName) {
String tooltipText = addFileName ? null : TRANSLATOR.getTranslation(Tags.HISTORY_RESOURCE_OPEN_ACTION_TOOLTIP);
AbstractAction openFileAction = new AbstractAction(getOpenFileActionName(fileStatus, addFileName)) {
@Override
public void actionPerformed(ActionEvent e) {
try {
Optional<URL> fileURL = getFileURL(revisionID, fileStatus);
fileURL.ifPresent(url -> PluginWorkspaceProvider.getPluginWorkspace().open(url));
} catch (NoRepositorySelected | IOException e1) {
LOGGER.error(e1.getMessage(), e1);
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(UNABLE_TO_OPEN_REVISION + e1.getMessage());
}
}
};
openFileAction.putValue(Action.SHORT_DESCRIPTION, tooltipText);
return openFileAction;
}
use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class HistoryViewContextualMenuPresenter method existsLocalFile.
/**
* Used to verify if a file exists on local disk.
*
* @param filePath the file path
*
* @return <code>true</code> if the file exists
*/
private boolean existsLocalFile(String filePath) {
String selectedRepository = "";
boolean toReturn = true;
try {
selectedRepository = GitAccess.getInstance().getWorkingCopy().getAbsolutePath();
// NOSONAR findsecbugs:PATH_TRAVERSAL_IN - false pozitive
File file = new File(selectedRepository, filePath);
toReturn = file.exists();
} catch (NoRepositorySelected e) {
toReturn = false;
}
return toReturn;
}
use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class HistoryViewContextualMenuPresenter method populateActions4MultipleSelection.
/**
* We have multiple revisions selected for a given path.
*
* @param jPopupMenu Menu to populate.
* @param filePath Selected path.
* @param commitCharacteristics Revisions.
*/
private void populateActions4MultipleSelection(JPopupMenu jPopupMenu, String filePath, CommitCharacteristics... commitCharacteristics) {
// Add open actions.
String fileName = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().getFileName(filePath);
String actionName = MessageFormat.format(TRANSLATOR.getTranslation(Tags.OPEN_FILE), fileName);
Action open = new AbstractAction(actionName) {
@Override
public void actionPerformed(ActionEvent e) {
for (CommitCharacteristics commitCharacteristic : commitCharacteristics) {
try {
Optional<FileStatus> fileStatus = getFileStatus(filePath, commitCharacteristic);
checkIfValidForOpen(filePath, commitCharacteristic, fileStatus);
Optional<URL> fileURL = getFileURL(commitCharacteristic.getCommitId(), fileStatus.get());
fileURL.ifPresent(url -> PluginWorkspaceProvider.getPluginWorkspace().open(url));
} catch (IOException | GitAPIException | NoRepositorySelected e1) {
LOGGER.debug(e1.getMessage(), e1);
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(UNABLE_TO_OPEN_REVISION + e1.getMessage());
}
}
}
};
// Add Compare action.
if (commitCharacteristics.length == 2) {
CommitCharacteristics c1 = commitCharacteristics[0];
CommitCharacteristics c2 = commitCharacteristics[1];
addCompareWithEachOtherAction(jPopupMenu, filePath, c1, c2);
}
jPopupMenu.add(open);
}
use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class HistoryViewContextualMenuPresenter method createOpenWorkingCopyFileAction.
/**
* Creates an action to open a working copy file.
*
* @author Alex_Smarandache
*
* @param fileStatus File path, relative to the working copy.
* @param commitID Current commit ID.
* @param addFileName <code>true</code> to append the name of the file to the name of the action.
*
* @return The action that will open the file when invoked.
*/
protected Action createOpenWorkingCopyFileAction(FileStatus fileStatus, String commitID, boolean addFileName) {
return new AbstractAction(getOpenFileWorkingCopyActionName(fileStatus, addFileName)) {
@Override
public void actionPerformed(ActionEvent e) {
try {
String localFilePath = RevCommitUtil.getNewPathInWorkingCopy(GitAccess.getInstance().getGit(), fileStatus.getFileLocation(), commitID);
URL fileURL = FileUtil.getFileURL(localFilePath);
boolean isProjectExt = false;
int index = localFilePath.lastIndexOf('.');
if (index != -1) {
String ext = localFilePath.substring(index + 1);
isProjectExt = "xpr".equals(ext);
}
PluginWorkspaceProvider.getPluginWorkspace().open(fileURL, isProjectExt ? EditorPageConstants.PAGE_TEXT : null, isProjectExt ? "text/xml" : null);
} catch (FileNotFoundException ex) {
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(UNABLE_TO_OPEN_REVISION + ex.getMessage());
LOGGER.debug(ex.getMessage(), ex);
} catch (NoRepositorySelected | IOException | GitAPIException ex) {
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(UNABLE_TO_OPEN_REVISION + ex.getMessage());
LOGGER.error(ex.getMessage(), ex);
}
}
};
}
use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class PanelRefresh method tryToSwitchToRepo.
/**
* Try to switch to repo, if the user will agree.
*
* @param repoDir Repository directory.
*
* @return <code>true</code> if repo changed.
*/
private boolean tryToSwitchToRepo(File repoDir) {
boolean repoChanged = false;
try {
File currentRepo = null;
if (gitAccess.isRepoInitialized()) {
currentRepo = gitAccess.getRepository().getDirectory().getParentFile();
}
if (currentRepo == null || !same(currentRepo, repoDir)) {
JComboBox<String> wcComboBox = stagingPanel.getWorkingCopySelectionPanel().getWorkingCopyCombo();
if (wcComboBox.isPopupVisible()) {
wcComboBox.setPopupVisible(false);
}
WhenRepoDetectedInProject whatToDo = OptionsManager.getInstance().getWhenRepoDetectedInProject();
String projectDirPath = getCanonicalPath(repoDir);
if (whatToDo == WhenRepoDetectedInProject.ASK_TO_SWITCH_TO_WC) {
repoChanged = switchToProjectRepoIfUserAgrees(projectDirPath);
} else if (whatToDo == WhenRepoDetectedInProject.AUTO_SWITCH_TO_WC) {
GitAccess.getInstance().setRepositoryAsync(projectDirPath);
repoChanged = true;
}
}
} catch (NoRepositorySelected e) {
LOGGER.warn(e.getMessage(), e);
}
return repoChanged;
}
Aggregations