Browse Source

fixed output on save file and save as

master
oyvang 11 years ago
parent
commit
81cd2ef6d4
  1. 19
      juci/notebook.cc
  2. 3
      juci/notebook.h
  3. 2
      juci/terminal.h
  4. 30
      juci/window.cc
  5. 2
      juci/window.h

19
juci/notebook.cc

@ -624,15 +624,21 @@ void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview,
} }
} }
void Notebook::Controller:: OnSaveFile() { bool Notebook::Controller:: OnSaveFile() {
INFO("Notebook save file"); INFO("Notebook save file");
if (text_vec_.at(CurrentPage())->is_saved()) { if (text_vec_.at(CurrentPage())->is_saved()) {
std::ofstream file; std::ofstream file;
file.open (text_vec_.at(CurrentPage())->path()); file.open (text_vec_.at(CurrentPage())->path());
file << CurrentTextView().get_buffer()->get_text(); file << CurrentTextView().get_buffer()->get_text();
file.close(); file.close();
return true;
} else { } 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 != "") { if (path != "") {
std::ofstream file; std::ofstream file;
file.open (path); file.open (path);
@ -640,8 +646,9 @@ void Notebook::Controller:: OnSaveFile() {
file.close(); file.close();
text_vec_.at(CurrentPage())->set_file_path(path); text_vec_.at(CurrentPage())->set_file_path(path);
text_vec_.at(CurrentPage())->set_is_saved(true); text_vec_.at(CurrentPage())->set_is_saved(true);
return true;
} }
} return false;
} }
@ -662,18 +669,14 @@ std::string Notebook::Controller::OnSaveFileAs(){
case(Gtk::RESPONSE_OK): { case(Gtk::RESPONSE_OK): {
DEBUG("get_filename()"); DEBUG("get_filename()");
std::string path = dialog.get_filename(); std::string path = dialog.get_filename();
DEBUG_VAR(path);
unsigned pos = path.find_last_of("/\\"); unsigned pos = path.find_last_of("/\\");
std::cout << path<< std::endl;
//notebook_.OnSaveFile(path);
return path; return path;
break;
} }
case(Gtk::RESPONSE_CANCEL): { case(Gtk::RESPONSE_CANCEL): {
break; break;
} }
default: { default: {
std::cout << "Unexpected button clicked." << std::endl; DEBUG("Unexpected button clicked.");
break; break;
} }
} }

3
juci/notebook.h

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

2
juci/terminal.h

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

30
juci/window.cc

@ -33,21 +33,26 @@ Window::Window() :
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(); SaveFileAs();
}); });
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(); SaveFile();
}); });
keybindings_. keybindings_.
action_group_menu()-> action_group_menu()->
add(Gtk::Action::create("ProjectCompileAndRun", add(Gtk::Action::create("ProjectCompileAndRun",
@ -206,3 +211,20 @@ void Window::OnOpenFile() {
bool Window::OnMouseRelease(GdkEventButton *button){ bool Window::OnMouseRelease(GdkEventButton *button){
return notebook_.OnMouseRelease(button); return notebook_.OnMouseRelease(button);
} }
bool Window::SaveFile() {
if(notebook_.OnSaveFile()) {
terminal_.PrintMessage("File saved to: " +
notebook_.CurrentPagePath()+"\n");
return true;
}
return false;
}
bool Window::SaveFileAs() {
if(notebook_.OnSaveFile(notebook_.OnSaveFileAs())){
terminal_.PrintMessage("File saved to: " +
notebook_.CurrentPagePath()+"\n");
return true;
}
return false;
}

2
juci/window.h

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

Loading…
Cancel
Save