MainWindow.java 50.0 KB
Newer Older
S
Skylot 已提交
1
package jadx.gui.ui;
S
Skylot 已提交
2

3
import java.awt.AWTEvent;
4 5 6 7 8 9 10
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
11
import java.awt.Rectangle;
12
import java.awt.Toolkit;
13 14
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
S
Skylot 已提交
15 16
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
S
Skylot 已提交
17 18
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
19
import java.awt.event.InputEvent;
20
import java.awt.event.KeyAdapter;
S
Skylot 已提交
21
import java.awt.event.KeyEvent;
S
Skylot 已提交
22 23
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
24 25
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
26
import java.awt.geom.AffineTransform;
S
Skylot 已提交
27
import java.io.InputStream;
28
import java.net.URL;
29 30
import java.nio.file.Files;
import java.nio.file.Path;
31
import java.nio.file.Paths;
32
import java.util.ArrayList;
S
Skylot 已提交
33
import java.util.Arrays;
34 35
import java.util.Collections;
import java.util.HashSet;
36
import java.util.List;
37
import java.util.Locale;
38
import java.util.Set;
39 40
import java.util.Timer;
import java.util.TimerTask;
41
import java.util.stream.Collectors;
S
Skylot 已提交
42

43 44 45 46 47
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
48
import javax.swing.JFileChooser;
49 50 51 52 53 54
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
55
import javax.swing.JPopupMenu;
56 57 58 59 60 61
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
62
import javax.swing.ToolTipManager;
63
import javax.swing.WindowConstants;
64 65 66 67 68 69 70 71 72 73 74
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeWillExpandListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

75
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
76
import org.fife.ui.rsyntaxtextarea.Theme;
77
import org.jetbrains.annotations.NotNull;
78
import org.jetbrains.annotations.Nullable;
S
Skylot 已提交
79 80 81
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

82
import ch.qos.logback.classic.Level;
83
import net.fabricmc.mappingio.format.MappingFormat;
84

85
import jadx.api.JadxArgs;
86
import jadx.api.JavaNode;
S
Skylot 已提交
87
import jadx.api.ResourceFile;
88
import jadx.api.plugins.utils.CommonFileUtils;
89
import jadx.core.Jadx;
90
import jadx.core.utils.ListUtils;
91
import jadx.core.utils.StringUtils;
92
import jadx.core.utils.files.FileUtils;
S
Skylot 已提交
93
import jadx.gui.JadxWrapper;
94
import jadx.gui.device.debugger.BreakpointManager;
95
import jadx.gui.jobs.BackgroundExecutor;
96
import jadx.gui.jobs.DecompileTask;
97
import jadx.gui.jobs.ExportTask;
98
import jadx.gui.jobs.ProcessResult;
99
import jadx.gui.jobs.TaskStatus;
100
import jadx.gui.plugins.mappings.MappingExporter;
101
import jadx.gui.plugins.quark.QuarkDialog;
102
import jadx.gui.settings.JadxProject;
S
Skylot 已提交
103 104
import jadx.gui.settings.JadxSettings;
import jadx.gui.settings.JadxSettingsWindow;
105 106
import jadx.gui.treemodel.ApkSignature;
import jadx.gui.treemodel.JClass;
107
import jadx.gui.treemodel.JField;
108
import jadx.gui.treemodel.JLoadableNode;
109
import jadx.gui.treemodel.JMethod;
110
import jadx.gui.treemodel.JNode;
111
import jadx.gui.treemodel.JPackage;
112 113
import jadx.gui.treemodel.JResource;
import jadx.gui.treemodel.JRoot;
114
import jadx.gui.ui.codearea.AbstractCodeArea;
115
import jadx.gui.ui.codearea.AbstractCodeContentPanel;
116
import jadx.gui.ui.codearea.EditorTheme;
S
Skylot 已提交
117
import jadx.gui.ui.codearea.EditorViewState;
118 119 120 121 122
import jadx.gui.ui.dialog.ADBDialog;
import jadx.gui.ui.dialog.AboutDialog;
import jadx.gui.ui.dialog.LogViewerDialog;
import jadx.gui.ui.dialog.RenameDialog;
import jadx.gui.ui.dialog.SearchDialog;
123 124
import jadx.gui.ui.filedialog.FileDialogWrapper;
import jadx.gui.ui.filedialog.FileOpenMode;
125
import jadx.gui.ui.panel.ContentPanel;
126
import jadx.gui.ui.panel.IssuesPanel;
127 128 129
import jadx.gui.ui.panel.JDebuggerPanel;
import jadx.gui.ui.panel.ProgressPanel;
import jadx.gui.ui.popupmenu.JPackagePopupMenu;
S
Skylot 已提交
130
import jadx.gui.ui.treenodes.StartPageNode;
131
import jadx.gui.ui.treenodes.SummaryNode;
S
Skylot 已提交
132 133 134 135
import jadx.gui.update.JadxUpdate;
import jadx.gui.update.JadxUpdate.IUpdateCallback;
import jadx.gui.update.data.Release;
import jadx.gui.utils.CacheObject;
136
import jadx.gui.utils.FontUtils;
137
import jadx.gui.utils.ILoadListener;
S
Skylot 已提交
138
import jadx.gui.utils.Icons;
139
import jadx.gui.utils.LafManager;
S
Skylot 已提交
140 141
import jadx.gui.utils.Link;
import jadx.gui.utils.NLS;
142
import jadx.gui.utils.SystemInfo;
143
import jadx.gui.utils.UiUtils;
144
import jadx.gui.utils.fileswatcher.LiveReloadWorker;
145
import jadx.gui.utils.logs.LogCollector;
146
import jadx.gui.utils.ui.ActionHandler;
147
import jadx.gui.utils.ui.NodeLabel;
S
Skylot 已提交
148

149
import static io.reactivex.internal.functions.Functions.EMPTY_RUNNABLE;
150 151
import static javax.swing.KeyStroke.getKeyStroke;

S
Skylot 已提交
152 153 154
public class MainWindow extends JFrame {
	private static final Logger LOG = LoggerFactory.getLogger(MainWindow.class);

155 156
	private static final String DEFAULT_TITLE = "jadx-gui";

S
Skylot 已提交
157 158
	private static final double BORDER_RATIO = 0.15;
	private static final double WINDOW_RATIO = 1 - BORDER_RATIO * 2;
159
	public static final double SPLIT_PANE_RESIZE_WEIGHT = 0.15;
S
Skylot 已提交
160

161 162
	private static final ImageIcon ICON_ADD_FILES = UiUtils.openSvgIcon("ui/addFile");
	private static final ImageIcon ICON_SAVE_ALL = UiUtils.openSvgIcon("ui/menu-saveall");
163
	private static final ImageIcon ICON_RELOAD = UiUtils.openSvgIcon("ui/refresh");
164 165 166 167 168 169 170 171 172
	private static final ImageIcon ICON_EXPORT = UiUtils.openSvgIcon("ui/export");
	private static final ImageIcon ICON_EXIT = UiUtils.openSvgIcon("ui/exit");
	private static final ImageIcon ICON_SYNC = UiUtils.openSvgIcon("ui/pagination");
	private static final ImageIcon ICON_FLAT_PKG = UiUtils.openSvgIcon("ui/moduleGroup");
	private static final ImageIcon ICON_SEARCH = UiUtils.openSvgIcon("ui/find");
	private static final ImageIcon ICON_FIND = UiUtils.openSvgIcon("ui/ejbFinderMethod");
	private static final ImageIcon ICON_COMMENT_SEARCH = UiUtils.openSvgIcon("ui/usagesFinder");
	private static final ImageIcon ICON_BACK = UiUtils.openSvgIcon("ui/left");
	private static final ImageIcon ICON_FORWARD = UiUtils.openSvgIcon("ui/right");
173
	private static final ImageIcon ICON_QUARK = UiUtils.openSvgIcon("ui/quark");
174 175 176 177 178
	private static final ImageIcon ICON_PREF = UiUtils.openSvgIcon("ui/settings");
	private static final ImageIcon ICON_DEOBF = UiUtils.openSvgIcon("ui/helmChartLock");
	private static final ImageIcon ICON_LOG = UiUtils.openSvgIcon("ui/logVerbose");
	private static final ImageIcon ICON_INFO = UiUtils.openSvgIcon("ui/showInfos");
	private static final ImageIcon ICON_DEBUGGER = UiUtils.openSvgIcon("ui/startDebugger");
179

S
Skylot 已提交
180 181 182
	private final transient JadxWrapper wrapper;
	private final transient JadxSettings settings;
	private final transient CacheObject cacheObject;
183
	private final transient BackgroundExecutor backgroundExecutor;
184 185 186

