Skip to content

Commit

Permalink
Improvements: Export & auto change theme for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
r57zone committed Sep 28, 2020
1 parent 1ad541c commit a0abf98
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 22 deletions.
4 changes: 3 additions & 1 deletion Source/Windows/Project1.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Main};
Unit1 in 'Unit1.pas' {Main},
Unit2 in 'Unit2.pas' {Settings};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TMain, Main);
Application.CreateForm(TSettings, Settings);
Application.Run;
end.
46 changes: 42 additions & 4 deletions Source/Windows/Unit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ TMain = class(TForm)
procedure CopyBtnClick(Sender: TObject);
procedure CutBtnClick(Sender: TObject);
procedure AddStyle(FileName: string);
procedure ExportNotes(FileName: string);
private
procedure LoadNotes;
procedure NewNote(MemoFocus: boolean);
Expand All @@ -60,12 +61,12 @@ TMain = class(TForm)
ID_NEW_NOTE, ID_NOTES, ID_TODAY, ID_YESTERDAY, ID_DAYSAGO, ID_SYNC: string;
ID_CUT, ID_COPY, ID_PASTE, IDS_LAST_UPDATE: string;

ID_SETTINGS, ID_INTERFACE, ID_USE_DARK_THEME, ID_SYNCHRONIZATION,
ID_SETTINGS, ID_INTERFACE, ID_DARK_THEME, IDS_THEME_TIME, ID_SYNCHRONIZATION,
ID_SYNC_PORT, ID_SYNC_WITH_ANY_IPS, ID_ALLOW_IPS, ID_OK, ID_CANCEL: string;

AllowIPs: TStringList;
AllowAnyIPs: boolean;
UseDarkTheme: boolean;
UseDarkTheme, UseThemeTime: boolean;

implementation

Expand Down Expand Up @@ -162,6 +163,9 @@ procedure TMain.FormCreate(Sender: TObject);
Ini: TIniFile;
Reg: TRegistry;
WND: HWND;

CurDate: TDateTime;
CurHour, NilTime: Word;
begin
//Ïðåäîòâðàùåíèå ïîâòîðîãî çàïóñêà
WND:=FindWindow('TMain', 'EasyNotes');
Expand All @@ -174,7 +178,17 @@ procedure TMain.FormCreate(Sender: TObject);
Ini:=TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Config.ini');
IdHTTPServer.DefaultPort:=Ini.ReadInteger('Main', 'Port', 735);
AllowAnyIPs:=Ini.ReadBool('Sync', 'AllowAnyIPs', false);

UseDarkTheme:=Ini.ReadBool('Main', 'DarkTheme', false);
UseThemeTime:=Ini.ReadBool('Main', 'ThemeTime', false);

//Àâòîìàòè÷åñêîå èçìåíåíèå òåìû îò âðåìåíè ñóòîê
if (UseDarkTheme = false) and (UseThemeTime) then begin
DecodeTime(Now, CurHour, NilTime, NilTime, NilTime);
if (CurHour <= 9) or (CurHour >= 17) then
UseDarkTheme:=true;
end;

Width:=Ini.ReadInteger('Main', 'Width', Width);
Height:=Ini.ReadInteger('Main', 'Height', Height);
OldWidth:=Width;
Expand Down Expand Up @@ -207,7 +221,8 @@ procedure TMain.FormCreate(Sender: TObject);

ID_SETTINGS:='Íàñòðîéêè';
ID_INTERFACE:='Èíòåðôåéñ';
ID_USE_DARK_THEME:='Èñïîëüçîâàòü ò¸ìíóþ òåìó';
ID_DARK_THEME:='Ò¸ìíàÿ òåìà';
IDS_THEME_TIME:='Òåìà â çàâèñèìîñòè îò âðåìåíè';
ID_SYNCHRONIZATION:='Ñèíõðîíèçàöèÿ';
ID_SYNC_PORT:='Ïîðò';
ID_SYNC_WITH_ANY_IPS:='Ñèíõðîíèçàöèÿ ñ ëþáûìè IP (íåáåçîïàñíî)';
Expand All @@ -228,7 +243,8 @@ procedure TMain.FormCreate(Sender: TObject);

ID_SETTINGS:='Settings';
ID_INTERFACE:='Interface';
ID_USE_DARK_THEME:='Use a dark theme';
ID_DARK_THEME:='Dark theme';
IDS_THEME_TIME:='Theme is time dependent';
ID_SYNCHRONIZATION:='Synchronization';
ID_SYNC_PORT:='Port';
ID_SYNC_WITH_ANY_IPS:='Synchronization with any IP (not secure)';
Expand All @@ -255,6 +271,10 @@ procedure TMain.FormCreate(Sender: TObject);
//Îãðàíè÷åíèå IP àäðåñîâ äëÿ ñèíõðîíèçàöèè
AllowIPs:=TStringList.Create;
AllowIPs.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'AllowIPs.txt');

