Browse Source

merged

merge-requests/365/head
Jørgen Lien Sellæg 11 years ago
parent
commit
1b098cb320
  1. 4
      juci/api.cc
  2. 15
      juci/api_ext.cc
  3. 33
      juci/config.cc
  4. 7
      juci/config.h
  5. 27
      juci/config.json
  6. 45
      juci/directories.cc
  7. 99
      juci/notebook.cc
  8. 4
      juci/notebook.h
  9. 27
      juci/source.cc
  10. 9
      juci/source.h
  11. 56
      juci/terminal.cc
  12. 17
      juci/terminal.h
  13. 9
      juci/window.cc

4
juci/api.cc

@ -8,9 +8,12 @@ Notebook::Controller* PluginApi::notebook_;
/////////////////////////////
PluginApi::PluginApi(Menu::Controller& menu_ctl_,
Notebook::Controller& notebook_ctl_) {
DEBUG("Adding pointers for the API");
menu_ = &menu_ctl_;
notebook_ = &notebook_ctl_;
DEBUG("Initiating plugins(from plugins.py)..");
InitPlugins();
DEBUG("Plugins initiated..");
}
PluginApi::~PluginApi() {
@ -61,6 +64,7 @@ void PluginApi::InitPlugins() {
}
void PluginApi::AddMenuElement(std::string plugin_name) {
DEBUG("Adding menu element for "+plugin_name);
AddMenuXml(plugin_name, "PluginMenu");
std::string plugin_action_name = plugin_name+"Menu";
menu_->keybindings_.action_group_menu()

15
juci/api_ext.cc

@ -1,15 +0,0 @@
#include "api.h"
BOOST_PYTHON_MODULE(juci_to_python_api) {
using namespace boost::python;
// plugin inclusion
def("addMenuElement", &libjuci::AddMenuElement);
def("addSubMenuElement", &libjuci::AddSubMenuElement);
def("loadPlugin", &libjuci::LoadPlugin);
def("initPlugin", &libjuci::InitPlugin);
// text editing
def("replaceLine", &libjuci::ReplaceLine);
def("replaceWord", &libjuci::ReplaceWord);
def("getWord", &libjuci::GetWord);
} // module::juci_to_python_api

33
juci/config.cc

@ -9,39 +9,55 @@ MainConfig::MainConfig() :
GenerateSource();
GenerateKeybindings();
GenerateDirectoryFilter();
GenerateTerminalCommands();
}
void MainConfig::GenerateSource() {
INFO("Generating source cfg");
DEBUG("Fetching source cfg");
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 colors_json = source_json.get_child("colors");
boost::property_tree::ptree extensions_json = source_json.get_child("extensions");
for (auto &i : colors_json) {
source_cfg_.InsertTag(i.first, i.second.get_value<std::string>());
}
for (auto &i : syntax_json) {
source_cfg_.InsertType(i.first, i.second.get_value<std::string>());
}
INFO("Source cfg generated");
for (auto &i : extensions_json) {
source_cfg_.InsertExtension(i.second.get_value<std::string>());
}
DEBUG("Source cfg fetched");
}
void MainConfig::GenerateTerminalCommands() {
boost::property_tree::ptree source_json = cfg_.get_child("project");
boost::property_tree::ptree compile_commands_json = source_json.get_child("compile_commands");
boost::property_tree::ptree run_commands_json = source_json.get_child("run_commands");
for (auto &i : compile_commands_json) {
terminal_cfg_.InsertCompileCommand(i.second.get_value<std::string>());
}
for (auto &i : run_commands_json) {
terminal_cfg_.SetRunCommand(i.second.get_value<std::string>());
}
}
void MainConfig::GenerateKeybindings() {
INFO("Generating keybindings");
DEBUG("Fetching keybindings");
std::string line;
std::ifstream menu_xml("menu.xml");
if (menu_xml.is_open()) {
while (getline(menu_xml, line)) {
while (getline(menu_xml, line))
keybindings_cfg_.AppendXml(line);
}
}
boost::property_tree::ptree keys_json = cfg_.get_child("keybindings");
for (auto &i : keys_json)
keybindings_cfg_.key_map()[i.first] = i.second.get_value<std::string>();
INFO("Keybindings generated");
DEBUG("Keybindings fetched");
}
void MainConfig::GenerateDirectoryFilter() {
DEBUG("Fetching directory filter");
boost::property_tree::ptree dir_json = cfg_.get_child("directoryfilter");
boost::property_tree::ptree ignore_json = dir_json.get_child("ignore");
boost::property_tree::ptree except_json = dir_json.get_child("exceptions");
@ -49,6 +65,5 @@ void MainConfig::GenerateDirectoryFilter() {
dir_cfg_.AddException(i.second.get_value<std::string>());
for ( auto &i : ignore_json )
dir_cfg_.AddIgnore(i.second.get_value<std::string>());
DEBUG("Directory filter fetched");
}

7
juci/config.h

@ -1,3 +1,5 @@
#ifndef JUCI_CONFIG_H_
#define JUCI_CONFIG_H_
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <fstream>
@ -5,6 +7,7 @@
#include "keybindings.h"
#include "source.h"
#include "directories.h"
#include "terminal.h"
class MainConfig {
public:
@ -12,14 +15,18 @@ public:
Source::Config& source_cfg() { return source_cfg_; }
Keybindings::Config& keybindings_cfg() { return keybindings_cfg_; }
Directories::Config& dir_cfg() { return dir_cfg_; }
Terminal::Config& terminal_cfg() { return terminal_cfg_; }
void PrintMenu();
void GenerateSource();
void GenerateKeybindings();
void GenerateDirectoryFilter();
void GenerateTerminalCommands();
private:
boost::property_tree::ptree cfg_;
boost::property_tree::ptree key_tree_;
Source::Config source_cfg_;
Keybindings::Config keybindings_cfg_;
Directories::Config dir_cfg_;
Terminal::Config terminal_cfg_;
};
#endif

27
juci/config.json

@ -16,7 +16,19 @@
"702": "keyword",
"703": "own",
"705": "comment"
}
},
"extensions": [
"c",
"cc",
"cpp",
"cxx",
"c++",
"h",
"hh",
"hpp",
"hxx",
"h++"
]
},
"keybindings": {
"split_window": "<control><alt>s",
@ -27,7 +39,7 @@
"edit_undo": "<control>z",
"save": "<control>s",
"save_as": "<control><shift>s",
"compile_and_run": "<control><alt>r>",
"compile_and_run": "<control><alt>r",
"compile": "<control>r"
},
"directoryfilter": {
@ -44,6 +56,17 @@
"in-lowercase.pls"
]
},
"project": {
"run_commands": [
"./.build/"
],
"compile_commands": [
"rm -rf ./.build",
"mkdir ./.build",
"cmake -B./.build -H.",
"cd ./.build/; make"
]
},
"example": {
"key": "value",
"key2": [

45
juci/directories.cc

@ -3,6 +3,7 @@
Directories::Controller::Controller(Directories::Config& cfg) :
config_(cfg) {
DEBUG("adding treeview to scrolledwindow");
m_ScrolledWindow.add(m_TreeView);
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
}
@ -13,18 +14,21 @@ open_folder(const boost::filesystem::path& dir_path) {
m_refTreeModel = Gtk::TreeStore::create(view());
m_TreeView.set_model(m_refTreeModel);
m_TreeView.remove_all_columns();
DEBUG("Getting project name from CMakeLists.txt");
std::string project_name = GetCmakeVarValue(dir_path, "project");
m_TreeView.append_column(project_name, view().m_col_name);
int row_id = 0;
Gtk::TreeModel::Row row;
DEBUG("Listing directories");
list_dirs(dir_path, row, row_id);
DEBUG("Sorting directories");
m_refTreeModel->set_sort_column(0, Gtk::SortType::SORT_ASCENDING);
INFO("Folder opened");
DEBUG("Folder opened");
}
bool Directories::Controller::IsIgnored(std::string path) {
DEBUG("Checking if file-/directory is filtered");
std::transform(path.begin(), path.end(), path.begin(), ::tolower);
// std::cout << "ignored?: " << path << std::endl;
if (config().IsException(path)) {
return false;
}
@ -37,12 +41,13 @@ void Directories::Controller::
list_dirs(const boost::filesystem::path& dir_path,
Gtk::TreeModel::Row &parent,
unsigned row_id) {
boost::filesystem::directory_iterator end_itr;
unsigned dir_counter = row_id;
unsigned file_counter = 0;
Gtk::TreeModel::Row child;
Gtk::TreeModel::Row row;
DEBUG("");
// Fill the treeview
for ( boost::filesystem::directory_iterator itr( dir_path );
itr != end_itr;
@ -74,15 +79,17 @@ list_dirs(const boost::filesystem::path& dir_path,
}
}
}
int Directories::Controller::count(const std::string path) {
int count = 0;
for (int i = 0; i < path.size(); i++)
if (path[i] == '/') count++;
if (path[i] == '/')
count++;
return count;
}
std::string Directories::Controller::
GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_name) {
std::string Directories::Controller::
GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_name) {
INFO("fetches cmake variable value for: "+command_name);
std::string project_name;
std::string project_name_var;
@ -149,32 +156,32 @@ int Directories::Controller::count(const std::string path) {
}
INFO("Couldn't find value in CMakeLists.txt");
return "no project name";
}
}
Directories::Config::Config() {
}
Directories::Config::Config(Directories::Config& cfg) :
Directories::Config::Config() {
}
Directories::Config::Config(Directories::Config& cfg) :
ignore_list_(cfg.ignore_list()), exception_list_(cfg.exception_list()) {
}
}
void Directories::Config::AddIgnore(std::string filter) {
void Directories::Config::AddIgnore(std::string filter) {
ignore_list_.push_back(filter);
}
}
void Directories::Config::AddException(std::string filter) {
void Directories::Config::AddException(std::string filter) {
exception_list_.push_back(filter);
}
}
bool Directories::Config::IsIgnored(std::string str) {
bool Directories::Config::IsIgnored(std::string str) {
for ( auto &i : ignore_list() )
if (str.find(i, 0) != std::string::npos)
return true;
return false;
}
}
bool Directories::Config::IsException(std::string str) {
bool Directories::Config::IsException(std::string str) {
for ( std::string &i : exception_list() )
if (i == str)
return true;
return false;
}
}

