Skip to content

Commit

Permalink
Implemented MVP code pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
mousebyte committed Dec 12, 2018
1 parent 17fea35 commit f0a5174
Show file tree
Hide file tree
Showing 30 changed files with 859 additions and 565 deletions.
48 changes: 26 additions & 22 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MouseNet.Logophi.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<userSettings>
<MouseNet.Logophi.Properties.Settings>
<setting name="SaveHistory" serializeAs="String">
<value>True</value>
</setting>
<setting name="MaxHistory" serializeAs="String">
<value>25</value>
</setting>
<setting name="PersistentCache" serializeAs="String">
<value>False</value>
</setting>
</MouseNet.Logophi.Properties.Settings>
</userSettings>
<configSections>
<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MouseNet.Logophi.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<userSettings>
<MouseNet.Logophi.Properties.Settings>
<setting name="SaveHistory" serializeAs="String">
<value>True</value>
</setting>
<setting name="MaxHistory" serializeAs="String">
<value>25</value>
</setting>
<setting name="PersistentCache" serializeAs="String">
<value>False</value>
</setting>
</MouseNet.Logophi.Properties.Settings>
</userSettings>
</configuration>
75 changes: 75 additions & 0 deletions AppContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Windows.Forms;
using MouseNet.Logophi.Forms;
using MouseNet.Logophi.Properties;
using MouseNet.Logophi.Views.Presentation;

namespace MouseNet.Logophi
{
internal class AppContext : ApplicationContext
{
private readonly BookmarksFormPresenter
_bookmarksFormPresenter;

private readonly MainFormPresenter _mainFormPresenter;
private readonly NotifyIcon _trayIcon;

public AppContext()
{
Application.ApplicationExit += OnApplicationExit;
_mainFormPresenter =
new MainFormPresenter(
Settings.Default.PersistentCache);
_bookmarksFormPresenter = new BookmarksFormPresenter(
_mainFormPresenter.Thesaurus,
_mainFormPresenter.Search);
var openMenuItem = new ToolStripMenuItem {Text = @"Open"};
openMenuItem.Click += OnOpen;
var exitMenuItem = new ToolStripMenuItem {Text = @"Exit"};
exitMenuItem.Click +=
(sender,
args) => Application.Exit();
_trayIcon = new NotifyIcon
{
Icon = Resources.logophi,
Text = Resources.AppName,
Visible = true,
ContextMenuStrip = new ContextMenuStrip
{
Items = {openMenuItem, exitMenuItem}
}
};
_trayIcon.DoubleClick += OnOpen;
}

private void PresentMainForm()
{
var form = new MainForm();
form.ViewBookmarksClicked += OnViewBookmarksClicked;
_mainFormPresenter.Present(form);
}

private void OnApplicationExit
(object sender,
EventArgs e)
{
_trayIcon.Visible = false;
_trayIcon.Dispose();
}

private void OnOpen
(object sender,
EventArgs e)
{
PresentMainForm();
}

private void OnViewBookmarksClicked
(object sender,
EventArgs e)
{
var form = new BookmarksForm();
_bookmarksFormPresenter.Present(form);
}
}
}
62 changes: 0 additions & 62 deletions BookmarksForm.cs

This file was deleted.

8 changes: 4 additions & 4 deletions BookmarksForm.Designer.cs → Forms/BookmarksForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions Forms/BookmarksForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections;
using System.Windows.Forms;
using MouseNet.Logophi.Views;

namespace MouseNet.Logophi.Forms
{
public partial class BookmarksForm : Form, IBookmarksFormView
{
public BookmarksForm()
{
InitializeComponent();
}

public IList Items => _cBookmarksList.Items;
public event EventHandler<string> BookmarkRemoved;
public event EventHandler<string> BookmarkActivated;

private void InvokeBookmarkActivated
(object sender,
MouseEventArgs args)
{
var i = _cBookmarksList.IndexFromPoint(args.Location);
if (i != ListBox.NoMatches)
BookmarkActivated?.Invoke(
this,
(string) _cBookmarksList.Items[i]);
}

private void InvokeBookmarkRemoved
(object sender,
EventArgs args)
{
BookmarkRemoved?.Invoke(sender,
_cBookmarksList
.SelectedItem.ToString());
}
}
}
File renamed without changes.
15 changes: 8 additions & 7 deletions MainForm.Designer.cs → Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f0a5174

Please sign in to comment.