Fixing blank lines

This commit is contained in:
Clint Rutkas 2019-12-12 13:26:02 -08:00
parent 826858c170
commit de64b33bb8
13 changed files with 159 additions and 63 deletions

View File

@ -27,7 +27,7 @@ namespace FancyZonesEditor
{
if (e.Args.Length > 1)
{
UInt16.TryParse(e.Args[1], out _idInitial);
ushort.TryParse(e.Args[1], out _idInitial);
}
LayoutModel foundModel = null;
@ -57,6 +57,7 @@ namespace FancyZonesEditor
}
}
}
if (foundModel == null)
{
foundModel = _settings.DefaultModels[0];

View File

@ -115,6 +115,7 @@ namespace FancyZonesEditor
{
newWidth = (int)_settings.WorkArea.Width - rect.X;
}
MinWidth = rect.Width = newWidth;
}
@ -130,8 +131,10 @@ namespace FancyZonesEditor
{
newHeight = (int)_settings.WorkArea.Height - rect.Y;
}
MinHeight = rect.Height = newHeight;
}
Model.Zones[ZoneIndex] = rect;
}
@ -144,6 +147,7 @@ namespace FancyZonesEditor
Canvas.SetZIndex(this, c_zIndex++);
base.OnPreviewMouseDown(e);
}
private void NWResize_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
SizeMove(e.HorizontalChange, e.VerticalChange);

View File

@ -134,6 +134,7 @@ namespace FancyZonesEditor
{
_editor = new CanvasEditor();
}
Content = _editor;
}

View File

@ -19,6 +19,7 @@ namespace FancyZonesEditor
{
model.Persist(mainEditor.GetZoneRects());
}
_choosing = true;
this.Close();
EditorOverlay.Current.Close();

View File

