Skip to content

Commit

Permalink
Fixed shift bug; added statusbar showing mode; added Bind type
Browse files Browse the repository at this point in the history
  • Loading branch information
ktvoelker committed Dec 15, 2010
1 parent cb0cf34 commit 1158c43
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 36 deletions.
87 changes: 87 additions & 0 deletions Di/Bind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// Bind.cs
//
// Author:
// Karl Voelker <[email protected]>
//
// Copyright (c) 2010 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
{
public class Actor : IDisposable
{
private Action action;

public Actor(Action _action)
{
action = _action;
}

public void Dispose()
{
action();
}
}

public class Bind<P, V>
{
public delegate void ValueChanged(P p, V v);

private ValueChanged _changed;

public event ValueChanged Changed
{
add { _changed += value; }
remove { _changed -= value; }
}

private P p;

private V v;

public V Value
{
get { return v; }

set
{
v = value;
_changed(p, v);
}
}

public Bind(P _p)
{
p = _p;
}

public Bind(P _p, V _v) : this(_p)
{
v = _v;
}

public static implicit operator V(Bind<P, V> obj)
{
return obj.v;
}

public IDisposable WithChange()
{
return new Actor(() => _changed(p, v));
}
}
}

8 changes: 4 additions & 4 deletions Di/Controller/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ public TextBuffer GtkTextBuffer
private BufferMode CommandMode;
private BufferMode InsertMode;

private BufferMode CurrentMode;
public Bind<Buffer, BufferMode> CurrentMode { get; private set; }
private IList<UnparsedCommand> CurrentCommand;

public Buffer(KeyMap commandModeMap, KeyMap insertModeMap, Model.Buffer _model)
{
model = _model;
CommandMode = new BufferMode() { Name = "Command", KeyMap = commandModeMap };
InsertMode = new BufferMode() { Name = "Insert", KeyMap = insertModeMap };
CurrentMode = CommandMode;
CurrentMode = new Bind<Buffer, BufferMode>(this, CommandMode);
CurrentCommand = new List<UnparsedCommand>();
}

public void KeyPressedHandler(EventKey e)
{
CurrentMode.KeyMap.Lookup(e).ForEach(a =>
CurrentMode.Value.KeyMap.Lookup(e).ForEach(a =>
{
CurrentCommand.Add(new UnparsedCommand(a, e.KeyValue));
});
Expand All @@ -62,7 +62,7 @@ public void KeyPressedHandler(EventKey e)

private void EnterMode(BufferMode b)
{
CurrentMode = b;
CurrentMode.Value = b;
}

public void EnterCommandMode()
Expand Down
12 changes: 6 additions & 6 deletions Di/Controller/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override void Execute(Buffer b)
}
}

