private void HandleOpenHelp(MenuItem menu, PopupTargetInfo pti)
 {
     using (JaneScript js = WrapperManager.GetJaneScript()) {
         FileInfo fi = new FileInfo(js.ExeName());
         Process.Start(Path.Combine(fi.Directory.FullName, "NJSP_CN.txt"));
     }
 }
 private void HandleFindId(MenuItem mi, PopupTargetInfo pti)
 {
     using (JaneScript js = WrapperManager.GetJaneScript())
     using (ViewItem view = pti.PopupObject.ConvertToConcreteWrapper<ViewItem>())
     using (ThreadItem thread = view.Thread()) {
         if (null == thread) {
             js.Log("通常のスレッドのタブから実行してください。");
             return;
         }
         string id;
         int resNumber = pti.Number;
         if (resNumber > 0) {
             //日付中ID
             using (ResItem res = thread.GetRes(resNumber)) {
                 id = res.Id;
             }
         } else {
             id = pti.InfoText;
         }
         if (string.IsNullOrEmpty(id)) {
             js.Log("IDが取得できませんでした。");
         }
         try {
             this.DoFindId(js, thread, id);
         } catch (Exception ex) {
             js.Log(ex.Message);
             js.Log(ex.StackTrace);
         }
     }
 }
 public void MenuHandler(Converter<ThreadItem, object> selector, MenuItem menu, PopupTargetInfo pti)
 {
     using (ViewList vl = this.js.ViewList())
     using (DisposableList<ViewItem> views = new DisposableList<ViewItem>(vl))
     using (DisposableList<ThreadItem> threads = new DisposableList<ThreadItem>()) {
         //スレッドを抽出
         foreach (ViewItem view in views) {
             ThreadItem t = view.Thread();
             if (t != null) threads.Add(t);
         }
         //スレッドを全部閉じる
         foreach (ThreadItem t in threads) {
             this.js.Close(t);
         }
         //スレッドのソートキー取得
         List<ThreadKeyPair> pairs = new List<ThreadKeyPair>(threads.Count);
         foreach (ThreadItem t in threads) {
             pairs.Add(new ThreadKeyPair() {
                 Thread = t,
                 SortKey = (IComparable)selector(t),
             });
         }
         //スレッドソート
         if (this.ascending) {
             pairs.Sort(this.AscendingComparison);
         } else {
             pairs.Sort(this.DescendingComparison);
         }
         //全部開く
         foreach (var p in pairs) {
             this.js.Open(p.Thread, 0, OpenOperation.Local, true, false, true);
         }
     }
 }
 public void MenuHandler(Predicate<ViewItem> pred, MenuItem menu, PopupTargetInfo pti)
 {
     JaneScript js = base.Host.JaneScript;
     using (ViewList vl = js.ViewList()){
         List<TitleUriPair> pairs = new List<TitleUriPair>();
         using (DisposableList<ViewItem> views = new DisposableList<ViewItem>(vl)) {
             foreach (ViewItem view in views) {
                 if (pred(view)) {
                     using (ThreadItem t = view.Thread()) {
                         pairs.Add(new TitleUriPair() {
                             Title = t.Title,
                             Uri = t.URL,
                         });
                     }
                 }
             }
         }
         if (pairs.Count == 0) {
             js.Log("書き出す対象のスレッドが1つもありませんでした。");
             return;
         }
         string titleShort = "開いているスレの書き出し";
         string titleLong = string.Format("{0}: {1}", titleShort, menu.Caption);
         Util.WriteToNewView(js, titleShort, titleLong, titleLong, false, false, (datout) => {
             datout.WriteText(titleLong);
             datout.WriteBR();
             datout.WriteText(string.Format("{0} スレッド", pairs.Count));
             datout.WriteBR();
             datout.WriteHTML("<hr><br>");
             foreach (TitleUriPair pair in pairs) {
                 datout.WriteHTML(string.Format("{0}<br><a href=\"{1}\">{1}</a><br>", HttpUtility.HtmlEncode(pair.Title), pair.Uri));
             }
         });
     }
 }
 public void MenuHandler(Predicate<ViewItem> pred, MenuItem menu, PopupTargetInfo pti)
 {
     JaneScript js = base.Host.JaneScript;
     using (ViewList vl = js.ViewList())
     using (DisposableList<ViewItem> views = new DisposableList<ViewItem>(vl)) {
         List<ViewItem> closeTargets = new List<ViewItem>();
         foreach (ViewItem view in views) {
             if (pred(view)) {
                 closeTargets.Add(view);
             }
         }
         foreach (ViewItem view in closeTargets) {
             js.Close(view);
         }
     }
 }
 private void HandleGroupBy(MenuItem mi, PopupTargetInfo pti)
 {
     using (JaneScript js = WrapperManager.GetJaneScript())
     using (ViewItem view = pti.PopupObject.ConvertToConcreteWrapper<ViewItem>())
     using (ThreadItem thread = view.Thread()) {
         if (null == thread) {
             js.Log("通常のスレッドのタブから実行してください。");
             return;
         }
         this.DoGroupBy(js, thread);
     }
 }
 private void HandleTop10(MenuItem mi, PopupTargetInfo pti)
 {
     JaneScript js = base.Host.JaneScript;
     using (ViewItem view = pti.PopupObject.ConvertToConcreteWrapper<ViewItem>())
     using (ThreadItem thread = view.Thread()) {
         if (null == thread) {
             js.Log("通常のスレッドのタブから実行してください。");
             return;
         }
         this.DoTop10(js, thread);
     }
 }
 private void WriteLastDat(MenuItem menu, PopupTargetInfo pti)
 {
     JaneScript js = base.Host.JaneScript;
     FileInfo fi = new FileInfo(Path.Combine(new FileInfo(js.ExeName()).Directory.FullName, "last.dat"));
     if (!fi.Exists) {
         js.Log("last.dat が見つかりませんでした");
         return;
     }
     List<string> lines = new List<string>();
     using (Stream stream = fi.OpenRead())
     using (StreamReader reader = new StreamReader(stream, MiscWritePlugin.encShiftJis)) {
         string line;
         while (null != (line = reader.ReadLine())) {
             lines.Add(line);
         }
     }
     Util.WriteToNewView(js, "last.dat", "last.dat の書き出し", "last.dat の書き出し", false, false, (datout) => {
         lines.ForEach(line => {
             datout.WriteHTML(string.Format("<a href=\"{0}\">{0}</a><br>", line));
         });
     });
 }
 private void WriteDraftsTitle(MenuItem menu, PopupTargetInfo pti)
 {
     JaneScript js = base.Host.JaneScript;
     Util.WriteToNewView(js, "草稿一覧", "草稿一覧", "草稿一覧", false, false, (datout) => {
         this.FindAndWriteDrafts(js, datout, false);
     });
 }
 private void WriteClipboardTextAsText(MenuItem menu, PopupTargetInfo pti)
 {
     JaneScript js = base.Host.JaneScript;
     if (!Clipboard.ContainsText()) {
         js.Log("クリップボードにテキストがありませんでした。");
     }
     string text = Clipboard.GetText();
     Util.WriteToNewView(js, "クリップボード", "クリップボードをテキストとして書き出し", "クリップボードをテキストとして書き出し", false, false, (datout) => {
         string[] lines = text.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
         foreach (string line in lines) {
             datout.WriteText(line);
             datout.WriteBR();
         }
     });
 }
 private void WriteClipboardTextAsHtml(MenuItem menu, PopupTargetInfo pti)
 {
     JaneScript js = base.Host.JaneScript;
     if (!Clipboard.ContainsText()) {
         js.Log("クリップボードにテキストがありませんでした。");
     }
     string text = Clipboard.GetText();
     Util.WriteToNewView(js, "last.dat", "クリップボードをHTMLとして書き出し", "クリップボードをHTMLとして書き出し", false, false, (datout) => {
         datout.WriteHTML(text);
     });
 }