Community
    • Login

    The problem with notepad.runMenuCommand

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 2 Posters 92 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      westyles
      last edited by

      I created an issue: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/17164
      but it was closed. Then I added more details—I made a screen recording of the problem.
      There is a problem with any language other than EN.

      And I found a discussion thread on the same issue:
      https://sourceforge.net/p/npppythonscript/discussion/1188886/thread/bc080292/

      And I realized that it was because of nativeLang.xml
      The essence of the problem is that the command:
      notepad.runMenuCommand(menuName, menuOption) for menuName does not use “menuId”,
      and “name” from the xml string: <Item menuId=“language” name=“&Language”/>
      Which varies depending on the language npp! And it turns out that the command is not universal!

      Usually, universal commands are used for this, and I think that “menuId” or “Id” should be used here!
      Then no one will have any problems writing code.

      I decided to write on the forum because I found a solution to get around this, given the situation, and before calling the command, I substitute the necessary current translation as follows:

      langID_dict = {'abkhazian.xml': 'Асинтаксисқәа', 'afrikaans.xml': 'Taal', 'albanian.xml': 'Gjuha', 'arabic.xml': 'لغة',
      'aragonese.xml': 'Luengache', 'aranese.xml': 'Lenguatge', 'azerbaijani.xml': 'Dil', 'basque.xml': 'Hizkuntza',
      'belarusian.xml': 'Сінтаксіс', 'bengali.xml': 'ভাষা', 'bosnian.xml': 'Jezik', 'brazilian_portuguese.xml': 'Linguagem',
      'breton.xml': 'Yezh', 'bulgarian.xml': 'Синтаксис', 'catalan.xml': 'Llenguatge', 'chineseSimplified.xml': '语言(L)',
      'corsican.xml': 'Linguaghju', 'croatian.xml': 'Sintakse', 'czech.xml': 'Syntaxe', 'danish.xml': 'Sprog',
      'dutch.xml': 'Syntaxis', 'english.xml': 'Language', 'english_customizable.xml': 'Language', 'esperanto.xml': 'Lingvaĵo',
      'estonian.xml': 'Keel', 'extremaduran.xml': 'Luenga', 'farsi.xml': 'زبان', 'finnish.xml': 'Koodikieli',
      'french.xml': 'Langage', 'friulian.xml': 'Lengaç', 'galician.xml': 'Linguaxe', 'georgian.xml': 'სინტაქსი',
      'german.xml': 'Sprache', 'greek.xml': 'Γλώσσα', 'gujarati.xml': 'ભાષા', 'hebrew.xml': 'שפה',
      'hindi.xml': 'भाषा', 'hongKongCantonese.xml': '語言(L)', 'hungarian.xml': 'Nyelv', 'indonesian.xml': 'Bahasa',
      'irish.xml': 'Teanga', 'italian.xml': 'Linguaggio', 'japanese.xml': '言語(L)', 'kabyle.xml': 'Tameslayt',
      'kannada.xml': 'ಲ್ಯಾಂಗ್ವೇಜ್', 'kazakh.xml': 'Бағдарламалық тіл', 'korean.xml': '언어(L)', 'kurdish.xml': 'زمانەكان',
      'kyrgyz.xml': 'Синтаксис', 'latvian.xml': 'Valoda', 'ligurian.xml': 'Lengoaggio', 'lithuanian.xml': 'Kalba',
      'luxembourgish.xml': 'Sprooch', 'macedonian.xml': 'Јазик', 'malay.xml': 'Bahasa', 'marathi.xml': 'भाषा',
      'mongolian.xml': 'Хэл', 'nepali.xml': 'भाषा', 'norwegian.xml': 'Språk', 'nynorsk.xml': 'Språk',
      'occitan.xml': 'Lengatge', 'piglatin.xml': 'Anguagelay', 'polish.xml': 'Składnia', 'portuguese.xml': 'Linguagem',
      'punjabi.xml': 'ਭਾਸ਼ਾ', 'romanian.xml': 'Limbaj', 'russian.xml': 'Синтаксисы', 'samogitian.xml': 'Shnekta',
      'sardinian.xml': 'Limbàgiu', 'serbian.xml': 'Jezik', 'serbianCyrillic.xml': 'Језик', 'sinhala.xml': 'භාෂාව',
      'slovak.xml': 'Jazyk', 'slovenian.xml': 'Sintaksa jezika', 'spanish.xml': 'Lenguaje', 'spanish_ar.xml': 'Lenguaje',
      'swedish.xml': 'Språk', 'tagalog.xml': 'Wika', 'taiwaneseMandarin.xml': '語言(L)', 'tajikCyrillic.xml': 'Забон',
      'tamil.xml': 'மொழி (L)', 'tatar.xml': 'Синтакслар', 'telugu.xml': 'ల్యాంగ్వేజ్ (L)', 'thai.xml': 'ภาษา (L)',
      'turkish.xml': 'Diller', 'ukrainian.xml': 'Мова', 'urdu.xml': 'پروگرامنگ زبان', 'uyghur.xml': 'پروگرامما تىلى',
      'uzbek.xml': 'Sintaksislar', 'uzbekCyrillic.xml': 'Синтаксис', 'venetian.xml': 'Ƚenguagio', 'vietnamese.xml': 'Ngôn ngữ',
      'welsh.xml': 'Iaith (L)', 'zulu.xml': 'ulimi'}
      
      _file_lang = notepad.getNativeLangFileName()
      notepad.runMenuCommand(langID_dict[_file_lang], '222')
      
      PeterJonesP 1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @westyles
        last edited by PeterJones

        To begin with: I like your workaround script. It’s a great thing to share, which is why I upvoted it. (I am saying this, so that you don’t take my further comments as a criticism of this script)

        @westyles said in The problem with notepad.runMenuCommand:

        I created an issue: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/17164
        but it was closed.

        Because it was missing essential details for any Notepad++ bug report. Namely, it did not include the steps to reproduce, nor did it include the ?-menu’s Debug Info that every issue requests that you include. Based on this lack of information, the developer could not replicate your problem, and thus closed the issue. (But more on this in a bit)

        Then I added more details—I made a screen recording of the problem.

        But a screen recording is not necessarily sufficient to show the steps to reproduce, clicking on links to random upload websites is foolish (so i wouldn’t expect anyone to click to your random “video” – please note, such websites would allow you to upload malicious content and claim it’s a video), and you didn’t include the requested details.

        And I found a discussion thread on the same issue:

        Notice where that discussion was: in the NppPythonScript plugin repo for the old 2016-era version of the PythonScript plugin. That plugin has a new home and a new maintainer/developer. If you want a feature request or bug report for the PythonScript plugin, you would need to go to the https://github.com/bruderstein/pythonscript repo. But this is neither a bug, nor does a feature need to be added

        And this is not a bug. The notepad.runMenuCommand() interface is well established as being based on the name of the menu item. It literally searches the underlying win32 menu objects looking for matching text. If you want a new command that runs it based on menuCommand-ID, you could request that (if it didn’t already exist). But note, that’s precisely what notepad.menuCommand() does – it “Runs a Notepad++ menu command. Use the MENUCOMMAND enum, or integers directly from the nativeLang.xml file.” So if you want to use Command ID, then use notepad.menuCommand(). If you want to use the name of the command, use notepad.runMenuCommand().

        W 1 Reply Last reply Reply Quote 2
        • W
          westyles @PeterJones
          last edited by

          @PeterJones said in The problem with notepad.runMenuCommand:

          And this is not a bug

          Thank you for the clarification
          I replied to you here:
          https://github.com/notepad-plus-plus/notepad-plus-plus/issues/17164#issuecomment-3762757796

          Added:
          I’ve already written to the PythonScript plugin author, and one feature has already been added at my request, under Settings:
          “DISABLE” another script is running popup warning

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @westyles
            last edited by

            @westyles said in The problem with notepad.runMenuCommand:

            @PeterJones said in The problem with notepad.runMenuCommand:

            And this is not a bug

            Thank you for the clarification
            I replied to you here

            Since it is not a Notepad++ application issue, but your usage of a plugin, with you thinking that the plugin needs a new feature, continuing the conversation in the official application Issues is the wrong place, as I tried to make clear. So I will quote your message from there, and reply here, where it belongs.

            When I figured it out for myself, I realized that in my case, neither of the two commands you mentioned would work. There are no suitable commands.

            I disagree.

            Because I need to call up the menu items created with user userDefineLangs (from files in the userDefineLangs folder), they are created each time npp is started.

            Yep. But they still have command-ID values – you just have to figure out what they are. And once you do, notepad.menuCommand will work for you, because as I quoted before, it is documented to work either with the plugin’s ENUM values for builtin, or using the raw command-ID integer.

            There are no permanent built-in commands for this;

            I disagree.

            only notepad.runMenuCommand is suitable, and it depends on the npp language.

            It’s not the only suitable choice.

            As you wrote, in this case, another command is needed that will call menuId or ID

            That’s exactly what notepad.menuCommand does.

            So, in my current Notepad++ instance, the Language > Markdown (preinstalled) is getting the dynamic commandID=46181. I can determine this easily using the UI Spy plugin:
            fe024044-c9ca-4324-b264-986832378db5-image.png

            So then I call up the PythonScript console, and send the command notepad.menuCommand(46181), and it changes my language from Normal text file (Language > None (Normal Text)) to the UDL Markdown (preinstalled), thus showing that, indeed, you can use already-existing notepad.menuCommand() using an integer command ID to call a UDL’s command ID (or anything else by commandID).

            So if you know the commandID, whether it’s a built-in command or a dynamic command (like a UDL or macro), you can use notepad.menuCommand(). If you don’t already know the commandID, then you cannot use it (but then again, you couldn’t use this “new” function that you claim you want, because this new requested function would also require that you already know the commandID, based on the feature you described).

            So I don’t see why you think it won’t work for you. Because I can use it to call any of the UDL or Macros that I want to call.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors