5 changed files with 246 additions and 230 deletions
@ -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_ = ¬ebook_; |
}); |
||||||
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_ = ¬ebook_; |
||||||
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…
Reference in new issue