Skip to content

Commit

Permalink
Allow profiles to be loaded from install and user location in home di…
Browse files Browse the repository at this point in the history
…rectory

Allow css file for report to be loaded from home directory but if not exists fall back to default
  • Loading branch information
robincornelius committed Feb 1, 2017
1 parent fa6d774 commit 1c03f44
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
45 changes: 34 additions & 11 deletions EDSTest/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,48 @@ public ODEditor_MainForm()
loadprofiles();

insertToolStripMenuItem.Enabled = false;


}

private void loadprofiles()
{
string[] profilelist = Directory.GetFiles(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)+Path.DirectorySeparatorChar+"Profiles");
ToolStripMenuItem[] items = new ToolStripMenuItem[profilelist.Length];

// load default profiles from the install directory
// load user profiles from the My Documents\.edseditor\profiles\ folder
// Personal is my documents in windows and ~ in mono

List<string> profilelist = Directory.GetFiles(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar + "Profiles").ToList();
string homepath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal), ".edseditor");
homepath = Path.Combine(homepath, "profiles");

if (Directory.Exists(homepath))
{
profilelist.AddRange(Directory.GetFiles(homepath).ToList());
}

int count = 0;
//some attempt to validate files

foreach (string file in profilelist)
{
if (Path.GetExtension(file) == ".xml")
count++;
}


ToolStripMenuItem[] items = new ToolStripMenuItem[count];

int x = 0;
foreach(string file in profilelist)
{

ToolStripMenuItem i = new ToolStripMenuItem();
i.Name = Path.GetFileName(file);
i.Text = Path.GetFileName(file);
i.Click += ProfileAddClick;
i.Image = Properties.Resources.InsertColumn_5626;
items[x++] = i;
if (Path.GetExtension(file) == ".xml")
{
ToolStripMenuItem i = new ToolStripMenuItem();
i.Name = Path.GetFileName(file);
i.Text = Path.GetFileName(file);
i.Click += ProfileAddClick;
i.Image = Properties.Resources.InsertColumn_5626;
items[x++] = i;
}
}

insertToolStripMenuItem.DropDownItems.AddRange(items);
Expand Down
17 changes: 16 additions & 1 deletion EDSTest/ReportView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@ public ReportView(string pathtohtml)

private void WebBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
string text = System.IO.File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "style.css"));

//Try to load a css override from ~/.edseditor/style.css first then fallback to installed default

string csspath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal), ".edseditor");
csspath = Path.Combine(csspath, "style.css");

if(!File.Exists(csspath))
{
csspath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "style.css");
}

if (!File.Exists(csspath))
return;

string text = System.IO.File.ReadAllText(csspath);

mshtml.HTMLDocument CurrentDocument = (HTMLDocument)webBrowser1.Document.DomDocument;
mshtml.IHTMLStyleSheet styleSheet = CurrentDocument.createStyleSheet("", 0);
styleSheet.cssText = text;
Expand Down

0 comments on commit 1c03f44

Please sign in to comment.