OSDN Git Service

ポップアップメニューのカスタマイズ化への道第一歩。
authorh677 <h677>
Sat, 11 Jul 2009 04:34:17 +0000 (04:34 +0000)
committerh677 <h677>
Sat, 11 Jul 2009 04:34:17 +0000 (04:34 +0000)
ブラウザタブを設定可能にした。

Encrypt/UBase64.pas
Giko.pas
PopupMenuUtil.pas [new file with mode: 0644]
gikoNavi.dpr
gikoNavi.res
readme/defaultFiles.ini
res/default/popupmenu.default [new file with mode: 0644]

index 4337a7c..a33946d 100644 (file)
@@ -12,6 +12,7 @@ procedure HogeBase64Decode(inputStream, outputStream: TStream); overload;
 
 function HogeBase64Encode(const inputStr: string): string; overload;
 function HogeBase64Decode(const inputStr: string): string; overload;
+function HogeBase64Encode(inputArray: array of Byte): string; overload;
 
 implementation
 
@@ -148,4 +149,19 @@ begin
   inputStream.Free;
 end;
 
+function HogeBase64Encode(inputArray: array of Byte): string; overload;
+var
+  inputStream: TMemoryStream;
+  outputStream: TStringStream;
+begin
+  inputStream := TMemoryStream.Create;
+  inputStream.WriteBuffer(inputArray, Length(inputArray));
+  inputStream.Position := 0;
+  outputStream:= TStringStream.Create('');
+  HogeBase64Encode(inputStream, outputStream);
+  result := outputStream.DataString;
+  outputStream.Free;
+  inputStream.Free;
+end;
+
 end.
index 666d167..94a8bee 100644 (file)
--- a/Giko.pas
+++ b/Giko.pas
@@ -692,7 +692,7 @@ type
         //! \82à\82Á\82Æ\82à\8cÃ\82¢Browser\82Ì\8aJ\95ú
         procedure ReleaseOldestBrowser;
         //! \83A\83N\83e\83B\83u\82È\83^\83u\82Æ\93¯\82\94Â\82Ì\8aJ\82¢\82Ä\82¢\82é\83X\83\8c\83b\83h\82ð\83\81\83j\83\85\81[\83A\83C\83e\83\80\82É\92Ç\89Á
-        procedure AddMenuSameBoardThread;
+        procedure AddMenuSameBoardThread(MenuItem: TMenuItem);
         //!  \83A\83N\83e\83B\83u\82È\83^\83u\82Æ\93¯\82\94Â\82Ì\8aJ\82¢\82Ä\82¢\82é\83X\83\8c\83b\83h\83N\83\8a\83b\83N\83C\83x\83\93\83g
         procedure SameBoardThreadSubItemOnClick(Sender: TObject);
         //! \83|\83b\83v\83A\83b\83v\83u\83\89\83E\83U\8dì\90¬
@@ -879,7 +879,7 @@ uses
        About, Option, Round, Splash, Sort, ListSelect, Imm,
        NewBoard, MojuUtils, Clipbrd, GikoBayesian,Y_TextConverter,
        HTMLCreate, ListViewUtils, GikoDataModule, GikoMessage,
-  InputAssistDataModule, Types, ReplaceDataModule;
+  InputAssistDataModule, Types, ReplaceDataModule, PopupMenuUtil;
 
 const
        BLANK_HTML: string = 'about:blank';
@@ -1315,9 +1315,10 @@ begin
        GikoDM.RepaintStatusBar;
        StatusBarResize(Sender);
 
-       dummy1.Caption  := ItemReservPMenu.Caption;
-       dummy1.Hint     := ItemReservPMenu.Hint;
-
+//     dummy1.Caption  := ItemReservPMenu.Caption;
+//     dummy1.Hint     := ItemReservPMenu.Hint;
+    // \83u\83\89\83E\83U\83|\83b\83v\83A\83b\83v\83\81\83j\83\85\81[\82Ì\8f\89\8aú\89»
+    PopupMenuUtil.ReadSetting(GikoDM.GikoFormActionList, BrowserTabPopupMenu);
     // \83}\83E\83X\83W\83F\83X\83`\83\83\81[
     MouseGesture := TMouseGesture.Create;
 
