Skip to content
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

Series of changes to enable plugin to work on CLion 2016.3.2. #30

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Binary file added CLionArduinoPlugin.zip
Binary file not shown.
19 changes: 13 additions & 6 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@
group-id CDATA #REQUIRED>
]>
<idea-plugin version="2">
<id>io.github.francoiscambell.clionarduinoplugin</id>
<id>io.github.francoiscambell.clionarduinoplugin2017</id>
<name>Arduino</name>
<version>1.2.2</version>
<version>1.2.3</version>
<vendor email="" url="https://github.com/francoiscampbell/CLionArduinoPlugin">Francois Campbell</vendor>

<description><![CDATA[
<h1>CLion Arduino Plugin</h1>
<h1>CLion Arduino Plugin v2</h1>
<br>

<a href="https://github.com/francoiscampbell/CLionArduinoPlugin">GitHub</a> |
This is a branch of the original CLionArduinoPlugin written by Francois Cambell to resolve crash issues.
<br>
<a href="https://github.com/rjuang/CLionArduinoPlugin">Branched Repo</a> |
<a href="https://github.com/francoiscampbell/CLionArduinoPlugin">Original Repo</a> |
<a href="https://github.com/francoiscampbell/CLionArduinoPlugin/issues">Issues</a>
<br>
<br>
Expand All @@ -59,6 +61,11 @@
]]></description>

<change-notes><![CDATA[
<b>1.2.3</b>
<ul>
<li>Fixed to run on CLion 2016.3.2 and 2017.2.1</li>
<li>Updating plugin xml to create a branch that can be uploaded to Jetbrains plugin repo.</li>
</ul>
<b>1.2.2</b>
<ul>
<li>Fixed .ino and .pde files not refactorable. Increased compatibility for Servo library</li>
Expand Down Expand Up @@ -141,4 +148,4 @@
</action>
</actions>

</idea-plugin>
</idea-plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.intellij.icons.*;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.wm.impl.welcomeScreen.*;
import io.github.francoiscambell.clionarduinoplugin.wizards.*;
import io.github.francoiscambell.clionarduinoplugin.wizards.NewArduinoProjectWizard;

/**
* Created by francois on 15-08-14.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package io.github.francoiscambell.clionarduinoplugin.wizards;

import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.TextBrowseFolderListener;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.jetbrains.cidr.cpp.cmake.projectWizard.CMakeProjectStepAdapter;
import com.jetbrains.cidr.cpp.cmake.workspace.CMakeWorkspace;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import static java.awt.GridBagConstraints.HORIZONTAL;
import static java.awt.GridBagConstraints.LINE_END;
import static java.awt.GridBagConstraints.LINE_START;

/**
* Created by radford on 1/9/17.
*/
public class NewArduinoProjectForm extends CMakeProjectStepAdapter {
private JTextField projectNameTextField;
private TextFieldWithBrowseButton projectPathField;

private JPanel mainPanel;
private String lastSelectedPath;

public NewArduinoProjectForm(String defaultProjectName, String defaultProjectPath) {
lastSelectedPath = defaultProjectPath;

mainPanel = new JPanel(new GridBagLayout());

projectNameTextField = new JTextField(defaultProjectName, 20);

GridBagConstraints constraints = new GridBagConstraints();
constraints.ipadx = 5;
constraints.fill = HORIZONTAL;

constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 0.2;
constraints.anchor = LINE_END;

mainPanel.add(new JLabel("Project Name"), constraints);

constraints.gridx = 1;
constraints.gridy = 0;
constraints.weightx = 0.8;
constraints.anchor = LINE_START;

mainPanel.add(projectNameTextField, constraints);

projectPathField = new TextFieldWithBrowseButton(
new JTextField(
defaultProjectPath,
20),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lastSelectedPath = projectPathField.getText();
}
}
);

projectPathField.addBrowseFolderListener(
"Select Target Project Directory",
null,
null,
new FileChooserDescriptor(false,
true,
false,
false,
false,
false));


projectNameTextField.getDocument().addDocumentListener(
new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
syncFields();
}

@Override
public void removeUpdate(DocumentEvent e) {
syncFields();
}

@Override
public void changedUpdate(DocumentEvent e) {
syncFields();
}

private void syncFields() {
String projectName = "/" + projectNameTextField.getText();
if (!lastSelectedPath.endsWith(projectName)) {
projectPathField.setText(lastSelectedPath.concat(projectName));
projectPathField.setAutoscrolls(true);
}
}
}
);

constraints.gridx = 0;
constraints.gridy = 1;
constraints.weightx = 0.2;
constraints.anchor = LINE_END;
mainPanel.add(new JLabel("Project Path"), constraints);

constraints.gridx = 1;
constraints.gridy = 1;
constraints.weightx = 0.8;
constraints.anchor = LINE_START;
mainPanel.add(projectPathField, constraints);
}

@Override
protected void init() {
mainPanel.setVisible(true);
}

@Override
public JComponent getPreferredFocusedComponent() {
return mainPanel;
}

@Override
public void dispose() {
mainPanel.setVisible(false);
}

public String getName() {
return projectNameTextField.getText().replaceAll("-", "_");
}

public String getLocation() {
return projectPathField.getText();
}

