Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Tooltips on non progress keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaillon committed Apr 4, 2017
1 parent 14f7d29 commit 63269a2
Show file tree
Hide file tree
Showing 31 changed files with 826 additions and 543 deletions.
2 changes: 1 addition & 1 deletion 3PA/3P.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
<Content Include="_Resource\Images\ParserItem\Type\MainBlock.png" />
<Content Include="_Resource\Images\ParserItem\Type\Method.png" />
<Content Include="_Resource\Images\ParserItem\Type\NotApplicable.png" />
<Content Include="_Resource\Images\ParserItem\Type\Numbers.png" />
<Content Include="_Resource\Images\ParserItem\Type\Number.png" />
<Content Include="_Resource\Images\ParserItem\Type\OnEvent.png" />
<Content Include="_Resource\Images\ParserItem\Type\Preprocessed.png" />
<Content Include="_Resource\Images\ParserItem\Type\PreprocessorBlock.png" />
Expand Down
3 changes: 3 additions & 0 deletions 3PA/Lib/ProcessIo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public bool TryDoWait(bool hidden = false) {
/// Start the process synchronously
/// </summary>
public bool DoWait(bool hidden = false) {
StandardOutput.Clear();
ErrorOutput.Clear();

if (hidden) {
StartInfo.CreateNoWindow = true;
StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Expand Down
1 change: 0 additions & 1 deletion 3PA/Lib/UpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ It will be automatically installed the next time you restart Notepad++<br>
/// </summary>
private static void UpdateDoneFromVersion(string fromVersion) {
if (!fromVersion.IsHigherVersionThan("1.7.3")) {
UserCommunication.Notify("Cleaning libraries...");
Utils.DeleteDirectory(Path.Combine(Npp.ConfigDirectory, "Libraries"), true);
}
}
Expand Down
127 changes: 1 addition & 126 deletions 3PA/Lib/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Security.Cryptography;
Expand All @@ -37,7 +36,6 @@
using System.Windows.Forms;
using YamuiFramework.Helper;
using YamuiFramework.HtmlRenderer.Core.Core.Entities;
using _3PA.Lib.Ftp;
using _3PA.MainFeatures;
using _3PA.MainFeatures.Appli;
using _3PA.MainFeatures.FileExplorer;
Expand Down Expand Up @@ -183,7 +181,7 @@ public static bool DeleteDirectory(string path, bool recursive) {
try {
if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
return true;
Directory.Delete(path, true);
Directory.Delete(path, recursive);
} catch (Exception e) {
UserCommunication.Notify("Failed to delete the following directory :<br>" + path.ToHtmlLink() + "<div class='AlternatBackColor' style='padding: 5px; margin: 5px;'>\"" + e.Message + "\"</div>", MessageImg.MsgHighImportance, "Delete folder", "Can't delete a folder!");
return false;
Expand Down Expand Up @@ -770,128 +768,5 @@ public static bool ZipFolder(string zipPath, string folderPath, ZipStorer.Compre

#endregion

#region Wrapper around FtpsClient

private static Dictionary<string, FtpsClient> _ftpClients = new Dictionary<string, FtpsClient>();

/// <summary>
/// Sends a file to a ftp(s) server : EASY MODE, connects, create the directories...
/// Utils.SendFileToFtp(@"D:\Profiles\jcaillon\Downloads\function_forward_sample.p", "ftp://cnaf049:[email protected]/cnaf/users/cnaf049/vm/jca/derp/yolo/test.p");
/// </summary>
public static bool SendFileToFtp(string localFilePath, string ftpUri) {
if (string.IsNullOrEmpty(localFilePath) || !File.Exists(localFilePath))
return false;

try {
// parse our uri
var regex = new Regex(@"^(ftps?:\/\/([^:\/@]*)?(:[^:\/@]*)?(@[^:\/@]*)?(:[^:\/@]*)?)(\/.*)$");
var match = regex.Match(ftpUri.Replace("\\", "/"));
if (!match.Success)
return false;

var serverUri = match.Groups[1].Value;
var distantPath = match.Groups[6].Value;
string userName = null;
string passWord = null;
string server;
int port;
if (!string.IsNullOrEmpty(match.Groups[4].Value)) {
userName = match.Groups[2].Value;
passWord = match.Groups[3].Value.Trim(':');
server = match.Groups[4].Value.Trim('@');
if (!int.TryParse(match.Groups[5].Value.Trim(':'), out port))
port = -1;
} else {
server = match.Groups[2].Value;
if (!int.TryParse(match.Groups[3].Value.Trim(':'), out port))
port = -1;
}

FtpsClient ftp;
if (!_ftpClients.ContainsKey(serverUri))
_ftpClients.Add(serverUri, new FtpsClient());
ftp = _ftpClients[serverUri];

// try to connect!
if (!ftp.Connected) {
if (!ConnectFtp(ftp, userName, passWord, server, port, serverUri))
return false;
}

// dispose of the ftp on shutdown
Plug.OnShutDown += DisconnectFtp;

try {
ftp.PutFile(localFilePath, distantPath);
} catch (Exception) {
// might be disconnected??
try {
ftp.GetCurrentDirectory();
} catch (Exception) {
if (!ConnectFtp(ftp, userName, passWord, server, port, serverUri))
return false;
}
try {
// try to create the directory and then push the file again
ftp.MakeDir((Path.GetDirectoryName(distantPath) ?? "").Replace('\\', '/'), true);
ftp.PutFile(localFilePath, distantPath);
} catch (Exception e) {
if (!IsSpamming(serverUri, 2000, true))
ErrorHandler.ShowErrors(e, "Error sending a file! " + e.Message);
}
}
} catch (Exception e) {
ErrorHandler.ShowErrors(e, "Error sending a file to FTP");
}

return true;
}

public static bool ConnectFtp(FtpsClient ftp, string userName, string passWord, string server, int port, string serverUri) {
NetworkCredential credential = null;
if (!string.IsNullOrEmpty(userName))
credential = new NetworkCredential(userName, passWord);

var modes = new List<EsslSupportMode>();
typeof(EsslSupportMode).ForEach<EsslSupportMode>((s, l) => { modes.Add((EsslSupportMode) l); });

ftp.DataConnectionMode = EDataConnectionMode.Passive;
while (!ftp.Connected && ftp.DataConnectionMode == EDataConnectionMode.Passive) {
foreach (var mode in modes.OrderByDescending(mode => mode)) {
try {
var curPort = port > -1 ? port : ((mode & EsslSupportMode.Implicit) == EsslSupportMode.Implicit ? 990 : 21);
ftp.Connect(server, curPort, credential, mode, 1800);
ftp.Connected = true;
break;
} catch (Exception) {
//ignored
}
}
ftp.DataConnectionMode = EDataConnectionMode.Active;
}

// failed?
if (!ftp.Connected) {
if (!IsSpamming(serverUri, 2000, true)) {
UserCommunication.Notify(string.Format(@"Failed to connect to the FTP server!<br><br>The connexion used was:
<br>- Username : {0}
<br>- Password : {1}
<br>- Host : {2}
<br>- Port : {3}
", userName ?? "none", passWord ?? "none", server, port == -1 ? 21 : port), MessageImg.MsgError, "Ftp connexion", "Failed");
}
return false;
}
return true;
}

private static void DisconnectFtp() {
foreach (var ftpsClient in _ftpClients) {
ftpsClient.Value.Close();
}
_ftpClients.Clear();
}

#endregion
}
}
12 changes: 8 additions & 4 deletions 3PA/MainFeatures/Appli/Pages/Actions/DoDeployPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public override void OnShow() {

// cur env
lblCurEnv.Text = string.Format("{0} <a href='#'>(switch)</a>", ProEnvironment.Current.Name + (!string.IsNullOrEmpty(ProEnvironment.Current.Suffix) ? " - " + ProEnvironment.Current.Suffix : ""));
lbl_deployDir.Text = string.Format("The deployment directory is <a href='{0}'>{0}</a>", ProEnvironment.Current.BaseCompilationPath);
lbl_deployDir.Text = @"The deployment directory is " + ProEnvironment.Current.BaseCompilationPath.ToHtmlLink();

// update the rules for the current env
var currentDeployer = ProEnvironment.Current.Deployer;
Expand Down Expand Up @@ -267,7 +267,7 @@ private void BtStartOnButtonPressed(object sender, EventArgs eventArgs) {

UpdateProgressBar();

btCancel.SafeInvoke(button => button.Visible = true);
//btCancel.SafeInvoke(button => button.Visible = true);

if (_proDeployment.Start()) {
this.SafeInvoke(page => {
Expand Down Expand Up @@ -297,10 +297,11 @@ private void OnCompilationEnd(ProDeployment proDeployment) {
}
ResetScreen();
UpdateReport(_proDeployment.FormatDeploymentReport());
btReport.Visible = true;

// notify the user
if (!_proDeployment.HasBeenCancelled) {
UserCommunication.NotifyUnique("ReportAvailable", "The requested deployment is over,<br>please check the generated report to see the result :<br><br><a href= '#'>Cick here to see the report</a>", MessageImg.MsgInfo, "Deploy your application", "Report available", args => {
UserCommunication.NotifyUnique("ReportAvailable", "The requested deployment is over,<br>please check the generated report to see the result :<br><br><a href= '#'>Click here to see the report</a>", MessageImg.MsgInfo, "Deploy your application", "Report available", args => {
Appli.GoToPage(PageNames.MassCompiler);
UserCommunication.CloseUniqueNotif("ReportAvailable");
}, Appli.IsFocused() ? 10 : 0);
Expand Down Expand Up @@ -410,7 +411,10 @@ private void CbNameOnSelectedIndexChanged(YamuiComboBox sender) {
// allows to update the progression bar
private void UpdateProgressBar() {
progressBar.SafeInvoke(bar => {
bar.Text = @"Step " + _proDeployment.CurrentStep + @" / " + _proDeployment.TotalNumberOfSteps + @" ~ " + Math.Round(_proDeployment.ProgressionPercentage, 1) + @"%" + @" (elapsed time = " + _proDeployment.GetElapsedTime() + @")";
if (_proDeployment.ProgressionPercentage < 0.1)
bar.Text = @"Initializing, please wait...";
else
bar.Text = Math.Round(_proDeployment.ProgressionPercentage, 1) + @"%" + @" (in " + _proDeployment.GetElapsedTime() + @", step " + _proDeployment.CurrentStep + @"/" + _proDeployment.MaxStep + @")";
bar.Progress = _proDeployment.ProgressionPercentage;
});
}
Expand Down
2 changes: 1 addition & 1 deletion 3PA/MainFeatures/AppliMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private AppliMenu() {

#region Main menu

var goToDefItem = new MenuItem(this, "Go to definition", ImageResources.GoToDefinition, item => ProMisc.GoToDefinition(), "Go_To_Definition", "Ctrl+B");
var goToDefItem = new MenuItem(this, "Go to definition", ImageResources.GoToDefinition, item => ProMisc.GoToDefinition(false), "Go_To_Definition", "Ctrl+B") { Generic = true };
goToDefItem.SubText = "Middle click / " + goToDefItem.SubText;
var goToPreviousJump = new MenuItem(this, "Go to previous jump point", ImageResources.GoBackward, item => Npp.GoBackFromDefinition(), "Go_Backwards", "Ctrl+Shift+B") {
Generic = true
Expand Down
33 changes: 30 additions & 3 deletions 3PA/MainFeatures/AutoCompletionFeature/CompletionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,13 @@ public override Image ItemTypeImage {
/// </summary>
internal abstract class TextCompletionItem : CompletionItem {

public Token OriginToken { get; set; }

public override bool SurvivesFilter(int currentLine, ParsedScopeItem currentScope) {
return true;
}

public override string ToString() {
return "This is a piece of text extracted from your current file";
}
}

/// <summary>
Expand All @@ -817,7 +819,7 @@ public override CompletionType Type {
}

public override Image ItemTypeImage {
get { return ImageResources.Numbers; }
get { return ImageResources.Number; }
}
}

Expand All @@ -831,6 +833,14 @@ internal abstract class LangCompletionItem : CompletionItem {
public override bool SurvivesFilter(int currentLine, ParsedScopeItem currentScope) {
return true;
}

public override string ToString() {
var toDisplay = new StringBuilder();
toDisplay.Append(HtmlHelper.FormatSubtitle("DEFINITION"));
toDisplay.Append(HtmlHelper.FormatRow("Defined for the language", NppKeyword.Lang.LangName));
toDisplay.Append(HtmlHelper.FormatRow("Extracted from", NppKeyword.OriginFile.ToHtmlLink()));
return toDisplay.ToString();
}
}

/// <summary>
Expand All @@ -844,6 +854,23 @@ public override CompletionType Type {
public override Image ItemTypeImage {
get { return ImageResources.LangFunction; }
}

public override string ToString() {
var toDisplay = new StringBuilder(base.ToString());
if (NppKeyword.Overloads != null) {
toDisplay.Append(HtmlHelper.FormatSubtitle("OVERLOADS"));
foreach (var overload in NppKeyword.Overloads) {
toDisplay.Append("<div>" + overload.Description + "</div>");
toDisplay.Append(@"<div class='ToolTipcodeSnippet'>");
toDisplay.Append("<b>" + DisplayText + "</b> (");
toDisplay.Append(string.Join(", ", overload.Params));
toDisplay.Append(")<br>");
toDisplay.Append("<b>returns</b> " + overload.ReturnValue);
toDisplay.Append(@"</div>");
}
}
return toDisplay.ToString();
}
}

/// <summary>
Expand Down
52 changes: 42 additions & 10 deletions 3PA/MainFeatures/AutoCompletionFeature/NppLang.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ public LangDescription ReadApiFileIfNeeded() {
});
}

_keywords.Add(new NppKeyword(keyword) {
_keywords.Add(new NppKeywordApis(keyword, this) {
Overloads = overloads,
Origin = NppKeywordOrigin.AutoCompApiXml
Origin = NppKeywordOrigin.Api
});
}
}
Expand Down Expand Up @@ -298,8 +298,8 @@ public LangDescription ReadApiFileIfNeeded() {
foreach (var keyword in WebUtility.HtmlDecode(descendant.Value).Replace('\r', ' ').Replace('\n', ' ').Split(' ')) {
if (!string.IsNullOrEmpty(keyword) && !uniqueKeywords.Contains(keyword)) {
uniqueKeywords.Add(keyword);
_keywords.Add(new NppKeyword(keyword) {
Origin = NppKeywordOrigin.UserLangXml
_keywords.Add(new NppKeywordUserLangs(keyword, this) {
Origin = NppKeywordOrigin.UserLangs
});
}
}
Expand All @@ -318,8 +318,8 @@ public LangDescription ReadApiFileIfNeeded() {
foreach (var keyword in WebUtility.HtmlDecode(descendant.Value).Split(' ')) {
if (!string.IsNullOrEmpty(keyword) && !uniqueKeywords.Contains(keyword)) {
uniqueKeywords.Add(keyword);
_keywords.Add(new NppKeyword(keyword) {
Origin = NppKeywordOrigin.LangsXml
_keywords.Add(new NppKeywordLangs(keyword, this) {
Origin = NppKeywordOrigin.Langs
});
}
}
Expand Down Expand Up @@ -364,23 +364,55 @@ internal class NppKeyword {
public string Value { get; set; }

public NppKeywordOrigin Origin { get; set; }

public List<NppOverload> Overloads { get; set; }

public LangDescription Lang { get; private set; }

internal class NppOverload {
public string Description { get; set; }
public string ReturnValue { get; set; }
public List<string> Params { get; set; }
}

public NppKeyword(string value) {
public NppKeyword(string value, LangDescription langDescription) {
Value = value;
Lang = langDescription;
}

public virtual string OriginFile {
get { return ""; }
}
}

internal class NppKeywordLangs : NppKeyword {
public NppKeywordLangs(string value, LangDescription langDescription) : base(value, langDescription) {}

public override string OriginFile {
get { return Npp.ConfXml.FileNppLangsXml; }
}
}

internal class NppKeywordUserLangs : NppKeyword {
public NppKeywordUserLangs(string value, LangDescription langDescription) : base(value, langDescription) { }

public override string OriginFile {
get { return Npp.ConfXml.FileNppUserDefinedLang; }
}
}

internal class NppKeywordApis : NppKeyword {
public NppKeywordApis(string value, LangDescription langDescription) : base(value, langDescription) { }

public override string OriginFile {
get { return Path.Combine(Npp.FolderNppAutocompApis, Lang.LangName + ".xml"); }
}
}

internal enum NppKeywordOrigin {
LangsXml,
UserLangXml,
AutoCompApiXml
Langs,
UserLangs,
Api
}

#endregion
Expand Down
Loading

0 comments on commit 63269a2

Please sign in to comment.