Browse Source

Merge pull request #209 from cppit/remove_old_files

Remove old files
merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
77023ac5cb
  1. 1
      .gitignore
  2. 5
      README.md
  3. 19
      docs/api.md
  4. 67
      plugins/snippet.py
  5. 12
      src/CMakeLists.txt
  6. 2384
      src/Doxyfile.in
  7. 213
      src/api.cc
  8. 72
      src/api.h
  9. 15
      src/api_ext.cc
  10. 9
      src/cmake/Modules/FindPlantuml.cmake
  11. 5
      src/config.cc
  12. 78
      src/files.h
  13. 27
      src/juci.h

1
.gitignore vendored

@ -3,7 +3,6 @@
!*/
#Whitelist
!*.cc
!*.h

5
README.md

@ -49,4 +49,7 @@ See [enhancements](https://github.com/cppit/jucipp/labels/enhancement) for plann
* [tiny-process-library](http://github.com/eidheim/tiny-process-library/) (downloaded directly with git --recursive, no need to install)
## Installation
See [installation guide](http://github.com/cppit/jucipp/blob/master/docs/install.md).
See [installation guide](docs/install.md).
## Documentation
See [how to build the API doc](docs/api.md).

19
docs/api.md

@ -0,0 +1,19 @@
# juCi++ API doc
## Prerequisites:
* doxygen
* plantuml
* install via apt-get or download from http://plantuml.com/
* see also http://plantuml.com/starting.html
* if downloaded either copy the jar file to /usr/bin or set the environment variable PLANTUML_PATH to point to the path containing the jar file)
## How to build the API doc:
```sh
mkdir jucipp/build
cd jucipp/build
cmake ..
make doc
```
## Where is the generated API documentation
Open jupicpp/build/src/html/index.html

67
plugins/snippet.py

@ -1,67 +0,0 @@
#!/usr/bin/python
#snippet plugin
import juci_to_python_api as juci, inspect
def initPlugin():
juci.addMenuElement("Snippet")
juci.addSubMenuElement("SnippetMenu", #name of parent menu
"Insert snippet", #menu description
"insertSnippet()", #function to execute
inspect.getfile(inspect.currentframe()), #plugin path
"<control><alt>space")
snippets = {}
snippets["for"] = """\
for(int i=0; i<v.size(); i++) {
// std::cout << v[i] << std::endl;
// Write code here
}
"""
snippets["if"] = """\
if(true) {
// Write code here
}
"""
snippets["ifelse"] = """\
if(false) {
// Write code here
} else {
// Write code here
}
"""
snippets["while"] = """\
while(condition) {
// Write code here
}
"""
snippets["main"] = """\
int main(int argc, char *argv[]) {
//Do something
}
"""
snippets["hello"] = """\
#include <iostream>
int main(int argc, char *argv[]) {
std::cout << "Hello, world! << std::endl;
}
"""
def getSnippet(word):
try:
output = snippets[word]
except KeyError:
output = word
return output
def insertSnippet():
theWord=juci.getWord()
output=getSnippet(theWord)
juci.replaceWord(output)

12
src/CMakeLists.txt

@ -141,3 +141,15 @@ target_link_libraries(${project_name} ${global_libraries})
install(TARGETS ${project_name}
RUNTIME DESTINATION bin
)
# add a target to generate API documentation with Doxygen
find_package(Plantuml)
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen to ${CMAKE_CURRENT_BINARY_DIR}" VERBATIM
)
endif(DOXYGEN_FOUND)

2384
src/Doxyfile.in

File diff suppressed because it is too large Load Diff

213
src/api.cc

@ -1,213 +0,0 @@
#include "api.h"
#include "logging.h"
#include "singletons.h"
Menu* PluginApi::menu=nullptr;
Notebook* PluginApi::notebook=nullptr;
/////////////////////////////
//// API ServiceProvider ////
/////////////////////////////
PluginApi::PluginApi(Notebook* notebook, Menu* menu) {
DEBUG("Adding pointers for the API");
this->notebook = notebook;
this->menu = menu;
DEBUG("Initiating plugins(from plugins.py)..");
#ifndef __APPLE__
//InitPlugins(); //TODO: fix this
#endif
DEBUG("Plugins initiated..");
}
void PluginApi::ReplaceWord(std::string word) {
Glib::RefPtr<Gtk::TextBuffer> buffer = libjuci::BufferFromNotebook();
Gtk::TextIter word_start = libjuci::IterFromNotebook();
Gtk::TextIter word_end = libjuci::IterFromNotebook();
libjuci::IterToWordStart(word_start);
libjuci::IterToWordEnd(word_end);
if (word_start != word_end) {
buffer->erase(word_start, word_end);
Gtk::TextIter current = libjuci::IterFromNotebook();
buffer->insert(current, word);
}
}
void PluginApi::ReplaceLine(std::string line) {
WARNING("use of unimplemented method");
}
std::string PluginApi::GetWord() {
Glib::RefPtr<Gtk::TextBuffer> buffer = libjuci::BufferFromNotebook();
Gtk::TextIter word_start = libjuci::IterFromNotebook();
Gtk::TextIter word_end = libjuci::IterFromNotebook();
libjuci::IterToWordStart(word_start);
libjuci::IterToWordEnd(word_end);
if (word_start < word_end) {
std::string word = buffer->get_text(word_start, word_end);
return word;
}
return "";
}
void PluginApi::InitPlugins() {
libjuci::LoadPlugin(Singleton::config_dir() + "plugins.py");
}
void PluginApi::AddMenuElement(std::string plugin_name) {
DEBUG("Adding menu element for "+plugin_name);
AddMenuXml(plugin_name, "PluginMenu");
std::string plugin_action_name = plugin_name+"Menu";
menu->action_group->add(Gtk::Action::create(plugin_action_name, plugin_name));
}
void PluginApi::AddSubMenuElement(std::string parent_menu,
std::string menu_name,
std::string menu_func_name,
std::string plugin_path,
std::string menu_keybinding) {
AddSubMenuXml(menu_func_name, parent_menu);
menu->action_group->add(Gtk::Action::create(menu_func_name,
menu_name),
Gtk::AccelKey(menu_keybinding),
[=]() {
libjuci::LoadPluginFunction(menu_func_name, plugin_path);
});
}
void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) {
std::string temp_menu = menu->ui;
std::size_t plugin_menu_pos = temp_menu.find(parent_menu);
// +2 gets you outside of the tag:<'menu_name'>
plugin_menu_pos+=parent_menu.size() +2;
std::string menu_prefix = temp_menu.substr(0, plugin_menu_pos);
std::string menu_suffix = temp_menu.substr(plugin_menu_pos);
std::string menu_input =
" <menu action='"+plugin_name+"Menu'> "
" </menu> ";
menu->ui = menu_prefix + menu_input + menu_suffix;
}
void PluginApi::AddSubMenuXml(std::string plugin_name,
std::string parent_menu) {
std::string temp_menu = menu->ui;
std::size_t parent_menu_pos = temp_menu.find(parent_menu);
// +2 gets you outside of the tag:<'menu_name'>
parent_menu_pos+=parent_menu.size() +2;
std::string menu_prefix = temp_menu.substr(0, parent_menu_pos);
std::string menu_suffix = temp_menu.substr(parent_menu_pos);
std::string menu_input ="<menuitem action='"+plugin_name+"'/>";
menu->ui = menu_prefix + menu_input + menu_suffix;
}
///////////////////////
//// Api to python ////
///////////////////////
void libjuci::ReplaceWord(const std::string word) {
PluginApi::ReplaceWord(word);
}
void libjuci::ReplaceLine(const std::string line) {
std::cout << "unimplemented: " << __func__ << " called"
<< std::endl;
}
std::string libjuci::GetWord() {
return PluginApi::GetWord();
}
void libjuci::AddMenuElement(std::string plugin_name) {
PluginApi::AddMenuElement(plugin_name);
}
void libjuci::AddSubMenuElement(std::string parent_menu,
std::string menu_name,
std::string menu_func_name,
std::string plugin_path,
std::string menu_keybinding) {
PluginApi::AddSubMenuElement(parent_menu,
menu_name,
menu_func_name,
plugin_path,
menu_keybinding);
}
//////////////////////////////
//// Boost.Python methods ////
//////////////////////////////
namespace bp = boost::python;
bp::api::object libjuci::OpenPythonScript(const std::string path,
bp::api::object python_name_space) {
bp::str str_path(path);
return bp::exec_file(str_path, python_name_space);
}
void libjuci::LoadPlugin(const std::string& plugin_name) {
try {
Py_Initialize();
bp::api::object main_module = bp::import("__main__");
bp::api::object main_namespace =
main_module.attr("__dict__");
bp::api::object ignored2 =
OpenPythonScript(plugin_name, main_namespace);
}catch (bp::error_already_set const&) {
PyErr_Print();
}
}
void libjuci::LoadPluginFunction(const std::string &function_name,
const std::string &plugin_path) {
try {
Py_Initialize();
bp::api::object main_module = bp::import("__main__");
bp::api::object main_namespace = main_module.attr("__dict__");
bp::api::object ignored2 = OpenPythonScript(plugin_path, main_namespace);
bp::str func_name(function_name);
bp::api::object returnValue = bp::eval(func_name, main_namespace);
}catch (bp::error_already_set const&) {
PyErr_Print();
}
}
void libjuci::InitPlugin(const std::string& plugin_path) {
try {
Py_Initialize();
bp::api::object main_module = bp::import("__main__");
bp::api::object main_namespace = main_module.attr("__dict__");
bp::api::object ignored2 = OpenPythonScript(plugin_path, main_namespace);
bp::object returnValue = bp::eval("initPlugin()", main_namespace);
// do something with return_value
}catch (bp::error_already_set const&) {
PyErr_Print();
}
}
///////////////////////
//// Glib wrappers ////
///////////////////////
void libjuci::IterToWordStart(Gtk::TextIter &iter) {
if (!iter.starts_line()) {
while (!iter.starts_word()) {
iter.backward_char();
}
}
}
void libjuci::IterToWordEnd(Gtk::TextIter &iter) {
if (!iter.ends_line()) {
while (!iter.ends_word()) {
iter.forward_char();
}
}
}
Glib::RefPtr<Gtk::TextBuffer> libjuci::BufferFromNotebook() {
return Glib::RefPtr<Gtk::TextBuffer>(PluginApi::notebook->get_current_view()->get_buffer());
}
Gtk::TextIter libjuci::IterFromNotebook() {
return libjuci::BufferFromNotebook()->get_insert()->get_iter();
}

