Introduce property LogToFile in TMainForm, which is synced with the registry setting asLogToFile. Fixes issue #2936.

This commit is contained in:
Ansgar Becker
2012-08-23 23:16:36 +00:00
parent 65a9011206
commit 491a6298d1
4 changed files with 65 additions and 77 deletions

View File

@ -3371,8 +3371,8 @@ begin
if (not SameAsDefault) and (not SameAsCurrent) then begin if (not SameAsDefault) and (not SameAsCurrent) then begin
FRegistry.WriteInteger(ValueName, I); FRegistry.WriteInteger(ValueName, I);
Inc(FWrites); Inc(FWrites);
FSettings[Index].CurrentInt := I;
end; end;
FSettings[Index].CurrentInt := I;
end; end;
adBool: begin adBool: begin
SameAsDefault := B = FSettings[Index].DefaultBool; SameAsDefault := B = FSettings[Index].DefaultBool;
@ -3380,8 +3380,8 @@ begin
if (not SameAsDefault) and (not SameAsCurrent) then begin if (not SameAsDefault) and (not SameAsCurrent) then begin
FRegistry.WriteBool(ValueName, B); FRegistry.WriteBool(ValueName, B);
Inc(FWrites); Inc(FWrites);
FSettings[Index].CurrentBool := B;
end; end;
FSettings[Index].CurrentBool := B;
end; end;
adString: begin adString: begin
SameAsDefault := S = FSettings[Index].DefaultString; SameAsDefault := S = FSettings[Index].DefaultString;
@ -3389,8 +3389,8 @@ begin
if (not SameAsDefault) and (not SameAsCurrent) then begin if (not SameAsDefault) and (not SameAsCurrent) then begin
FRegistry.WriteString(ValueName, S); FRegistry.WriteString(ValueName, S);
Inc(FWrites); Inc(FWrites);
FSettings[Index].CurrentString := S;
end; end;
FSettings[Index].CurrentString := S;
end; end;
else else
raise Exception.CreateFmt(SUnsupportedSettingsDatatype, [FSettings[Index].Name]); raise Exception.CreateFmt(SUnsupportedSettingsDatatype, [FSettings[Index].Name]);

View File

@ -8844,6 +8844,7 @@ object MainForm: TMainForm
end end
object popupSqlLog: TPopupMenu object popupSqlLog: TPopupMenu
Images = ImageListMain Images = ImageListMain
OnPopup = popupSqlLogPopup
Left = 8 Left = 8
Top = 96 Top = 96
object Copy1: TMenuItem object Copy1: TMenuItem

View File

