Browse Source

doin it

master
tedjk 11 years ago
parent
commit
5ebfb3f489
  1. 4
      juci/notebook.cc
  2. 1
      juci/notebook.h
  3. 96
      juci/terminal.cc
  4. 9
      juci/terminal.h
  5. 366
      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); 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";

366
juci/window.cc

@ -1,179 +1,187 @@
#include "window.h" #include "window.h"
Window::Window() : 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(), main_config_.source_cfg(), main_config_.dir_cfg()),
menu_(keybindings()) { menu_(keybindings()) {
set_title("juCi++"); set_title("juCi++");
set_default_size(600, 400); set_default_size(600, 400);
add(window_box_); add(window_box_);
keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit",
Gtk::Stock::QUIT), Gtk::Stock::QUIT),
[this]() { [this]() {
OnWindowHide(); OnWindowHide();
}); });
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile",
Gtk::Stock::OPEN), Gtk::Stock::OPEN),
[this]() { [this]() {
OnOpenFile(); OnOpenFile();
}); });
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder",
"Open folder"), "Open folder"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings_.config_
.key_map()["open_folder"]), .key_map()["open_folder"]),
[this]() { [this]() {
OnFileOpenFolder(); OnFileOpenFolder();
}); });
keybindings_.action_group_menu()->add(Gtk::Action::create("FileSaveAs", keybindings_.action_group_menu()->add(Gtk::Action::create("FileSaveAs",
"Save as"), "Save as"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings_.config_
.key_map()["save_as"]), .key_map()["save_as"]),
[this]() { [this]() {
notebook_.OnSaveFile(); notebook_.OnSaveFile();
}); });
keybindings_.action_group_menu()->add(Gtk::Action::create("FileSave", keybindings_.action_group_menu()->add(Gtk::Action::create("FileSave",
"Save"), "Save"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings_.config_
.key_map()["save"]), .key_map()["save"]),
[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();
terminal_.Terminal().signal_button_release_event(). std::string path =
connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); notebook_.CurrentPagePath();
terminal_.SetFolderCommand(path);
PluginApi::menu_ = &menu_; terminal_.Compile();
PluginApi::notebook_ = &notebook_; });
PluginApi::InitPlugins();
this->signal_button_release_event().
add_accel_group(keybindings_.ui_manager_menu()->get_accel_group()); connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false);
add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group()); terminal_.Terminal().signal_button_release_event().
keybindings_.BuildMenu(); connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false);
window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); PluginApi::menu_ = &menu_;
window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK); PluginApi::notebook_ = &notebook_;
window_box_.pack_start(notebook_.view()); PluginApi::InitPlugins();
window_box_.pack_end(terminal_.view(),Gtk::PACK_SHRINK);
show_all_children(); add_accel_group(keybindings_.ui_manager_menu()->get_accel_group());
} // Window constructor add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group());
keybindings_.BuildMenu();
void Window::OnWindowHide() {
hide(); window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK);
} window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK);
void Window::OnFileOpenFolder() { window_box_.pack_start(notebook_.view());
Gtk::FileChooserDialog dialog("Please choose a folder", window_box_.pack_end(terminal_.view(),Gtk::PACK_SHRINK);
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); show_all_children();
} // Window constructor
dialog.set_transient_for(*this);
//Add response buttons the the dialog: void Window::OnWindowHide() {
dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL); hide();
dialog.add_button("Select", Gtk::RESPONSE_OK); }
void Window::OnFileOpenFolder() {
int result = dialog.run(); Gtk::FileChooserDialog dialog("Please choose a folder",
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
//Handle the response:
switch(result) dialog.set_transient_for(*this);
{ //Add response buttons the the dialog:
case(Gtk::RESPONSE_OK): dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
{ dialog.add_button("Select", Gtk::RESPONSE_OK);
std::cout << "Folder selected: " << dialog.get_filename()
<< std::endl; int result = dialog.run();
notebook_.directories().open_folder(dialog.get_filename());
std::cout << dialog.get_filename()<< std::endl; //Handle the response:
break; switch(result)
} {
case(Gtk::RESPONSE_CANCEL): case(Gtk::RESPONSE_OK):
{ {
std::cout << "Cancel clicked." << std::endl; std::cout << "Folder selected: " << dialog.get_filename()
break; << std::endl;
} notebook_.directories().open_folder(dialog.get_filename());
default: std::cout << dialog.get_filename()<< std::endl;
{ break;
std::cout << "Unexpected button clicked." << std::endl; }
break; case(Gtk::RESPONSE_CANCEL):
} {
} std::cout << "Cancel clicked." << std::endl;
} break;
}
default:
void Window::OnOpenFile() { {
Gtk::FileChooserDialog dialog("Please choose a file", std::cout << "Unexpected button clicked." << std::endl;
Gtk::FILE_CHOOSER_ACTION_OPEN); break;
dialog.set_transient_for(*this); }
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); }
}
//Add response buttons the the dialog:
dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
dialog.add_button("_Open", Gtk::RESPONSE_OK); void Window::OnOpenFile() {
Gtk::FileChooserDialog dialog("Please choose a file",
//Add filters, so that only certain file types can be selected: Gtk::FILE_CHOOSER_ACTION_OPEN);
Glib::RefPtr<Gtk::FileFilter> filter_text = Gtk::FileFilter::create(); dialog.set_transient_for(*this);
filter_text->set_name("Text files"); dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
filter_text->add_mime_type("text/plain");
dialog.add_filter(filter_text); //Add response buttons the the dialog:
dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
Glib::RefPtr<Gtk::FileFilter> filter_cpp = Gtk::FileFilter::create(); dialog.add_button("_Open", Gtk::RESPONSE_OK);
filter_cpp->set_name("C/C++ files");
filter_cpp->add_mime_type("text/x-c"); //Add filters, so that only certain file types can be selected:
filter_cpp->add_mime_type("text/x-c++"); Glib::RefPtr<Gtk::FileFilter> filter_text = Gtk::FileFilter::create();
filter_cpp->add_mime_type("text/x-c-header"); filter_text->set_name("Text files");
dialog.add_filter(filter_cpp); filter_text->add_mime_type("text/plain");
dialog.add_filter(filter_text);
Glib::RefPtr<Gtk::FileFilter> filter_any = Gtk::FileFilter::create();
filter_any->set_name("Any files"); Glib::RefPtr<Gtk::FileFilter> filter_cpp = Gtk::FileFilter::create();
filter_any->add_pattern("*"); filter_cpp->set_name("C/C++ files");
dialog.add_filter(filter_any); filter_cpp->add_mime_type("text/x-c");
filter_cpp->add_mime_type("text/x-c++");
int result = dialog.run(); filter_cpp->add_mime_type("text/x-c-header");
dialog.add_filter(filter_cpp);
switch (result) {
case(Gtk::RESPONSE_OK): { Glib::RefPtr<Gtk::FileFilter> filter_any = Gtk::FileFilter::create();
std::cout << "Open clicked." << std::endl; filter_any->set_name("Any files");
std::string path = dialog.get_filename(); filter_any->add_pattern("*");
dialog.add_filter(filter_any);
std::cout << "File selected: " << path << std::endl;
notebook_.OnOpenFile(path); int result = dialog.run();
break;
} switch (result) {
case(Gtk::RESPONSE_CANCEL): { case(Gtk::RESPONSE_OK): {
std::cout << "Cancel clicked." << std::endl; std::cout << "Open clicked." << std::endl;
break; std::string path = dialog.get_filename();
}
default: { std::cout << "File selected: " << path << std::endl;
std::cout << "Unexpected button clicked." << std::endl; notebook_.OnOpenFile(path);
break; break;
} }
} case(Gtk::RESPONSE_CANCEL): {
} std::cout << "Cancel clicked." << std::endl;
bool Window::OnMouseRelease(GdkEventButton *button){ break;
return notebook_.OnMouseRelease(button); }
} default: {
std::cout << "Unexpected button clicked." << std::endl;
break;
}
}
}
bool Window::OnMouseRelease(GdkEventButton *button){
return notebook_.OnMouseRelease(button);
}

Loading…
Cancel
Save