using NModel; using NModel.Attributes; using NModel.Execution; namespace NewsReader { static class NewsReaderUI { // Types for each state variable enum Page { Topics, Messages }; enum Style { WithText, TitlesOnly }; enum Sort { ByFirst, ByMostRecent }; // State variables, initial state static Page page = Page.Topics; static Style style = Style.WithText; static Sort sort = Sort.ByMostRecent; // Actions: enabling condition, then action method static bool SelectMessagesEnabled() { return (page == Page.Topics); } [Action] static void SelectMessages() { page = Page.Messages; } static bool SelectTopicsEnabled() { return (page == Page.Messages); } [Action] static void SelectTopics() { page = Page.Topics; } static bool ShowTitlesEnabled() { return (page == Page.Topics && style == Style.WithText); } [Action] static void ShowTitles() { style = Style.TitlesOnly; } static bool ShowTextEnabled() { return (page == Page.Topics && style == Style.TitlesOnly); } [Action] static void ShowText() { style = Style.WithText; } static bool SortByFirstEnabled() { return (page == Page.Topics && style == Style.TitlesOnly && sort == Sort.ByMostRecent); } [Action] static void SortByFirst() { sort = Sort.ByFirst; } static bool SortByMostRecentEnabled() { return (page == Page.Topics && style == Style.TitlesOnly && sort == Sort.ByFirst); } [Action] static void SortByMostRecent() { sort = Sort.ByMostRecent; } } public static class Factory { public static ModelProgram Create() { return new LibraryModelProgram(typeof(Factory).Assembly, "NewsReader"); } } }