//Ýêñïîðò
if (LowerCase(ParamStr(1)) = '-export') and (Trim(ParamStr(2)) <> '') then
ExportNotes(ParamStr(2));
end;

function ExtractTitle(Str: string): string;
Expand Down Expand Up @@ -686,6 +706,24 @@ procedure TMain.AddStyle(FileName: string);
StyleFile.Free;
end;

procedure TMain.ExportNotes(FileName: string);
var
i: integer; SQLTB: TSQLiteTable; Notes: TStringList;
begin
Notes:=TStringList.Create;
SQLTB:=SQLDB.GetTable('SELECT * FROM Notes ORDER BY DateTime DESC');
try
for i:=0 to SQLTB.Count - 1 do begin
Notes.Text:=Notes.Text + DateTimeToStr(UNIXToDateTime(StrToInt64(SQLTB.FieldAsString(2)))) + #13#10 + CharCodesToStr(SQLTB.FieldAsString(1)) + #13#10 + #13#10;
SQLTB.Next;
end;
finally
SQLTB.Free;
end;
Notes.SaveToFile(FileName);
Notes.Free;
end;

initialization
OleInitialize(nil);

Expand Down
28 changes: 19 additions & 9 deletions Source/Windows/Unit2.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object Settings: TSettings
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = #1053#1072#1089#1090#1088#1086#1081#1082#1080
ClientHeight = 280
ClientHeight = 296
ClientWidth = 272
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Expand All @@ -21,21 +21,31 @@ object Settings: TSettings
Left = 8
Top = 8
Width = 257
Height = 49
Height = 65
Caption = #1048#1085#1090#1077#1088#1092#1077#1081#1089
TabOrder = 0
object DarkThemeCB: TCheckBox
Left = 8
Top = 20
Width = 201
Width = 97
Height = 17
Caption = #1048#1089#1087#1086#1083#1100#1079#1086#1074#1072#1090#1100' '#1090#1077#1084#1085#1091#1102' '#1090#1077#1084#1091
Caption = #1058#1105#1084#1085#1072#1103' '#1090#1077#1084#1072
TabOrder = 0
OnClick = DarkThemeCBClick
end
object ThemeTimeCB: TCheckBox
Left = 8
Top = 40
Width = 201
Height = 17
Caption = #1058#1077#1084#1072' '#1074' '#1079#1072#1074#1080#1089#1080#1084#1086#1089#1090#1080' '#1086#1090' '#1074#1088#1077#1084#1077#1085#1080
TabOrder = 1
OnClick = ThemeTimeCBClick
end
end
object SyncGB: TGroupBox
Left = 8
Top = 64
Top = 80
Width = 257
Height = 177
Caption = #1057#1080#1085#1093#1088#1086#1085#1080#1079#1072#1094#1080#1103
Expand Down Expand Up @@ -81,16 +91,16 @@ object Settings: TSettings
end
object OkBtn: TButton
Left = 8
Top = 248
Top = 264
Width = 75
Height = 25
Caption = #1054#1082
Caption = #1054#1050
TabOrder = 2
OnClick = OkBtnClick
end
object CancelBtn: TButton
Left = 88
Top = 248
Top = 264
Width = 75
Height = 25
Caption = #1054#1090#1084#1077#1085#1072
Expand All @@ -99,7 +109,7 @@ object Settings: TSettings
end
object AboutBtn: TButton
Left = 240
Top = 248
Top = 264
Width = 25
Height = 25
Caption = '?'
Expand Down
30 changes: 25 additions & 5 deletions Source/Windows/Unit2.pas
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ TSettings = class(TForm)
AllowedIPsMemo: TMemo;
AboutBtn: TButton;
AllowAnyIPsCB: TCheckBox;
ThemeTimeCB: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure CancelBtnClick(Sender: TObject);
procedure AboutBtnClick(Sender: TObject);
procedure OkBtnClick(Sender: TObject);
procedure AllowAnyIPsCBClick(Sender: TObject);
procedure ThemeTimeCBClick(Sender: TObject);
procedure DarkThemeCBClick(Sender: TObject);
private
{ Private declarations }
public
Expand All @@ -47,7 +50,8 @@ procedure TSettings.FormCreate(Sender: TObject);

