Skip to content

Commit

Permalink
Remove extension handling
Browse files Browse the repository at this point in the history
  • Loading branch information
luboid committed Jun 11, 2018
1 parent 5226868 commit f564fad
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 112 deletions.
24 changes: 24 additions & 0 deletions TrivadisPLSQLCop/TrivadisPLSQLCop/Callbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ namespace TrivadisPLSQLCop

delegate void IdeGetPopupObject(out IntPtr objectType, out IntPtr objectOwner, out IntPtr objectName, out IntPtr subObject); //74

[return: MarshalAs(UnmanagedType.Bool)]
delegate bool IdeGetWindowObject(out IntPtr objectType, out IntPtr objectOwner, out IntPtr objectName, out IntPtr subObject); //110

delegate IntPtr IdeGetObjectSource(byte[] objectType, byte[] objectOwner, byte[] objectName); //79



public class Callbacks
{
const int CREATE_WINDOW_CALLBACK = 20;
Expand All @@ -58,6 +63,7 @@ public class Callbacks
const int CREATE_POPUP_ITEM_CALLBACK = 69;
const int GET_POPUP_OBJECT_CALLBACK = 74;
const int GET_OBJECT_SOURCE_CALLBACK = 79;
const int GET_WINDOW_OBJECT_CALLBACK = 110;
//IDE_GetFileData
static IdeCreateWindow createWindowCallback;
static IdeSetText setTextCallback;
Expand All @@ -75,6 +81,7 @@ public class Callbacks
static IdeCreatePopupItem createPopupItemCallback;
static IdeGetPopupObject getPopupObjectCallback;
static IdeGetObjectSource getObjectSourceCallback;
static IdeGetWindowObject getWindowObjectCallback;

public static string GetObjectSource(string objectType, string objectOwner, string objectName)
{
Expand All @@ -84,6 +91,20 @@ public static string GetObjectSource(string objectType, string objectOwner, stri
objectName.ToUTF8ByteArray()).PtrUTF8StrToString();
}

public static bool GetWindowObject(out string objectType, out string objectOwner, out string objectName, out string subObject)
{
IntPtr objectTypePtr, objectOwnerPtr, objectNamePtr, subObjectPtr;

var result = getWindowObjectCallback(out objectTypePtr, out objectOwnerPtr, out objectNamePtr, out subObjectPtr);

objectType = objectTypePtr.PtrUTF8StrToString();
objectOwner = objectOwnerPtr.PtrUTF8StrToString();
objectName = objectNamePtr.PtrUTF8StrToString();
subObject = subObjectPtr.PtrUTF8StrToString();

return result;
}

public static void GetPopupObject(out string objectType, out string objectOwner, out string objectName, out string subObject)
{
IntPtr objectTypePtr, objectOwnerPtr, objectNamePtr, subObjectPtr;
Expand Down Expand Up @@ -233,6 +254,9 @@ public static void RegisterCallback(int index, IntPtr function)
case GET_OBJECT_SOURCE_CALLBACK:
getObjectSourceCallback = Marshal.GetDelegateForFunctionPointer<IdeGetObjectSource>(function);
break;
case GET_WINDOW_OBJECT_CALLBACK:
getWindowObjectCallback = Marshal.GetDelegateForFunctionPointer<IdeGetWindowObject>(function);
break;

}
}
Expand Down
73 changes: 21 additions & 52 deletions TrivadisPLSQLCop/TrivadisPLSQLCop/PlugIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,7 @@ public class PlugIn
private const int PLUGIN_POPUPMENU_OBJECT_BROWSER_INDEX = 5;
private const int PLUGIN_POPUPMENU_OBJECT_BROWSER_BOTH_INDEX = 6;

private static ConcurrentDictionary<string, string> extesionsMap =
new ConcurrentDictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
private static ConcurrentDictionary<string, string> objectTypeExtesions =
new ConcurrentDictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);

public static int Id { get; set; }
static PlugIn()
{
objectTypeExtesions["PACKAGE"] = "pks";
objectTypeExtesions["PACKAGE BODY"] = "pkb";
objectTypeExtesions["FUNCTION"] = "fnc";
objectTypeExtesions["PROCEDURE"] = "prc";
objectTypeExtesions["TRIGGER"] = "trg";
objectTypeExtesions["TYPE"] = "tps";
objectTypeExtesions["TYPE BODY"] = "tbp";
objectTypeExtesions["VIEW"] = "vw";
// .sql, .prc, .fnc, .pks, .pkb, .trg, .vw, .tps, .tbp, .plb, .pls, .rcv, .spc, .typ, .aqt, .aqp, .ctx, .dbl, .tab, .dim,
// .snp, .con, .collt, .seq, .syn, .grt, .sp, .spb, .sps.
}


[DllExport("IdentifyPlugIn", CallingConvention = CallingConvention.Cdecl)]
public static string IdentifyPlugIn(int id)
Expand Down Expand Up @@ -122,7 +103,7 @@ static void ClearDirectories()
Directory.CreateDirectory(content);
}
}
public static void RunPLSQLCop(string extension, string title)
public static void RunPLSQLCop(string title)
{
string html = Path.Combine(TempDirectory, "result.html");
string check = SettingsDialog.GetTrivadisCheck(Id);
Expand All @@ -132,7 +113,7 @@ public static void RunPLSQLCop(string extension, string title)
p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.FileName = SettingsDialog.GetTrivadisLocation(Id);
p.Arguments = string.Format("path=\"{0}\" html=true output=\"{1}\" filter=\"({2})$\" check=\"{3}\" skip=\"{4}\"",
ContentDirectory, html, extension, check, skip);
ContentDirectory, html, "sql", check, skip);

