Skip to content

Commit

Permalink
keep save window position dual screen
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Dec 23, 2022
1 parent b2f337a commit 32ad122
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
10 changes: 8 additions & 2 deletions AddInManager/App.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="RevitAddinManager.Properties.App" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
Expand All @@ -16,6 +16,12 @@
<setting name="ThemName" serializeAs="String">
<value>Default</value>
</setting>
<setting name="AppLeft" serializeAs="String">
<value>0</value>
</setting>
<setting name="AppTop" serializeAs="String">
<value>0</value>
</setting>
</RevitAddinManager.Properties.App>
</userSettings>
</configuration>
2 changes: 1 addition & 1 deletion AddInManager/Model/ProcessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class ProcessManager
public static void SetRevitAsWindowOwner(this Window window)
{
if (null == window) { return; }
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.WindowStartupLocation = WindowStartupLocation.Manual;
WindowInteropHelper helper = new WindowInteropHelper(window);
helper.Owner = GetActivateWindow();
window.Loaded += delegate { FrmControl.IsOpened = true; };
Expand Down
27 changes: 25 additions & 2 deletions AddInManager/Properties/App.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions AddInManager/Properties/App.settings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?>
<?xml version="1.0" encoding="UTF-8"?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="RevitAddinManager.Properties" GeneratedClassName="App">
<Profiles />
<Settings>
Expand All @@ -11,5 +11,12 @@
<Setting Name="ThemName" Type="System.String" Scope="User">
<Value Profile="(Default)">Default</Value>
</Setting>
<Setting Name="AppLeft" Type="System.Double" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="AppTop" Type="System.Double" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>
</SettingsFile>

3 changes: 3 additions & 0 deletions AddInManager/View/FrmAddInManager.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
d:DataContext="{d:DesignInstance viewModel:AddInManagerViewModel}"
d:DesignHeight="600"
d:DesignWidth="400"
Closed="OnCloseApp"
FocusManager.FocusedElement="{Binding ElementName=tbxSearch}"
Icon="../Resources/dev.ico"
Left="{model:SettingBinding AppLeft}"
PreviewKeyDown="CloseFormEvent"
SizeChanged="FrmSizeChanged"
Top="{model:SettingBinding AppTop}"
mc:Ignorable="d">
<Window.Resources>
<ResourceDictionary>
Expand Down
8 changes: 7 additions & 1 deletion AddInManager/View/FrmAddInManager.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public FrmAddInManager(AddInManagerViewModel vm)
ThemManager.ChangeThem(true);
Title += DefaultSetting.Version;
}

private void TbxDescription_OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
if (viewModel.MAddinManagerBase.ActiveCmdItem != null && TabControl.SelectedIndex == 0)
Expand Down Expand Up @@ -158,4 +157,11 @@ private DispatcherTimer Debounce(DispatcherTimer dispatcher, TimeSpan interval,

return dispatcher;
}

private void OnCloseApp(object sender, EventArgs e)
{
Properties.App.Default.AppLeft = Left;
Properties.App.Default.AppTop = Top;
Properties.App.Default.Save();
}
}
2 changes: 2 additions & 0 deletions AddInManager/ViewModel/AddInManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class AddInManagerViewModel : ViewModelBase
public AssemLoader AssemLoader { get; set; }
public int AppWidth { get; set; } = 400;
public int AppHeight { get; set; } = 600;
public int AppLeft { get; set; } = 0;
public int AppTop { get; set; } = 0;
public AddinManagerBase MAddinManagerBase { get; set; }

private ObservableCollection<AddinModel> commandItems;
Expand Down

0 comments on commit 32ad122

Please sign in to comment.