72
src/api.h

@ -1,72 +0,0 @@
#ifndef JUCI_API_H_
#define JUCI_API_H_
#include <boost/python.hpp>
#include <Python.h>
#include <string>
#include "notebook.h"
#include "menu.h"
////////////////////
//// Plugin Api ////
////////////////////
class PluginApi {
public:
PluginApi(Notebook* notebook, Menu* menu);
static Menu* menu;
static Notebook* notebook;
static void InitPlugins();
// for Python module:
static std::string GetWord();
// menu management
static void AddMenuElement(const std::string plugin_name);
static void AddSubMenuElement(const std::string parent_menu,
const std::string menu_name,
const std::string menu_func_name,
const std::string plugin_path,
const std::string menu_keybinding);
static void ReplaceWord(const std::string word);
static void ReplaceLine(const std::string line);
protected:
static void AddMenuXml(std::string plugin_name, std::string parent_menu);
static void AddSubMenuXml(std::string plugin_name, std::string parent_menu);
}; // PluginApi
namespace libjuci {
///////////////////////
//// Glib wrappers ////
///////////////////////
void IterToWordStart(Gtk::TextIter &iter);
void IterToWordEnd(Gtk::TextIter &iter);
Gtk::TextIter IterFromNotebook();
Glib::RefPtr<Gtk::TextBuffer> BufferFromNotebook();
///////////////////////
//// Api to python ////
///////////////////////
void ReplaceWord(const std::string word);
void ReplaceLine(const std::string line);
std::string GetWord();
void AddMenuElement(const std::string plugin_name);
void AddSubMenuElement(const std::string parent_menu,
const std::string menu_name,
const std::string menu_func_name,
const std::string plugin_path,
const std::string menu_keybinding);
void AddMenuXml(const std::string plugin_name,
const std::string parent_menu);
void AddSubMenuXml(const std::string plugin_name,
const std::string parent_menu);
//////////////////////////////
//// Boost.Python methods ////
//////////////////////////////
namespace bp = boost::python;
bp::api::object OpenPythonScript(const std::string path,
bp::api::object python_name_space);
void LoadPlugin(const std::string& plugin_name);
void LoadPluginFunction(const std::string &function_name,
const std::string &plugin_path);
void InitPlugin(const std::string& plugin_path);
} // namespace libjuci
#endif // JUCI_API_H_

