Browse Source

Resolved conficts.

merge-requests/365/head
eidheim 11 years ago
parent
commit
dda05737f2
  1. 13
      CMakeLists.txt
  2. 53
      README.md
  3. 22
      docs/install.md
  4. 164
      juci/CMakeLists.txt
  5. 89
      juci/config.json
  6. 40
      juci/menu.xml
  7. 13
      juci/plugins.py
  8. 92
      juci/sourcefile.cc
  9. 21
      juci/sourcefile.h
  10. 0
      plugins/snippet.py
  11. 123
      src/CMakeLists.txt
  12. 8
      src/api.cc
  13. 1
      src/api.h
  14. 0
      src/api_ext.cc
  15. 0
      src/cmake/Modules/FindLibClang.cmake
  16. 9
      src/cmake/Modules/FindLibClangmm.cmake
  17. 44
      src/config.cc
  18. 5
      src/config.h
  19. 9
      src/directories.cc
  20. 0
      src/directories.h
  21. 0
      src/entrybox.cc
  22. 0
      src/entrybox.h
  23. 225
      src/files.h
  24. 2
      src/juci.cc
  25. 0
      src/juci.h
  26. 0
      src/logging.h
  27. 3
      src/menu.cc
  28. 0
      src/menu.h
  29. 8
      src/notebook.cc
  30. 0
      src/notebook.h
  31. 0
      src/selectiondialog.cc
  32. 0
      src/selectiondialog.h
  33. 0
      src/singletons.cc
  34. 4
      src/singletons.h
  35. 6
      src/source.cc
  36. 0
      src/source.h
  37. 32
      src/sourcefile.cc
  38. 20
      src/sourcefile.h
  39. 0
      src/terminal.cc
  40. 0
      src/terminal.h
  41. 0
      src/tooltips.cc
  42. 0
      src/tooltips.h
  43. 50
      src/window.cc
  44. 0
      src/window.h

13
CMakeLists.txt

@ -0,0 +1,13 @@
cmake_minimum_required (VERSION 2.8.4)
set(project_name juci)
set(module juci_to_python_api)
#### TODO WINDOWS SUPPORT ####
set(bin_install_path "/usr/local/bin")
set(lib_install_path "/usr/local/lib/python2.7/dist-packages/")
#####
project (${project_name})
add_subdirectory("src")

53
README.md