99
juci/notebook.cc

@ -1,10 +1,10 @@
#include <fstream>
#include "notebook.h"
#include "logging.h"
#include <fstream>
Notebook::Model::Model() {
cc_extension_ = ".cc";
h_extension_ = ".h";
cc_extension_ = ".cpp";
h_extension_ = ".hpp";
scrollvalue_ = 50;
}
@ -13,10 +13,10 @@ Notebook::View::View() : notebook_() {
view_.set_position(120);
}
Notebook::Controller::Controller(Gtk::Window* window, Keybindings::Controller& keybindings,
Notebook::Controller::Controller(Gtk::Window* window,
Keybindings::Controller& keybindings,
Source::Config& source_cfg,
Directories::Config& dir_cfg) :
source_config_(source_cfg),
directories_(dir_cfg),
index_(0, 1) {
INFO("Create notebook");
@ -25,12 +25,15 @@ Notebook::Controller::Controller(Gtk::Window* window, Keybindings::Controller& k
refClipboard_ = Gtk::Clipboard::get();
ispopup = false;
view().pack1(directories_.widget(), true, true);
source_config_ = source_cfg;
CreateKeybindings(keybindings);
INFO("Notebook Controller Success");
} // Constructor
void Notebook::Controller::CreateKeybindings(Keybindings::Controller
&keybindings) {
INFO("Notebook create signal handlers");
directories().m_TreeView.signal_row_activated()
.connect(sigc::mem_fun(*this,
&Notebook::Controller::OnDirectoryNavigation));
@ -140,6 +143,7 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
[this]() {
Search(false);
});
INFO("Notebook signal handlers sucsess");
}
bool Notebook::Controller:: OnMouseRelease(GdkEventButton* button) {
@ -155,6 +159,9 @@ bool Notebook::Controller::OnKeyRelease(GdkEventKey* key) {
}
bool Notebook::Controller::GeneratePopup(int key_id) {
INFO("Notebook genereate popup, getting iters");
std::string path = text_vec_.at(CurrentPage())->path();
if (!LegalExtension(path.substr(path.find_last_of(".") + 1))) return false;
// Get function to fill popup with suggests item vector under is for testing
Gtk::TextIter beg = CurrentTextView().get_buffer()->get_insert()->get_iter();
Gtk::TextIter end = CurrentTextView().get_buffer()->get_insert()->get_iter();
@ -167,6 +174,7 @@ bool Notebook::Controller::GeneratePopup(int key_id) {
end.backward_search("\"", Gtk::TEXT_SEARCH_VISIBLE_ONLY, tmp, tmp1, line)
||
end.backward_search("//", Gtk::TEXT_SEARCH_VISIBLE_ONLY, tmp, tmp1, line);
INFO("Notebook genereate popup, checking key_id");
if (illegal_chars) {
return false;
}
@ -189,6 +197,7 @@ bool Notebook::Controller::GeneratePopup(int key_id) {
} else {
return false;
}
INFO("Notebook genereate popup, getting autocompletions");
std::vector<Source::AutoCompleteData> acdata;
text_vec_.at(CurrentPage())->
GetAutoCompleteSuggestions(beg.get_line()+1,
@ -229,16 +238,19 @@ bool Notebook::Controller::GeneratePopup(int key_id) {
popup_.get_vbox()->pack_start(popup_scroll_);
popup_.set_transient_for(*window_);
popup_.show_all();
INFO("Notebook genereate popup, moving popup");
int popup_x = popup_.get_width();
int popup_y = items.size() * 20;
PopupSetSize(popup_scroll_, popup_x, popup_y);
int x, y;
FindPopupPosition(CurrentTextView(), popup_x, popup_y, x, y);
popup_.move(x, y+15);
INFO("Notebook genereate popup, create handler");
PopupSelectHandler(popup_, listview_, &items);
ispopup = true;
INFO("Notebook genereate popup, run popup");
popup_.run();
INFO("Notebook genereate popup, hide popup");
popup_.hide();
ispopup = false;
return true;
@ -261,6 +273,7 @@ bool Notebook::Controller::ScrollEventCallback(GdkEventScroll* scroll_event) {
return true;
}
Notebook::Controller::~Controller() {
INFO("Notebook destructor");
for (auto &i : text_vec_) delete i;
for (auto &i : linenumbers_vec_) delete i;
for (auto &i : editor_vec_) delete i;
@ -276,6 +289,7 @@ Gtk::Box& Notebook::Controller::entry_view() {
}
void Notebook::Controller::OnNewPage(std::string name) {
INFO("Notebook Generate new page");
OnCreatePage();
text_vec_.back()->OnNewEmptyFile();
Notebook().append_page(*editor_vec_.back(), name);
@ -294,6 +308,7 @@ MapBuffers(std::map<std::string, std::string> *buffers) {
}
void Notebook::Controller::OnOpenFile(std::string path) {
INFO("Notebook open file");
OnCreatePage();
text_vec_.back()->OnOpenFile(path);
text_vec_.back()->set_is_saved(true);
@ -303,12 +318,11 @@ void Notebook::Controller::OnOpenFile(std::string path) {
Notebook().set_current_page(Pages()-1);
Notebook().set_focus_child(text_vec_.back()->view());
OnBufferChange();
text_vec_.back()->set_is_changed(false);
}
void Notebook::Controller::OnCreatePage() {
INFO("Notebook create page");
text_vec_.push_back(new Source::Controller(source_config(), this));
linenumbers_vec_.push_back(new Source::Controller(source_config(), this));
scrolledline_vec_.push_back(new Gtk::ScrolledWindow());
@ -329,9 +343,11 @@ void Notebook::Controller::OnCreatePage() {
}
void Notebook::Controller::OnCloseCurrentPage() {
// TODO(oyvang) zalox, forgi)
// Save a temp file, in case you close one you dont want to close?
INFO("Notebook close page");
if (Pages() != 0) {
if(text_vec_.back()->is_changed()){
AskToSaveDialog();
}
int page = CurrentPage();
Notebook().remove_page(page);
delete text_vec_.at(page);
@ -372,6 +388,7 @@ void Notebook::Controller::OnEditCut() {
}
std::string Notebook::Controller::GetCursorWord() {
INFO("Notebook get cursor word");
int page = CurrentPage();
std::string word;
Gtk::TextIter start, end;
@ -399,6 +416,7 @@ void Notebook::Controller::OnEditSearch() {
}
void Notebook::Controller::Search(bool forward) {
INFO("Notebook search");
int page = CurrentPage();
std::string search_word;
search_word = entry_.text();
@ -456,10 +474,12 @@ void Notebook::Controller::OnBufferChange() {
ScrollEventCallback(scroll);
delete scroll;
}
text_vec_.at(page)->set_is_changed(true);
}
void Notebook::Controller
::OnDirectoryNavigation(const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn* column) {
INFO("Notebook directory navigation");
Gtk::TreeModel::iterator iter = directories().m_refTreeModel->get_iter(path);
if (iter) {
Gtk::TreeModel::Row row = *iter;
@ -539,6 +559,7 @@ void Notebook::Controller::PopupSelectHandler(Gtk::Dialog &popup,
void Notebook::Controller::PopupSetSize(Gtk::ScrolledWindow &scroll,
int &current_x,
int &current_y) {
INFO("Notebook popup set size");
int textview_x = CurrentTextView().get_width();
int textview_y = 150;
bool is_never_scroll_x = true;
@ -573,6 +594,7 @@ void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview,
int popup_y,
int &x,
int &y) {
INFO("Notebook popup find position");
Gdk::Rectangle temp1, temp2;
textview.get_cursor_locations(
CurrentTextView().
@ -602,6 +624,7 @@ void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview,
}
void Notebook::Controller:: OnSaveFile() {
INFO("Notebook save file");
if (text_vec_.at(CurrentPage())->is_saved()) {
std::ofstream file;
file.open (text_vec_.at(CurrentPage())->path());
@ -622,16 +645,23 @@ void Notebook::Controller:: OnSaveFile() {
std::string Notebook::Controller::OnSaveFileAs(){
INFO("Notebook save as");
Gtk::FileChooserDialog dialog("Please choose a file",
Gtk::FILE_CHOOSER_ACTION_SAVE);
DEBUG("SET TRANSISTEN FPR");
dialog.set_transient_for(*window_);
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
dialog.add_button("_Save", Gtk::RESPONSE_OK);
//dialog.set_current_name("Untitled");
DEBUG("RUN DIALOG");
int result = dialog.run();
DEBUG("DIALOG RUNNING");
switch (result) {
case(Gtk::RESPONSE_OK): {
DEBUG("get_filename()");
std::string path = dialog.get_filename();
DEBUG_VAR(path);
unsigned pos = path.find_last_of("/\\");
std::cout << path<< std::endl;
//notebook_.OnSaveFile(path);
@ -649,3 +679,50 @@ std::string Notebook::Controller::OnSaveFileAs(){
return "";
}
void Notebook::Controller::AskToSaveDialog() {
INFO("AskToSaveDialog");
DEBUG("AskToSaveDialog: Finding file path");
Gtk::MessageDialog dialog(*window_, "Save file!",
false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_secondary_text(
"Do you want to save: " +
text_vec_.at(CurrentPage())->path()+" ?");
DEBUG("AskToSaveDialog: run dialog");
int result = dialog.run();
//Handle the response:
DEBUG("AskToSaveDialog: switch response");
switch(result)
{
case(Gtk::RESPONSE_YES):
{
DEBUG("AskToSaveDialog: save file: yes, trying to save file");
OnSaveFile();
DEBUG("AskToSaveDialog: save file: yes, saved sucess");
break;
}
case(Gtk::RESPONSE_NO):
{
DEBUG("AskToSaveDialog: save file: no");
break;
}
default:
{
DEBUG("AskToSaveDialog: unexpected action: Default switch");
break;
}
}
}
bool Notebook::Controller::LegalExtension(std::string e) {
std::transform(e.begin(), e.end(),e.begin(), ::tolower);
std::vector<std::string> extensions =
source_config().extensiontable();
if (find(extensions.begin(), extensions.end(), e) != extensions.end()) {
DEBUG("Legal extension");
return true;
}
DEBUG("Ilegal extension");
return false;
}

4
juci/notebook.h

@ -68,7 +68,7 @@ namespace Notebook {
Gtk::Paned& view();
bool GeneratePopup(int key);
void Search(bool forward);
const Source::Config& source_config() { return source_config_; }
Source::Config& source_config() { return source_config_; }
bool OnMouseRelease(GdkEventButton* button);
bool OnKeyRelease(GdkEventKey* key);
std::string OnSaveFileAs();
@ -88,6 +88,8 @@ namespace Notebook {
void PopupSetSize(Gtk::ScrolledWindow& scroll,
int &current_x,
int &current_y);
void AskToSaveDialog();
bool LegalExtension(std::string extension);
Glib::RefPtr<Gtk::Builder> m_refBuilder;
Glib::RefPtr<Gio::SimpleActionGroup> refActionGroup;
Source::Config source_config_;

27
juci/source.cc

@ -70,9 +70,18 @@ const std::unordered_map<string, string>& Source::Config::typetable() const {
return typetable_;
}
std::vector<string>& Source::Config::extensiontable(){
return extensiontable_;
}
void Source::Config::InsertTag(const string &key, const string &value) {
tagtable_[key] = value;
}
void Source::Config::InsertExtension(const string &ext) {
extensiontable_.push_back(ext);
}
// Source::View::Config::SetTagTable()
// sets the tagtable for the view
void Source::Config::
@ -295,21 +304,6 @@ string extract_file_path(const std::string &file_path) {
return file_path.substr(0, file_path.find_last_of('/'));
}
std::vector<std::string> extentions() {
return {".h", ".cc", ".cpp", ".hpp"};
}
bool check_extention(const std::string &file_path) {
std::string extention = file_path.substr(file_path.find_last_of('.'),
file_path.size());
for (auto &ex : extentions()) {
if (extention == ex) {
return true;
}
}
return false;
}
void Source::View::OnUpdateSyntax(const std::vector<Source::Range> &ranges,
const Source::Config &config) {
if (ranges.empty() || ranges.size() == 0) {
@ -349,7 +343,7 @@ void Source::Controller::OnOpenFile(const string &filepath) {
buffer()->set_text(s.get_content());
int start_offset = buffer()->begin().get_offset();
int end_offset = buffer()->end().get_offset();
if (check_extention(filepath)) {
if (!notebook_->LegalExtension(filepath.substr(filepath.find_last_of(".") + 1))) {
view().ApplyConfig(model().config());
model().InitSyntaxHighlighting(filepath,
extract_file_path(filepath),
@ -360,7 +354,6 @@ void Source::Controller::OnOpenFile(const string &filepath) {
view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset),
model().config());
buffer()->signal_end_user_action().connect([this]() {
if (!go) {
std::thread parse([this]() {

9
juci/source.h

@ -20,16 +20,19 @@ namespace Source {
Config();
const std::unordered_map<std::string, std::string>& tagtable() const;
const std::unordered_map<std::string, std::string>& typetable() const;
std::vector<std::string>& extensiontable();
void SetTagTable(const std::unordered_map<std::string, std::string>
&tagtable);
void InsertTag(const std::string &key, const std::string &value);
void SetTypeTable(const std::unordered_map<std::string, std::string>
&tagtable);
void InsertType(const std::string &key, const std::string &value);
void InsertExtension(const std::string &ext);
std::vector<std::string> extensiontable_;
private:
std::unordered_map<std::string, std::string> tagtable_;
std::unordered_map<std::string, std::string> typetable_;
std::string background_;
}; // class Config
@ -150,11 +153,12 @@ namespace Source {
*suggestions);
Glib::RefPtr<Gtk::TextBuffer> buffer();
bool is_saved() { return is_saved_; }
bool is_changed() { return is_changed_; }
std::string path() { return model().file_path(); }
void set_is_saved(bool isSaved) { is_saved_ = isSaved; }
void set_is_changed(bool isChanged) { is_changed_ = isChanged; }
void set_file_path(std::string path) { model().set_file_path(path); }
private:
void OnLineEdit();
void OnSaveFile();
@ -162,6 +166,7 @@ namespace Source {
std::mutex parsing;
bool go = false;
bool is_saved_ = false;
bool is_changed_ = false;
protected:
View view_;

56
juci/terminal.cc

@ -1,10 +1,26 @@
#include "terminal.h"
#include <iostream>
#include <thread>
// #include <pstream.h>
// #include <string>
#include "logging.h"
Terminal::Config::Config() {
}
Terminal::Config::Config(Terminal::Config& original) :
run_command_(original.run_command_){
for (auto it = 0; it<original.compile_commands().size(); ++it) {
InsertCompileCommand(original.compile_commands().at(it));
}
}
void Terminal::Config::InsertCompileCommand(std::string command){
compile_commands_.push_back(command);
}
void Terminal::Config::SetRunCommand(std::string command){
run_command_ = command;
}
Terminal::View::View(){
scrolledwindow_.add(textview_);
scrolledwindow_.set_size_request(-1,150);
@ -13,36 +29,51 @@ Terminal::View::View(){
}
Terminal::Controller::Controller() {
Terminal::Controller::Controller(Terminal::Config& cfg) :
config_(cfg) {
folder_command_ = "";
}
void Terminal::Controller::SetFolderCommand( boost::filesystem::path
CMake_path) {
INFO("Terminal: SetFolderCommand");
path_ = CMake_path.string();
folder_command_ = "cd "+ path_ + "; ";
}
void Terminal::Controller::Compile(){
INFO("Terminal: Compile");
Terminal().get_buffer()->set_text("");
ExecuteCommand("cmake .", "r");
if (ExistInConsole(cmake_sucsess)){
ExecuteCommand("make", "r");
DEBUG("Terminal: Compile: running cmake command");
std::vector<std::string> commands = config().compile_commands();
for (auto it = 0; it < commands.size(); ++it) {
ExecuteCommand(commands.at(it), "r");
}
PrintMessage("\n");
DEBUG("Terminal: Compile: compile done");
}
void Terminal::Controller::Run(std::string executable) {
INFO("Terminal: Run");
PrintMessage("juCi++ execute: " + executable + "\n");
ExecuteCommand("./"+executable, "r");
DEBUG("Terminal: Compile: running run command: ");
DEBUG_VAR(executable);
ExecuteCommand("cd "+config().run_command() + "; ./"+executable, "r");
PrintMessage("\n");
}
void Terminal::Controller::PrintMessage(std::string message){
INFO("Terminal: PrintMessage");
Terminal().get_buffer()->
insert(Terminal().get_buffer()-> end(),"> "+message);
}
bool Terminal::Controller::ExistInConsole(std::string string) {
INFO("Terminal: ExistInConsole");
DEBUG("Terminal: PrintMessage: finding string in buffer");
double pos = Terminal().get_buffer()->
get_text().find(string);
if (pos == std::string::npos) return false;
@ -50,17 +81,22 @@ bool Terminal::Controller::ExistInConsole(std::string string) {
}
void Terminal::Controller::ExecuteCommand(std::string command, std::string mode) {
INFO("Terminal: ExecuteCommand");
command = folder_command_+command;
std::cout << "EXECUTE COMMAND: "<< command << std::endl;
FILE* p = popen(command.c_str(), mode.c_str());
DEBUG("Terminal: PrintMessage: Running command");
FILE* p = NULL;
std::cout << command << std::endl;
p = popen(command.c_str(), mode.c_str());
std::cout << "KJØRTE FINT!" << std::endl;
if (p == NULL) {
PrintMessage("juCi++ ERROR: Failed to run command" + command + "\n");
}else {
std::cout << "SKRIVER UT KOMMANDO RESULAT" << std::endl;
char buffer[1028];
while (fgets(buffer, 1028, p) != NULL) {
PrintMessage(buffer);
}
pclose(p);
}
}

17
juci/terminal.h

@ -7,6 +7,19 @@
namespace Terminal {
class Config {
public:
Config ();
Config(Terminal::Config& original);
std::vector<std::string>& compile_commands() { return compile_commands_; }
void InsertCompileCommand(std::string command);
std::string& run_command() { return run_command_; }
void SetRunCommand(std::string command);
private:
std::vector<std::string> compile_commands_;
std::string run_command_;
};
class View {
public:
View();
@ -20,13 +33,15 @@ namespace Terminal {
class Controller {
public:
Controller();
Controller(Terminal::Config& cfg);
Gtk::HBox& view() {return view_.view();}
Gtk::TextView& Terminal(){return view_.textview();}
void SetFolderCommand(boost::filesystem::path CMake_path);
void Run(std::string executable);
void Compile();
Terminal::Config& config() { return config_; }
private:
Terminal::Config config_;
void ExecuteCommand(std::string command, std::string mode);
bool OnButtonRealeaseEvent(GdkEventKey* key);
bool ExistInConsole(std::string string);

9
juci/window.cc

@ -5,6 +5,7 @@ Window::Window() :
window_box_(Gtk::ORIENTATION_VERTICAL),
main_config_(),
keybindings_(main_config_.keybindings_cfg()),
terminal_(main_config_.terminal_cfg()),
notebook_(this,keybindings(),
main_config_.source_cfg(),
main_config_.dir_cfg()),
@ -54,12 +55,12 @@ Window::Window() :
Gtk::AccelKey(keybindings_.config_
.key_map()["compile_and_run"]),
[this]() {
notebook_.OnSaveFile();
if (running.try_lock()) {
std::thread execute([=]() {
notebook_.OnSaveFile();
std::string path = notebook_.CurrentPagePath();
int pos = path.find_last_of("/\\");
if(pos != std::string::npos){
if(pos != std::string::npos) {
path.erase(path.begin()+pos,path.end());
terminal_.SetFolderCommand(path);
}
@ -80,9 +81,9 @@ Window::Window() :
Gtk::AccelKey(keybindings_.config_
.key_map()["compile"]),
[this]() {
notebook_.OnSaveFile();
if (running.try_lock()) {
std::thread execute([=]() {
notebook_.OnSaveFile();
std::string path = notebook_.CurrentPagePath();
int pos = path.find_last_of("/\\");
if(pos != std::string::npos){
@ -95,7 +96,6 @@ Window::Window() :
running.unlock();
}
});
this->signal_button_release_event().
connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false);
terminal_.Terminal().signal_button_release_event().
@ -122,7 +122,6 @@ void Window::OnWindowHide() {
void Window::OnFileOpenFolder() {
Gtk::FileChooserDialog dialog("Please choose a folder",
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
dialog.set_transient_for(*this);
//Add response buttons the the dialog:
dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);

Loading…
Cancel
Save