diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index 64c2849..5cd0026 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -111,6 +111,9 @@ add_executable(${project_name} terminal.cc ) +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) + + add_library(${module} SHARED api api_ext @@ -132,8 +135,8 @@ link_directories( ${LIBCLANG_LIBRARY_DIRS} ) #module: -set_target_properties(${module} PROPERTIES PREFIX "") -# LIBRARY_OUTPUT_DIRECTORY "/usr/lib/python2.7/dist-packages/") +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} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) diff --git a/juci/directories.cc b/juci/directories.cc index c54ba0e..73fb825 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -96,21 +96,38 @@ int Directories::Controller::count(const std::string path) { while (std::getline(ifs, line)) { if (line.find(command_name+"(", 0) != std::string::npos || line.find(command_name+" (", 0) != std::string::npos ) { - size_t variable_start = line.find("{", 0); - size_t variable_end = line.find("}", variable_start); - project_name_var = line.substr(variable_start+1, - (variable_end)-variable_start-1); + size_t variable_start = line.find("{", 0); + size_t variable_end = line.find("}", variable_start); + project_name_var = line.substr(variable_start+1, + (variable_end)-variable_start-1); boost::algorithm::trim(project_name_var); - if (variable_start == std::string::npos) { // not a variable + if (variable_start == std::string::npos) { // not a variabel variable_start = line.find("(", 0); - variable_end = line.find(")", variable_start); - INFO("Wasn't a variable, returning value"); + + variable_end = line.find(' ', variable_start); + if(variable_end != std::string::npos){ + return line.substr(variable_start+1, + (variable_end)-variable_start-1); + } + variable_end = line.find("#", variable_start); + if(variable_end != std::string::npos){ + return line.substr(variable_start+1, + (variable_end)-variable_start-1); + } + variable_end = line.find(")", variable_start); return line.substr(variable_start+1, (variable_end)-variable_start-1); + if (variable_start == std::string::npos) { // not a variable + variable_start = line.find("(", 0); + variable_end = line.find(")", variable_start); + INFO("Wasn't a variable, returning value"); + return line.substr(variable_start+1, + (variable_end)-variable_start-1); } break; } } + } std::ifstream ifs2(itr->path().string()); while (std::getline(ifs2, line)) { if (line.find("set(", 0) != std::string::npos diff --git a/juci/plugins.py b/juci/plugins.py index f8faf6e..ef50bb7 100644 --- a/juci/plugins.py +++ b/juci/plugins.py @@ -2,7 +2,7 @@ #plugin handler import sys, os, glob cwd = os.getcwd() -sys.path.append(cwd) +sys.path.append(cwd+"/lib") import juci_to_python_api as juci def loadplugins(): diff --git a/juci/source.cc b/juci/source.cc index dbc08e4..cc7949c 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -359,7 +359,7 @@ void Source::Controller::OnOpenFile(const string &filepath) { notebook_->index()); view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset), model().config()); - } + buffer()->signal_end_user_action().connect([this]() { if (!go) { @@ -399,6 +399,7 @@ void Source::Controller::OnOpenFile(const string &filepath) { syntax.unlock(); } }); + } } Glib::RefPtr Source::Controller::buffer() { return view().get_buffer(); diff --git a/juci/terminal.cc b/juci/terminal.cc index e7f1ede..4e7a28e 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -1,6 +1,8 @@ #include "terminal.h" #include #include +// #include +// #include Terminal::View::View(){ @@ -21,32 +23,17 @@ void Terminal::Controller::SetFolderCommand( boost::filesystem::path folder_command_ = "cd "+ path_ + "; "; } -bool Terminal::Controller::Compile(){ - if (running.try_lock()) { - std::thread execute([=]() { - Terminal().get_buffer()->set_text(""); - ExecuteCommand("cmake ."); - if (ExistInConsole(cmake_sucsess)){ - ExecuteCommand("make"); - } - }); - execute.detach(); - running.unlock(); - if (ExistInConsole(make_built)) return true; - } - PrintMessage("juCi++ ERROR: Failed to compile project in directory" - + path_ + "\n"); - return false; +void Terminal::Controller::Compile(){ + Terminal().get_buffer()->set_text(""); + ExecuteCommand("cmake .", "r"); + if (ExistInConsole(cmake_sucsess)){ + ExecuteCommand("make", "r"); + } } void Terminal::Controller::Run(std::string executable) { - if (running.try_lock()) { - std::thread execute([=]() { - ExecuteCommand("./"+executable); - }); - execute.detach(); - running.unlock(); - } + PrintMessage("juCi++ execute: " + executable + "\n"); + ExecuteCommand("./"+executable, "r"); } void Terminal::Controller::PrintMessage(std::string message){ @@ -54,22 +41,6 @@ void Terminal::Controller::PrintMessage(std::string message){ insert(Terminal().get_buffer()-> end(),"> "+message); } -// bool Terminal::Controller::FindExecutable(std::string executable) { -// std::string build = Terminal().get_buffer()->get_text(); -// double pos = build.find(make_built); -// Gtk::TextIter start = Terminal().get_buffer()->get_iter_at_offset(pos); -// Gtk::TextIter end = Terminal().get_buffer()->get_iter_at_offset(pos); -// while (!end.ends_line()) { -// end.forward_char(); -// } -// build = Terminal().get_buffer()->get_text(start, end); -// pos = build.find_last_of(" "); -// build = build.substr(pos+1); -// std::cout << "DEBUG: BUILD TARGET = "<< build << std::endl; -// std::cout << "EDEBUG: ECUTABLE FILE = "<< executable << std::endl; -// if(build != executable) return false; -// return true; -// } bool Terminal::Controller::ExistInConsole(std::string string) { double pos = Terminal().get_buffer()-> @@ -78,14 +49,15 @@ bool Terminal::Controller::ExistInConsole(std::string string) { return true; } -void Terminal::Controller::ExecuteCommand(std::string command) { +void Terminal::Controller::ExecuteCommand(std::string command, std::string mode) { command = folder_command_+command; std::cout << "EXECUTE COMMAND: "<< command << std::endl; - FILE* p = popen(command.c_str(), "r"); + FILE* p = popen(command.c_str(), mode.c_str()); + if (p == NULL) { PrintMessage("juCi++ ERROR: Failed to run command" + command + "\n"); }else { - char buffer[1028]; + char buffer[1028]; while (fgets(buffer, 1028, p) != NULL) { PrintMessage(buffer); } diff --git a/juci/terminal.h b/juci/terminal.h index 650758f..a3fa6a6 100644 --- a/juci/terminal.h +++ b/juci/terminal.h @@ -25,17 +25,15 @@ namespace Terminal { Gtk::TextView& Terminal(){return view_.textview();} void SetFolderCommand(boost::filesystem::path CMake_path); void Run(std::string executable); - bool Compile(); + void Compile(); private: - void ExecuteCommand(std::string command); + void ExecuteCommand(std::string command, std::string mode); bool OnButtonRealeaseEvent(GdkEventKey* key); bool ExistInConsole(std::string string); - // bool FindExecutable(std::string executable); void PrintMessage(std::string message); Terminal::View view_; std::string folder_command_; std::string path_; - std::mutex running; const std::string cmake_sucsess = "Build files have been written to:"; const std::string make_built = "Built target"; const std::string make_executable = "Linking CXX executable"; diff --git a/juci/window.cc b/juci/window.cc index f489bbe..3cc5b89 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -33,53 +33,71 @@ Window::Window() : }); keybindings_.action_group_menu()->add(Gtk::Action::create("FileSaveAs", - "Save as"), - Gtk::AccelKey(keybindings_.config_ - .key_map()["save_as"]), - [this]() { - notebook_.OnSaveFile(); - }); + "Save as"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["save_as"]), + [this]() { + notebook_.OnSaveFile(); + }); keybindings_.action_group_menu()->add(Gtk::Action::create("FileSave", - "Save"), - Gtk::AccelKey(keybindings_.config_ - .key_map()["save"]), - [this]() { - notebook_.OnSaveFile(); - }); - keybindings_. - action_group_menu()-> - add(Gtk::Action::create("ProjectCompileAndRun", - "Compile And Run"), - Gtk::AccelKey(keybindings_.config_ - .key_map()["compile_and_run"]), - [this]() { - notebook_.OnSaveFile(); - std::string path = notebook_.CurrentPagePath(); - terminal_.SetFolderCommand(path); - if(terminal_.Compile()) { - std::string executable = notebook_.directories(). - GetCmakeVarValue(path,"add_executable"); - terminal_.Run(executable); - } - }); - + "Save"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["save"]), + [this]() { + notebook_.OnSaveFile(); + }); keybindings_. - action_group_menu()-> - add(Gtk::Action::create("ProjectCompile", - "Compile"), - Gtk::AccelKey(keybindings_.config_ - .key_map()["compile"]), - [this]() { - notebook_.OnSaveFile(); - std::string path = - notebook_.CurrentPagePath(); - terminal_.SetFolderCommand(path); - terminal_.Compile(); - }); - - this->signal_button_release_event(). - connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); + action_group_menu()-> + add(Gtk::Action::create("ProjectCompileAndRun", + "Compile And Run"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["compile_and_run"]), + [this]() { + if (running.try_lock()) { + std::thread execute([=]() { + notebook_.OnSaveFile(); + std::string path = notebook_.CurrentPagePath(); + int pos = path.find_last_of("/\\"); + if(pos != std::string::npos){ + path.erase(path.begin()+pos,path.end()); + terminal_.SetFolderCommand(path); + } + terminal_.Compile(); + std::string executable = notebook_.directories(). + GetCmakeVarValue(path,"add_executable"); + terminal_.Run(executable); + }); + execute.detach(); + running.unlock(); + } + }); + + keybindings_. + action_group_menu()-> + add(Gtk::Action::create("ProjectCompile", + "Compile"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["compile"]), + [this]() { + if (running.try_lock()) { + std::thread execute([=]() { + notebook_.OnSaveFile(); + std::string path = notebook_.CurrentPagePath(); + int pos = path.find_last_of("/\\"); + if(pos != std::string::npos){ + path.erase(path.begin()+pos,path.end()); + terminal_.SetFolderCommand(path); + } + terminal_.Compile(); + }); + execute.detach(); + running.unlock(); + } + }); + + this->signal_button_release_event(). + connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); terminal_.Terminal().signal_button_release_event(). connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); @@ -88,9 +106,12 @@ Window::Window() : keybindings_.BuildMenu(); window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); + window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK); - window_box_.pack_start(notebook_.view()); - window_box_.pack_end(terminal_.view(),Gtk::PACK_SHRINK); + paned_.set_position(300); + paned_.pack1(notebook_.view(), true, false); + paned_.pack2(terminal_.view(), true, true); + window_box_.pack_end(paned_); show_all_children(); INFO("Window created"); } // Window constructor diff --git a/juci/window.h b/juci/window.h index a39bd23..7f2b3f7 100644 --- a/juci/window.h +++ b/juci/window.h @@ -26,11 +26,12 @@ public: Keybindings::Controller& keybindings() { return keybindings_; } private: + std::mutex running; + Gtk::VPaned paned_; //signal handlers void OnWindowHide(); void OnOpenFile(); void OnFileOpenFolder(); - bool OnMouseRelease(GdkEventButton* button); };