	private transient @NotNull JadxProject project;

187 188
	private transient Action newProjectAction;
	private transient Action saveProjectAction;
189
	private transient JMenu exportMappingsMenu;
S
Skylot 已提交
190

S
Skylot 已提交
191
	private JPanel mainPanel;
192
	private JSplitPane splitPane;
S
Skylot 已提交
193

S
Skylot 已提交
194
	private JTree tree;
S
Skylot 已提交
195
	private DefaultTreeModel treeModel;
S
Skylot 已提交
196
	private JRoot treeRoot;
S
Skylot 已提交
197
	private TabbedPane tabbedPane;
J
Jan S 已提交
198
	private HeapUsageBar heapUsageBar;
199
	private transient boolean treeReloading;
S
Skylot 已提交
200

S
Skylot 已提交
201
	private boolean isFlattenPackage;
202
	private JToggleButton flatPkgButton;
S
Skylot 已提交
203 204
	private JCheckBoxMenuItem flatPkgMenuItem;

S
Skylot 已提交
205
	private JToggleButton deobfToggleBtn;
S
Skylot 已提交
206 207
	private JCheckBoxMenuItem deobfMenuItem;

208 209 210
	private JCheckBoxMenuItem liveReloadMenuItem;
	private final LiveReloadWorker liveReloadWorker;

S
Skylot 已提交
211 212
	private transient Link updateLink;
	private transient ProgressPanel progressPane;
213
	private transient Theme editorTheme;
214

215 216 217
	private JDebuggerPanel debuggerPanel;
	private JSplitPane verticalSplitter;

218 219 220
	private List<ILoadListener> loadListeners = new ArrayList<>();
	private boolean loaded;

221
	public MainWindow(JadxSettings settings) {
S
Skylot 已提交
222
		this.settings = settings;
S
Skylot 已提交
223
		this.cacheObject = new CacheObject();
224 225
		this.project = new JadxProject(this);
		this.wrapper = new JadxWrapper(this);
226
		this.liveReloadWorker = new LiveReloadWorker(this);
S
Skylot 已提交
227

228
		resetCache();
229
		FontUtils.registerBundledFonts();
S
Skylot 已提交
230
		initUI();
231
		this.backgroundExecutor = new BackgroundExecutor(settings, progressPane);
232
		initMenuAndToolbar();
233
		registerMouseNavigationButtons();
234
		UiUtils.setWindowIcons(this);
235
		loadSettings();
236

237
		update();
238
		checkForUpdate();
239 240
	}

241
	public void init() {
S
Skylot 已提交
242 243
		pack();
		setLocationAndPosition();
244
		splitPane.setDividerLocation(settings.getTreeWidth());
J
Jan S 已提交
245
		heapUsageBar.setVisible(settings.isShowHeapUsageBar());
S
Skylot 已提交
246
		setVisible(true);
247 248
		setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		addWindowListener(new WindowAdapter() {
249
			@Override
250 251 252 253
			public void windowClosing(WindowEvent e) {
				closeWindow();
			}
		});
S
Skylot 已提交
254

255 256 257 258
		processCommandLineArgs();
	}

	private void processCommandLineArgs() {
259
		if (settings.getFiles().isEmpty()) {
S
Skylot 已提交
260
			tabbedPane.showNode(new StartPageNode());
S
Skylot 已提交
261
		} else {
262
			open(FileUtils.fileNamesToPaths(settings.getFiles()), this::handleSelectClassOption);
263 264 265 266 267
		}
	}

	private void handleSelectClassOption() {
		if (settings.getCmdSelectClass() != null) {
268
			JavaNode javaNode = wrapper.searchJavaClassByFullAlias(settings.getCmdSelectClass());
269 270 271
			if (javaNode == null) {
				javaNode = wrapper.searchJavaClassByOrigClassName(settings.getCmdSelectClass());
			}
272 273 274 275
			if (javaNode == null) {
				JOptionPane.showMessageDialog(this,
						NLS.str("msg.cmd_select_class_error", settings.getCmdSelectClass()),
						NLS.str("error_dialog.title"), JOptionPane.ERROR_MESSAGE);
276
				return;
277
			}
278
			tabbedPane.codeJump(cacheObject.getNodeCache().makeFrom(javaNode));
S
Skylot 已提交
279 280 281
		}
	}

282
	private void checkForUpdate() {
S
Skylot 已提交
283 284 285
		if (!settings.isCheckForUpdates()) {
			return;
		}
286
		JadxUpdate.check(new IUpdateCallback() {
S
Skylot 已提交
287
			@Override
288
			public void onUpdate(Release r) {
A
Ahmed Ashour 已提交
289 290 291
				SwingUtilities.invokeLater(() -> {
					updateLink.setText(NLS.str("menu.update_label", r.getName()));
					updateLink.setVisible(true);
S
Skylot 已提交
292 293 294
				});
			}
		});
295 296
	}

S
Skylot 已提交
297
	public void openFileDialog() {
298
		showOpenDialog(FileOpenMode.OPEN);
S
Skylot 已提交
299 300 301
	}

	public void openProjectDialog() {
302
		showOpenDialog(FileOpenMode.OPEN_PROJECT);
S
Skylot 已提交
303 304
	}

305
	private void showOpenDialog(FileOpenMode mode) {
306 307 308 309
		saveAll();
		if (!ensureProjectIsSaved()) {
			return;
		}
310
		FileDialogWrapper fileDialog = new FileDialogWrapper(this, mode);
311 312 313 314
		List<Path> openPaths = fileDialog.show();
		if (!openPaths.isEmpty()) {
			settings.setLastOpenFilePath(fileDialog.getCurrentDir());
			open(openPaths);
315 316 317 318
		}
	}

	public void addFiles() {
319
		FileDialogWrapper fileDialog = new FileDialogWrapper(this, FileOpenMode.ADD);
320 321
		List<Path> addPaths = fileDialog.show();
		if (!addPaths.isEmpty()) {
322
			addFiles(addPaths);
323 324 325
		}
	}

326 327 328 329 330
	public void addFiles(List<Path> addPaths) {
		project.setFilePaths(ListUtils.distinctMergeSortedLists(addPaths, project.getFilePaths()));
		reopen();
	}

331
	private void newProject() {
S
Skylot 已提交
332
		saveAll();
333 334
		if (!ensureProjectIsSaved()) {
			return;
335
		}
336
		closeAll();
337
		exportMappingsMenu.setEnabled(false);
338
		updateProject(new JadxProject(this));
339 340
	}

341
	private void saveProject() {
342
		if (!project.isSaveFileSelected()) {
343
			saveProjectAs();
344
		} else {
345 346 347 348 349 350
			project.save();
			update();
		}
	}

	private void saveProjectAs() {
351
		FileDialogWrapper fileDialog = new FileDialogWrapper(this, FileOpenMode.SAVE_PROJECT);
352
		if (project.getFilePaths().size() == 1) {
353
			// If there is only one file loaded we suggest saving the jadx project file next to the loaded file
354 355
			Path projectPath = getProjectPathForFile(this.project.getFilePaths().get(0));
			fileDialog.setSelectedFile(projectPath);
356
		}
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
		List<Path> saveFiles = fileDialog.show();
		if (saveFiles.isEmpty()) {
			return;
		}
		settings.setLastSaveProjectPath(fileDialog.getCurrentDir());
		Path savePath = saveFiles.get(0);
		if (!savePath.getFileName().toString().toLowerCase(Locale.ROOT).endsWith(JadxProject.PROJECT_EXTENSION)) {
			savePath = savePath.resolveSibling(savePath.getFileName() + "." + JadxProject.PROJECT_EXTENSION);
		}
		if (Files.exists(savePath)) {
			int res = JOptionPane.showConfirmDialog(
					this,
					NLS.str("confirm.save_as_message", savePath.getFileName()),
					NLS.str("confirm.save_as_title"),
					JOptionPane.YES_NO_OPTION);
			if (res == JOptionPane.NO_OPTION) {
				return;
374 375
			}
		}
376 377 378
		project.saveAs(savePath);
		settings.addRecentProject(savePath);
		update();
379 380
	}

381
	private void exportMappings(MappingFormat mappingFormat) {
382
		FileDialogWrapper fileDialog = new FileDialogWrapper(this, FileOpenMode.CUSTOM_SAVE);
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
		fileDialog.setTitle(NLS.str("file.export_mappings_as"));
		Path workingDir = project.getWorkingDir();
		Path baseDir = workingDir != null ? workingDir : settings.getLastSaveFilePath();
		if (mappingFormat.hasSingleFile()) {
			fileDialog.setSelectedFile(baseDir.resolve("mappings." + mappingFormat.fileExt));
			fileDialog.setFileExtList(Collections.singletonList(mappingFormat.fileExt));
			fileDialog.setSelectionMode(JFileChooser.FILES_ONLY);
		} else {
			fileDialog.setCurrentDir(baseDir);
			fileDialog.setSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		}
		List<Path> paths = fileDialog.show();
		if (paths.size() != 1) {
			return;
		}
		Path savePath = paths.get(0);
		LOG.info("Export mappings to: {}", savePath.toAbsolutePath());
		backgroundExecutor.execute(NLS.str("progress.export_mappings"),
				() -> new MappingExporter(wrapper.getDecompiler().getRoot())
						.exportMappings(savePath, project.getCodeData(), mappingFormat),
				s -> update());
404 405
	}

S
Skylot 已提交
406 407 408 409 410
	public void open(Path path) {
		open(Collections.singletonList(path), EMPTY_RUNNABLE);
	}

