Browse Source

Merged

master
Jørgen Lien Sellæg 11 years ago
parent
commit
f32a1b9327
  1. 4
      juci/CMakeLists.txt
  2. 25
      juci/api.cc
  3. 6
      juci/api.h
  4. 5
      juci/api_ext.cc
  5. 13
      juci/config.cc
  6. 131
      juci/directories.cc
  7. 2
      juci/directories.h
  8. 4
      juci/notebook.cc
  9. 1
      juci/notebook.h
  10. 6
      juci/plugins.py
  11. 96
      juci/terminal.cc
  12. 9
      juci/terminal.h
  13. 370
      juci/window.cc
  14. 1
      juci/window.h

4
juci/CMakeLists.txt

@ -132,8 +132,8 @@ link_directories(
${LIBCLANG_LIBRARY_DIRS}
)
#module:
set_target_properties(${module} PROPERTIES PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "/usr/lib/python2.7/dist-packages/")
set_target_properties(${module} PROPERTIES PREFIX "")
# LIBRARY_OUTPUT_DIRECTORY "/usr/lib/python2.7/dist-packages/")
target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
#executable:
target_link_libraries(${project_name} ${LIVCLANG_LIBRARIES} ${LCL_LIBRARIES} ${GTKMM_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})

25
juci/api.cc

@ -5,6 +5,20 @@ Notebook::Controller* PluginApi::notebook_;
/////////////////////////////
//// API ServiceProvider ////
/////////////////////////////
PluginApi::PluginApi(Menu::Controller& menu_ctl_,
Notebook::Controller& notebook_ctl_) {
menu_ = &menu_ctl_;
notebook_ = &notebook_ctl_;
InitPlugins();
}
PluginApi::~PluginApi() {
delete menu_;
delete notebook_;
menu_ = NULL;
notebook_ = NULL;
}
std::string PluginApi::ProjectPath() {
int MAXPATHLEN = 50;
char temp[MAXPATHLEN];
@ -107,7 +121,7 @@ void libjuci::ReplaceWord(const std::string word) {
}
void libjuci::ReplaceLine(const std::string line) {
std::cout << "unimplemented function: 'libjuci::ReplaceLine()' called"
std::cout << "unimplemented: " << __func__ << " called"
<< std::endl;
}
std::string libjuci::GetWord() {
@ -201,16 +215,7 @@ void libjuci::IterToWordEnd(Gtk::TextIter &iter) {
}
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_
// ->source_vec_.at(i)
// ->view().get_buffer());
->CurrentTextView().get_buffer());
}

6
juci/api.h

@ -12,6 +12,8 @@
////////////////////
class PluginApi {
public:
PluginApi(Menu::Controller&, Notebook::Controller&);
~PluginApi();
static Menu::Controller* menu_;
static Notebook::Controller* notebook_;
static void InitPlugins();
@ -25,7 +27,6 @@ public:
const std::string menu_func_name,
const std::string plugin_path,
const std::string menu_keybinding);
// text-buffer functions
static void ReplaceWord(const std::string word);
static void ReplaceLine(const std::string line);
protected:
@ -64,11 +65,10 @@ namespace libjuci {
namespace bp = boost::python;
bp::api::object OpenPythonScript(const std::string path,
bp::api::object python_name_space);
void LoadPlugin(const std::string& plugin_name);
void LoadPluginFunction(const std::string &function_name,
const std::string &plugin_path);
void InitPlugin(const std::string& plugin_path);
} // libjuci
} // namespace libjuci
#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("replaceWord", &libjuci::ReplaceWord);
def("getWord", &libjuci::GetWord);
//something more
}// module::juci_to_python_api
} // module::juci_to_python_api

13
juci/config.cc

@ -6,20 +6,17 @@ MainConfig::MainConfig() :
GenerateSource();
GenerateKeybindings();
GenerateDirectoryFilter();
// keybindings_cfg_ = cfg_.get_child("keybindings");
// notebook_cfg_ = cfg_.get_child("notebook");
// menu_cfg_ = cfg_.get_child("menu");
}
void MainConfig::GenerateSource() {
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");
for ( auto &i : colors_json ) {
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>());
for (auto &i : syntax_json) {
source_cfg_.InsertType(i.first, i.second.get_value<std::string>());
}
}
@ -40,9 +37,9 @@ void MainConfig::GenerateDirectoryFilter() {
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");
for ( auto &i : except_json )
for ( auto &i : except_json )
dir_cfg_.AddException(i.second.get_value<std::string>());
for ( auto &i : ignore_json )
for ( auto &i : ignore_json )
dir_cfg_.AddIgnore(i.second.get_value<std::string>());
}

131
juci/directories.cc