public class Ignore : LoneCommand
public class Ignore : RepeatCommand
{
public override void Execute(Buffer b)
{
Expand Down Expand Up @@ -149,11 +149,11 @@ public class InsertKey : RepeatCommand

public RepeatCommand SetKey(uint val)
{
if (val >= MinInsertableChar && val <= MaxInsertableChar)
{
return new InsertChar((char) val);
}
return this;
if (val >= MinInsertableChar && val <= MaxInsertableChar)
{
return new InsertChar((char) val);
}
return new Ignore();
}

public override void Execute(Buffer b)
Expand Down
10 changes: 5 additions & 5 deletions Di/Controller/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ namespace Di.Controller
public partial class Main
{

public delegate void VisibleBuffersChangedHandler(int n);
public delegate void WindowsChangedHandler(int n);

public VisibleBuffersChangedHandler visibleBuffersChanged;
public WindowsChangedHandler windowsChanged;

public event VisibleBuffersChangedHandler VisibleBuffersChangedEvent
public event WindowsChangedHandler WindowsChangedEvent
{
add { visibleBuffersChanged += value; }
remove { visibleBuffersChanged -= value; }
add { windowsChanged += value; }
remove { windowsChanged -= value; }
}

}
Expand Down
10 changes: 5 additions & 5 deletions Di/Controller/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public partial class Main
{
private Model.Main model;

private IList<Buffer> visibleBuffers;
public IEnumerable<Buffer> VisibleBuffers
private IList<Buffer> windows;
public IEnumerable<Buffer> Windows
{
get { return visibleBuffers; }
get { return windows; }
}

public KeyMap CommandMode
Expand Down Expand Up @@ -75,10 +75,10 @@ public Main(Model.Main m)
InsertMode.Add(Key.Right, new Command.Right());
InsertMode.Add(Key.Delete, new Command.Delete(), new Command.Right());

visibleBuffers = new List<Buffer>();
windows = new List<Buffer>();
if (model.Buffers.Count() > 0)
{
visibleBuffers.Add(new Buffer(CommandMode, InsertMode, model.Buffers.Item(0)));
windows.Add(new Buffer(CommandMode, InsertMode, model.Buffers.Item(0)));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Di/Di.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<Compile Include="Controller\Command.cs" />
<Compile Include="Range.cs" />
<Compile Include="CharIter.cs" />
<Compile Include="Bind.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
Expand Down
15 changes: 5 additions & 10 deletions Di/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@
TODO
====

Using the shift key seems to cause a crash.

Add a visual indication of the current mode.

Replace the term "visible buffer" with something shorter and more distinct, perhaps "viewport".

Add support for files projects
Add support for projects

Search up from the current directory for di-project.ini
Globs for inclusion and exclusion of files into project
Project name (show it, and nothing else other than "Di", in the title bar)

Add commands:
Add a new visible buffer and switch to it
Hide the current visible buffer
Load a file in the current visible buffer
Add a new window and switch to it
Hide the current window
Load a file in the current window

Keep a list of project files sorted by most-recently-visible
Prefer the most-recently-visible file over other matches
Expand All @@ -39,6 +33,7 @@ Add support for language plug-ins, which will ultimately provide:
and should otherwise begin automatic completion.
Logic for moving by words and by matching brackets
Syntax coloring
Logic for dividing the buffer into subbuffers

Configuration support
$HOME/di-user.ini
Expand Down
20 changes: 15 additions & 5 deletions Di/View/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@
using Pango;
namespace Di.View
{
public class Buffer : HBox
public class Buffer : VBox
{
private const uint StatusbarMode = 1;

private Controller.Buffer ctl;
private Gtk.ScrolledWindow scroll;
private Gtk.Statusbar status;

public Buffer(Controller.Buffer _ctl)
{
ctl = _ctl;
Homogeneous = true;
Spacing = 20;
BorderWidth = 20;
Homogeneous = false;
Spacing = 0;
BorderWidth = 0;
var textView = new BufferTextView(ctl);
scroll = new Gtk.ScrolledWindow()
{
Expand All @@ -51,7 +54,14 @@ public Buffer(Controller.Buffer _ctl)
ctl.GtkTextBuffer.Changed += delegate {
showCursor();
};
Add(scroll);
PackStart(scroll, true, true, 0);
status = new Gtk.Statusbar();
status.Push(StatusbarMode, ctl.CurrentMode.Value.Name);
ctl.CurrentMode.Changed += (b, m) => {
status.Pop(StatusbarMode);
status.Push(StatusbarMode, m.Name);
};
PackStart(status, false, false, 0);
}

private class BufferTextView : TextView
Expand Down
2 changes: 1 addition & 1 deletion Di/View/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Main(Controller.Main c) : base(WindowType.Toplevel)
DefaultHeight = 600;
DeleteEvent += OnDeleteEvent;
buffersBox = new HBox();
foreach (var buffer in ctl.VisibleBuffers)
foreach (var buffer in ctl.Windows)
{
buffersBox.Add(new Buffer(buffer));
}
Expand Down

0 comments on commit 1158c43

Please sign in to comment.