2
// PListEditorViewContent.cs
5
// Mike Krüger <mkrueger@xamarin.com>
7
// Copyright (c) 2011 Xamarin <http://xamarin.com>
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using MonoDevelop.Ide.Gui;
29
using MonoDevelop.Core;
30
using MonoDevelop.Projects;
31
using MonoDevelop.Ide;
32
using MonoMac.Foundation;
33
using MonoDevelop.Ide.Gui.Content;
34
using MonoDevelop.Projects.Text;
38
namespace MonoDevelop.MacDev.PlistEditor
40
public class PListEditorViewContent : AbstractViewContent, ITextFile
42
PObjectContainer pobject;
43
IPListDisplayWidget widget;
46
public override Gtk.Widget Control { get { return control; } }
48
public PListEditorViewContent (IPlistEditingHandler handler, Project proj)
50
if (handler != null) {
51
widget = new PListEditorWidget (handler, proj);
52
control = (Gtk.Widget) widget;
54
widget = new CustomPropertiesWidget ();
55
var csw = new MonoDevelop.Components.CompactScrolledWindow ();
57
csw.AddWithViewport ((Gtk.Widget)widget);
62
public override void Load (string fileName)
64
ContentName = fileName;
66
if (pobject == null) {
67
var dict = new PDictionary ();
68
if (dict.Reload (fileName)) {
71
var arr = new PArray ();
72
if (!arr.Reload (fileName)) {
73
MessageService.ShowError (GettextCatalog.GetString ("Can't load plist file {0}.", fileName));
80
widget.SetPListContainer (pobject);
81
pobject.Changed += (sender, e) => {
89
public override void Save (string fileName)
91
ContentName = fileName;
94
pobject.Save (fileName);
96
} catch (Exception e) {
97
MessageService.ShowException (e, GettextCatalog.GetString ("Error while writing plist"));
105
string ITextFile.Text {
106
get { EnsureBuffer (); return Buffer; }
109
char ITextFile.GetCharAt (int position)
112
return Buffer [position];
115
string ITextFile.GetText (int startPosition, int endPosition)
118
return Buffer.Substring (startPosition, endPosition - startPosition + 1);
121
int ITextFile.GetPositionFromLineColumn (int line, int column)
126
for (int i = 0; i < Buffer.Length && lin <= line; i++) {
127
if (line == lin && column == col)
129
if (Buffer[i] == '\r') {
130
if (i + 1 < Buffer.Length && Buffer[i + 1] == '\n')
133
} else if (Buffer[i] == '\n') {
141
void ITextFile.GetLineColumnFromPosition (int position, out int line, out int column)
146
for (int i = 0; i < position; i++) {
147
if (Buffer[i] == '\r') {
148
if (i + 1 < position && Buffer[i + 1] == '\n')
151
} else if (Buffer[i] == '\n') {
160
FilePath ITextFile.Name {
161
get { return ContentName; }
164
int ITextFile.Length {
165
get { EnsureBuffer (); return Buffer.Length; }
171
Buffer = pobject.ToXml () ?? "";
b'\\ No newline at end of file'