mirror of
https://github.com/LorenzCK/OnTopReplica.git
synced 2024-05-21 04:43:55 +12:00
Regions in alphabetic order.
Some code reorganization.
This commit is contained in:
parent
ee7f86b704
commit
26741c7035
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
|
|
@ -81,7 +81,6 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace OnTopReplica {
|
|||
|
||||
public static void PopulateMenu(Form ownerForm, WindowManager windowManager, ToolStrip menu,
|
||||
WindowHandle currentHandle, EventHandler clickHandler) {
|
||||
var regions = Settings.Default.SavedRegions;
|
||||
var regions = GetRegions();
|
||||
|
||||
//Clear
|
||||
menu.Items.Clear();
|
||||
|
@ -59,33 +59,54 @@ namespace OnTopReplica {
|
|||
};
|
||||
tsi.Click += clickHandler;
|
||||
|
||||
if (regions != null && regions.Count > 0) {
|
||||
//Add subitem for no region
|
||||
var nullRegionItem = new ToolStripMenuItem(Strings.MenuWindowsWholeRegion);
|
||||
nullRegionItem.Tag = new WindowSelectionData {
|
||||
Handle = h,
|
||||
Region = null
|
||||
};
|
||||
nullRegionItem.Image = Resources.regions;
|
||||
nullRegionItem.Click += clickHandler;
|
||||
|
||||
tsi.DropDownItems.Add(nullRegionItem);
|
||||
|
||||
foreach (StoredRegion region in regions) {
|
||||
var regionItem = new ToolStripMenuItem(region.Name);
|
||||
regionItem.Tag = new WindowSelectionData {
|
||||
Handle = h,
|
||||
Region = region
|
||||
};
|
||||
regionItem.Click += clickHandler;
|
||||
|
||||
tsi.DropDownItems.Add(regionItem);
|
||||
}
|
||||
}
|
||||
PopulateRegions(tsi, h, clickHandler, regions);
|
||||
|
||||
menu.Items.Add(tsi);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void PopulateRegions(ToolStripMenuItem tsi, WindowHandle handle,
|
||||
EventHandler clickHandler, IEnumerable<StoredRegion> regions) {
|
||||
|
||||
if (regions != null) {
|
||||
//Add subitem for no region
|
||||
var nullRegionItem = new ToolStripMenuItem(Strings.MenuWindowsWholeRegion);
|
||||
nullRegionItem.Tag = new WindowSelectionData {
|
||||
Handle = handle,
|
||||
Region = null
|
||||
};
|
||||
nullRegionItem.Image = Resources.regions;
|
||||
nullRegionItem.Click += clickHandler;
|
||||
|
||||
tsi.DropDownItems.Add(nullRegionItem);
|
||||
|
||||
foreach (StoredRegion region in regions) {
|
||||
var regionItem = new ToolStripMenuItem(region.Name);
|
||||
regionItem.Tag = new WindowSelectionData {
|
||||
Handle = handle,
|
||||
Region = region
|
||||
};
|
||||
regionItem.Click += clickHandler;
|
||||
|
||||
tsi.DropDownItems.Add(regionItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<StoredRegion> GetRegions() {
|
||||
if (Settings.Default.SavedRegions == null || Settings.Default.SavedRegions.Count == 0)
|
||||
return null;
|
||||
|
||||
StoredRegion[] regions = new StoredRegion[Settings.Default.SavedRegions.Count];
|
||||
Settings.Default.SavedRegions.CopyTo(regions);
|
||||
|
||||
Array.Sort<StoredRegion>(regions, new Comparison<StoredRegion>((a, b) => {
|
||||
return a.Name.CompareTo(b.Name);
|
||||
}));
|
||||
|
||||
return regions;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ using System.Text;
|
|||
namespace OnTopReplica {
|
||||
/// <summary>A helper class that allows you to easily build and keep a list of Windows (in the form of WindowHandle objects).</summary>
|
||||
public class WindowManager {
|
||||
IList<WindowHandle> _windows = null;
|
||||
List<WindowHandle> _windows = null;
|
||||
|
||||
public enum EnumerationMode {
|
||||
/// <summary>All windows with 'Visible' flag.</summary>
|
||||
|
@ -28,7 +28,7 @@ namespace OnTopReplica {
|
|||
|
||||
/// <summary>Refreshes the window list.</summary>
|
||||
public void Refresh(EnumerationMode mode) {
|
||||
_windows = new List<WindowHandle>();
|
||||
_windows = new List<WindowHandle>();
|
||||
|
||||
NativeMethods.EnumWindowsProc proc = null;
|
||||
switch (mode) {
|
||||
|
@ -49,9 +49,9 @@ namespace OnTopReplica {
|
|||
}
|
||||
|
||||
|
||||
public IList<WindowHandle> Windows {
|
||||
public IEnumerable<WindowHandle> Windows {
|
||||
get {
|
||||
return _windows;
|
||||
return _windows;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,8 @@ namespace OnTopReplica {
|
|||
|
||||
private bool EnumWindowProcAll(IntPtr hwnd, IntPtr lParam) {
|
||||
if (NativeMethods.IsWindowVisible(hwnd)) {
|
||||
_windows.Add(new WindowHandle(hwnd, GetWindowTitle(hwnd)));
|
||||
string title = GetWindowTitle(hwnd);
|
||||
_windows.Add( new WindowHandle(hwnd, title));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -68,7 +69,8 @@ namespace OnTopReplica {
|
|||
if (NativeMethods.IsWindowVisible(hwnd)) {
|
||||
//Check if window has no parent
|
||||
if ((long)NativeMethods.GetParent(hwnd) == 0 && NativeMethods.GetDesktopWindow() != hwnd) {
|
||||
_windows.Add(new WindowHandle(hwnd, GetWindowTitle(hwnd)));
|
||||
string title = GetWindowTitle(hwnd);
|
||||
_windows.Add( new WindowHandle(hwnd, title));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -94,9 +96,8 @@ namespace OnTopReplica {
|
|||
bool hasOwner = (long)NativeMethods.GetWindow(hwnd, NativeMethods.GetWindowMode.GW_OWNER) != 0;
|
||||
NativeMethods.WindowExStyles exStyle = (NativeMethods.WindowExStyles)NativeMethods.GetWindowLong(hwnd, NativeMethods.WindowLong.ExStyle);
|
||||
|
||||
if (((exStyle & NativeMethods.WindowExStyles.ToolWindow) == 0 && !hasOwner) ||
|
||||
((exStyle & NativeMethods.WindowExStyles.AppWindow) == NativeMethods.WindowExStyles.AppWindow && hasOwner)) {
|
||||
//Accept
|
||||
if (((exStyle & NativeMethods.WindowExStyles.ToolWindow) == 0 && !hasOwner) || //unowned non-tool window
|
||||
((exStyle & NativeMethods.WindowExStyles.AppWindow) == NativeMethods.WindowExStyles.AppWindow && hasOwner)) { //owned application window
|
||||
_windows.Add(new WindowHandle(hwnd, title));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,4 +48,4 @@
|
|||
</setting>
|
||||
</OnTopReplica.Properties.Settings>
|
||||
</userSettings>
|
||||
<startup/></configuration>
|
||||
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
|
||||
|
|
Loading…
Reference in a new issue