Browse Source

Merge branch 'master' of bitbucket.org:cppit/juci

merge-requests/365/head
Jørgen Lien Sellæg 11 years ago
parent
commit
118763e6f9
  1. 7
      juci/CMakeLists.txt
  2. 17
      juci/directories.cc
  3. 2
      juci/plugins.py
  4. 3
      juci/source.cc
  5. 48
      juci/terminal.cc
  6. 6
      juci/terminal.h
  7. 31
      juci/window.cc
  8. 3
      juci/window.h

7
juci/CMakeLists.txt

@ -111,6 +111,9 @@ add_executable(${project_name}
terminal.cc terminal.cc
) )
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
add_library(${module} SHARED add_library(${module} SHARED
api api
api_ext api_ext
@ -132,8 +135,8 @@ link_directories(
${LIBCLANG_LIBRARY_DIRS} ${LIBCLANG_LIBRARY_DIRS}
) )
#module: #module:
set_target_properties(${module} PROPERTIES PREFIX "") set_target_properties(${module} PROPERTIES PREFIX ""
# LIBRARY_OUTPUT_DIRECTORY "/usr/lib/python2.7/dist-packages/") LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib/")
target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES}) target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
#executable: #executable:
target_link_libraries(${project_name} ${LIVCLANG_LIBRARIES} ${LCL_LIBRARIES} ${GTKMM_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) target_link_libraries(${project_name} ${LIVCLANG_LIBRARIES} ${LCL_LIBRARIES} ${GTKMM_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})

17
juci/directories.cc

@ -101,6 +101,22 @@ int Directories::Controller::count(const std::string path) {
project_name_var = line.substr(variable_start+1, project_name_var = line.substr(variable_start+1,
(variable_end)-variable_start-1); (variable_end)-variable_start-1);
boost::algorithm::trim(project_name_var); boost::algorithm::trim(project_name_var);
if (variable_start == std::string::npos) { // not a variabel
variable_start = line.find("(", 0);
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 if (variable_start == std::string::npos) { // not a variable
variable_start = line.find("(", 0); variable_start = line.find("(", 0);
variable_end = line.find(")", variable_start); variable_end = line.find(")", variable_start);
@ -111,6 +127,7 @@ int Directories::Controller::count(const std::string path) {
break; break;
} }
} }
}
std::ifstream ifs2(itr->path().string()); std::ifstream ifs2(itr->path().string());
while (std::getline(ifs2, line)) { while (std::getline(ifs2, line)) {
if (line.find("set(", 0) != std::string::npos if (line.find("set(", 0) != std::string::npos

2
juci/plugins.py

@ -2,7 +2,7 @@
#plugin handler #plugin handler
import sys, os, glob import sys, os, glob
cwd = os.getcwd() cwd = os.getcwd()
sys.path.append(cwd) sys.path.append(cwd+"/lib")
import juci_to_python_api as juci import juci_to_python_api as juci
def loadplugins(): def loadplugins():

3
juci/source.cc

@ -359,7 +359,7 @@ void Source::Controller::OnOpenFile(const string &filepath) {
notebook_->index()); notebook_->index());
view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset), view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset),
model().config()); model().config());
}
buffer()->signal_end_user_action().connect([this]() { buffer()->signal_end_user_action().connect([this]() {
if (!go) { if (!go) {
@ -400,6 +400,7 @@ void Source::Controller::OnOpenFile(const string &filepath) {
} }
}); });
} }
}
Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer() { Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer() {
return view().get_buffer(); return view().get_buffer();
} }

48
juci/terminal.cc