@ -37,6 +37,7 @@ namespace FancyZonesEditor
{
_rowInfo[row] = new RowColInfo(model.RowPercents[row]);
}
_colInfo = new RowColInfo[cols];
for (int col = 0; col < cols; col++)
{
@ -51,6 +52,7 @@ namespace FancyZonesEditor
maxIndex = Math.Max(maxIndex, model.CellChildMap[row, col]);
}
}
for (int i = 0; i <= maxIndex; i++)
{
AddZone();
@ -63,6 +65,7 @@ namespace FancyZonesEditor
Model = new GridLayoutModel();
DataContext = Model;
}
Model.PropertyChanged += OnGridDimensionsChanged;
AddDragHandles();
}
@ -118,6 +121,7 @@ namespace FancyZonesEditor
}
}
}
OnGridDimensionsChanged();
return;
}
@ -128,7 +132,6 @@ namespace FancyZonesEditor
private void ExtendRangeToHaveEvenCellEdges()
{
// extend each edge of the [(_startCol, _startRow) - (_endCol, _endRow)] range based on merged cells until you have 4 straight edges with no "straddling cells"
GridLayoutModel model = Model;
while (_startRow > 0)
@ -143,6 +146,7 @@ namespace FancyZonesEditor
break;
}
}
if (!dirty)
{
break;
@ -161,6 +165,7 @@ namespace FancyZonesEditor
break;
}
}
if (!dirty)
{
break;
@ -179,6 +184,7 @@ namespace FancyZonesEditor
break;
}
}
if (!dirty)
{
break;
@ -197,6 +203,7 @@ namespace FancyZonesEditor
break;
}
}
if (!dirty)
{
break;
@ -260,6 +267,7 @@ namespace FancyZonesEditor
model.CellChildMap[walkRow++, foundCol + i] = newChildIndex;
}
}
if (_colInfo[foundCol + i].End == offset)
{
foundExistingSplit = true;
@ -277,6 +285,7 @@ namespace FancyZonesEditor
{
foundCol++;
}
offset -= _colInfo[foundCol].Start;
}
@ -300,11 +309,13 @@ namespace FancyZonesEditor
newCellChildMap[row, col] = model.CellChildMap[row, sourceCol];
}
}
if (col != foundCol)
{
sourceCol++;
}
}
model.CellChildMap = newCellChildMap;
sourceCol = 0;
@ -325,6 +336,7 @@ namespace FancyZonesEditor
newColInfo[col] = _colInfo[sourceCol++];
}
}
_colInfo = newColInfo;
model.ColumnPercents = newColPercents;
@ -332,7 +344,6 @@ namespace FancyZonesEditor
}
else // Horizontal
{
if (splitee.HorizontalSnapPoints != null)
{
offset += Canvas.GetTop(splitee);
@ -349,6 +360,7 @@ namespace FancyZonesEditor
model.CellChildMap[foundRow + i, walkCol] = newChildIndex;
}
}
if (_rowInfo[foundRow + i].End == offset)
{
foundExistingSplit = true;
@ -366,6 +378,7 @@ namespace FancyZonesEditor
{
foundRow++;
}
offset -= _rowInfo[foundRow].Start;
}
@ -390,11 +403,13 @@ namespace FancyZonesEditor
newCellChildMap[row, col] = model.CellChildMap[sourceRow, col];
}
}
if (row != foundRow)
{
sourceRow++;
}
}
model.CellChildMap = newCellChildMap;
sourceRow = 0;
@ -415,6 +430,7 @@ namespace FancyZonesEditor
newRowInfo[row] = _rowInfo[sourceRow++];
}
}
_rowInfo = newRowInfo;
model.RowPercents = newRowPercents;
@ -455,8 +471,9 @@ namespace FancyZonesEditor
resizer.DragDelta += Resizer_DragDelta;
if (orientation == Orientation.Vertical)
{
index += (Model.Rows - 1);
index += Model.Rows - 1;
}
AdornerLayer.Children.Insert(index, resizer);
}
@ -510,10 +527,12 @@ namespace FancyZonesEditor
OnGridDimensionsChanged();
}
}
private static void OnGridDimensionsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((GridEditor)d).OnGridDimensionsChanged();
}
private void OnGridDimensionsChanged()
{
GridLayoutModel model = Model;
@ -557,8 +576,6 @@ namespace FancyZonesEditor
left += cellWidth + spacing;
}
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < cols; col++)
@ -579,6 +596,7 @@ namespace FancyZonesEditor
{
maxRow++;
}
zone.HorizontalSnapPoints = null;
if (maxRow > row)
{
@ -650,7 +668,7 @@ namespace FancyZonesEditor
{
GridResizer resizer = (GridResizer)adornerChildren[childIndex++];
int startRow = -1;
int endRow = rows - 1;;
int endRow = rows - 1;
for (int row = 0; row < rows; row++)
{
if ((startRow == -1) && (model.CellChildMap[row, col] != model.CellChildMap[row, col + 1]))
@ -663,6 +681,7 @@ namespace FancyZonesEditor
break;
}
}
if (startRow != -1)
{
Canvas.SetLeft(resizer, _colInfo[col].End + (spacing / 2) - 24); // hard coding this as (resizer.ActualWidth / 2) will still evaluate to 0 here ... a layout hasn't yet happened
@ -801,6 +820,7 @@ namespace FancyZonesEditor
break;
}
}
if ((_startRow >= 0) && (_endRow == -1))
{
_endRow = rows - 1;
@ -821,6 +841,7 @@ namespace FancyZonesEditor
break;
}
}
if ((_startCol >= 0) && (_endCol == -1))
{
_endCol = cols - 1;
@ -869,6 +890,7 @@ namespace FancyZonesEditor
}
}
}
OnGridDimensionsChanged();
ClearSelection();
}
@ -904,5 +926,4 @@ namespace FancyZonesEditor
private const int c_multiplier = 10000;
}
}

View File

@ -79,6 +79,7 @@ namespace FancyZonesEditor
{
isVertical = !isVertical;
}
return isVertical;
}
}
@ -117,6 +118,7 @@ namespace FancyZonesEditor
{
pos = bodyHeight - SplitterThickness;
}
Canvas.SetLeft(_splitter, 0);
Canvas.SetTop(_splitter, pos);
_splitter.MinWidth = Body.ActualWidth;
@ -200,6 +202,7 @@ namespace FancyZonesEditor
}
}
}
base.OnMouseMove(e);
}
@ -229,6 +232,7 @@ namespace FancyZonesEditor
}
}
}
_mouseDownPos = new Point(-1, -1);
base.OnMouseUp(e);
}
@ -238,7 +242,6 @@ namespace FancyZonesEditor
public event MouseEventHandler MergeDrag;
public event MouseButtonEventHandler MergeComplete;
private Rectangle _splitter;
private bool _switchOrientation = false;
private Point _lastPos = new Point(-1,-1);

