Skip to content

Commit

Permalink
LogView: Option to activate on Error only
Browse files Browse the repository at this point in the history
For the case that someone is not interested in A LogView popping up for
info items.
  • Loading branch information
EcljpseB0T authored and jukzi committed Mar 5, 2024
1 parent 1c1bdd2 commit d6e7495
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class LogView extends ViewPart implements LogListener {
protected static final String P_COLUMN_2 = "column3"; //$NON-NLS-1$
protected static final String P_COLUMN_3 = "column4"; //$NON-NLS-1$
public static final String P_ACTIVATE = "activate"; //$NON-NLS-1$
public static final String P_ACTIVATE_WARN = "activateWarn"; //$NON-NLS-1$
public static final String P_ACTIVATE_ERRROR = "activateError"; //$NON-NLS-1$
public static final String P_SHOW_FILTER_TEXT = "show_filter_text"; //$NON-NLS-1$
public static final String P_ORDER_TYPE = "orderType"; //$NON-NLS-1$
public static final String P_ORDER_VALUE = "orderValue"; //$NON-NLS-1$
Expand Down Expand Up @@ -147,6 +149,8 @@ public class LogView extends ViewPart implements LogListener {
private Action fReadLogAction;
private Action fCopyAction;
private Action fActivateViewAction;
private Action fActivateViewWarnAction;
private Action fActivateViewErrorAction;
private Action fOpenLogAction;
private Action fExportLogAction;
private Action fExportLogEntryAction;
Expand Down Expand Up @@ -311,8 +315,14 @@ private void createActions() {
mgr.add(createFilterAction());
mgr.add(new Separator());

fActivateViewAction = createActivateViewAction();
fActivateViewAction = createActivateViewAction(Messages.LogView_activate, P_ACTIVATE);
mgr.add(fActivateViewAction);
fActivateViewWarnAction = createActivateViewAction(Messages.LogView_activateWarn, P_ACTIVATE_WARN);
mgr.add(fActivateViewWarnAction);
fActivateViewErrorAction = createActivateViewAction(Messages.LogView_activateError, P_ACTIVATE_ERRROR);
mgr.add(fActivateViewErrorAction);
mgr.add(new Separator());

if (fFilteredTree.getFilterControl() != null)
mgr.add(createShowTextFilter());

Expand Down Expand Up @@ -349,14 +359,29 @@ private void createActions() {
fTree.setMenu(menu);
}

private Action createActivateViewAction() {
Action action = new Action(Messages.LogView_activate) { //
private Action createActivateViewAction(String msg, String key) {
Action action = new Action(msg) {
@Override
public void run() {
fMemento.putString(P_ACTIVATE, isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
if (isChecked()) {
// on disabling one disable the others:
if (P_ACTIVATE.equals(key)) {
fActivateViewWarnAction.setChecked(false);
fActivateViewErrorAction.setChecked(false);
} else if (P_ACTIVATE_WARN.equals(key)) {
fActivateViewAction.setChecked(false);
fActivateViewErrorAction.setChecked(false);
} else if (P_ACTIVATE_ERRROR.equals(key)) {
fActivateViewAction.setChecked(false);
fActivateViewWarnAction.setChecked(false);
}
}
fMemento.putString(P_ACTIVATE, Boolean.toString(fActivateViewAction.isChecked()));
fMemento.putString(P_ACTIVATE_WARN, Boolean.toString(fActivateViewWarnAction.isChecked()));
fMemento.putString(P_ACTIVATE_ERRROR, Boolean.toString(fActivateViewErrorAction.isChecked()));
}
};
action.setChecked(fMemento.getString(P_ACTIVATE).equals("true")); //$NON-NLS-1$
action.setChecked(Boolean.parseBoolean(fMemento.getString(key)));
return action;
}

Expand Down Expand Up @@ -746,7 +771,7 @@ protected void setLogFile(File path) {
} finally {
fReadLogAction.setText(Messages.LogView_readLog_reload);
fReadLogAction.setToolTipText(Messages.LogView_readLog_reload);
asyncRefresh(false);
asyncRefresh();
resetDialogButtons();
}
}
Expand Down Expand Up @@ -842,7 +867,7 @@ public void handleClear() {
currentSession.removeAllChildren();
}
}
asyncRefresh(false);
asyncRefresh();
resetDialogButtons();
});
}
Expand All @@ -862,7 +887,7 @@ protected void reloadLog() {
} finally {
fReadLogAction.setText(Messages.LogView_readLog_restore);
fReadLogAction.setToolTipText(Messages.LogView_readLog_restore);
asyncRefresh(false);
asyncRefresh();
resetDialogButtons();
}
}
Expand Down Expand Up @@ -891,15 +916,15 @@ private CompletableFuture<List<LogEntry>> fetchLogEntries() {
}

