private static void load_contexts(settings_file sett) { logger.Debug("loading contexts"); int history_count = int.Parse( sett.get("history_count", "0")); for (int idx = 0; idx < history_count; ++idx) { history hist = new history(); string guid = sett.get("history." + idx + ".guid"); if (guid != "") { // 1.5.6+ - guid points to the whole settings string settings = sett.get("guid." + guid); if (settings == "") { logger.Debug("history guid removed " + guid); continue; // entry removed } Debug.Assert(settings.Contains(guid)); hist.from_settings(new settings_as_string(settings)); } else { // old code (pre 1.5.6) string type_str = sett.get("history." + idx + "type", "file"); if (type_str == "0") type_str = "file"; string name = sett.get("history." + idx + "name"); string friendly_name = sett.get("history." + idx + "friendly_name"); settings_as_string history_sett = new settings_as_string(""); history_sett.set("type", type_str); history_sett.set("name", name); history_sett.set("friendly_name", friendly_name); // create a guid now history_sett.set("guid", Guid.NewGuid().ToString()); hist.from_settings(history_sett); } history_.Add( hist ); } history_ = history_.Where(h => { if (h.type == history.entry_type.file) { // 1.5.11 - don't include this into the list next time the user opens the app // (so that he'll see the "Drop me like it's hot" huge message) if (h.name.EndsWith("LogWizardSetupSample.log")) return false; if (File.Exists(h.name)) // 1.1.5+ - compute md5s for this md5_log_keeper.inst.compute_default_md5s_for_file(h.name); else return false; } return true; }).ToList(); int count = int.Parse( sett.get("context_count", "1")); for ( int i = 0; i < count ; ++i) { ui_context ctx = new ui_context(); ctx.load("context." + i); contexts_.Add(ctx); } // 1.1.25 - at application start - remove empty contexts (like, the user may have dragged a file, not what he wanted, dragged another) contexts_ = contexts_.Where(x => x.has_not_empty_views || x.name == "Default").ToList(); }
private string ui_context_to_str(ui_context cur) { if (cur.views.Count < 1) return ""; // no views var formatter = new XmlSerializer(typeof (ui_context)); string str = ""; using (var stream = new MemoryStream()) { formatter.Serialize(stream, cur); stream.Flush(); stream.Position = 0; using (var reader = new StreamReader(stream)) str = reader.ReadToEnd(); } return str; }
private void addContext_Click(object sender, EventArgs e) { new_context_form new_ = new new_context_form(this); new_.Location = Cursor.Position; if (new_.ShowDialog() == DialogResult.OK) { ui_context new_ctx = new ui_context(); if (new_.basedOnExisting.Checked) new_ctx.copy_from(cur_context()); // 1.3.33+ - we want unique context names! new_ctx.name = util.unique_name( contexts_.Select(x => x.name), new_.name.Text); contexts_.Add(new_ctx); update_contexts_combos_in_all_forms(); curContextCtrl.SelectedIndex = curContextCtrl.Items.Count - 1; } }
/* 1.1.25+ - on new file (that does not match any context) - we will create a context matching the name of the file (if one exists, we will automatically select it) - by default, we'll never go to the "Default" context - the idea is for the uesr not to have to mistakenly delete a context when he's selecting a different type of file, (since he would want new filters). thus, just create a new context where he can do anything */ private void create_context_for_log(settings_as_string log_settings) { string context_name = log_settings.get("context"); if (contexts_.FirstOrDefault(x => x.name == context_name) != null) // in this case, I already have a context, and the context exists return; ui_context log_ctx = settings_to_context(log_settings); if (log_ctx.name != "Default") // we already have a context return; ui_context new_ctx = new ui_context(); contexts_.Add(new_ctx); switch (log_settings.get("type")) { case "file": string file = log_settings.get("name"); Debug.Assert(file != ""); new_ctx.name = Path.GetFileNameWithoutExtension(new FileInfo(file).Name); break; case "event_log": new_ctx.name = least_unused_context_name("Event Log"); break; case "debug_print": new_ctx.name = least_unused_context_name("Debug"); break; default: Debug.Assert(false); return; } Debug.Assert(new_ctx.name != ""); log_settings.set("context", new_ctx.name); update_contexts_combos_in_all_forms(); }
private static void load_contexts(settings_file sett) { logger.Debug("loading contexts"); history_list_.load(); int count = int.Parse( sett.get("context_count", "1")); for ( int i = 0; i < count ; ++i) { ui_context ctx = new ui_context(); ctx.load("context." + i); contexts_.Add(ctx); } // 1.1.25 - at application start - remove empty contexts (like, the user may have dragged a file, not what he wanted, dragged another) contexts_ = contexts_.Where(x => x.has_not_empty_views || x.name == "Default").ToList(); }
public void copy_from(ui_context other) { default_settings_ = other.default_settings_; name = other.name; views = other.views.ToList(); }