Skip to content

Commit

Permalink
change button style;
Browse files Browse the repository at this point in the history
add open note button;
move most per-note settings to note content file;
move paper color to format window;
changes to format window layouts;
minor changes to help texts;
add app.manifest;
other minor changes;
  • Loading branch information
changbowen committed Nov 11, 2019
1 parent d3f4300 commit 2108429
Show file tree
Hide file tree
Showing 24 changed files with 1,258 additions and 968 deletions.
74 changes: 1 addition & 73 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,89 +10,17 @@
</startup>
<userSettings>
<DesktopNote.Properties.Settings>
<setting name="Win_Size" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>300, 350</string>
</ArrayOfString>
</value>
</setting>
<setting name="Win_Pos" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>0, 0</string>
</ArrayOfString>
</value>
</setting>
<setting name="Doc_Location" serializeAs="Xml">
<setting name="NoteList" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>DesktopNoteContent</string>
</ArrayOfString>
</value>
</setting>
<setting name="Bak_Location" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>DesktopNoteContent.txt</string>
</ArrayOfString>
</value>
</setting>
<setting name="AutoDock" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>True</string>
</ArrayOfString>
</value>
</setting>
<setting name="UpgradeFlag" serializeAs="String">
<value>True</value>
</setting>
<setting name="DockedTo" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>0</string>
</ArrayOfString>
</value>
</setting>
<setting name="Font" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>Segoe Print</string>
</ArrayOfString>
</value>
</setting>
<setting name="FontColor" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>#FF000000</string>
</ArrayOfString>
</value>
</setting>
<setting name="BackColor" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>#00FFFFFF</string>
</ArrayOfString>
</value>
</setting>
<setting name="PaperColor" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>#FFFFF7C5</string>
</ArrayOfString>
</value>
</setting>
</DesktopNote.Properties.Settings>
</userSettings>
</configuration>
2 changes: 1 addition & 1 deletion App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--<ResourceDictionary Source="Resources/StringResources.zh.xaml"/>-->
<!--<ResourceDictionary Source="Themes/Generic.xaml" />-->
<ResourceDictionary Source="Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
109 changes: 39 additions & 70 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Collections.Specialized;
//using System.Configuration;
//using System.Data;
//using System.Linq;
using System.Linq;
//using System.Threading.Tasks;
using System.Windows;

namespace DesktopNote
{
public partial class App : Application
{
public static readonly string AppRootDir = AppDomain.CurrentDomain.BaseDirectory;
public static List<MainWindow> MainWindows = new List<MainWindow>();
public static ResourceDictionary Res;
public static Win_Format FormatWindow;
public static Win_Search SearchWindow;
public static Win_Options OptionsWindow;
Expand All @@ -27,31 +28,27 @@ public partial class App : Application

private void RunCheck(object sender1, StartupEventArgs e1)
{
if (SingleInstance.CheckExist(MutexString, ref mtx))
{
if (SingleInstance.CheckExist(MutexString, ref mtx)) {
SingleInstance.SendNotifyMessage(SingleInstance.HWND_BROADCAST, SingleInstance.RegisteredWM, IntPtr.Zero, IntPtr.Zero);
Current.Shutdown();
return;
}

AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs e) =>
{
var desiredAssembly = new System.Reflection.AssemblyName(e.Name).Name;
switch (desiredAssembly)
{
case "Xceed.Wpf.Toolkit":
case "Hardcodet.Wpf.TaskbarNotification":
var ressourceName = "DesktopNote.Resources." + desiredAssembly + ".dll";
using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(ressourceName))
{
byte[] assemblyData = new byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return System.Reflection.Assembly.Load(assemblyData);
}
default:
return null;
}
};
AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs e) => {
var desiredAssembly = new System.Reflection.AssemblyName(e.Name).Name;
switch (desiredAssembly) {
case "Xceed.Wpf.Toolkit":
case "Hardcodet.Wpf.TaskbarNotification":
var ressourceName = "DesktopNote.Resources." + desiredAssembly + ".dll";
using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(ressourceName)) {
byte[] assemblyData = new byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return System.Reflection.Assembly.Load(assemblyData);
}
default:
return null;
}
};