@@ -1351,6 +1352,7 @@ begin
     // D&D\82ð\8eó\82¯\8eæ\82é
     DragAcceptFiles(ListView.Handle, True);
 
+
     // \8f\89\8aú\89»\82É\8e¸\94s\82µ\82½\83\82\83W\83\85\81[\83\8b\83`\83F\83b\83N
     if (FavoriteDM.AbEnd) then begin
         GikoUtil.MsgBox(Self.Handle,
@@ -4391,7 +4393,7 @@ procedure TGikoForm.SetSelectItemRound(RoundFlag: Boolean; RoundName: string; Pa
 var
        threadItem : TThreadItem;
 begin
-       if ParentName <> 'dummy1' then begin
+       if ParentName <> 'RoundItem' then begin
                SetSelectItemRound(RoundFlag, RoundName);
        end else begin
                threadItem := GetActiveContent;
@@ -6497,17 +6499,24 @@ end;
 
 
 procedure TGikoForm.BrowserTabPopupMenuPopup(Sender: TObject);
+var
+    i:Integer;
 begin
-       AddRoundNameMenu(dummy1);
-    AddMenuSameBoardThread;
+    for i := 0  to BrowserTabPopupMenu.Items.Count - 1 do begin
+        if (BrowserTabPopupMenu.Items[i].Name='RoundItem') then begin
+            AddRoundNameMenu(BrowserTabPopupMenu.Items[i]);
+        end else if (BrowserTabPopupMenu.Items[i].Name='BoardThreadItem') then begin
+            AddMenuSameBoardThread(BrowserTabPopupMenu.Items[i])
+        end;
+    end;
 end;
 //! \83A\83N\83e\83B\83u\82È\83^\83u\82Æ\93¯\82\94Â\82Ì\8aJ\82¢\82Ä\82¢\82é\83X\83\8c\83b\83h\82ð\83\81\83j\83\85\81[\83A\83C\83e\83\80\82É\92Ç\89Á
-procedure TGikoForm.AddMenuSameBoardThread;
+procedure TGikoForm.AddMenuSameBoardThread(MenuItem: TMenuItem);
 var
        i: Integer;
        Item: TMenuItem;
 begin
-    SameBoardThreadItem.Clear;
+    MenuItem.Clear;
     for i := 0 to BrowserTab.Tabs.Count - 1 do begin
         // \93¯\82\94Â\82©\82Ç\82¤\82©
         if (FActiveContent.Thread.ParentBoard =
@@ -6517,23 +6526,23 @@ begin
                 TBrowserRecord(BrowserTab.Tabs.Objects[i]).Thread then begin
                 Item := TMenuItem.Create(Self);
                 Item.Caption := TBrowserRecord(BrowserTab.Tabs.Objects[i]).Thread.Title;
+                Item.Hint    := TBrowserRecord(BrowserTab.Tabs.Objects[i]).Thread.URL;
                 Item.OnClick := SameBoardThreadSubItemOnClick;
-                SameBoardThreadItem.Add(Item);
+                MenuItem.Add(Item);
             end;
         end;
     end;
     // \89½\82à\96³\82¢\82È\82ç\8eg\97p\82Å\82«\82È\82¢\82æ\82¤\82É\82·\82é
-    SameBoardThreadItem.Enabled := SameBoardThreadItem.Count > 0;
+    MenuItem.Enabled := MenuItem.Count > 0;
 end;
 //!  \83A\83N\83e\83B\83u\82È\83^\83u\82Æ\93¯\82\94Â\82Ì\8aJ\82¢\82Ä\82¢\82é\83X\83\8c\83b\83h\83N\83\8a\83b\83N\83C\83x\83\93\83g
 procedure TGikoForm.SameBoardThreadSubItemOnClick(Sender: TObject);
 var
-       i, j: Integer;
+       i: Integer;
        MenuItem: TMenuItem;
 begin
        if Sender is TMenuItem then begin
         try
-            j := 0;
             MenuItem := TMenuItem(Sender);
             for i := 0 to BrowserTab.Tabs.Count - 1 do begin
                 // \93¯\82\94Â\82©\82Ç\82¤\82©
@@ -6541,12 +6550,11 @@ begin
                     TBrowserRecord(BrowserTab.Tabs.Objects[i]).Thread.ParentBoard) then begin
                     if FActiveContent.Thread <>
                         TBrowserRecord(BrowserTab.Tabs.Objects[i]).Thread then begin
-                        if (SameBoardThreadItem.Items[j] = MenuItem) then begin
-                            MoveToURL( TBrowserRecord(BrowserTab.Tabs.Objects[i])
-                                .Thread.URL);
+                        if (MenuItem.Hint = TBrowserRecord(BrowserTab.Tabs.Objects[i])
+                                .Thread.URL) then begin
+                            MoveToURL( MenuItem.Hint);
                             Exit;
                         end;
-                        Inc(j);
                     end;
                 end;
             end;
diff --git a/PopupMenuUtil.pas b/PopupMenuUtil.pas
new file mode 100644 (file)
index 0000000..cd10212
--- /dev/null
@@ -0,0 +1,177 @@
+unit PopupMenuUtil;
+
+interface
+
+uses
+       Windows, Messages, SysUtils, Classes, Controls,
+       StdCtrls, ExtCtrls, ComCtrls, ActnList, Menus,
+    IniFiles,  GikoSystem, MojuUtils, Giko;
+
+    procedure ReadSetting(ActionList: TActionList; PopupMenu: TPopupMenu);
+    function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
+    function GetMenuItem(Section: string; PopupMenu: TPopupMenu; ActionList: TActionList; MenuName: string): TMenuItem;
+    function checkActionName(Section: string ; ActionName: string): Boolean;
+const
+    //! \90Ý\92è\83t\83@\83C\83\8b\96¼
+       INI_FILENAME: string = 'popupmenu.ini';
+    //! \83u\83\89\83E\83U\83^\83u\83Z\83N\83V\83\87\83\93\96¼
+    BROWSER_TAB: string = 'BrowserTab';
+    //! \83Z\83N\83V\83\87\83\93\82Ì\88ê\97\97
+    SECTIONS : array[0..0] of string =( 'BrowserTab' ) ;
+
+    //! \83u\83\89\83E\83U\83^\83u\83|\83b\83v\83A\83b\83v\82É\90Ý\92è\89Â\94\\82È\83\81\83j\83\85\81[\96¼
+    ACK_BROWSER: array[0..7]   of string = (
+                                            'ItemReloadAction',
+                                            'FavoriteAddAction',
+                                            'BrowserTabCloseAction',
+                                            'NotSelectTabCloseAction',
+                                            'LeftTabCloseAction',
+                                            'RightTabCloseAction',
+                                            'ActiveLogDeleteAction',
+                                            'AllTabCloseAction');
+
+implementation
+procedure ReadSetting(ActionList: TActionList; PopupMenu: TPopupMenu);
+const
+    // \93Á\8eê\83A\83N\83V\83\87\83\93\96¼
+    // \8f\84\89ñ\83A\83C\83e\83\80
+    ROUNDITEM = 'RoundItem';
+    // \93¯\88ê\94Â\83X\83\8c\83b\83h\88ê\97\97\97p
+    SAMPETHREAD='SameBoardThreadItem';
+var
+    ini : TMemIniFile;
+    mkeys, skeys : TStringList;
+    i, j, idx: Integer;
+    value, subValue : String;
+    item, subItem : TMenuItem;
+begin
+    if (FileExists(GikoSys.Setting.GetConfigDir + INI_FILENAME)) Then begin
+        ini := TMemIniFile.Create(GikoSys.Setting.GetConfigDir + INI_FILENAME);
+        mkeys := TStringList.Create;
+        mkeys.Sorted := true;
+        skeys := TStringList.Create;
+        skeys.Sorted := true;
+        try
+            for idx := 0 to Length(SECTIONS) - 1 do begin
+                ini.ReadSection(SECTIONS[idx], mkeys);
+                // main\91æ\88ê\8aK\91w sub\91æ\93ñ\8aK\91w\82Ì\95ª\97£
+                for i := mkeys.Count - 1 downto 0 do begin
+                    if (Pos('sub', mkeys[i]) = 1) then begin
+                        skeys.Add(mkeys[i]);
+                        mkeys.Delete(i);
+                    end;
+                end;
+                // \91æ\88ê\8aK\91w\82Ì\8f\88\97\9d
+                PopupMenu.Items.Clear;
+                for i := 0 to mkeys.Count - 1 do begin
+                    value := ini.ReadString(SECTIONS[idx], mkeys[i], '-');
+                    item := GetMenuItem(SECTIONS[idx], PopupMenu, ActionList, value);
+                    if (item <> nil) then begin
+                        PopupMenu.Items.Add(item);
+                        // \83A\83N\83V\83\87\83\93\82ª\90Ý\92è\82³\82ê\82Ä\82¢\82é\82à\82Ì\82É\82Í\91æ\93ñ\91w\82Í\82Â\82¯\82È\82¢
+                        if (item.Action = nil) then begin
+                            // \91æ\93ñ\8aK\91w\82Ì\8f\88\97\9d(\82 \82ê\82Î)
+                            for j := 0 to skeys.Count - 1 do begin
+                                if (Pos('sub.' + mkeys[i], skeys[j]) = 1) then begin
+                                    subValue := ini.ReadString(SECTIONS[idx], skeys[j], '-');
+                                    subItem := GetMenuItem(SECTIONS[idx], PopupMenu, ActionList, subValue);
+                                    if (subItem <> nil) then begin
+                                        item.Add(subItem);
+                                    end;
+                                end;
+                            end;
+                        end;
+                    end;
+                end;
+                // \82±\82Ì\83Z\83N\83V\83\87\83\93\82Ì\8f\88\97\9d\82ª\8fI\82í\82Á\82½\82Ì\82Å\83N\83\8a\83A
+                mkeys.Clear;
+                skeys.Clear;
+            end;
+        finally
+            skeys.Free;
+            mkeys.Free;
+            ini.Free;
+        end;
+    end;
+end;
+//! \83\81\83j\83\85\81[\82ð\95Ô\82·
+function GetMenuItem(Section: string; PopupMenu: TPopupMenu; ActionList: TActionList; MenuName: string): TMenuItem;
+var
+    Action: TCustomAction;
+begin
+    Result := nil;
+    // \83_\83u\83\8b\83N\83H\81[\83g\82Å\8en\82Ü\82é\82Æ\82«\82Í\83\89\83x\83\8b
+    if (Pos('"', MenuName)=1) then begin
+        Result := TMenuItem.Create(PopupMenu);
+        Result.Caption := Copy(MenuName, 2, Length(MenuName));
+    end else if (MenuName = '-' ) then begin
+        // \8bæ\90Ø\82è\90ü
+        Result := TMenuItem.Create(PopupMenu);
+        Result.Caption := '-';
+    end else begin
+        if (BROWSER_TAB = Section) then begin
+            // \83u\83\89\83E\83U\83^\83u\82Ì\93Á\8eê\91Î\89\9e
+            if (MenuName = 'RoundItem' ) then begin
+                try
+                    // \8f\84\89ñ\83\81\83j\83\85\81[\97p\83_\83~\81[
+                    Result := TMenuItem.Create(PopupMenu);
+                    Result.Name := 'RoundItem';
+                    Result.Caption := GikoForm.ItemReservPMenu.Caption;
+                    Result.Hint    := GikoForm.ItemReservPMenu.Hint;
+                except
+                    // \8aù\82É\8eg\82í\82ê\82Ä\82é\82Æ\82«\82Í\83G\83\89\81[\82É\82È\82é
+                    Result.Free;
+                    Result := nil;
+                end;
+            end else if (MenuName = 'BoardThreadItem' ) then begin
+                try
+                    // \93¯\88ê\94Â\83X\83\8c\83b\83h\95\\8e¦\97p\83_\83~\81[
+                    Result := TMenuItem.Create(PopupMenu);
+                    Result.Name := 'BoardThreadItem';
+                    Result.Caption := '\93¯\94Â\82Å\95\\8e¦\82µ\82Ä\82¢\82é\83X\83\8c\83b\83h';
+                except
+                    // \8aù\82É\8eg\82í\82ê\82Ä\82é\82Æ\82«\82Í\83G\83\89\81[\82É\82È\82é
+                    Result.Free;
+                    Result := nil;
+                end;
+            end;
+        end;
+        // \83\81\83j\83\85\81[\82ª\8c\88\82Ü\82ç\82¸\82É\81A\8b\96\89Â\82³\82ê\82½\83A\83N\83V\83\87\83\93\96¼\82È\82çAction\82©\82ç\8dì\90¬
+        if (Result = nil) and (checkActionName(Section, MenuName)) then begin
+            Action := GetActionItem(ActionList, MenuName);
+            if Action <> nil then begin
+                Result := TMenuItem.Create(PopupMenu);
+                Result.Action := Action;
+            end;
+        end;
+    end;
+end;
+//ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
+function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
+var
+       i: Integer;
+begin
+       for i := 0 to ActionList.ActionCount - 1 do begin
+               if ActionList.Actions[i].Name = ActionName then begin
+                       Result := TCustomAction(ActionList.Actions[i]);
+                       Exit;
+               end;
+       end;
+       Result := nil;
+end;
+
+function checkActionName(Section: string ; ActionName: string): Boolean;
+var
+    i : Integer;
+begin
+    Result := False;
+    if (BROWSER_TAB = Section) then begin
+        for i :=0 to  Length(ACK_BROWSER) - 1 do begin
+            if (ACK_BROWSER[i] = ActionName) then begin
+                Result := True;
+                Break;
+            end;
+        end;
+    end;
+end;
+end.
index be2121b..ae74676 100644 (file)
@@ -81,7 +81,8 @@ uses
   NewBoardURL in 'NewBoardURL.pas' {NewBoardURLForm},
   ExtPreviewDatamodule in 'ExtPreviewDatamodule.pas' {ExtPreviewDM: TDataModule},
   UpdateCheck in 'UpdateCheck.pas' {UpdateCheckForm},
-  SHA1Unit in 'SHA1Unit.pas';
+  SHA1Unit in 'SHA1Unit.pas',
+  PopupMenuUtil in 'PopupMenuUtil.pas';
 
 {$R *.RES}
 {$R gikoResource.res}
index 5e5b436..a854c20 100644 (file)
Binary files a/gikoNavi.res and b/gikoNavi.res differ
index ae26594..814a7f0 100644 (file)
@@ -25,3 +25,7 @@ TO=config\replace.ini
 [extpreview]
 FROM=config\default\extpreview.default
 TO=config\extpreview.ini
+
+[popupmenu]
+FROM=config\default\popupmenu.default
+TO=config\popupmenu.ini
diff --git a/res/default/popupmenu.default b/res/default/popupmenu.default
new file mode 100644 (file)
index 0000000..72bd50c
--- /dev/null
@@ -0,0 +1,29 @@
+; \83|\83b\83v\83A\83b\83v\83\81\83j\83\85\81[\90Ý\92è\83t\83@\83C\83\8b
+
+[BrowserTab]
+;\83u\83\89\83E\83U\83^\83u\83|\83b\83v\83A\83b\83v\83\81\83j\83\85\81[\90Ý\92è
+main.01=ItemReloadAction
+main.02=-
+main.03=FavoriteAddAction
+main.04=RoundItem
+main.05=-
+main.06=BoardThreadItem
+main.07=-
+main.08=BrowserTabCloseAction
+main.09=NotSelectTabCloseAction
+main.10=LeftTabCloseAction
+main.11=RightTabCloseAction
+main.12=-
+main.13=ActiveLogDeleteAction
+main.14=-
+main.15=AllTabCloseAction
+;; \83T\83u\83\81\83j\83\85\81[\82Ì\8dì\82è\95û
+;; " \82Å\82Í\82\82ß\82é\82Æ\91æ\88ê\8aK\91w\97p\82Ì\83\89\83x\83\8b\82ð\8dì\82ê\82é
+;; sub.\83\89\83x\83\8b\82É\82µ\82½\83L\81[.0X \82Ì\8c`\82Å\83T\83u\83\81\83j\83\85\81[\82ð\97ñ\8b\93\82·\82é
+;; \89º\82Í\81A\83^\83u\91\80\8dì\82ð\83T\83u\83\81\83j\83\85\81[\82É\92Ç\89Á\82µ\82½\97á
+;main.16="\83^\83u
+;sub.main.16.01=BrowserTabCloseAction
+;sub.main.16.02=NotSelectTabCloseAction
+;sub.main.16.03=LeftTabCloseAction
+;sub.main.16.04=RightTabCloseAction
+;sub.main.16.05=AllTabCloseAction