Skip to content

Commit

Permalink
Implemented M+C support for file chooser with V support stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
ktvoelker committed Mar 5, 2011
1 parent 1ba195e commit d66c893
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 73 deletions.
87 changes: 46 additions & 41 deletions Di.sln
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Di", "Di\Di.csproj", "{B7E42D49-B878-4E02-A30A-D4653BC3A847}"
EndProject
Project("{9344bdbb-3e7f-41fc-a0dd-8665d75ee146}") = "Packages", "Packages.mdproj", "{1210A0FA-12B2-4B45-9140-922A9B15686D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B0169427-FDA2-485F-A1E2-280EE44D8F2D}"
ProjectSection(SolutionItems) = preProject
Controller.cs = Controller.cs
ControllerEvents.cs = ControllerEvents.cs
Main.cs = Main.cs
Model.cs = Model.cs
View.cs = View.cs
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ini", "Ini\Ini.csproj", "{8619C6C2-C719-4371-9F61-10A735FB8B99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1210A0FA-12B2-4B45-9140-922A9B15686D}.Debug|x86.ActiveCfg = Debug|Any CPU
{1210A0FA-12B2-4B45-9140-922A9B15686D}.Release|x86.ActiveCfg = Release|Any CPU
{8619C6C2-C719-4371-9F61-10A735FB8B99}.Debug|x86.ActiveCfg = Debug|x86
{8619C6C2-C719-4371-9F61-10A735FB8B99}.Debug|x86.Build.0 = Debug|x86
{8619C6C2-C719-4371-9F61-10A735FB8B99}.Release|x86.ActiveCfg = Release|x86
{8619C6C2-C719-4371-9F61-10A735FB8B99}.Release|x86.Build.0 = Release|x86
{B7E42D49-B878-4E02-A30A-D4653BC3A847}.Debug|x86.ActiveCfg = Debug|x86
{B7E42D49-B878-4E02-A30A-D4653BC3A847}.Debug|x86.Build.0 = Debug|x86
{B7E42D49-B878-4E02-A30A-D4653BC3A847}.Release|x86.ActiveCfg = Release|x86
{B7E42D49-B878-4E02-A30A-D4653BC3A847}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Di\Di.csproj
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Di", "Di\Di.csproj", "{B7E42D49-B878-4E02-A30A-D4653BC3A847}"
EndProject
Project("{9344bdbb-3e7f-41fc-a0dd-8665d75ee146}") = "Packages", "Packages.mdproj", "{1210A0FA-12B2-4B45-9140-922A9B15686D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B0169427-FDA2-485F-A1E2-280EE44D8F2D}"
ProjectSection(SolutionItems) = preProject
Controller.cs = Controller.cs
ControllerEvents.cs = ControllerEvents.cs
Main.cs = Main.cs
Model.cs = Model.cs
View.cs = View.cs
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ini", "Ini\Ini.csproj", "{8619C6C2-C719-4371-9F61-10A735FB8B99}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9AD86991-1B57-43B2-90EA-6243998DA089}"
ProjectSection(SolutionItems) = preProject
Di\Model\Language.cs = Di\Model\Language.cs
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1210A0FA-12B2-4B45-9140-922A9B15686D}.Debug|x86.ActiveCfg = Debug|Any CPU
{1210A0FA-12B2-4B45-9140-922A9B15686D}.Release|x86.ActiveCfg = Release|Any CPU
{8619C6C2-C719-4371-9F61-10A735FB8B99}.Debug|x86.ActiveCfg = Debug|x86
{8619C6C2-C719-4371-9F61-10A735FB8B99}.Debug|x86.Build.0 = Debug|x86
{8619C6C2-C719-4371-9F61-10A735FB8B99}.Release|x86.ActiveCfg = Release|x86
{8619C6C2-C719-4371-9F61-10A735FB8B99}.Release|x86.Build.0 = Release|x86
{B7E42D49-B878-4E02-A30A-D4653BC3A847}.Debug|x86.ActiveCfg = Debug|x86
{B7E42D49-B878-4E02-A30A-D4653BC3A847}.Debug|x86.Build.0 = Debug|x86
{B7E42D49-B878-4E02-A30A-D4653BC3A847}.Release|x86.ActiveCfg = Release|x86
{B7E42D49-B878-4E02-A30A-D4653BC3A847}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Di\Di.csproj
EndGlobalSection
EndGlobal
9 changes: 8 additions & 1 deletion Di/Controller/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,14 @@ public class CreateAndFocusWindow : LoneCommand
{
public override void Execute(Window b)
{
b.Controller.FocusedWindow.Value = b.Controller.CreateWindow();
FileChooser chooser = null;
Action<Di.Model.ProjectFile> handler = file =>
{
b.Controller.CallEndFileChooser(chooser);
b.Controller.FocusedWindow.Value = b.Controller.CreateWindow(file);
};
chooser = new FileChooser(b.Controller.Model.CurrentProject, handler);
b.Controller.CallBeginFileChooser(chooser);
}
}
}
Expand Down
65 changes: 65 additions & 0 deletions Di/Controller/FileChooser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// FileChooser.cs
//
// Author:
// Karl Voelker <[email protected]>
//
// Copyright (c) 2011 Karl Voelker
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
namespace Di.Controller
{
public class FileChooser
{
private Di.Model.Project project;

private Action<Di.Model.ProjectFile> handler;

private Di.Model.FileQuery query;

public string Query
{
set
{
query = new Di.Model.FileQuery(value);
Files.Clear();
Update();
}
}

public BindList<Di.Model.ProjectFile> Files;

public FileChooser(Di.Model.Project _project, Action<Di.Model.ProjectFile> _handler)
{
project = _project;
handler = _handler;
query = new Di.Model.FileQuery("");
Files = new BindList<Di.Model.ProjectFile>();
Update();
}

public void Choose(Di.Model.ProjectFile file)
{
handler(file);
}

private void Update()
{
query.Evaluate(project.Files).ForEach(f => Files.Add(f));
}
}
}