@Override
public JComponent getComponent() {
return mainPanel;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
package io.github.francoiscambell.clionarduinoplugin.wizards;

import com.intellij.ide.*;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.project.*;
import com.intellij.openapi.ui.*;
import com.intellij.openapi.util.io.*;
import com.intellij.openapi.vfs.*;
import com.jetbrains.cidr.cpp.*;
import com.intellij.ide.RecentDirectoryProjectsManager;
import com.intellij.ide.RecentProjectsManager;
import com.intellij.ide.util.DirectoryUtil;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.impl.stores.DirectoryStorageUtil;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.cidr.cpp.CPPLog;
import com.jetbrains.cidr.cpp.cmake.CMakeProjectOpenProcessor;
import com.jetbrains.cidr.cpp.cmake.projectWizard.*;
import com.jetbrains.cidr.cpp.cmake.workspace.*;
import io.github.francoiscambell.clionarduinoplugin.*;
import io.github.francoiscambell.clionarduinoplugin.resources.*;
import io.github.francoiscambell.clionarduinoplugin.CMakeListsEditor;
import io.github.francoiscambell.clionarduinoplugin.resources.ArduinoToolchainFiles;
import io.github.francoiscambell.clionarduinoplugin.resources.Strings;
import org.jdom.JDOMException;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Optional;

import static com.jetbrains.cidr.cpp.cmake.projectWizard.CLionProjectWizardUtils.refreshProjectDir;

import java.io.*;

/**
* Created by francois on 15-08-14.
*/
public class NewArduinoProjectWizard extends CMakeProjectWizard {
private NewCMakeProjectStepAdapter adapter = new NewCMakeProjectStepAdapter();

private String lastDir = Optional.ofNullable(RecentProjectsManager.getInstance().getLastProjectCreationLocation())
.orElse("");

private NewArduinoProjectForm adapter = new NewArduinoProjectForm(
"untitled-0",
new File(lastDir).getPath());

public NewArduinoProjectWizard() {
super("New Arduino Sketch Project", "NewArduinoSketchProject");
Expand All @@ -27,7 +49,8 @@ public NewArduinoProjectWizard() {

@Override
protected boolean tryFinish() {
String projectRootPath = this.adapter.getLocation();
String projectRootPath = adapter.getLocation();

File projectRootDir = new File(projectRootPath);
if (projectRootDir.exists()) {
String[] fileList = projectRootDir.list(new FilenameFilter() {
Expand All @@ -46,10 +69,8 @@ public boolean accept(File dir, String name) {
} else {
try {
VfsUtil.createDirectories(projectRootPath);
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
} catch (IOException e) {
} catch (IOException | RuntimeException e) {
CPPLog.LOG.warn(e);
return false;
}
}
Expand Down Expand Up @@ -90,6 +111,14 @@ public static String createProject(String projectName, String projectRootPath) t
cMakeListsEditor.project("${PROJECT_NAME}");
cMakeListsEditor.blankLine();
cMakeListsEditor.set("${CMAKE_PROJECT_NAME}_SKETCH", projectName + ".ino");
cMakeListsEditor.blankLine();
cMakeListsEditor.appendLine("#### Uncomment below additional settings as needed.");
cMakeListsEditor.appendLine("# set(${CMAKE_PROJECT_NAME}_BOARD mega)");
cMakeListsEditor.appendLine("# set(${CMAKE_PROJECT_NAME}_PORT /dev/ttyACM0)");
cMakeListsEditor.appendLine("# set(mega.build.mcu atmega2560)");
cMakeListsEditor.appendLine("# set(mega.upload.protocol wiring)");
cMakeListsEditor.appendLine("# set(mega.upload.speed 115200)");
cMakeListsEditor.blankLine();
cMakeListsEditor.method("generate_arduino_firmware", "${CMAKE_PROJECT_NAME}");

ArduinoToolchainFiles.copyToDirectory(VfsUtil.findFileByIoFile(projectRoot, true));
Expand All @@ -114,16 +143,30 @@ protected void doRunWizard() {
if (mainSketchFile == null) {
return;
}
final Project project = CMakeWorkspace.openProject(cMakeLists, null, false);

final Project project;
try {
project = ProjectManager.getInstance().loadAndOpenProject(cMakeLists.getPath());
} catch (IOException | JDOMException e) {
CPPLog.LOG.warn(e);
return;
}

if (project == null) {
return;
}
deleteBuildOutputDir(project);

CMakeProjectOpenProcessor.OpenProjectSpec projectSpec = CMakeProjectOpenProcessor.getHelper()
.getAndClearFileToOpenData(project);

deleteBuildOutputDir(projectSpec);
(new OpenFileDescriptor(project, cMakeLists)).navigate(false);
(new OpenFileDescriptor(project, mainSketchFile)).navigate(true);
}

private void deleteBuildOutputDir(Project project) {
FileUtil.delete(CMakeWorkspace.getInstance(project).getProjectGeneratedDir());
private void deleteBuildOutputDir(CMakeProjectOpenProcessor.OpenProjectSpec projectSpec) {
if (projectSpec != null && projectSpec.generationDir != null) {
FileUtil.delete(projectSpec.generationDir);
}
}
}