Beispiel #1
0
        public void UpdateFromDisc()
        {
            Data = new DirectoryMetaInformation();

            foreach (var directory in Model.EnumerateDirectories(Path))
            {
                Data.TotalWordCount += (new MetaInformation(directory)).Data.TotalWordCount;
            }

            foreach (var file in Model.EnumerateFiles(Path))
            {
                Data.Files.Add(file, new FileMetaInformation
                {
                    WordCount = WordParser.CountWords(System.IO.File.ReadAllText(file))
                });
            }

            Data.TotalWordCount += Data.Files.Select(f => f.Value.WordCount).Sum();
        }
Beispiel #2
0
        private void RefreshWordCountMenuItemHandler(object sender, EventArgs e)
        {
            //InvokeCommand(new Commands.CountWords((ContextNode.Tag as NodeTag).Path));
            var tag = ContextNode.Tag as NodeTag;

            if (tag.NodeType == NodeTag.Type.File)
            {
                // Handle case where document is open?
                tag.WordCount = WordParser.CountWords(System.IO.File.ReadAllText(tag.Path));
            }
            else if (tag.NodeType == NodeTag.Type.Directory)
            {
                // Need to update tags of sub folders.
                var meta = new MetaInformation(tag.Path);
                meta.UpdateFromDisc();
                tag.WordCount = meta.Data.TotalWordCount;
                meta.Save();
            }

            Refresh();
        }
Beispiel #3
0
 public override int CountWords(Model Model, Main View)
 {
     return(WordParser.CountWords(Contents));
 }
Beispiel #4
0
        private void initContextMenu()
        {
            this.miUndo              = new MenuItem("Undo", (s, ea) => Undo());
            this.miRedo              = new MenuItem("Redo", (s, ea) => Redo());
            this.miCut               = new MenuItem("Cut", (s, ea) => Cut());
            this.miCopy              = new MenuItem("Copy", (s, ea) => Copy());
            this.miPaste             = new MenuItem("Paste", (s, ea) => Paste());
            this.miDelete            = new MenuItem("Delete", (s, ea) => ReplaceSelection(""));
            this.miSelectAll         = new MenuItem("Select All", (s, ea) => SelectAll());
            this.miDefineWord        = new MenuItem("Define word");
            this.miDefineWord.Click += (sender, args) =>
            {
                MessageBox.Show(WordAtPoint(ContextPoint));
            };
            this.miThesarus        = new MenuItem("Thesarus");
            this.miThesarus.Click += (sender, args) =>
            {
                var charPosition = CharPositionFromPointClose(ContextPoint.X, ContextPoint.Y);
                if (charPosition == -1)
                {
                    return;
                }

                var lineIndex = LineFromPosition(charPosition);
                var line      = Lines[lineIndex];
                var offset    = charPosition - line.Position;
                var wordStart = FindWordStartBackwards(line.Text, offset);
                var wordEnd   = FindWordEnd(line.Text, offset);
                if (wordEnd <= wordStart)
                {
                    return;
                }
                var word = line.Text.Substring(wordStart, wordEnd - wordStart);

                var suggestions = Thesaurus.Lookup(word);

                if (suggestions != null)
                {
                    var contextMenu = new ContextMenuStrip();
                    foreach (var meaning in suggestions.GetSynonyms())
                    {
                        var item = new ToolStripMenuItem(meaning.Key);
                        item.Click += (s, _a) =>
                        {
                            TargetStart = wordStart + line.Position;
                            TargetEnd   = wordEnd + line.Position;
                            ReplaceTarget(item.Text);
                        };
                        contextMenu.Items.Add(item);
                    }
                    contextMenu.Show(this, PointToClient(Control.MousePosition));
                }
            };

            this.miSelectionWordCount        = new MenuItem("selection word count");
            this.miSelectionWordCount.Click += (sender, args) =>
            {
                System.Windows.Forms.MessageBox.Show(String.Format("{0} words", WordParser.CountWords(SelectedText)), "Word count", System.Windows.Forms.MessageBoxButtons.OK);
            };
            this.miLaunchDistractionFree        = new MenuItem("Distraction Free");
            this.miLaunchDistractionFree.Click += (sender, args) =>
            {
                var distractionFree = new DistractionFreeEditor(LoadedFont, Document);
                distractionFree.ShowDialog();
            };
            this.miCloseDistractionFree        = new MenuItem("Close Distraction Free");
            this.miCloseDistractionFree.Click += (sender, args) =>
            {
                FindForm().Close();
            };
        }