Browse Source

fixed output on save file and save as

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

49
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;
} }
@ -658,26 +665,22 @@ std::string Notebook::Controller::OnSaveFileAs(){
DEBUG("RUN DIALOG"); DEBUG("RUN DIALOG");
int result = dialog.run(); int result = dialog.run();
DEBUG("DIALOG RUNNING"); DEBUG("DIALOG RUNNING");
switch (result) { switch (result) {
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("/\\"); return path;
std::cout << path<< std::endl; }
//notebook_.OnSaveFile(path); case(Gtk::RESPONSE_CANCEL): {
return path; break;
break; }
} default: {
case(Gtk::RESPONSE_CANCEL): { DEBUG("Unexpected button clicked.");
break; break;
} }
default: { }
std::cout << "Unexpected button clicked." << std::endl; return "";
break;
}
}
return "";
} }
void Notebook::Controller::AskToSaveDialog() { void Notebook::Controller::AskToSaveDialog() {

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

54
juci/window.cc

@ -33,23 +33,28 @@ Window::Window() :
OnFileOpenFolder(); 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_. keybindings_.
action_group_menu()-> action_group_menu()->
add(Gtk::Action::create("FileSaveAs",
"Save as"),
Gtk::AccelKey(keybindings_.config_
.key_map()["save_as"]),
[this]() {
SaveFileAs();
});
keybindings_.
action_group_menu()->
add(Gtk::Action::create("FileSave",
"Save"),
Gtk::AccelKey(keybindings_.config_
.key_map()["save"]),
[this]() {
SaveFile();
});
keybindings_.
action_group_menu()->
add(Gtk::Action::create("ProjectCompileAndRun", add(Gtk::Action::create("ProjectCompileAndRun",
"Compile And Run"), "Compile And Run"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings_.config_
@ -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