Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing navigate dialog
  • Loading branch information
samirm19 committed Dec 4, 2020
commit f1da0a6f066f888389e2e6b4a1dacff250cd7d92
10 changes: 9 additions & 1 deletion app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
@@ -2606,9 +2606,17 @@ public void addCompilerProgressListener(CompilerProgressListener listener){

public void handleAddProjectView(){


// Check if the recent sketch is saved, if not fall back on the sketchbook path
if(untitled){
project = new EditorProject(PreferencesData.get("sketchbook.path"), base, this);
}else{
project = new EditorProject(sketch.getFolder().getAbsolutePath(), base, this);
}

// Reset the panels and add the project view
middle.remove(editor_upper);
project = new EditorProject(PreferencesData.get("sketchbook.path"), base, this);

middle.add(project);
middle.add(editor_upper);

61 changes: 42 additions & 19 deletions app/src/processing/app/EditorProject.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package processing.app;

import processing.app.tools.jexplorer.JExplorerPanel;

import processing.app.tools.NavigateDialog;
import processing.app.tools.ProjectExplorer;
import javax.swing.*;
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;
import java.io.IOException;

import static java.awt.Color.RED;
import static processing.app.I18n.tr;


public class EditorProject extends JPanel {

private JExplorerPanel fileExplorerPanel;
private ProjectExplorer fileExplorerPanel;

private File fileRoot;

@@ -37,7 +30,7 @@ public EditorProject(String path, Base base, Editor editor){
fileRoot = new File(path);
this.base = base;
this.editor = editor;
fileExplorerPanel = new JExplorerPanel(fileRoot, editor);
fileExplorerPanel = new ProjectExplorer(fileRoot, editor);
projectToolbar = new ProjectToolbar(editor, this);
/*buttons_popup = new Label("Toggle Project View");
buttons_popup.setForeground(new Color(23, 161, 165));
@@ -75,29 +68,59 @@ public EditorProject(String path, Base base, Editor editor){

}

public void resetProject(){
public void resetProject(File file){
// Resetting the project View and root directory
fileRoot = new File(path);
fileRoot = file;
path = file.getPath();
fileExplorerPanel.replaceWorkingDirectory(fileRoot);

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


editor.statusNotice(tr("Navigated to :")+path);
}


public void handleNavigate(){
chooser = new JFileChooser();
/*chooser = new JFileChooser();
chooser.setCurrentDirectory(fileRoot);
chooser.setDialogTitle("Choose project directory : ");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

if (chooser.showOpenDialog(fileExplorerPanel) == JFileChooser.APPROVE_OPTION) {
this.path = chooser.getSelectedFile().getAbsolutePath();
resetProject();
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
resetProject(chooser.getSelectedFile());
}
/*JDialog jDialog = new JDialog();
JTextField pathfield = new JTextField();
jDialog.setPreferredSize(new Dimension(400,400));
jDialog.setTitle("Choose the directory to navigate to :");
JPanel panel = new JPanel(new BorderLayout());
panel.add(pathfield, BorderLayout.NORTH);
JExplorerPanel navigator = new JExplorerPanel(new File("/home/sami"), editor);
panel.add(navigator, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
JButton open = new JButton("Open");
buttonPanel.add(open);
open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
JButton cancel = new JButton("Cancel");
buttonPanel.add(cancel);
open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jDialog.dispose();
}
});
panel.add(buttonPanel, BorderLayout.SOUTH);
jDialog.add(panel);
jDialog.pack();
jDialog.setLocationRelativeTo(null);
jDialog.setVisible(true);*/
NavigateDialog navigateDialog = new NavigateDialog(new File("/home/sami/"), fileRoot);
}


6 changes: 6 additions & 0 deletions app/src/processing/app/ProjectToolbar.java
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;

import static processing.app.I18n.tr;
@@ -431,6 +432,11 @@ private void handleSelectionPressed(int sel, int x, int y) {
case SKETCH:
// TODO
// Check save state (if not save) then open sketch folder
if(editor.untitled){
editor.handleSaveAs();
}
// Get the diretory of the sketch
editorProject.resetProject(editor.sketch.getFolder());
break;

case TOGGLE:
24 changes: 11 additions & 13 deletions app/src/processing/app/macosx/ThinkDifferent.java
Original file line number Diff line number Diff line change
@@ -22,14 +22,12 @@

package processing.app.macosx;

import com.apple.eawt.*;
import com.apple.eawt.AppEvent.AppReOpenedEvent;

import java.awt.Desktop;

import com.apple.eawt.AppEvent;
import processing.app.Base;
import processing.app.Editor;

import java.awt.desktop.*;
import java.io.File;
import java.util.List;

@@ -48,11 +46,11 @@ public class ThinkDifferent {
private static final int MAX_WAIT_FOR_BASE = 30000;

static public void init() {
Desktop application = Desktop.getDesktop();
Application application = Application.getApplication();

application.addAppEventListener(new AppReopenedListener() {
application.addAppEventListener(new AppReOpenedListener() {
@Override
public void appReopened(AppReopenedEvent aroe) {
public void appReOpened(AppReOpenedEvent aroe) {
try {
if (Base.INSTANCE.getEditors().size() == 0) {
Base.INSTANCE.handleNew();
@@ -62,11 +60,10 @@ public void appReopened(AppReopenedEvent aroe) {
e.printStackTrace();
}
}

});
application.setAboutHandler(new AboutHandler() {
@Override
public void handleAbout(AboutEvent aboutEvent) {
public void handleAbout(AppEvent.AboutEvent aboutEvent) {
new Thread(() -> {
if (waitForBase()) {
Base.INSTANCE.handleAbout();
@@ -76,7 +73,7 @@ public void handleAbout(AboutEvent aboutEvent) {
});
application.setPreferencesHandler(new PreferencesHandler() {
@Override
public void handlePreferences(PreferencesEvent preferencesEvent) {
public void handlePreferences(AppEvent.PreferencesEvent preferencesEvent) {
new Thread(() -> {
if (waitForBase()) {
Base.INSTANCE.handlePrefs();
@@ -86,7 +83,7 @@ public void handlePreferences(PreferencesEvent preferencesEvent) {
});
application.setOpenFileHandler(new OpenFilesHandler() {
@Override
public void openFiles(OpenFilesEvent openFilesEvent) {
public void openFiles(final AppEvent.OpenFilesEvent openFilesEvent) {
new Thread(() -> {
if (waitForBase()) {
for (File file : openFilesEvent.getFiles()) {
@@ -107,7 +104,7 @@ public void openFiles(OpenFilesEvent openFilesEvent) {
});
application.setQuitHandler(new QuitHandler() {
@Override
public void handleQuitRequestWith(QuitEvent quitEvent, QuitResponse quitResponse) {
public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse quitResponse) {
new Thread(() -> {
if (waitForBase()) {
if (Base.INSTANCE.handleQuit()) {
@@ -117,7 +114,8 @@ public void handleQuitRequestWith(QuitEvent quitEvent, QuitResponse quitResponse
}
}
}).start();
}});
}
});
}

private static boolean waitForBase() {
87 changes: 87 additions & 0 deletions app/src/processing/app/tools/NavigateDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package processing.app.tools;

import processing.app.Editor;
import processing.app.tools.jexplorer.JExplorerPanel;

import javax.swing.*;
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 NavigateDialog extends JExplorerPanel implements ActionListener {

private JTextField pathfield;
private JDialog dialog;
private JButton open, cancel;

public NavigateDialog(File rootFile, File projectDir){
super(rootFile);
this.getTree().addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}

@Override
public void mousePressed(MouseEvent e) {

}

@Override
public void mouseReleased(MouseEvent e) {

}

@Override
public void mouseEntered(MouseEvent e) {

}

@Override
public void mouseExited(MouseEvent e) {

}
});
pathfield = new JTextField();

dialog = new JDialog();
dialog.setBackground(Color.BLACK);
pathfield = new JTextField();
dialog.setPreferredSize(new Dimension(400,400));
dialog.setTitle("Choose the directory to navigate to :");
JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque(false);
panel.add(pathfield, BorderLayout.NORTH);
panel.add(this, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
panel.setOpaque(false);
open = new JButton("Open");
open.addActionListener(this);
buttonPanel.add(open);
cancel = new JButton("Cancel");
cancel.addActionListener(this);
buttonPanel.add(cancel);
panel.add(buttonPanel, BorderLayout.SOUTH);
dialog.add(panel);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e) {

if(e.getSource() == open){

}
if(e.getSource() == cancel){
dialog.setVisible(false);
dialog.dispose();
}
}


}
21 changes: 21 additions & 0 deletions app/src/processing/app/tools/ProjectExplorer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package processing.app.tools;

import processing.app.Editor;
import processing.app.tools.jexplorer.JExplorerPanel;

import java.io.File;

public class ProjectExplorer extends JExplorerPanel {

private Editor editor;

public ProjectExplorer(File rootDir, Editor editor) {
super(rootDir);
this.editor = editor;
}

@Override
protected void handleOpenFile(File file) {
editor.getSketchController().addFile(file);
}
}
8 changes: 2 additions & 6 deletions app/src/processing/app/tools/jexplorer/JExplorerPanel.java
Original file line number Diff line number Diff line change
@@ -75,17 +75,15 @@ public class JExplorerPanel extends JPanel {

private Translate translate;

private Editor editor;

// Alow Ctrl+Z last file operation.
private LimitedQueue<FileOperation> undoQueue = new LimitedQueue<FileOperation>(5);

private FileTransferable currentFileTransferable;

public JExplorerPanel(File rootDir, Editor editor) {
public JExplorerPanel(File rootDir) {
super();
this.rootDir = rootDir;
this.editor = editor;
initComponents();
initMenus();
initKeyboard();
@@ -465,9 +463,7 @@ protected void handleProperties() {
}


protected void handleOpenFile(File file) {
editor.getSketchController().addFile(file);
}
protected void handleOpenFile(File file) {}

protected void handleRename() {