using (var f = System.Diagnostics.Process.Start(p))
{
Expand All @@ -152,6 +133,18 @@ public static void RunCurrenWindowPLSQLCop()
{
try
{
string objectType, objectOwner, objectName, subObject;
if (!Callbacks.GetWindowObject(out objectType, out objectOwner, out objectName, out subObject))
{
return;
}

var items = new string[] { "PACKAGE", "PACKAGE BODY", "FUNCTION", "PROCEDURE", "TRIGGER", "TYPE", "TYPE BODY" };
if (Array.IndexOf<string>(items, objectType) == -1)
{
return;
}

string fileNameWithPath = null;
string fileName = null;
string fileNameExtension = null;
Expand All @@ -176,19 +169,12 @@ public static void RunCurrenWindowPLSQLCop()

ClearDirectories();

string copyTo = Path.Combine(ContentDirectory, fileName);
string copyToExtension = fileNameExtension.Replace(".", string.Empty);

var items = ExtensionMap;
if (items.ContainsKey(copyToExtension))
{
copyToExtension = items[copyToExtension];
copyTo = Path.ChangeExtension(copyTo, "." + copyToExtension);
}
string copyTo = Path.Combine(ContentDirectory,
Path.ChangeExtension(fileName, ".sql"));

Utils.CopyTo(fileNameWithPath, Path.Combine(ContentDirectory, copyTo), Encoding.Default /*new System.Text.UTF8Encoding(false)*/);

RunPLSQLCop(copyToExtension, fileName);
RunPLSQLCop(Path.GetFileNameWithoutExtension(copyTo));

}
catch (Exception ex)
Expand Down Expand Up @@ -217,12 +203,11 @@ public static void RunContextMenuPLSQLCop(int context)

ClearDirectories();

string extension = objectTypeExtesions[objectType];
string fileName = objectName + "." + extension;
string fileName = Path.Combine(ContentDirectory, objectName + ".sql");

File.WriteAllText(Path.Combine(ContentDirectory, fileName), builder.ToString(), Encoding.Default /*new System.Text.UTF8Encoding(false)*/);
File.WriteAllText(fileName, builder.ToString(), Encoding.Default /*new System.Text.UTF8Encoding(false)*/);

RunPLSQLCop(extension, fileName);
RunPLSQLCop(objectName);
}
catch (Exception ex)
{
Expand All @@ -241,29 +226,13 @@ public static void AfterExecuteWindow(int windowType, int result)
RunCurrenWindowPLSQLCop();
}

static ConcurrentDictionary<string, string> ExtensionMap
{
get
{
if (0 == extesionsMap.Count)
{
SettingsDialog.GetTrivadisExtensionMap(Id).MapToDictionary(extesionsMap);
}
return extesionsMap;
}
}

[DllExport("OnMenuClick", CallingConvention = CallingConvention.Cdecl)]
public static void OnMenuClick(int index)
{
switch (index)
{
case PLUGIN_MENU_PREFERENCES_INDEX:
SettingsDialog frm = new SettingsDialog(Id, PLUGIN_NAME);
if (frm.ShowDialog())
{
extesionsMap.Clear();
}
(new SettingsDialog(Id, PLUGIN_NAME)).ShowDialog();
break;
case PLUGIN_POPUPMENU_INDEX:
RunCurrenWindowPLSQLCop();
Expand Down
51 changes: 8 additions & 43 deletions TrivadisPLSQLCop/TrivadisPLSQLCop/SettingsDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions TrivadisPLSQLCop/TrivadisPLSQLCop/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public static string GetTrivadisLocation(int id)
return Callbacks.GetPrefAsString(id, "", "TrivadisLocation", @"C:\tvdcc\tvdcc.cmd");
}

public static string GetTrivadisExtensionMap(int id)
{
return Callbacks.GetPrefAsString(id, "", "TrivadisExtensionMap", "pck|pks,bdy|pkb,spc|pks");
}

public static string GetTrivadisCheck(int id)
{
return Callbacks.GetPrefAsString(id, "", "TrivadisCheck", "");
Expand All @@ -42,15 +37,13 @@ public static bool GetTrivadisRunAfterCompile(int id)
public new bool ShowDialog()
{
textBox1.Text = GetTrivadisLocation(id);
textBox2.Text = GetTrivadisExtensionMap(id);
textBox3.Text = GetTrivadisCheck(id);
textBox4.Text = GetTrivadisSkip(id);
checkBox1.Checked = GetTrivadisRunAfterCompile(id);

if (base.ShowDialog() == DialogResult.OK)
{
Callbacks.SetPrefAsString(id, "", "TrivadisLocation", textBox1.Text);
Callbacks.SetPrefAsString(id, "", "TrivadisExtensionMap", textBox2.Text);
Callbacks.SetPrefAsString(id, "", "TrivadisCheck", textBox3.Text);
Callbacks.SetPrefAsString(id, "", "TrivadisSkip", textBox4.Text);
Callbacks.SetPrefAsBool(id, "", "TrivadisRunAfterCompile", checkBox1.Checked);
Expand All @@ -63,15 +56,5 @@ private void SettingsDialog_Shown(object sender, EventArgs e)
{
textBox1.Focus();
}

private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = @"C:\tvdcc\tvdcc.cmd";
textBox2.Text = "pck|pks,bdy|pkb,spc|pks";
textBox3.Text = "";
textBox4.Text = "";
checkBox1.Checked = true;

}
}
}

0 comments on commit f564fad

Please sign in to comment.