void save_cb(GtkButton *button, GtkWindow *window) { GtkWidget *dialog; int result; if (get_num_pages() == 0) return; if (is_new_file() == FALSE) { save_current_file(); return; } dialog = gtk_file_chooser_dialog_new("Save File", window, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); result = gtk_dialog_run(GTK_DIALOG(dialog)); if (result == GTK_RESPONSE_ACCEPT) { char *chosen_file_path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); if (chosen_file_path != NULL) save_new_file(chosen_file_path); } gtk_widget_destroy(dialog); }
unicode DocumentView::guess_mimetype() const { if(is_new_file()) { return "text/plain"; } auto info = file_->query_info(G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); return info->get_content_type(); }
void DocumentView::set_file(GioFilePtr file) { disconnect_file_monitor(); if(!file) { create_new_file(); } file_ = file; if(!is_new_file()) { connect_file_monitor(); reload(); } else { file_etag_ = ""; //Wipe out the etag if this is a new file } }
void DocumentView::close() { //Display a prompt encourage saving unless the file is new and empty if(buffer() && buffer()->get_modified() && !(is_new_file() && buffer_->get_text().size() == 0)) { Gtk::MessageDialog dialog(window_._gtk_window(), "Do you want to save your work?", true, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO, true); dialog.set_message(_u("The file <i>{0}</i> has been changed since it was last saved.").format(name()).encode(), true); dialog.set_secondary_text("Do you want to save the file?"); int response = dialog.run(); switch(response) { case Gtk::RESPONSE_YES: { bool was_saved = window_.toolbutton_save_clicked(); if(!was_saved) { L_DEBUG("User cancelled saving a file, so we won't close the buffer"); return; } } break; default: break; } } disconnect_file_monitor(); signal_closed_(*this); }