Skip to content

Commit bec8926

Browse files
Merge pull request #65 from freshprogrammer/dev
0.7.4 Added Move to center and tweaked transparency increment
2 parents f28591b + dc06a49 commit bec8926

7 files changed

Lines changed: 83 additions & 29 deletions

File tree

FreshTools/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.7.3.0")]
36-
[assembly: AssemblyFileVersion("0.7.3.0")]
35+
[assembly: AssemblyVersion("0.7.4.0")]
36+
[assembly: AssemblyFileVersion("0.7.4.0")]

FreshTools/code/FreshTools.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ static void Main(string[] args)
130130
public void LoadConfig()
131131
{
132132
settingsFile = new VariablesFile(configFilePath, null, false);
133+
UpdateConfigFile();
133134
VariableLibrary vars = settingsFile.variables;
134-
135+
135136
//load variables
136137
WindowManager.LoadSnapSizes(settingsFile);
137138
WindowManager.LoadHotKeys(settingsFile);
@@ -149,6 +150,18 @@ public void LoadConfig()
149150
SaveConfig();
150151
}
151152

153+
public void UpdateConfigFile()
154+
{
155+
//attempt to fix script file
156+
//rename old variables to match
157+
settingsFile = new VariablesFile(configFilePath, null, false);
158+
settingsFile.RenameVariable("HotKey_DecreaseWindowTranspancy", "HotKey_DecreaseWindowTransparency");
159+
settingsFile.RenameVariable("HotKey_IncreaseWindowTranspancy", "HotKey_IncreaseWindowTransparency");
160+
161+
//remove dead variables
162+
163+
}
164+
152165
/// <summary>
153166
/// Make sure config variables that can be changed are updated in config file
154167
/// </summary>

FreshTools/code/Scripting/VariableLibrary.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ public class VariableLibrary : IEnumerable
1212
private VariablesComparator variablesComparator;
1313
private bool variableListSorted = true;
1414
private Variable searchDummy;
15+
public readonly bool CaseSensitive;
1516

1617
public VariableLibrary(bool caseSensitive)
1718
{
19+
this.CaseSensitive = caseSensitive;
1820
variablesComparator = new VariablesComparator(caseSensitive);
1921
variables = new List<Variable>();
2022
}

FreshTools/code/Scripting/VariablesFile.cs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34

45
namespace FreshTools
@@ -66,9 +67,46 @@ public void LoadFile(string fileName)
6667
streamReader.Close();
6768
}
6869
Profiler.Stop();
69-
}
70+
}
7071

72+
public void RenameVariable(string oldName, string newName)
73+
{
74+
for (int i = 0; i < lines.Count; i++)
75+
{
76+
try
77+
{
78+
string varName = lines[i].Content;
79+
if (varName == null || varName.Trim().Length == 0 || varName.Substring(0, 2) == "//")
80+
continue;
81+
varName = varName.Replace("var ", "").Trim();
82+
varName = varName.Substring(0, varName.IndexOf("=")).Trim();
83+
StringComparison sc = StringComparison.CurrentCulture;
84+
if (variables.CaseSensitive)
85+
sc = StringComparison.CurrentCultureIgnoreCase;
86+
87+
if (varName.Equals(oldName, sc))
88+
{
89+
variables.RemoveVariable(oldName);
90+
91+
if (newName != null)
92+
{
93+
//TODO not sure this should properly recursively scan through other script files.
94+
lines[i] = new ScriptLine("var " + newName + " = " + lines[i].Content.Substring(lines[i].Content.IndexOf("=")+1), this, parent);
95+
variables.Add(lines[i].Variable);
96+
}
97+
else//remove variable
98+
lines.RemoveAt(i--);
99+
break;
100+
}
101+
}
102+
catch (ArgumentOutOfRangeException) { }
103+
}
104+
}
71105

106+
public void RemoveVariable(string name)
107+
{
108+
RenameVariable(name, null);
109+
}
72110

73111
//preserve comments and such by preserving all original text... not done
74112
public string SaveString()