private void updateLogViewer(List<LogEntry> entries) {
OptionalInt maxSeverity = entries.stream().mapToInt(LogEntry::getSeverity).max();
synchronized (elements) {
elements.clear();
groups.clear();
group(entries);
limitEntriesCount();
}
setContentDescription(getTitleSummary());

asyncRefresh(false);
maxSeverity.ifPresent(this::asyncRefreshAndActivate);
}

private Display getDisplay() {
Expand Down Expand Up @@ -1102,7 +1127,6 @@ public void logged(org.osgi.service.log.LogEntry input) {

if (shouldReadLog) {
readLogFile();
asyncRefresh(true);
} else {
LogEntry entry = betterInput != null ? createLogEntry(betterInput) : createLogEntry(input);

Expand All @@ -1117,7 +1141,6 @@ public void logged(org.osgi.service.log.LogEntry input) {
}
if (!useBatchedEntries) {
pushEntry(entry);
asyncRefresh(true);
}
}
}
Expand All @@ -1139,7 +1162,6 @@ protected IStatus run(IProgressMonitor monitor) {
}
}
}
asyncRefresh(true);
return Status.OK_STATUS;
}
};
Expand Down Expand Up @@ -1187,7 +1209,7 @@ private void pushEntry(LogEntry entry) {
limitEntriesCount();
}
}
asyncRefresh(true);
asyncRefreshAndActivate(entry.getSeverity());
}

private Throttler createMutualRefresh(Display display) {
Expand Down Expand Up @@ -1226,15 +1248,18 @@ private Throttler createMutualActivate(Display display) {
});
}