@ -11,7 +11,7 @@ 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();
std::string project_name = get_project_name(dir_path);
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;
@ -77,79 +77,80 @@ int Directories::Controller::count(const std::string path) {
if (path[i] == '/') count++;
return count;
}
std::string Directories::Controller::
get_project_name(const boost::filesystem::path& dir_path) {
std::string project_name;
std::string project_name_var;
boost::filesystem::directory_iterator end_itr;
for (boost::filesystem::directory_iterator itr( dir_path );
itr != end_itr;
++itr ) {
if (itr->path().filename().string() == "CMakeLists.txt") {
std::ifstream ifs(itr->path().string());
std::string line;
while (std::getline(ifs, line)) {
if (line.find("project(", 0) != std::string::npos
|| line.find("project (", 0) != std::string::npos ) {
size_t variabel_start = line.find("{", 0);
size_t variabel_end = line.find("}", variabel_start);
project_name_var = line.substr(variabel_start+1,
(variabel_end)-variabel_start-1);
boost::algorithm::trim(project_name_var);
if (variabel_start == std::string::npos) { // not a variabel
variabel_start = line.find("(", 0);
variabel_end = line.find(")", variabel_start);
return line.substr(variabel_start+1,
(variabel_end)-variabel_start-1);
std::string Directories::Controller::
GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_name) {
std::string project_name;
std::string project_name_var;
boost::filesystem::directory_iterator end_itr;
for (boost::filesystem::directory_iterator itr( dir_path );
itr != end_itr;
++itr ) {
if (itr->path().filename().string() == "CMakeLists.txt") {
std::ifstream ifs(itr->path().string());
std::string line;
while (std::getline(ifs, line)) {
if (line.find(command_name+"(", 0) != std::string::npos
|| line.find(command_name+" (", 0) != std::string::npos ) {
size_t variable_start = line.find("{", 0);
size_t variable_end = line.find("}", variable_start);
project_name_var = line.substr(variable_start+1,
(variable_end)-variable_start-1);
boost::algorithm::trim(project_name_var);
if (variable_start == std::string::npos) { // not a variable
variable_start = line.find("(", 0);
variable_end = line.find(")", variable_start);
return line.substr(variable_start+1,
(variable_end)-variable_start-1);
}
break;
}
break;
}
}
std::ifstream ifs2(itr->path().string());
while (std::getline(ifs2, line)) {
if (line.find("set(", 0) != std::string::npos
|| line.find("set (", 0) != std::string::npos) {
if( line.find(project_name_var, 0) != std::string::npos) {
size_t variabel_start = line.find(project_name_var, 0)
+project_name_var.length();
size_t variabel_end = line.find(")", variabel_start);
project_name = line.substr(variabel_start+1,
variabel_end-variabel_start-1);
boost::algorithm::trim(project_name);
return project_name;
std::ifstream ifs2(itr->path().string());
while (std::getline(ifs2, line)) {
if (line.find("set(", 0) != std::string::npos
|| line.find("set (", 0) != std::string::npos) {
if( line.find(project_name_var, 0) != std::string::npos) {
size_t variable_start = line.find(project_name_var, 0)
+project_name_var.length();
size_t variable_end = line.find(")", variable_start);
project_name = line.substr(variable_start+1,
variable_end-variable_start-1);
boost::algorithm::trim(project_name);
return project_name;
}
}
}
break;
}
break;
}
return "no project name";
}
return "no project name";
}
Directories::Config::Config() {
}
Directories::Config::Config(Directories::Config& cfg) :
ignore_list_(cfg.ignore_list()), exception_list_(cfg.exception_list()) {
}
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) {
ignore_list_.push_back(filter);
}
void Directories::Config::AddIgnore(std::string filter) {
ignore_list_.push_back(filter);
}
void Directories::Config::AddException(std::string filter) {
exception_list_.push_back(filter);
}
void Directories::Config::AddException(std::string filter) {
exception_list_.push_back(filter);
}
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::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) {
for ( std::string &i : exception_list() )
if (i == str)
return true;
return false;
}
bool Directories::Config::IsException(std::string str) {
for ( std::string &i : exception_list() )
if (i == str)
return true;
return false;
}

2
juci/directories.h

@ -51,7 +51,7 @@ namespace Directories {
void open_folder(const boost::filesystem::path& dir_path);
void list_dirs(const boost::filesystem::path& dir_path,
Gtk::TreeModel::Row &row, unsigned depth);
std::string get_project_name(const boost::filesystem::path& dir_path);
std::string GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_name);
int count(const std::string path);
// Child widgets:

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

6
juci/plugins.py

@ -1,9 +1,11 @@
#!/usr/bin/python
#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():
cwd = os.getcwd()
plugin_files = glob.glob(cwd+"/plugins/*.py")
for current_file in plugin_files:
juci.initPlugin(current_file)

96
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_ + "; ";
}
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) {
if (folder_command_=="") {
PrintMessage("juCi++ ERROR: Can not find project's CMakeList.txt\n");
} else {
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();
}
}
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);
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";

370
juci/window.cc

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

1
juci/window.h

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

Loading…
Cancel
Save