Skip to content

Commit

Permalink
Add feature auto close on focus lost preference
Browse files Browse the repository at this point in the history
  • Loading branch information
d-akara committed May 12, 2018
1 parent 07d75b6 commit 6b2d5b4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,31 @@ public void initialize(Display display) throws ExecutionException {
ListRankAndFilter<QuickAccessElement> listRankAndFilter = CommanderContentProviders.listRankAndFilter(labelField, providerField);

eclipseCommandProvider = new EclipseCommandProvider();
PersistedWorkingSet<QuickAccessElement> historyStore = createSettingsStore(eclipseCommandProvider);
PersistedWorkingSet<QuickAccessElement> settingsStore = createSettingsStore(eclipseCommandProvider);

kaviPickList = new KaviPickListDialog<>();
kaviPickList.setListContentProvider("discovery", CommanderContentProviders.listContentDiscoveryProvider(listRankAndFilter, historyStore, eclipseCommandProvider))
.setResolvedAction(resolvedAction(display, historyStore))
kaviPickList.setListContentProvider("discovery", CommanderContentProviders.listContentDiscoveryProvider(listRankAndFilter, settingsStore, eclipseCommandProvider))
.setResolvedAction(resolvedAction(display, settingsStore))
.addColumn(labelField.fieldId, labelField.fieldResolver).widthPercent(100)
.addColumn(providerField.fieldId, providerField.fieldResolver).width(85).right().italic().fontColor(100, 100, 100).backgroundColor(250, 250, 250);

kaviPickList.setListContentProvider("working", CommanderContentProviders.listContentRecallProvider(listRankAndFilter, historyStore, eclipseCommandProvider))
.setResolvedAction(resolvedAction(display, historyStore))
kaviPickList.setListContentProvider("working", CommanderContentProviders.listContentRecallProvider(listRankAndFilter, settingsStore, eclipseCommandProvider))
.setResolvedAction(resolvedAction(display, settingsStore))
.addColumn(labelField.fieldId, labelField.fieldResolver).widthPercent(100).setMarkerIndicatorProvider(item -> {
HistoryEntry historyEntry = historyStore.getHistoryEntry(item);
HistoryEntry historyEntry = settingsStore.getHistoryEntry(item);
if (historyEntry == null) return false;
return historyEntry.keepForever;
})
.addColumn(providerField.fieldId, providerField.fieldResolver).width(85).right().italic().fontColor(100, 100, 100).backgroundColor(250, 250, 250);

InternalCommandContextProvider contextProvider = InternalCommandContextProviderFactory.makeProvider(kaviPickList, historyStore);
InternalCommandContextProviderFactory.addWorkingSetCommands(contextProvider, kaviPickList, historyStore);
InternalCommandContextProviderFactory.addExportImportCommands(contextProvider, kaviPickList, historyStore, "commander-settings.json");
InternalCommandContextProvider contextProvider = InternalCommandContextProviderFactory.makeProvider(kaviPickList, settingsStore);
InternalCommandContextProviderFactory.addWorkingSetCommands(contextProvider, kaviPickList, settingsStore);
InternalCommandContextProviderFactory.addExportImportCommands(contextProvider, kaviPickList, settingsStore, "commander-settings.json");
InternalCommandContextProviderFactory.installProvider(contextProvider, kaviPickList);

kaviPickList.setBounds(600, 400);
kaviPickList.setCurrentProvider(historyStore.getContentMode());
kaviPickList.setCurrentProvider(settingsStore.getContentMode());
kaviPickList.setAutoCloseOnFocusLost(settingsStore.getAutoCloseFocusLost());
kaviPickList.open();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ public String getContentMode() {
return contentMode;
}

public PersistedWorkingSet<T> setAutoCloseFocusLost(boolean autoClose) {
commanderSettings.autoCloseFocusLost = autoClose;
return this;
}

public boolean getAutoCloseFocusLost() {
return commanderSettings.autoCloseFocusLost;
}

public PersistedWorkingSet<T> setHistoryPermanent(T historyItem, boolean permanent) {
historyChangedSinceCheck = true;
HistoryEntry entry = makeEntry(historyItem);
Expand All @@ -140,8 +149,9 @@ public PersistedWorkingSet<T> removeHistory(T historyItem) {

public class CommanderSettings {
private String featureId;
private int version = 1;
private int version = 2;
private String contentMode;
private boolean autoCloseFocusLost = false;
private final List<HistoryEntry> entries;
public CommanderSettings(String featureId, List<HistoryEntry> entries) {
this.featureId = featureId;
Expand Down Expand Up @@ -211,6 +221,10 @@ private CommanderSettings migrateSettings(CommanderSettings settings) {
settings.version = 1;
settings.contentMode = "working"; // assume those who have already been using Commander are already expect his behavior
}
if (settings.version == 1) {
settings.version = 2;
settings.autoCloseFocusLost = false; // existing default behavior
}
if (!settings.featureId.equals(this.featureId)) {
throw new RuntimeException("Settings featureId [" + settings.featureId + "] does not match [" + this.featureId + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ private static void addDefaultInternalCommands(InternalCommandContextProvider pr
currentProvider.refreshFromContentProvider();
kaviPickList.refresh();
});

provider.addCommand(command -> {
return "Settings: Toggle Auto Close On Focus Lost: " + historyStore.getAutoCloseFocusLost();
},
(currentProvider, command) -> {
historyStore.setAutoCloseFocusLost(!historyStore.getAutoCloseFocusLost());
historyStore.save();
currentProvider.refreshFromContentProvider();
kaviPickList.refresh();
});

}

public static void addWorkingSetCommands(InternalCommandContextProvider contextProvider, KaviPickListDialog kaviPickList, PersistedWorkingSet historyStore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class KaviPickListDialog<T> extends PopupDialog {
private final KaviList<T> kaviList;
private Text listFilterInputControl;
private final StatusDisplayInfo displayInfo = new StatusDisplayInfo();
private boolean autoCloseOnFocusLost = false;

public KaviPickListDialog() {
super(ProgressManagerUtil.getDefaultParent(), SWT.RESIZE | SWT.NO_BACKGROUND, true, true, false, true, true, null, "Central Command");
Expand Down Expand Up @@ -85,6 +86,8 @@ public void show() {

@Override
public boolean close() {
if (autoCloseOnFocusLost) return super.close();

// override so that losing focus does not close dialog
return false;
}
Expand Down Expand Up @@ -139,6 +142,10 @@ public void refresh() {
kaviList.refresh();
}

public void setAutoCloseOnFocusLost(boolean autoClose) {
this.autoCloseOnFocusLost = autoClose;
}

private class StatusDisplayInfo {
public String mode;
public int itemCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
public class FinderHandler extends AbstractHandler implements IStartup {
private static EclipsePluginLogger logger = new EclipsePluginLogger(Constants.BUNDLE_ID);
private boolean initialized = false;
private PersistedWorkingSet<ResourceItem> historyStore = null;
private PersistedWorkingSet<ResourceItem> settingsStore = null;
private List<ResourceItem> files = null;
private long lastResourceRefresh = 0l;

Expand All @@ -64,9 +64,9 @@ public void earlyStartup() {
private void initialize() {
if (!initialized) {
initialized = true;
historyStore = createSettingsStore();
settingsStore = createSettingsStore();
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage();
EclipseWorkbench.createListenerForEditorFocusChanges(workbenchPage, resourceItem -> historyStore.addToHistory(resourceItem).save());
EclipseWorkbench.createListenerForEditorFocusChanges(workbenchPage, resourceItem -> settingsStore.addToHistory(resourceItem).save());

EclipseWorkbench.notifyResourceAddedOrRemoved(() -> {
files = null;
Expand All @@ -88,30 +88,30 @@ public Object execute(ExecutionEvent event) throws ExecutionException {

KaviPickListDialog<ResourceItem> finder = new KaviPickListDialog<>();
finder.setListContentProvider("discovery", listContentProvider(listRankAndFilter(nameResolver, pathResolver, projectResolver), this::getAllFileAndTypeResources))
.setMultiResolvedAction(resourceItems -> handleSelectionAction(historyStore, workbenchPage, workspace, resourceItems))
.setMultiResolvedAction(resourceItems -> handleSelectionAction(settingsStore, workbenchPage, workspace, resourceItems))
.setShowAllWhenNoFilter(false)
.setDebounceTimeProvider(inputCommand -> inputCommand.countFilterableCharacters() > 2 ? 50:200)
.addColumn(nameResolver.fieldId, nameResolver.fieldResolver).widthPercent(30)
.addColumn(projectResolver.fieldId, projectResolver.fieldResolver).widthPercent(30).fontColor(155, 103, 4)
.addColumn(pathResolver.fieldId, pathResolver.fieldResolver).widthPercent(40).italic().fontColor(100, 100, 100).backgroundColor(250, 250, 250);

finder.setListContentProvider("working", listContentProviderWorkingSet(listRankAndFilter(nameResolver, pathResolver, projectResolver), historyStore))
.setMultiResolvedAction(resourceItems -> handleSelectionAction(historyStore, workbenchPage, workspace, resourceItems))
finder.setListContentProvider("working", listContentProviderWorkingSet(listRankAndFilter(nameResolver, pathResolver, projectResolver), settingsStore))
.setMultiResolvedAction(resourceItems -> handleSelectionAction(settingsStore, workbenchPage, workspace, resourceItems))
.addColumn(nameResolver.fieldId, nameResolver.fieldResolver).widthPercent(30).setMarkerIndicatorProvider(item -> {
HistoryEntry historyEntry = historyStore.getHistoryEntry(item);
HistoryEntry historyEntry = settingsStore.getHistoryEntry(item);
if (historyEntry == null) return false;
return historyEntry.keepForever;
})
.addColumn(projectResolver.fieldId, projectResolver.fieldResolver).widthPercent(30).fontColor(155, 103, 4)
.addColumn(pathResolver.fieldId, pathResolver.fieldResolver).widthPercent(40).italic().fontColor(100, 100, 100).backgroundColor(250, 250, 250);


InternalCommandContextProvider contextProvider = InternalCommandContextProviderFactory.makeProvider(finder, historyStore);
InternalCommandContextProviderFactory.addWorkingSetCommands(contextProvider, finder, historyStore);
InternalCommandContextProviderFactory.addExportImportCommands(contextProvider, finder, historyStore, "finder-settings_" + EclipseWorkbench.workspaceName() + ".json");
InternalCommandContextProvider contextProvider = InternalCommandContextProviderFactory.makeProvider(finder, settingsStore);
InternalCommandContextProviderFactory.addWorkingSetCommands(contextProvider, finder, settingsStore);
InternalCommandContextProviderFactory.addExportImportCommands(contextProvider, finder, settingsStore, "finder-settings_" + EclipseWorkbench.workspaceName() + ".json");
InternalCommandContextProviderFactory.installProvider(contextProvider, finder);

finder.setCurrentProvider(historyStore.getContentMode());
finder.setCurrentProvider(settingsStore.getContentMode());
finder.setBounds(800, 400);
finder.open();
return null;
Expand Down

0 comments on commit 6b2d5b4

Please sign in to comment.