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. 70
      juci/terminal.cc
  4. 9
      juci/terminal.h
  5. 29
      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,
int popup_x,
int popup_y,

1
juci/notebook.h

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

70
juci/terminal.cc

@ -2,14 +2,12 @@
#include <iostream>
#include <thread>
Terminal::View::View(){
scrolledwindow_.add(textview_);
scrolledwindow_.set_size_request(-1,150);
view_.add(scrolledwindow_);
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_ = "";
}
void Terminal::Controller::SetFolderCommand(std::string path) {
int pos = path.find_last_of("/\\");
path.erase(path.begin()+pos,path.end());
folder_command_ = "cd "+ path + "; ";
void Terminal::Controller::SetFolderCommand( boost::filesystem::path
CMake_path) {
path_ = CMake_path.string();
folder_command_ = "cd "+ path_ + "; ";
}
void Terminal::Controller::CompileAndRun(std::string project_name) {
if (folder_command_=="") {
PrintMessage("juCi++ ERROR: Can not find project's CMakeList.txt\n");
} else {
bool Terminal::Controller::Compile(){
if (running.try_lock()) {
std::thread execute([=]() {
Terminal().get_buffer()->set_text("");
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();
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) {
if (running.try_lock()) {
std::thread execute([=]() {
ExecuteCommand("./"+executable);
});
execute.detach();
running.unlock();
}
}
}
void Terminal::Controller::PrintMessage(std::string message){
Terminal().get_buffer()->
insert(Terminal().get_buffer()-> end(),"> "+message);
y 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(" ");
std::cout << "FINNER NY POS" << std::endl;
build = build.substr(pos+1);
std::cout <<"BUILD TARGET = "<< build << std::endl;
std::cout << "EXECUTABLE FILE = "<< executable << std::endl;
if(build != executable) return false;
return true;
}
// 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()->

9
juci/terminal.h

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

29
juci/window.cc

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

Loading…
Cancel
Save