#495 patch solving the feature request - ID: 3606375

None
pending-rejected
Alan Ezust
general (64)
5
2014-04-26
2013-05-02
Marek Bílý
No

path solving the feature request: jedit startup option (turn on/off) in its trayicon menu (OS Windows) - ID: 3606375

Discussion

  • Marek Bílý
    Marek Bílý
    2013-05-21

    From 448dc85031b9078d29bbcf1e93caf02eac51c1c9 Mon Sep 17 00:00:00 2001
    From: Marek Bily <bilymare@fel.cvut.cz>
    Date: Thu, 2 May 2013 17:41:24 +0200
    Subject: [PATCH] the patch solving the feature: jedit startup option in its
    trayicon menu (OS Windows) - ID: 3606375

    ---
    org/gjt/sp/jedit/gui/tray/JEditSwingTrayIcon.java | 122 +++++++++++++++++++++-
    org/jedit/localization/jedit_cs.props | 4 +-
    org/jedit/localization/jedit_en.props | 2 +
    org/jedit/localization/jedit_fr.props | 4 +-
    org/jedit/localization/jedit_ja.props | 4 +-
    package-files/windows/win32installer.iss | 8 +-
    6 files changed, 134 insertions(+), 10 deletions(-)

    diff --git a/org/gjt/sp/jedit/gui/tray/JEditSwingTrayIcon.java b/org/gjt/sp/jedit/gui/tray/JEditSwingTrayIcon.java
    index 294bedd..f70888a 100644
    --- a/org/gjt/sp/jedit/gui/tray/JEditSwingTrayIcon.java
    +++ b/org/gjt/sp/jedit/gui/tray/JEditSwingTrayIcon.java
    @@ -42,6 +42,15 @@ import org.gjt.sp.jedit.View;
    import org.gjt.sp.jedit.jEdit;
    import org.gjt.sp.jedit.msg.EditPaneUpdate;
    import org.gjt.sp.util.StringList;
    +
    +import java.io.BufferedReader;
    +import java.io.IOException;
    +import java.io.InputStreamReader;
    +import javax.swing.JOptionPane;
    +import java.net.URLDecoder;
    +import java.io.UnsupportedEncodingException;
    +import java.util.logging.Level;
    +import java.util.logging.Logger;
    //}}}

    /**
    @@ -53,24 +62,66 @@ public class JEditSwingTrayIcon extends JEditTrayIcon implements EBComponent
    private boolean restore;
    private String userDir;
    private String[] args;
    + private boolean isWindows;
    + private boolean isAutoStart;

    //{{{ JEditSwingTrayIcon() constructor
    public JEditSwingTrayIcon()
    {
    super(GUIUtilities.getEditorIcon(), "jEdit");
    setImageAutoSize(true);
    +
    + String system=System.getProperty("os.name");
    + system=system.toUpperCase();
    + if(system.startsWith("WINDOWS")){
    + isWindows=true;
    + String outS;
    + final String dosCommand = "reg query \"HKEY_CURRENT_USER\\Software\\"
    + + "Microsoft\\Windows\\CurrentVersion\\Run\" /v \"jEdit Server\"";
    + try {
    + final Process process = Runtime.getRuntime().exec(dosCommand);
    + BufferedReader r_in = new BufferedReader(new InputStreamReader(process.getInputStream()));
    + BufferedReader r_err = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    + isAutoStart=false;
    + while((outS=r_in.readLine())!=null){
    + System.out.println(outS+"");
    + isAutoStart=true;
    + }
    + while((outS=r_err.readLine())!=null){
    + System.out.println(outS+"");
    + isAutoStart=false;
    + }
    +
    + } catch (IOException e) {
    + e.printStackTrace();
    + }
    + }else{
    + isWindows=false;
    + }
    +
    JPopupMenu popup = new JPopupMenu();
    JMenuItem newViewItem = new JMenuItem(jEdit.getProperty("tray.newView.label"));
    + popup.add(newViewItem);
    + JMenuItem offAutoStart = new JMenuItem(jEdit.getProperty("tray.offAutoStartoff.label"));
    + if(isAutoStart){
    + offAutoStart= new JMenuItem(jEdit.getProperty("tray.offAutoStarton.label"));
    + }else{
    + offAutoStart = new JMenuItem(jEdit.getProperty("tray.offAutoStartoff.label"));
    + }
    JMenuItem newPlainViewItem = new JMenuItem(jEdit.getProperty("tray.newPlainView.label"));
    JMenuItem exitItem = new JMenuItem(jEdit.getProperty("tray.exit.label"));

    - popup.add(newViewItem);
    +
    popup.add(newPlainViewItem);
    popup.addSeparator();
    + if(isWindows){
    + popup.add(offAutoStart);
    + }
    popup.add(exitItem);
    - ActionListener actionListener = new MyActionListener(newViewItem, newPlainViewItem, exitItem);
    + ActionListener actionListener = new MyActionListener(newViewItem, newPlainViewItem, offAutoStart, exitItem);
    newViewItem.addActionListener(actionListener);
    newPlainViewItem.addActionListener(actionListener);
    + offAutoStart.addActionListener(actionListener);
    exitItem.addActionListener(actionListener);
    setMenu(popup);
    addMouseListener(new MyMouseAdapter());
    @@ -169,12 +220,14 @@ public class JEditSwingTrayIcon extends JEditTrayIcon implements EBComponent
    {
    private final JMenuItem newViewItem;
    private final JMenuItem newPlainViewItem;
    + private final JMenuItem offAutoStart;
    private final JMenuItem exitItem;

    - MyActionListener(JMenuItem newViewItem, JMenuItem newPlainViewItem, JMenuItem exitItem)
    + MyActionListener(JMenuItem newViewItem, JMenuItem newPlainViewItem, JMenuItem offAutoStart, JMenuItem exitItem)
    {
    this.newViewItem = newViewItem;
    this.newPlainViewItem = newPlainViewItem;
    + this.offAutoStart = offAutoStart;
    this.exitItem = exitItem;
    }

    @@ -187,6 +240,69 @@ public class JEditSwingTrayIcon extends JEditTrayIcon implements EBComponent
    } else if (e.getSource() == newPlainViewItem)
    {
    jEdit.newView(null, null, true);
    + } else if (e.getSource() == offAutoStart)
    + {
    +
    + String textAutostart=offAutoStart.getText();
    +
    + String textAutostartOn=jEdit.getProperty("tray.offAutoStarton.label");
    + if(textAutostart.equals(textAutostartOn)){
    + int result= JOptionPane.showConfirmDialog (null, "Would You Like to stop autostart?","Warning",JOptionPane.YES_NO_OPTION);
    + if(result == JOptionPane.YES_OPTION){
    + String dosCommand = "reg delete \"HKEY_CURRENT_USER\\Software\\"
    + + "Microsoft\\Windows\\CurrentVersion\\Run\" /v \"jEdit Server\" /f";
    + try {
    + Process process = Runtime.getRuntime().exec(dosCommand);
    + BufferedReader r_in = new BufferedReader(new InputStreamReader(process.getInputStream()));
    + if(r_in.readLine()!=null){
    + offAutoStart.setText(jEdit.getProperty("tray.offAutoStartoff.label"));
    + }
    + process.destroy();
    +
    + } catch (IOException eexq) {
    + eexq.printStackTrace();
    + }
    + }
    + }else{
    + int result= JOptionPane.showConfirmDialog (null, "Would You Like to turn on autostart?","Warning",JOptionPane.YES_NO_OPTION);
    + if(result == JOptionPane.YES_OPTION){
    + String path = JEditSwingTrayIcon.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    + String decodedPath="C:\\Program Files\\jEdit\\jedit.exe";
    + try {
    + decodedPath = URLDecoder.decode(path, "UTF-8");
    + } catch (UnsupportedEncodingException exuex) {
    + Logger.getLogger(JEditSwingTrayIcon.class.getName()).log(Level.SEVERE, null, exuex);
    + }
    + if(decodedPath.charAt(0)=='/'){
    + decodedPath=decodedPath.substring(1);
    + }
    + decodedPath=decodedPath.replaceAll("/", "\\\\");
    + int indexer=decodedPath.length()-1;
    + while(decodedPath.charAt(indexer)!='\\'){
    + indexer--;
    +
    + }
    + indexer++;
    + decodedPath=decodedPath.substring(0, indexer);
    + String dosCommand = "reg add \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\"
    + + "CurrentVersion\\Run\" /v \"jEdit Server\" /t \"REG_SZ\" /d \""+decodedPath
    + +"jedit.exe -background -nogui --l4j-dont-wait\" /f";
    + try {
    + final Process process = Runtime.getRuntime().exec(dosCommand);
    + BufferedReader r_in = new BufferedReader(new InputStreamReader(process.getInputStream()));
    + BufferedReader r_err = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    + String outS;
    + while((outS=r_in.readLine())!=null){
    + offAutoStart.setText(jEdit.getProperty("tray.offAutoStarton.label"));
    + }
    +
    + } catch (IOException exio) {
    + exio.printStackTrace();
    +
    + }
    + }
    +
    + }
    } else if (e.getSource() == exitItem)
    {
    jEdit.exit(null, true);
    diff --git a/org/jedit/localization/jedit_cs.props b/org/jedit/localization/jedit_cs.props
    index 0040992..3145e61 100644
    --- a/org/jedit/localization/jedit_cs.props
    +++ b/org/jedit/localization/jedit_cs.props
    @@ -1,4 +1,4 @@
    -###
    +###
    ### jEdit user interface definitions,
    ### :tabSize=8:indentSize=8:noTabs=false:
    ### :folding=explicit:collapseFolds=1:
    @@ -77,6 +77,8 @@ view.context.customize=Upravit toto menu...
    #{{{ System tray menu
    tray.newView.label=NovĂ˝ pohled
    tray.newPlainView.label=NovĂ˝ prostĂ˝ pohled
    +tray.offAutoStarton.label=Ukoncit autospusteni
    +tray.offAutoStartoff.label=Zapnout autospusteni
    tray.exit.label=UkonÄŤit
    #}}}

    diff --git a/org/jedit/localization/jedit_en.props b/org/jedit/localization/jedit_en.props
    index 4a6e71a..41bb8f5 100644
    --- a/org/jedit/localization/jedit_en.props
    +++ b/org/jedit/localization/jedit_en.props
    @@ -78,6 +78,8 @@ view.context.customize=Customize This Menu...
    tray.newView.label=New view
    tray.newPlainView.label=New plain view
    tray.exit.label=Exit
    +tray.offAutoStarton.label=Turn off Autostart
    +tray.offAutoStartoff.label=Turn on Autostart
    #}}}

    #{{{ Menu bar
    diff --git a/org/jedit/localization/jedit_fr.props b/org/jedit/localization/jedit_fr.props
    index eafe2b6..5b43b59 100644
    --- a/org/jedit/localization/jedit_fr.props
    +++ b/org/jedit/localization/jedit_fr.props
    @@ -1,4 +1,4 @@
    -###
    +###
    ### jEdit user interface definitions,
    ### :tabSize=8:indentSize=8:noTabs=false:
    ### :folding=explicit:collapseFolds=1:
    @@ -78,6 +78,8 @@ view.context.customize=Personnaliser ce menu...
    tray.newView.label=Nouvel affichage
    tray.newPlainView.label=Nouvel affichage simple
    tray.exit.label=Fermer
    +tray.offAutoStarton.label=Turn off Autostart
    +tray.offAutoStartoff.label=Turn on Autostart
    #}}}

    #{{{ Menu bar
    diff --git a/org/jedit/localization/jedit_ja.props b/org/jedit/localization/jedit_ja.props
    index b75b9cf..238cfda 100644
    --- a/org/jedit/localization/jedit_ja.props
    +++ b/org/jedit/localization/jedit_ja.props
    @@ -1,4 +1,4 @@
    -###
    +###
    ### jEdit user interface definitions,
    ### :tabSize=8:indentSize=8:noTabs=false:
    ### :folding=explicit:collapseFolds=1:
    @@ -78,6 +78,8 @@ view.context.customize=������をカスタ�イズ...
    tray.newView.label=新規���
    tray.newPlainView.label=新規�������
    tray.exit.label=終了
    +tray.offAutoStarton.label=Turn off Autostart
    +tray.offAutoStartoff.label=Turn on Autostart
    #}}}

    #{{{ Menu bar
    diff --git a/package-files/windows/win32installer.iss b/package-files/windows/win32installer.iss
    index 06ea99c..863aff6 100644
    --- a/package-files/windows/win32installer.iss
    +++ b/package-files/windows/win32installer.iss
    @@ -79,7 +79,7 @@ Name: {userappdata}\Microsoft\Internet Explorer\Quick Launch\jEdit; Filename: {a
    [Languages]
    Name: en; MessagesFile: compiler:Default.isl
    Name: de; MessagesFile: compiler:Languages\German.isl
    -Name: eu; MessagesFile: compiler:Languages\Basque.isl
    +;Name: eu; MessagesFile: compiler:Languages\Basque.isl
    Name: pt_BR; MessagesFile: compiler:Languages\BrazilianPortuguese.isl
    Name: ca; MessagesFile: compiler:Languages\Catalan.isl
    Name: cs; MessagesFile: compiler:Languages\Czech.isl
    @@ -88,14 +88,14 @@ Name: nl; MessagesFile: compiler:Languages\Dutch.isl
    Name: fi; MessagesFile: compiler:Languages\Finnish.isl
    Name: fr; MessagesFile: compiler:Languages\French.isl
    Name: he; MessagesFile: compiler:Languages\Hebrew.isl
    -Name: hu; MessagesFile: compiler:Languages\Hungarian.isl
    +;Name: hu; MessagesFile: compiler:Languages\Hungarian.isl
    Name: it; MessagesFile: compiler:Languages\Italian.isl
    Name: ja; MessagesFile: compiler:Languages\Japanese.isl
    Name: no; MessagesFile: compiler:Languages\Norwegian.isl
    Name: pl; MessagesFile: compiler:Languages\Polish.isl
    Name: pt; MessagesFile: compiler:Languages\Portuguese.isl
    Name: ru; MessagesFile: compiler:Languages\Russian.isl
    -Name: sk; MessagesFile: compiler:Languages\Slovak.isl
    +;Name: sk; MessagesFile: compiler:Languages\Slovak.isl
    Name: sl; MessagesFile: compiler:Languages\Slovenian.isl
    Name: es; MessagesFile: compiler:Languages\Spanish.isl

    @@ -130,7 +130,7 @@ Root: HKCR; Subkey: *\Shell; Flags: uninsdeletekeyifempty
    Root: HKCR; Subkey: *\Shell\{cm:OpenWithProgram,jEdit}; Flags: uninsdeletekey
    Root: HKCR; Subkey: *\Shell\{cm:OpenWithProgram,jEdit}\Command; ValueType: string; ValueData: """{app}\jedit.exe"" ""%1"""
    Root: HKCR; Subkey: *\Shell\{cm:OpenWithProgram,jEdit}; ValueName: Icon; ValueType: string; ValueData: "{app}\jedit.exe"
    -Root: HKLM; Subkey: SOFTWARE\Microsoft\Windows\CurrentVersion\Run; ValueType: string; ValueName: jEdit Server; ValueData: """{app}\jedit.exe"" -background -nogui --l4j-dont-wait"; Flags: uninsdeletevalue; Tasks: autostartserver
    +Root: HKCU; Subkey: SOFTWARE\Microsoft\Windows\CurrentVersion\Run; ValueType: string; ValueName: jEdit Server; ValueData: """{app}\jedit.exe"" -background -nogui --l4j-dont-wait"; Flags: uninsdeletevalue; Tasks: autostartserver

    [Run]
    Filename: {app}\jedit.exe; Description: {cm:ViewFile,README}; Parameters: "--l4j-dont-wait -nosettings ""{app}\doc\README.txt"""; WorkingDir: {app}; Flags: nowait postinstall skipifsilent
    --
    1.8.0.msysgit.0

     
  • Alan Ezust
    Alan Ezust
    2013-05-21

    For logging errors, it is better to use the jEdit "Log" class rather than the swing logger API.
    We don't use the swing logger class anywhere else in the code.

     
  • Alan Ezust
    Alan Ezust
    2013-08-10

    • assigned_to: nobody --> ezust
     
  • Alan Ezust
    Alan Ezust
    2013-08-10

    Here is one more comment about your patch:

    Regarding this part:
    + String system=System.getProperty("os.name");
    + system=system.toUpperCase();
    + if(system.startsWith("WINDOWS")){
    + isWindows=true;
    it is better to use OperatingSystem.isWindows()

     
    Last edit: Alan Ezust 2014-04-26
  • Alan Ezust
    Alan Ezust
    2014-04-26

    Also, why are there changes to win32installer.iss? It seems 3 lines are now commented out with a ; but I don't understand why.

     
  • Alan Ezust
    Alan Ezust
    2014-04-26

    • status: open --> pending-rejected
    • Group: -->