├── lib ├── commons-io-2.4.jar ├── commons-io-2.4-javadoc.jar └── commons-io-2.4-sources.jar ├── src └── io │ └── github │ └── francoiscambell │ └── clionarduinoplugin │ ├── resources │ ├── icons │ │ ├── Arduino_Logo.png │ │ ├── Arduino_Logo@2x.png │ │ ├── Arduino_Logo_dark.png │ │ ├── Arduino_Logo@2x_dark.png │ │ └── ArduinoIcon.java │ ├── Strings.java │ └── ArduinoToolchainFiles.java │ ├── actions │ ├── NewArduinoProject.java │ └── NewSketchFile.java │ ├── ArduinoSketchFileCreator.java │ ├── components │ └── ArduinoFileTypeRegistration.java │ ├── CMakeListsEditor.java │ └── wizards │ └── NewArduinoProjectWizard.java ├── .gitmodules ├── .gitignore ├── README.md └── META-INF └── plugin.xml /lib/commons-io-2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/francoiscampbell/CLionArduinoPlugin/HEAD/lib/commons-io-2.4.jar -------------------------------------------------------------------------------- /lib/commons-io-2.4-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/francoiscampbell/CLionArduinoPlugin/HEAD/lib/commons-io-2.4-javadoc.jar -------------------------------------------------------------------------------- /lib/commons-io-2.4-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/francoiscampbell/CLionArduinoPlugin/HEAD/lib/commons-io-2.4-sources.jar -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/resources/icons/Arduino_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/francoiscampbell/CLionArduinoPlugin/HEAD/src/io/github/francoiscambell/clionarduinoplugin/resources/icons/Arduino_Logo.png -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/resources/icons/Arduino_Logo@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/francoiscampbell/CLionArduinoPlugin/HEAD/src/io/github/francoiscambell/clionarduinoplugin/resources/icons/Arduino_Logo@2x.png -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/resources/icons/Arduino_Logo_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/francoiscampbell/CLionArduinoPlugin/HEAD/src/io/github/francoiscambell/clionarduinoplugin/resources/icons/Arduino_Logo_dark.png -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/resources/icons/Arduino_Logo@2x_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/francoiscampbell/CLionArduinoPlugin/HEAD/src/io/github/francoiscambell/clionarduinoplugin/resources/icons/Arduino_Logo@2x_dark.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/io/github/francoiscambell/clionarduinoplugin/resources/arduino-cmake"] 2 | path = src/io/github/francoiscambell/clionarduinoplugin/resources/arduino-cmake 3 | url = git://github.com/francoiscampbell/arduino-cmake.git 4 | ignore = dirty 5 | -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/resources/icons/ArduinoIcon.java: -------------------------------------------------------------------------------- 1 | package io.github.francoiscambell.clionarduinoplugin.resources.icons; 2 | 3 | import com.intellij.openapi.util.*; 4 | 5 | import javax.swing.*; 6 | 7 | /** 8 | * Created by francois on 15-08-04. 9 | */ 10 | public class ArduinoIcon { 11 | public static final Icon ARDUINO_ICON = IconLoader.getIcon("Arduino_Logo.png"); 12 | } 13 | -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/actions/NewArduinoProject.java: -------------------------------------------------------------------------------- 1 | package io.github.francoiscambell.clionarduinoplugin.actions; 2 | 3 | import com.intellij.icons.*; 4 | import com.intellij.openapi.actionSystem.*; 5 | import com.intellij.openapi.wm.impl.welcomeScreen.*; 6 | import io.github.francoiscambell.clionarduinoplugin.wizards.*; 7 | 8 | /** 9 | * Created by francois on 15-08-14. 10 | */ 11 | public class NewArduinoProject extends AnAction { 12 | public void update(AnActionEvent event) { 13 | Presentation presentation = event.getPresentation(); 14 | if (ActionPlaces.isMainMenuOrActionSearch(event.getPlace())) { 15 | presentation.setIcon(null); 16 | } 17 | 18 | if (NewWelcomeScreen.isNewWelcomeScreen(event)) { 19 | event.getPresentation().setIcon(AllIcons.Welcome.CreateNewProject); 20 | } 21 | 22 | } 23 | 24 | @Override 25 | public void actionPerformed(AnActionEvent e) { 26 | (new NewArduinoProjectWizard()).runWizard(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/resources/Strings.java: -------------------------------------------------------------------------------- 1 | package io.github.francoiscambell.clionarduinoplugin.resources; 2 | 3 | /** 4 | * Created by francois on 15-08-04. 5 | */ 6 | public class Strings { 7 | public static final String CMAKE_LISTS_FILENAME = "CMakeLists.txt"; 8 | public static final String CPP_EXT = "cpp"; 9 | public static final String DEFAULT_ARDUINO_SKETCH_CONTENTS = "#include \n\nvoid setup() {\n\n}\n\nvoid loop() {\n\n}"; 10 | public static final String ENTER_FILENAME = "Enter filename"; 11 | public static final String ERROR = "Error"; 12 | public static final String FILE_ALREADY_EXISTS = "File Already Exists"; 13 | public static final String INO_EXT = "ino"; 14 | public static final String DOT_INO_EXT = "." + INO_EXT; 15 | public static final String MAIN_CPP_FILENAME = "main.cpp"; 16 | public static final String PDE_EXT = "PDE"; 17 | public static final String DOT_PDE_EXT = "." + PDE_EXT; 18 | public static final String QUESTION_OVERWRITE = "Do you wish to overwrite the existing file?"; 19 | public static final String SKETCH_NAME = "Sketch Name"; 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion 4 | 5 | *.iml 6 | 7 | ## Directory-based project format: 8 | .idea/ 9 | # if you remove the above rule, at least ignore the following: 10 | 11 | # User-specific stuff: 12 | # .idea/workspace.xml 13 | # .idea/tasks.xml 14 | # .idea/dictionaries 15 | 16 | # Sensitive or high-churn files: 17 | # .idea/dataSources.ids 18 | # .idea/dataSources.xml 19 | # .idea/sqlDataSources.xml 20 | # .idea/dynamic.xml 21 | # .idea/uiDesigner.xml 22 | 23 | # Gradle: 24 | # .idea/gradle.xml 25 | # .idea/libraries 26 | 27 | # Mongo Explorer plugin: 28 | # .idea/mongoSettings.xml 29 | 30 | ## File-based project format: 31 | *.ipr 32 | *.iws 33 | 34 | ## Plugin-specific files: 35 | 36 | # IntelliJ 37 | /out/ 38 | 39 | # mpeltonen/sbt-idea plugin 40 | .idea_modules/ 41 | 42 | # JIRA plugin 43 | atlassian-ide-plugin.xml 44 | 45 | # Crashlytics plugin (for Android Studio and IntelliJ) 46 | com_crashlytics_export_strings.xml 47 | crashlytics.properties 48 | crashlytics-build.properties 49 | 50 | /*.zip 51 | 52 | *.DS_Store 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/ArduinoSketchFileCreator.java: -------------------------------------------------------------------------------- 1 | package io.github.francoiscambell.clionarduinoplugin; 2 | 3 | import com.intellij.openapi.application.*; 4 | import com.intellij.openapi.command.*; 5 | import com.intellij.openapi.editor.*; 6 | import com.intellij.openapi.fileEditor.*; 7 | import com.intellij.openapi.project.*; 8 | import com.intellij.openapi.vfs.*; 9 | import io.github.francoiscambell.clionarduinoplugin.resources.*; 10 | 11 | import java.io.*; 12 | 13 | /** 14 | * Created by francois on 15-08-04. 15 | */ 16 | public class ArduinoSketchFileCreator { 17 | 18 | public static VirtualFile createSketchFileWithName(final Project project, final VirtualFile directory, final String name) { 19 | ApplicationManager.getApplication().runWriteAction(new Runnable() { 20 | @Override 21 | public void run() { 22 | try { 23 | VirtualFile sketch = directory.createChildData(this, name); 24 | final Document sketchDocument = FileDocumentManager.getInstance().getDocument(sketch); 25 | if (sketchDocument != null) { 26 | CommandProcessor.getInstance().executeCommand(project, new Runnable() { 27 | @Override 28 | public void run() { 29 | sketchDocument.setText(Strings.DEFAULT_ARDUINO_SKETCH_CONTENTS); 30 | } 31 | }, null, null, sketchDocument); 32 | } 33 | } catch (IOException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | }); 38 | return directory.findChild(name); 39 | } 40 | 41 | public static void addFileToCMakeLists(final Project project, final VirtualFile file) { 42 | CMakeListsEditor.getInstance(project.getBaseDir()).set("SOURCE_FILES", file.getName()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/components/ArduinoFileTypeRegistration.java: -------------------------------------------------------------------------------- 1 | package io.github.francoiscambell.clionarduinoplugin.components; 2 | 3 | import com.intellij.openapi.application.*; 4 | import com.intellij.openapi.components.*; 5 | import com.intellij.openapi.fileTypes.*; 6 | import io.github.francoiscambell.clionarduinoplugin.resources.*; 7 | import org.jetbrains.annotations.*; 8 | 9 | /** 10 | * Created by francois on 15-08-03. 11 | */ 12 | public class ArduinoFileTypeRegistration implements ApplicationComponent { 13 | 14 | public void initComponent() { 15 | ApplicationManager.getApplication().invokeLater(new Runnable() { 16 | @Override 17 | public void run() { 18 | ApplicationManager.getApplication().runWriteAction(new Runnable() { 19 | @Override 20 | public void run() { 21 | FileType cpp = FileTypeManager.getInstance().getFileTypeByExtension(Strings.CPP_EXT); 22 | FileTypeManager.getInstance().associateExtension(cpp, Strings.INO_EXT); 23 | FileTypeManager.getInstance().associateExtension(cpp, Strings.PDE_EXT); 24 | } 25 | }); 26 | } 27 | }); 28 | } 29 | 30 | public void disposeComponent() { 31 | ApplicationManager.getApplication().invokeLater(new Runnable() { 32 | @Override 33 | public void run() { 34 | ApplicationManager.getApplication().runWriteAction(new Runnable() { 35 | @Override 36 | public void run() { 37 | FileType cpp = FileTypeManager.getInstance().getFileTypeByExtension(Strings.CPP_EXT); 38 | FileTypeManager.getInstance().removeAssociatedExtension(cpp, Strings.INO_EXT); 39 | FileTypeManager.getInstance().removeAssociatedExtension(cpp, Strings.PDE_EXT); 40 | } 41 | }); 42 | } 43 | }); 44 | } 45 | 46 | @NotNull 47 | public String getComponentName() { 48 | return "ArduinoFileTypeRegistration"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #CLion Arduino Plugin 2 | 3 | This is a JetBrains CLion plugin that integrates [Arduino CMake](https://github.com/francoiscampbell/arduino-cmake) into the IDE. 4 | 5 | The current features are to create an Arduino CMake project in one click, and to create new sketch files. 6 | 7 | For those asking how to upload, you need to specify the serial port in the CMakeLists.txt file. For example: 8 | 9 | set(${CMAKE_PROJECT_NAME}_BOARD uno) 10 | set(${CMAKE_PROJECT_NAME}_PORT /dev/ttys0) 11 | 12 | This will create the 'upload' configuration in your Run Configurations and you can click the Run button or use the keyboard shortcut to upload. 13 | 14 | Future features are to add menu option to easily change the board type, port number, import existing Arduino projects, etc. 15 | 16 | ## Update on status: 17 | It seems that arduino-cmake (the backing plugin) development has pretty much stalled, which is the root cause of most of the issues here, so I've got my own fork and I've tried to implement most of the fixes from previous forks of the project, which are also mostly dead. This project was just an exercise in making a JetBrains plugin that turned out well, but I don't have a lot of free time on my hands to do this though, what with full-time university and what not, so I can't give a definite date on what will be fixed when, but I will make an effort to get it done. 18 | 19 | ## Release Notes 20 | 21 | **1.2.2** 22 | 23 | * Fixed .ino and .pde files not refactorable. Increased compatibility for Servo library 24 | 25 | **1.2.1** 26 | 27 | * Re-compiled for Java 6 28 | 29 | **1.2.0** 30 | 31 | * Added new project creation to Welcome Screen and File menu 32 | 33 | **1.1.0** 34 | 35 | * Compatiblity with Arduino SDK 1.6 on Mac OS X 36 | 37 | **1.0.2** 38 | 39 | * Removed Groovy runtime, no longer necessary 40 | 41 | **1.0.1** 42 | 43 | * Fixed organization 44 | 45 | **1.0** 46 | 47 | * Convert a project to Arduino CMake. This replaces CMakeLists.txt with a default one, deletes the default main.cpp file, copies in the Arduino CMake toolchain files, and deletes the build direcory to start fresh 48 | * Associates .ino and .pde files as C++ source, so you get syntax highlighting and prediction, etc. 49 | * Create a new sketch file in any directory. If you omit the extension, it will add .ino automatically 50 | * Adds import for Arduino.h to all newly created sketch files to enable code completion 51 | * Compiled with Java 6 for compatibility with OS X out of the box 52 | -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/resources/ArduinoToolchainFiles.java: -------------------------------------------------------------------------------- 1 | package io.github.francoiscambell.clionarduinoplugin.resources; 2 | 3 | import com.intellij.openapi.application.ApplicationManager; 4 | import com.intellij.openapi.vfs.VirtualFile; 5 | import org.apache.commons.io.IOUtils; 6 | 7 | import java.io.Closeable; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.OutputStream; 11 | 12 | /** 13 | * Created by francois on 15-08-03. 14 | */ 15 | public class ArduinoToolchainFiles { 16 | public static InputStream getArduinoToolchainCmake() { 17 | return ArduinoToolchainFiles.class.getResourceAsStream("arduino-cmake/cmake/ArduinoToolchain.cmake"); 18 | } 19 | 20 | public static InputStream getArduinoCmake() { 21 | return ArduinoToolchainFiles.class.getResourceAsStream("arduino-cmake/cmake/Platform/Arduino.cmake"); 22 | } 23 | 24 | public static void copyToDirectory(final VirtualFile projectRoot) { 25 | ApplicationManager.getApplication().runWriteAction(new Runnable() { 26 | @Override 27 | public void run() { 28 | try { 29 | VirtualFile cmakeDirectory = projectRoot.createChildDirectory(this, "cmake"); 30 | VirtualFile platformDirectory = cmakeDirectory.createChildDirectory(this, "Platform"); 31 | 32 | VirtualFile arduinoToolchain = cmakeDirectory.createChildData(this, "ArduinoToolchain.cmake"); 33 | VirtualFile arduino = platformDirectory.createChildData(this, "Arduino.cmake"); 34 | 35 | OutputStream arduinoToolchainOutputStream = arduinoToolchain.getOutputStream(this); 36 | OutputStream arduinoOutputStream = arduino.getOutputStream(this); 37 | 38 | InputStream arduinoToolchainInputStream = getArduinoToolchainCmake(); 39 | InputStream arduinoInputStream = getArduinoCmake(); 40 | 41 | try { 42 | IOUtils.copy(arduinoToolchainInputStream, arduinoToolchainOutputStream); 43 | IOUtils.copy(arduinoInputStream, arduinoOutputStream); 44 | } finally { 45 | closeStreams(arduinoToolchainOutputStream, 46 | arduinoOutputStream, 47 | arduinoToolchainInputStream, 48 | arduinoInputStream); 49 | } 50 | } catch (IOException e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | }); 55 | } 56 | 57 | private static void closeStreams(Closeable... streams) { 58 | for (Closeable c : streams) { 59 | IOUtils.closeQuietly(c); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/CMakeListsEditor.java: -------------------------------------------------------------------------------- 1 | package io.github.francoiscambell.clionarduinoplugin; 2 | 3 | import com.intellij.openapi.application.*; 4 | import com.intellij.openapi.command.*; 5 | import com.intellij.openapi.editor.*; 6 | import com.intellij.openapi.fileEditor.*; 7 | import com.intellij.openapi.vfs.*; 8 | 9 | import java.util.*; 10 | 11 | /** 12 | * Created by francois on 15-08-04. 13 | */ 14 | public class CMakeListsEditor { 15 | private static Map INSTANCES = new WeakHashMap(); 16 | private VirtualFile cMakeListsVirtualFile; 17 | 18 | private CMakeListsEditor(VirtualFile cMakeLists) { 19 | this.cMakeListsVirtualFile = cMakeLists; 20 | } 21 | 22 | public static CMakeListsEditor getInstance(VirtualFile cMakeLists) { 23 | if (!INSTANCES.containsKey(cMakeLists)) { 24 | INSTANCES.put(cMakeLists, new CMakeListsEditor(cMakeLists)); 25 | } 26 | return INSTANCES.get(cMakeLists); 27 | } 28 | 29 | private VirtualFile getCMakeListsVirtualFile() { 30 | return cMakeListsVirtualFile; 31 | } 32 | 33 | private Document getCMakeListsDocument() { 34 | return FileDocumentManager.getInstance().getDocument(getCMakeListsVirtualFile()); 35 | } 36 | 37 | public void clear() { 38 | final Document cMakeLists = getCMakeListsDocument(); 39 | ApplicationManager.getApplication().runWriteAction(new Runnable() { 40 | @Override 41 | public void run() { 42 | CommandProcessor.getInstance().executeCommand(null, new Runnable() { 43 | @Override 44 | public void run() { 45 | cMakeLists.deleteString(0, cMakeLists.getTextLength()); 46 | FileDocumentManager.getInstance().saveDocument(cMakeLists); 47 | } 48 | }, null, null, cMakeLists); 49 | } 50 | }); 51 | } 52 | 53 | public void addLine(int line, final String text) { 54 | final Document cMakeLists = getCMakeListsDocument(); 55 | final int lineEndOffset = cMakeLists.getLineEndOffset(line); 56 | 57 | ApplicationManager.getApplication().runWriteAction(new Runnable() { 58 | @Override 59 | public void run() { 60 | CommandProcessor.getInstance().executeCommand(null, new Runnable() { 61 | @Override 62 | public void run() { 63 | cMakeLists.insertString(lineEndOffset, text + "\n"); 64 | FileDocumentManager.getInstance().saveDocument(cMakeLists); 65 | } 66 | }, null, null, cMakeLists); 67 | } 68 | }); 69 | } 70 | 71 | public void appendLine(String text) { 72 | int lastLine = getCMakeListsDocument().getLineCount(); 73 | if (lastLine != 0) { 74 | lastLine--; 75 | } 76 | addLine(lastLine, text); 77 | } 78 | 79 | public void blankLine() { 80 | appendLine(""); 81 | } 82 | 83 | public void minVersion(String minVersion) { 84 | method("cmake_minimum_required", "VERSION", minVersion); 85 | } 86 | 87 | public void set(String var, String value) { 88 | method("set", var, value); 89 | } 90 | 91 | public void project(String projectName) { 92 | method("project", projectName); 93 | } 94 | 95 | public void method(String methodName, String... args) { 96 | StringBuilder builder = new StringBuilder(methodName); 97 | builder.append('('); 98 | for (String arg : args) { 99 | builder.append(arg); 100 | builder.append(' '); 101 | } 102 | if (args.length > 0) { 103 | builder.deleteCharAt(builder.length() - 1); 104 | } 105 | builder.append(')'); 106 | appendLine(builder.toString()); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/actions/NewSketchFile.java: -------------------------------------------------------------------------------- 1 | package io.github.francoiscambell.clionarduinoplugin.actions; 2 | 3 | import com.intellij.ide.*; 4 | import com.intellij.openapi.actionSystem.*; 5 | import com.intellij.openapi.application.*; 6 | import com.intellij.openapi.fileEditor.*; 7 | import com.intellij.openapi.project.*; 8 | import com.intellij.openapi.ui.*; 9 | import com.intellij.openapi.vfs.*; 10 | import com.intellij.psi.*; 11 | import io.github.francoiscambell.clionarduinoplugin.*; 12 | import io.github.francoiscambell.clionarduinoplugin.resources.*; 13 | import io.github.francoiscambell.clionarduinoplugin.resources.icons.*; 14 | import org.jetbrains.annotations.*; 15 | 16 | import java.io.*; 17 | 18 | /** 19 | * Created by francois on 15-08-02. 20 | */ 21 | public class NewSketchFile extends AnAction { 22 | 23 | public void actionPerformed(AnActionEvent e) { 24 | final Project project = e.getRequiredData(CommonDataKeys.PROJECT); 25 | final IdeView view = e.getRequiredData(LangDataKeys.IDE_VIEW); 26 | 27 | PsiDirectory directory = view.getOrChooseDirectory(); 28 | if (directory == null) { 29 | return; 30 | } 31 | final VirtualFile directoryVirtualFile = directory.getVirtualFile(); 32 | 33 | boolean loop = false; 34 | do { 35 | String filename = getDesiredFilename(project); 36 | if (filename == null) { //cancel 37 | return; 38 | } 39 | if (filename.isEmpty()) { //no name entered 40 | showEmptyFilenameError(project); 41 | loop = true; 42 | continue; 43 | } 44 | filename = correctExtension(filename); //add .ino if the current filename doesn't end with .ino or .pde 45 | 46 | VirtualFile existingFile = directoryVirtualFile.findChild(filename); 47 | if (existingFile != null) { 48 | int overwriteChoice = getOverwriteChoice(project); //ask to overwrite file 49 | switch (overwriteChoice) { 50 | case Messages.YES: 51 | deleteVirtualFile(existingFile); 52 | loop = false; 53 | break; 54 | case Messages.NO: 55 | loop = true; 56 | continue; 57 | case Messages.CANCEL: 58 | return; 59 | } 60 | } 61 | VirtualFile sketch = ArduinoSketchFileCreator 62 | .createSketchFileWithName(project, directoryVirtualFile, filename); 63 | // ArduinoSketchFileCreator.addFileToCMakeLists(project, sketch); //not sure if i need to do this or not 64 | FileEditorManager.getInstance(project).openFile(sketch, true, true); //open in editor 65 | } while (loop); 66 | } 67 | 68 | private void showEmptyFilenameError(Project project) { 69 | Messages.showErrorDialog(project, Strings.ENTER_FILENAME, Strings.ERROR); 70 | } 71 | 72 | private int getOverwriteChoice(Project project) { 73 | return Messages 74 | .showYesNoCancelDialog(project, Strings.QUESTION_OVERWRITE, Strings.FILE_ALREADY_EXISTS, ArduinoIcon.ARDUINO_ICON); 75 | } 76 | 77 | private String getDesiredFilename(Project project) { 78 | return Messages 79 | .showInputDialog(project, Strings.ENTER_FILENAME, Strings.SKETCH_NAME, ArduinoIcon.ARDUINO_ICON); 80 | } 81 | 82 | @NotNull 83 | private String correctExtension(String filename) { 84 | if (!(filename.endsWith(Strings.DOT_INO_EXT) || filename.endsWith(Strings.DOT_PDE_EXT))) { 85 | filename = filename + Strings.DOT_INO_EXT; 86 | } 87 | return filename; 88 | } 89 | 90 | 91 | private void deleteVirtualFile(final VirtualFile virtualFile) { 92 | if (virtualFile == null) { 93 | return; 94 | } 95 | ApplicationManager.getApplication().runWriteAction(new Runnable() { 96 | @Override 97 | public void run() { 98 | try { 99 | virtualFile.delete(this); 100 | } catch (IOException e) { 101 | e.printStackTrace(); 102 | } 103 | } 104 | }); 105 | 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/io/github/francoiscambell/clionarduinoplugin/wizards/NewArduinoProjectWizard.java: -------------------------------------------------------------------------------- 1 | package io.github.francoiscambell.clionarduinoplugin.wizards; 2 | 3 | import com.intellij.ide.*; 4 | import com.intellij.openapi.fileEditor.*; 5 | import com.intellij.openapi.project.*; 6 | import com.intellij.openapi.ui.*; 7 | import com.intellij.openapi.util.io.*; 8 | import com.intellij.openapi.vfs.*; 9 | import com.jetbrains.cidr.cpp.*; 10 | import com.jetbrains.cidr.cpp.cmake.projectWizard.*; 11 | import com.jetbrains.cidr.cpp.cmake.workspace.*; 12 | import io.github.francoiscambell.clionarduinoplugin.*; 13 | import io.github.francoiscambell.clionarduinoplugin.resources.*; 14 | 15 | import java.io.*; 16 | 17 | /** 18 | * Created by francois on 15-08-14. 19 | */ 20 | public class NewArduinoProjectWizard extends CMakeProjectWizard { 21 | private NewCMakeProjectStepAdapter adapter = new NewCMakeProjectStepAdapter(); 22 | 23 | public NewArduinoProjectWizard() { 24 | super("New Arduino Sketch Project", "NewArduinoSketchProject"); 25 | initWithStep(adapter); 26 | } 27 | 28 | @Override 29 | protected boolean tryFinish() { 30 | String projectRootPath = this.adapter.getLocation(); 31 | File projectRootDir = new File(projectRootPath); 32 | if (projectRootDir.exists()) { 33 | String[] fileList = projectRootDir.list(new FilenameFilter() { 34 | public boolean accept(File dir, String name) { 35 | return !".DS_Store".equalsIgnoreCase(name) && !"Thumbs.db".equalsIgnoreCase(name); 36 | } 37 | }); 38 | if (fileList != null && fileList.length > 0) { 39 | int dialogAnswer = Messages.showYesNoDialog(String 40 | .format("Directory \'%s\' already exists and not empty.\nWould you like to continue?", projectRootPath), "Project Directory Already Exists", Messages 41 | .getQuestionIcon()); 42 | if (dialogAnswer != 0) { 43 | return false; 44 | } 45 | } 46 | } else { 47 | try { 48 | VfsUtil.createDirectories(projectRootPath); 49 | } catch (RuntimeException e) { 50 | e.printStackTrace(); 51 | throw e; 52 | } catch (IOException e) { 53 | return false; 54 | } 55 | } 56 | 57 | String projectRootDirParentPath = projectRootDir.getParent(); 58 | if (projectRootDirParentPath != null) { 59 | RecentProjectsManager.getInstance().setLastProjectCreationLocation(projectRootDirParentPath); 60 | } 61 | 62 | try { 63 | createProject(this.adapter.getName(), projectRootPath); 64 | return true; 65 | } catch (IOException e) { 66 | CPPLog.LOG.warn(e); 67 | return false; 68 | } 69 | } 70 | 71 | public static String createProject(String projectName, String projectRootPath) throws IOException { 72 | File projectRoot = new File(projectRootPath); 73 | File cMakeLists = new File(projectRoot, "CMakeLists.txt"); 74 | if (!cMakeLists.exists() && !cMakeLists.createNewFile()) { 75 | throw new IOException("Cannot create file " + cMakeLists); 76 | } else { 77 | projectName = FileUtil.sanitizeFileName(projectName); 78 | File mainSketchFile = new File(projectRoot, projectName + ".ino"); 79 | if (!mainSketchFile.exists() && !mainSketchFile.createNewFile()) { 80 | throw new IOException("Cannot create file " + mainSketchFile); 81 | } else { 82 | FileUtil.writeToFile(mainSketchFile, Strings.DEFAULT_ARDUINO_SKETCH_CONTENTS); 83 | 84 | VirtualFile cMakeListsVirtualFile = VfsUtil.findFileByIoFile(cMakeLists, true); 85 | CMakeListsEditor cMakeListsEditor = CMakeListsEditor.getInstance(cMakeListsVirtualFile); 86 | cMakeListsEditor.clear(); 87 | cMakeListsEditor.minVersion("2.8.4"); 88 | cMakeListsEditor.set("CMAKE_TOOLCHAIN_FILE", "${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake"); 89 | cMakeListsEditor.set("PROJECT_NAME", projectName); 90 | cMakeListsEditor.project("${PROJECT_NAME}"); 91 | cMakeListsEditor.blankLine(); 92 | cMakeListsEditor.set("${CMAKE_PROJECT_NAME}_SKETCH", projectName + ".ino"); 93 | cMakeListsEditor.method("generate_arduino_firmware", "${CMAKE_PROJECT_NAME}"); 94 | 95 | ArduinoToolchainFiles.copyToDirectory(VfsUtil.findFileByIoFile(projectRoot, true)); 96 | 97 | return projectName; 98 | } 99 | } 100 | } 101 | 102 | @Override 103 | protected void doRunWizard() { 104 | VirtualFile projectRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(this.adapter.getLocation()); 105 | if (projectRoot == null) { 106 | return; 107 | } 108 | refreshProjectDir(projectRoot); 109 | final VirtualFile cMakeLists = projectRoot.findChild("CMakeLists.txt"); 110 | if (cMakeLists == null) { 111 | return; 112 | } 113 | final VirtualFile mainSketchFile = projectRoot.findChild(this.adapter.getName() + ".ino"); 114 | if (mainSketchFile == null) { 115 | return; 116 | } 117 | final Project project = CMakeWorkspace.openProject(cMakeLists, null, false); 118 | if (project == null) { 119 | return; 120 | } 121 | deleteBuildOutputDir(project); 122 | (new OpenFileDescriptor(project, cMakeLists)).navigate(false); 123 | (new OpenFileDescriptor(project, mainSketchFile)).navigate(true); 124 | } 125 | 126 | private void deleteBuildOutputDir(Project project) { 127 | FileUtil.delete(CMakeWorkspace.getInstance(project).getProjectGeneratedDir()); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 3 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 37 | ]> 38 | 39 | io.github.francoiscambell.clionarduinoplugin 40 | Arduino 41 | 1.2.2 42 | Francois Campbell 43 | 44 | CLion Arduino Plugin 46 |
47 | 48 | GitHub | 49 | Issues 50 |
51 |
52 | This is a plugin that integrates Arduino CMake into the IDE. 53 |
54 |
55 | The current features are to create an Arduino CMake project in one click, and to create new sketch files. 56 |
57 |
58 | Future features are to add menu option to easily change the board type, port number, import existing Arduino projects, etc. 59 | ]]>
60 | 61 | 1.2.2 63 |
    64 |
  • Fixed .ino and .pde files not refactorable. Increased compatibility for Servo library
  • 65 |
