From f3365cb8fe6b7a362db05ec94b84d0d07fa39e4d Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Mon, 30 Dec 2013 12:02:45 +0100 Subject: [PATCH] Make button click depend on current mode. Fix #243 Both insert mode and disabled mode use the same greyed out icon for the toolbar button. If you're in insert mode and click the button, we used to disable the extension as normal. However, it felt like clicking the button did nothing, because the icon didn't change. Even if it _would_ change, it feels more natural if the extension is _enabled_ again at that point. So now, if you're in insert mode and click the button, we enter normal mode. (#243) If the current site is blacklisted, clicking the button used to disable the extension. Well, it was already disabled, but the button icon changed from the blacklisted icon (red) to the disabled icon (grey). Clicking again went back to blacklisted mode. That's pretty weird. Now we open the menu popup when clicked instead, which will show the trash can icon which is used to un-blacklist the site. Un-blacklisting directly when clicking the button would be to go too far, since that can potentially remove more blacklisting rules than the user wants to. Using the popup you have a chance to review what will be removed when un-blacklisting. To sum up, the button clicking is more intuitive now: - If enabled: Disable - Otherwise: Enable (almost) --- extension/bootstrap.coffee | 5 +++-- extension/locale/de/vimfx.properties | 2 +- extension/locale/el-GR/vimfx.properties | 2 +- extension/locale/en-US/vimfx.properties | 2 +- extension/locale/hu/vimfx.properties | 2 +- extension/locale/id/vimfx.properties | 2 +- extension/locale/nl/vimfx.properties | 2 +- extension/locale/pl/vimfx.properties | 2 +- extension/locale/ru/vimfx.properties | 2 +- extension/locale/zh-CN/vimfx.properties | 2 +- extension/packages/button.coffee | 25 +++++++++++++++++-------- extension/packages/events.coffee | 1 + 12 files changed, 30 insertions(+), 19 deletions(-) diff --git a/extension/bootstrap.coffee b/extension/bootstrap.coffee index 2999dcf..e7a128f 100644 --- a/extension/bootstrap.coffee +++ b/extension/bootstrap.coffee @@ -40,7 +40,8 @@ do (global = this) -> global.startup = (data, reason) -> # Requires for startup/install { loadCss } = require 'utils' - { addEventListeners } = require 'events' + { addEventListeners + , vimBucket } = require 'events' { getPref , initPrefValues } = require 'prefs' { setButtonInstallPosition @@ -62,7 +63,7 @@ do (global = this) -> options.observe() watchWindows(addEventListeners, 'navigator:browser') - watchWindows(addToolbarButton, 'navigator:browser') + watchWindows(addToolbarButton.bind(undefined, vimBucket), 'navigator:browser') unload(release) diff --git a/extension/locale/de/vimfx.properties b/extension/locale/de/vimfx.properties index 9383d47..610825d 100644 --- a/extension/locale/de/vimfx.properties +++ b/extension/locale/de/vimfx.properties @@ -1,7 +1,7 @@ button_tooltip_enabled=VimFx ist aktiviert. Zum Deaktivieren hier klicken. (shift-alt-v) button_tooltip_disabled=VimFx ist deaktiviert. Zum Aktivieren hier klicken. (shift-alt-v) button_tooltip_blacklisted=Diese Seite ist auf der schwarzen Liste -button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc (by default) to exit +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Click to exit (Esc [by default]) item_preferences=Einstellungen item_blacklist_button_tooltip=Schwarze Liste item_blacklist_button_inverse_tooltip=Remove this rule diff --git a/extension/locale/el-GR/vimfx.properties b/extension/locale/el-GR/vimfx.properties index 5a66b9e..e62fe34 100644 --- a/extension/locale/el-GR/vimfx.properties +++ b/extension/locale/el-GR/vimfx.properties @@ -1,7 +1,7 @@ button_tooltip_enabled=Το VimFx είναι ενεργοποιημένο. Κάντε κλικ για να το απενεργοποιήσετε (shift-alt-v) button_tooltip_disabled=Το VimFx είναι απενεργοποιημένο. Κάντε κλικ για να το ενεργοποιήσετε (shift-alt-v) button_tooltip_blacklisted=Το VimFx είναι στην μαύρη λίστα σε αυτήν την σελίδα. -button_tooltip_insertMode=Το VimFx είναι σε λειτουργία εισαγωγής (insert mode) σε αυτή τη Σελίδα: Όλες οι εντολές αγνοούνται. Πατήστε Esc (προεπιλογμένο) για να βγείτε +button_tooltip_insertMode=Το VimFx είναι σε λειτουργία εισαγωγής (insert mode) σε αυτή τη Σελίδα: Όλες οι εντολές αγνοούνται. Κάντε κλικ για να βγείτε (Esc [προεπιλεγμένο]) item_preferences=Προτιμήσεις item_blacklist_button_tooltip=Μαύρη Λίστα item_blacklist_button_inverse_tooltip=Κατάργηση αυτού του κανόνα diff --git a/extension/locale/en-US/vimfx.properties b/extension/locale/en-US/vimfx.properties index 06e0590..110ab3a 100644 --- a/extension/locale/en-US/vimfx.properties +++ b/extension/locale/en-US/vimfx.properties @@ -1,7 +1,7 @@ button_tooltip_enabled=VimFx is Enabled. Click to Disable (shift-alt-v) button_tooltip_disabled=VimFx is Disabled. Click to Enable (shift-alt-v) button_tooltip_blacklisted=VimFx is Blacklisted on this Page -button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc (by default) to exit +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Click to exit (Esc [by default]) item_preferences=Preferences item_blacklist_button_tooltip=Blacklist item_blacklist_button_inverse_tooltip=Remove this rule diff --git a/extension/locale/hu/vimfx.properties b/extension/locale/hu/vimfx.properties index a9bea5f..a73478e 100644 --- a/extension/locale/hu/vimfx.properties +++ b/extension/locale/hu/vimfx.properties @@ -1,7 +1,7 @@ button_tooltip_enabled=VimFx aktív. Kattints az inaktiváláshoz (shift-alt-v) button_tooltip_disabled=VimFx inaktív. Kattints az aktiváláshoz (shift-alt-v) button_tooltip_blacklisted=Az oldal feketelistázva a VimFX-ben. -button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc (by default) to exit +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Click to exit (Esc [by default]) item_preferences=Beállítások item_blacklist_button_tooltip=Feketelista item_blacklist_button_inverse_tooltip=Remove this rule diff --git a/extension/locale/id/vimfx.properties b/extension/locale/id/vimfx.properties index 66e7194..7aa42c9 100644 --- a/extension/locale/id/vimfx.properties +++ b/extension/locale/id/vimfx.properties @@ -1,7 +1,7 @@ button_tooltip_enabled=VimFx telah Aktif. Klik untuk Nonaktifkan (shift-alt-v) button_tooltip_disabled=VimFx telah Nonaktif. Klik untuk Aktifkan (shift-alt-v) button_tooltip_blacklisted=VimFx telah Dilarang pada halaman ini -button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc (by default) to exit +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Click to exit (Esc [by default]) item_preferences=Preferensi item_blacklist_button_tooltip=Larangan item_blacklist_button_inverse_tooltip=Remove this rule diff --git a/extension/locale/nl/vimfx.properties b/extension/locale/nl/vimfx.properties index 6eefaef..c8fe709 100644 --- a/extension/locale/nl/vimfx.properties +++ b/extension/locale/nl/vimfx.properties @@ -1,7 +1,7 @@ button_tooltip_enabled=VimFx is ingeschakeld. Klik om uit te schakelen (shift-alt-v) button_tooltip_disabled=VimFx is uitgeschakeld. Klik om in te schakelen (shift-alt-v) button_tooltip_blacklisted=VimFx is uitgeschakeld op deze pagina -button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc (by default) to exit +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Click to exit (Esc [by default]) item_preferences=Instellingen item_blacklist_button_tooltip=Zwarte lijst item_blacklist_button_inverse_tooltip=Remove this rule diff --git a/extension/locale/pl/vimfx.properties b/extension/locale/pl/vimfx.properties index 73bf76f..efe5ae5 100644 --- a/extension/locale/pl/vimfx.properties +++ b/extension/locale/pl/vimfx.properties @@ -1,7 +1,7 @@ button_tooltip_enabled=VimFx jest włączony. Kliknij, aby wyłączyć (shift-alt-v) button_tooltip_disabled=VimFx jest wyłączony. Kliknij, aby włączyć (shift-alt-v) button_tooltip_blacklisted=Ta strona jest na czarnej liście VimFx -button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Press Esc (by default) to exit +button_tooltip_insertMode=VimFx is in insert mode on this Page: All commands are ignored. Click to exit (Esc [by default]) item_preferences=Preferencje item_blacklist_button_tooltip=Czarna lista item_blacklist_button_inverse_tooltip=Remove this rule diff --git a/extension/locale/ru/vimfx.properties b/extension/locale/ru/vimfx.properties index 962d83c..9c84e72 100644 --- a/extension/locale/ru/vimfx.properties +++ b/extension/locale/ru/vimfx.properties @@ -1,7 +1,7 @@ button_tooltip_enabled=VimFx работает. Нажмите чтобы выключить (shift-alt-v) button_tooltip_disabled=VimFx не работает. Нажмите чтобы включить (shift-alt-v) button_tooltip_blacklisted=VimFx содержит текущую страницу в стоп-списке -button_tooltip_insertMode=VimFx в режиме ввода на этой странице: все команды игнорируются. Нажмите Esc для выхода +button_tooltip_insertMode=VimFx в режиме ввода на этой странице: все команды игнорируются. Нажмите чтобы для выхода (Esc) item_preferences=Настройки item_blacklist_button_tooltip=Добавить в стоп-список item_blacklist_button_inverse_tooltip=Убрать эту комбинацию diff --git a/extension/locale/zh-CN/vimfx.properties b/extension/locale/zh-CN/vimfx.properties index f780d68..e77370f 100644 --- a/extension/locale/zh-CN/vimfx.properties +++ b/extension/locale/zh-CN/vimfx.properties @@ -1,7 +1,7 @@ button_tooltip_enabled=VimFx 已启用。点击禁用 (shift-alt-v) button_tooltip_disabled=VimFx 已禁用。点击启用 (shift-alt-v) button_tooltip_blacklisted=当前页面已被列入黑名单 -button_tooltip_insertMode=VimFx 在当前页面处于插入模式:所有命令都将被忽略。按下 Esc(默认)键退出插入模式 +button_tooltip_insertMode=VimFx 在当前页面处于插入模式:所有命令都将被忽略。点击退出(Esc[默认]) item_preferences=首选项 item_blacklist_button_tooltip=添加到黑名单 item_blacklist_button_inverse_tooltip=移除此规则 diff --git a/extension/packages/button.coffee b/extension/packages/button.coffee index 9b42dde..6ffc962 100644 --- a/extension/packages/button.coffee +++ b/extension/packages/button.coffee @@ -23,11 +23,11 @@ positions = {} setButtonInstallPosition = (toolbarId, beforeId) -> positions[BUTTON_ID] = {toolbarId, beforeId} -addToolbarButton = (window) -> +addToolbarButton = (vimBucket, window) -> document = window.document win = document.querySelector('window') - [ button, keyset ] = createButton(window) + [ button, keyset ] = createButton(vimBucket, window) # Namespace to put the VimFx state on, for example button.VimFx = {} @@ -48,7 +48,7 @@ addToolbarButton = (window) -> keysetParent.removeChild(keyset) $(document, 'navigator-toolbox').palette.removeChild(button) -createButton = (window) -> +createButton = (vimBucket, window) -> document = window.document button = document.createElement('toolbarbutton') @@ -57,17 +57,26 @@ createButton = (window) -> button.setAttribute('label', 'VimFx') button.setAttribute('class', 'toolbarbutton-1') + menupopup = createMenupopup(window, button) + onButtonCommand = (event) -> - disabled = not getPref('disabled') - setPref('disabled', disabled) - updateToolbarButton(window, {disabled}) + switch + when button.VimFx.blacklisted + menupopup.openPopup(button, 'after_start') + when button.VimFx.insertMode + return unless currentTabWindow = utils.getEventCurrentTabWindow(event) + return unless vim = vimBucket.get(currentTabWindow) + updateToolbarButton(window, {insertMode: false}) + vim.enterMode('normal') + else + disabled = not getPref('disabled') + setPref('disabled', disabled) + updateToolbarButton(window, {disabled}) event.stopPropagation() button.addEventListener('command', onButtonCommand, false) - createMenupopup(window, button) - vimkey = document.createElement('key') vimkey.setAttribute('id', KEY_ID) vimkey.setAttribute('key', 'V') diff --git a/extension/packages/events.coffee b/extension/packages/events.coffee index 63c946f..4d4650e 100644 --- a/extension/packages/events.coffee +++ b/extension/packages/events.coffee @@ -112,3 +112,4 @@ addEventListeners = (window) -> window.gBrowser.removeTabsProgressListener(tabsListener) exports.addEventListeners = addEventListeners +exports.vimBucket = vimBucket -- 2.39.3