#dotCover
*.dotCover
.vs
+.vscode
buffer.SelectionChanged += Buffer_SelectionChanged;
buffer.PositionChanged += Buffer_PositionChanged;
buffer.FoldingEvent += Buffer_FoldingEvent;
- buffer.Add (new CodeLine(""));
}
#endregion
+ protected override void onInitialized (object sender, EventArgs e) {
+ buffer.Add (new CodeLine (""));
+ base.onInitialized (sender, e);
+ }
ReaderWriterLockSlim editorMutex = new ReaderWriterLockSlim (LockRecursionPolicy.SupportsRecursion);
#region private and protected fields
bool foldingEnabled = true;
- int leftMargin = 0; //margin used to display line numbers, folding errors,etc...
+ int leftMargin; //margin used to display line numbers, folding errors,etc...
int visibleLines = 1;
int visibleColumns = 1;
int firstPrintedLine = -1;
filePath = value;
if (!string.IsNullOrEmpty (filePath)) {
parser = getParserFromExt (System.IO.Path.GetExtension (filePath));
- loadSource();
+ if (File.Exists (filePath))
+ loadSource ();
+ else {
+ buffer.Clear ();
+ buffer.Add (new CodeLine (""));
+ }
}
}
}
return (BufferParser)Activator.CreateInstance (parserType, buffer );
}
void loadSource () {
-
- try {
- using (StreamReader sr = new StreamReader (filePath)) {
- if (parser == null)
- buffer.Load (sr.ReadToEnd());
- else//parser may have special linebrk rules
- buffer.Load (sr.ReadToEnd (), parser.LineBrkRegex);
- }
- } catch (Exception ex) {
- Debug.WriteLine (ex.ToString ());
+ using (StreamReader sr = new StreamReader (filePath)) {
+ if (parser == null)
+ buffer.Load (sr.ReadToEnd());
+ else//parser may have special linebrk rules
+ buffer.Load (sr.ReadToEnd (), parser.LineBrkRegex);
}
updateMaxScrollY ();
else
mgFg = Colors.LightGrey;
}else if (buffer.CurrentLine == lineIndex && HasFocus) {
- mgFg = Colors.Black;
- mgBg = Colors.DarkGrey;
+ mgFg = Colors.White;
+ mgBg = Colors.RoyalBlue;
}
string strLN = (lineIndex+1).ToString ();
gr.SetSource (mgBg);
Rectangle cb = ClientRectangle;
+
Foreground.SetAsSource (gr);
buffer.editMutex.EnterReadLock ();
}
li--;
}
-
- for (int i = 0; i < visibleLines; i++) {
+ int i;
+ for (i = 0; i < visibleLines; i++) {
if (i + ScrollY >= unfoldedLines)//TODO:need optimize
break;
drawLine (gr, cb, i);
}
+ double y = cb.Y + (fe.Ascent + fe.Descent) * i, x = cb.X;
+ if (y < cb.Bottom) {
+ //draw end of margin
+ Rectangle mgR = new Rectangle ((int)x, (int)y, leftMargin - leftMarginGap, (int)(cb.Bottom - y));
+ gr.SetSource (Colors.Grey);
+ gr.Rectangle (mgR);
+ gr.Fill ();
+ }
}
editorMutex.ExitReadLock ();
Height = "14";
Background = "White";
}
-
-MenuItem {
- Template = "#Crow.Coding.ui.MenuItem.template";
-}
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0"?>
-<Popper Font="{./Font}" Caption="{./Caption}" Background="{./Background}" PopDirection="{./PopDirection}"
- Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseClick="./onMI_Click"
- IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}" IsEnabled="{./IsEnabled}">
- <Template>
- <CheckBox IsChecked="{²./IsPopped}" Caption="{./Caption}" Background="{./Background}" Foreground="{./Foreground}">
- <Template>
- <Border Name="border1"
- MouseEnter="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}"
- MouseLeave="{Foreground=Transparent}"
- MouseDown="{Foreground=vgradient|0:Black|0.05:Grey|0.85:Grey|1:White}"
- MouseUp="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}"
- MinimumSize = "40,0"
- Foreground="Transparent"
- Background="{./Background}">
- <HorizontalStack HorizontalAlignment="Left" Margin="1">
- <Image MaximumSize="10,10" Picture="{../../../../../Icon}"/>
- <Label Text="{./Caption}"
- Foreground="{./Foreground}"
- Font="{./Font}" />
- </HorizontalStack>
- </Border>
- </Template>
- </CheckBox>
- </Template>
- <Border Foreground="DimGrey" Width="{../PopWidth}" Height="{../PopHeight}" Background="Jet">
- <VerticalStack Name="ItemsContainer"/>
- </Border>
-</Popper>
public Command CMDNew, CMDOpen, CMDSave, CMDSaveAs, CMDQuit, CMDShowLeftPane,
CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste, CMDHelp, CMDAbout, CMDOptions;
- string _curFilePath = "unamed.txt";
+ const string _defaultFileName = "unnamed.txt";
string _text = "", _origText="";
+ bool isDirty = false;
+ public new bool IsDirty { get { return _text != _origText; } }
List<string> undoStack = new List<string>();
List<string> redoStack = new List<string>();
NotifyValueChanged ("IsDirty", IsDirty);
}
}
- bool isDirty = false;
- public bool IsDirty { get { return _text != _origText; }}
public string CurrentDir {
get { return Configuration.Global.Get<string>("CurrentDir"); }
NotifyValueChanged (CurrentDir);
}
}
- public string CurFilePath {
- get { return _curFilePath; }
+ public string CurrentFilePath {
+ get { return Configuration.Global.Get<string> ("CurrentFilePath"); }
set {
- if (_curFilePath == value)
+ if (CurrentFilePath == value)
return;
- _curFilePath = value;
- NotifyValueChanged (_curFilePath);
+ Configuration.Global.Set ("CurrentFilePath", value);
+ NotifyValueChanged (CurrentFilePath);
+
}
}
- bool showLeftPane;
+ public string CurFileName {
+ get => string.IsNullOrEmpty (CurrentFilePath) ? _defaultFileName : Path.GetFileName (CurrentFilePath);
+ }
+ public string CurFileDir {
+ get => string.IsNullOrEmpty (CurrentFilePath) ? CurrentDir : Path.GetDirectoryName (CurrentFilePath);
+ }
+
public bool ShowLeftPane {
get { return Configuration.Global.Get<bool> ("ShowLeftPane"); }
set {
}
}
- public string CurFileFullPath { get { return Path.Combine(CurrentDir,CurFilePath); }}
-
void initCommands(){
CMDNew = new Command(new Action(() => onNewFile())) { Caption = "New", Icon = new SvgPicture("#CrowEdit.ui.icons.blank-file.svg")};
CMDOpen = new Command(new Action(() => openFileDialog())) { Caption = "Open...", Icon = new SvgPicture("#CrowEdit.ui.icons.outbox.svg")};
{
FileDialog fd = sender as FileDialog;
- if (!string.IsNullOrEmpty (fd.SelectedFile))
- CurFilePath = fd.SelectedFile;
- CurrentDir = fd.SelectedDirectory;
+ if (string.IsNullOrEmpty (fd.SelectedFile))
+ return;
+ CurrentFilePath = Path.Combine (fd.SelectedDirectory, fd.SelectedFile);
- System.Diagnostics.Debug.WriteLine (CurFileFullPath);
// using (StreamWriter sr = new StreamWriter (fd.SelectedFile)) {
// sr.Write(_text);
// }
_origText = _text;
NotifyValueChanged ("IsDirty", false);
- NotifyValueChanged ("CurFileFullPath", (object)CurFileFullPath);
}
void onTextChanged (object sender, TextChangeEventArgs e)
{
openFile (filePath, directory);
}
void newFile () {
- CurFilePath = "unamed.txt";
+ CurrentFilePath = Path.Combine (CurFileDir, _defaultFileName);
_origText = _text = "";
NotifyValueChanged ("Text", (object)_text);
NotifyValueChanged ("IsDirty", false);
undoStack.Clear ();
CMDRedo.CanExecute = false;
CMDUndo.CanExecute = false;
- NotifyValueChanged ("CurFileFullPath", (object)CurFileFullPath);
}
void openFile (string filePath, string directory) {
- CurFilePath = filePath;
- CurrentDir = directory;
-
+ CurrentFilePath = Path.Combine(directory, filePath);
redoStack.Clear ();
undoStack.Clear ();
CMDRedo.CanExecute = false;
CMDUndo.CanExecute = false;
-
- NotifyValueChanged ("CurFileFullPath", (object)CurFileFullPath);
}
[STAThread]
this.ValueChanged += CrowEdit_ValueChanged;
initCommands ();
Load ("#CrowEdit.ui.main.crow").DataSource = this;
- NotifyValueChanged ("CurFileFullPath", (object)CurFileFullPath);
}
/*void textView_KeyDown (object sender, Crow.KeyEventArgs e)
--- /dev/null
+MenuIconSize = "14";
+
+MenuItem {
+ Template = "#CrowEdit.ui.MenuItem.template";
+}
+
+MenuIcon {
+ Margin = "2";
+ Width = "${MenuIconSize}";
+ Height = "${MenuIconSize}";
+}
<?xml version="1.0"?>
<Popper Font="{./Font}" Caption="{./Caption}" Background="{./Background}" PopDirection="{./PopDirection}"
- Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseClick="./onMI_Click"
- IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}" IsEnabled="{./IsEnabled}">
+ Foreground = "{./Foreground}" CanPop="{./HasChildren}"
+ IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}">
<Template>
- <Border Name="border1"
- MouseEnter="{Foreground=vgradient|0:White|0.2:Gray|0.9:Gray|1:Black}"
- MouseLeave="{Foreground=Transparent}"
- MouseDown="{Foreground=vgradient|0:Black|0.05:Gray|0.85:Gray|1:White}"
- MouseUp="{Foreground=vgradient|0:White|0.2:Gray|0.9:Gray|1:Black}"
- MinimumSize = "40,0"
- Foreground="Transparent"
- Background="{./Background}">
- <HorizontalStack HorizontalAlignment="Left" Margin="1">
- <Image MaximumSize="10,10" Picture="{../../../../Icon}"/>
- <Label Text="{./Caption}"
- Foreground="{./Foreground}"
- Font="{./Font}" />
- </HorizontalStack>
- </Border>
+ <CheckBox IsChecked="{²./IsPopped}" Caption="{./Caption}" Background="{./Background}" Foreground="{./Foreground}">
+ <Template>
+ <Border Name="border1"
+ MinimumSize = "60,0"
+ Foreground="Transparent"
+ Background="{./Background}">
+ <HorizontalStack HorizontalAlignment="Left" Margin="1">
+ <Image Style="MenuIcon" Picture="{../../../../../Icon}"/>
+ <Label Text="{./Caption}"
+ Foreground="{./Foreground}"
+ Font="{./Font}" />
+ </HorizontalStack>
+ </Border>
+ </Template>
+ </CheckBox>
</Template>
- <Border Foreground="DimGray" Width="{../PopWidth}" Height="{../PopHeight}" Background="Onyx">
+ <Border Foreground="DimGrey" Width="{../PopWidth}" Height="{../PopHeight}" Background="${MenuBackground}">
<VerticalStack Name="ItemsContainer"/>
</Border>
</Popper>
<?xml version="1.0"?>
-<VerticalStack Spacing="0" Background="DimGrey">
+<VerticalStack Spacing="0" >
<Menu>
<MenuItem Caption="File" Width="Fit" PopWidth="80">
<MenuItem Command="{CMDNew}" />
<MenuItem Command="{CMDSaveAs}" />
<MenuItem Command="{CMDQuit}" />
</MenuItem>
- <MenuItem Caption="Edit" Name="edit" Width="Fit" PopWidth="100">
+ <MenuItem Caption="Edit" Name="edit" Width="Fit" PopWidth="130">
<MenuItem Command="{CMDUndo}" />
<MenuItem Command="{CMDRedo}" />
<MenuItem Command="{CMDCut}" />
<HorizontalStack Height="Fit" Margin="2" Background="Onyx">
<Image Margin="2" Width="16" Height="16" Path="#Crow.Icons.level-up.svg" MouseClick="./goUpDirClick"
Background="Jet" MouseEnter="{Background=Grey}" MouseLeave="{Background=Jet}" />
- <TextBox Text="{²CurrentDir}" Margin="2"/>
+ <TextBox Text="{²CurrentDir}" Margin="1"/>
</HorizontalStack>
- <DirectoryView Margin="1" Name="dv" CurrentDirectory="{CurrentDir}" SelectedItemChanged="Dv_SelectedItemChanged"/>
+ <DirectoryView Margin="0" Name="dv" CurrentDirectory="{CurrentDir}" SelectedItemChanged="Dv_SelectedItemChanged" Background="Jet"/>
</VerticalStack>
<Splitter Width="6" Visible="{ShowLeftPane}"/>
<VerticalStack>
<HorizontalStack Height="Stretched" >
- <SourceEditor Focusable="true" Name="editor" Font="monospace, 12" VerticalAlignment="Top" FilePath="{CurFileFullPath}"
+ <SourceEditor Focusable="true" Name="editor" Font="monospace, 12" VerticalAlignment="Top" FilePath="{CurrentFilePath}"
Foreground="Jet" Background="White" Width="Stretched" Height="Stretched" KeyDown="textView_KeyDown"/>
<ScrollBar Name="scrollbarY" Value="{²../editor.ScrollY}"
- Maximum="{../editor.MaxScrollY}" Orientation="Vertical" Width="14" />
+ Maximum="{../editor.MaxScrollY}" Orientation="Vertical" Width="14"
+ LargeIncrement="{../editor.VisibleLines}"
+ CursorSize="{../editor.ChildHeightRatio}"/>
</HorizontalStack>
<ScrollBar Style="HScrollBar" Name="scrollbarX" Value="{²../editor.ScrollX}"
- Maximum="{../editor.MaxScrollX}" Height="14" />
+ Maximum="{../editor.MaxScrollX}" Height="14"
+ LargeIncrement="{../editor.VisibleColumns}"
+ CursorSize="{../editor.ChildWidthRatio}"/>
<HorizontalStack Height="Fit">
<Label Text="{../../editor.HoverError}" Width="Stretched"/>
<Widget Background="Red" Width="5" Height="5" Visible="{../../editor.IsDirty}"/>
<?xml version="1.0" encoding="UTF-8" ?>
<FileDialog Width="60%" Height="50%" Caption="Open File" AlwaysOnTop="true"
- CurrentDirectory="{CurrentDir}"
- SelectedFile="{CurFilePath}"
+ CurrentDirectory="{CurFileDir}"
+ SelectedFile="{CurFileName}"
OkClicked="openFileDialog_OkClicked"/>
<?xml version="1.0" encoding="UTF-8" ?>
-<FileDialog Width="60%" Height="50%" Caption="Save File" CurrentDirectory="{CurrentDir}" OkClicked="saveFileDialog_OkClicked"/>
+<FileDialog Width="60%" Height="50%" Caption="Save File" CurrentDirectory="{CurFileDir}" OkClicked="saveFileDialog_OkClicked"/>