	public void open(List<Path> paths) {
411
		open(paths, EMPTY_RUNNABLE);
412 413
	}

414 415
	private void open(List<Path> paths, Runnable onFinish) {
		saveAll();
416
		closeAll();
417 418
		if (paths.size() == 1 && openSingleFile(paths.get(0), onFinish)) {
			return;
419
		}
420 421 422 423
		// start new project
		project = new JadxProject(this);
		project.setFilePaths(paths);
		loadFiles(onFinish);
424 425
	}

426 427 428 429 430 431 432 433 434
	private boolean openSingleFile(Path singleFile, Runnable onFinish) {
		String fileExtension = CommonFileUtils.getFileExtension(singleFile.getFileName().toString());
		if (fileExtension != null && fileExtension.equalsIgnoreCase(JadxProject.PROJECT_EXTENSION)) {
			openProject(singleFile, onFinish);
			return true;
		}
		// check if project file already saved with default name
		Path projectPath = getProjectPathForFile(singleFile);
		if (Files.exists(projectPath)) {
435
			LOG.info("Loading project {}", projectPath);
436 437 438 439 440 441 442 443 444 445 446
			openProject(projectPath, onFinish);
			return true;
		}
		return false;
	}

	private static Path getProjectPathForFile(Path loadedFile) {
		String fileName = loadedFile.getFileName() + "." + JadxProject.PROJECT_EXTENSION;
		return loadedFile.resolveSibling(fileName);
	}

447
	public synchronized void reopen() {
448 449
		saveAll();
		closeAll();
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
		loadFiles(EMPTY_RUNNABLE);
	}

	private void openProject(Path path, Runnable onFinish) {
		JadxProject jadxProject = JadxProject.load(this, path);
		if (jadxProject == null) {
			JOptionPane.showMessageDialog(
					this,
					NLS.str("msg.project_error"),
					NLS.str("msg.project_error_title"),
					JOptionPane.INFORMATION_MESSAGE);
			jadxProject = new JadxProject(this);
		}
		settings.addRecentProject(path);
		project = jadxProject;
		loadFiles(onFinish);
	}

	private void loadFiles(Runnable onFinish) {
469
		exportMappingsMenu.setEnabled(false);
470
		if (project.getFilePaths().isEmpty()) {
471 472 473
			return;
		}
		backgroundExecutor.execute(NLS.str("progress.load"),
474
				wrapper::open,
475 476 477 478 479 480
				status -> {
					if (status == TaskStatus.CANCEL_BY_MEMORY) {
						showHeapUsageBar();
						UiUtils.errorMessage(this, NLS.str("message.memoryLow"));
						return;
					}
481 482 483 484
					if (status != TaskStatus.COMPLETE) {
						LOG.warn("Loading task incomplete, status: {}", status);
						return;
					}
485
					checkLoadedStatus();
486
					onOpen();
487
					exportMappingsMenu.setEnabled(true);
488 489 490 491
					onFinish.run();
				});
	}

492 493 494 495 496
	private void saveAll() {
		saveOpenTabs();
		BreakpointManager.saveAndExit();
	}

497
	private void closeAll() {
498
		notifyLoadListeners(false);
499 500
		cancelBackgroundJobs();
		clearTree();
501
		resetCache();
502 503 504
		LogCollector.getInstance().reset();
		wrapper.close();
		tabbedPane.closeAllTabs();
505
		UiUtils.resetClipboardOwner();
506 507 508
		System.gc();
	}

509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
	private void checkLoadedStatus() {
		if (!wrapper.getClasses().isEmpty()) {
			return;
		}
		int errors = LogCollector.getInstance().getErrors();
		if (errors > 0) {
			int result = JOptionPane.showConfirmDialog(this,
					NLS.str("message.load_errors", errors),
					NLS.str("message.errorTitle"),
					JOptionPane.OK_CANCEL_OPTION,
					JOptionPane.ERROR_MESSAGE);
			if (result == JOptionPane.OK_OPTION) {
				LogViewerDialog.openWithLevel(this, Level.ERROR);
			}
		} else {
			UiUtils.showMessageBox(this, NLS.str("message.no_classes"));
		}
	}

528
	private void onOpen() {
529 530 531
		deobfToggleBtn.setSelected(settings.isDeobfuscationOn());
		initTree();
		update();
532
		updateLiveReload(project.isEnableLiveReload());
533
		BreakpointManager.init(project.getFilePaths().get(0).toAbsolutePath().getParent());
534 535 536

		backgroundExecutor.execute(NLS.str("progress.load"),
				this::restoreOpenTabs,
537 538 539 540
				status -> {
					runInitialBackgroundJobs();
					notifyLoadListeners(true);
				});
541 542
	}

543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
	public void updateLiveReload(boolean state) {
		if (liveReloadWorker.isStarted() == state) {
			return;
		}
		project.setEnableLiveReload(state);
		liveReloadMenuItem.setEnabled(false);
		backgroundExecutor.execute(
				(state ? "Starting" : "Stopping") + " live reload",
				() -> liveReloadWorker.updateState(state),
				s -> {
					liveReloadMenuItem.setState(state);
					liveReloadMenuItem.setEnabled(true);
				});
	}

558 559
	private void addTreeCustomNodes() {
		treeRoot.replaceCustomNode(ApkSignature.getApkSignature(wrapper));
560
		treeRoot.replaceCustomNode(new SummaryNode(this));
561 562 563
	}

	private boolean ensureProjectIsSaved() {
564
		if (!project.isSaved() && !project.isInitial()) {
565 566 567 568 569 570 571 572 573
			int res = JOptionPane.showConfirmDialog(
					this,
					NLS.str("confirm.not_saved_message"),
					NLS.str("confirm.not_saved_title"),
					JOptionPane.YES_NO_CANCEL_OPTION);
			if (res == JOptionPane.CANCEL_OPTION) {
				return false;
			}
			if (res == JOptionPane.YES_OPTION) {
574
				saveProject();
575 576 577 578 579
			}
		}
		return true;
	}

580
	public void updateProject(@NotNull JadxProject jadxProject) {
581 582 583 584
		this.project = jadxProject;
		update();
	}

585 586 587 588 589 590 591 592
	private void update() {
		newProjectAction.setEnabled(!project.isInitial());
		saveProjectAction.setEnabled(!project.isSaved());

		Path projectPath = project.getProjectPath();
		String pathString;
		if (projectPath == null) {
			pathString = "";
593
		} else {
S
Skylot 已提交
594
			pathString = " [" + projectPath.toAbsolutePath().getParent() + ']';
595 596 597
		}
		setTitle((project.isSaved() ? "" : '*')
				+ project.getName() + pathString + " - " + DEFAULT_TITLE);
598 599 600 601
	}

	protected void resetCache() {
		cacheObject.reset();
602 603
	}

604
	synchronized void runInitialBackgroundJobs() {
S
Skylot 已提交
605 606 607 608
		if (settings.isAutoStartJobs()) {
			new Timer().schedule(new TimerTask() {
				@Override
				public void run() {
609
					waitDecompileTask();
S
Skylot 已提交
610 611 612
				}
			}, 1000);
		}
613 614
	}

615 616 617 618 619
	private static final Object DECOMPILER_TASK_SYNC = new Object();

