Browse Source

Fiked Terminal compile and run functions

master
oyvang 11 years ago
parent
commit
129ef27155
  1. 4
      juci/notebook.cc
  2. 1
      juci/notebook.h
  3. 96
      juci/terminal.cc
  4. 9
      juci/terminal.h
  5. 57
      juci/window.cc

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);

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); y 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";

57
juci/window.cc

@ -43,30 +43,39 @@ Window::Window() :
notebook_.OnSaveFile(); notebook_.OnSaveFile();
}); });
keybindings_.action_group_menu()->add(Gtk::Action::create("ProjectCompileAndRun", keybindings_.
"Compile And Run"), action_group_menu()->
Gtk::AccelKey(keybindings_.config_ add(Gtk::Action::create("ProjectCompileAndRun",
.key_map()["compile_and_run"]), "Compile And Run"),
[this]() { Gtk::AccelKey(keybindings_.config_
terminal_. .key_map()["compile_and_run"]),
SetFolderCommand("/home/gm/ClionProjects/testi/CM.txt"); [this]() {
std::string p = notebook_.directories().get_project_name("/home/gm/ClionProjects/testi"); notebook_.OnSaveFile();
terminal_.CompileAndRun(p); std::string path = notebook_.CurrentPagePath();
}); terminal_.SetFolderCommand(path);
if(terminal_.Compile()) {
keybindings_.action_group_menu()->add(Gtk::Action::create("ProjectCompile", std::string executable = notebook_.directories().
"Compile"), getCmakeVarValue(path,"add_executable(");
Gtk::AccelKey(keybindings_.config_ terminal_.Run(executable)
.key_map()["compile"]), }
[this]() { });
terminal_.
SetFolderCommand("/home/gm/ClionProjects/testi/CM.txt"); keybindings_.
std::string p = notebook_.directories().get_project_name("/home/gm/ClionProjects/testi"); action_group_menu()->
terminal_.CompileAndRun(p); add(Gtk::Action::create("ProjectCompile",
}); "Compile"),
Gtk::AccelKey(keybindings_.config_
this->signal_button_release_event(). .key_map()["compile"]),
connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); [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);
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);

Loading…
Cancel
Save