Skip to content

Commit

Permalink
number of changes and new features
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Jul 17, 2012
1 parent 110b9d6 commit cddff65
Show file tree
Hide file tree
Showing 59 changed files with 2,638 additions and 613 deletions.
5 changes: 5 additions & 0 deletions O2.FluentSharp.BCL/O2.FluentSharp.BCL.csproj
Expand Up @@ -46,6 +46,8 @@
<Compile Include="O2_DotNetWrappers\DotNet\ClickOnceDeployment.cs" />
<Compile Include="O2_DotNetWrappers\DotNet\CompileEngine_WinForms.cs" />
<Compile Include="O2_DotNetWrappers\DotNet\DnD.cs" />
<Compile Include="O2_DotNetWrappers\ExtensionMethods\WinForms_ExtensionMethods_Misc_GUI_Helpers.cs" />
<Compile Include="O2_DotNetWrappers\ExtensionMethods\WinForms_ExtensionMethods_WebBrowser.cs" />
<Compile Include="O2_DotNetWrappers\ExtensionMethods\Clipboard_ExtensionMethods.cs" />
<Compile Include="O2_DotNetWrappers\ExtensionMethods\ComObjects_ExtensionMethods.cs" />
<Compile Include="O2_DotNetWrappers\ExtensionMethods\Compilation_ExtensionMethods.cs" />
Expand Down Expand Up @@ -171,6 +173,9 @@
<Compile Include="O2_Views_ASCX\Ascx\DataViewers\ascx_FunctionsViewer.Designer.cs">
<DependentUpon>ascx_FunctionsViewer.cs</DependentUpon>
</Compile>
<Compile Include="O2_Views_ASCX\Ascx\DataViewers\ascx_ObjectViewer.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="O2_Views_ASCX\Ascx\DataViewers\ascx_ShowInfo.cs">
<SubType>UserControl</SubType>
</Compile>
Expand Down
Expand Up @@ -4,12 +4,19 @@
using System.Text;
using System.Windows.Forms;
using O2.DotNetWrappers.ExtensionMethods;
using System.Drawing;
using System.Drawing;
using O2.Views.ASCX.classes.MainGUI;