	public void waitDecompileTask() {
		synchronized (DECOMPILER_TASK_SYNC) {
			try {
620
				DecompileTask decompileTask = new DecompileTask(wrapper);
621
				backgroundExecutor.executeAndWait(decompileTask);
622
				backgroundExecutor.execute(decompileTask.getTitle(), wrapper::unloadClasses).get();
623
				processDecompilationResults(decompileTask.getResult());
624
				System.gc();
625 626 627
			} catch (Exception e) {
				LOG.error("Decompile task execution failed", e);
			}
628
		}
629 630
	}

631 632
	private void processDecompilationResults(ProcessResult decompile) {
		int skippedCls = decompile.getSkipped();
633 634 635
		if (skippedCls == 0) {
			return;
		}
636
		TaskStatus status = decompile.getStatus();
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
		LOG.warn("Decompile and indexing of some classes skipped: {}, status: {}", skippedCls, status);
		switch (status) {
			case CANCEL_BY_USER: {
				String reason = NLS.str("message.userCancelTask");
				String message = NLS.str("message.indexIncomplete", reason, skippedCls);
				JOptionPane.showMessageDialog(this, message);
				break;
			}
			case CANCEL_BY_TIMEOUT: {
				String reason = NLS.str("message.taskTimeout", decompile.getTimeLimit());
				String message = NLS.str("message.indexIncomplete", reason, skippedCls);
				JOptionPane.showMessageDialog(this, message);
				break;
			}
			case CANCEL_BY_MEMORY: {
				showHeapUsageBar();
				JOptionPane.showMessageDialog(this, NLS.str("message.indexingClassesSkipped", skippedCls));
				break;
			}
		}
	}

659
	public void cancelBackgroundJobs() {
660
		backgroundExecutor.cancelAll();
661 662
	}

S
Skylot 已提交
663
	private void saveAll(boolean export) {
664
		FileDialogWrapper fileDialog = new FileDialogWrapper(this, FileOpenMode.EXPORT);
665 666 667
		List<Path> saveDirs = fileDialog.show();
		if (saveDirs.isEmpty()) {
			return;
668
		}
669 670 671 672 673 674 675 676
		JadxArgs decompilerArgs = wrapper.getArgs();
		decompilerArgs.setExportAsGradleProject(export);
		if (export) {
			decompilerArgs.setSkipSources(false);
			decompilerArgs.setSkipResources(false);
		} else {
			decompilerArgs.setSkipSources(settings.isSkipSources());
			decompilerArgs.setSkipResources(settings.isSkipResources());
677
		}
678 679
		settings.setLastSaveFilePath(fileDialog.getCurrentDir());
		backgroundExecutor.execute(new ExportTask(this, wrapper, saveDirs.get(0).toFile()));
680 681
	}

S
Skylot 已提交
682
	public void initTree() {
S
Skylot 已提交
683
		treeRoot = new JRoot(wrapper);
684
		treeRoot.setFlatPackages(isFlattenPackage);
685
		treeModel.setRoot(treeRoot);
686
		addTreeCustomNodes();
S
Skylot 已提交
687
		treeRoot.update();
S
Skylot 已提交
688 689 690
		reloadTree();
	}

691
	private void clearTree() {
692
		tabbedPane.reset();
693
		treeRoot = null;
694
		treeModel.setRoot(null);
695 696 697
		treeModel.reload();
	}

698
	public void reloadTree() {
699 700
		treeReloading = true;

701
		treeModel.reload();
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
		List<String[]> treeExpansions = project.getTreeExpansions();
		if (!treeExpansions.isEmpty()) {
			expand(treeRoot, treeExpansions);
		} else {
			tree.expandRow(1);
		}

		treeReloading = false;
	}

	private void expand(TreeNode node, List<String[]> treeExpansions) {
		TreeNode[] pathNodes = treeModel.getPathToRoot(node);
		if (pathNodes == null) {
			return;
		}
		TreePath path = new TreePath(pathNodes);
		for (String[] expansion : treeExpansions) {
			if (Arrays.equals(expansion, getPathExpansion(path))) {
				tree.expandPath(path);
				break;
			}
		}
		for (int i = node.getChildCount() - 1; i >= 0; i--) {
			expand(node.getChildAt(i), treeExpansions);
		}
S
Skylot 已提交
727 728
	}

729 730 731 732 733 734
	private void toggleFlattenPackage() {
		setFlattenPackage(!isFlattenPackage);
	}

	private void setFlattenPackage(boolean value) {
		isFlattenPackage = value;
S
Skylot 已提交
735
		settings.setFlattenPackage(isFlattenPackage);
736 737 738 739

		flatPkgButton.setSelected(isFlattenPackage);
		flatPkgMenuItem.setState(isFlattenPackage);

740 741 742
		Object root = treeModel.getRoot();
		if (root instanceof JRoot) {
			JRoot treeRoot = (JRoot) root;
743
			treeRoot.setFlatPackages(isFlattenPackage);
S
Skylot 已提交
744
			reloadTree();
745 746 747
		}
	}

S
Skylot 已提交
748 749 750 751 752 753 754
	private void toggleDeobfuscation() {
		boolean deobfOn = !settings.isDeobfuscationOn();
		settings.setDeobfuscationOn(deobfOn);
		settings.sync();

		deobfToggleBtn.setSelected(deobfOn);
		deobfMenuItem.setState(deobfOn);
755
		reopen();
S
Skylot 已提交
756 757
	}

S
Skylot 已提交
758 759 760 761
	private boolean nodeClickAction(@Nullable Object obj) {
		if (obj == null) {
			return false;
		}
S
Skylot 已提交
762 763 764
		try {
			if (obj instanceof JResource) {
				JResource res = (JResource) obj;
S
Skylot 已提交
765 766
				ResourceFile resFile = res.getResFile();
				if (resFile != null && JResource.isSupportedForView(resFile.getType())) {
S
Skylot 已提交
767
					return tabbedPane.showNode(res);
S
Skylot 已提交
768
				}
S
Skylot 已提交
769
			} else if (obj instanceof JNode) {
770 771
				JNode node = (JNode) obj;
				if (node.getRootClass() != null) {
772
					tabbedPane.codeJump(node);
S
Skylot 已提交
773
					return true;
774
				}
S
Skylot 已提交
775
				return tabbedPane.showNode(node);
S
Skylot 已提交
776
			}
S
Skylot 已提交
777 778
		} catch (Exception e) {
			LOG.error("Content loading error", e);
S
Skylot 已提交
779
		}
S
Skylot 已提交
780
		return false;
S
Skylot 已提交
781 782
	}

783
	private void treeRightClickAction(MouseEvent e) {
784
		JNode obj = getJNodeUnderMouse(e);
785
		if (obj instanceof JPackage) {
S
Skylot 已提交
786
			JPackagePopupMenu menu = new JPackagePopupMenu(this, (JPackage) obj);
787
			menu.show(e.getComponent(), e.getX(), e.getY());
788
		} else if (obj instanceof JClass || obj instanceof JField || obj instanceof JMethod) {
789
			JMenuItem jmi = new JMenuItem(NLS.str("popup.rename"));
790 791
			jmi.addActionListener(action -> RenameDialog.rename(this, obj));
			JPopupMenu menu = new JPopupMenu();
792 793
			menu.add(jmi);
			menu.show(e.getComponent(), e.getX(), e.getY());
794 795 796 797
		}
	}

	@Nullable
798 799 800 801
	private JNode getJNodeUnderMouse(MouseEvent mouseEvent) {
		TreePath path = tree.getClosestPathForLocation(mouseEvent.getX(), mouseEvent.getY());
		if (path == null) {
			return null;
802
		}
803 804 805 806 807 808
		// allow 'closest' path only at the right of the item row
		Rectangle pathBounds = tree.getPathBounds(path);
		if (pathBounds != null) {
			int y = mouseEvent.getY();
			if (y < pathBounds.y || y > (pathBounds.y + pathBounds.height)) {
				return null;
809
			}
810 811 812 813 814 815 816
			if (mouseEvent.getX() < pathBounds.x) {
				// exclude expand/collapse events
				return null;
			}
		}
		Object obj = path.getLastPathComponent();
		if (obj instanceof JNode) {
S
Skylot 已提交
817
			tree.setSelectionPath(path);
818
			return (JNode) obj;
819
		}
820
		return null;
821
	}
822

823
	public void syncWithEditor() {
S
Skylot 已提交
824 825
		ContentPanel selectedContentPanel = tabbedPane.getSelectedCodePanel();
		if (selectedContentPanel == null) {
S
Skylot 已提交
826 827
			return;
		}
S
Skylot 已提交
828 829
		JNode node = selectedContentPanel.getNode();
		if (node.getParent() == null && treeRoot != null) {
S
Skylot 已提交
830
			// node not register in tree
831
			node = treeRoot.searchNode(node);
S
Skylot 已提交
832
			if (node == null) {
S
Skylot 已提交
833 834 835 836
				LOG.error("Class not found in tree");
				return;
			}
		}
S
Skylot 已提交
837
		TreeNode[] pathNodes = treeModel.getPathToRoot(node);
S
Skylot 已提交
838 839 840 841 842 843
		if (pathNodes == null) {
			return;
		}
		TreePath path = new TreePath(pathNodes);
		tree.setSelectionPath(path);
		tree.makeVisible(path);
844
		tree.scrollPathToVisible(path);
845
		tree.requestFocus();
846 847 848
	}