//localization
var lang = System.Threading.Thread.CurrentThread.CurrentCulture.Name.Substring(0, 2);
Expand All @@ -60,15 +57,11 @@ private void RunCheck(object sender1, StartupEventArgs e1)
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var resourceName = assembly.GetName().Name + ".g";
var resourceManager = new System.Resources.ResourceManager(resourceName, assembly);
try
{
try {
var resourceSet = resourceManager.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true);
foreach (System.Collections.DictionaryEntry resource in resourceSet)
{
if ((string)resource.Key == @"resources/stringresources." + lang + ".baml")
{
var dict = new ResourceDictionary
{
foreach (System.Collections.DictionaryEntry resource in resourceSet) {
if ((string)resource.Key == @"resources/stringresources." + lang + ".baml") {
var dict = new ResourceDictionary {
Source = new Uri(@"Resources\StringResources." + lang + ".xaml", UriKind.Relative)
};
Resources.MergedDictionaries.Add(dict);
Expand All @@ -77,64 +70,40 @@ private void RunCheck(object sender1, StartupEventArgs e1)
}
}
}
finally
{
finally {
resourceManager.ReleaseAllResources();
}
//set english as fallback language
if (!langadded)
Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(@"Resources\StringResources.en.xaml", UriKind.Relative) });

//other run checks
if (PathIsNetworkPath(AppDomain.CurrentDomain.BaseDirectory))
{
MessageBox.Show((string)Resources["msgbox_run_from_network"], "", MessageBoxButton.OK, MessageBoxImage.Exclamation);
if (PathIsNetworkPath(AppDomain.CurrentDomain.BaseDirectory)) {
Helpers.MsgBox("msgbox_run_from_network", button: MessageBoxButton.OK, image: MessageBoxImage.Exclamation);
Current.Shutdown();
return;
}

//remove deleted notes from settings
var set = DesktopNote.Properties.Settings.Default;
for (int i = set.Doc_Location.Count - 1; i >= 0; i--)
{
if (!string.IsNullOrWhiteSpace(set.Doc_Location[i])) continue;
foreach (System.Configuration.SettingsPropertyValue propval in set.PropertyValues)
{
if (propval.Property.PropertyType == typeof(StringCollection))
((StringCollection)propval.PropertyValue).RemoveAt(i);
}
}
set.Save();
Res = Current.Resources;

//load notes
for (int i = 0; i < set.Doc_Location.Count; i++)
{
var newmainwin = new MainWindow(i);
MainWindows.Add(newmainwin);
//Current.MainWindow = mainwin;
newmainwin.Show();
foreach (var path in Setting.NoteList) {
Helpers.OpenNote(path)?.Show();
}

if (MainWindows.Count == 0) Win_Format.NewNote();
if (MainWindows.Count == 0) Helpers.NewNote();
}

public static void Quit(bool savesetting)
public async static void Quit()
{
foreach (var win in MainWindows)
{
if (win == null) continue;
var exMsg = win.SaveToXamlPkg();
if (exMsg != null &&
MessageBox.Show(exMsg + "\r\n" + (string)App.Current.Resources["msgbox_not_saved_confirm"], "", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) != MessageBoxResult.Yes)
return;
if (savesetting)
{
win.CurrentSetting.Win_Pos = new Point(win.Left, win.Top);
win.CurrentSetting.Win_Size = new Size(win.Width, win.Height);
win.CurrentSetting.DockedTo = (int)win.LastDockStatus;
}
//update notelist
Setting.NoteList.Clear();
Setting.NoteList.AddRange(App.MainWindows.Select(w => w.CurrentSetting.Doc_Location).ToArray());
Setting.Save();

foreach (var win in MainWindows.ToArray()) {
await win.Close();
}
DesktopNote.Properties.Settings.Default.Save();

Current.Shutdown();
}

Expand Down
7 changes: 7 additions & 0 deletions DesktopNote.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<StartupObject>
</StartupObject>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -85,7 +88,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Helpers.cs" />
<Compile Include="Setting.cs" />
<None Include="app.manifest" />
<None Include="Setting.cs.old" />
<Compile Include="SingleInstance.cs" />
<Compile Include="WinAPI.cs" />
<Compile Include="Win_Format.xaml.cs">
Expand Down Expand Up @@ -160,6 +166,7 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
<Resource Include="Resources\FontAwesomeSolid.otf" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
2 changes: 2 additions & 0 deletions GetCurrentMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private struct Rect2

public Rect GetInfo(Window win)
{
if (!win.IsLoaded || PresentationSource.FromVisual(win) == null) return new Rect();

var mi = new MonitorInfo();
mi.cbSize = (uint)Marshal.SizeOf(typeof(MonitorInfo));
var hwmon = MonitorFromWindow(new System.Windows.Interop.WindowInteropHelper(win).EnsureHandle(), MONITOR_DEFAULTTOPRIMERTY);
Expand Down
Loading

0 comments on commit 2108429

Please sign in to comment.