66 | 1.2.1 67 |
    68 |
  • Re-compiled for Java 6
  • 69 |
70 | 1.2.0 71 |
    72 |
  • Added new project creation to Welcome Screen and File menu
  • 73 |
74 | 1.1.0 75 |
    76 |
  • Compatiblity with Arduino SDK 1.6 on Mac OS X
  • 77 |
78 | 1.0.2 79 |
    80 |
  • Removed Groovy runtime, no longer necessary
  • 81 |
82 | 1.0.1 83 |
    84 |
  • Fixed organization
  • 85 |
86 | 1.0 87 |
    88 |
  • Convert a project to Arduino CMake. This replaces CMakeLists.txt with a default one, deletes the default 89 | main.cpp file, copies in the Arduino CMake toolchain files, and deletes the build direcory to start 90 | fresh 91 |
  • 92 |
  • Associates .ino and .pde files as C++ source, so you get syntax highlighting and prediction, etc.
  • 93 |
  • Create a new sketch file in any directory. If you omit the extension, it will add .ino automatically 94 |
  • 95 |
  • Adds import for Arduino.h to all newly created sketch files to enable code completion
  • 96 |
  • Compiled with Java 6 for compatibility with OS X out of the box
  • 97 |
98 | ]]> 99 |
100 | 101 | 102 | 103 | 104 | 106 | com.intellij.modules.clion 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | io.github.francoiscambell.clionarduinoplugin.components.ArduinoFileTypeRegistration 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 133 | 134 | 135 | 139 | 140 | 141 | 142 | 143 | 144 |
--------------------------------------------------------------------------------