OSDN Git Service

[#34600] add a new function "show all histories" into GUI menu t34600
authorargius <argius.net@gmail.com>
Sat, 22 Nov 2014 13:07:28 +0000 (22:07 +0900)
committerargius <argius.net@gmail.com>
Sat, 22 Nov 2014 13:07:28 +0000 (22:07 +0900)
src/net/argius/stew/ui/window/AnyActionKey.java
src/net/argius/stew/ui/window/ConsoleTextArea.java
src/net/argius/stew/ui/window/Menu.u8p
src/net/argius/stew/ui/window/Menu_ja.u8p
src/net/argius/stew/ui/window/WindowLauncher.java
src/net/argius/stew/ui/window/WindowOutputProcessor.java
src/net/argius/stew/ui/window/messages.u8p
src/net/argius/stew/ui/window/messages_ja.u8p

index fa299a7..7fa9188 100644 (file)
@@ -32,6 +32,7 @@ public enum AnyActionKey {
     breakCommand,
     lastHistory,
     nextHistory,
+    showAllHistories,
     sendRollback,
     sendCommit,
     connect,
index 0ac57eb..74f188e 100644 (file)
@@ -161,6 +161,17 @@ final class ConsoleTextArea extends JTextArea implements AnyActionListener, Text
     }
 
     /**
+     * Prepares submitting.
+     * Clears selection, moves cursor to end, and focuses this.
+     */
+    void prepareSubmitting() {
+        final int ep = getEndPosition();
+        setSelectionStart(ep);
+        moveCaretPosition(ep);
+        requestFocus();
+    }
+
+    /**
      * Clears text.
      */
     void clear() {
index 67a6bd8..039368f 100644 (file)
@@ -73,7 +73,7 @@ item.autoAdjustModeHeaderAndValue.checkbox=yes
 
 group.command=Command
 group.command.mnemonic=C
-group.command.items=executeCommand,breakCommand,,lastHistory,nextHistory,sendRollback,sendCommit,,connect,disconnect,,postProcessMode,inputEcryptionKey,editConnectors
+group.command.items=executeCommand,breakCommand,,lastHistory,nextHistory,showAllHistories,sendRollback,sendCommit,,connect,disconnect,,postProcessMode,inputEcryptionKey,editConnectors
 item.executeCommand=Execute
 item.executeCommand.mnemonic=X
 item.executeCommand.shortcut=ctrl M
@@ -86,6 +86,8 @@ item.lastHistory.shortcut=ctrl UP
 item.nextHistory=History Next
 item.nextHistory.mnemonic=N
 item.nextHistory.shortcut=ctrl DOWN
+item.showAllHistories=Show All Histories
+item.showAllHistories.mnemonic=A
 item.sendRollback=Rollback
 item.sendRollback.mnemonic=R
 item.sendCommit=Commit
index 5bcfd36..047101b 100644 (file)
@@ -30,6 +30,7 @@ item.executeCommand=実行
 item.breakCommand=中断
 item.lastHistory=前のコマンド履歴
 item.nextHistory=次のコマンド履歴
+item.showAllHistories=コマンド履歴を全表示
 item.sendRollback=ロールバック
 item.sendCommit=コミット
 item.connect=接続
index 2af3031..0024c79 100644 (file)
@@ -298,6 +298,18 @@ public final class WindowLauncher implements
                 retrieveHistory(-1);
             } else if (ev.isAnyOf(nextHistory)) {
                 retrieveHistory(+1);
+            } else if (ev.isAnyOf(showAllHistories)) {
+                if (historyList.isEmpty()) {
+                    op.showInformationMessageDialog(res.get("w.no-histories"), null);
+                } else {
+                    final String msg = res.get("i.choose-history", historyList.size());
+                    final String lastCommand = historyList.get(historyList.size() - 1);
+                    Object value = op.showInputDialog(msg, null, historyList.toArray(), lastCommand);
+                    if (value != null) {
+                        textArea.replace((String)value);
+                        textArea.prepareSubmitting();
+                    }
+                }
             } else if (ev.isAnyOf(sendRollback)) {
                 if (confirmCommitable()
                     && showConfirmDialog(op, res.get("i.confirm-rollback"), null, OK_CANCEL_OPTION) == OK_OPTION) {
@@ -652,10 +664,7 @@ public final class WindowLauncher implements
             historyIndex = historyList.size() - 1;
         }
         textArea.replace(historyList.get(historyIndex));
-        final int endPosition = textArea.getEndPosition();
-        textArea.setSelectionStart(endPosition);
-        textArea.moveCaretPosition(endPosition);
-        textArea.requestFocus();
+        textArea.prepareSubmitting();
     }
 
     /**
index abf3e2f..0cf54c8 100644 (file)
@@ -402,6 +402,36 @@ final class WindowOutputProcessor extends JFrame implements OutputProcessor, Any
         currentDirectory = dir;
     }
 
+    Object showInputDialog(String message, String title, Object[] values, Object initial) {
+        return showInputDialog(this, message, title, values, initial);
+    }
+
+    static Object showInputDialog(Component parent, String message, String title, Object[] values, Object initial) {
+        JOptionPane p = new JOptionPane(message, PLAIN_MESSAGE, OK_CANCEL_OPTION);
+        p.setWantsInput(true);
+        p.setSelectionValues(values);
+        p.setInitialSelectionValue(initial);
+        p.setComponentOrientation(parent.getComponentOrientation());
+        JDialog d = p.createDialog(parent, title);
+        Dimension size = d.getSize();
+        if (size.width > parent.getWidth() || size.height > parent.getHeight()) {
+            if (size.width > parent.getWidth()) {
+                size.width = (int)(parent.getWidth() * 0.95);
+            }
+            if (size.height > parent.getHeight()) {
+                size.height = (int)(parent.getHeight() * 0.95);
+            }
+            d.setPreferredSize(size);
+            d.setSize(size);
+            d.setLocationRelativeTo(parent);
+        }
+        p.selectInitialValue();
+        d.setVisible(true);
+        d.dispose();
+        Object value = p.getInputValue();
+        return (value == UNINITIALIZED_VALUE) ? null : value;
+    }
+
     void showInformationMessageDialog(String message, String title) {
         showInformationMessageDialog(this, message, title);
     }
index da55619..439b64c 100644 (file)
@@ -1,5 +1,6 @@
 i.cancelled=The command was canceled.\n(The process in the server-side may be still working.)
 i.choose-connection=Choose Connector
+i.choose-history=Choose a command history of {0} histories
 i.confirm-close=Do you want to close this window?
 i.confirm-commit=Do you want to commit?
 i.confirm-overwrite=The file [{0}] already exists. Overwrite it?
@@ -19,6 +20,7 @@ i.statusbar-message=\ Execution Time {0} seconds ( {1} )
 w.connector-readonly=This connector is read-only.
 w.import-target-not-available=The destination to import is not available.
 w.no-connector=No Connector.
+w.no-histories=No command histories.
 w.not-connect=Not connected.
 e.cannot-open-help-automatically=Can't open help({0}) automatically on this platform.
 e.enables-select-just-1-table=You can choose only one of tables. 
index 45d7003..16ffbec 100644 (file)
@@ -1,5 +1,6 @@
 i.cancelled=コマンドがキャンセルされました。\n(サーバ側の処理はキャンセルされていません。)
 i.choose-connection=接続を選択
+i.choose-history=コマンド履歴{0}件からコマンドを選択
 i.confirm-close=ウィンドウを閉じてよろしいですか?
 i.confirm-commit=コミットします。よろしいですか?
 i.confirm-overwrite=ファイル {0} は存在します。\n上書きしますか?
@@ -19,6 +20,7 @@ i.statusbar-message=\ 実行時間 {0} 秒 ( {1} )
 w.connector-readonly=コネクタは読取専用です。
 w.import-target-not-available=インポート先が無効です。
 w.no-connector=接続設定がありません。
+w.no-histories=コマンド履歴がありません。
 w.not-connect=接続されていません。
 e.cannot-open-help-automatically=このプラットフォームでは自動でヘルプ({0})を開けません。\r
 e.enables-select-just-1-table=テーブルは1つだけ選択できます。