15
src/api_ext.cc

@ -1,15 +0,0 @@
#include "api.h"
BOOST_PYTHON_MODULE(juci_to_python_api) {
using namespace boost::python;
// plugin inclusion
def("addMenuElement", &libjuci::AddMenuElement);
def("addSubMenuElement", &libjuci::AddSubMenuElement);
def("loadPlugin", &libjuci::LoadPlugin);
def("initPlugin", &libjuci::InitPlugin);
// text editing
def("replaceLine", &libjuci::ReplaceLine);
def("replaceWord", &libjuci::ReplaceWord);
def("getWord", &libjuci::GetWord);
} // module::juci_to_python_api

9
src/cmake/Modules/FindPlantuml.cmake

@ -0,0 +1,9 @@
if(NOT DEFINED plantuml_FOUND)
find_file(PLANTUML_JARFILE
NAMES plantuml.jar
HINTS "$ENV{PLANTUML_PATH}" ENV PLANTUML_DIR
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
plantuml DEFAULT_MSG PLANTUML_JARFILE)
endif()

5
src/config.cc

@ -59,14 +59,11 @@ void Config::load() {
void Config::find_or_create_config_files() {
auto config_dir = home/"config";
auto config_json = config_dir/"config.json";
auto plugins_py = config_dir/"plugins.py";
boost::filesystem::create_directories(config_dir); // io exp captured by calling method
if (!boost::filesystem::exists(config_json))
filesystem::write(config_json, configjson); // vars configjson and pluginspy
if (!boost::filesystem::exists(plugins_py)) // live in files.h
filesystem::write(plugins_py, pluginspy);
filesystem::write(config_json, configjson);
auto juci_style_path = home/"styles";
boost::filesystem::create_directories(juci_style_path); // io exp captured by calling method

78
src/files.h

@ -326,82 +326,4 @@ const std::string juci_dark_blue_style =
"\n"
"</style-scheme>\n";
const std::string pluginspy =
"#!/usr/bin/python \n"
"import juci_to_python_api as juci \n"
"import glob \n"
"\n"
"def loadplugins(): \n"
" plugin_files = glob.glob(\"../plugins/*.py\") \n"
" for current_file in plugin_files: \n"
" juci.initPlugin(current_file) \n"
"loadplugins() \n";
const std::string snippetpy =
"#!/usr/bin/python \n"
"#snippet plugin \n"
"import juci_to_python_api as juci, inspect \n"
" \n"
"def initPlugin(): \n"
" juci.addMenuElement(\"Snippet\") \n"
" juci.addSubMenuElement(\"SnippetMenu\", #name of parent menu \n"
" \"Insert snippet\", #menu description \n"
" \"insertSnippet()\", #function to execute \n"
" inspect.getfile(inspect.currentframe()), #plugin path \n"
" \"<control><alt>space\") \n"
"snippets = {} \n"
" \n"
"snippets[\"for\"] = \"\"\"\\\n"
"for(int i=0; i<v.size(); i++) { \n"
" // std::cout << v[i] << std::endl; \n"
" // Write code here \n"
"} \n"
"\"\"\" \n"
" \n"
"snippets[\"if\"] = \"\"\"\\\n"
"if(true) { \n"
" // Write code here \n"
"} \n"
"\"\"\" \n"
" \n"
"snippets[\"ifelse\"] = \"\"\"\\\n"
"if(false) { \n"
" // Write code here \n"
"} else { \n"
" // Write code here \n"
"} \n"
"\"\"\" \n"
" \n"
"snippets[\"while\"] = \"\"\"\\\n"
"while(condition) { \n"
" // Write code here \n"
"} \n"
"\"\"\" \n"
" \n"
"snippets[\"main\"] = \"\"\"\\\n"
"int main(int argc, char *argv[]) { \n"
" //Do something \n"
"} \n"
"\"\"\" \n"
" \n"
"snippets[\"hello\"] = \"\"\"\\\n"
"#include <iostream> \n"
" \n"
"int main(int argc, char *argv[]) { \n"
" std::cout << \"Hello, world! << std::endl; \n"
"} \n"
"\"\"\" \n"
" \n"
"def getSnippet(word): \n"
" try: \n"
" output = snippets[word] \n"
" except KeyError: \n"
" output = word \n"
" return output \n"
" \n"
"def insertSnippet(): \n"
" theWord=juci.getWord() \n"
" output=getSnippet(theWord) \n"
" juci.replaceWord(output) \n";
#endif // JUCI_FILES_H_

27
src/juci.h

@ -1,3 +1,30 @@
/**
\mainpage
juCi++ is a lightweight C++ IDE written in C++
(<a href="https://github.com/cppit/jucipp">Github page</a>).
\section sec_overview Overview
The application entry point is the class Application.
\section sec_dependencies Dependencies
juCi++ is based on boost, gtkmm and libclang (among others).
\startuml
left to right direction
component [juCi++] #LightGreen
component [libclangmm] #Cyan
component [tiny-process-library] #Cyan
[juCi++] --> [boost-filesystem] : use
[juCi++] --> [boost-regex] : use
[juCi++] --> [gtkmm-3.0] : use
[juCi++] --> [gtksourceviewmm-3.0] : use
[juCi++] --> [aspell] : use
[juCi++] --> [lbclang] : use
[juCi++] --> [lbdb] : use
[juCi++] --> [libclangmm] : use
[juCi++] --> [tiny-process-library] : use
\enduml
*/
#ifndef JUCI_JUCI_H_
#define JUCI_JUCI_H_

Loading…
Cancel
Save