Browse Source

Merge branch 'master' of bitbucket.org:cppit/juci

merge-requests/365/head
Jørgen Lien Sellæg 11 years ago
parent
commit
fd0047e415
  1. 15
      juci/api_ext.cc
  2. 17
      juci/config.json
  3. 2
      juci/menu.cc
  4. 46
      juci/notebook.cc
  5. 3
      juci/notebook.h
  6. 2
      juci/terminal.h
  7. 45
      juci/window.cc
  8. 2
      juci/window.h

15
juci/api_ext.cc

@ -0,0 +1,15 @@
#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

17
juci/config.json

@ -31,14 +31,23 @@
]
},
"keybindings": {
"split_window": "<control><alt>s",
"new_file": "<control>n",
"new_h_file": "<control><alt>h",
"new_cc_file": "<alt>c",
"close_tab": "<control>w",
"new_cc_file": "<control><alt>c",
"open_folder": "<control><alt>o",
"edit_undo": "<control>z",
"open_file": "<control>o",
"save": "<control>s",
"save_as": "<control><shift>s",
"quit": "<control>q",
"split_window": "<control><alt>s",
"close_tab": "<control>w",
"edit_copy": "<control>c",
"edit_cut": "<control>x",
"edit_paste": "<control>v",
"edit_undo": "<control>z",
"edit_find": "<control>f",
"compile_and_run": "<control><alt>r",
"compile": "<control>r"
},

2
juci/menu.cc

@ -15,7 +15,7 @@ Menu::Controller::Controller(Keybindings::Controller& keybindings) :
menu_view_(Gtk::ORIENTATION_VERTICAL),
keybindings_(keybindings) {
keybindings_.action_group_menu()->add(Gtk::Action::create("FileNew",
Gtk::Stock::FILE));
"New File"));
keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu",
Gtk::Stock::EDIT));
keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu",

46
juci/notebook.cc

@ -44,16 +44,16 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
keybindings.action_group_menu()->
add(Gtk::Action::create("FileNewStandard",
Gtk::Stock::NEW,
"New empty file",
"Create a new file"),
"New empty file"),
Gtk::AccelKey(keybindings.config_
.key_map()["new_file"]),
[this]() {
is_new_file_ = true;
OnFileNewEmptyfile();
});
keybindings.action_group_menu()->
add(Gtk::Action::create("FileNewCC",
"New cc file"),
"New source file"),
Gtk::AccelKey(keybindings.config_
.key_map()["new_cc_file"]),
[this]() {
@ -62,7 +62,7 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
});
keybindings.action_group_menu()->
add(Gtk::Action::create("FileNewH",
"New h file"),
"New header file"),
Gtk::AccelKey(keybindings.config_
.key_map()["new_h_file"]),
[this]() {
@ -79,7 +79,9 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
});
keybindings.action_group_menu()->
add(Gtk::Action::create("EditFind",
Gtk::Stock::FIND),
"Find"),
Gtk::AccelKey(keybindings.config_
.key_map()["edit_find"]),
[this]() {
is_new_file_ = false;
OnEditSearch();
@ -87,19 +89,26 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
});
keybindings.action_group_menu()->
add(Gtk::Action::create("EditCopy",
Gtk::Stock::COPY),
"Copy"),
Gtk::AccelKey(keybindings.config_
.key_map()["edit_copy"]),
[this]() {
OnEditCopy();
});
keybindings.action_group_menu()->
add(Gtk::Action::create("EditCut",
Gtk::Stock::CUT),
"Cut"),
Gtk::AccelKey(keybindings.config_
.key_map()["edit_cut"]),
[this]() {
OnEditCut();
});
keybindings.action_group_menu()->
add(Gtk::Action::create("EditPaste",
Gtk::Stock::PASTE),
"Paste"),
Gtk::AccelKey(keybindings.config_
.key_map()["edit_paste"]),
[this]() {
OnEditPaste();
});
@ -623,15 +632,21 @@ void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview,
}
}
void Notebook::Controller:: OnSaveFile() {
bool Notebook::Controller:: OnSaveFile() {
INFO("Notebook save file");
if (text_vec_.at(CurrentPage())->is_saved()) {
std::ofstream file;
file.open (text_vec_.at(CurrentPage())->path());
file << CurrentTextView().get_buffer()->get_text();
file.close();
return true;
} else {
std::string path = OnSaveFileAs();
return OnSaveFile(OnSaveFileAs());
}
return false;
}
bool Notebook::Controller:: OnSaveFile(std::string path) {
INFO("Notebook save file with path");
if (path != "") {
std::ofstream file;
file.open (path);
@ -639,8 +654,9 @@ void Notebook::Controller:: OnSaveFile() {
file.close();
text_vec_.at(CurrentPage())->set_file_path(path);
text_vec_.at(CurrentPage())->set_is_saved(true);
return true;
}
}
return false;
}
@ -661,18 +677,14 @@ std::string Notebook::Controller::OnSaveFileAs(){
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);
return path;
break;
}
case(Gtk::RESPONSE_CANCEL): {
break;
}
default: {
std::cout << "Unexpected button clicked." << std::endl;
DEBUG("Unexpected button clicked.");
break;
}
}