FreshTools/code/Systems/MouseListener.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ private static void ConsumeKeyAsync()
209209
Thread.Sleep(3);
210210
}
211211
var item = queue.Dequeue();
212-
if (item is bool) break;
212+
if (item is bool)
213+
break;
213214

214215
if(item!=null)
215216
MListener_MouseEvent(item as RawMouseEventArgs);

FreshTools/code/Systems/WindowManager.cs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public static class WindowManager
5353
//alpha control variables
5454
private static IntPtr lastWindowAlphaHandle = IntPtr.Zero;
5555
private static byte lastWindowAlpha = 0;
56-
private const byte WindowAlphaIncrement = 32;
57-
private const byte MinWindowAlpha = 32;
56+
private const byte WindowAlphaIncrement = 16;
57+
private const byte MinWindowAlpha = 16;
5858

5959
#region Setup and teardown
6060
static WindowManager()
@@ -254,7 +254,6 @@ public static void LoadHotKeys(VariablesFile settingsFile)
254254
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_RestoreLayout3", "|^!D3").String, out hk))
255255
snapHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, RestoreLayout3));
256256
//corner move hotkeys - with defaults
257-
//if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_MoveActiveWindowToBottomLeft", "|^+G").String, out hk))
258257
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_MoveActiveWindowToBottomLeft", "|^!End").String, out hk))
259258
snapHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, MoveActiveWindowToBottomLeft));
260259
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_MoveActiveWindowToBottomRight", "|^!PageDown").String, out hk))
@@ -263,8 +262,8 @@ public static void LoadHotKeys(VariablesFile settingsFile)
263262
snapHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, MoveActiveWindowToTopLeft));
264263
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_MoveActiveWindowToTopRight", "|^!PageUp").String, out hk))
265264
snapHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, MoveActiveWindowToTopRight));
266-
//if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_MoveActiveWindowToCenter", "|^!+NumPad5").String, out hk)) //broken because of shift numpad
267-
// snapHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, MoveActiveWindowToTopRight));
265+
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_MoveActiveWindowToCenter", "|^!Multiply").String, out hk))
266+
snapHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, MoveActiveWindowToCenter));
268267

269268
//altsnap hotkeys - with defaults
270269
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_Alt_SnapActiveWindowToBottomLeft", "|^!Oemcomma").String, out hk))
@@ -291,10 +290,10 @@ public static void LoadHotKeys(VariablesFile settingsFile)
291290
miscHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, MoveActiveWindowToLeftScreen));
292291
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_MoveActiveWindowToRightScreen", "|^+S").String, out hk))
293292
miscHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, MoveActiveWindowToRightScreen));
294-
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_IncreaseWindowTranspancy", "^!Add").String, out hk))
295-
miscHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, IncreaseWindowTranspancy));
296-
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_DecreaseWindowTranspancy", "^!Subtract").String, out hk))
297-
miscHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, DecreaseWindowTranspancy));
293+
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_IncreaseWindowTransparency", "^!Add").String, out hk))
294+
miscHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, IncreaseWindowTransparency));
295+
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_DecreaseWindowTransparency", "^!Subtract").String, out hk))
296+
miscHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, DecreaseWindowTransparency));
298297
if (HotKey.TryParseHotKey(settingsFile.variables.GetVariable("HotKey_SendActiveWindowToBack", "|^!W").String, out hk))
299298
miscHotKeys.Add(new HotKey(hk.Modifiers, hk.Key, SendActiveWindowToBack));
300299

@@ -595,7 +594,7 @@ private static void MoveActiveWindowTo(int x, int y, int newWidth, int newHeight
595594
}
596595
}
597596

598-
private static void SetWindowTransparancy(int d)
597+
private static void SetWindowTransparency(int d)
599598
{
600599
byte a;
601600
IntPtr handle = GetForegroundWindow();
@@ -623,7 +622,7 @@ private static void SetWindowTransparancy(int d)
623622

624623
//Enable extended layered style on window if not enabled
625624
SetWindowLong(handle, GWL_EXSTYLE, GetWindowLong(handle, GWL_EXSTYLE) | WS_EX_LAYERED);
626-
//set window transparency
625+
//set window Transparency
627626
SetLayeredWindowAttributes(handle, 0, a, LWA_ALPHA);
628627

629628
lastWindowAlpha = a;
@@ -729,7 +728,7 @@ private static void SnapActiveWindow(SnapDirection dir)
729728
}
730729