private void asyncRefresh(final boolean activate) {
if (fTree.isDisposed())
return;
mutualRefresh.throttledExec();
if (activate && fActivateViewAction.isChecked()) {
private void asyncRefreshAndActivate(int severity) {
asyncRefresh();
if ((fActivateViewAction.isChecked()) || (severity >= IStatus.WARNING && fActivateViewWarnAction.isChecked())
|| (severity >= IStatus.ERROR && fActivateViewErrorAction.isChecked())) {
mutualActivate.throttledExec();
}
}

private void asyncRefresh() {
mutualRefresh.throttledExec();
}

@Override
public void setFocus() {
if (isDisposed()) {
Expand Down Expand Up @@ -1384,7 +1409,9 @@ public void saveState(IMemento memento) {
this.fMemento.putInteger(P_COLUMN_1, getColumnWidth(fColumn1, 300));
this.fMemento.putInteger(P_COLUMN_2, getColumnWidth(fColumn2, 150));
this.fMemento.putInteger(P_COLUMN_3, getColumnWidth(fColumn3, 150));
this.fMemento.putString(P_ACTIVATE, fActivateViewAction.isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
this.fMemento.putString(P_ACTIVATE, Boolean.toString(fActivateViewAction.isChecked()));
this.fMemento.putString(P_ACTIVATE_WARN, Boolean.toString(fActivateViewWarnAction.isChecked()));
this.fMemento.putString(P_ACTIVATE_ERRROR, Boolean.toString(fActivateViewErrorAction.isChecked()));
memento.putMemento(this.fMemento);
writeSettings();
}
Expand Down Expand Up @@ -1736,6 +1763,10 @@ private void readSettings() {
fMemento.putInteger(P_COLUMN_2, getColumnWidthPreference(instancePrefs, defaultPrefs, P_COLUMN_2, 150));
fMemento.putInteger(P_COLUMN_3, getColumnWidthPreference(instancePrefs, defaultPrefs, P_COLUMN_3, 150));
fMemento.putBoolean(P_ACTIVATE, instancePrefs.getBoolean(P_ACTIVATE, defaultPrefs.getBoolean(P_ACTIVATE, true)));
fMemento.putBoolean(P_ACTIVATE_WARN,
instancePrefs.getBoolean(P_ACTIVATE_WARN, defaultPrefs.getBoolean(P_ACTIVATE_WARN, true)));
fMemento.putBoolean(P_ACTIVATE_ERRROR,
instancePrefs.getBoolean(P_ACTIVATE_ERRROR, defaultPrefs.getBoolean(P_ACTIVATE_ERRROR, true)));
fMemento.putInteger(P_ORDER_VALUE, instancePrefs.getInt(P_ORDER_VALUE, defaultPrefs.getInt(P_ORDER_VALUE, DESCENDING)));
fMemento.putInteger(P_ORDER_TYPE, instancePrefs.getInt(P_ORDER_TYPE, defaultPrefs.getInt(P_ORDER_TYPE, LogView.DATE)));
fMemento.putBoolean(P_SHOW_FILTER_TEXT, instancePrefs.getBoolean(P_SHOW_FILTER_TEXT, defaultPrefs.getBoolean(P_SHOW_FILTER_TEXT, true)));
Expand Down Expand Up @@ -1797,6 +1828,8 @@ private void writeViewSettings() {
instancePrefs.putInt(P_COLUMN_2, fMemento.getInteger(P_COLUMN_2).intValue());
instancePrefs.putInt(P_COLUMN_3, fMemento.getInteger(P_COLUMN_3).intValue());
instancePrefs.putBoolean(P_ACTIVATE, fMemento.getBoolean(P_ACTIVATE).booleanValue());
instancePrefs.putBoolean(P_ACTIVATE_WARN, fMemento.getBoolean(P_ACTIVATE_WARN).booleanValue());
instancePrefs.putBoolean(P_ACTIVATE_ERRROR, fMemento.getBoolean(P_ACTIVATE_ERRROR).booleanValue());
instancePrefs.putInt(P_ORDER_VALUE, fMemento.getInteger(P_ORDER_VALUE).intValue());
instancePrefs.putInt(P_ORDER_TYPE, fMemento.getInteger(P_ORDER_TYPE).intValue());
instancePrefs.putBoolean(P_SHOW_FILTER_TEXT, fMemento.getBoolean(P_SHOW_FILTER_TEXT).booleanValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class Messages extends NLS {
public static String LogView_operation_importing;
public static String LogView_operation_reloading;
public static String LogView_activate;
public static String LogView_activateWarn;
public static String LogView_activateError;
public static String LogView_AddingBatchedEvents;
public static String LogView_view_currentLog;
public static String LogView_view_currentLog_tooltip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ LogView_confirmOverwrite_message = File " {0}" exists. Would you like to overwri
LogView_confirmDelete_deleteButton = &Delete All Events
LogView_operation_importing = Importing log...
LogView_operation_reloading = Reloading...
LogView_activate = &Activate on new events
LogView_activate = &Activate on any new event
LogView_activateWarn = Activate on new warning or error
LogView_activateError = Activate on new error
LogView_AddingBatchedEvents=Adding batched log events...
LogView_view_currentLog = &Open Log
LogView_view_currentLog_tooltip = Open Log
Expand Down

0 comments on commit d6e7495

Please sign in to comment.