Skip to content

Commit 52d2fd4

Browse files
authored
Clear log action. (#2214)
* Clear log action. * wordsmithing * fixed updating
1 parent 7439267 commit 52d2fd4

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/io/flutter/logging/FlutterLogView.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.intellij.execution.process.ProcessHandler;
1111
import com.intellij.execution.ui.ConsoleView;
1212
import com.intellij.execution.ui.ConsoleViewContentType;
13+
import com.intellij.icons.AllIcons;
1314
import com.intellij.openapi.Disposable;
1415
import com.intellij.openapi.actionSystem.*;
1516
import com.intellij.openapi.application.ApplicationManager;
@@ -34,7 +35,6 @@
3435
import javax.swing.tree.DefaultMutableTreeNode;
3536
import javax.swing.tree.DefaultTreeModel;
3637
import javax.swing.tree.MutableTreeNode;
37-
import javax.swing.tree.TreeNode;
3838
import java.text.SimpleDateFormat;
3939

4040
public class FlutterLogView extends JPanel implements ConsoleView, DataProvider, FlutterLog.Listener {
@@ -101,6 +101,25 @@ void setBounds(TableColumn column) {
101101
}
102102
}
103103

104+
private class ClearLogAction extends AnAction {
105+
ClearLogAction() {
106+
super("Clear All", "Clear the log", AllIcons.Actions.GC);
107+
}
108+
109+
@Override
110+
public void actionPerformed(AnActionEvent e) {
111+
ApplicationManager.getApplication().invokeLater(() -> {
112+
model.getRoot().removeAllChildren();
113+
model.update();
114+
});
115+
}
116+
117+
@Override
118+
public void update(AnActionEvent e) {
119+
e.getPresentation().setEnabled(model.getRoot().getChildCount() > 0);
120+
}
121+
}
122+
104123
@NotNull final FlutterApp app;
105124
final FlutterLogTreeTableModel model;
106125
private final FlutterLogTreeTable treeTable;
@@ -150,6 +169,7 @@ public FlutterLogView(@NotNull FlutterApp app) {
150169
}
151170

152171
private DefaultActionGroup createToolbar() {
172+
//noinspection UnnecessaryLocalVariable
153173
final DefaultActionGroup toolbarGroup = new DefaultActionGroup();
154174
// TODO(pq): add toolbar items.
155175
return toolbarGroup;
@@ -228,8 +248,9 @@ public boolean canPause() {
228248
@NotNull
229249
@Override
230250
public AnAction[] createConsoleActions() {
231-
// TODO(pq): consider actions (show up in a vertical bar).
232-
return new AnAction[0];
251+
return new AnAction[]{
252+
new ClearLogAction()
253+
};
233254
}
234255

235256
@Override
@@ -275,7 +296,7 @@ public FlutterLogTreeTableModel(@NotNull FlutterLog log, @NotNull Disposable par
275296

276297
updateRunnable = () -> {
277298
((AbstractTableModel)treeTable.getModel()).fireTableDataChanged();
278-
reload((TreeNode)getRoot());
299+
reload(getRoot());
279300
treeTable.updateUI();
280301

281302
// Auto-scroll.
@@ -295,6 +316,11 @@ private void update() {
295316
}
296317
}
297318

319+
@Override
320+
public LogRootTreeNode getRoot() {
321+
return (LogRootTreeNode)super.getRoot();
322+
}
323+
298324
private LogTreeColumn getColumn(int index) {
299325
return LogTreeColumn.values()[index];
300326
}
@@ -338,7 +364,7 @@ public void setTree(JTree tree) {
338364
}
339365

340366
public void onEvent(FlutterLogEntry entry) {
341-
final MutableTreeNode root = (MutableTreeNode)getRoot();
367+
final MutableTreeNode root = getRoot();
342368
final FlutterEventNode node = new FlutterEventNode(entry);
343369
ApplicationManager.getApplication().invokeLater(() -> {
344370
insertNodeInto(node, root, root.getChildCount());

0 commit comments

Comments
 (0)