View File

@ -53,6 +53,7 @@ namespace FancyZonesEditor
{
Body.Margin = new Thickness(0);
}
if (_model is GridLayoutModel)
{
RenderPreview();
@ -135,6 +136,7 @@ namespace FancyZonesEditor
span++;
walk++;
}
Grid.SetRowSpan(rect, span);
span = 1;
@ -144,6 +146,7 @@ namespace FancyZonesEditor
span++;
walk++;
}
Grid.SetColumnSpan(rect, span);
rect.Margin = margin;

View File

@ -101,6 +101,7 @@ namespace FancyZonesEditor
{
return;
}
model.IsSelected = false;
_editing = true;
this.Close();
@ -132,6 +133,7 @@ namespace FancyZonesEditor
}
}
}
model.Name = _defaultNamePrefix + (++maxCustomIndex);
}
@ -146,6 +148,7 @@ namespace FancyZonesEditor
{
window = new CanvasEditorWindow();
}
window.Owner = EditorOverlay.Current;
window.DataContext = model;
window.Show();
@ -165,6 +168,7 @@ namespace FancyZonesEditor
{
model.Apply((model as CanvasLayoutModel).Zones.ToArray());
}
this.Close();
}
}
@ -201,6 +205,7 @@ namespace FancyZonesEditor
{
SetSelectedItem();
}
model.Delete();
}
}
@ -234,6 +239,7 @@ namespace FancyZonesEditor
return null;
}
}
public class BooleanToIntConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
@ -242,14 +248,17 @@ namespace FancyZonesEditor
{
return (bool)value == true ? 1 : 0;
}
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is int)
{
return (int)value == 1;
}
return false;
}
}

View File

@ -13,7 +13,7 @@ namespace FancyZonesEditor.Models
{
public CanvasLayoutModel(ushort version, string name, ushort id, byte[] data) : base(name, id)
{
if (version == c_latestVersion)
if (version == _latestVersion)
{
Load(data);
}
@ -45,12 +45,17 @@ namespace FancyZonesEditor.Models
}
}
}
private int _referenceWidth;
// ReferenceHeight - the reference height for the layout rect that all Zones are relative to
public int ReferenceHeight
{
get { return _referenceHeight; }
get
{
return _referenceHeight;
}
set
{
if (_referenceHeight != value)
@ -60,6 +65,7 @@ namespace FancyZonesEditor.Models
}
}
}
private int _referenceHeight;
// Zones - the list of all zones in this layout, described as independent rectangles
@ -128,8 +134,8 @@ namespace FancyZonesEditor.Models
int i = 0;
// Common persisted values between all layout types
data[i++] = (byte)(c_latestVersion / 256);
data[i++] = (byte)(c_latestVersion % 256);
data[i++] = (byte)(_latestVersion / 256);
data[i++] = (byte)(_latestVersion % 256);
data[i++] = 1; // LayoutModelType: 1 == CanvasLayoutModel
data[i++] = (byte)(Id / 256);
data[i++] = (byte)(Id % 256);
@ -155,9 +161,10 @@ namespace FancyZonesEditor.Models
data[i++] = (byte)(rect.Height / 256);
data[i++] = (byte)(rect.Height % 256);
}
return data;
}
private static ushort c_latestVersion = 0;
private static ushort _latestVersion = 0;
}
}

View File