59 changes: 54 additions & 5 deletions Di/Controller/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Di.Controller
{
public partial class Main
{
private Model.Main model;
public readonly Model.Main Model;

private readonly BindList<Window> windows;
public readonly ReadOnlyCollection<Window> Windows;
Expand All @@ -37,9 +37,51 @@ public partial class Main

public readonly ReadOnlyCollection<WindowMode> WindowModes;

public delegate void FileChooserHandler(FileChooser c);

private FileChooserHandler beginFileChooser = (c) => { return; };

public event FileChooserHandler BeginFileChooser
{
add
{
beginFileChooser += value;
}

remove
{
beginFileChooser -= value;
}
}

public void CallBeginFileChooser(FileChooser c)
{
beginFileChooser(c);
}

private FileChooserHandler endFileChooser = (c) => { return; };

public event FileChooserHandler EndFileChooser
{
add
{
endFileChooser += value;
}

remove
{
beginFileChooser -= value;
}
}

public void CallEndFileChooser(FileChooser c)
{
endFileChooser(c);
}

public Main(Model.Main m)
{
model = m;
Model = m;

var windowModes = new List<WindowMode>();
WindowModes = new ReadOnlyCollection<WindowMode>(windowModes);
Expand Down Expand Up @@ -107,9 +149,9 @@ public Main(Model.Main m)
windowModes.Add(new WindowMode { Name = "Window", KeyMap = windowMode });

windows = new BindList<Window>();
if (model.Buffers.HasAny())
if (Model.Buffers.HasAny())
{
var window = new Window(this, model.Buffers.Item(0));
var window = new Window(this, Model.Buffers.Item(0));
windows.Add(window);
FocusedWindow.Value = window;
}
Expand All @@ -119,7 +161,14 @@ public Main(Model.Main m)

public Window CreateWindow()
{
var window = new Window(this, model.CreateBuffer());
var window = new Window(this, Model.CreateBuffer());
windows.Add(window);
return window;
}

public Window CreateWindow(Di.Model.ProjectFile file)
{
var window = new Window(this, Model.CreateBuffer(file));
windows.Add(window);
return window;
}
Expand Down
6 changes: 6 additions & 0 deletions Di/Di.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<Compile Include="Controller\MenuMode.cs" />
<Compile Include="FileMatcher.cs" />
<Compile Include="View\FileChooserView.cs" />
<Compile Include="Model\ProjectFile.cs" />
<Compile Include="Model\Language\Plain.cs" />
<Compile Include="Model\Language\Base.cs" />
<Compile Include="Model\FileQuery.cs" />
<Compile Include="Controller\FileChooser.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
Expand All @@ -71,6 +76,7 @@
<Folder Include="Model\" />
<Folder Include="Controller\" />
<Folder Include="View\" />
<Folder Include="Model\Language\" />
</ItemGroup>
<ItemGroup>
<None Include="TODO.txt" />
Expand Down
12 changes: 10 additions & 2 deletions Di/Model/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ public class Buffer : TextBuffer
{
private static TextTagTable tags = new TextTagTable();

private string fileName;
private ProjectFile file;

public Buffer() : base(tags)
{
fileName = null;
file = null;
}

public Buffer(ProjectFile _file) : base(tags)
{
file = _file;
var input = file.File.OpenText();
InsertAtCursor(input.ReadToEnd());
input.Close();
}

public void InsertAtCursor(char c)
Expand Down
41 changes: 41 additions & 0 deletions Di/Model/FileQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// FileQuery.cs
//
// Author:
// Karl Voelker <[email protected]>
//
// Copyright (c) 2011 Karl Voelker
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Di.Model
{
public class FileQuery
{
private string query;

public FileQuery(string _query)
{
query = _query;
}

public IQueryable<ProjectFile> Evaluate(IEnumerable<ProjectFile> files)
{
return files.AsQueryable().Where(f => f.File.Name == query);
}
}
}

33 changes: 33 additions & 0 deletions Di/Model/Language/Base.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Language.cs
//
// Author:
// Karl Voelker <[email protected]>
//
// Copyright (c) 2011 Karl Voelker
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace Di.Model.Language
{
public abstract class Base
{
public string Name { get; protected set; }

public Base()
{
}
}
}

Loading

0 comments on commit d66c893

Please sign in to comment.