lw_common.ui.note_ctrl.save_to C# (CSharp) Method

save_to() public method

public save_to ( string file_name ) : void
file_name string
return void
        public void save_to(string file_name) {
            if (file_name == "")
                file_name = file_name_;

            // needs to be loaded first
            if (file_name == "")
                return;
            bool force_save = file_name != file_name_;
            if (!dirty_ && !force_save)
                return;
            if (file_name == file_name_ && notes_sorted_by_line_index_.Count < 1)
                return; // optimization - nothing to save_to

            settings_file sett = new settings_file(file_name) { log_each_set = false };

            // first, save_to lines - don't save_to the cur_line
            sett.set("line_count", "" + (lines_.Count - 1));
            int line_idx = 0;
            foreach ( var l in lines_)
                if (l.Key != cur_line_id_) {
                    string prefix = "line." + line_idx + ".";
                    sett.set(prefix + "id", "" + l.Key);
                    sett.set(prefix + "index", "" + l.Value.idx);
                    sett.set(prefix + "view_name", l.Value.view_name);
                    sett.set(prefix + "msg", l.Value.msg);
                    ++line_idx;
                }

            // save_to notes
            sett.set("note_count", "" + notes_sorted_by_line_index_.Count);
            for (int idx = 0; idx < notes_sorted_by_line_index_.Count; ++idx) {
                string prefix = "note." + idx + ".";
                note_item n = notes_sorted_by_line_index_[idx];
                if (n.the_note != null) {
                    sett.set(prefix + "author_name", n.the_note.author_name);
                    sett.set(prefix + "author_initials", n.the_note.author_initials);
                    sett.set(prefix + "author_color", util.color_to_str(n.the_note.author_color));
                    sett.set(prefix + "note_text", n.the_note.note_text);
                }
                else 
                    // clear the author name, so we know it's not a note (it's a line)
                    sett.set(prefix + "author_name", "");

                sett.set(prefix + "deleted", n.deleted ? "1" : "0");
                sett.set(prefix + "note_id", "" + n.note_id);
                sett.set(prefix + "reply_id", "" + n.reply_id);
                sett.set(prefix + "line_id", "" + n.line_id);
                sett.set(prefix + "added_at", "" + n.utc_last_edited.Ticks);
            }
            sett.save();

            if ( file_name == file_name_)
                dirty_ = false;
        }