@ -20,34 +20,45 @@ namespace FancyZonesEditor.Models
Reload(data);
}
}
// Rows - number of rows in the Grid
public int Rows
{
get { return _rows; }
set
{
get
{
return _rows;
}
set
{
if (_rows != value)
{
_rows = value;
FirePropertyChanged("Rows");
}
}
}
}
}
private int _rows = 1;
// Columns - number of columns in the Grid
public int Columns
{
get { return _cols; }
set
{
get
{
return _cols;
}
set
{
if (_cols != value)
{
_cols = value;
FirePropertyChanged("Columns");
}
}
}
}
}
private int _cols = 1;
// CellChildMap - represents which "children" belong in which grid cells;
@ -116,6 +127,7 @@ namespace FancyZonesEditor.Models
cellChildMap[row, col] = CellChildMap[row, col];
}
}
layout.CellChildMap = cellChildMap;
int[] rowPercents = new int[rows];
@ -123,6 +135,7 @@ namespace FancyZonesEditor.Models
{
rowPercents[row] = RowPercents[row];
}
layout.RowPercents = rowPercents;
int[] colPercents = new int[cols];
@ -130,6 +143,7 @@ namespace FancyZonesEditor.Models
{
colPercents[col] = ColumnPercents[col];
}
layout.ColumnPercents = colPercents;
return layout;
@ -169,6 +183,7 @@ namespace FancyZonesEditor.Models
index = mapping.Count;
mapping.Add(source);
}
cellChildMap[row, col] = index;
}
}

View File

@ -26,10 +26,14 @@ namespace FancyZonesEditor.Models
_id = id;
}
// Name - the display name for this layout model - is also used as the key in the registry
// Name - the display name for this layout model - is also used as the key in the registry
public string Name
{
get { return _name; }
get
{
return _name;
}
set
{
if (_name != value)
@ -39,6 +43,7 @@ namespace FancyZonesEditor.Models
}
}
}
private string _name;
// Id - the unique ID for this layout model - is used to connect fancy zones' ZonesSets with the editor's Layouts
@ -51,16 +56,22 @@ namespace FancyZonesEditor.Models
{
_id = ++s_maxId;
}
return _id;
}
}
private ushort _id = 0;
// IsSelected (not-persisted) - tracks whether or not this LayoutModel is selected in the picker
// TODO: once we switch to a picker per monitor, we need to move this state to the view
public bool IsSelected
{
get { return _isSelected; }
get
{
return _isSelected;
}
set
{
if (_isSelected != value)
@ -111,7 +122,7 @@ namespace FancyZonesEditor.Models
LayoutModel model = null;
byte[] data = (byte[])Registry.GetValue(_fullRegistryPath, name, null);
ushort version = (ushort)(data[0] * 256 + data[1]);
ushort version = (ushort)((data[0] * 256) + data[1]);
byte type = data[2];
ushort id = (ushort)((data[3] * 256) + data[4]);
@ -127,6 +138,7 @@ namespace FancyZonesEditor.Models
{
s_maxId = id;
}
s_customModels.Add(model);
}
}
@ -134,12 +146,14 @@ namespace FancyZonesEditor.Models
return s_customModels;
}
private static ObservableCollection<LayoutModel> s_customModels = null;
private static ushort s_maxId = 0;
// Callbacks that the base LayoutModel makes to derived types
protected abstract byte[] GetPersistData();
public abstract LayoutModel Clone();
// PInvokes to handshake with fancyzones backend

View File

