From a0d2cd7490193d0b2c829321d1ac940e5b20c73a Mon Sep 17 00:00:00 2001 From: oyvang Date: Thu, 28 May 2015 14:12:47 +0200 Subject: [PATCH] added snippets and forgie's createproject plugin --- Projects/newtestProject/CMakeLists.txt | 11 ++++++ juci/plugins/createproject.py | 47 ++++++++++++++++++++++++ juci/plugins/snippet.py | 50 +++++++++++++++++++++++++- juci/terminal.cc | 9 ++--- 4 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 Projects/newtestProject/CMakeLists.txt create mode 100644 juci/plugins/createproject.py diff --git a/Projects/newtestProject/CMakeLists.txt b/Projects/newtestProject/CMakeLists.txt new file mode 100644 index 0000000..bef2faf --- /dev/null +++ b/Projects/newtestProject/CMakeLists.txt @@ -0,0 +1,11 @@ + cmake_minimum_required (VERSION 2.8.4) + set(project_name newtestproject) + project (${project_name}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + + INCLUDE(FindPkgConfig) + + add_executable(main + main.cpp + ) + \ No newline at end of file diff --git a/juci/plugins/createproject.py b/juci/plugins/createproject.py new file mode 100644 index 0000000..6fdc199 --- /dev/null +++ b/juci/plugins/createproject.py @@ -0,0 +1,47 @@ +#!/usr/bin/python +#snippet plugin +import juci_to_python_api as juci, inspect +import sys, os + +def initPlugin(): + juci.addMenuElement("CreateProject") + juci.addSubMenuElement("CreateProjectMenu", #name of parent menu + "Create new project", #menu description + "newProject()", #function to execute + inspect.getfile(inspect.currentframe()), #plugin path + "p") + +def newProject(): + path='../Projects/newtestProject/' + if not os.path.exists(path): + os.makedirs(path) + cmake=path+'CMakeLists.txt' + main=path+'main.cpp' + + + + cmakefile = open(cmake, 'w') + + cmakefile.write("""\ + cmake_minimum_required (VERSION 2.8.4) + set(project_name newtestproject) + project (${project_name}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + + INCLUDE(FindPkgConfig) + + add_executable(main + main.cpp + ) + """) + + mainfile = open(main, 'w') + + mainfile.write("""\ + #include + + int main(int argc, char *argv[]) { + std::cout << "Hello, world!" << std::endl; + } + """) + diff --git a/juci/plugins/snippet.py b/juci/plugins/snippet.py index 5f77be6..9355cf9 100644 --- a/juci/plugins/snippet.py +++ b/juci/plugins/snippet.py @@ -48,10 +48,58 @@ snippets["hello"] = """\ #include int main(int argc, char *argv[]) { - std::cout << "Hello, world! << std::endl; + std::cout << "Hello, world!" << std::endl; } """ +snippets["fore"] = """\ +for (auto i : v) { + //std::cout << i << std::endl; +} +""" + +snippets["funca"] = """\ +auto functionName(arg) { + // Write code here + return n; +} +""" + +snippets["lambdaa"] = """\ +auto lambda = []() { + //code here + }; +""" + +snippets["jucifor"] = """\ +#include +#include + + +int main(int argc, char *argv[]) { + //Example under from this line to +4 + std::vector v = {"Hello!", "This is juCi++"}; + for (auto& i : v) { + std::cout << i << std::endl; + } +return 0; +} +""" +snippets["switch"] = """\ +switch (arg) { + case 1: //some code + //recommended to use break or return on only one possible outcome + default: //some code +} +""" +snippets["cout"] = """\ +std::cout << "example"; +""" +snippets["coute"] = """\ +std::cout << "example" << std::endl; +""" + + def getSnippet(word): try: output = snippets[word] diff --git a/juci/terminal.cc b/juci/terminal.cc index 00c7004..69749bb 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -85,14 +85,11 @@ void Terminal::Controller::ExecuteCommand(std::string command, std::string mode) command = folder_command_+command; DEBUG("Terminal: PrintMessage: Running command"); FILE* p = NULL; - std::cout << command << std::endl; - p = popen(command.c_str(), mode.c_str()); - std::cout << "KJØRTE FINT!" << std::endl; - if (p == NULL) { + p = popen(command.c_str(), mode.c_str()); + if (p == NULL) { PrintMessage("juCi++ ERROR: Failed to run command" + command + "\n"); }else { - std::cout << "SKRIVER UT KOMMANDO RESULAT" << std::endl; - char buffer[1028]; + char buffer[1028]; while (fgets(buffer, 1028, p) != NULL) { PrintMessage(buffer); }