Skip to content

Commit

Permalink
Change the colors in the file explorer when GIT is activated apache#4316
Browse files Browse the repository at this point in the history


Ignored Git files are not correctly detected
Replace deprecated method setName() for RemoteRemoveCommand
Add BORDER to TableView in GitInfo
  • Loading branch information
nadment committed Sep 13, 2024
1 parent 9316649 commit 26fa4eb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
66 changes: 44 additions & 22 deletions plugins/misc/git/src/main/java/org/apache/hop/git/GitGuiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.hop.git.model.UIGit;
import org.apache.hop.git.model.VCS;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.dialog.EnterSelectionDialog;
import org.apache.hop.ui.core.dialog.EnterStringDialog;
import org.apache.hop.ui.core.dialog.ErrorDialog;
Expand Down Expand Up @@ -107,9 +108,15 @@ public GitGuiPlugin() {
git = null;
}

colorIgnored = new Color(HopGui.getInstance().getDisplay(), 125, 125, 125);
colorStaged = GuiResource.getInstance().getColorBlue();
colorUnstaged = GuiResource.getInstance().getColorRed();
// Adjust color for dark mode
if (PropsUi.getInstance().isDarkMode()) {
colorStaged = GuiResource.getInstance().getColorLightBlue();
colorIgnored = GuiResource.getInstance().getColorGray();
} else {
colorStaged = GuiResource.getInstance().getColorBlue();
colorIgnored = GuiResource.getInstance().getColorDarkGray();
}
colorUnstaged = GuiResource.getInstance().getColorBlack();

refreshChangedFiles();
}
Expand Down Expand Up @@ -411,11 +418,31 @@ public void rootChanged(String rootFolder, String rootName) {
enableButtons();
}

/**
* Normalize absolute filename.
*
* @param path
* @return
*/
private String getAbsoluteFilename(String path) {
try {
path = HopVfs.getFileObject(path).getName().getPath();
} catch (Exception e) {
// Ignore, keep simple path
}
return path;
}

/**
* Normalize absolute filename
*
* @param root
* @param relativePath
* @return
*/
private String getAbsoluteFilename(String root, String relativePath) {
String path = root + "/" + relativePath;
String path = root + File.separator + relativePath;
try {
// Get absolute filename
//
path = HopVfs.getFileObject(path).getName().getPath();
} catch (Exception e) {
// Ignore, keep simple path
Expand All @@ -439,9 +466,9 @@ private void refreshChangedFiles() {
}

Set<String> ignored = git.getIgnored(null);
for (String ignore : ignored) {
String filename = getAbsoluteFilename(git.getDirectory(), ignore);
ignoredFiles.put(filename, ignore);
for (String file : ignored) {
String path = getAbsoluteFilename(git.getDirectory(), file);
ignoredFiles.put(path, file);
}
}
}
Expand Down Expand Up @@ -486,16 +513,11 @@ private void enableButtons() {
*/
@Override
public void filePainted(Tree tree, TreeItem treeItem, String path, String name) {
// Normalize path
String absolutePath = getAbsoluteFilename(path);

GuiResource guiResource = GuiResource.getInstance();
UIFile file = null;
// Changed git file colored blue
try {
file = changedFiles.get(HopVfs.getFileObject(path).getName().getPath());
} catch (HopFileException e) {
// do nothing
}

UIFile file = changedFiles.get(absolutePath);
if (file != null) {
switch (file.getChangeType()) {
case DELETE, MODIFY, RENAME, COPY:
Expand All @@ -510,7 +532,7 @@ public void filePainted(Tree tree, TreeItem treeItem, String path, String name)
break;
}
}
String ignored = ignoredFiles.get(path);
String ignored = ignoredFiles.get(absolutePath);
if (ignored != null) {
treeItem.setForeground(colorIgnored);
}
Expand Down Expand Up @@ -563,18 +585,18 @@ public UIGit getGit() {
}

/**
* Gets changedFiles
* Gets changed files
*
* @return value of changedFiles
* @return map of changed files
*/
public Map<String, UIFile> getChangedFiles() {
return changedFiles;
}

/**
* Gets ignoredFiles
* Gets ignored files
*
* @return value of ignoredFiles
* @return map of ignored files
*/
public Map<String, String> getIgnoredFiles() {
return ignoredFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,12 @@ public void renderFile(Composite composite) {
new ColumnInfo("Comment", ColumnInfo.COLUMN_TYPE_TEXT),
};
wRevisions =
new TableView(hopGui.getVariables(), composite, SWT.NONE, revisionColumns, 1, null, props);
new TableView(
hopGui.getVariables(), composite, SWT.BORDER, revisionColumns, 1, null, props);
wRevisions.setReadonly(true);
PropsUi.setLook(wRevisions);
FormData fdRevisions = new FormData();
fdRevisions.left = new FormAttachment(0, margin);
fdRevisions.left = new FormAttachment(0, 0);
fdRevisions.top = new FormAttachment(lastControl, margin);
fdRevisions.right = new FormAttachment(100, 0);
fdRevisions.bottom = new FormAttachment(40, 0);
Expand Down Expand Up @@ -235,9 +236,10 @@ public void renderFile(Composite composite) {
ColumnInfo[] filesColumns = {
new ColumnInfo("Filename", ColumnInfo.COLUMN_TYPE_TEXT),
new ColumnInfo("Status", ColumnInfo.COLUMN_TYPE_TEXT),
new ColumnInfo("Staged?", ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] {"Y", "N"}),
new ColumnInfo("Staged", ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] {"Y", "N"}),
};
wFiles = new TableView(hopGui.getVariables(), sashForm, SWT.NONE, filesColumns, 1, null, props);
wFiles =
new TableView(hopGui.getVariables(), sashForm, SWT.BORDER, filesColumns, 1, null, props);
wFiles.setReadonly(true);
PropsUi.setLook(wFiles);
wFiles.table.addListener(SWT.Selection, e -> fileSelected());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void addRemote(String value) {

public void removeRemote() {
RemoteRemoveCommand cmd = git.remoteRemove();
cmd.setName(Constants.DEFAULT_REMOTE_NAME);
cmd.setRemoteName(Constants.DEFAULT_REMOTE_NAME);
try {
cmd.call();
} catch (GitAPIException e) {
Expand Down

0 comments on commit 26fa4eb

Please sign in to comment.