3
juci/notebook.h

@ -54,7 +54,8 @@ namespace Notebook {
void OnFileNewEmptyfile();
void OnFileNewHeaderFile();
void OnFileOpenFolder();
void OnSaveFile();
bool OnSaveFile();
bool OnSaveFile(std::string path);
void OnDirectoryNavigation(const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn* column);
void OnNewPage(std::string name);

2
juci/terminal.h

@ -40,12 +40,12 @@ namespace Terminal {
void Run(std::string executable);
void Compile();
Terminal::Config& config() { return config_; }
void PrintMessage(std::string message);
private:
Terminal::Config config_;
void ExecuteCommand(std::string command, std::string mode);
bool OnButtonRealeaseEvent(GdkEventKey* key);
bool ExistInConsole(std::string string);
void PrintMessage(std::string message);
Terminal::View view_;
std::string folder_command_;
std::string path_;

45
juci/window.cc

@ -16,12 +16,16 @@ Window::Window() :
set_default_size(600, 400);
add(window_box_);
keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit",
Gtk::Stock::QUIT),
"Quit juCi++"),
Gtk::AccelKey(keybindings_.config_
.key_map()["quit"]),
[this]() {
OnWindowHide();
});
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile",
Gtk::Stock::OPEN),
"Open file"),
Gtk::AccelKey(keybindings_.config_
.key_map()["open_file"]),
[this]() {
OnOpenFile();
});
@ -32,22 +36,26 @@ Window::Window() :
[this]() {
OnFileOpenFolder();
});
keybindings_.action_group_menu()->add(Gtk::Action::create("FileSaveAs",
keybindings_.
action_group_menu()->
add(Gtk::Action::create("FileSaveAs",
"Save as"),
Gtk::AccelKey(keybindings_.config_
.key_map()["save_as"]),
[this]() {
notebook_.OnSaveFile();
SaveFileAs();
});
keybindings_.action_group_menu()->add(Gtk::Action::create("FileSave",
keybindings_.
action_group_menu()->
add(Gtk::Action::create("FileSave",
"Save"),
Gtk::AccelKey(keybindings_.config_
.key_map()["save"]),
[this]() {
notebook_.OnSaveFile();
SaveFile();
});
keybindings_.
action_group_menu()->
add(Gtk::Action::create("ProjectCompileAndRun",
@ -55,7 +63,7 @@ Window::Window() :
Gtk::AccelKey(keybindings_.config_
.key_map()["compile_and_run"]),
[this]() {
notebook_.OnSaveFile();
SaveFile();
if (running.try_lock()) {
std::thread execute([=]() {
std::string path = notebook_.CurrentPagePath();
@ -81,7 +89,7 @@ Window::Window() :
Gtk::AccelKey(keybindings_.config_
.key_map()["compile"]),
[this]() {
notebook_.OnSaveFile();
SaveFile();
if (running.try_lock()) {
std::thread execute([=]() {
std::string path = notebook_.CurrentPagePath();
@ -206,3 +214,22 @@ void Window::OnOpenFile() {
bool Window::OnMouseRelease(GdkEventButton *button){
return notebook_.OnMouseRelease(button);
}
bool Window::SaveFile() {
if(notebook_.OnSaveFile()) {
terminal_.PrintMessage("File saved to: " +
notebook_.CurrentPagePath()+"\n");
return true;
}
terminal_.PrintMessage("File not saved");
return false;
}
bool Window::SaveFileAs() {
if(notebook_.OnSaveFile(notebook_.OnSaveFileAs())){
terminal_.PrintMessage("File saved to: " +
notebook_.CurrentPagePath()+"\n");
return true;
}
terminal_.PrintMessage("File not saved");
return false;
}

2
juci/window.h

@ -33,6 +33,8 @@ public:
void OnOpenFile();
void OnFileOpenFolder();
bool OnMouseRelease(GdkEventButton* button);
bool SaveFile();
bool SaveFileAs();
};
#endif // JUCI_WINDOW_H

Loading…
Cancel
Save