Browse Source

Merge branch 'forgieCleanup'

merge-requests/365/head
tedjk 11 years ago
parent
commit
5d4ecb11fa
  1. 4
      juci/CMakeLists.txt
  2. 18
      juci/api.cc
  3. 5
      juci/api.h
  4. 5
      juci/api_ext.cc
  5. 7
      juci/config.cc
  6. 26
      juci/directories.cc
  7. 4
      juci/notebook.cc
  8. 1
      juci/notebook.h
  9. 6
      juci/plugins.py
  10. 96
      juci/terminal.cc
  11. 9
      juci/terminal.h
  12. 69
      juci/window.cc
  13. 1
      juci/window.h

4
juci/CMakeLists.txt

@ -132,8 +132,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 "/usr/lib/python2.7/dist-packages/")
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})

18
juci/api.cc

@ -5,6 +5,13 @@ Notebook::Controller* PluginApi::notebook_;
///////////////////////////// /////////////////////////////
//// API ServiceProvider //// //// API ServiceProvider ////
///////////////////////////// /////////////////////////////
PluginApi::PluginApi(Menu::Controller& menu_ctl_,
Notebook::Controller& notebook_ctl_) {
menu_ = &menu_ctl_;
notebook_ = &notebook_ctl_;
InitPlugins();
}
std::string PluginApi::ProjectPath() { std::string PluginApi::ProjectPath() {
int MAXPATHLEN = 50; int MAXPATHLEN = 50;
char temp[MAXPATHLEN]; char temp[MAXPATHLEN];
@ -107,7 +114,7 @@ void libjuci::ReplaceWord(const std::string word) {
} }
void libjuci::ReplaceLine(const std::string line) { void libjuci::ReplaceLine(const std::string line) {
std::cout << "unimplemented function: 'libjuci::ReplaceLine()' called" std::cout << "unimplemented: " << __func__ << " called"
<< std::endl; << std::endl;
} }
std::string libjuci::GetWord() { std::string libjuci::GetWord() {
@ -201,16 +208,7 @@ void libjuci::IterToWordEnd(Gtk::TextIter &iter) {
} }
Glib::RefPtr<Gtk::TextBuffer> libjuci::BufferFromNotebook() { Glib::RefPtr<Gtk::TextBuffer> libjuci::BufferFromNotebook() {
// finding focused view
// int i = 0;
// while (!PluginApi::notebook_->source_vec_.at(i)->view().has_focus()) {
// i++;
// while(!PluginApi::notebook_->CurrentTextView().has_focus()) {
// i++;
// }
return Glib::RefPtr<Gtk::TextBuffer>(PluginApi::notebook_ return Glib::RefPtr<Gtk::TextBuffer>(PluginApi::notebook_
// ->source_vec_.at(i)
// ->view().get_buffer());
->CurrentTextView().get_buffer()); ->CurrentTextView().get_buffer());
} }

5
juci/api.h

@ -12,6 +12,7 @@
//////////////////// ////////////////////
class PluginApi { class PluginApi {
public: public:
PluginApi(Menu::Controller&, Notebook::Controller&);
static Menu::Controller* menu_; static Menu::Controller* menu_;
static Notebook::Controller* notebook_; static Notebook::Controller* notebook_;
static void InitPlugins(); static void InitPlugins();
@ -25,7 +26,6 @@ public:
const std::string menu_func_name, const std::string menu_func_name,
const std::string plugin_path, const std::string plugin_path,
const std::string menu_keybinding); const std::string menu_keybinding);
// text-buffer functions
static void ReplaceWord(const std::string word); static void ReplaceWord(const std::string word);
static void ReplaceLine(const std::string line); static void ReplaceLine(const std::string line);
protected: protected:
@ -64,11 +64,10 @@ namespace libjuci {
namespace bp = boost::python; namespace bp = boost::python;
bp::api::object OpenPythonScript(const std::string path, bp::api::object OpenPythonScript(const std::string path,
bp::api::object python_name_space); bp::api::object python_name_space);
void LoadPlugin(const std::string& plugin_name); void LoadPlugin(const std::string& plugin_name);
void LoadPluginFunction(const std::string &function_name, void LoadPluginFunction(const std::string &function_name,
const std::string &plugin_path); const std::string &plugin_path);
void InitPlugin(const std::string& plugin_path); void InitPlugin(const std::string& plugin_path);
} // libjuci } // namespace libjuci
#endif // JUCI_API_H_ #endif // JUCI_API_H_

5
juci/api_ext.cc

@ -12,7 +12,4 @@ BOOST_PYTHON_MODULE(juci_to_python_api) {
def("replaceLine", &libjuci::ReplaceLine); def("replaceLine", &libjuci::ReplaceLine);
def("replaceWord", &libjuci::ReplaceWord); def("replaceWord", &libjuci::ReplaceWord);
def("getWord", &libjuci::GetWord); def("getWord", &libjuci::GetWord);
} // module::juci_to_python_api
//something more
}// module::juci_to_python_api

7
juci/config.cc

@ -6,19 +6,16 @@ MainConfig::MainConfig() :
GenerateSource(); GenerateSource();
GenerateKeybindings(); GenerateKeybindings();
GenerateDirectoryFilter(); GenerateDirectoryFilter();
// keybindings_cfg_ = cfg_.get_child("keybindings");
// notebook_cfg_ = cfg_.get_child("notebook");
// menu_cfg_ = cfg_.get_child("menu");
} }
void MainConfig::GenerateSource() { void MainConfig::GenerateSource() {
boost::property_tree::ptree source_json = cfg_.get_child("source"); boost::property_tree::ptree source_json = cfg_.get_child("source");
boost::property_tree::ptree syntax_json = source_json.get_child("syntax"); boost::property_tree::ptree syntax_json = source_json.get_child("syntax");
boost::property_tree::ptree colors_json = source_json.get_child("colors"); boost::property_tree::ptree colors_json = source_json.get_child("colors");
for ( auto &i : colors_json ) { for (auto &i : colors_json) {
source_cfg_.InsertTag(i.first, i.second.get_value<std::string>()); source_cfg_.InsertTag(i.first, i.second.get_value<std::string>());
} }
for ( auto &i : syntax_json ) { for (auto &i : syntax_json) {
source_cfg_.InsertType(i.first, i.second.get_value<std::string>()); source_cfg_.InsertType(i.first, i.second.get_value<std::string>());
} }
} }