@ -1,45 +1,42 @@
# juCi++
###### a lightweight C++-IDE with support for C++11 and C++14.
## About
juCi++ is a lightweight C++-IDE written in C++. You can write plugins
in Python and configure the IDE from the config.json file.
## Autocompletion
The IDE supports autocompletion on accessor specifiers such as dot and arrow. The autocompletion has excellent support for C++11/14.
## Syntax Highlighting
The IDE also supports syntax highligthing even in C++11 and C++14.
## To get C++11 and C++14 support
If you want support for external libraries and C++11 and C++14 you need to make sure you add a parameter to the cmake command. This will make compile_commands.json wich tells juCi++ all the paramters for the compiler. There is a bug where juCi++ sometimes puts the compile_commands.json file in the incorrect folder. Please make sure this file exists and that the contents of it covers all your files.
```sh
$ cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
```
## Plugins
There are expansion oppertunities with usage of python plugins.
## Configuration
Configuration description will arrive shortly after source code is added.
A lot of IDEs struggle with good C++11/14 support. Therefore we
created juCi++. juCi++ is based of the compiler and will *always*
support new versions of C++.
## Features
* Syntax highlighing (even C++11/14)
* Superfast autocomletion (even external libraries)
* Accurate refactoring across files
* Basic editor functionallity
* Highlighting of similar types
* write your own plugins in python (limited atm)
## Dependencies ##
Please install these dependencies on your system.
* libclang
* libboost-python-dev
* libboost-filesystem-dev
* libboost-log-dev
* libboost-test-dev
* libboost-thread-dev
* libboost-system-dev
* libgtkmm-3.0-dev
* libgtksourceview2.0-dev
* libgtksourceviewmm-3.0-dev
* libpython-dev
* libclang-dev
* [libclangmm](http://github.com/cppit/libclangmm/)
* cmake
* make
* clang or gcc (compiler)
## Installation ##
Quickstart:
```sh
$ cmake .
$ make
$ sudo make install
```
See [installation guide](http://github.com/cppit/jucipp/blob/master/docs/install.md) for more details.
## Run
```sh
$ ./bin/juci
```

22
docs/install.md

@ -0,0 +1,22 @@
# juCi++
## Installation guide ##
Before installation, please install libclangmm see [installation guide](http://github.com/cppit/libclangmm/blob/master/docs/install.md) for installation.
## Debian
First dependencies:
```sh
$ sudo apt-get install libboost-python-dev libboost-filesystem-dev libboost-log-dev libboost-test-dev
libboost-thread-dev libboost-system-dev libgtkmm-3.0-dev libgtksourceview2.0-dev libgtksourceviewmm-3.0-dev
libpython-dev libclang-dev make cmake gcc
```
Install the project:
```sh
$ git clone http://github.com/cppit/jucipp.git juci
$ cd juci
$ cmake .
$ make
$ sudo make install
```
## Run
```sh
$ juci
```

164
juci/CMakeLists.txt

@ -1,164 +0,0 @@
cmake_minimum_required (VERSION 2.8.4)
set(project_name juci)
set(module juci_to_python_api)
project (${project_name})
add_definitions(-DBOOST_LOG_DYN_LINK)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -pthread -Wall -Wno-reorder")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/")
#You are of course using Homebrew:
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L/usr/local/opt/gettext/lib -I/usr/local/opt/gettext/include -undefined dynamic_lookup") #TODO: fix this
set(CMAKE_MACOSX_RPATH 1)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig")
endif()
INCLUDE(FindPkgConfig)
message("Searcing for libclang")
#LIBCLANG_FOUND System has libclang.
#LIBCLANG_INCLUDE_DIRS The libclang include directories.
#LIBCLANG_LIBRARIES The libraries needed to use libclang.
#LIBCLANG_LIBRARY_DIR The path to the directory containing libclang.
#LIBCLANG_KNOWN_LLVM_VERSIONS Known LLVM release numbers.
find_package(LibClangmm)
find_package(LibClang)
if(${LCL_FOUND})
message("libclangmm libraries found. Continuing")
message("${LCL_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "The libclangmm libraries are required. Quitting.")
endif()
if(${LIBCLANG_FOUND})
message("libclangmm libraries found. Continuing")
message("${LIBCLANG_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "The libclangmm libraries are required. Quitting.")
endif()
#### Finding boost, the variables below is set #####
#PYTHONLIBS_FOUND - True if headers and requested libraries were found
#PYTHON_INCLUDE_DIRS - Boost include directories
#PYTHON_LIBRARIES - Boost component libraries to be linked
find_package(PythonLibs 2.7)
#If python is found
if(${PYTHONLIBS_FOUND})
message("Python libraries found. Continuing")
else()
message("Please install python libraries. The libraries where not found.")
message("Python include dirs: ${PYTHON_INCLUDE_DIRS}")
message("Python link dirs ${PYTHON_LIBRARIES}")
message(FATAL_ERROR "The python libraries are required. Quitting.")
endif()
#### Finding boost, the variables below is set #####
#Boost_FOUND - True if headers and requested libraries were found
#Boost_INCLUDE_DIRS - Boost include directories
#Boost_LIBRARY_DIRS - Link directories for Boost libraries
#Boost_LIBRARIES - Boost component libraries to be linked
find_package(Boost 1.55 COMPONENTS python thread log system filesystem REQUIRED)
#If boost is not found
if(${Boost_FOUND})
message("Boost libraries found. Continuing")
else()
message("Please install boost libraries. The libraries where not found.")
message("Boost library dirs: ${Boost_LIBRARY_DIRS}")
message("Boost include dirs: ${Boost_INCLUDE_DIRS}")
message("Boost link dirs ${Boost_LIBRARIES}")
message(FATAL_ERROR "The boost libraries are required. Quitting.")
endif()
#### Finding gtkmm, the variables below is set #####
#GTKMM_FOUND - True if headers and requested libraries were found
#GTKMM_INCLUDE_DIRS - GTKMM include directories
#GTKMM_LIBRARY_DIRS - Link directories for GTKMM libraries
#GTKMM_LIBRARIES - GTKMM libraries to be linked
pkg_check_modules(GTKMM gtkmm-3.0) # The name GTKMM is set here for the variables abouve
#If gtkmm is not found
if(${GTKMM_FOUND})
message("Gtkmm libraries found. Continuing")
else()
message("Please install gtkmm libraries. The libraries where not found.")
message("Gtkmm library dirs ${GTKMM_LIBRARY_DIRS}")
message("Gtkmm include dirs ${GTKMM_INCLUDE_DIRS}")
message("Gtkmm link dirs ${GTKMM_LIBRARIES}")
message(FATAL_ERROR "The gtkmm libraries are required. Quitting.")
endif()
pkg_check_modules(GTKSVMM gtksourceviewmm-3.0)
if(${GTKSVMM_FOUND})
message("Gtksourceviewmm libraries found. Continuing")
else()
message(FATAL_ERROR "The gtksourceviewmm libraries are required. Quitting.")
endif()
# name of the executable on Windows will be example.exe
add_executable(${project_name}
#list of every needed file to create the executable
juci.h
juci.cc
menu.h
menu.cc
source.h
source.cc
selectiondialog.h
selectiondialog.cc
config.h
config.cc
sourcefile.h
sourcefile.cc
window.cc
window.h
api.h
api.cc
notebook.cc
notebook.h
entrybox.h
entrybox.cc
directories.h
directories.cc
terminal.h
terminal.cc
tooltips.h
tooltips.cc
singletons.h
singletons.cc
)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
add_library(${module} SHARED
api
api_ext
)
# dependencies
include_directories(
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
${GTKMM_INCLUDE_DIRS}
${GTKSVMM_INCLUDE_DIRS}
${LCL_INCLUDE_DIRS}
${LIBCLANG_INCLUDE_DIRS}
)
link_directories(
${GTKMM_LIBRARY_DIRS}
${GTKSVMM_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS}
${PYTHON_INCLUDE_DIRS}
${LCL_LIBRARY_DIRS}
${LIBCLANG_LIBRARY_DIRS}
)
#module:
set_target_properties(${module} PROPERTIES PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib/")
target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
#executable:
target_link_libraries(${project_name} ${LIVCLANG_LIBRARIES} ${LCL_LIBRARIES} ${GTKMM_LIBRARIES} ${GTKSVMM_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})

89
juci/config.json

@ -1,89 +0,0 @@
{
"source": {
"colors": {
"text_color": "black",
"string": "#CC0000",
"namespace_ref": "#990099",
"type": "#0066FF",
"keyword": "blue",
"comment": "grey",
"own": "pink",
"diagnostic_warning": "orange",
"diagnostic_error": "red"
},
"syntax": {
"43": "type",
"46": "namespace_ref",
"109": "string",
"702": "keyword",
"703": "own",
"705": "comment"
},
"visual": {
"background": "white",
"background_selected": "blue",
"background_tooltips": "yellow",
"font": "Monospace",
"show_line_numbers": 1,
"highlight_current_line": 1
},
"tab_size": 2,
"tab_char": "<space>"
},
"keybindings": {
"new_file": "<primary>n",
"open_folder": "<primary><alt>o",
"open_file": "<primary>o",
"save": "<primary>s",
"save_as": "<primary><shift>s",
"quit": "<primary>q",
"split_window": "<primary><alt>s",
"close_tab": "<primary>w",
"edit_copy": "<primary>c",
"edit_cut": "<primary>x",
"edit_paste": "<primary>v",
"edit_undo": "<primary>z",
"edit_redo": "<primary><shift>z",
"edit_find": "<primary>f",
"source_goto_declaration": "<primary>d",
"source_goto_method": "<primary>m",
"source_rename": "<primary>r",
"compile_and_run": "<primary>Return",
"compile": "<primary><shift>Return"
},
"directoryfilter": {
"ignore": [
"cmake",
"#",
"~",
".idea",
".so",
"in-lowercase.pls"
],
"exceptions": [
"cmakelists.txt",
"in-lowercase.pls"
]
},
"project": {
"run_commands": [
"./.build/"
],
"compile_commands": [
"rm -rf ./.build",
"mkdir ./.build",
"cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B./.build -H.",
"cd ./.build/; make",
"cp ./.build/compile_commands.json compile_commands.json"
]
},
"example": {
"key": "value",
"key2": [
"val1",
"val2",
3
],
"key3": "value"
}
}

40
juci/menu.xml

@ -1,40 +0,0 @@
<ui>
<menubar name='MenuBar'>
<menu action='FileMenu'>
<menuitem action='FileNewFile'/>
<menuitem action='FileOpenFile'/>
<menuitem action='FileOpenFolder'/>
<menuitem action='FileSave'/>
<menuitem action='FileSaveAs'/>
<separator/>
<menuitem action='FileQuit'/>
</menu>
<menu action='EditMenu'>
<menuitem action='EditCopy'/>
<menuitem action='EditCut'/>
<menuitem action='EditPaste'/>
<separator/>
<menuitem action='EditFind'/>
<menuitem action='EditUndo'/>
<menuitem action='EditRedo'/>
</menu>
<menu action='SourceMenu'>
<menuitem action='SourceGotoDeclaration'/>
<menuitem action='SourceGotoMethod'/>
<menuitem action='SourceRename'/>
</menu>
<menu action='ProjectMenu'>
<menuitem action='ProjectCompileAndRun'/>
<menuitem action='ProjectCompile'/>
</menu>
<menu action='WindowMenu'>
<menuitem action='WindowCloseTab'/>
<menuitem action='WindowSplitWindow'/>
</menu>
<menu action='PluginMenu'>
</menu>
<menu action='HelpMenu'>
<menuitem action='HelpAbout'/>
</menu>
</menubar>
</ui>

13
juci/plugins.py

@ -1,13 +0,0 @@
#!/usr/bin/python
#plugin handler
import sys, os, glob
cwd = os.getcwd()
sys.path.append(cwd+"/lib")
import juci_to_python_api as juci
def loadplugins():
plugin_files = glob.glob(cwd+"/plugins/*.py")
for current_file in plugin_files:
juci.initPlugin(current_file)
loadplugins()

92
juci/sourcefile.cc

@ -1,92 +0,0 @@
#include "sourcefile.h"
#include <giomm.h>
#include <string>
#include <iostream>
#include <vector>
using namespace std;
sourcefile::sourcefile(const string &input_filename)
: lines(), filename(input_filename) {
open(input_filename);
}
/**
*
*/
void sourcefile::open(const string &filename) {
Gio::init();
// Creates/Opens a file specified by the input string.
Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(filename);
if (!file) // Gio::File has overloaded operator
cerr << "Was not able to open file: " << filename << endl;
// Creates pointer for filestream
if (!file->query_exists()) {
file->create_file()->close();
}
Glib::RefPtr<Gio::FileInputStream> stream = file->read();
if (!stream) // error message on stream failure
cerr << filename << " returned an empty stream" << endl;
Glib::RefPtr<Gio::DataInputStream>
datainput = Gio::DataInputStream::create(stream);
string line;
while (datainput->read_line(line)) {
lines.push_back(line);
}
datainput->close();
stream->close();
}
vector<string> sourcefile::get_lines() {
return lines;
}
string sourcefile::get_line(int line_number) {
return lines[line_number];
}
int sourcefile::save(const string &text) {
Gio::init();
// Creates/Opens a file specified by the input string.
Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(filename);
if (!file) // Gio::File has overloaded operator
cerr << "Was not able to open file: " << filename << endl;
// Creates
Glib::RefPtr<Gio::FileOutputStream> stream =
file->query_exists() ? file->replace() : file->create_file();
if (!stream) // error message on stream failure
cerr << filename << " returned an empty stream" << endl;
Glib::RefPtr<Gio::DataOutputStream>
output = Gio::DataOutputStream::create(stream);
output->put_string(text);
output->close();
stream->close();
return 0;
}
string sourcefile::get_content() {
string res;
for (auto line : lines) {
res.append(line).append("\n");
}
return res;
}

21
juci/sourcefile.h

@ -1,21 +0,0 @@
#ifndef JUCI_SOURCEFILE_H_
#define JUCI_SOURCEFILE_H_
#include <string>
#include <vector>
class sourcefile {
public:
explicit sourcefile(const std::string &filename);
std::vector<std::string> get_lines();
std::string get_content();
std::string get_line(int line_number);
int save(const std::string &text);
private:
void open(const std::string &filename);
std::vector<std::string> lines;
std::string filename;
};
#endif // JUCI_SOURCEFILE_H_

0
juci/plugins/snippet.py → plugins/snippet.py

123
src/CMakeLists.txt

@ -0,0 +1,123 @@
add_definitions(-DBOOST_LOG_DYN_LINK)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -pthread -Wall -Wno-reorder")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/")
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L/usr/local/opt/gettext/lib -I/usr/local/opt/gettext/include -undefined dynamic_lookup") #T
set(CMAKE_MACOSX_RPATH 1)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig")
endif()
INCLUDE(FindPkgConfig)
set(validation true)
function(install_help APPLE UNIX WINDOWS)
message("Install package with:")
if(UNIX)
if(APPLE)
message("brew install ${APPLE}")
else()
message("sudo apt-get install ${UNIX}")
endif(APPLE)
endif(UNIX)
if(WINDOWS)
message("choco install ${WINDOWS}")
endif(WINDOWS)
endfunction(install_help)
function(validate FOUND APPLE UNIX WINDOWS)
if(!${FOUND})
set(validation false)
install_help(${APPLE} ${UNIX} ${WINDOWS})
endif()
endfunction(validate)
find_package(LibClangmm)
validate(${LCL_FOUND} "clangmm" "clangmm" "clangmm")
find_package(LibClang)
validate(${LIBCLANG_FOUND} "clang" "libclang-dev" "llvm")
find_package(PythonLibs 2.7)
validate(${PYTHONLIBS_FOUND} "python" "libpython-dev" "python")
find_package(Boost 1.55 COMPONENTS python thread log system filesystem REQUIRED)
validate(${Boost_FOUND} "boost" "libboost-all-dev" "boost")
pkg_check_modules(GTKMM gtkmm-3.0) # The name GTKMM is set here for the variables abouve
validate(${GTKMM_FOUND} "gtkmm" "libgtkmm-dev" "gtkmm")
pkg_check_modules(GTKSVMM gtksourceviewmm-3.0)
validate(${GTKSVMM_FOUND} "gtksvmm" "libgtksvmm-dev" "gtkmmsv")
if(${validation})
add_executable(${project_name}
juci.h
juci.cc
menu.h
menu.cc
source.h
source.cc
selectiondialog.h
selectiondialog.cc
config.h
config.cc
sourcefile.h
sourcefile.cc
window.cc
window.h
api.h
api.cc
notebook.cc
notebook.h
entrybox.h
entrybox.cc
directories.h
directories.cc
terminal.h
terminal.cc
tooltips.h
tooltips.cc
singletons.h
singletons.cc)
add_library(${module} SHARED
api
api_ext)
include_directories(
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
${GTKMM_INCLUDE_DIRS}
${GTKSVMM_INCLUDE_DIRS}
${LCL_INCLUDE_DIRS}
${LIBCLANG_INCLUDE_DIRS})
link_directories(
${GTKMM_LIBRARY_DIRS}
${GTKSVMM_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS}
${PYTHON_INCLUDE_DIRS}
${LCL_LIBRARY_DIRS}
${LIBCLANG_LIBRARY_DIRS})
set_target_properties(${module}
PROPERTIES PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib/")
target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
target_link_libraries(${project_name}
${LIBCLANG_LIBRARIES}
${LCL_LIBRARIES}
${GTKMM_LIBRARIES}
${GTKSVMM_LIBRARIES}
${Boost_LIBRARIES}
${PYTHON_LIBRARIES})
install(TARGETS ${project_name} ${module}
RUNTIME DESTINATION ${bin_install_path}
LIBRARY DESTINATION ${lib_install_path}
)
endif(${validation})

8
juci/api.cc → src/api.cc

@ -18,12 +18,6 @@ PluginApi::PluginApi(Notebook* notebook) {
DEBUG("Plugins initiated..");
}
std::string PluginApi::ProjectPath() {
int MAXPATHLEN = 50;
char temp[MAXPATHLEN];
return ( getcwd(temp, MAXPATHLEN) ? std::string( temp ) : std::string("") );
}
void PluginApi::ReplaceWord(std::string word) {
Glib::RefPtr<Gtk::TextBuffer> buffer = libjuci::BufferFromNotebook();
Gtk::TextIter word_start = libjuci::IterFromNotebook();
@ -57,7 +51,7 @@ std::string PluginApi::GetWord() {
}
void PluginApi::InitPlugins() {
libjuci::LoadPlugin(ProjectPath()+"/plugins.py");
libjuci::LoadPlugin(Singleton::config_dir() + "plugins.py");
}
void PluginApi::AddMenuElement(std::string plugin_name) {

1
juci/api.h → src/api.h

@ -16,7 +16,6 @@ public:
static Menu* menu_;
static Notebook* notebook;
static void InitPlugins();
static std::string ProjectPath();
// for Python module:
static std::string GetWord();
// menu management

0
juci/api_ext.cc → src/api_ext.cc

0
juci/cmake/Modules/FindLibClang.cmake → src/cmake/Modules/FindLibClang.cmake

9
juci/cmake/Modules/FindLibClangmm.cmake → src/cmake/Modules/FindLibClangmm.cmake

@ -1,20 +1,15 @@
# - Try to find LCL
# Once done this will define
# LCL_FOUND - Libclangmm is available
# LCL_INCLUDE_DIRS - The libclangmm include directories
# LCL_LIBRARIES -
# LCL_DEFINITIONS - Compiler switches required for using libclangmm
find_package(PkgConfig)
find_path(LCL_INCLUDE_DIR clangmm.h
HINTS "/usr/local/lib/libclangmm/include/"
HINTS "/usr/local/include/libclangmm/"
)
find_library(LCL_LIBRARY NAMES clangmm
HINTS "/usr/local/lib/libclangmm/"
HINTS "/usr/local/lib/"
)
set(LCL_LIBRARIES ${LCL_LIBRARY} )

44
juci/config.cc → src/config.cc

@ -1,24 +1,37 @@
#include "singletons.h"
#include "config.h"
#include "logging.h"
#include <fstream>
#include <string>
#include <exception>
#include "files.h"
#include "sourcefile.h"
MainConfig::MainConfig() {
INFO("Reading config file");
boost::property_tree::json_parser::read_json("config.json", cfg_);
INFO("Config file read");
find_or_create_config_files();
boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg);
GenerateSource();
GenerateKeybindings();
GenerateDirectoryFilter();
GenerateTerminalCommands();
}
void MainConfig::find_or_create_config_files() {
std::vector<std::string> files = {"config.json", "menu.xml", "plugins.py"};
boost::filesystem::create_directories(boost::filesystem::path(Singleton::config_dir()));
for (auto &file : files) {
auto path = boost::filesystem::path(Singleton::config_dir() + file);
if (!boost::filesystem::is_regular_file(path)) {
if (file == "config.json") juci::filesystem::save(path, configjson);
if (file == "plugins.py") juci::filesystem::save(path, pluginspy);
if (file == "menu.xml") juci::filesystem::save(path, menuxml);
}
}
}
void MainConfig::GenerateSource() {
auto source_cfg=Singleton::Config::source();
DEBUG("Fetching source cfg");
// boost::property_tree::ptree
auto source_json = cfg_.get_child("source");
auto source_json = cfg.get_child("source");
auto syntax_json = source_json.get_child("syntax");
auto colors_json = source_json.get_child("colors");
auto visual_json = source_json.get_child("visual");
@ -48,7 +61,7 @@ void MainConfig::GenerateSource() {
void MainConfig::GenerateTerminalCommands() {
auto terminal_cfg=Singleton::Config::terminal();
boost::property_tree::ptree source_json = cfg_.get_child("project");
boost::property_tree::ptree source_json = cfg.get_child("project");
boost::property_tree::ptree compile_commands_json = source_json.get_child("compile_commands");
boost::property_tree::ptree run_commands_json = source_json.get_child("run_commands");
for (auto &i : compile_commands_json)
@ -58,15 +71,14 @@ void MainConfig::GenerateTerminalCommands() {
}
void MainConfig::GenerateKeybindings() {
auto menu=Singleton::menu();
DEBUG("Fetching keybindings");
std::string line;
std::ifstream menu_xml("menu.xml");
if (menu_xml.is_open()) {
while (getline(menu_xml, line))
menu->ui+=line;
auto menu = Singleton::menu();
boost::filesystem::path path(Singleton::config_dir() + "menu.xml");
if (!boost::filesystem::is_regular_file(path)) {
std::cerr << "menu.xml not found" << std::endl;
throw;
}
boost::property_tree::ptree keys_json = cfg_.get_child("keybindings");
menu->ui = juci::filesystem::open(path);
boost::property_tree::ptree keys_json = cfg.get_child("keybindings");
for (auto &i : keys_json) {
auto key=i.second.get_value<std::string>();
menu->key_map[i.first] = key;
@ -77,7 +89,7 @@ void MainConfig::GenerateKeybindings() {
void MainConfig::GenerateDirectoryFilter() {
auto dir_cfg=Singleton::Config::directories();
DEBUG("Fetching directory filter");
boost::property_tree::ptree dir_json = cfg_.get_child("directoryfilter");
boost::property_tree::ptree dir_json = cfg.get_child("directoryfilter");
boost::property_tree::ptree ignore_json = dir_json.get_child("ignore");
boost::property_tree::ptree except_json = dir_json.get_child("exceptions");
for ( auto &i : except_json )

5
juci/config.h → src/config.h

@ -6,13 +6,14 @@
class MainConfig {
public:
MainConfig();
void find_or_create_config_files();
void PrintMenu();
void GenerateSource();
void GenerateKeybindings();
void GenerateDirectoryFilter();
void GenerateTerminalCommands();
private:
boost::property_tree::ptree cfg_;
boost::property_tree::ptree key_tree_;
boost::property_tree::ptree cfg;
boost::property_tree::ptree key_tree;
};
#endif

9
juci/directories.cc → src/directories.cc

@ -1,8 +1,8 @@
#include "directories.h"
#include "sourcefile.h"
#include "logging.h"
#include "singletons.h"
#include <algorithm>
#include <fstream>
#include "boost/algorithm/string.hpp"
namespace sigc {
@ -103,9 +103,7 @@ std::string Directories::get_cmakelists_variable(const boost::filesystem::path&
boost::filesystem::directory_iterator end_itr;
for (boost::filesystem::directory_iterator itr( dir_path );itr != end_itr;++itr ) {
if (itr->path().filename().string() == "CMakeLists.txt") {
std::ifstream ifs(itr->path().string());
std::string line;
while (std::getline(ifs, line)) {
for (auto &line : juci::filesystem::lines(itr->path())) {
if (line.find(command_name+"(", 0) != std::string::npos
|| line.find(command_name+" (", 0) != std::string::npos ) {
size_t variable_start = line.find("{", 0);
@ -140,8 +138,7 @@ std::string Directories::get_cmakelists_variable(const boost::filesystem::path&
}
}
}
std::ifstream ifs2(itr->path().string());
while (std::getline(ifs2, line)) {
for (auto &line : juci::filesystem::lines(itr->path())) {
if (line.find("set(", 0) != std::string::npos
|| line.find("set (", 0) != std::string::npos) {
if( line.find(project_name_var, 0) != std::string::npos) {

0
juci/directories.h → src/directories.h

0
juci/entrybox.cc → src/entrybox.cc

0
juci/entrybox.h → src/entrybox.h

225
src/files.h

@ -0,0 +1,225 @@
#include <string>
const std::string configjson =
"{\n"
" \"source\": {\n"
" \"colors\": {\n"
" \"text_color\": \"black\",\n"
" \"string\": \"#CC0000\",\n"
" \"namespace_ref\": \"#990099\",\n"
" \"type\": \"#0066FF\",\n"
" \"keyword\": \"blue\",\n"
" \"comment\": \"grey\",\n"
" \"own\": \"pink\",\n"
" \"diagnostic_warning\": \"orange\",\n"
" \"diagnostic_error\": \"red\"\n"
" },\n"
" \"syntax\": {\n"
" \"43\": \"type\",\n"
" \"46\": \"namespace_ref\",\n"
" \"109\": \"string\",\n"
" \"702\": \"keyword\",\n"
" \"703\": \"own\",\n"
" \"705\": \"comment\"\n"
" },\n"
" \"extensions\": [\n"
" \"c\",\n"
" \"cc\",\n"
" \"cpp\",\n"
" \"cxx\",\n"
" \"c++\",\n"
" \"h\",\n"
" \"hh\",\n"
" \"hpp\",\n"
" \"hxx\",\n"
" \"h++\"\n"
" ],\n"
" \"visual\": {\n"
" \"background\": \"white\",\n"
" \"background_selected\": \"blue\",\n"
" \"background_tooltips\": \"yellow\",\n"
" \"font\": \"Monospace\",\n"
" \"show_line_numbers\": 1,\n"
" \"highlight_current_line\": 1\n"
" },\n"
" \"tab_size\": 2,\n"
" \"tab_char\": \"<space>\"\n"
" },\n"
" \"keybindings\": {\n"
" \"new_file\": \"<primary>n\",\n"
" \"open_folder\": \"<primary><alt>o\",\n"
" \"open_file\": \"<primary>o\",\n"
" \"save\": \"<primary>s\",\n"
" \"save_as\": \"<primary><shift>s\",\n"
" \"quit\": \"<primary>q\",\n"
" \"split_window\": \"<primary><alt>s\",\n"
" \"close_tab\": \"<primary>w\",\n"
" \"edit_copy\": \"<primary>c\",\n"
" \"edit_cut\": \"<primary>x\",\n"
" \"edit_paste\": \"<primary>v\",\n"
" \"edit_undo\": \"<primary>z\",\n"
" \"edit_redo\": \"<primary><shift>z\",\n"
" \"edit_find\": \"<primary>f\",\n"
" \"source_goto_declaration\": \"<primary>d\",\n"
" \"source_goto_method\": \"<primary>m\",\n"
" \"source_rename\": \"<primary>r\",\n"
" \"compile_and_run\": \"<primary>Return\",\n"
" \"compile\": \"<primary><shift>Return\"\n"
" },\n"
" \"directoryfilter\": {\n"
" \"ignore\": [\n"
" \"cmake\",\n"
" \"#\",\n"
" \"~\",\n"
" \".idea\",\n"
" \".so\",\n"
" \"in-lowercase.pls\"\n"
" ],\n"
" \"exceptions\": [\n"
" \"cmakelists.txt\",\n"
" \"in-lowercase.pls\"\n"
" ]\n"
" },\n"
" \"project\": {\n"
" \"run_commands\": [\n"
" \"./.build/\"\n"
" ],\n"
" \"compile_commands\": [\n"
" \"rm -rf ./.build\",\n"
" \"mkdir ./.build\",\n"
" \"cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B./.build -H.\",\n"
" \"cd ./.build/; make\",\n"
" \"cp ./.build/compile_commands.json compile_commands.json\"\n"
" ]\n"
" },\n"
" \"example\": {\n"
" \"key\": \"value\",\n"
" \"key2\": [\n"
" \"val1\",\n"
" \"val2\",\n"
" 3\n"
" ],\n"
" \"key3\": \"value\"\n"
" }\n"
"}\n";
const std::string menuxml =
"<ui>\n"
" <menubar name=\"MenuBar\">\n"
" <menu action=\"FileMenu\">\n"
" <menuitem action=\"FileNewFile\"/>\n"
" <menuitem action=\"FileOpenFile\"/>\n"
" <menuitem action=\"FileOpenFolder\"/>\n"
" <menuitem action=\"FileSave\"/>\n"
" <menuitem action=\"FileSaveAs\"/>\n"
" <separator/>\n"
" <menuitem action=\"FileQuit\"/>\n"
" </menu>\n"
" <menu action=\"EditMenu\">\n"
" <menuitem action=\"EditCopy\"/>\n"
" <menuitem action=\"EditCut\"/>\n"
" <menuitem action=\"EditPaste\"/>\n"
" <separator/>\n"
" <menuitem action=\"EditFind\"/>\n"
" <menuitem action=\"EditUndo\"/>\n"
" <menuitem action=\"EditRedo\"/>\n"
" </menu>\n"
" <menu action=\"SourceMenu\">\n"
" <menuitem action=\"SourceGotoDeclaration\"/>\n"
" <menuitem action=\"SourceGotoMethod\"/>\n"
" <menuitem action=\"SourceRename\"/>\n"
" </menu>\n"
" <menu action=\"ProjectMenu\">\n"
" <menuitem action=\"ProjectCompileAndRun\"/>\n"
" <menuitem action=\"ProjectCompile\"/>\n"
" </menu>\n"
" <menu action=\"WindowMenu\">\n"
" <menuitem action=\"WindowCloseTab\"/>\n"
" <menuitem action=\"WindowSplitWindow\"/>\n"
" </menu>\n"
" <menu action=\"PluginMenu\">\n"
" </menu>\n"
" <menu action=\"HelpMenu\">\n"
" <menuitem action=\"HelpAbout\"/>\n"
" </menu>\n"
" </menubar>\n"
"</ui>\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";

2
juci/juci.cc → src/juci.cc

@ -3,7 +3,7 @@
void init_logging() {
add_common_attributes();
add_file_log(keywords::file_name = "juci.log",
add_file_log(keywords::file_name = Singleton::log_dir() + "juci.log",
keywords::auto_flush = true);
INFO("Logging initalized");
}

0
juci/juci.h → src/juci.h

0
juci/logging.h → src/logging.h

3
juci/menu.cc → src/menu.cc

@ -1,7 +1,9 @@
#include "menu.h"
#include "logging.h"
#include <iostream>
Menu::Menu() : box(Gtk::ORIENTATION_VERTICAL) {
INFO("Creating menu");
action_group = Gtk::ActionGroup::create();
ui_manager = Gtk::UIManager::create();
@ -16,6 +18,7 @@ Menu::Menu() : box(Gtk::ORIENTATION_VERTICAL) {
action_group->add(Gtk::Action::create("HelpMenu", "Help"));
action_group->add(Gtk::Action::create("HelpAbout", "About"), [this]() {
});
INFO("Menu created");
}
Gtk::Widget& Menu::get_widget() {

0
juci/menu.h → src/menu.h

8
juci/notebook.cc → src/notebook.cc

@ -1,8 +1,7 @@
#include <fstream>
#include "notebook.h"
#include "logging.h"
#include "sourcefile.h"
#include "singletons.h"
#include <iostream> //TODO: remove
using namespace std; //TODO: remove
namespace sigc {
@ -86,10 +85,7 @@ bool Notebook::save(int page) {
return false;
auto view=get_view(page);
if (view->file_path != "" && view->get_buffer()->get_modified()) {
std::ofstream file;
file.open(view->file_path);
file << view->get_buffer()->get_text();
file.close();
juci::filesystem::save(view->file_path, view->get_buffer()->get_text());
view->get_buffer()->set_modified(false);
Singleton::terminal()->print("File saved to: " +view->file_path+"\n");
return true;

0
juci/notebook.h → src/notebook.h

0
juci/selectiondialog.cc → src/selectiondialog.cc

0
juci/selectiondialog.h → src/selectiondialog.h

0
juci/singletons.cc → src/singletons.cc

4
juci/singletons.h → src/singletons.h

@ -6,6 +6,7 @@
#include "terminal.h"
#include "notebook.h"
#include "menu.h"
#include <string>
class Singleton {
public:
@ -19,7 +20,8 @@ public:
static std::unique_ptr<Terminal::Config> terminal_;
static std::unique_ptr<Directories::Config> directories_;
};
static std::string config_dir() { return std::string(getenv("HOME")) + "/.juci/config/"; }
static std::string log_dir() { return std::string(getenv("HOME")) + "/.juci/log/"; }
static Terminal *terminal();
static Menu *menu();
private:

6
juci/source.cc → src/source.cc

@ -1,7 +1,6 @@
#include "source.h"
#include "sourcefile.h"
#include <boost/property_tree/json_parser.hpp>
#include <fstream>
#include <boost/timer/timer.hpp>
#include "logging.h"
#include <algorithm>
@ -42,13 +41,10 @@ file_path(file_path), project_path(project_path) {
set_smart_home_end(Gsv::SMART_HOME_END_BEFORE);
set_show_line_numbers(Singleton::Config::source()->show_line_numbers);
set_highlight_current_line(Singleton::Config::source()->highlight_current_line);
sourcefile s(file_path);
get_source_buffer()->get_undo_manager()->begin_not_undoable_action();
get_source_buffer()->set_text(s.get_content());
get_source_buffer()->set_text(juci::filesystem::open(file_path));
get_source_buffer()->get_undo_manager()->end_not_undoable_action();
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0));
search_settings = gtk_source_search_settings_new();
gtk_source_search_settings_set_wrap_around(search_settings, true);
search_context = gtk_source_search_context_new(get_source_buffer()->gobj(), search_settings);

0
juci/source.h → src/source.h

32
src/sourcefile.cc

@ -0,0 +1,32 @@
#include "sourcefile.h"
#include <fstream>
std::string juci::filesystem::open(std::string path) {
std::string res;
for (auto &line : lines(path)) {
res += line;
}
return res;
}
std::vector<std::string> juci::filesystem::lines(std::string path) {
std::vector<std::string> res;
std::ifstream input(path);
if (input.is_open()) {
do { res.emplace_back(); } while(getline(input, res.back()));
}
input.close();
return res;
}
int juci::filesystem::save(std::string path, std::string new_content) {
std::ofstream output(path);
if(output.is_open()) {
output << new_content;
} else {
output.close();
return 1;
}
output.close();
return 0;
}

20
src/sourcefile.h

@ -0,0 +1,20 @@
#ifndef JUCI_SOURCEFILE_H_
#define JUCI_SOURCEFILE_H_
#include <vector>
#include <string>
#include <boost/filesystem.hpp>
namespace juci {
class filesystem {
public:
static std::string open(std::string);
static std::string open(boost::filesystem::path path) { return open(path.string()); }
static std::vector<std::string> lines(std::string);
static std::vector<std::string> lines(boost::filesystem::path path) { return lines(path.string()); };
static int save(std::string, std::string);
static int save(boost::filesystem::path path, std::string new_content) { return save(path.string(), new_content); }
static int save(std::string path) { return save(path, ""); };
static int save(boost::filesystem::path path) { return save(path, ""); };
};
} // namepace juci
#endif // JUCI_SOURCEFILE_H_

0
juci/terminal.cc → src/terminal.cc

0
juci/terminal.h → src/terminal.h

0
juci/tooltips.cc → src/tooltips.cc

0
juci/tooltips.h → src/tooltips.h

50
juci/window.cc → src/window.cc

@ -1,6 +1,7 @@
#include "window.h"
#include "logging.h"
#include "singletons.h"
#include "sourcefile.h"
#include "config.h"
#include "api.h"
@ -73,6 +74,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL) {
void Window::add_menu() {
auto menu=Singleton::menu();
INFO("Adding actions to menu");
menu->action_group->add(Gtk::Action::create("FileQuit", "Quit juCi++"), Gtk::AccelKey(menu->key_map["quit"]), [this]() {
hide();
});
@ -98,7 +100,7 @@ void Window::add_menu() {
if(auto entry=dynamic_cast<Gtk::Entry*>(widget))
entry->copy_clipboard();
else if(auto text_view=dynamic_cast<Gtk::TextView*>(widget))
text_view->get_buffer()->copy_clipboard(Gtk::Clipboard::get());
text_view->get_buffer()->copy_clipboard(Gtk::Clipboard::get());
});
menu->action_group->add(Gtk::Action::create("EditCut", "Cut"), Gtk::AccelKey(menu->key_map["edit_cut"]), [this]() {
auto widget=get_focus();
@ -118,7 +120,7 @@ void Window::add_menu() {
search_and_replace_entry();
});
menu->action_group->add(Gtk::Action::create("EditUndo", "Undo"), Gtk::AccelKey(menu->key_map["edit_undo"]), [this]() {
INFO("On undo");
INFO("On undo");
if(notebook.get_current_page()!=-1) {
auto undo_manager = notebook.get_current_view()->get_source_buffer()->get_undo_manager();
if (undo_manager->can_undo()) {
@ -126,7 +128,7 @@ void Window::add_menu() {
}
}
INFO("Done undo");
});
});
menu->action_group->add(Gtk::Action::create("EditRedo", "Redo"), Gtk::AccelKey(menu->key_map["edit_redo"]), [this]() {
INFO("On Redo");
if(notebook.get_current_page()!=-1) {
@ -205,9 +207,9 @@ void Window::add_menu() {
menu->action_group->add(Gtk::Action::create("WindowCloseTab", "Close tab"), Gtk::AccelKey(menu->key_map["close_tab"]), [this]() {
notebook.close_current_page();
});
add_accel_group(menu->ui_manager->get_accel_group());
menu->build();
INFO("Menu build")
box.pack_start(menu->get_widget(), Gtk::PACK_SHRINK);
}
@ -278,17 +280,11 @@ void Window::new_file_entry() {
Singleton::terminal()->print("Error: "+p.string()+" already exists.\n");
}
else {
std::ofstream f(p.string().c_str());
if(f) {
notebook.open(boost::filesystem::canonical(p).string());
Singleton::terminal()->print("New file "+p.string()+" created.\n");
if(notebook.project_path!="")
directories.open_folder(notebook.project_path); //TODO: Do refresh instead
}
else {
Singleton::terminal()->print("Error: could not create new file "+p.string()+".\n");
}
f.close();
juci::filesystem::save(p);
notebook.open(boost::filesystem::canonical(p).string());
Singleton::terminal()->print("New file "+p.string()+" created.\n");
if(notebook.project_path!="")
directories.open_folder(notebook.project_path); //TODO: Do refresh instead
}
}
entry_box.hide();
@ -498,23 +494,23 @@ void Window::rename_token_entry() {
};
label_it->update(0, "");
entry_box.entries.emplace_back(*token_name, [this, token_name, token](const std::string& content){
if(notebook.get_current_page()!=-1 && content!=*token_name) {
for(int c=0;c<notebook.size();c++) {
if(notebook.get_view(c)->rename_similar_tokens) {
auto number=notebook.get_view(c)->rename_similar_tokens(*token, content);
if(number>0) {
Singleton::terminal()->print("Replaced "+std::to_string(number)+" occurrences in file "+notebook.get_view(c)->file_path+"\n");
notebook.save(c);
if(notebook.get_current_page()!=-1 && content!=*token_name) {
for(int c=0;c<notebook.size();c++) {
if(notebook.get_view(c)->rename_similar_tokens) {
auto number=notebook.get_view(c)->rename_similar_tokens(*token, content);
if(number>0) {
Singleton::terminal()->print("Replaced "+std::to_string(number)+" occurrences in file "+notebook.get_view(c)->file_path+"\n");
notebook.save(c);
}
}
}
entry_box.hide();
}
entry_box.hide();
}
});
});
auto entry_it=entry_box.entries.begin();
entry_box.buttons.emplace_back("Rename", [this, entry_it](){
entry_it->activate();
});
entry_it->activate();
});
entry_box.show();
}
}

0
juci/window.h → src/window.h

Loading…
Cancel
Save