	private void initMenuAndToolbar() {
S
Skylot 已提交
849 850 851 852 853 854 855 856 857
		ActionHandler openAction = new ActionHandler(this::openFileDialog);
		openAction.setNameAndDesc(NLS.str("file.open_action"));
		openAction.setIcon(Icons.OPEN);
		openAction.setKeyBinding(getKeyStroke(KeyEvent.VK_O, UiUtils.ctrlButton()));

		ActionHandler openProject = new ActionHandler(this::openProjectDialog);
		openProject.setNameAndDesc(NLS.str("file.open_project"));
		openProject.setIcon(Icons.OPEN_PROJECT);
		openProject.setKeyBinding(getKeyStroke(KeyEvent.VK_O, InputEvent.SHIFT_DOWN_MASK | UiUtils.ctrlButton()));
S
Skylot 已提交
858

859 860 861 862 863 864 865 866
		Action addFilesAction = new AbstractAction(NLS.str("file.add_files_action"), ICON_ADD_FILES) {
			@Override
			public void actionPerformed(ActionEvent e) {
				addFiles();
			}
		};
		addFilesAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.add_files_action"));

S
Skylot 已提交
867
		newProjectAction = new AbstractAction(NLS.str("file.new_project"), Icons.NEW_PROJECT) {
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
			@Override
			public void actionPerformed(ActionEvent e) {
				newProject();
			}
		};
		newProjectAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.new_project"));

		saveProjectAction = new AbstractAction(NLS.str("file.save_project")) {
			@Override
			public void actionPerformed(ActionEvent e) {
				saveProject();
			}
		};
		saveProjectAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.save_project"));

		Action saveProjectAsAction = new AbstractAction(NLS.str("file.save_project_as")) {
			@Override
			public void actionPerformed(ActionEvent e) {
				saveProjectAs();
			}
		};
		saveProjectAsAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.save_project_as"));

891 892 893 894 895 896 897 898 899 900 901 902 903
		ActionHandler reload = new ActionHandler(ev -> UiUtils.uiRun(this::reopen));
		reload.setNameAndDesc(NLS.str("file.reload"));
		reload.setIcon(ICON_RELOAD);
		reload.setKeyBinding(getKeyStroke(KeyEvent.VK_F5, 0));

		ActionHandler liveReload = new ActionHandler(ev -> updateLiveReload(!project.isEnableLiveReload()));
		liveReload.setName(NLS.str("file.live_reload"));
		liveReload.setShortDescription(NLS.str("file.live_reload_desc"));
		liveReload.setKeyBinding(getKeyStroke(KeyEvent.VK_F5, InputEvent.SHIFT_DOWN_MASK));

		liveReloadMenuItem = new JCheckBoxMenuItem(liveReload);
		liveReloadMenuItem.setState(project.isEnableLiveReload());

904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
		Action exportMappingsAsTiny2 = new AbstractAction("Tiny v2 file") {
			@Override
			public void actionPerformed(ActionEvent e) {
				exportMappings(MappingFormat.TINY_2);
			}
		};
		exportMappingsAsTiny2.putValue(Action.SHORT_DESCRIPTION, "Tiny v2 file");

		Action exportMappingsAsEnigma = new AbstractAction("Enigma file") {
			@Override
			public void actionPerformed(ActionEvent e) {
				exportMappings(MappingFormat.ENIGMA);
			}
		};
		exportMappingsAsEnigma.putValue(Action.SHORT_DESCRIPTION, "Enigma file");

		Action exportMappingsAsEnigmaDir = new AbstractAction("Enigma directory") {
			@Override
			public void actionPerformed(ActionEvent e) {
				exportMappings(MappingFormat.ENIGMA_DIR);
			}
		};
		exportMappingsAsEnigmaDir.putValue(Action.SHORT_DESCRIPTION, "Enigma directory");

		exportMappingsMenu = new JMenu(NLS.str("file.export_mappings_as"));
		exportMappingsMenu.add(exportMappingsAsTiny2);
		exportMappingsMenu.add(exportMappingsAsEnigma);
		exportMappingsMenu.add(exportMappingsAsEnigmaDir);
		exportMappingsMenu.setEnabled(false);

934
		Action saveAllAction = new AbstractAction(NLS.str("file.save_all"), ICON_SAVE_ALL) {
935 936
			@Override
			public void actionPerformed(ActionEvent e) {
S
Skylot 已提交
937
				saveAll(false);
938
			}
939 940
		};
		saveAllAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.save_all"));
941
		saveAllAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_S, UiUtils.ctrlButton()));
942

S
Skylot 已提交
943 944 945 946 947 948 949
		Action exportAction = new AbstractAction(NLS.str("file.export_gradle"), ICON_EXPORT) {
			@Override
			public void actionPerformed(ActionEvent e) {
				saveAll(true);
			}
		};
		exportAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("file.export_gradle"));
950
		exportAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_E, UiUtils.ctrlButton()));
S
Skylot 已提交
951

952 953
		JMenu recentProjects = new JMenu(NLS.str("menu.recent_projects"));
		recentProjects.addMenuListener(new RecentProjectsMenuListener(recentProjects));
S
Skylot 已提交
954

955 956 957 958
		Action prefsAction = new AbstractAction(NLS.str("menu.preferences"), ICON_PREF) {
			@Override
			public void actionPerformed(ActionEvent e) {
				new JadxSettingsWindow(MainWindow.this, settings).setVisible(true);
S
Skylot 已提交
959 960
			}
		};
961 962
		prefsAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.preferences"));
		prefsAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_P,
963
				UiUtils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK));
S
Skylot 已提交
964

965
		Action exitAction = new AbstractAction(NLS.str("file.exit"), ICON_EXIT) {
966 967
			@Override
			public void actionPerformed(ActionEvent e) {
968
				closeWindow();
969 970
			}
		};
S
Skylot 已提交
971

S
Skylot 已提交
972
		isFlattenPackage = settings.isFlattenPackage();
973 974
		flatPkgMenuItem = new JCheckBoxMenuItem(NLS.str("menu.flatten"), ICON_FLAT_PKG);
		flatPkgMenuItem.setState(isFlattenPackage);
S
Skylot 已提交
975

976
		JCheckBoxMenuItem heapUsageBarMenuItem = new JCheckBoxMenuItem(NLS.str("menu.heapUsageBar"));
J
Jan S 已提交
977 978 979 980 981 982
		heapUsageBarMenuItem.setState(settings.isShowHeapUsageBar());
		heapUsageBarMenuItem.addActionListener(event -> {
			settings.setShowHeapUsageBar(!settings.isShowHeapUsageBar());
			heapUsageBar.setVisible(settings.isShowHeapUsageBar());
		});

983 984 985 986
		JCheckBoxMenuItem alwaysSelectOpened = new JCheckBoxMenuItem(NLS.str("menu.alwaysSelectOpened"));
		alwaysSelectOpened.setState(settings.isAlwaysSelectOpened());
		alwaysSelectOpened.addActionListener(event -> {
			settings.setAlwaysSelectOpened(!settings.isAlwaysSelectOpened());
987 988 989
			if (settings.isAlwaysSelectOpened()) {
				this.syncWithEditor();
			}
990 991
		});

992
		Action syncAction = new AbstractAction(NLS.str("menu.sync"), ICON_SYNC) {
S
Skylot 已提交
993 994 995 996
			@Override
			public void actionPerformed(ActionEvent e) {
				syncWithEditor();
			}
997 998
		};
		syncAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.sync"));
999
		syncAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_T, UiUtils.ctrlButton()));
S
Skylot 已提交
1000

1001 1002 1003
		Action textSearchAction = new AbstractAction(NLS.str("menu.text_search"), ICON_SEARCH) {
			@Override
			public void actionPerformed(ActionEvent e) {
1004 1005
				ContentPanel panel = tabbedPane.getSelectedCodePanel();
				if (panel instanceof AbstractCodeContentPanel) {
1006 1007 1008 1009 1010
					AbstractCodeArea codeArea = ((AbstractCodeContentPanel) panel).getCodeArea();
					String preferText = codeArea.getSelectedText();
					if (StringUtils.isEmpty(preferText)) {
						preferText = codeArea.getWordUnderCaret();
					}
1011 1012 1013 1014 1015
					if (!StringUtils.isEmpty(preferText)) {
						SearchDialog.searchText(MainWindow.this, preferText);
						return;
					}
				}
1016
				SearchDialog.search(MainWindow.this, SearchDialog.SearchPreset.TEXT);
1017 1018 1019
			}
		};
		textSearchAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.text_search"));
