OSDN Git Service

プレビューを他のアプリに渡す機能を追加
authorh677 <h677>
Mon, 3 Mar 2008 14:51:02 +0000 (14:51 +0000)
committerh677 <h677>
Mon, 3 Mar 2008 14:51:02 +0000 (14:51 +0000)
ExtPreviewDatamodule.dfm [new file with mode: 0644]
ExtPreviewDatamodule.pas [new file with mode: 0644]
Giko.pas
GikoSystem.pas
Setting.pas
gikoNavi.dpr
gikoNavi.res

diff --git a/ExtPreviewDatamodule.dfm b/ExtPreviewDatamodule.dfm
new file mode 100644 (file)
index 0000000..3d84e27
--- /dev/null
@@ -0,0 +1,16 @@
+object ExtPreviewDM: TExtPreviewDM
+  OldCreateOrder = False
+  OnCreate = DataModuleCreate
+  OnDestroy = DataModuleDestroy
+  Left = 200
+  Top = 120
+  Height = 150
+  Width = 215
+  object ExecuteTimer: TTimer
+    Enabled = False
+    Interval = 200
+    OnTimer = ExecuteTimerTimer
+    Left = 120
+    Top = 40
+  end
+end
diff --git a/ExtPreviewDatamodule.pas b/ExtPreviewDatamodule.pas
new file mode 100644 (file)
index 0000000..12c0f41
--- /dev/null
@@ -0,0 +1,181 @@
+unit ExtPreviewDatamodule;
+
+interface
+
+uses
+  SysUtils, Classes, bmRegExp, ExtCtrls;
+
+type
+  TCommand = class(TObject)
+  private
+    FCommand: String;
+    FConfirm: Boolean;
+    FContinue: Boolean;
+    FToURL: String;
+  public
+    constructor Create(const comm: String);
+    property Command: String read FCommand;
+    property Confirm: Boolean read FConfirm write FConfirm;
+    property Continue: Boolean read FContinue write FContinue;
+    property ToURL: String read FToURL write FToURL;
+  end;
+
+  TExtPreviewDM = class(TDataModule)
+    ExecuteTimer: TTimer;
+    procedure DataModuleCreate(Sender: TObject);
+    procedure DataModuleDestroy(Sender: TObject);
+    procedure ExecuteTimerTimer(Sender: TObject);
+  private
+    { Private \90é\8c¾ }
+       FAWKStr: TAWKStr;
+    FRegs: TStringList;
+    FExecCommand: TCommand;
+    function ReadCommand(const Line: String): TCommand;
+  public
+    { Public \90é\8c¾ }
+    function PreviewURL(const URL: String): Boolean;
+  end;
+
+var
+  ExtPreviewDM: TExtPreviewDM;
+
+implementation
+
+uses
+  GikoSystem, IniFiles, GikoUtil, Windows;
+
+constructor TCommand.Create(const comm: String);
+begin
+    FCommand := comm;
+    FConfirm := False;
+    FContinue := False;
+    FToURL := '';
+end;
+{$R *.dfm}
+{
+\brief \83R\83\93\83X\83g\83\89\83N\83^
+}
+procedure TExtPreviewDM.DataModuleCreate(Sender: TObject);
+var
+    values: TStringList;
+    i, pos: Integer;
+begin
+    FAWKStr := TAWKStr.Create(Self);
+    FRegs := TStringList.Create;
+    if (FileExists(GikoSys.GetExtpreviewFileName)) then begin
+        values := TStringList.Create;
+        try
+            values.LoadFromFile(GikoSys.GetExtpreviewFileName);
+            for i := 0 to values.Count - 1 do begin
+                if ( AnsiPos('#',values[i]) = 1 ) then begin
+                    // \90æ\93ª#\82Å\8en\82Ü\82é\82Í\83R\83\81\83\93\83g\8ds
+                end else begin
+                    pos := AnsiPos(#9,values[i]);
+                    if (pos > 0) then begin
+                        FRegs.AddObject(
+                            Copy(values[i], 1, pos - 1),
+                            ReadCommand(
+                                Copy(values[i], pos + 1, Length(values[i])))
+                                );
+                    end;
+                end;
+            end;
+        finally
+            values.Free;
+        end;
+    end;
+end;
+{
+\brief \83f\83X\83g\83\89\83N\83^
+}
+procedure TExtPreviewDM.DataModuleDestroy(Sender: TObject);
+begin
+    FRegs.Clear;
+    FRegs.Free;
+    FAWKStr.Free;
+end;
+{
+\brief \83R\83}\83\93\83h\8ds\89ð\8eß
+}
+function TExtPreviewDM.ReadCommand(const Line: String): TCommand;
+var
+    pos: Integer;
+    sub: String;
+begin
+
+    // FCommand , FConfirm , FContinue \82Ì\8f\87
+    pos := AnsiPos(#9, Line);
+    if (pos > 0) then begin
+        Result := TCommand.Create( Copy(Line, 1, pos - 1) );
+        sub := Copy(Line, pos + 1, Length(Line));
+    end else begin
+        Result := TCommand.Create( '' );
+        sub := '';
+    end;
+    pos := AnsiPos(#9, sub);
+    if (pos > 0) then begin
+        if (AnsiLowerCase(Copy(sub, 1, pos - 1)) = 'true' ) then begin
+            Result.Confirm := True;
+        end;
+        sub := Copy(Line, pos + 1, Length(Line));
+    end;
+    sub := Trim(sub);
+    if (AnsiLowerCase(sub) = 'true' ) then begin
+        Result.Continue := True;
+    end;
+end;
+{
+\brief \93o\98^\82³\82ê\82½URL\82ð\8f\88\97\9d\82·\82é\83R\83}\83\93\83h\82ð\95Ô\82·
+}
+function TExtPreviewDM.PreviewURL(const URL: String): Boolean;
+var
+    i: Integer;
+    RStart: Integer;
+    RLength: Integer;
+    EsqURL: String;
+begin
+    Result := False;
+    ExecuteTimer.Interval := 0;
+    ExecuteTimer.Enabled := False;
+    FExecCommand := nil;
+    if (Length(URL) > 0) and (FRegs.Count > 0) then begin
+        EsqURL := FAWKStr.ProcessEscSeq(URL);
+        for i := 0 to FRegs.Count - 1 do begin
+            FAWKStr.RegExp := FRegs[i];
+            if ( FAWKStr.Match(EsqURL, RStart, RLength ) <> 0 ) then begin
+                FExecCommand := TCommand(FRegs.Objects[i]);
+                FExecCommand.ToURL := Copy(EsqURL, RStart, RLength);
+                ExecuteTimer.Interval := GikoSys.Setting.PreviewWait;
+                ExecuteTimer.Enabled := True;
+                Result := not FExecCommand.FContinue;
+                break;
+            end;
+        end;
+    end;
+end;
+
+procedure TExtPreviewDM.ExecuteTimerTimer(Sender: TObject);
+var
+    rc: Integer;
+begin
+    // \83^\83C\83}\81[\92â\8e~
+    ExecuteTimer.Interval := 0;
+    ExecuteTimer.Enabled := False;
+
+    if (FExecCommand <> nil) then begin
+        rc := ID_YES;
+        if (FExecCommand.Confirm) then begin
+            // Msg
+            rc := GikoUtil.MsgBox(0, FExecCommand.Command + '\82É'#13#10 +
+                FExecCommand.ToURL + ' \82ð\93n\82µ\82Ü\82·\82©\81H',
+                '\8am\94F', MB_ICONQUESTION or MB_YESNO);
+        end;
+
+        if (rc = ID_YES) then begin
+            GikoSys.CreateProcess(
+                FExecCommand.Command, '"' + FExecCommand.ToURL + '"');
+        end;
+    end;
+end;
+
+end.
index f1d3ce8..3920020 100644 (file)
--- a/Giko.pas
+++ b/Giko.pas
@@ -19,7 +19,7 @@ uses
        {HintWindow,} GikoCoolBar, GikoListView, Search, ExternalBoardManager,
        ExternalBoardPlugInMain, StdActns, Variants, ExtActns,IdTCPConnection,
        IdBaseComponent, IdTCPClient, AppEvnts, BrowserRecord, MoveHistoryItem,
-    ShellAPI,Preview, HistoryList, ResPopupBrowser;
+    ShellAPI,Preview, HistoryList, ResPopupBrowser, ExtPreviewDatamodule;
 
 const
        NGWORDNAME_PANEL = 3;
@@ -1992,7 +1992,10 @@ begin
 
 //file:///C:/Borland/Projects/gikoNavi/test/read.cgi/qa/990576336/10
 //file:///C:/Borland/Projects/gikoNavi/test/read.cgi/qa/990576336/10-15
-
+    // \91¼\82Ì\83A\83v\83\8a\82Å\8f\88\97\9d\82·\82éURL\82©\8am\94F
+    if (ExtPreviewDM.PreviewURL(Text2)) then begin
+        Exit;
+    end;
        s := '';
        Ext := AnsiLowerCase(ExtractFileExt(Text2));
        if (Pos('http://', Text2) = 1) and (GikoSys.Setting.PreviewVisible) and
index f1afb9f..fb65905 100644 (file)
@@ -256,6 +256,7 @@ type
         procedure AddOutofIndexDat(Board: TBoard; DatList: TStringList; AllCreate: boolean = True);
         //! \83t\83@\83C\83\8b\96¼\82©\82ç\82Ì\83X\83\8c\83b\83h\8dì\90¬\93ú\82Ì\8eæ\93¾
         function GetCreateDateFromName(FileName: String): TDateTime;
+        function GetExtpreviewFileName: String;
        end;
 
 var
@@ -3447,6 +3448,12 @@ function TGikoSys.GetReplaceFileName: String;
 begin
     Result := Setting.GetReplaceFileName;
 end;
+//! \83v\83\8c\83r\83\85\81[\8ag\92£\82Ì\90Ý\92è\83t\83@\83C\83\8b\8eæ\93¾
+function TGikoSys.GetExtpreviewFileName: String;
+begin
+    Result := Setting.GetExtprevieFileName;
+end;
+
 //! \83t\83@\83C\83\8b\96¼\82©\82ç\82Ì\83X\83\8c\83b\83h\8dì\90¬\93ú\82Ì\8eæ\93¾
 function TGikoSys.GetCreateDateFromName(FileName: String): TDateTime;
 var
index ddddc3d..7a98588 100644 (file)
@@ -538,9 +538,10 @@ type
                procedure WriteLogFolder(AVal : String);
                function GetInputAssistFileName : String;
         function GetReplaceFileName: String;
+        function GetExtprevieFileName: String;
         {
         \brief  \83\8a\83\93\83N\97\9a\97ð\82Ì\95Û\8e\9d\83T\83C\83Y\82Ìsetter
-        \param  AVal    \90Ý\92è\82·\82é\83T\83C\83Y( >0) 
+        \param  AVal    \90Ý\92è\82·\82é\83T\83C\83Y( >0)
         }
         procedure SetMoveHistorySize(AVal : Integer);
                //\8eó\90M\83o\83b\83t\83@\83T\83C\83Y
@@ -860,6 +861,7 @@ const
        INPUTASSIST_FILE_NAME   = 'InputAssist.ini';
     FIXED_COOKIE =           'hana=mogera';
     REPLACE_FILE_NAME = 'replace.ini';
+    EXT_PREVIEW_FILE_NAME = 'extpreview.ini';
 
 implementation
 
@@ -2167,6 +2169,10 @@ function TSetting.GetReplaceFileName: String;
 begin
     Result := GetConfigDir + REPLACE_FILE_NAME;
 end;
+function TSetting.GetExtprevieFileName: String;
+begin
+    Result := GetConfigDir + EXT_PREVIEW_FILE_NAME;
+end;
 procedure TSetting.SetMoveHistorySize(AVal : Integer);
 begin
     if (AVal > 0) then begin
index de35f2a..e3b41d7 100644 (file)
@@ -79,7 +79,8 @@ uses
   ReplaceDataModule in 'ReplaceDataModule.pas' {ReplaceDM: TDataModule},
   ResPopupBrowser in 'ResPopupBrowser.pas',
   SkinFiles in 'SkinFiles.pas',
-  NewBoardURL in 'NewBoardURL.pas' {NewBoardURLForm};
+  NewBoardURL in 'NewBoardURL.pas' {NewBoardURLForm},
+  ExtPreviewDatamodule in 'ExtPreviewDatamodule.pas' {ExtPreviewDM: TDataModule};
 
 {$R *.RES}
 {$R gikoResource.res}
@@ -137,6 +138,7 @@ begin
   Application.CreateForm(TInputAssistDM, InputAssistDM);
   Application.CreateForm(TReplaceDM, ReplaceDM);
   Application.CreateForm(TGikoForm, GikoForm);
+  Application.CreateForm(TExtPreviewDM, ExtPreviewDM);
   Application.Run;
                ReleaseMutex(hMutex);
        end;
index 7ebd250..3a0eb0d 100644 (file)
Binary files a/gikoNavi.res and b/gikoNavi.res differ