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