S
Skylot 已提交
1020
		textSearchAction.putValue(Action.ACCELERATOR_KEY,
1021
				getKeyStroke(KeyEvent.VK_F, UiUtils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK));
S
Skylot 已提交
1022

1023 1024 1025
		Action clsSearchAction = new AbstractAction(NLS.str("menu.class_search"), ICON_FIND) {
			@Override
			public void actionPerformed(ActionEvent e) {
1026
				SearchDialog.search(MainWindow.this, SearchDialog.SearchPreset.CLASS);
S
Skylot 已提交
1027 1028
			}
		};
1029
		clsSearchAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.class_search"));
1030
		clsSearchAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_N, UiUtils.ctrlButton()));
S
Skylot 已提交
1031

1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
		Action commentSearchAction = new AbstractAction(NLS.str("menu.comment_search"), ICON_COMMENT_SEARCH) {
			@Override
			public void actionPerformed(ActionEvent e) {
				SearchDialog.search(MainWindow.this, SearchDialog.SearchPreset.COMMENT);
			}
		};
		commentSearchAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.comment_search"));
		commentSearchAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_SEMICOLON,
				UiUtils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK));

D
Donlon 已提交
1042
		Action deobfAction = new AbstractAction(NLS.str("menu.deobfuscation"), ICON_DEOBF) {
S
Skylot 已提交
1043 1044 1045 1046 1047 1048 1049
			@Override
			public void actionPerformed(ActionEvent e) {
				toggleDeobfuscation();
			}
		};
		deobfAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("preferences.deobfuscation"));
		deobfAction.putValue(Action.ACCELERATOR_KEY,
1050
				getKeyStroke(KeyEvent.VK_D, UiUtils.ctrlButton() | KeyEvent.ALT_DOWN_MASK));
S
Skylot 已提交
1051 1052 1053 1054 1055 1056 1057 1058

		deobfToggleBtn = new JToggleButton(deobfAction);
		deobfToggleBtn.setSelected(settings.isDeobfuscationOn());
		deobfToggleBtn.setText("");

		deobfMenuItem = new JCheckBoxMenuItem(deobfAction);
		deobfMenuItem.setState(settings.isDeobfuscationOn());

1059
		Action logAction = new AbstractAction(NLS.str("menu.log"), ICON_LOG) {
S
Skylot 已提交
1060 1061
			@Override
			public void actionPerformed(ActionEvent e) {
1062
				LogViewerDialog.open(MainWindow.this);
S
Skylot 已提交
1063 1064
			}
		};
1065 1066
		logAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("menu.log"));
		logAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_L,
1067
				UiUtils.ctrlButton() | KeyEvent.SHIFT_DOWN_MASK));
S
Skylot 已提交
1068

1069
		Action aboutAction = new AbstractAction(NLS.str("menu.about"), ICON_INFO) {
1070 1071 1072 1073 1074
			@Override
			public void actionPerformed(ActionEvent e) {
				new AboutDialog().setVisible(true);
			}
		};
S
Skylot 已提交
1075

1076
		Action backAction = new AbstractAction(NLS.str("nav.back"), ICON_BACK) {
S
Skylot 已提交
1077 1078
			@Override
			public void actionPerformed(ActionEvent e) {
1079 1080 1081 1082
				tabbedPane.navBack();
			}
		};
		backAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("nav.back"));
1083
		backAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_ESCAPE, 0));
1084 1085 1086 1087 1088

		Action forwardAction = new AbstractAction(NLS.str("nav.forward"), ICON_FORWARD) {
			@Override
			public void actionPerformed(ActionEvent e) {
				tabbedPane.navForward();
S
Skylot 已提交
1089 1090
			}
		};
1091
		forwardAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("nav.forward"));
1092
		forwardAction.putValue(Action.ACCELERATOR_KEY, getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK, SystemInfo.IS_MAC));
1093

1094 1095 1096 1097 1098 1099 1100 1101
		Action quarkAction = new AbstractAction("Quark Engine", ICON_QUARK) {
			@Override
			public void actionPerformed(ActionEvent e) {
				new QuarkDialog(MainWindow.this).setVisible(true);
			}
		};
		quarkAction.putValue(Action.SHORT_DESCRIPTION, "Quark Engine");

1102 1103 1104 1105 1106 1107 1108 1109 1110
		Action openDeviceAction = new AbstractAction(NLS.str("debugger.process_selector"), ICON_DEBUGGER) {
			@Override
			public void actionPerformed(ActionEvent e) {
				ADBDialog dialog = new ADBDialog(MainWindow.this);
				dialog.setVisible(true);
			}
		};
		openDeviceAction.putValue(Action.SHORT_DESCRIPTION, NLS.str("debugger.process_selector"));

1111 1112 1113
		JMenu file = new JMenu(NLS.str("menu.file"));
		file.setMnemonic(KeyEvent.VK_F);
		file.add(openAction);
S
Skylot 已提交
1114
		file.add(openProject);
1115
		file.add(addFilesAction);
1116 1117 1118 1119 1120
		file.addSeparator();
		file.add(newProjectAction);
		file.add(saveProjectAction);
		file.add(saveProjectAsAction);
		file.addSeparator();
1121 1122 1123
		file.add(reload);
		file.add(liveReloadMenuItem);
		file.addSeparator();
1124 1125
		file.add(exportMappingsMenu);
		file.addSeparator();
1126
		file.add(saveAllAction);
S
Skylot 已提交
1127
		file.add(exportAction);
1128
		file.addSeparator();
1129
		file.add(recentProjects);
1130 1131 1132 1133 1134 1135 1136 1137 1138
		file.addSeparator();
		file.add(prefsAction);
		file.addSeparator();
		file.add(exitAction);

		JMenu view = new JMenu(NLS.str("menu.view"));
		view.setMnemonic(KeyEvent.VK_V);
		view.add(flatPkgMenuItem);
		view.add(syncAction);
J
Jan S 已提交
1139
		view.add(heapUsageBarMenuItem);
1140
		view.add(alwaysSelectOpened);
1141 1142 1143 1144 1145

		JMenu nav = new JMenu(NLS.str("menu.navigation"));
		nav.setMnemonic(KeyEvent.VK_N);
		nav.add(textSearchAction);
		nav.add(clsSearchAction);
1146
		nav.add(commentSearchAction);
1147 1148 1149 1150 1151 1152
		nav.addSeparator();
		nav.add(backAction);
		nav.add(forwardAction);

		JMenu tools = new JMenu(NLS.str("menu.tools"));
		tools.setMnemonic(KeyEvent.VK_T);
S
Skylot 已提交
1153
		tools.add(deobfMenuItem);
1154 1155
		tools.add(quarkAction);
		tools.add(openDeviceAction);
S
Skylot 已提交
1156

S
Skylot 已提交
1157 1158
		JMenu help = new JMenu(NLS.str("menu.help"));
		help.setMnemonic(KeyEvent.VK_H);
1159
		help.add(logAction);
1160
		if (Jadx.isDevVersion()) {
1161 1162 1163 1164 1165 1166 1167
			help.add(new AbstractAction("Show sample error report") {
				@Override
				public void actionPerformed(ActionEvent e) {
					ExceptionDialog.throwTestException();
				}
			});
		}
1168
		help.add(aboutAction);
S
Skylot 已提交
1169

1170
		JMenuBar menuBar = new JMenuBar();
S
Skylot 已提交
1171
		menuBar.add(file);
S
Skylot 已提交
1172 1173
		menuBar.add(view);
		menuBar.add(nav);
S
Skylot 已提交
1174
		menuBar.add(tools);
S
Skylot 已提交
1175
		menuBar.add(help);
S
Skylot 已提交
1176 1177
		setJMenuBar(menuBar);

1178 1179
		flatPkgButton = new JToggleButton(ICON_FLAT_PKG);
		flatPkgButton.setSelected(isFlattenPackage);
S
Skylot 已提交
1180
		ActionListener flatPkgAction = e -> toggleFlattenPackage();
S
Skylot 已提交
1181
		flatPkgMenuItem.addActionListener(flatPkgAction);
1182
		flatPkgButton.addActionListener(flatPkgAction);
S
Skylot 已提交
1183 1184
		flatPkgButton.setToolTipText(NLS.str("menu.flatten"));

S
Skylot 已提交
1185 1186
		updateLink = new Link("", JadxUpdate.JADX_RELEASES_URL);
		updateLink.setVisible(false);
