Browse Source

Making the Title and the Tooltip editable in ViewContent

pull/12/head
Boris Kozorovitzky 15 years ago committed by Daniel Grunwald
parent
commit
4fbbc13493
  1. 81
      src/Main/Base/Project/Src/Gui/AbstractViewContent.cs
  2. 12
      src/Main/Base/Project/Src/Gui/IViewContent.cs
  3. 69
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs
  4. 19
      src/Main/Base/Project/Src/Util/FakeXmlViewContent.cs

81
src/Main/Base/Project/Src/Gui/AbstractViewContent.cs

@ -348,18 +348,19 @@ namespace ICSharpCode.SharpDevelop.Gui
string IViewContent.TitleName { string IViewContent.TitleName {
get { get {
if (titleName != null) if (titleName != null) {
return titleName; return titleName;
else if (files.Count > 0) } else if (files.Count > 0) {
return Path.GetFileName(files[0].FileName); return Path.GetFileName(files[0].FileName);
else } else {
return "[Default Title]"; return "[Default Title]";
} }
} }
}
public string TitleName { public string TitleName {
get { return titleName; } get { return titleName; }
protected set { set {
if (titleNameLocalizeExtension != null) { if (titleNameLocalizeExtension != null) {
titleNameLocalizeExtension.PropertyChanged -= OnTitleNameLocalizationChanged; titleNameLocalizeExtension.PropertyChanged -= OnTitleNameLocalizationChanged;
titleNameLocalizeExtension = null; titleNameLocalizeExtension = null;
@ -392,6 +393,78 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
#endregion #endregion
#region InfoTip
public event EventHandler InfoTipChanged;
void OnInfoTipChanged()
{
if (InfoTipChanged != null)
{
InfoTipChanged(this, EventArgs.Empty);
}
}
string infoTip;
LanguageDependentExtension infoTipLocalizeExtension;
string IViewContent.InfoTip
{
get
{
if (infoTip != null)
return infoTip;
else if (files.Count > 0)
return files[0].FileName;
else
return "[Default Info Tip]";
}
set
{
this.InfoTip = value;
}
}
public string InfoTip
{
get { return infoTip; }
set
{
if (infoTipLocalizeExtension != null)
{
infoTipLocalizeExtension.PropertyChanged -= OnInfoTipLocalizationChanged;
infoTipLocalizeExtension = null;
}
if (infoTip != value)
{
infoTip = value;
OnInfoTipChanged();
}
}
}
/// <summary>
/// Sets a localized info tip that will update automatically when the language changes.
/// </summary>
/// <param name="text">The input to the string parser which will localize info tip.</param>
protected void SetLocalizedInfoTip(string text)
{
infoTipLocalizeExtension = new StringParseExtension(text) { UsesAccessors = false };
infoTipLocalizeExtension.PropertyChanged += OnInfoTipLocalizationChanged;
OnInfoTipLocalizationChanged(null, null);
}
void OnInfoTipLocalizationChanged(object sender, EventArgs e)
{
string value = infoTipLocalizeExtension.Value;
if (infoTip != value)
{
infoTip = value;
OnInfoTipChanged();
}
}
#endregion
#region IDisposable #region IDisposable
public event EventHandler Disposed; public event EventHandler Disposed;

12
src/Main/Base/Project/Src/Gui/IViewContent.cs

@ -83,6 +83,18 @@ namespace ICSharpCode.SharpDevelop.Gui
/// </summary> /// </summary>
event EventHandler TitleNameChanged; event EventHandler TitleNameChanged;
/// <summary>
/// The tooltip that will be shown when you hover the mouse over the title
/// </summary>
string InfoTip {
get;
}
/// <summary>
/// Is called each time the info tip for the content has changed.
/// </summary>
event EventHandler InfoTipChanged;
/// <summary> /// <summary>
/// Saves the content to the location <code>fileName</code> /// Saves the content to the location <code>fileName</code>
/// </summary> /// </summary>

69
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs

@ -135,8 +135,12 @@ namespace ICSharpCode.SharpDevelop.Gui
void UpdateActiveViewContent() void UpdateActiveViewContent()
{ {
UpdateTitle(); UpdateTitleAndInfoTip();
IViewContent newActiveViewContent = this.ActiveViewContent; IViewContent newActiveViewContent = this.ActiveViewContent;
if (newActiveViewContent != null)
IsLocked = newActiveViewContent.IsReadOnly;
if (oldActiveViewContent != newActiveViewContent && ActiveViewContentChanged != null) { if (oldActiveViewContent != newActiveViewContent && ActiveViewContentChanged != null) {
ActiveViewContentChanged(this, EventArgs.Empty); ActiveViewContentChanged(this, EventArgs.Empty);
} }
@ -262,7 +266,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (this.DragEnabledArea != null) { if (this.DragEnabledArea != null) {
this.DragEnabledArea.ContextMenu = MenuService.CreateContextMenu(this, contextMenuPath); this.DragEnabledArea.ContextMenu = MenuService.CreateContextMenu(this, contextMenuPath);
UpdateTitle(); // set tooltip UpdateInfoTip(); // set tooltip
} }
} }
@ -348,33 +352,57 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
void OnInfoTipChanged(object sender, EventArgs e)
{
if (sender == ActiveViewContent) {
UpdateInfoTip();
}
}
void OnIsDirtyChanged(object sender, EventArgs e) void OnIsDirtyChanged(object sender, EventArgs e)
{ {
UpdateTitle(); UpdateTitle();
CommandManager.InvalidateRequerySuggested(); CommandManager.InvalidateRequerySuggested();
} }
void UpdateTitle() void UpdateTitleAndInfoTip()
{
UpdateInfoTip();
UpdateTitle();
}
void UpdateInfoTip()
{ {
IViewContent content = ActiveViewContent; IViewContent content = ActiveViewContent;
if (content != null) { if (content != null)
this.InfoTip = content.PrimaryFileName; {
string newInfoTip = content.InfoTip;
string newTitle = content.TitleName; if (newInfoTip != this.InfoTip) {
this.InfoTip = newInfoTip;
if (DragEnabledArea != null)
DragEnabledArea.ToolTip = this.InfoTip;
if (this.IsDirty) { OnInfoTipChanged();
newTitle += "*"; }
}
} }
IsLocked = content.IsReadOnly; void UpdateTitle()
{
IViewContent content = ActiveViewContent;
if (content != null) {
string newTitle = content.TitleName;
if (content.IsDirty)
newTitle += "*";
if (newTitle != Title) { if (newTitle != Title) {
Title = newTitle; Title = newTitle;
OnTitleChanged(EventArgs.Empty); OnTitleChanged();
} }
} }
} }
void RegisterNewContent(IViewContent content) void RegisterNewContent(IViewContent content)
{ {
Debug.Assert(content.WorkbenchWindow == null); Debug.Assert(content.WorkbenchWindow == null);
@ -382,6 +410,7 @@ namespace ICSharpCode.SharpDevelop.Gui
content.TabPageTextChanged += OnTabPageTextChanged; content.TabPageTextChanged += OnTabPageTextChanged;
content.TitleNameChanged += OnTitleNameChanged; content.TitleNameChanged += OnTitleNameChanged;
content.InfoTipChanged += OnInfoTipChanged;
content.IsDirtyChanged += OnIsDirtyChanged; content.IsDirtyChanged += OnIsDirtyChanged;
this.dockLayout.Workbench.OnViewOpened(new ViewContentEventArgs(content)); this.dockLayout.Workbench.OnViewOpened(new ViewContentEventArgs(content));
@ -393,6 +422,7 @@ namespace ICSharpCode.SharpDevelop.Gui
content.TabPageTextChanged -= OnTabPageTextChanged; content.TabPageTextChanged -= OnTabPageTextChanged;
content.TitleNameChanged -= OnTitleNameChanged; content.TitleNameChanged -= OnTitleNameChanged;
content.InfoTipChanged -= OnInfoTipChanged;
content.IsDirtyChanged -= OnIsDirtyChanged; content.IsDirtyChanged -= OnIsDirtyChanged;
this.dockLayout.Workbench.OnViewClosed(new ViewContentEventArgs(content)); this.dockLayout.Workbench.OnViewClosed(new ViewContentEventArgs(content));
@ -467,15 +497,26 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
void OnTitleChanged(EventArgs e) void OnTitleChanged()
{
if (TitleChanged != null)
{ {
if (TitleChanged != null) { TitleChanged(this, EventArgs.Empty);
TitleChanged(this, e);
} }
} }
public event EventHandler TitleChanged; public event EventHandler TitleChanged;
void OnInfoTipChanged()
{
if (InfoTipChanged != null)
{
InfoTipChanged(this, EventArgs.Empty);
}
}
public event EventHandler InfoTipChanged;
public override string ToString() public override string ToString()
{ {
return "[AvalonWorkbenchWindow: " + this.Title + "]"; return "[AvalonWorkbenchWindow: " + this.Title + "]";

19
src/Main/Base/Project/Src/Util/FakeXmlViewContent.cs

@ -90,6 +90,11 @@ namespace ICSharpCode.SharpDevelop.Util
remove { } remove { }
} }
event EventHandler IViewContent.InfoTipChanged {
add { }
remove { }
}
public event EventHandler Disposed; public event EventHandler Disposed;
event EventHandler ICanBeDirty.IsDirtyChanged { event EventHandler ICanBeDirty.IsDirtyChanged {
@ -128,6 +133,10 @@ namespace ICSharpCode.SharpDevelop.Util
get { get {
throw new NotImplementedException(); throw new NotImplementedException();
} }
set
{
throw new NotImplementedException();
}
} }
System.Collections.Generic.IList<OpenedFile> IViewContent.Files { System.Collections.Generic.IList<OpenedFile> IViewContent.Files {
@ -154,6 +163,16 @@ namespace ICSharpCode.SharpDevelop.Util
} }
} }
string IViewContent.InfoTip {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
bool IViewContent.CloseWithSolution { bool IViewContent.CloseWithSolution {
get { get {
throw new NotImplementedException(); throw new NotImplementedException();

Loading…
Cancel
Save