Caption:=ID_SETTINGS;
InterfaceGB.Caption:=ID_INTERFACE;
DarkThemeCB.Caption:=ID_USE_DARK_THEME;
DarkThemeCB.Caption:=ID_DARK_THEME;
ThemeTimeCB.Caption:=IDS_THEME_TIME;
SyncGB.Caption:=ID_SYNCHRONIZATION;
PortLbl.Caption:=ID_SYNC_PORT;
AllowAnyIPsCB.Caption:=ID_SYNC_WITH_ANY_IPS;
Expand All @@ -58,6 +62,7 @@ procedure TSettings.FormCreate(Sender: TObject);
Ini:=TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Config.ini');
PortEdt.Text:=IntToStr(Main.IdHTTPServer.DefaultPort);
DarkThemeCB.Checked:=UseDarkTheme;
ThemeTimeCB.Checked:=UseThemeTime;
if AllowAnyIPs then begin
AllowAnyIPsCB.Checked:=true;
AllowedIPsMemo.Enabled:=false;
Expand All @@ -73,8 +78,8 @@ procedure TSettings.CancelBtnClick(Sender: TObject);

procedure TSettings.AboutBtnClick(Sender: TObject);
begin
Application.MessageBox(PChar(Caption + ' 0.8.5' + #13#10 +
IDS_LAST_UPDATE + ' 14.09.20' + #13#10 +
Application.MessageBox(PChar(Caption + ' 0.8.6' + #13#10 +
IDS_LAST_UPDATE + ' 28.09.20' + #13#10 +
'https://r57zone.github.io' + #13#10 +
'[email protected]'), PChar(Caption), MB_ICONINFORMATION);
end;
Expand All @@ -84,9 +89,12 @@ procedure TSettings.OkBtnClick(Sender: TObject);
Ini: TIniFile;
begin
Ini:=TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Config.ini');
Ini.WriteInteger('Main', 'Port', StrToIntDef(PortEdt.Text, 735));
Ini.WriteInteger('Sync', 'Port', StrToIntDef(PortEdt.Text, 735));
if ThemeTimeCB.Checked then
DarkThemeCB.Checked:=false;
Ini.WriteBool('Main', 'DarkTheme', DarkThemeCB.Checked);
Ini.WriteBool('Main', 'AllowAnyIPs', AllowAnyIPsCB.Checked);
Ini.WriteBool('Main', 'ThemeTime', ThemeTimeCB.Checked);
Ini.WriteBool('Sync', 'AllowAnyIPs', AllowAnyIPsCB.Checked);
AllowedIPsMemo.Lines.SaveToFile(ExtractFilePath(ParamStr(0)) + 'AllowIPs.txt');
Ini.Free;
Main.IdHTTPServer.Active:=false;
Expand All @@ -99,4 +107,16 @@ procedure TSettings.AllowAnyIPsCBClick(Sender: TObject);
AllowedIPsMemo.Enabled:=not AllowAnyIPsCB.Checked;
end;

procedure TSettings.ThemeTimeCBClick(Sender: TObject);
begin
if (ThemeTimeCB.Checked) and (DarkThemeCB.Checked) then
DarkThemeCB.Checked:=false;
end;

procedure TSettings.DarkThemeCBClick(Sender: TObject);
begin
if (DarkThemeCB.Checked) and (ThemeTimeCB.Checked) then
ThemeTimeCB.Checked:=false;
end;

end.
Binary file removed Source/Windows/sqlite3.dll
Binary file not shown.
6 changes: 3 additions & 3 deletions Source/Windows/style/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!--<link rel="stylesheet" href="all.css">-->
<style type="text/css">
html,body{padding:0;margin:0;}
body{font-family:Segoe UI; color:#666666; background-color:#f8f8f8;
body{font-family:Segoe UI; color:#333; background-color:#f8f8f8;

scrollbar-arrow-color: #606060;

Expand All @@ -33,8 +33,8 @@
#list #items{height:calc(100% - 40px); overflow:auto; border-right: 1px solid #d5d5d5;}
#list #items #note{cursor:pointer; height:40px; border-bottom:1px solid #ededed; overflow:hidden;}
#list #items #note:hover{background-color:#ededed;}
#list #items #note #title{float:left; width:calc(100% - 130px); margin:10px 0 0 8px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
#list #items #note #date{float:right; width:90px; margin:10px 10px 0 0; color:#454545; font-size:10pt; text-align:right;}
#list #items #note #title{float:left; width:calc(100% - 125px); margin:10px 0 0 8px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
#list #items #note #date{float:right; width:85px; margin:10px 10px 0 0; color:#454545; font-size:13px; text-align:right;}

#editor{float:right; width:63%; height:100%;}
#meta{color:#ac5942; height:38px; width:100%; font-size:14px; cursor:default; overflow:hidden; white-space:nowrap;}
Expand Down

0 comments on commit a0abf98

Please sign in to comment.