Check-in [ef8f24d6c5]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Moved GetSettings to the plugin class. Read eventual version override from settings file (but it doesn't seem to work yet).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | version-override
Files: files | file ages | folders
SHA1:ef8f24d6c5dafaf2b6de46876316ed9cdb46f398
User & Date: Martijn 2013-07-12 20:02:58
Context
2013-07-14
09:37
Tries to read the installed version of IE from iexplore.exe's file version info. Otherwise, tries from svcVersion as well as from Version in HKLM\Software\Microsoft\Internet Explorer. Moved composition of the plugin's menu items from the constructor to the override of SetInfo, since we now need the config dir, and we don't know that until we have a handle to the Npp window. Closed-Leaf check-in: dcf6086ee4 user: Martijn tags: version-override
2013-07-12
20:02
Moved GetSettings to the plugin class. Read eventual version override from settings file (but it doesn't seem to work yet). check-in: ef8f24d6c5 user: Martijn tags: version-override
2013-03-03
13:48
Updated trunk to match with v1.3 check-in: 12f8f07a24 user: Martijn tags: trunk
Changes

Changes to src/F_PreviewHTML.pas.

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
...
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
    { Private declarations }
    FBufferID: NativeInt;
    FScrollPositions: TStringList;
    FFilterThread: TCustomFilterThread;
    FScrollTop: Integer;
    FScrollLeft: Integer;

    function  GetSettings(const Name: string = 'Settings.ini'): TIniFile;

    procedure SaveScrollPos;
    procedure RestoreScrollPos(const BufferID: NativeInt);

    function  DetermineCustomFilter: string;
    function  ExecuteCustomFilter(const FilterName, HTML: string; const BufferID: NativeInt): Boolean;
    function  TransformXMLToHTML(const XML: WideString): string;

................................................................................
  FScrollPositions := TStringList.Create;
  self.NppDefaultDockingMask := DWS_DF_FLOATING; // whats the default docking position
  //self.KeyPreview := true; // special hack for input forms
  self.OnFloat := self.FormFloat;
  self.OnDock := self.FormDock;
  inherited;
  FBufferID := -1;
  with GetSettings() do begin
    tmrAutorefresh.Interval := ReadInteger('Autorefresh', 'Interval', tmrAutorefresh.Interval);
  end;
end {TfrmHTMLPreview.FormCreate};
{ ------------------------------------------------------------------------------------------------ }
procedure TfrmHTMLPreview.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FScrollPositions);
................................................................................
    3, 7: FilterData.Encoding := TEncoding.Unicode;
    5:    FilterData.Encoding := TEncoding.UTF7;
    else  FilterData.Encoding := TEncoding.ANSI;
  end;
  FilterData.UseBOM := BufferEncoding in [1, 2, 3];
  FilterData.Modified := SendMessage(hScintilla, SCI_GETMODIFY, 0, 0) <> 0;

  Filters := GetSettings('Filters.ini');
  try
    FilterData.FilterInfo := TStringList.Create;
    Filters.ReadSectionValues(FilterName, FilterData.FilterInfo);
  finally
    Filters.Free;
  end;

................................................................................
{ ------------------------------------------------------------------------------------------------ }
procedure TfrmHTMLPreview.FormShow(Sender: TObject);
begin
  inherited;
  SendMessage(self.Npp.NppData.NppHandle, NPPM_SETMENUITEMCHECK, self.CmdID, 1);
end;

{ ------------------------------------------------------------------------------------------------ }
function TfrmHTMLPreview.GetSettings(const Name: string): TIniFile;
begin
  ForceDirectories(Npp.ConfigDir + '\PreviewHTML');
  Result := TIniFile.Create(Npp.ConfigDir + '\PreviewHTML\' + Name);
end {TfrmHTMLPreview.GetSettings};

{ ------------------------------------------------------------------------------------------------ }
function TfrmHTMLPreview.TransformXMLToHTML(const XML: WideString): string;
  { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  function CreateDOMDocument: OleVariant;
  var
    nVersion: Integer;
  begin







<
<







 







|







 







|







 







<
<
<
<
<
<
<







46
47
48
49
50
51
52


53
54
55
56
57
58
59
...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
...
546
547
548
549
550
551
552







553
554
555
556
557
558
559
    { Private declarations }
    FBufferID: NativeInt;
    FScrollPositions: TStringList;
    FFilterThread: TCustomFilterThread;
    FScrollTop: Integer;
    FScrollLeft: Integer;



    procedure SaveScrollPos;
    procedure RestoreScrollPos(const BufferID: NativeInt);

    function  DetermineCustomFilter: string;
    function  ExecuteCustomFilter(const FilterName, HTML: string; const BufferID: NativeInt): Boolean;
    function  TransformXMLToHTML(const XML: WideString): string;

................................................................................
  FScrollPositions := TStringList.Create;
  self.NppDefaultDockingMask := DWS_DF_FLOATING; // whats the default docking position
  //self.KeyPreview := true; // special hack for input forms
  self.OnFloat := self.FormFloat;
  self.OnDock := self.FormDock;
  inherited;
  FBufferID := -1;
  with TNppPluginPreviewHTML(Npp).GetSettings() do begin
    tmrAutorefresh.Interval := ReadInteger('Autorefresh', 'Interval', tmrAutorefresh.Interval);
  end;
end {TfrmHTMLPreview.FormCreate};
{ ------------------------------------------------------------------------------------------------ }
procedure TfrmHTMLPreview.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FScrollPositions);
................................................................................
    3, 7: FilterData.Encoding := TEncoding.Unicode;
    5:    FilterData.Encoding := TEncoding.UTF7;
    else  FilterData.Encoding := TEncoding.ANSI;
  end;
  FilterData.UseBOM := BufferEncoding in [1, 2, 3];
  FilterData.Modified := SendMessage(hScintilla, SCI_GETMODIFY, 0, 0) <> 0;

  Filters := TNppPluginPreviewHTML(Npp).GetSettings('Filters.ini');
  try
    FilterData.FilterInfo := TStringList.Create;
    Filters.ReadSectionValues(FilterName, FilterData.FilterInfo);
  finally
    Filters.Free;
  end;

................................................................................
{ ------------------------------------------------------------------------------------------------ }
procedure TfrmHTMLPreview.FormShow(Sender: TObject);
begin
  inherited;
  SendMessage(self.Npp.NppData.NppHandle, NPPM_SETMENUITEMCHECK, self.CmdID, 1);
end;








{ ------------------------------------------------------------------------------------------------ }
function TfrmHTMLPreview.TransformXMLToHTML(const XML: WideString): string;
  { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  function CreateDOMDocument: OleVariant;
  var
    nVersion: Integer;
  begin

Changes to src/U_Npp_PreviewHTML.pas.

1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16
17
18
19
20
21
22
23
24


25
26
27
28
29
30
31
..
61
62
63
64
65
66
67



68
69
70
71
72
73
74
...
228
229
230
231
232
233
234








235
236
237
238
239
240
241
unit U_Npp_PreviewHTML;

////////////////////////////////////////////////////////////////////////////////////////////////////
interface

uses
  SysUtils, Windows,
  NppPlugin, SciSupport,
  F_About, F_PreviewHTML;

type
  TNppPluginPreviewHTML = class(TNppPlugin)


  public
    constructor Create;
    procedure CommandShowPreview;
    procedure CommandSetIEVersion(const BrowserEmulation: Integer);
    procedure CommandOpenFile(const Filename: nppString);
    procedure CommandShowAbout;
    procedure CommandReplaceHelloWorld;

    procedure DoNppnToolbarModification; override;
    procedure DoNppnFileClosed(const BufferID: Cardinal); override;
    procedure DoNppnBufferActivated(const BufferID: Cardinal); override;
    procedure DoModified(const hwnd: HWND; const modificationType: Integer); override;


  end {TNppPluginPreviewHTML};

procedure _FuncReplaceHelloWorld; cdecl;
procedure _FuncShowPreview; cdecl;
procedure _FuncOpenSettings; cdecl;
procedure _FuncOpenFilters; cdecl;
procedure _FuncShowAbout; cdecl;
................................................................................
  self.PluginName := '&Preview HTML';

  sk.IsShift := True; sk.IsCtrl := true; sk.IsAlt := False;
  sk.Key := 'H'; // Ctrl-Shift-H
  self.AddFuncItem('&Preview HTML', _FuncShowPreview, sk);

  IEVersion := GetIEVersion;



  Val(IEVersion, MajorIEVersion, Code);
  if Code <= 1 then
    MajorIEVersion := 0;

  EmulatedVersion := GetBrowserEmulation div 1000;

  if MajorIEVersion > 7 then begin
................................................................................
      frmHTMLPreview.Hide
    ;
  end;
  if frmHTMLPreview.Visible then begin
    frmHTMLPreview.btnRefresh.Click;
  end;
end {TNppPluginPreviewHTML.CommandShowPreview};









{ ------------------------------------------------------------------------------------------------ }
procedure TNppPluginPreviewHTML.DoNppnToolbarModification;
var
  tb: TToolbarIcons;
begin
  tb.ToolbarIcon := 0;






|





>
>












>
>







 







>
>
>







 







>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
...
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
unit U_Npp_PreviewHTML;

////////////////////////////////////////////////////////////////////////////////////////////////////
interface

uses
  SysUtils, Windows, IniFiles,
  NppPlugin, SciSupport,
  F_About, F_PreviewHTML;

type
  TNppPluginPreviewHTML = class(TNppPlugin)
  private
    FSettings: TIniFile;
  public
    constructor Create;
    procedure CommandShowPreview;
    procedure CommandSetIEVersion(const BrowserEmulation: Integer);
    procedure CommandOpenFile(const Filename: nppString);
    procedure CommandShowAbout;
    procedure CommandReplaceHelloWorld;

    procedure DoNppnToolbarModification; override;
    procedure DoNppnFileClosed(const BufferID: Cardinal); override;
    procedure DoNppnBufferActivated(const BufferID: Cardinal); override;
    procedure DoModified(const hwnd: HWND; const modificationType: Integer); override;

    function  GetSettings(const Name: string = 'Settings.ini'): TIniFile;
  end {TNppPluginPreviewHTML};

procedure _FuncReplaceHelloWorld; cdecl;
procedure _FuncShowPreview; cdecl;
procedure _FuncOpenSettings; cdecl;
procedure _FuncOpenFilters; cdecl;
procedure _FuncShowAbout; cdecl;
................................................................................
  self.PluginName := '&Preview HTML';

  sk.IsShift := True; sk.IsCtrl := true; sk.IsAlt := False;
  sk.Key := 'H'; // Ctrl-Shift-H
  self.AddFuncItem('&Preview HTML', _FuncShowPreview, sk);

  IEVersion := GetIEVersion;
  with GetSettings do begin
    IEVersion := ReadString('Emulation', 'IE version', IEVersion);
  end;
  Val(IEVersion, MajorIEVersion, Code);
  if Code <= 1 then
    MajorIEVersion := 0;

  EmulatedVersion := GetBrowserEmulation div 1000;

  if MajorIEVersion > 7 then begin
................................................................................
      frmHTMLPreview.Hide
    ;
  end;
  if frmHTMLPreview.Visible then begin
    frmHTMLPreview.btnRefresh.Click;
  end;
end {TNppPluginPreviewHTML.CommandShowPreview};

{ ------------------------------------------------------------------------------------------------ }
function TNppPluginPreviewHTML.GetSettings(const Name: string): TIniFile;
begin
  ForceDirectories(ConfigDir + '\PreviewHTML');
  Result := TIniFile.Create(ConfigDir + '\PreviewHTML\' + Name);
end {TNppPluginPreviewHTML.GetSettings};


{ ------------------------------------------------------------------------------------------------ }
procedure TNppPluginPreviewHTML.DoNppnToolbarModification;
var
  tb: TToolbarIcons;
begin
  tb.ToolbarIcon := 0;

Changes to src/prj/PreviewHTML.dproj.

1
2
3
4
5
6
7
8
9
10
11
12
13
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
	<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
		<PropertyGroup>
			<ProjectGuid>{A2533A0E-8621-4A31-A675-059AFF5AA9FB}</ProjectGuid>
			<MainSource>PreviewHTML.dpr</MainSource>
			<Base>True</Base>
			<Config Condition="'$(Config)'==''">Release</Config>
			<TargetedPlatforms>1</TargetedPlatforms>
			<AppType>Library</AppType>
			<FrameworkType>VCL</FrameworkType>
			<ProjectVersion>13.4</ProjectVersion>
			<Platform Condition="'$(Platform)'==''">Win32</Platform>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
................................................................................
		<PropertyGroup Condition="'$(Cfg_2)'!=''">
			<DCC_SymbolReferenceInfo>2</DCC_SymbolReferenceInfo>
			<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
			<DCC_Optimize>false</DCC_Optimize>
			<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
			<VerInfo_Release>0</VerInfo_Release>
			<VerInfo_Debug>true</VerInfo_Debug>
			<VerInfo_Keys>CompanyName=Voronwë;FileDescription=HTML Preview plugin for Notepad++;FileVersion=1.3.0.0;InternalName=PreviewHTML;LegalCopyright=© Martijn Coppoolse;LegalTrademarks=;OriginalFilename=PreviewHTML.dll;ProductName=Notepad++;ProductVersion=6.0.0.0;Comments=http://martijn.coppoolse.com/software</VerInfo_Keys>
			<PostBuildEvent><![CDATA[]]></PostBuildEvent>
		</PropertyGroup>
		<ItemGroup>
			<DelphiCompile Include="$(MainSource)">
				<MainSource>MainSource</MainSource>
			</DelphiCompile>
			<RcCompile Include="PreviewHTML_TB.rc">
................................................................................
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='OSX32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>&quot;C:\MC\Run\Util\Compression\UPX\upx.exe&quot; --best -q &quot;$(OUTPUTPATH)&quot; </PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='Win32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent><![CDATA[]]></PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
	</Project>





|







 







|

|







 







<
<
<
<
<
<
<
<



1
2
3
4
5
6
7
8
9
10
11
12
13
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
...
214
215
216
217
218
219
220








221
222
223
	<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
		<PropertyGroup>
			<ProjectGuid>{A2533A0E-8621-4A31-A675-059AFF5AA9FB}</ProjectGuid>
			<MainSource>PreviewHTML.dpr</MainSource>
			<Base>True</Base>
			<Config Condition="'$(Config)'==''">Debug</Config>
			<TargetedPlatforms>1</TargetedPlatforms>
			<AppType>Library</AppType>
			<FrameworkType>VCL</FrameworkType>
			<ProjectVersion>13.4</ProjectVersion>
			<Platform Condition="'$(Platform)'==''">Win32</Platform>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
................................................................................
		<PropertyGroup Condition="'$(Cfg_2)'!=''">
			<DCC_SymbolReferenceInfo>2</DCC_SymbolReferenceInfo>
			<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
			<DCC_Optimize>false</DCC_Optimize>
			<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
			<VerInfo_MinorVer>4</VerInfo_MinorVer>
			<VerInfo_Debug>true</VerInfo_Debug>
			<VerInfo_Keys>CompanyName=Voronwë;FileDescription=HTML Preview plugin for Notepad++;FileVersion=1.4.0.0;InternalName=PreviewHTML;LegalCopyright=© Martijn Coppoolse;LegalTrademarks=;OriginalFilename=PreviewHTML.dll;ProductName=Notepad++;ProductVersion=6.0.0.0;Comments=http://martijn.coppoolse.com/software</VerInfo_Keys>
			<PostBuildEvent><![CDATA[]]></PostBuildEvent>
		</PropertyGroup>
		<ItemGroup>
			<DelphiCompile Include="$(MainSource)">
				<MainSource>MainSource</MainSource>
			</DelphiCompile>
			<RcCompile Include="PreviewHTML_TB.rc">
................................................................................
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='OSX32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>&quot;C:\MC\Run\Util\Compression\UPX\upx.exe&quot; --best -q &quot;$(OUTPUTPATH)&quot; </PostBuildEvent>








			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
	</Project>