groups = new ArrayList<>();
@@ -152,8 +149,7 @@ private static String autoLink(String input) {
if (c == '=') {
continue;
}
- }
- else if (c == '>') {
+ } else if (c == '>') {
continue;
}
}
diff --git a/src/cn/ieclipse/smartim/common/Notifications.java b/src/cn/ieclipse/smartim/common/Notifications.java
index 1389201..02836a5 100644
--- a/src/cn/ieclipse/smartim/common/Notifications.java
+++ b/src/cn/ieclipse/smartim/common/Notifications.java
@@ -6,7 +6,6 @@
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationType;
-import com.intellij.openapi.ui.popup.Balloon;
/**
* Created by Jamling on 2017/10/31.
diff --git a/src/cn/ieclipse/smartim/common/WrapHTMLFactory.java b/src/cn/ieclipse/smartim/common/WrapHTMLFactory.java
index 9661799..9f06da8 100644
--- a/src/cn/ieclipse/smartim/common/WrapHTMLFactory.java
+++ b/src/cn/ieclipse/smartim/common/WrapHTMLFactory.java
@@ -15,7 +15,7 @@
*/
package cn.ieclipse.smartim.common;
-import javax.swing.SizeRequirements;
+import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.Element;
import javax.swing.text.GlyphView;
diff --git a/src/cn/ieclipse/smartim/console/IMChatConsole.java b/src/cn/ieclipse/smartim/console/IMChatConsole.java
index c4d56b6..b3d589d 100644
--- a/src/cn/ieclipse/smartim/console/IMChatConsole.java
+++ b/src/cn/ieclipse/smartim/console/IMChatConsole.java
@@ -1,19 +1,18 @@
package cn.ieclipse.smartim.console;
-import cn.ieclipse.smartim.AbstractSmartClient;
import cn.ieclipse.smartim.IMHistoryManager;
import cn.ieclipse.smartim.SmartClient;
-import cn.ieclipse.smartim.actions.ScrollLockAction;
-import cn.ieclipse.smartim.actions.SendFileAction;
-import cn.ieclipse.smartim.actions.SendImageAction;
+import cn.ieclipse.smartim.actions.*;
import cn.ieclipse.smartim.common.IMUtils;
import cn.ieclipse.smartim.common.LOG;
import cn.ieclipse.smartim.common.WrapHTMLFactory;
import cn.ieclipse.smartim.idea.EditorUtils;
import cn.ieclipse.smartim.model.IContact;
+import cn.ieclipse.smartim.model.impl.AbstractContact;
import cn.ieclipse.smartim.settings.SmartIMSettings;
import cn.ieclipse.smartim.views.IMPanel;
import cn.ieclipse.util.BareBonesBrowserLaunch;
+import cn.ieclipse.util.EncodeUtils;
import cn.ieclipse.util.StringUtils;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionToolbar;
@@ -52,10 +51,13 @@ public IMChatConsole(IContact target, IMPanel imPanel) {
this.uin = target.getUin();
this.imPanel = imPanel;
initUI();
- loadHistories();
+ new Thread() {
+ public void run() {
+ loadHistories();
+ }
+ }.start();
}
-
public SmartClient getClient() {
return imPanel.getClient();
}
@@ -65,7 +67,7 @@ public SmartClient getClient() {
public abstract void post(final String msg);
public String getHistoryFile() {
- return uin;
+ return EncodeUtils.getMd5(contact.getName());
}
public String getUin() {
@@ -96,6 +98,17 @@ public void loadHistories() {
}
}
+ public void clearHistories() {
+ IMHistoryManager.getInstance().clear(getClient(), getHistoryFile());
+ historyWidget.setText("");
+ }
+
+ public void clearUnread() {
+ if (contact != null && contact instanceof AbstractContact) {
+ ((AbstractContact) contact).clearUnRead();
+ }
+ }
+
public boolean hideMyInput() {
return false;
}
@@ -121,7 +134,7 @@ public void send(final String input) {
String msg = IMUtils.formatHtmlMyMsg(System.currentTimeMillis(), name, input);
if (!hideMyInput()) {
insertDocument(msg);
- IMHistoryManager.getInstance().save(client, getUin(), msg);
+ IMHistoryManager.getInstance().save(client, getHistoryFile(), msg);
}
new Thread() {
@Override
@@ -141,6 +154,7 @@ public void run() {
LOG.error("发送文件失败 : " + e);
LOG.sendNotification("发送文件失败",
String.format("文件:%s(%s)", file, e.getMessage()));
+ error(String.format("发送文件失败:%s(%s)", file, e.getMessage()));
} finally {
uploadLock = false;
}
@@ -157,12 +171,7 @@ public void error(Throwable e) {
}
public void error(final String msg) {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- insertDocument(String.format("
%s
", msg));
- }
- });
+ insertDocument(String.format("
%s
", msg));
}
private void createUIComponents() {
@@ -170,12 +179,7 @@ private void createUIComponents() {
}
public void write(final String msg) {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- insertDocument(msg);
- }
- });
+ insertDocument(msg);
}
protected JBSplitter splitter;
@@ -236,7 +240,10 @@ protected void initToolBar() {
protected void initToolBar(DefaultActionGroup group) {
group.add(new SendImageAction(this));
group.add(new SendFileAction(this));
+ // group.add(new SendProjectFileAction(this));
+ group.add(new SendProjectFileAction2(this));
group.add(new ScrollLockAction(this));
+ group.add(new ClearHistoryAction(this));
}
public class SendAction extends AbstractAction {
@@ -329,20 +336,25 @@ protected boolean hyperlinkActivated(String desc) {
return false;
}
- protected void insertDocument(String msg) {
- try {
- HTMLEditorKit kit = (HTMLEditorKit) historyWidget.getEditorKit();
- HTMLDocument doc = (HTMLDocument) historyWidget.getDocument();
- // historyWidget.getDocument().insertString(len - offset,
- // trimMsg(msg), null);
- // Element root = doc.getDefaultRootElement();
- // Element body = root.getElement(1);
- // doc.insertBeforeEnd(body, msg);
- int pos = historyWidget.getCaretPosition();
- kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
- historyWidget.setCaretPosition(scrollLock ? pos : doc.getLength());
- } catch (Exception e) {
- e.printStackTrace();
- }
+ protected void insertDocument(final String msg) {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ HTMLEditorKit kit = (HTMLEditorKit) historyWidget.getEditorKit();
+ HTMLDocument doc = (HTMLDocument) historyWidget.getDocument();
+ // historyWidget.getDocument().insertString(len - offset,
+ // trimMsg(msg), null);
+ // Element root = doc.getDefaultRootElement();
+ // Element body = root.getElement(1);
+ // doc.insertBeforeEnd(body, msg);
+ int pos = historyWidget.getCaretPosition();
+ kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
+ historyWidget.setCaretPosition(scrollLock ? pos : doc.getLength());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
}
}
diff --git a/src/cn/ieclipse/smartim/console/MockChatConsole.java b/src/cn/ieclipse/smartim/console/MockChatConsole.java
index a190783..f8a4862 100644
--- a/src/cn/ieclipse/smartim/console/MockChatConsole.java
+++ b/src/cn/ieclipse/smartim/console/MockChatConsole.java
@@ -35,9 +35,13 @@ public void loadHistories() {
@Override
public void send(String input) {
- String msg = IMUtils.formatHtmlMyMsg(System.currentTimeMillis(), "Me", input);
+ String msg = IMUtils.formatHtmlMyMsg(System.currentTimeMillis(), "Me",
+ input);
if (!hideMyInput()) {
insertDocument(msg);
}
+ String msg2 = IMUtils.formatHtmlMsg(false, false,
+ System.currentTimeMillis(), "Me", input);
+ write(msg2);
}
}
diff --git a/src/cn/ieclipse/smartim/dialogs/BroadcastDialog.java b/src/cn/ieclipse/smartim/dialogs/BroadcastDialog.java
new file mode 100644
index 0000000..d45734c
--- /dev/null
+++ b/src/cn/ieclipse/smartim/dialogs/BroadcastDialog.java
@@ -0,0 +1,137 @@
+package cn.ieclipse.smartim.dialogs;
+
+import cn.ieclipse.smartim.common.IMUtils;
+import cn.ieclipse.smartim.views.CheckBoxTreeCellRenderer;
+import cn.ieclipse.smartim.views.CheckBoxTreeNodeSelectionListener;
+import cn.ieclipse.smartim.views.IMPanel;
+
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BroadcastDialog extends JDialog implements ActionListener {
+
+ private final JPanel contentPanel = new JPanel();
+ protected JTextArea text;
+ protected JTabbedPane tabHost;
+ protected IMPanel imPanel;
+
+ /**
+ * Launch the application.
+ */
+ public static void main(String[] args) {
+ try {
+ BroadcastDialog dialog = new BroadcastDialog(null);
+ dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+ dialog.setVisible(true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Create the dialog.
+ */
+ public BroadcastDialog(IMPanel imPanel) {
+ this.imPanel = imPanel;
+ setLocationRelativeTo(null);
+ setSize(400, 300);
+ getContentPane().setLayout(new BorderLayout());
+ contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
+ getContentPane().add(contentPanel, BorderLayout.CENTER);
+ contentPanel.setLayout(new BorderLayout(0, 0));
+ {
+ text = new JTextArea();
+ text.setRows(4);
+ text.setLineWrap(true);
+ JScrollPane scrollPane = new JScrollPane(text);
+ contentPanel.add(scrollPane, BorderLayout.NORTH);
+ }
+ {
+ tabHost = new JTabbedPane(JTabbedPane.TOP);
+ contentPanel.add(tabHost, BorderLayout.CENTER);
+ }
+ {
+ JPanel buttonPane = new JPanel();
+ buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
+ getContentPane().add(buttonPane, BorderLayout.SOUTH);
+ {
+ JButton okButton = new JButton("OK");
+ okButton.setActionCommand("OK");
+ buttonPane.add(okButton);
+ getRootPane().setDefaultButton(okButton);
+ okButton.addActionListener(this);
+ }
+ {
+ JButton cancelButton = new JButton("Cancel");
+ cancelButton.setActionCommand("Cancel");
+ buttonPane.add(cancelButton);
+ cancelButton.addActionListener(this);
+ }
+ }
+ initTab(tabHost);
+ }
+
+ protected void initTab(JTabbedPane host) {
+
+ }
+
+ protected void initTrees(JTree... trees) {
+ for (JTree tree : trees) {
+ if (tree != null) {
+ initTree(tree);
+ }
+ }
+ }
+
+ protected void initTree(JTree tree) {
+ tree.setCellRenderer(new CheckBoxTreeCellRenderer());
+ tree.setShowsRootHandles(false);
+ tree.setRootVisible(false);
+ tree.addMouseListener(new CheckBoxTreeNodeSelectionListener());
+ }
+
+ public void updateTrees(JTree... trees) {
+ for (JTree tree : trees) {
+ if (tree != null) {
+ tree.updateUI();
+ }
+ }
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if ("OK".equals(e.getActionCommand())) {
+ okPressed();
+ }
+ else if ("Cancel".equals(e.getActionCommand())) {
+
+ }
+ dispose();
+ }
+
+ protected void okPressed() {
+ final String text = this.text.getText().trim();
+ if (IMUtils.isEmpty(text)) {
+ return;
+ }
+ final List