Skip to content

Commit

Permalink
Merge pull request #130 from arbmu/bugfix/fix_query_autocomplete
Browse files Browse the repository at this point in the history
Query autocomplete fixes
  • Loading branch information
tdanner committed Mar 22, 2018
2 parents ba4be32 + 0774ec6 commit f017110
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 27 deletions.
7 changes: 3 additions & 4 deletions Src/SwqlStudio/ActivityMonitorTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ namespace SwqlStudio
public partial class ActivityMonitorTab : TabTemplate, IConnectionTab
{
private string subscriptionId;
private bool conneciotnSet = false;
private bool connectionSet;

public SubscriptionManager SubscriptionManager { get; set; }

public override bool AllowsChangeConnection => !this.conneciotnSet;
public override bool AllowsChangeConnection => !this.connectionSet;

public override ConnectionInfo ConnectionInfo
{
get { return base.ConnectionInfo; }
set
{
base.ConnectionInfo = value;
this.conneciotnSet = true;
this.connectionSet = true;
}
}

Expand Down
21 changes: 16 additions & 5 deletions Src/SwqlStudio/LexerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface ILexerDataSource
{
string Text { get; }
}
internal class LexerService
internal sealed class LexerService : IDisposable
{
/// <summary>
/// Namespace is, for our usage, SwisEntity with ColumnNames of the internal namespaces and classes
Expand Down Expand Up @@ -122,12 +122,18 @@ private void RefreshMetadata(IMetadataProvider provider)
return Tuple.Create(entityFullName.Substring(0, lastDot), entityFullName.Substring(lastDot + 1));
}

private void OnProviderEntitiesRefreshed(object sender, EventArgs args)
{
RefreshMetadata((IMetadataProvider) sender);
}

private Action Unsubscribe;

public void SetMetadata(IMetadataProvider provider)
{
provider.EntitiesRefreshed += (sender, args) =>
{
RefreshMetadata(provider);
};
Unsubscribe?.Invoke();
Unsubscribe = () => provider.EntitiesRefreshed -= OnProviderEntitiesRefreshed;
provider.EntitiesRefreshed += OnProviderEntitiesRefreshed;
RefreshMetadata(provider);
}

Expand Down Expand Up @@ -222,5 +228,10 @@ private static ExpectedCaretPosition DetectAutoCompletion(string text, int textP
return new ExpectedCaretPosition(ExpectedCaretPositionType.Keyword, null);
}

public void Dispose()
{
Unsubscribe?.Invoke();
Unsubscribe = null;
}
}
}
25 changes: 19 additions & 6 deletions Src/SwqlStudio/QueryTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace SwqlStudio
{
public partial class QueryTab : TabTemplate, IConnectionTab
public sealed partial class QueryTab : TabTemplate, IConnectionTab
{
private readonly CachedParameters preserved = new CachedParameters();

Expand All @@ -32,10 +32,10 @@ private bool HasSubscription

public override ConnectionInfo ConnectionInfo
{
get { return base.ConnectionInfo; }
set
{
base.ConnectionInfo = value;
SetMetadataProvider();
queryStatusBar1.Initialize(base.ConnectionInfo);
}
}
Expand All @@ -53,8 +53,9 @@ enum Tabs
}

private Font nullFont;
public IApplicationService ApplicationService { get; set; }
public SubscriptionManager SubscriptionManager { get; set; }
private IApplicationService ApplicationService { get; }
private SubscriptionManager SubscriptionManager { get; }
private ServerList ServerList { get; }

public QueryTab()
{
Expand All @@ -65,6 +66,14 @@ public QueryTab()
AddRunContextMenu();
}

internal QueryTab(IApplicationService applicationService, ServerList serverList, ConnectionInfo connectionInfo, SubscriptionManager subscriptionManager) : this()
{
ApplicationService = applicationService;
ServerList = serverList;
ConnectionInfo = connectionInfo;
SubscriptionManager = subscriptionManager;
}

private void AddRunContextMenu()
{
ToolStripMenuItem runMenuItem = new ToolStripMenuItem();
Expand Down Expand Up @@ -757,9 +766,13 @@ private void gridContextMenuStrip_Opening(object sender, System.ComponentModel.C
deleteToolStripMenuItem.Enabled = dataGridView1.Columns.Contains("Uri") && dataGridView1.SelectedRows.Count > 0;
}

internal void SetMetadataProvider(IMetadataProvider provider)
private void SetMetadataProvider()
{
sciTextEditorControl1.SetMetadata(provider);
IMetadataProvider provider;
if (ServerList != null && ConnectionInfo != null && ServerList.TryGetProvider(ConnectionInfo, out provider))
{
sciTextEditorControl1.SetMetadata(provider);
}
}

private void sciTextEditorControl1_TextChanged(object sender, EventArgs e)
Expand Down
6 changes: 6 additions & 0 deletions Src/SwqlStudio/SciTextEditorControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,11 @@ protected override void OnCharAdded(CharAddedEventArgs e)
}

string ILexerDataSource.Text => this.Text;

protected override void Dispose(bool disposing)
{
LexerService.Dispose();
base.Dispose(disposing);
}
}
}
4 changes: 2 additions & 2 deletions Src/SwqlStudio/ServerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Add(ConnectionInfo connection)
var provider = new SwisMetaDataProvider(connection);
metadataProviders[connection] = provider;
var e = new ConnectionsEventArgs(connection);
ConnectionAdded(this, e);
ConnectionAdded?.Invoke(this, e);
}

public void Remove(ConnectionInfo connection)
Expand All @@ -31,7 +31,7 @@ public void Remove(ConnectionInfo connection)
connections.Remove(key);
metadataProviders.Remove(connection);
var e = new ConnectionsEventArgs(connection);
ConnectionRemoved(this, e);
ConnectionRemoved?.Invoke(this, e);
}

public bool Exists(ConnectionInfo connection)
Expand Down
2 changes: 1 addition & 1 deletion Src/SwqlStudio/TabTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SwqlStudio
{
public abstract class TabTemplate : UserControl
public class TabTemplate : UserControl
{
private ConnectionInfo connection;

Expand Down
12 changes: 3 additions & 9 deletions Src/SwqlStudio/TabsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,11 @@ internal void CreateTabFromPrevious()

private QueryTab CreateQueryTab(string title, ConnectionInfo info)
{
var queryTab = new QueryTab
var queryTab = new QueryTab(applicationService, serverList, info, applicationService.SubscriptionManager)
{
ConnectionInfo = info,
Dock = DockStyle.Fill,
ApplicationService = this.applicationService,
SubscriptionManager = this.applicationService.SubscriptionManager
Dock = DockStyle.Fill
};

IMetadataProvider provider;
this.serverList.TryGetProvider(info, out provider);
queryTab.SetMetadataProvider(provider);

AddNewTab(queryTab, title);
return queryTab;
}
Expand Down

0 comments on commit f017110

Please sign in to comment.