namespace O2.DotNetWrappers.ExtensionMethods
{
public static class ConfigFiles_ExtensionMethods_WinForms
{
{
public static Panel editLocalConfigFile(this string file)
{
var panel = O2Gui.open<Panel>("Editing local config file: {0}".format(file), 700, 300);
return file.editLocalConfigFile(panel);
}

public static T editLocalConfigFile<T>(this string file, T control)
where T : Control
{
Expand Down
Expand Up @@ -14,31 +14,29 @@ public static class Threads_ExtensionMethods
/// <param name="control"></param>
/// <param name="codeToInvoke"></param>
/// <returns></returns>
public static object invokeOnThread(this Control control, Func<object> codeToInvoke)
public static T invokeOnThread<T>(this Control control, Func<T> codeToInvoke)
{
try
{
{
if (control.isNull() || control.IsDisposed)
return default(T);
if (control.InvokeRequired)
{
object returnData = null;
T returnData = default(T);
//lock (control)
//{
var sync = new AutoResetEvent(false);
var sync = new AutoResetEvent(false);
if (control.IsDisposed)
return default(T);
control.Invoke(new EventHandler((sender, e) =>
{
//try
//{
returnData = codeToInvoke();
//}
//catch (Exception ex)
//{
// System.Diagnostics.Debug.WriteLine("in invokeOnThread: " + ex.Message);
//}
{
if (control.IsDisposed.isFalse())
returnData = codeToInvoke();
sync.Set();
}));
if (sync.WaitOne(2000).isFalse())
{
return null;
return default(T);
}
//}
return returnData;
Expand All @@ -48,8 +46,8 @@ public static object invokeOnThread(this Control control, Func<object> codeToInv

catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
return null;
System.Diagnostics.Debug.WriteLine(ex.Message);
return default(T);
}
}

Expand All @@ -59,16 +57,22 @@ public static object invokeOnThread(this Control control, Func<object> codeToInv
/// </summary>
public static void invokeOnThread(this Control control, O2Thread.FuncVoid codeToInvoke)
{
if (control.isNull())
if (control.isNull() || control.IsDisposed)
{
"Control.invokeOnThread, provided control value was null (so not invoking code)".error();
"Control.invokeOnThread, provided control value was null or dispose(so not invoking code)".error();
return;
}
try
{
if (control.InvokeRequired)
control.Invoke(new EventHandler((sender, e) => codeToInvoke()));
else
{
if (control.InvokeRequired)
{
control.Invoke(new EventHandler((sender, e)=>{
if (control.IsDisposed)
return;
codeToInvoke();
}));
}
else
codeToInvoke();
}

Expand Down Expand Up @@ -180,6 +184,35 @@ public static bool okThread(this Form form, EventHandler target)
System.Diagnostics.Debug.WriteLine(ex.Message);
return false;
}
}
}

public static T onThread<T>(this T control, Action action) where T : Control
{
return control.update((c) => action());
}
public static T onThread<T>(this T control, Action<T> action) where T : Control
{
return (T)control.invokeOnThread(
() =>
{
action(control);
return control;
});
}
public static T update<T>(this T control, Action updateAction) where T : Control
{
return control.update((c) => updateAction());
}
public static T update<T>(this T control, Action<T> updateAction) where T : Control
{
return (T)control.invokeOnThread(
() =>
{
control.refresh_Disable();
updateAction(control);
control.refresh_Enable();
return control;
});
}
}
}
Expand Up @@ -660,10 +660,14 @@ public static List<Control> controls(this List<Control> controls, bool includeRo
}
public static T control<T>(this Control control, bool searchRecursively) where T : Control
{
if (control.notNull())
foreach (var childControl in control.controls(searchRecursively))
if (childControl is T)
return (T)childControl;
try
{
if (control.notNull())
foreach (var childControl in control.controls(searchRecursively))
if (childControl is T)
return (T)childControl;
}
catch {}
return null;
}
public static List<Control> list(this Control.ControlCollection controlCollection)
Expand Down Expand Up @@ -847,13 +851,15 @@ public static Bitmap fromClipboardGetImage(this Control control)
control.AllowDrop = true;
control.DragEnter += (sender, e) => Dnd.setEffect(e);
control.DragDrop += (sender, e)
=>
{
var fileOrFolder = Dnd.tryToGetFileOrDirectoryFromDroppedObject(e);
if (fileOrFolder.valid())
onDropFileOrFolder(fileOrFolder);
};
control.DragDrop += (sender, e)=>{
var fileOrFolder = Dnd.tryToGetFileOrDirectoryFromDroppedObject(e);
if (fileOrFolder.valid())
O2Thread.mtaThread(
() =>{
onDropFileOrFolder(fileOrFolder);
});
};
return control;
});
//
Expand Down Expand Up @@ -1369,6 +1375,11 @@ public static Panel insert_Below(this Control control, int width, st
return control.insert_Below<Panel>(width).add_GroupBox(title).add_Panel();
}

public static Panel insert_ActionPanel(this Control control)
{
return control.insert_Above(40, "Actions");
}

// Key Events
public static T onKeyPress<T>(this T control, Func<Keys, bool> callback) where T : Control
{
Expand Down Expand Up @@ -1399,8 +1410,9 @@ public static Panel insert_Below(this Control control, int width, st
control.KeyDown += (sender, e) =>
{
if (e.KeyData == onlyFireOnKey)
{
callback(control.Text);
{
var text = control.Text;
O2Thread.mtaThread(() => callback(text));
e.Handled = true;
e.SuppressKeyPress = true;
}
Expand Down Expand Up @@ -1433,7 +1445,7 @@ public static Panel insert_Below(this Control control, int width, st
textBox.KeyUp += (sender, e) =>
{
if (onlyFireOnEnter.isFalse() || e.KeyCode == Keys.Enter)
onTextChanged(textBox.get_Text());
O2Thread.mtaThread(()=>onTextChanged(textBox.get_Text()));
};
return control;
}
Expand All @@ -1451,7 +1463,7 @@ public static Panel insert_Below(this Control control, int width, st
var text = comboBox.Text;
if (onlyFireOnEnter.isFalse() || e.KeyCode == Keys.Enter)
{
onTextChanged(text);
O2Thread.mtaThread(()=> onTextChanged(text));
if (addToHistory)
{
comboBox.Items.Insert(0, text);
Expand Down Expand Up @@ -1578,7 +1590,11 @@ public static string askUserForDirectory(this Control control, string baseDirect
public static T pink<T>(this T control) where T : Control
{
return control.backColor(Color.LightPink);
}
}
public static T red<T>(this T control) where T : Control
{
return control.backColor(Color.Red);
}
public static T green<T>(this T control) where T : Control
{
return control.backColor(Color.LightGreen);
Expand Down Expand Up @@ -1631,5 +1647,28 @@ public static Label append_Below_Label(this Control control, string label)
{
return control.parent().add_Label(label, control.top() + 22 , control.left());
}

//Refresh enable and disable
public static T refresh_Disable<T>(this T control) where T : Control
{
return control.beginUpdate();
}

public static T refresh_Enable<T>(this T control) where T : Control
{
return control.endUpdate();
}

public static T beginUpdate<T>(this T control) where T : Control
{
control.invoke("BeginUpdateInternal");
return control;
}

public static T endUpdate<T>(this T control) where T : Control
{
control.invoke("EndUpdateInternal");
return control;
}
}
}
Expand Up @@ -12,6 +12,9 @@
using O2.DotNetWrappers.DotNet;
using System.Drawing;
using O2.Views.ASCX.Ascx.MainGUI;
using System.Diagnostics;
using System.Reflection;
using System.IO;

namespace O2.DotNetWrappers.ExtensionMethods
{
Expand Down Expand Up @@ -245,6 +248,12 @@ public static Icon set_As_Default_Form_Icon(this Icon icon)
typeof(Form).fieldValue("defaultIcon", icon);
return icon;
}

public static Icon asIcon(this Bitmap bitmap)
{
return Icon.FromHandle(bitmap.GetHicon());
}

public static Icon icon(this string iconFile)
{
try
Expand All @@ -256,7 +265,29 @@ public static Icon icon(this string iconFile)
"[icon] {0}".error(ex.Message);
return null;
}
}
}

public static string saveAs_Icon(this Bitmap bitmap)
{
return bitmap.saveAs_Icon(".ico".tempFile());
}

public static string saveAs_Icon(this Bitmap bitmap, string targetFile)
{
return bitmap.asIcon().saveAs(targetFile);
}
public static string save(this Icon icon)
{
return icon.saveAs(".ico".tempFile());
}

public static string saveAs(this Icon icon, string targetFile)
{
using (FileStream fileStream = new FileStream(targetFile, FileMode.Create))
icon.Save(fileStream);
return targetFile;
}

public static T set_Form_Icon<T>(this T control, string iconFile) where T : Control
{
return control.set_Form_Icon(iconFile.icon());
Expand Down Expand Up @@ -284,6 +315,16 @@ public static Form set_O2Icon(this Form form)
return form.set_Icon("O2Logo.ico".local().icon());
}

public static Form set_DefaultIcon(this Form form)
{
try
{
var icon = Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location);
form.set_Icon(icon);
}
catch { }
return form;
}
public static Form clientSize(this Form form, int width, int height)
{
return (Form)form.invokeOnThread(() =>
Expand Down

0 comments on commit cddff65

Please sign in to comment.