@ -29,6 +29,7 @@ namespace FancyZonesEditor
return true;
}
}
return false;
}
}
@ -70,7 +71,11 @@ namespace FancyZonesEditor
// ZoneCount - number of zones selected in the picker window
public int ZoneCount
{
get { return _zoneCount; }
get
{
return _zoneCount;
}
set
{
if (_zoneCount != value)
@ -82,12 +87,17 @@ namespace FancyZonesEditor
}
}
}
private int _zoneCount;
// Spacing - how much space in between zones of the grid do you want
public int Spacing
{
get { return _spacing; }
get
{
return _spacing;
}
set
{
if (_spacing != value)
@ -98,12 +108,17 @@ namespace FancyZonesEditor
}
}
}
private int _spacing;
// ShowSpacing - is the Spacing value used or ignored?
public bool ShowSpacing
{
get { return _showSpacing; }
get
{
return _showSpacing;
}
set
{
if (_showSpacing != value)
@ -114,12 +129,17 @@ namespace FancyZonesEditor
}
}
}
private bool _showSpacing;
// IsShiftKeyPressed - is the shift key currently being held down
public bool IsShiftKeyPressed
{
get { return _isShiftKeyPressed; }
get
{
return _isShiftKeyPressed;
}
set
{
if (_isShiftKeyPressed != value)
@ -129,12 +149,17 @@ namespace FancyZonesEditor
}
}
}
private bool _isShiftKeyPressed;
// IsCtrlKeyPressed - is the ctrl key currently being held down
public bool IsCtrlKeyPressed
{
get { return _isCtrlKeyPressed; }
get
{
return _isCtrlKeyPressed;
}
set
{
if (_isCtrlKeyPressed != value)
@ -144,38 +169,25 @@ namespace FancyZonesEditor
}
}
}
private bool _isCtrlKeyPressed;
public Rect WorkArea
{
get { return _workArea; }
}
private Rect _workArea;
public static uint Monitor
{
get { return _monitor; }
}
private static uint _monitor;
public static uint Monitor { get; private set; }
public static String UniqueKey
{
get { return _uniqueKey; }
}
private static String _uniqueKey;
private String _uniqueRegistryPath;
public static string UniqueKey { get; private set; }
public static String WorkAreaKey
{
get { return _workAreaKey; }
}
private static String _workAreaKey;
private string _uniqueRegistryPath;
public static float Dpi
{
get { return _dpi; }
}
private static float _dpi;
public static string WorkAreaKey { get; private set; }
public static float Dpi { get; private set; }
private int ReadRegistryInt(string valueName, int defaultValue)
{
@ -225,6 +237,7 @@ namespace FancyZonesEditor
{
rows++;
}
rows--;
cols = ZoneCount / rows;
if (ZoneCount % rows == 0)
@ -236,6 +249,7 @@ namespace FancyZonesEditor
cols++;
mergeCount = rows - (ZoneCount % rows);
}
_gridModel.Rows = rows;
_gridModel.Columns = cols;
_gridModel.RowPercents = new int[rows];
@ -285,10 +299,10 @@ namespace FancyZonesEditor
private void ParseCommandLineArgs()
{
_workArea = System.Windows.SystemParameters.WorkArea;
_monitor = 0;
Monitor = 0;
_uniqueRegistryPath = FullRegistryPath;
_uniqueKey = "";
_dpi = 1;
UniqueKey = "";
Dpi = 1;
string[] args = Environment.GetCommandLineArgs();
if (args.Length == 7)
@ -300,8 +314,8 @@ namespace FancyZonesEditor
// 5 = resolution key (passed back to engine to persist data)
// 6 = monitor DPI (float)
_uniqueKey = args[1];
_uniqueRegistryPath += "\\" + _uniqueKey;
UniqueKey = args[1];
_uniqueRegistryPath += "\\" + UniqueKey;
var parsedLocation = args[4].Split('_');
var x = int.Parse(parsedLocation[0]);
@ -309,14 +323,14 @@ namespace FancyZonesEditor
var width = int.Parse(parsedLocation[2]);
var height = int.Parse(parsedLocation[3]);
_workAreaKey = args[5];
WorkAreaKey = args[5];
// Try invariant culture first, caller likely uses invariant i.e. "C" locale to construct parameters
foreach (var cultureInfo in new[] { CultureInfo.InvariantCulture, CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture })
{
try
{
_dpi = float.Parse(args[6], cultureInfo);
Dpi = float.Parse(args[6], cultureInfo);
break;
}
catch (FormatException)
@ -329,13 +343,14 @@ namespace FancyZonesEditor
uint monitor = 0;
if (uint.TryParse(args[4], out monitor))
{
_monitor = monitor;
Monitor = monitor;
}
}
}
public IList<LayoutModel> DefaultModels { get { return _defaultModels; } }
public ObservableCollection<LayoutModel> CustomModels
{
get
@ -345,9 +360,11 @@ namespace FancyZonesEditor
_customModels = LayoutModel.LoadCustomModels();
_customModels.Insert(0, _blankCustomModel);
}
return _customModels;
}
}
private ObservableCollection<LayoutModel> _customModels;
public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones";

View File

@ -15,10 +15,10 @@ namespace FancyZonesEditor
{
InitializeComponent();
}
void onLoad(object sender, RoutedEventArgs e)
{
//WindowEditor window = new WindowEditor(); window.Show();
}
}
}