@ -880,10 +880,12 @@ type
var Allowed: Boolean); var Allowed: Boolean);
procedure actGroupObjectsExecute(Sender: TObject); procedure actGroupObjectsExecute(Sender: TObject);
procedure lblExplainProcessAnalyzerClick(Sender: TObject); procedure lblExplainProcessAnalyzerClick(Sender: TObject);
procedure popupSqlLogPopup(Sender: TObject);
private private
FLastHintMousepos: TPoint; FLastHintMousepos: TPoint;
FLastHintControlIndex: Integer; FLastHintControlIndex: Integer;
FDelimiter: String; FDelimiter: String;
FLogToFile: Boolean;
FFileNameSessionLog: String; FFileNameSessionLog: String;
FFileHandleSessionLog: Textfile; FFileHandleSessionLog: Textfile;
FLastMouseUpOnPageControl: Cardinal; FLastMouseUpOnPageControl: Cardinal;
@ -949,6 +951,7 @@ type
function TreeClickHistoryPrevious(MayBeNil: Boolean=False): PVirtualNode; function TreeClickHistoryPrevious(MayBeNil: Boolean=False): PVirtualNode;
procedure OperationRunning(Runs: Boolean); procedure OperationRunning(Runs: Boolean);
function RunQueryFiles(Filenames: TStrings; Encoding: TEncoding): Boolean; function RunQueryFiles(Filenames: TStrings; Encoding: TEncoding): Boolean;
procedure SetLogToFile(Value: Boolean);
public public
QueryTabs: TObjectList<TQueryTab>; QueryTabs: TObjectList<TQueryTab>;
ActiveObjectEditor: TDBObjectEditor; ActiveObjectEditor: TDBObjectEditor;
@ -1003,8 +1006,7 @@ type
property ActiveConnection: TDBConnection read GetActiveConnection; property ActiveConnection: TDBConnection read GetActiveConnection;
property ActiveDatabase: String read GetActiveDatabase; property ActiveDatabase: String read GetActiveDatabase;
property ActiveDbObj: TDBObject read FActiveDbObj write SetActiveDBObj; property ActiveDbObj: TDBObject read FActiveDbObj write SetActiveDBObj;
procedure ActivateFileLogging; property LogToFile: Boolean read FLogToFile write SetLogToFile;
procedure DeactivateFileLogging;
procedure RefreshTree(FocusNewObject: TDBObject=nil); procedure RefreshTree(FocusNewObject: TDBObject=nil);
function GetRootNode(Tree: TBaseVirtualTree; Connection: TDBConnection): PVirtualNode; function GetRootNode(Tree: TBaseVirtualTree; Connection: TDBConnection): PVirtualNode;
function FindDBObjectNode(Tree: TBaseVirtualTree; Obj: TDBObject): PVirtualNode; function FindDBObjectNode(Tree: TBaseVirtualTree; Obj: TDBObject): PVirtualNode;
@ -1276,9 +1278,7 @@ begin
SaveListSetup(ListCommandStats); SaveListSetup(ListCommandStats);
SaveListSetup(ListTables); SaveListSetup(ListTables);
if AppSettings.ReadBool(asLogToFile) then LogToFile := False;
DeactivateFileLogging;
AppSettings.Free; AppSettings.Free;
end; end;
@ -1498,8 +1498,7 @@ begin
actDataShowNext.Hint := 'Show next '+FormatNumber(AppSettings.ReadInt(asDatagridRowsPerStep))+' rows ...'; actDataShowNext.Hint := 'Show next '+FormatNumber(AppSettings.ReadInt(asDatagridRowsPerStep))+' rows ...';
actAboutBox.Caption := 'About '+APPNAME+' '+AppVersion; actAboutBox.Caption := 'About '+APPNAME+' '+AppVersion;
// Activate logging // Activate logging
if AppSettings.ReadBool(asLogToFile) then LogToFile := AppSettings.ReadBool(asLogToFile);
ActivateFileLogging;
if AppSettings.ReadBool(asLogHorizontalScrollbar) then if AppSettings.ReadBool(asLogHorizontalScrollbar) then
actLogHorizontalScrollbar.Execute; actLogHorizontalScrollbar.Execute;
@ -4127,7 +4126,7 @@ begin
SynMemoSQLLog.Repaint; SynMemoSQLLog.Repaint;
// Log to file? // Log to file?
if AppSettings.ReadBool(asLogToFile) then if FLogToFile then
try try
Sess := ''; Sess := '';
if Assigned(Connection) then if Assigned(Connection) then
@ -4135,8 +4134,9 @@ begin
WriteLn(FFileHandleSessionLog, Format('/* %s [%s] */ %s', [DateTimeToStr(Now), Sess, msg])); WriteLn(FFileHandleSessionLog, Format('/* %s [%s] */ %s', [DateTimeToStr(Now), Sess, msg]));
except except
on E:Exception do begin on E:Exception do begin
DeactivateFileLogging; LogToFile := False;
ErrorDialog('Error writing to session log file.', FFileNameSessionLog+CRLF+CRLF+E.Message+CRLF+CRLF+'Logging is disabled now.'); AppSettings.WriteBool(asLogToFile, False);
ErrorDialog('Error writing to session log file.', E.Message+CRLF+'Filename: '+FFileNameSessionLog+CRLF+CRLF+'Logging is disabled now.');
end; end;
end; end;
end; end;
@ -5318,6 +5318,15 @@ begin
ActiveQueryMemo.SetFocus; ActiveQueryMemo.SetFocus;
end; end;
procedure TMainForm.popupSqlLogPopup(Sender: TObject);
begin
// Update popupMenu items
menuLogToFile.Checked := FLogToFile;
menuOpenLogFolder.Enabled := FLogToFile;
end;
procedure TMainForm.AutoRefreshSetInterval(Sender: TObject); procedure TMainForm.AutoRefreshSetInterval(Sender: TObject);
var var
SecondsStr: String; SecondsStr: String;
@ -6399,14 +6408,15 @@ end;
Start writing logfile. Start writing logfile.
Called either in FormShow or after closing preferences dialog Called either in FormShow or after closing preferences dialog
} }
procedure TMainForm.ActivateFileLogging; procedure TMainForm.SetLogToFile(Value: Boolean);
var var
LogfilePattern, LogDir: String; LogfilePattern, LogDir: String;
i : Integer; i : Integer;
begin begin
if AppSettings.ReadBool(asLogToFile) then if Value = FLogToFile then
Exit; Exit;
if Value then begin
// Ensure directory exists // Ensure directory exists
LogDir := AppSettings.ReadString(asSessionLogsDirectory); LogDir := AppSettings.ReadString(asSessionLogsDirectory);
if LogDir[Length(LogDir)] <> '\' then if LogDir[Length(LogDir)] <> '\' then
@ -6430,35 +6440,22 @@ begin
else else
Rewrite(FFileHandleSessionLog); Rewrite(FFileHandleSessionLog);
{$I+} {$I+}
if IOResult <> 0 then if IOResult <> 0 then begin
begin AppSettings.WriteBool(asLogToFile, False);
ErrorDialog('Error opening session log file', FFileNameSessionLog+CRLF+CRLF+'Logging is disabled now.'); ErrorDialog('Error opening session log file', FFileNameSessionLog+CRLF+CRLF+'Logging is disabled now.');
AppSettings.WriteBool(asLogToFile, False); end else begin
end else FLogToFile := Value;
AppSettings.WriteBool(asLogToFile, True); LogSQL('Writing to session log file now: '+FFileNameSessionLog);
// Update popupMenu items end;
menuLogToFile.Checked := AppSettings.ReadBool(asLogToFile); end else begin
menuOpenLogFolder.Enabled := AppSettings.ReadBool(asLogToFile);
end;
{**
Close logfile.
Called in FormClose, in ActivateFileLogging and on closing preferences dialog
}
procedure TMainForm.DeactivateFileLogging;
begin
if not AppSettings.ReadBool(asLogToFile) then
Exit;
AppSettings.WriteBool(asLogToFile, False);
{$I-} // Supress errors {$I-} // Supress errors
CloseFile(FFileHandleSessionLog); CloseFile(FFileHandleSessionLog);
{$I+} {$I+}
// Reset IOResult so later checks in ActivateFileLogging doesn't get an old value // Reset IOResult so later checks in ActivateFileLogging doesn't get an old value
IOResult; IOResult;
// Update popupMenu items FLogToFile := Value;
menuLogToFile.Checked := AppSettings.ReadBool(asLogToFile); LogSQL('Writing to session log file disabled now');
menuOpenLogFolder.Enabled := AppSettings.ReadBool(asLogToFile); end;
end; end;
@ -6505,18 +6502,11 @@ end;
Enable/disable file logging by popupmenuclick Enable/disable file logging by popupmenuclick
} }
procedure TMainForm.menuLogToFileClick(Sender: TObject); procedure TMainForm.menuLogToFileClick(Sender: TObject);
var
WasActivated: Boolean;
begin begin
WasActivated := AppSettings.ReadBool(asLogToFile); LogToFile := not LogToFile;
if not WasActivated then
ActivateFileLogging
else
DeactivateFileLogging;
// Save option // Save option
AppSettings.ResetPath; AppSettings.ResetPath;
AppSettings.WriteBool(asLogToFile, not WasActivated); AppSettings.WriteBool(asLogToFile, LogToFile);
end; end;

View File

@ -303,10 +303,7 @@ begin
end; end;
end; end;
if chkLogToFile.Checked then Mainform.LogToFile := chkLogToFile.Checked;
Mainform.ActivateFileLogging
else
Mainform.DeactivateFileLogging;
DatatypeCategories[dtcInteger].Color := FGridTextColors[dtcInteger]; DatatypeCategories[dtcInteger].Color := FGridTextColors[dtcInteger];
DatatypeCategories[dtcReal].Color := FGridTextColors[dtcReal]; DatatypeCategories[dtcReal].Color := FGridTextColors[dtcReal];
DatatypeCategories[dtcText].Color := FGridTextColors[dtcText]; DatatypeCategories[dtcText].Color := FGridTextColors[dtcText];