Skip to content

Adding a Project View to the Arduino IDE #11048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Next Next commit
Project View Added
  • Loading branch information
samigamer1999 committed Dec 2, 2020
commit d7bbac4be13bec11ee9e920e25180de14f00c487
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
<classpathentry kind="lib" path="app/lib/jackson-annotations-2.9.5.jar"/>
<classpathentry kind="lib" path="app/lib/commons-compress-1.8.jar"/>
<classpathentry kind="lib" path="app/lib/commons-lang3-3.8.1.jar"/>
<classpathentry kind="lib" path="app/lib/jexplorertree-0.0.1-SNAPSHOT.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/arduino-core"/>
<classpathentry kind="output" path="app/bin"/>
</classpath>
1 change: 0 additions & 1 deletion app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
@@ -854,7 +854,6 @@ public boolean accept(File dir, String name) {
handleOpen(inputFile);
}


/**
* Open a sketch in a new window.
*
25 changes: 4 additions & 21 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
@@ -55,22 +55,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.TransferHandler;
import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.swing.text.BadLocationException;
@@ -327,21 +312,19 @@ public void windowDeactivated(WindowEvent e) {



project = new EditorProject("/home/sami/Arduino", base, this);
project = new EditorProject(PreferencesData.get("sketchbook.path"), base, this);
middle.add(project);
codePanel = new JPanel(new BorderLayout());
editor_upper.add(codePanel);
middle.add(editor_upper);

JSplitPane splitProject = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, project, editor_upper);
splitProject.setBackground(new Color(23, 161, 165));
splitProject.setContinuousLayout(true);
splitProject.setResizeWeight(0.25);
splitProject.setBackground(Color.BLACK);
middle.add(splitProject);
upper.add(middle);
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, upper, consolePanel);
SwingUtilities.invokeLater(project);


// repaint child panes while resizing
splitPane.setContinuousLayout(true);
@@ -1673,7 +1656,7 @@ public void addLineHighlight(int line) throws BadLocationException {
}
}
}
textArea.addLineHighlight(line, new Color(1, 0, 0, 0.2f));
textArea.addLineHighlight(line, new Color(0, 0, 255, 0.2f));
textArea.setCaretPosition(textArea.getLineStartOffset(line));
}

174 changes: 86 additions & 88 deletions app/src/processing/app/EditorProject.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,113 @@
package processing.app;

import processing.app.tools.jexplorer.JExplorerPanel;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;

public class EditorProject extends JScrollPane implements Runnable, MouseListener {

private DefaultMutableTreeNode root;

private DefaultTreeModel treeModel;
public class EditorProject extends Panel implements ActionListener, MouseListener{

private JTree tree;
private JExplorerPanel fileExplorerPanel;

private File fileRoot;

private Base base;

private Editor editor;

private String workspace = System.getProperty("user.home") + "/";
private JPanel settingsbox;

private String path;

private JButton settings;

private JButton toggle;

private JFileChooser chooser;

private Label buttons_popup;

public EditorProject(String path, Base base, Editor editor){
this.setLayout(new BorderLayout());
fileRoot = new File(path);
this.base = base;
this.editor = editor;
this.setPreferredSize(new Dimension(400, 1000));
fileExplorerPanel = new JExplorerPanel(fileRoot, editor);
buttons_popup = new Label("Toggle Project View");
buttons_popup.setForeground(new Color(23, 161, 165));
buttons_popup.setBackground(new Color(23, 161, 165));
settingsbox = new JPanel();
settingsbox.setLayout(new BoxLayout(settingsbox, BoxLayout.LINE_AXIS));
settingsbox.setOpaque(true);
settingsbox.setBackground(new Color(23, 161, 165));
this.path = path;
settings = new JButton("S");
settings.addActionListener(this);
settings.addMouseListener(this);
toggle = new JButton("T");
toggle.addActionListener(this);
toggle.addMouseListener(this);
this.add(settings);
//settingsbox.add(new Label("Project View"));
JPanel buttons_panel = new JPanel();
buttons_panel.setLayout(new FlowLayout());
buttons_panel.setOpaque(false);

settingsbox.add(settings);
settingsbox.add(toggle);
settingsbox.add(buttons_popup);
//settingsbox.add(Box.createHorizontalGlue());
//settingsbox.add(buttons_panel);
this.add(settingsbox, BorderLayout.NORTH);
this.add(fileExplorerPanel);

}

@Override
public void run() {
root = new DefaultMutableTreeNode(new FileNode(fileRoot));
treeModel = new DefaultTreeModel(root);
public void resetProject(){
// Resetting the project View and root directory
fileRoot = new File(path);
fileExplorerPanel.replaceWorkingDirectory(fileRoot);

// Resetting the sketchbook path
PreferencesData.set("sketchbook.path", path);
}


tree = new JTree(treeModel);
tree.setShowsRootHandles(true);
tree.addMouseListener(this);
setViewportView(tree);
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == settings){
chooser = new JFileChooser();
chooser.setCurrentDirectory(fileRoot);
chooser.setDialogTitle("Choose project directory : ");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

if (chooser.showOpenDialog(fileExplorerPanel) == JFileChooser.APPROVE_OPTION) {
System.out.println("You moved your workspace to : " + chooser.getSelectedFile());
this.path = chooser.getSelectedFile().getAbsolutePath();
resetProject();
}
else {
System.out.println("No Selection ");
}
}

if(e.getSource() == toggle){
//TODO
}
}

CreateChildNodes ccn =
new CreateChildNodes(fileRoot, root);
new Thread(ccn).start();
}

@Override
public void mouseClicked(MouseEvent e) {
int selRow = tree.getRowForLocation(e.getX(), e.getY());
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
if(selRow != -1) {
if(e.getClickCount() == 2) {
String path = selPath.toString().replaceAll("\\]| |\\[|", "").replaceAll(",", File.separator);
try {
editor.getSketchController().addFile(new File(workspace + path));

} catch (Exception exception) {
exception.printStackTrace();
}
}
}

}

@Override
@@ -78,67 +122,21 @@ public void mouseReleased(MouseEvent e) {

@Override
public void mouseEntered(MouseEvent e) {
if(e.getSource() == settings){
buttons_popup.setForeground(Color.WHITE);
buttons_popup.setText("Change Workspace");
}

if(e.getSource() == toggle){
buttons_popup.setForeground(Color.WHITE);
buttons_popup.setText("Toggle Project View");
}
}

@Override
public void mouseExited(MouseEvent e) {

buttons_popup.setText("");
}

public class CreateChildNodes implements Runnable {

private DefaultMutableTreeNode root;

private File fileRoot;

public CreateChildNodes(File fileRoot,
DefaultMutableTreeNode root) {
this.fileRoot = fileRoot;
this.root = root;
}

@Override
public void run() {
createChildren(fileRoot, root);
}

private void createChildren(File fileRoot,
DefaultMutableTreeNode node) {
File[] files = fileRoot.listFiles();
if (files == null) return;

for (File file : files) {
DefaultMutableTreeNode childNode =
new DefaultMutableTreeNode(new FileNode(file));
node.add(childNode);
if (file.isDirectory()) {
createChildren(file, childNode);
}
}
}

}

public class FileNode {

private File file;

public FileNode(File file) {
this.file = file;
}

@Override
public String toString() {
String name = file.getName();
if (name.equals("")) {
return file.getAbsolutePath();
} else {
return name;
}
}
}

}


1 change: 1 addition & 0 deletions app/src/processing/app/SketchController.java
Original file line number Diff line number Diff line change
@@ -508,6 +508,7 @@ public boolean addFile(File sourceFile) {
sketch.prepareDataFolder();
destFile = new File(sketch.getDataFolder(), filename);
isData = true;
JOptionPane.showMessageDialog(null,"This file is not supported by the Arduino editor","Invalid extension",1);
}

if (!sourceFile.equals(destFile)) {
Loading
Oops, something went wrong.