S
Skylot 已提交
1187 1188 1189

		JToolBar toolbar = new JToolBar();
		toolbar.setFloatable(false);
1190
		toolbar.add(openAction);
1191 1192
		toolbar.add(addFilesAction);
		toolbar.addSeparator();
1193 1194
		toolbar.add(reload);
		toolbar.addSeparator();
1195
		toolbar.add(saveAllAction);
S
Skylot 已提交
1196
		toolbar.add(exportAction);
S
Skylot 已提交
1197
		toolbar.addSeparator();
1198
		toolbar.add(syncAction);
S
Skylot 已提交
1199 1200
		toolbar.add(flatPkgButton);
		toolbar.addSeparator();
1201 1202
		toolbar.add(textSearchAction);
		toolbar.add(clsSearchAction);
1203
		toolbar.add(commentSearchAction);
S
Skylot 已提交
1204
		toolbar.addSeparator();
1205 1206
		toolbar.add(backAction);
		toolbar.add(forwardAction);
S
Skylot 已提交
1207 1208
		toolbar.addSeparator();
		toolbar.add(deobfToggleBtn);
1209 1210
		toolbar.add(quarkAction);
		toolbar.add(openDeviceAction);
S
Skylot 已提交
1211
		toolbar.addSeparator();
1212
		toolbar.add(logAction);
S
Skylot 已提交
1213
		toolbar.addSeparator();
1214
		toolbar.add(prefsAction);
S
Skylot 已提交
1215 1216
		toolbar.addSeparator();
		toolbar.add(Box.createHorizontalGlue());
S
Skylot 已提交
1217 1218
		toolbar.add(updateLink);

S
Skylot 已提交
1219
		mainPanel.add(toolbar, BorderLayout.NORTH);
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235

		addLoadListener(loaded -> {
			textSearchAction.setEnabled(loaded);
			clsSearchAction.setEnabled(loaded);
			commentSearchAction.setEnabled(loaded);
			backAction.setEnabled(loaded);
			forwardAction.setEnabled(loaded);
			syncAction.setEnabled(loaded);
			saveAllAction.setEnabled(loaded);
			exportAction.setEnabled(loaded);
			saveProjectAsAction.setEnabled(loaded);
			reload.setEnabled(loaded);
			deobfAction.setEnabled(loaded);
			quarkAction.setEnabled(loaded);
			return false;
		});
S
Skylot 已提交
1236 1237 1238
	}

	private void initUI() {
1239
		setMinimumSize(new Dimension(200, 150));
S
Skylot 已提交
1240
		mainPanel = new JPanel(new BorderLayout());
1241
		splitPane = new JSplitPane();
S
Skylot 已提交
1242
		splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
S
Skylot 已提交
1243 1244
		mainPanel.add(splitPane);

S
Skylot 已提交
1245 1246
		DefaultMutableTreeNode treeRootNode = new DefaultMutableTreeNode(NLS.str("msg.open_file"));
		treeModel = new DefaultTreeModel(treeRootNode);
S
Skylot 已提交
1247
		tree = new JTree(treeModel);
1248
		ToolTipManager.sharedInstance().registerComponent(tree);
S
Skylot 已提交
1249
		tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
S
Skylot 已提交
1250 1251 1252 1253 1254 1255 1256
		tree.setFocusable(false);
		tree.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent e) {
				tree.setFocusable(false);
			}
		});
1257
		tree.addMouseListener(new MouseAdapter() {
S
Skylot 已提交
1258
			@Override
S
Skylot 已提交
1259
			public void mousePressed(MouseEvent e) {
1260
				if (SwingUtilities.isLeftMouseButton(e)) {
S
Skylot 已提交
1261 1262 1263 1264 1265
					if (!nodeClickAction(getJNodeUnderMouse(e))) {
						// click ignored -> switch to focusable mode
						tree.setFocusable(true);
						tree.requestFocus();
					}
1266
				} else if (SwingUtilities.isRightMouseButton(e)) {
1267 1268
					treeRightClickAction(e);
				}
S
Skylot 已提交
1269 1270
			}
		});
1271 1272 1273 1274
		tree.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER) {
1275
					nodeClickAction(tree.getLastSelectedPathComponent());
1276 1277 1278
				}
			}
		});
S
Skylot 已提交
1279 1280 1281
		tree.setCellRenderer(new DefaultTreeCellRenderer() {
			@Override
			public Component getTreeCellRendererComponent(JTree tree,
1282 1283
					Object value, boolean selected, boolean expanded,
					boolean isLeaf, int row, boolean focused) {
S
Skylot 已提交
1284 1285
				Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
				if (value instanceof JNode) {
1286
					JNode jNode = (JNode) value;
1287
					NodeLabel.disableHtml(this, jNode.disableHtml());
1288
					setText(jNode.makeStringHtml());
1289 1290 1291 1292
					setIcon(jNode.getIcon());
					setToolTipText(jNode.getTooltip());
				} else {
					setToolTipText(null);
S
Skylot 已提交
1293
				}
1294 1295 1296
				if (value instanceof JPackage) {
					setEnabled(((JPackage) value).isEnabled());
				}
S
Skylot 已提交
1297
				return c;
S
Skylot 已提交
1298 1299
			}
		});
1300 1301
		tree.addTreeWillExpandListener(new TreeWillExpandListener() {
			@Override
1302
			public void treeWillExpand(TreeExpansionEvent event) {
1303 1304
				TreePath path = event.getPath();
				Object node = path.getLastPathComponent();
1305 1306
				if (node instanceof JLoadableNode) {
					((JLoadableNode) node).loadNode();
1307
				}
1308 1309 1310 1311
				if (!treeReloading) {
					project.addTreeExpansion(getPathExpansion(event.getPath()));
					update();
				}
1312 1313 1314
			}

			@Override
1315
			public void treeWillCollapse(TreeExpansionEvent event) {
1316 1317 1318 1319
				if (!treeReloading) {
					project.removeTreeExpansion(getPathExpansion(event.getPath()));
					update();
				}
1320 1321
			}
		});
S
Skylot 已提交
1322

1323
		progressPane = new ProgressPanel(this, true);
1324
		IssuesPanel issuesPanel = new IssuesPanel(this);
1325 1326

		JPanel leftPane = new JPanel(new BorderLayout());
1327 1328 1329
		JScrollPane treeScrollPane = new JScrollPane(tree);
		treeScrollPane.setMinimumSize(new Dimension(100, 150));

1330 1331 1332 1333
		JPanel bottomPane = new JPanel(new BorderLayout());
		bottomPane.add(issuesPanel, BorderLayout.PAGE_START);
		bottomPane.add(progressPane, BorderLayout.PAGE_END);

1334
		leftPane.add(treeScrollPane, BorderLayout.CENTER);
1335
		leftPane.add(bottomPane, BorderLayout.PAGE_END);
1336
		splitPane.setLeftComponent(leftPane);
S
Skylot 已提交
1337

S
Skylot 已提交
1338
		tabbedPane = new TabbedPane(this);
1339
		tabbedPane.setMinimumSize(new Dimension(150, 150));
S
Skylot 已提交
1340
		splitPane.setRightComponent(tabbedPane);
S
Skylot 已提交
1341

S
Skylot 已提交
1342
		new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
1343

J
Jan S 已提交
1344 1345 1346
		heapUsageBar = new HeapUsageBar();
		mainPanel.add(heapUsageBar, BorderLayout.SOUTH);

1347 1348 1349 1350 1351
		verticalSplitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
		verticalSplitter.setTopComponent(splitPane);
		verticalSplitter.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);

		mainPanel.add(verticalSplitter, BorderLayout.CENTER);
S
Skylot 已提交
1352 1353
		setContentPane(mainPanel);
		setTitle(DEFAULT_TITLE);
S
Skylot 已提交
1354 1355
	}

1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
	private void registerMouseNavigationButtons() {
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		toolkit.addAWTEventListener(event -> {
			if (event instanceof MouseEvent) {
				MouseEvent mouseEvent = (MouseEvent) event;
				if (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED) {
					int rawButton = mouseEvent.getButton();
					if (rawButton <= 3) {
						return;
					}
					int button = remapMouseButton(rawButton);
					switch (button) {
						case 4:
							tabbedPane.navBack();
							break;
						case 5:
							tabbedPane.navForward();
							break;
					}
				}
			}
		}, AWTEvent.MOUSE_EVENT_MASK);
	}

	private static int remapMouseButton(int rawButton) {
		if (SystemInfo.IS_LINUX) {
			if (rawButton == 6) {
				return 4;
			}
			if (rawButton == 7) {
				return 5;
			}
		}
		return rawButton;
	}