26
juci/directories.cc

@ -92,16 +92,16 @@ int Directories::Controller::count(const std::string path) {
while (std::getline(ifs, line)) { while (std::getline(ifs, line)) {
if (line.find(command_name+"(", 0) != std::string::npos if (line.find(command_name+"(", 0) != std::string::npos
|| line.find(command_name+" (", 0) != std::string::npos ) { || line.find(command_name+" (", 0) != std::string::npos ) {
size_t variabel_start = line.find("{", 0); size_t variable_start = line.find("{", 0);
size_t variabel_end = line.find("}", variabel_start); size_t variable_end = line.find("}", variable_start);
project_name_var = line.substr(variabel_start+1, project_name_var = line.substr(variable_start+1,
(variabel_end)-variabel_start-1); (variable_end)-variable_start-1);
boost::algorithm::trim(project_name_var); boost::algorithm::trim(project_name_var);
if (variabel_start == std::string::npos) { // not a variabel if (variable_start == std::string::npos) { // not a variable
variabel_start = line.find("(", 0); variable_start = line.find("(", 0);
variabel_end = line.find(")", variabel_start); variable_end = line.find(")", variable_start);
return line.substr(variabel_start+1, return line.substr(variable_start+1,
(variabel_end)-variabel_start-1); (variable_end)-variable_start-1);
} }
break; break;
} }
@ -111,11 +111,11 @@ int Directories::Controller::count(const std::string path) {
if (line.find("set(", 0) != std::string::npos if (line.find("set(", 0) != std::string::npos
|| line.find("set (", 0) != std::string::npos) { || line.find("set (", 0) != std::string::npos) {
if( line.find(project_name_var, 0) != std::string::npos) { if( line.find(project_name_var, 0) != std::string::npos) {
size_t variabel_start = line.find(project_name_var, 0) size_t variable_start = line.find(project_name_var, 0)
+project_name_var.length(); +project_name_var.length();
size_t variabel_end = line.find(")", variabel_start); size_t variable_end = line.find(")", variable_start);
project_name = line.substr(variabel_start+1, project_name = line.substr(variable_start+1,
variabel_end-variabel_start-1); variable_end-variable_start-1);
boost::algorithm::trim(project_name); boost::algorithm::trim(project_name);
return project_name; return project_name;
} }

4
juci/notebook.cc

@ -564,6 +564,10 @@ void Notebook::Controller::PopupSetSize(Gtk::ScrolledWindow &scroll,
} }
} }
std::string Notebook::Controller::CurrentPagePath(){
return text_vec_.at(CurrentPage())->path();
}
void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview, void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview,
int popup_x, int popup_x,
int popup_y, int popup_y,

1
juci/notebook.h

@ -40,6 +40,7 @@ namespace Notebook {
int CurrentPage(); int CurrentPage();
Gtk::Box& entry_view(); Gtk::Box& entry_view();
Gtk::Notebook& Notebook(); Gtk::Notebook& Notebook();
std::string CurrentPagePath();
void OnBufferChange(); void OnBufferChange();
void BufferChangeHandler(Glib::RefPtr<Gtk::TextBuffer> void BufferChangeHandler(Glib::RefPtr<Gtk::TextBuffer>
buffer); buffer);

6
juci/plugins.py

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

96
juci/terminal.cc

@ -2,14 +2,12 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
Terminal::View::View(){ Terminal::View::View(){
scrolledwindow_.add(textview_); scrolledwindow_.add(textview_);
scrolledwindow_.set_size_request(-1,150); scrolledwindow_.set_size_request(-1,150);
view_.add(scrolledwindow_); view_.add(scrolledwindow_);
textview_.set_editable(false); textview_.set_editable(false);
//Pango::TabArray tabsize;
//tabsize.set_tab(200,Pango::TAB_LEFT, 200);
//textview_.set_tabs(tabsize);
} }
@ -17,59 +15,61 @@ Terminal::Controller::Controller() {
folder_command_ = ""; folder_command_ = "";
} }
void Terminal::Controller::SetFolderCommand(std::string path) { void Terminal::Controller::SetFolderCommand( boost::filesystem::path
int pos = path.find_last_of("/\\"); CMake_path) {
path.erase(path.begin()+pos,path.end()); path_ = CMake_path.string();
folder_command_ = "cd "+ 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::CompileAndRun(std::string project_name) { void Terminal::Controller::Run(std::string executable) {
if (folder_command_=="") { if (running.try_lock()) {
PrintMessage("juCi++ ERROR: Can not find project's CMakeList.txt\n"); std::thread execute([=]() {
} else { ExecuteCommand("./"+executable);
if (running.try_lock()) { });
std::thread execute([=]() { execute.detach();
Terminal().get_buffer()->set_text(""); running.unlock();
ExecuteCommand("cmake ."); }
if (ExistInConsole(cmake_sucsess)){
ExecuteCommand("make");
if (ExistInConsole(make_built)){
if (FindExecutable(project_name)) {
ExecuteCommand("./"+project_name);
} else {
PrintMessage("juCi++ ERROR: Can not find Executable\n");
}
}
}
});
execute.detach();
running.unlock();
}
}
} }
void Terminal::Controller::PrintMessage(std::string message){ void Terminal::Controller::PrintMessage(std::string message){
Terminal().get_buffer()-> Terminal().get_buffer()->
insert(Terminal().get_buffer()-> end(),"> "+message); insert(Terminal().get_buffer()-> end(),"> "+message);
} }
bool Terminal::Controller::FindExecutable(std::string executable) { // bool Terminal::Controller::FindExecutable(std::string executable) {
std::string build = Terminal().get_buffer()->get_text(); // std::string build = Terminal().get_buffer()->get_text();
double pos = build.find(make_built); // double pos = build.find(make_built);
Gtk::TextIter start = Terminal().get_buffer()->get_iter_at_offset(pos); // Gtk::TextIter start = Terminal().get_buffer()->get_iter_at_offset(pos);
Gtk::TextIter end = Terminal().get_buffer()->get_iter_at_offset(pos); // Gtk::TextIter end = Terminal().get_buffer()->get_iter_at_offset(pos);
while (!end.ends_line()) { // while (!end.ends_line()) {
end.forward_char(); // end.forward_char();
} // }
build = Terminal().get_buffer()->get_text(start, end); // build = Terminal().get_buffer()->get_text(start, end);
pos = build.find_last_of(" "); // pos = build.find_last_of(" ");
std::cout << "FINNER NY POS" << std::endl; // build = build.substr(pos+1);
build = build.substr(pos+1); // std::cout << "DEBUG: BUILD TARGET = "<< build << std::endl;
std::cout <<"BUILD TARGET = "<< build << std::endl; // std::cout << "EDEBUG: ECUTABLE FILE = "<< executable << std::endl;
std::cout << "EXECUTABLE FILE = "<< executable << std::endl; // if(build != executable) return false;
if(build != executable) return false; // return true;
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()->

9
juci/terminal.h

@ -3,6 +3,7 @@
#include <mutex> #include <mutex>
#include "gtkmm.h" #include "gtkmm.h"
#include <boost/filesystem.hpp>
namespace Terminal { namespace Terminal {
@ -22,16 +23,18 @@ namespace Terminal {
Controller(); Controller();
Gtk::HBox& view() {return view_.view();} Gtk::HBox& view() {return view_.view();}
Gtk::TextView& Terminal(){return view_.textview();} Gtk::TextView& Terminal(){return view_.textview();}
void SetFolderCommand(std::string path); void SetFolderCommand(boost::filesystem::path CMake_path);
void CompileAndRun(std::string project_name); void Run(std::string executable);
bool Compile();
private: private:
void ExecuteCommand(std::string command); void ExecuteCommand(std::string command);
bool OnButtonRealeaseEvent(GdkEventKey* key); bool OnButtonRealeaseEvent(GdkEventKey* key);
bool ExistInConsole(std::string string); bool ExistInConsole(std::string string);
bool FindExecutable(std::string executable); // 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::mutex running; 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";

69
juci/window.cc

@ -4,8 +4,11 @@ Window::Window() :
window_box_(Gtk::ORIENTATION_VERTICAL), window_box_(Gtk::ORIENTATION_VERTICAL),
main_config_(), main_config_(),
keybindings_(main_config_.keybindings_cfg()), keybindings_(main_config_.keybindings_cfg()),
notebook_(this,keybindings(), main_config_.source_cfg(), main_config_.dir_cfg()), notebook_(this,keybindings(),
menu_(keybindings()) { main_config_.source_cfg(),
main_config_.dir_cfg()),
menu_(keybindings()),
api_(menu_, notebook_) {
set_title("juCi++"); set_title("juCi++");
set_default_size(600, 400); set_default_size(600, 400);
add(window_box_); add(window_box_);
@ -42,38 +45,42 @@ Window::Window() :
[this]() { [this]() {
notebook_.OnSaveFile(); notebook_.OnSaveFile();
}); });
keybindings_.
keybindings_.action_group_menu()->add(Gtk::Action::create("ProjectCompileAndRun", action_group_menu()->
"Compile And Run"), add(Gtk::Action::create("ProjectCompileAndRun",
Gtk::AccelKey(keybindings_.config_ "Compile And Run"),
.key_map()["compile_and_run"]), Gtk::AccelKey(keybindings_.config_
[this]() { .key_map()["compile_and_run"]),
terminal_. [this]() {
SetFolderCommand("/home/gm/ClionProjects/testi/CM.txt"); notebook_.OnSaveFile();
std::string p = notebook_.directories().GetCmakeVarValue("/home/gm/ClionProjects/testi", "project"); std::string path = notebook_.CurrentPagePath();
terminal_.CompileAndRun(p); terminal_.SetFolderCommand(path);
}); if(terminal_.Compile()) {
std::string executable = notebook_.directories().
keybindings_.action_group_menu()->add(Gtk::Action::create("ProjectCompile", GetCmakeVarValue(path,"add_executable");
"Compile"), terminal_.Run(executable);
Gtk::AccelKey(keybindings_.config_ }
.key_map()["compile"]), });
[this]() {
terminal_. keybindings_.
SetFolderCommand("/home/gm/ClionProjects/testi/CM.txt"); action_group_menu()->
std::string p = notebook_.directories().GetCmakeVarValue("/home/gm/ClionProjects/testi", "project"); add(Gtk::Action::create("ProjectCompile",
terminal_.CompileAndRun(p); "Compile"),
}); Gtk::AccelKey(keybindings_.config_
.key_map()["compile"]),
this->signal_button_release_event(). [this]() {
connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); 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);
terminal_.Terminal().signal_button_release_event(). terminal_.Terminal().signal_button_release_event().
connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false);
PluginApi::menu_ = &menu_;
PluginApi::notebook_ = &notebook_;
PluginApi::InitPlugins();
add_accel_group(keybindings_.ui_manager_menu()->get_accel_group()); add_accel_group(keybindings_.ui_manager_menu()->get_accel_group());
add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group()); add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group());
keybindings_.BuildMenu(); keybindings_.BuildMenu();

1
juci/window.h

@ -22,6 +22,7 @@ public:
Menu::Controller menu_; Menu::Controller menu_;
Notebook::Controller notebook_; Notebook::Controller notebook_;
Terminal::Controller terminal_; Terminal::Controller terminal_;
PluginApi api_;
Keybindings::Controller& keybindings() { return keybindings_; } Keybindings::Controller& keybindings() { return keybindings_; }
private: private:

Loading…
Cancel
Save