731730

732-
private static void MoveActiveWindowToCorner(SnapDirection dir)
731+
private static void MoveActiveWindowTo(SnapDirection dir)
733732
{
734733
//keep window size and move to a given corner or center
735734
if (!(dir == SnapDirection.TopLeft || dir == SnapDirection.TopRight || dir == SnapDirection.BottomLeft || dir == SnapDirection.BottomRight || dir == SnapDirection.Center))
@@ -807,30 +806,30 @@ public static void SnapActiveWindowToBottomRight(object o, HotKeyEventArgs args)
807806
}
808807
#endregion
809808

810-
#region Move active window to all 4 corners
809+
#region Move active window to all 4 corners & center
811810
public static void MoveActiveWindowToTopLeft(object o, HotKeyEventArgs args)
812811
{
813-
MoveActiveWindowToCorner(SnapDirection.TopLeft);
812+
MoveActiveWindowTo(SnapDirection.TopLeft);
814813
}
815814

816815
public static void MoveActiveWindowToTopRight(object o, HotKeyEventArgs args)
817816
{
818-
MoveActiveWindowToCorner(SnapDirection.TopRight);
817+
MoveActiveWindowTo(SnapDirection.TopRight);
819818
}
820819

821820
public static void MoveActiveWindowToBottomLeft(object o, HotKeyEventArgs args)
822821
{
823-
MoveActiveWindowToCorner(SnapDirection.BottomLeft);
822+
MoveActiveWindowTo(SnapDirection.BottomLeft);
824823
}
825824

826825
public static void MoveActiveWindowToBottomRight(object o, HotKeyEventArgs args)
827826
{
828-
MoveActiveWindowToCorner(SnapDirection.BottomRight);
827+
MoveActiveWindowTo(SnapDirection.BottomRight);
829828
}
830829

831830
public static void MoveActiveWindowToCenter(object o, HotKeyEventArgs args)
832831
{
833-
MoveActiveWindowToCorner(SnapDirection.Center);
832+
MoveActiveWindowTo(SnapDirection.Center);
834833
}
835834
#endregion
836835

@@ -839,14 +838,14 @@ public static void SendActiveWindowToBack(object sender = null, HotKeyEventArgs
839838
SendActiveWindowToBack();
840839
}
841840

842-
public static void IncreaseWindowTranspancy(object sender = null, HotKeyEventArgs e = null)
841+
public static void IncreaseWindowTransparency(object sender = null, HotKeyEventArgs e = null)
843842
{
844-
SetWindowTransparancy(1);
843+
SetWindowTransparency(1);
845844
}
846845

847-
public static void DecreaseWindowTranspancy(object sender = null, HotKeyEventArgs e = null)
846+
public static void DecreaseWindowTransparency(object sender = null, HotKeyEventArgs e = null)
848847
{
849-
SetWindowTransparancy(-1);
848+
SetWindowTransparency(-1);
850849
}
851850

852851
public static void SaveLayout1(object sender = null, HotKeyEventArgs e = null)

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Fresh Tools
22
### Description
3-
v.0.7.3
3+
v.0.7.4
44

55
This is a collection of tools and code archives for doing usefull stuff that can be controlled via notification icon.
66

@@ -40,6 +40,7 @@ Snap | CTRL ALT Home | Move window to top left corner
4040
Snap | CTRL ALT PageUp | Move window to top right corner
4141
Snap | CTRL ALT End | Move window to bottom left corner
4242
Snap | CTRL ALT PageDown | Move window to bottom right corner
43+
Snap | CTRL ALT Multiply | Move window to Center
4344
Snap Alt | CTRL ALT comma | Snap window to bottom left corner
4445
Snap Alt | CTRL ALT period | Snap window to bottom
4546
Snap Alt | CTRL ALT slash | Snap window to bottom right corner

0 commit comments

Comments
 (0)