|
// ******************************************************************************
// ******************************************************************************
// ASP.NET DaST Rendering Engine
// Copyright (C) 2011 Roman Gubarenko
// Project Home: http://aspnetdast.sourceforge.net/
// ******************************************************************************
// ******************************************************************************
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// ******************************************************************************
// Primary Contact: rgubarenko@gmail.com
// Learn More: http://aspnetdast.sourceforge.net/
// Project Repository: http://sourceforge.net/projects/aspnetdast/
// ******************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AspNetDaST.Web.Private;
namespace AspNetDaST.Web
{
public class PathNavigator
{
internal ScopeTreeModel _scopeTree;
internal ScopeController _controller;
internal PathExact _origPath;
// current navigation values
private PathExact _currPath;
private int? _savedAxis;
private ScopeFacade _scope;
internal PathNavigator(ScopeController controller, PathExact path)
{
_scopeTree = controller.TreeNode.ScopeTree;
_controller = controller;
_origPath = path;
ResetNavigation();
}
internal void ResetNavigation()
{
_currPath = PathExact.Empty.Append(_origPath);
_savedAxis = null;
_scope = null;
}
#region Navigation Interface
public ScopeFacade Scope
{
get
{
var scopeData = _scopeTree.GetScopeDataBag(_currPath);
return new ScopeFacade(_scopeTree, _currPath, scopeData);
}
}
public PathNavigator Fwd(params object[] segments)
{
if (segments == null || segments.Length == 0) throw new DaSTException("Invalid path specification");
int oldLength = _currPath.Length;
_currPath = _currPath.Append(segments);
if (_savedAxis.HasValue)
{
_currPath[oldLength].Axis = _savedAxis.Value;
}
EnsureValidCurrPath();
return this;
}
public PathNavigator Rew(int countSteps)
{
if (countSteps <= 0 || countSteps > _currPath.Length) throw new DaSTException("Invalid number of steps");
_savedAxis = _currPath[_currPath.Length - countSteps].Axis;
_currPath = _currPath.Subpath(_currPath.Length - countSteps);
EnsureValidCurrPath();
return this;
}
private void EnsureValidCurrPath()
{
// make sure that selection does not go beyond current control
var foundNode = _scopeTree.GetNode(_currPath);
// ensure scope is accessible
if(!ScopeTreeTools.Model.IsScopeAccessible(_controller, foundNode))
throw new DaSTException("Cannot access scope beyond current controller");
}
#endregion
public override string ToString()
{
return _currPath.ToString();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Software Architect with over 15 years in IT field. Started with deep math and C++ Computer Vision software. Currently in .NET and PHP web development. Creator of DaST pattern, open-source frameworks, and plugins. Interested in cutting Edge IT, open-source, Web 2.0, .NET, MVC, C++, Java, jQuery, Mobile tech, and extreme sports.