void DocumentView::save(const unicode& path) { L_DEBUG("Saving file: " + path.encode()); trim_trailing_newlines(); trim_trailing_whitespace(); Glib::ustring text = buffer()->get_text(); if(file_->get_path() == path.encode()) { //FIXME: Use entity tag arguments to make sure that the file //didn't change since the last time we saved file_->replace_contents(std::string(text.c_str()), "", file_etag_); connect_file_monitor(); } else { auto file = Gio::File::create_for_path(path.encode()); if(!os::path::exists(path)) { file->create_file(); } file->replace_contents(text, "", file_etag_); connect_file_monitor(); } buffer()->set_modified(false); apply_settings(guess_mimetype()); //Make sure we update the settings when we've saved the file window_.rebuild_open_list(); run_linters_and_stuff(); }
/* print_opml_node -- convert given node to OPML and append */ void print_opml_node(GString *out, node *n, scratch_pad *scratch) { #ifdef DEBUG_ON fprintf(stderr, "print_opml_node: %d\n",n->key); #endif switch (n->key) { case METADATA: /* Metadata is present, so will need to be appended later */ break; case METAKEY: g_string_append_printf(out, "<outline text=\""); print_opml_string(out, n->str); g_string_append_printf(out, "\" _note=\""); trim_trailing_newlines(n->children->str); print_opml_string(out, n->children->str); g_string_append_printf(out, "\"/>"); break; case HEADINGSECTION: /* Need to handle "nesting" properly */ g_string_append_printf(out, "<outline "); /* Print header */ print_opml_node(out, n->children, scratch); /* print remainder of paragraphs as note */ g_string_append_printf(out, " _note=\""); print_opml_node_tree(out, n->children->next, scratch); g_string_append_printf(out, "\">"); break; case H1: case H2: case H3: case H4: case H5: case H6: g_string_append_printf(out, "text=\""); print_opml_string(out, n->str); g_string_append_printf(out,"\""); break; case VERBATIM: case VERBATIMFENCE: print_opml_string(out, n->str); break; case SPACE: print_opml_string(out, n->str); break; case STR: print_opml_string(out, n->str); break; case LINEBREAK: g_string_append_printf(out, " "); break; case PLAIN: print_opml_node_tree(out, n->children, scratch); if ((n->next != NULL) && (n->next->key == PLAIN)) { g_string_append_printf(out, " "); } break; default: fprintf(stderr, "print_opml_node encountered unknown element key = %d\n", n->key); exit(EXIT_FAILURE); } #ifdef DEBUG_ON fprintf(stderr, "finish print_opml_node: %d\n", n->key); #endif }