578
626
private void _CommandEcho(CommandModel cd)
580
cd.FrontendManager.AddTextToChat(
582
String.Format("-!- {0}", cd.Parameter)
586
private void _CommandExec(CommandModel cd)
588
if (cd.DataArray.Length >= 2) {
590
System.Diagnostics.Process process = new System.Diagnostics.Process();
591
process.StartInfo.FileName = cd.DataArray[1];
592
if (cd.DataArray.Length >= 3) {
593
process.StartInfo.Arguments = String.Join(" ", cd.DataArray,
594
2, cd.DataArray.Length-2);
596
process.StartInfo.RedirectStandardOutput = true;
597
process.StartInfo.RedirectStandardError = true;
598
process.StartInfo.UseShellExecute = false;
602
output = process.StandardOutput.ReadToEnd();
603
cd.FrontendManager.AddTextToChat(cd.Chat, output);
628
var msg = new MessageBuilder().
630
AppendText(cd.Parameter).
632
cd.FrontendManager.AddMessageToChat(cd.Chat, msg);
609
635
private void _CommandWindow(CommandModel cd)
611
FrontendManager fm = cd.FrontendManager;
612
637
if (cd.DataArray.Length >= 2) {
613
638
var currentChat = ChatViewManager.CurrentChatView;
614
639
if (cd.Parameter.ToLower() == "close") {
684
709
ChatViewManager.CurrentChatView.Clear();
712
void CommandGenerateMessages(CommandModel cd)
715
Int32.TryParse(cd.Parameter, out count);
717
var chat = ChatViewManager.CurrentChatView;
718
var builder = new MessageBuilder();
719
var sender = new ContactModel("msg-tester", "msg-tester", "test", "test");
720
builder.AppendMessage(sender, "time for a messsage generator command so I can test speed and memory usage");
721
var text = builder.CreateText(" *formatted text* ");
723
builder.Append(text);
724
builder.AppendUrl("https://www.smuxi.org/");
726
var msgs = new List<MessageModel>(count);
727
for (var i = 0; i < count; i++) {
728
var msg = builder.ToMessage();
732
DateTime start, stop;
733
start = DateTime.UtcNow;
734
foreach (var msg in msgs) {
735
chat.AddMessage(msg);
737
stop = DateTime.UtcNow;
739
builder = new MessageBuilder();
741
"ChatView.AddMessage(): count: {0} took: {1:0} ms avg: {2:0.00} ms",
743
(stop - start).TotalMilliseconds,
744
(stop - start).TotalMilliseconds / count
746
chat.AddMessage(builder.ToMessage());
748
builder = new MessageBuilder();
750
"ChatView.AddMessage(): MessageTextTagTable.Size: {0}",
751
chat.OutputMessageTextView.MessageTextTagTable.Size
753
chat.AddMessage(builder.ToMessage());
687
756
private void _NickCompletion()
689
// return if we don't support the current ChatView
690
if (!(ChatViewManager.CurrentChatView is GroupChatView) &&
691
!(ChatViewManager.CurrentChatView is PersonChatView)) {
758
// perform completion
695
760
int position = Position;
701
// find the current word
703
temp = text.Substring(0, position);
704
previous_space = temp.LastIndexOf(' ');
705
next_space = text.IndexOf(' ', position);
708
_Logger.Debug("previous_space: "+previous_space);
709
_Logger.Debug("next_space: "+next_space);
712
if (previous_space != -1 && next_space != -1) {
713
// previous and next space exist
714
word = text.Substring(previous_space + 1, next_space - previous_space - 1);
715
} else if (previous_space != -1) {
716
// previous space exist
717
word = text.Substring(previous_space + 1);
718
} else if (next_space != -1) {
720
word = text.Substring(0, next_space);
726
if (word == String.Empty) {
730
bool leadingAt = false;
731
// remove leading @ character
732
if (word.StartsWith("@")) {
733
word = word.Substring(1);
737
// find the possible nickname
739
bool partial_found = false;
742
ChatView view = ChatViewManager.CurrentChatView;
743
if (view is GroupChatView) {
744
GroupChatView cp = (GroupChatView) view;
745
if (Settings.BashStyleCompletion) {
746
IList<string> result = cp.PersonLookupAll(word);
747
if (result == null || result.Count == 0) {
749
} else if (result.Count == 1) {
752
} else if (result.Count >= 2) {
753
string[] nickArray = new string[result.Count];
754
result.CopyTo(nickArray, 0);
755
string nicks = String.Join(" ", nickArray, 1, nickArray.Length - 1);
756
ChatViewManager.CurrentChatView.AddMessage(
757
new MessageModel(String.Format("-!- {0}", nicks))
760
partial_found = true;
764
PersonModel person = cp.PersonLookup(word);
765
if (person != null) {
767
nick = person.IdentityName;
771
var personChat = (PersonChatView) ChatViewManager.CurrentChatView;
772
var personModel = personChat.PersonModel;
773
if (personModel.IdentityName.StartsWith(word,
774
StringComparison.InvariantCultureIgnoreCase)) {
776
nick = personModel.IdentityName;
780
string completionChar = Settings.CompletionCharacter;
781
// add leading @ back and supress completion character
783
word = String.Format("@{0}", word);
784
nick = String.Format("@{0}", nick);
785
completionChar = String.Empty;
789
// put the found nickname in place
790
if (previous_space != -1 && next_space != -1) {
791
// previous and next space exist
792
temp = text.Remove(previous_space + 1, word.Length);
793
temp = temp.Insert(previous_space + 1, nick);
796
Position = previous_space + 1 + nick.Length;
798
Position = previous_space + 2 + nick.Length;
800
} else if (previous_space != -1) {
801
// only previous space exist
802
temp = text.Remove(previous_space + 1, word.Length);
803
temp = temp.Insert(previous_space + 1, nick);
809
Position = previous_space + 2 + nick.Length;
810
} else if (next_space != -1) {
811
// only next space exist
812
temp = text.Remove(0, next_space + 1);
814
Text = nick + " " + temp;
815
Position = nick.Length;
817
Text = String.Format("{0}{1} {2}", nick,
818
completionChar, temp);
819
Position = nick.Length + completionChar.Length + 1;
826
Text = String.Format("{0}{1} ", nick, completionChar);
761
NickCompleter.Complete(ref text, ref position, ChatViewManager.CurrentChatView);
833
766
public virtual void ApplyConfig(UserConfig config)