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

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

54
juci/window.cc

@ -33,23 +33,28 @@ Window::Window() :
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_.
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",
"Compile And Run"),
Gtk::AccelKey(keybindings_.config_
@ -206,3 +211,20 @@ 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;
}
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 OnFileOpenFolder();
bool OnMouseRelease(GdkEventButton* button);
bool SaveFile();
bool SaveFileAs();
};
#endif // JUCI_WINDOW_H

Loading…
Cancel
Save