@ -1,6 +1,8 @@
#include "terminal.h" #include "terminal.h"
#include <iostream> #include <iostream>
#include <thread> #include <thread>
// #include <pstream.h>
// #include <string>
Terminal::View::View(){ Terminal::View::View(){
@ -21,32 +23,17 @@ void Terminal::Controller::SetFolderCommand( boost::filesystem::path
folder_command_ = "cd "+ path_ + "; "; folder_command_ = "cd "+ path_ + "; ";
} }
bool Terminal::Controller::Compile(){ void Terminal::Controller::Compile(){
if (running.try_lock()) {
std::thread execute([=]() {
Terminal().get_buffer()->set_text(""); Terminal().get_buffer()->set_text("");
ExecuteCommand("cmake ."); ExecuteCommand("cmake .", "r");
if (ExistInConsole(cmake_sucsess)){ if (ExistInConsole(cmake_sucsess)){
ExecuteCommand("make"); ExecuteCommand("make", "r");
} }
});
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::Run(std::string executable) { void Terminal::Controller::Run(std::string executable) {
if (running.try_lock()) { PrintMessage("juCi++ execute: " + executable + "\n");
std::thread execute([=]() { ExecuteCommand("./"+executable, "r");
ExecuteCommand("./"+executable);
});
execute.detach();
running.unlock();
}
} }
void Terminal::Controller::PrintMessage(std::string message){ void Terminal::Controller::PrintMessage(std::string message){
@ -54,22 +41,6 @@ void Terminal::Controller::PrintMessage(std::string message){
insert(Terminal().get_buffer()-> end(),"> "+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) { bool Terminal::Controller::ExistInConsole(std::string string) {
double pos = Terminal().get_buffer()-> double pos = Terminal().get_buffer()->
@ -78,10 +49,11 @@ bool Terminal::Controller::ExistInConsole(std::string string) {
return true; return true;
} }
void Terminal::Controller::ExecuteCommand(std::string command) { void Terminal::Controller::ExecuteCommand(std::string command, std::string mode) {
command = folder_command_+command; command = folder_command_+command;
std::cout << "EXECUTE COMMAND: "<< command << std::endl; 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) { if (p == NULL) {
PrintMessage("juCi++ ERROR: Failed to run command" + command + "\n"); PrintMessage("juCi++ ERROR: Failed to run command" + command + "\n");
}else { }else {

6
juci/terminal.h

@ -25,17 +25,15 @@ namespace Terminal {
Gtk::TextView& Terminal(){return view_.textview();} Gtk::TextView& Terminal(){return view_.textview();}
void SetFolderCommand(boost::filesystem::path CMake_path); void SetFolderCommand(boost::filesystem::path CMake_path);
void Run(std::string executable); void Run(std::string executable);
bool Compile(); void Compile();
private: private:
void ExecuteCommand(std::string command); void ExecuteCommand(std::string command, std::string mode);
bool OnButtonRealeaseEvent(GdkEventKey* key); bool OnButtonRealeaseEvent(GdkEventKey* key);
bool ExistInConsole(std::string string); bool ExistInConsole(std::string string);
// bool FindExecutable(std::string executable);
void PrintMessage(std::string message); void PrintMessage(std::string message);
Terminal::View view_; Terminal::View view_;
std::string folder_command_; std::string folder_command_;
std::string path_; std::string path_;
std::mutex running;
const std::string cmake_sucsess = "Build files have been written to:"; const std::string cmake_sucsess = "Build files have been written to:";
const std::string make_built = "Built target"; const std::string make_built = "Built target";
const std::string make_executable = "Linking CXX executable"; const std::string make_executable = "Linking CXX executable";

31
juci/window.cc

@ -54,13 +54,22 @@ Window::Window() :
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings_.config_
.key_map()["compile_and_run"]), .key_map()["compile_and_run"]),
[this]() { [this]() {
if (running.try_lock()) {
std::thread execute([=]() {
notebook_.OnSaveFile(); notebook_.OnSaveFile();
std::string path = notebook_.CurrentPagePath(); 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_.SetFolderCommand(path);
if(terminal_.Compile()) { }
terminal_.Compile();
std::string executable = notebook_.directories(). std::string executable = notebook_.directories().
GetCmakeVarValue(path,"add_executable"); GetCmakeVarValue(path,"add_executable");
terminal_.Run(executable); terminal_.Run(executable);
});
execute.detach();
running.unlock();
} }
}); });
@ -71,12 +80,21 @@ Window::Window() :
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings_.config_
.key_map()["compile"]), .key_map()["compile"]),
[this]() { [this]() {
if (running.try_lock()) {
std::thread execute([=]() {
notebook_.OnSaveFile(); notebook_.OnSaveFile();
std::string path = std::string path = notebook_.CurrentPagePath();
notebook_.CurrentPagePath(); int pos = path.find_last_of("/\\");
if(pos != std::string::npos){
path.erase(path.begin()+pos,path.end());
terminal_.SetFolderCommand(path); terminal_.SetFolderCommand(path);
}
terminal_.Compile(); terminal_.Compile();
}); });
execute.detach();
running.unlock();
}
});
this->signal_button_release_event(). this->signal_button_release_event().
connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false);
@ -88,9 +106,12 @@ Window::Window() :
keybindings_.BuildMenu(); keybindings_.BuildMenu();
window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK);
window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK); window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK);
window_box_.pack_start(notebook_.view()); paned_.set_position(300);
window_box_.pack_end(terminal_.view(),Gtk::PACK_SHRINK); paned_.pack1(notebook_.view(), true, false);
paned_.pack2(terminal_.view(), true, true);
window_box_.pack_end(paned_);
show_all_children(); show_all_children();
INFO("Window created"); INFO("Window created");
} // Window constructor } // Window constructor

3
juci/window.h

@ -26,11 +26,12 @@ public:
Keybindings::Controller& keybindings() { return keybindings_; } Keybindings::Controller& keybindings() { return keybindings_; }
private: private:
std::mutex running;
Gtk::VPaned paned_;
//signal handlers //signal handlers
void OnWindowHide(); void OnWindowHide();
void OnOpenFile(); void OnOpenFile();
void OnFileOpenFolder(); void OnFileOpenFolder();
bool OnMouseRelease(GdkEventButton* button); bool OnMouseRelease(GdkEventButton* button);
}; };

Loading…
Cancel
Save