public CommandResult CopyToFile() { if (GEnv.TextSelection.IsEmpty) { return(CommandResult.Ignored); } SaveFileDialog dlg = new SaveFileDialog(); dlg.InitialDirectory = GApp.Options.DefaultFileDir; dlg.Title = GApp.Strings.GetString("Util.DestinationToSave"); dlg.Filter = "All Files(*.*)|*.*"; string selectedtext = GEnv.TextSelection.GetSelectedText(); //このファイル選択ダイアログを閉じた直後にOnGotFocusが発生し、テキスト選択がクリアされることがあるので事前に取得しておく if (GCUtil.ShowModalDialog(_frame, dlg) == DialogResult.OK) { GApp.Options.DefaultFileDir = GUtil.FileToDir(dlg.FileName); try { StreamWriter wr = new StreamWriter(new FileStream(dlg.FileName, FileMode.Create), Encoding.Default); wr.Write(selectedtext); wr.Close(); return(CommandResult.Success); } catch (Exception ex) { GUtil.Warning(GApp.Frame, ex.Message); return(CommandResult.Failed); } } else { return(CommandResult.Cancelled); } }
public CommandResult SaveShortCut() { //コネクションがあればファイルを尋ねる SaveFileDialog dlg = new SaveFileDialog(); dlg.Title = GApp.Strings.GetString("Util.SaveShortcut"); dlg.InitialDirectory = GApp.Options.DefaultFileDir; dlg.DefaultExt = "gts"; dlg.AddExtension = true; dlg.Filter = "Terminal Shortcut(*.gts)|*.gts"; if (GCUtil.ShowModalDialog(GApp.Frame, dlg) == DialogResult.OK) { try { ConfigNode cn = new ConfigNode("poderosa-shortcut"); _connection.Param.Export(cn); XmlWriter wr = XMLUtil.CreateDefaultWriter(dlg.FileName); DOMNodeConverter.Write(wr, cn); wr.WriteEndDocument(); wr.Close(); GApp.Options.DefaultFileDir = GUtil.FileToDir(dlg.FileName); return(CommandResult.Success); } catch (Exception ex) { MessageBox.Show(GEnv.Frame, ex.Message, GApp.Strings.GetString("Message.SaveError"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(CommandResult.Failed); } } else { return(CommandResult.Cancelled); } }
public CommandResult PasteFromFile() { OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = GApp.Options.DefaultFileDir; dlg.Title = GApp.Strings.GetString("Util.SourceToLoad"); dlg.Filter = "All Files(*.*)|*.*"; ConnectionTag ct = GEnv.Connections.FindTag(_connection); if (ct.ModalTerminalTask != null) { return(CommandResult.Denied); } if (GCUtil.ShowModalDialog(GApp.Frame, dlg) == DialogResult.OK) { GApp.Options.DefaultFileDir = GUtil.FileToDir(dlg.FileName); try { StreamReader re = new StreamReader(new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read), _connection.Param.EncodingProfile.Encoding); if (new FileInfo(dlg.FileName).Length > 0x1000) //4KB以上は非同期 { SendingLargeText dlg2 = new SendingLargeText(new PasteProcessor(ct, re)); re.Close(); if (GCUtil.ShowModalDialog(GApp.Frame, dlg2) == DialogResult.OK) { return(CommandResult.Success); } else { return(CommandResult.Cancelled); } } else { PasteProcessor p = new PasteProcessor(ct, re); p.Perform(); re.Close(); } //GEnv.Frame.StatusBar.IndicateSendData(); return(CommandResult.Success); } catch (Exception ex) { GUtil.Warning(GEnv.Frame, ex.Message); return(CommandResult.Failed); } } else { return(CommandResult.Cancelled); } }
public CommandResult OpenShortCutWithDialog() { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = GApp.Strings.GetString("Util.OpenShortcutFile"); dlg.Multiselect = false; dlg.InitialDirectory = GApp.Options.DefaultFileDir; dlg.DefaultExt = "gts"; dlg.AddExtension = true; dlg.Filter = "Terminal Shortcut(*.gts)|*.gts|All Files(*.*)|*.*"; if (GCUtil.ShowModalDialog(_frame, dlg) == DialogResult.OK) { GApp.Options.DefaultFileDir = GUtil.FileToDir(dlg.FileName); return(OpenShortCut(dlg.FileName)); } return(CommandResult.Cancelled); }