1392 1393 1394 1395 1396 1397 1398
	private static String[] getPathExpansion(TreePath path) {
		List<String> pathList = new ArrayList<>();
		while (path != null) {
			Object node = path.getLastPathComponent();
			String name;
			if (node instanceof JClass) {
				name = ((JClass) node).getCls().getClassNode().getClassInfo().getFullName();
1399
			} else {
1400 1401 1402 1403 1404
				name = node.toString();
			}
			pathList.add(name);
			path = path.getParentPath();
		}
1405
		return pathList.toArray(new String[0]);
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
	}

	public static void getExpandedPaths(JTree tree, TreePath path, List<TreePath> list) {
		if (tree.isExpanded(path)) {
			list.add(path);

			TreeNode node = (TreeNode) path.getLastPathComponent();
			for (int i = node.getChildCount() - 1; i >= 0; i--) {
				TreeNode n = node.getChildAt(i);
				TreePath child = path.pathByAddingChild(n);
				getExpandedPaths(tree, child, list);
			}
		}
	}

S
Skylot 已提交
1421
	public void setLocationAndPosition() {
1422
		if (settings.loadWindowPos(this)) {
1423 1424
			return;
		}
1425 1426
		GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
		DisplayMode mode = gd.getDisplayMode();
1427 1428 1429
		AffineTransform trans = gd.getDefaultConfiguration().getDefaultTransform();
		int w = (int) (mode.getWidth() / trans.getScaleX());
		int h = (int) (mode.getHeight() / trans.getScaleY());
1430 1431 1432
		setBounds((int) (w * BORDER_RATIO), (int) (h * BORDER_RATIO),
				(int) (w * WINDOW_RATIO), (int) (h * WINDOW_RATIO));
		setLocationRelativeTo(null);
S
Skylot 已提交
1433
	}
1434

1435
	private void setEditorTheme(String editorThemePath) {
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
		try {
			URL themeUrl = getClass().getResource(editorThemePath);
			if (themeUrl != null) {
				try (InputStream is = themeUrl.openStream()) {
					editorTheme = Theme.load(is);
					return;
				}
			}
			Path themePath = Paths.get(editorThemePath);
			if (Files.isRegularFile(themePath)) {
				try (InputStream is = Files.newInputStream(themePath)) {
					editorTheme = Theme.load(is);
					return;
				}
			}
		} catch (Exception e) {
			LOG.error("Failed to load editor theme: {}", editorThemePath, e);
		}
		LOG.warn("Falling back to default editor theme: {}", editorThemePath);
		editorThemePath = EditorTheme.getDefaultTheme().getPath();
S
Skylot 已提交
1456 1457
		try (InputStream is = getClass().getResourceAsStream(editorThemePath)) {
			editorTheme = Theme.load(is);
1458
			return;
1459
		} catch (Exception e) {
1460 1461
			LOG.error("Failed to load default editor theme: {}", editorThemePath, e);
			editorTheme = new Theme(new RSyntaxTextArea());
1462 1463 1464 1465 1466 1467 1468 1469
		}
	}

	public Theme getEditorTheme() {
		return editorTheme;
	}

	public void loadSettings() {
1470 1471
		LafManager.updateLaf(settings);

1472 1473 1474 1475 1476 1477 1478 1479
		Font font = settings.getFont();
		Font largerFont = font.deriveFont(font.getSize() + 2.f);

		setFont(largerFont);
		setEditorTheme(settings.getEditorThemePath());
		tree.setFont(largerFont);
		tree.setRowHeight(-1);

S
Skylot 已提交
1480 1481 1482
		tabbedPane.loadSettings();
	}

1483
	private void closeWindow() {
1484
		saveAll();
1485 1486 1487
		if (!ensureProjectIsSaved()) {
			return;
		}
1488
		settings.setTreeWidth(splitPane.getDividerLocation());
1489
		settings.saveWindowPos(this);
1490
		settings.setMainWindowExtendedState(getExtendedState());
1491 1492 1493
		if (debuggerPanel != null) {
			saveSplittersInfo();
		}
1494
		heapUsageBar.reset();
1495
		closeAll();
1496 1497

		FileUtils.deleteTempRootDir();
1498
		dispose();
1499
		System.exit(0);
1500 1501
	}

S
Skylot 已提交
1502
	private void saveOpenTabs() {
1503
		project.saveOpenTabs(tabbedPane.getEditorViewStates(), tabbedPane.getSelectedIndex());
S
Skylot 已提交
1504 1505
	}

1506 1507 1508 1509 1510 1511 1512 1513
	private void restoreOpenTabs() {
		List<EditorViewState> openTabs = project.getOpenTabs(this);
		if (openTabs.isEmpty()) {
			return;
		}
		for (EditorViewState viewState : openTabs) {
			tabbedPane.restoreEditorViewState(viewState);
		}
1514 1515 1516 1517 1518
		try {
			tabbedPane.setSelectedIndex(project.getActiveTab());
		} catch (Exception e) {
			LOG.warn("Failed to restore active tab", e);
		}
1519 1520
	}

1521 1522 1523 1524 1525 1526
	private void saveSplittersInfo() {
		settings.setMainWindowVerticalSplitterLoc(verticalSplitter.getDividerLocation());
		settings.setDebuggerStackFrameSplitterLoc(debuggerPanel.getLeftSplitterLocation());
		settings.setDebuggerVarTreeSplitterLoc(debuggerPanel.getRightSplitterLocation());
	}

1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
	public void addLoadListener(ILoadListener loadListener) {
		this.loadListeners.add(loadListener);
		// set initial value
		loadListener.update(loaded);
	}

	public void notifyLoadListeners(boolean loaded) {
		this.loaded = loaded;
		loadListeners.removeIf(listener -> listener.update(loaded));
	}

1538 1539 1540 1541
	public JadxWrapper getWrapper() {
		return wrapper;
	}

1542 1543 1544 1545
	public JadxProject getProject() {
		return project;
	}

1546 1547 1548 1549
	public TabbedPane getTabbedPane() {
		return tabbedPane;
	}

S
Skylot 已提交
1550 1551 1552 1553
	public JadxSettings getSettings() {
		return settings;
	}

S
Skylot 已提交
1554 1555 1556 1557
	public CacheObject getCacheObject() {
		return cacheObject;
	}

1558 1559 1560 1561
	public BackgroundExecutor getBackgroundExecutor() {
		return backgroundExecutor;
	}

1562 1563 1564 1565
	public JRoot getTreeRoot() {
		return treeRoot;
	}

1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
	public JDebuggerPanel getDebuggerPanel() {
		initDebuggerPanel();
		return debuggerPanel;
	}

	public void showDebuggerPanel() {
		initDebuggerPanel();
	}

	public void destroyDebuggerPanel() {
		saveSplittersInfo();
		debuggerPanel.setVisible(false);
		debuggerPanel = null;
	}

1581 1582 1583 1584 1585
	public void showHeapUsageBar() {
		settings.setShowHeapUsageBar(true);
		heapUsageBar.setVisible(true);
	}

1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598
	private void initDebuggerPanel() {
		if (debuggerPanel == null) {
			debuggerPanel = new JDebuggerPanel(this);
			debuggerPanel.loadSettings();
			verticalSplitter.setBottomComponent(debuggerPanel);
			int loc = settings.getMainWindowVerticalSplitterLoc();
			if (loc == 0) {
				loc = 300;
			}
			verticalSplitter.setDividerLocation(loc);
		}
	}

1599
	private class RecentProjectsMenuListener implements MenuListener {
1600
		private final JMenu menu;
S
Skylot 已提交
1601

1602 1603
		public RecentProjectsMenuListener(JMenu menu) {
			this.menu = menu;
S
Skylot 已提交
1604 1605 1606
		}

		@Override
S
Skylot 已提交
1607
		public void menuSelected(MenuEvent menuEvent) {
1608
			Set<Path> current = new HashSet<>(project.getFilePaths());
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
			List<JMenuItem> items = settings.getRecentProjects()
					.stream()
					.filter(path -> !current.contains(path))
					.map(path -> {
						JMenuItem menuItem = new JMenuItem(path.toAbsolutePath().toString());
						menuItem.addActionListener(e -> open(Collections.singletonList(path)));
						return menuItem;
					}).collect(Collectors.toList());

			menu.removeAll();
			if (items.isEmpty()) {
				menu.add(new JMenuItem(NLS.str("menu.no_recent_projects")));
			} else {
				items.forEach(menu::add);
1623
			}
S
Skylot 已提交
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633
		}

		@Override
		public void menuDeselected(MenuEvent e) {
		}

		@Override
		public void menuCanceled(MenuEvent e) {
		}
	}
S
Skylot 已提交
1634
}