📄 mainform.cs
字号:
// -------------------------------------------------------------------------
/// <summary>
/// Kliknutie na View->Output. Zobrazi Output panel.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Clicked_ViewOutput(object sender, EventArgs e)
{
this.OutputPanel.BringToFront();
}
// -------------------------------------------------------------------------
/// <summary>
/// Kliknutie na View->GoToLine. Zobrazi formular na ktorom
/// uzivatel vyberie cislo riadku, kam sa ma kurzor premiestnit.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Clicked_ViewGoToLine(object sender, EventArgs e)
{
if (this.ActualTextAreaControl == null)
{
return;
}
GotoLineForm form = new GotoLineForm();
if (form.ShowDialog(this) == DialogResult.OK)
{
this.ActualTextAreaControl.JumpTo((form.GetLineNumber-1), 0);
#if !LINUX
this.SelectedTabPage.Focus();
#endif
}
}
// -------------------------------------------------------------------------
/// <summary>
/// Kliknutie na Format->Increase Indent.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Clicked_FormatIndent(object sender, EventArgs e)
{
if (this.ActualTextAreaControl != null)
{
this.ActualTextAreaControl.ExecuteDialogKey(Keys.Tab);
}
}
// -------------------------------------------------------------------------
/// <summary>
/// Kliknutie na Format->Decrease Indent.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Clicked_FormatUnindent(object sender, EventArgs e)
{
if (this.ActualTextAreaControl != null)
{
this.ActualTextAreaControl.ExecuteDialogKey(Keys.Tab | Keys.Shift);
}
}
// -------------------------------------------------------------------------
/// <summary>
/// Kliknutie na Format->Insert Time Stamp
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Clicked_FormatTimeStamp(object sender, EventArgs e)
{
if (this.ActualTextAreaControl != null)
{
this.ActualTextAreaControl.InsertString(System.DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"));
}
}
// -------------------------------------------------------------------------
/// <summary>
/// Kliknutie na About->License. Zobrazi licencne podmienky.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Clicked_AboutLicense(object sender, EventArgs e)
{
LicenseForm license = new LicenseForm();
license.ShowDialog(this);
}
// -------------------------------------------------------------------------
/// <summary>
/// Kliknutie na About->License. Zobrazi licencne podmienky.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Clicked_AboutAbout(object sender, EventArgs e)
{
AboutForm about = new AboutForm();
about.ShowDialog(this);
}
#endregion
#region Obsluha eventov hlavneho menu
// -------------------------------------------------------------------------
/// <summary>
/// Vola sa pred zobrazenim File ponuky v hlavnom menu
/// </summary>
/// <param name="mc"></param>
private void BeforeFilePopup(MenuCommand mc)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("Before FILE menu popup");
#endif
if (this.ActualTextAreaControl == null)
{
mc.MenuCommands[2].Enabled = mc.MenuCommands[3].Enabled = false;
mc.MenuCommands[5].Text = "&Save";
mc.MenuCommands[6].Text = "Save &As";
mc.MenuCommands[5].Enabled = mc.MenuCommands[6].Enabled = mc.MenuCommands[7].Enabled = false;
return;
}
mc.MenuCommands[5].Text = "&Save " + this.SelectedTabPage.TitleToShow;
mc.MenuCommands[6].Text = "Save " + this.SelectedTabPage.TitleToShow + " &As";
mc.MenuCommands[5].Enabled = this.SelectedTabPage.TextAreaHasChanges;
mc.MenuCommands[6].Enabled = mc.MenuCommands[7].Enabled = true;
mc.MenuCommands[2].Enabled = mc.MenuCommands[3].Enabled = true;
}
// -------------------------------------------------------------------------
/// <summary>
/// Vola sa pred zobrazenim Edit ponuky v hlavnom menu
/// </summary>
/// <param name="mc"></param>
private void BeforeEditPopup(MenuCommand mc)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("Before EDIT menu popup");
#endif
if (this.ActualTextAreaControl == null)
{
foreach (MenuCommand c in mc.MenuCommands)
{
c.Enabled = false;
}
return;
}
mc.MenuCommands["&Undo"].Enabled = this.ActualTextAreaControl.Document.UndoStack.CanUndo;
mc.MenuCommands["&Redo"].Enabled = this.ActualTextAreaControl.Document.UndoStack.CanRedo;
mc.MenuCommands["Cu&t"].Enabled = this.ActualTextAreaControl.Document.HasSomethingSelected;
mc.MenuCommands["&Copy"].Enabled = this.ActualTextAreaControl.Document.HasSomethingSelected;
mc.MenuCommands["&Paste"].Enabled = false;
IDataObject data = Clipboard.GetDataObject();
if (data != null)
{
if (data.GetDataPresent(DataFormats.Text) == true)
{
mc.MenuCommands["&Paste"].Enabled = true;
}
}
mc.MenuCommands["Select &All"].Enabled = true;
mc.MenuCommands["&Find..."].Enabled = true;
mc.MenuCommands["Find &Next"].Enabled = true;
}
#endregion
#region Obsluha ostatnych eventov
// -------------------------------------------------------------------------
/// <summary>
/// Zavola sa pri stlaceni stacidla CLOSE na TabControle
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnClosePressed(object sender, EventArgs e)
{
if (this.SelectedTabPage != null)
{
this.FileClose(this.SelectedTabPage);
}
}
// -------------------------------------------------------------------------
/// <summary>
/// Zavola sa ked uzivatel 'zaziada' o kontextove menu
/// </summary>
/// <param name="offset">Offset, v dokumente kde sa vyvolal tento event</param>
/// <param name="screen_coordinates">Pozicia na obrazovke, kde sa vyvolal tento event.
/// (Je to pozicia na celej obrazovke, NIE len v ramci okna alebo aplikacie)</param>
private void OnContextMenuToShow(int offset, Point screen_coordinates)
{
// Create the contextmenu items
MenuCommand contextFold = new MenuCommand("Fold");
MenuCommand contextUnfold = new MenuCommand("Unfold");
MenuCommand contextSep1 = new MenuCommand("-");
MenuCommand contextCut = new MenuCommand("Cu&t");
contextCut.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.Cut.png");
contextCut.Enabled = this.ActualTextAreaControl.Document.HasSomethingSelected;
MenuCommand contextCopy = new MenuCommand("&Copy");
contextCopy.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.Copy.png");
contextCopy.Enabled = this.ActualTextAreaControl.Document.HasSomethingSelected;
MenuCommand contextPaste = new MenuCommand("&Paste");
contextPaste.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.Paste.png");
IDataObject data = Clipboard.GetDataObject();
if (data != null)
{
if (data.GetDataPresent(DataFormats.Text) == true)
{
contextPaste.Enabled = true;
}
}
MenuCommand contextSep2 = new MenuCommand("-");
MenuCommand contextUndo = new MenuCommand("&Undo");
contextUndo.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.UndoIcon.png");
contextUndo.Enabled = this.ActualTextAreaControl.Document.UndoStack.CanUndo;
MenuCommand contextRedo = new MenuCommand("&Redo");
contextRedo.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.RedoIcon.png");
contextRedo.Enabled = this.ActualTextAreaControl.Document.UndoStack.CanRedo;
// Create the popup menu object
PopupMenu contextMenu = new PopupMenu();
// Define the list of menu commands
contextMenu.MenuCommands.AddRange(new MenuCommand[]{contextFold,
contextUnfold,
contextSep1,
contextCut,
contextCopy,
contextPaste,
contextSep2,
contextUndo,
contextRedo});
// Show it!
MenuCommand selected = contextMenu.TrackPopup(screen_coordinates);
if (selected == null)
{
return;
}
if (Object.ReferenceEquals(selected, contextCut) == true)
{
this.Clicked_EditCut(null, null);
return;
}
if (Object.ReferenceEquals(selected, contextCopy) == true)
{
this.Clicked_EditCopy(null,null);
//this.ActualTextAreaControl.ClipboardHandler.Copy(null, null);
return;
}
if (Object.ReferenceEquals(selected, contextPaste) == true)
{
this.Clicked_EditPaste(null,null);
// this.ActualTextAreaControl.ClipboardHandler.Paste(null, null);
return;
}
if (Object.ReferenceEquals(selected, contextFold) == true)
{
this.ActualTextAreaControl.ExecuteDialogKey(Keys.Control | Keys.F);
return;
}
if (Object.ReferenceEquals(selected, contextUnfold) == true)
{
this.ActualTextAreaControl.ExecuteDialogKey(Keys.Control | Keys.Shift | Keys.F);
return;
}
if (Object.ReferenceEquals(selected, contextUndo) == true)
{
this.ActualTextAreaControl.Undo();
return;
}
if (Object.ReferenceEquals(selected, contextRedo) == true)
{
this.ActualTextAreaControl.Redo();
return;
}
}
// -------------------------------------------------------------------------
/// <summary>
/// Zavola sa pre zatvorenim formu
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (this.FileCloseAll() == false)
{
e.Cancel = true;
}
}
#endregion
// -------------------------------------------------------------------------
/// <summary>
/// Obsluha eventu - zavola sa po zmene pozicie kurzora v editore
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CaretChanged(object sender, DLTextEditor.Document.Caret.CaretEventArgs e)
{
this.statusBar.SetInsertMode((this.ActualTextAreaControl.Document.Caret.CaretMode == DLTextEditor.Document.Caret.CaretMode.InsertMode) ? true : false);
Point pos = this.ActualTextAreaControl.Document.OffsetToView(this.ActualTextAreaControl.Document.Caret.Offset);
DLTextEditor.Document.LineManager.LineSegment line = this.ActualTextAreaControl.Document.GetLineSegment(pos.Y);
this.statusBar.SetCursorPosition(pos.X + 1, pos.Y + 1, this.ActualTextAreaControl.Document.Caret.Offset - line.Offset + 1);
}
// -------------------------------------------------------------------------
/// <summary>
/// Vyvola sa po tom, co uzivatel prepne na inu zalozku (zvoli iny editor)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void OnSelectionChanged(object sender, EventArgs e)
{
if (this.SelectedTabPage == null)
{
this.ActualTextAreaControl = null;
this.statusBar.SetCursorPosition(0, 0, 0);
return;
}
DLTextEditor.TextAreaControl txt = this.SelectedTabPage.TextAreaControl; //((XML_editor.TabPages.TextAreaTabPage)this.tabControl.SelectedTab).TextAreaControl;
#if DEBUG
System.Diagnostics.Debug.Assert(txt != null, "MainForm.cs :: OnSelectionChanged(...) -> txt == null");
System.Diagnostics.Debug.WriteLine("OK - MainForm.cs :: OnSelectionChanged(...) -> txt != null");
#endif
this.ActualTextAreaControl = txt;
this.CaretChanged(null, null);
}
// -------------------------------------------------------------------------
/// <summary>
/// Vrati odkaz na otvoreny <see cref="DLTextEditor.TextAreaControl"/> - ak je
/// otvoreny :-)
/// </summary>
/// <param name="fullFileName">Cela cesta k suboru</param>
/// <returns>Instancia <see cref="DLTextEditor.TextAreaControl"/>, ktora obsahuje
/// subor uvedeny v <paramref name="fullFileName"/></returns>
public DLTextEditor.TextAreaControl GetTextAreaControlByFileName(string fullFileName)
{
foreach (XML_editor.TabPages.TextAreaTabPage tp in this.tabControl.TabPages)
{
#if DEBUG
System.Diagnostics.Debug.Assert(tp != null, "XML_editor.MainForms.MainForm.cs :: GetTextAreaControlByFileName() => tp == null");
#endif
if (tp.TextAreaControl.FileName == fullFileName)
{
return tp.TextAreaControl;
}
}
return null;
}
// -------------------------------------------------------------------------
/// <summary>
/// Vrati odkaz na <see cref="Crownwood.Magic.Controls.TabPage"/>
/// </summary>
/// <param name="fullFileName">Cela cesta k suboru</param>
/// <returns>Instancia <see cref="Crownwood.Magic.Controls.TabPage"/>, ktora obsahuje
/// subor uvedeny v <paramref name="fullFileName"/></returns>
public XML_editor.TabPages.TextAreaTabPage GetTabPageByFileName(string fullFileName)
{
foreach (XML_editor.TabPages.TextAreaTabPage tp in this.tabControl.TabPages)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -