Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OpenChart.Tests/src/Actions/TestCloseProjectAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NUnit.Framework;
using OpenChart.Projects;
using OpenChart.UI.Actions;
using OpenChart.UI.MenuActions;

namespace OpenChart.Tests.Actions
{
Expand Down
2 changes: 1 addition & 1 deletion OpenChart.Tests/src/Actions/TestNewProjectAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NUnit.Framework;
using OpenChart.UI.Actions;
using OpenChart.UI.MenuActions;

namespace OpenChart.Tests.Actions
{
Expand Down
2 changes: 1 addition & 1 deletion OpenChart.Tests/src/Actions/TestQuitAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NUnit.Framework;
using OpenChart.UI.Actions;
using OpenChart.UI.MenuActions;

namespace OpenChart.Tests.Actions
{
Expand Down
2 changes: 1 addition & 1 deletion OpenChart.Tests/src/Actions/TestSaveAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NUnit.Framework;
using OpenChart.Projects;
using OpenChart.UI.Actions;
using OpenChart.UI.MenuActions;

namespace OpenChart.Tests.Actions
{
Expand Down
2 changes: 1 addition & 1 deletion OpenChart.Tests/src/Actions/TestSaveAsAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NUnit.Framework;
using OpenChart.Projects;
using OpenChart.UI.Actions;
using OpenChart.UI.MenuActions;

namespace OpenChart.Tests.Actions
{
Expand Down
2 changes: 1 addition & 1 deletion OpenChart.Tests/src/TestApplication.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NUnit.Framework;
using OpenChart.UI.Actions;
using OpenChart.UI.MenuActions;

namespace OpenChart.Tests
{
Expand Down
20 changes: 10 additions & 10 deletions OpenChart/src/Application.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ManagedBass;
using OpenChart.UI.Actions;
using OpenChart.UI.MenuActions;
using OpenChart.UI.Windows;
using Serilog;
using System;
Expand All @@ -19,7 +19,7 @@ public class Application : Gtk.Application, IApplication
/// <summary>
/// A dictionary of action names --> actions.
/// </summary>
public Dictionary<string, IAction> ActionDict { get; private set; }
public Dictionary<string, IMenuAction> ActionDict { get; private set; }

ApplicationData applicationData;
public ApplicationData GetData() => applicationData;
Expand All @@ -36,7 +36,7 @@ public class Application : Gtk.Application, IApplication

public Application() : base(AppId, GLib.ApplicationFlags.None)
{
ActionDict = new Dictionary<string, IAction>();
ActionDict = new Dictionary<string, IMenuAction>();
LogFile = Path.Combine("logs", "OpenChart.log");
}

Expand All @@ -55,12 +55,12 @@ public void Cleanup()
public void InitActions()
{
// File actions
addAction(new NewProjectAction(this));
addAction(new NewChartAction(this));
addAction(new CloseProjectAction(this));
addAction(new SaveAction(this));
addAction(new SaveAsAction(this));
addAction(new QuitAction(this));
addMenuAction(new NewProjectAction(this));
addMenuAction(new NewChartAction(this));
addMenuAction(new CloseProjectAction(this));
addMenuAction(new SaveAction(this));
addMenuAction(new SaveAsAction(this));
addMenuAction(new QuitAction(this));
}

/// <summary>
Expand Down Expand Up @@ -195,7 +195,7 @@ protected override void OnStartup()
}
}

private void addAction(IAction action)
private void addMenuAction(IMenuAction action)
{
// FIXME: Can't add accelerators/hotkeys since the Gtk wrapper takes the wrong
// type of argument, resulting in a segfault.
Expand Down
7 changes: 7 additions & 0 deletions OpenChart/src/ApplicationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OpenChart.Formats.OpenChart.Version0_1;
using OpenChart.NoteSkins;
using OpenChart.Projects;
using OpenChart.UI.Actions;
using Serilog;
using System;

Expand All @@ -27,6 +28,11 @@ public ProjectChangedEventArgs(Project oldProject, Project newProject)
/// </summary>
public class ApplicationData
{
/// <summary>
/// A factory for producing IAction instances.
/// </summary>
public ActionFactory ActionFactory { get; private set; }

/// <summary>
/// The absolute path to the folder where the OpenChart executable is.
/// </summary>
Expand Down Expand Up @@ -80,6 +86,7 @@ public Project CurrentProject
public ApplicationData(string appFolder)
{
AppFolder = appFolder;
ActionFactory = new ActionFactory(this);
Formats = new FormatManager();
NoteSkins = new NoteSkinManager();
}
Expand Down
1 change: 1 addition & 0 deletions OpenChart/src/ApplicationEventBus.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using OpenChart.UI.MenuActions;
using OpenChart.Charting;
using OpenChart.Projects;
using System;
Expand Down
21 changes: 21 additions & 0 deletions OpenChart/src/UI/Actions/ActionFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace OpenChart.UI.Actions
{
/// <summary>
/// A factory class for creating IAction instances.
/// </summary>
public class ActionFactory
{
/// <summary>
/// The application data.
/// </summary>
public ApplicationData ApplicationData { get; private set; }

/// <summary>
/// Creates a new ActionFactory instance.
/// </summary>
public ActionFactory(ApplicationData appData)
{
ApplicationData = appData;
}
}
}
30 changes: 5 additions & 25 deletions OpenChart/src/UI/Actions/IAction.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
namespace OpenChart.UI.Actions
{
/// <summary>
/// An interface for an action. These actions are fairly analagous to the Command pattern,
/// the key difference being that once an action is created it lives for the lifecycle
/// of the application.
///
/// Action instances are stored in <see cref="OpenChart.Application.ActionDict" /> and can
/// be retrieved by their name.
///
/// For dynamic actions that need to respond to the state of the application (such as only
/// allowing the "Close Project" action to fire when a project is actually loaded), actions
/// should add event listener(s) to <see cref="OpenChart.Application.EventBus" /> and respond
/// to those events within the action class itself. Keeping all of the action-related code
/// inside the action classes makes it easy to find later on.
/// An interface for a general purpose action. These actions differ from menu actions in that
/// the menu actions are meant to be the UI part whereas classes that implement IAction are
/// the logical part. Menu actions most likely will end up calling an IAction instance.
/// </summary>
public interface IAction
{
/// <summary>
/// The GLib/Gtk action object.
/// Executes the action.
/// </summary>
GLib.IAction Action { get; }

/// <summary>
/// The hotkey for the action.
/// </summary>
string GetHotkey();

/// <summary>
/// The name of the action. This is the name of the action referred to in
/// the code, not its display name. Display names are set in <see cref="OpenChart.UI.Actions.MenuModel" />
/// </summary>
string GetName();
void Run();
}
}
20 changes: 20 additions & 0 deletions OpenChart/src/UI/Actions/IUndoable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace OpenChart.UI.Actions
{
/// <summary>
/// An interface for an undoable action. Undoable actions appear in the Edit menu after they
/// are executed.
/// </summary>
public interface IUndoable
{
/// <summary>
/// Gets the name of the action as a string. This is the text that appears in the UI under
/// the Edit menu. It doesn't need to be constant.
/// </summary>
string GetName();

/// <summary>
/// Reverts the action.
/// </summary>
void Undo();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Serilog;

namespace OpenChart.UI.Actions
namespace OpenChart.UI.MenuActions
{
/// <summary>
/// An action that triggers the current active project to close. This action
/// is only enabled when an active project is open.
/// </summary>
public class CloseProjectAction : Actions.IAction
public class CloseProjectAction : IMenuAction
{
IApplication app;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using OpenChart.Charting.Properties;
using Serilog;

namespace OpenChart.UI.Actions
namespace OpenChart.UI.MenuActions
{
/// <summary>
/// An action that triggers the application to create a new chart.
/// </summary>
public class NewChartAction : Actions.IAction
public class NewChartAction : IMenuAction
{
IApplication app;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using OpenChart.Projects;
using Serilog;

namespace OpenChart.UI.Actions
namespace OpenChart.UI.MenuActions
{
/// <summary>
/// An action that triggers the application to create a new project.
/// </summary>
public class NewProjectAction : Actions.IAction
public class NewProjectAction : IMenuAction
{
IApplication app;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Serilog;

namespace OpenChart.UI.Actions
namespace OpenChart.UI.MenuActions
{
/// <summary>
/// An action that triggers the application to quit.
/// </summary>
public class QuitAction : Actions.IAction
public class QuitAction : IMenuAction
{
IApplication app;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Serilog;

namespace OpenChart.UI.Actions
namespace OpenChart.UI.MenuActions
{
/// <summary>
/// An action that triggers the application to save the current project.
/// </summary>
public class SaveAction : Actions.IAction
public class SaveAction : IMenuAction
{
IApplication app;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Serilog;

namespace OpenChart.UI.Actions
namespace OpenChart.UI.MenuActions
{
/// <summary>
/// An action that triggers the application to save the current project.
/// </summary>
public class SaveAsAction : Actions.IAction
public class SaveAsAction : IMenuAction
{
IApplication app;

Expand Down
33 changes: 33 additions & 0 deletions OpenChart/src/UI/MenuActions/IMenuAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace OpenChart.UI.MenuActions
{
/// <summary>
/// An interface for a menu action. These are actions which are invoked through the app menu.
///
/// Action instances are stored in <see cref="OpenChart.Application.ActionDict" /> and can
/// be retrieved by their name.
///
/// For dynamic actions that need to respond to the state of the application (such as only
/// allowing the "Close Project" action to fire when a project is actually loaded), actions
/// should add event listener(s) to <see cref="OpenChart.Application.EventBus" /> and respond
/// to those events within the action class itself. Keeping all of the action-related code
/// inside the action classes makes it easy to find later on.
/// </summary>
public interface IMenuAction
{
/// <summary>
/// The GLib/Gtk action object.
/// </summary>
GLib.IAction Action { get; }

/// <summary>
/// The hotkey for the action.
/// </summary>
string GetHotkey();

/// <summary>
/// The name of the action. This is the name of the action referred to in
/// the code, not its display name. Display names are set in <see cref="OpenChart.UI.MenuActions.MenuModel" />
/// </summary>
string GetName();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GLib;

namespace OpenChart.UI.Actions
namespace OpenChart.UI.MenuActions
{
/// <summary>
/// The model/layout of the menu shown in the <see cref="OpenChart.UI.Widgets.MenuBar" /> widget.
Expand Down
2 changes: 1 addition & 1 deletion OpenChart/src/UI/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Gtk;
using ChartObjects = OpenChart.Charting.Objects;
using OpenChart.UI.Actions;
using OpenChart.UI.MenuActions;
using OpenChart.UI.NoteField;

namespace OpenChart.UI.Windows
Expand Down