Exemplo n.º 1
0
        /// <summary>
        /// A new skin is selected for this note.
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Event arguments</param>
        private void menuNoteSkins_skin_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            foreach (ToolStripMenuItem curtsi in this.menuNoteSkins.DropDownItems)
            {
                curtsi.Checked = false;
            }

            ToolStripMenuItem tsi = null;

            try
            {
                tsi = (ToolStripMenuItem)sender;
            }
            catch (InvalidCastException invcastexc)
            {
                Log.Write(LogType.exception, invcastexc.Message);
                return;
            }

            tsi.Checked      = true;
            this.note.SkinNr = this.notes.GetSkinNr(tsi.Text);
            this.BackColor   = this.notes.GetPrimaryClr(this.note.SkinNr);
            if (this.notes.GetPrimaryTexture(this.note.SkinNr) != null)
            {
                this.BackgroundImageLayout = this.notes.GetPrimaryTextureLayout(this.note.SkinNr);
                this.BackgroundImage       = this.notes.GetPrimaryTexture(this.note.SkinNr);
            }
            else
            {
                this.BackgroundImage = null;
            }

            this.pnlHead.BackColor      = Color.Transparent;
            this.rtbNote.BackColor      = this.notes.GetPrimaryClr(this.note.SkinNr);
            this.lblNoteTitle.ForeColor = this.notes.GetTextClr(this.note.SkinNr);
            Program.Formmanager.FrmManageNotesNeedUpdate = true;
            Program.Formmanager.RefreshFrmManageNotes();
            if (!SyntaxHighlight.KeywordsInitialized)
            {
                SyntaxHighlight.InitHighlighter();
            }

            SyntaxHighlight.CheckSyntaxFull(this.rtbNote, this.note.SkinNr, this.notes);
            if (Settings.HighlightClearLexiconMemory)
            {
                SyntaxHighlight.DeinitHighlighter();
            }

            if (!this.saveWorker.IsBusy)
            {
                this.saveWorker.RunWorkerAsync(this.rtbNote.Rtf);
            }

            Cursor.Current = Cursors.Default;
            Log.Write(LogType.info, "Note " + this.note.Filename + " skin changed to " + this.notes.GetSkinName(this.note.SkinNr));
        }
Exemplo n.º 2
0
        /// <summary>
        /// User pressed the accept note button. Note will now be saved.
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Event arguments</param>
        private void btnAddNote_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.tbTitle.Text))
            {
                this.tbTitle.Text = DateTime.Now.ToString();
            }
            else if (string.IsNullOrEmpty(this.rtbNewNote.Text))
            {
                string newnote_entercontent = Strings.T("Please enter some content.");
                this.rtbNewNote.Text = newnote_entercontent;
                this.rtbNewNote.Focus();
                this.rtbNewNote.SelectAll();
            }
            else
            {
                if (this.note == null)
                {
                    // new note
                    this.note = this.notes.AddNoteDefaultSettings(this.tbTitle.Text, Settings.NotesDefaultSkinnr, this.Location.X, this.Location.Y, this.Width, this.Height, this.rtbNewNote.Rtf, this.rtbNewNote.WordWrap);
                }
                else
                {
                    // editing note, update note
                    this.note.Title = this.tbTitle.Text;
                    if (!xmlUtil.WriteNote(this.note, this.notes.GetSkinName(this.note.SkinNr), this.rtbNewNote.Rtf))
                    {
                        string newnote_exccantwritenote = Strings.T("Could not write note.");
                        throw new ApplicationException(newnote_exccantwritenote);
                    }

                    this.note.Tempcontent = this.rtbNewNote.Rtf;
                    this.note.Wordwarp    = this.rtbNewNote.WordWrap;
                    this.note.CreateForm();
                    this.note.Tempcontent = null;
                }

                if (PluginsManager.EnabledPlugins != null)
                {
                    for (int i = 0; i < PluginsManager.EnabledPlugins.Count; i++)
                    {
                        PluginsManager.EnabledPlugins[i].SavingNote(this.note.Filename, this.rtbNewNote.Rtf, this.note.Title);
                    }
                }

                Program.Formmanager.Frmneweditnoteopen = false;
                SyntaxHighlight.DeinitHighlighter();
                Program.Formmanager.FrmManageNotesNeedUpdate = true;
                Program.Formmanager.RefreshFrmManageNotes();
                this.Close();
                GC.Collect();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Pasting text as note content.
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Event arguments</param>
        private void pastTextToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Clipboard.ContainsText())
            {
                this.rtbNewNote.Text = this.rtbNewNote.Text + Clipboard.GetText();
                if (SyntaxHighlight.KeywordsInitialized)
                {
                    SyntaxHighlight.InitHighlighter();
                }

                SyntaxHighlight.CheckSyntaxFull(this.rtbNewNote, this.GetSkinnr(), this.notes);
            }
            else
            {
                string newnote_emptyclipboard = Strings.T("There is no text on the clipboard.");
                MessageBox.Show(newnote_emptyclipboard);
                Log.Write(LogType.error, newnote_emptyclipboard);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Key is released in rtbNewNote
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Key event arguments</param>
        private void rtbNewNote_KeyUp(object sender, KeyEventArgs e)
        {
            if (!SyntaxHighlight.KeywordsInitialized)
            {
                SyntaxHighlight.InitHighlighter();
            }

            int pos = this.rtbNewNote.SelectionStart;

            if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Enter || e.KeyValue == 190)
            {
                SyntaxHighlight.CheckSyntaxQuick(this.rtbNewNote, this.GetSkinnr(), this.notes);
            }
            else if (e.Control && e.KeyCode == Keys.V)
            {
                SyntaxHighlight.CheckSyntaxFull(this.rtbNewNote, this.GetSkinnr(), this.notes);
            }

            this.rtbNewNote.SelectionStart = pos;
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            /*
             * a suggestion to "protect" against insecure Dynamic Library Loading vulnerability in windows
             * it does not fix it, it makes it harder to exploit insecure dll loading.
             * NoteFly uses APPDATA, TEMP and SystemRoot variables.
             * A subfolder in %APPDATA% is where NoteFly stores it program settings, skins settings, log etc.
             * %TEMP% is needs for logging if appdatafolder is not found.
             * %SystemRoot% is required by the LinkLabel control to work properly.
             * %SystemDrive% is required by NET framework.
             * Plugin developers should not rely on environment variables.
             */
            Program.LoadPlatformOs();
            if (Program.CurrentOS == OS.WINDOWS)
            {
                System.Collections.IDictionary environmentVariables = Environment.GetEnvironmentVariables();
                foreach (System.Collections.DictionaryEntry de in environmentVariables)
                {
                    string currentvariable = de.Key.ToString();
                    if (!currentvariable.Equals("APPDATA", StringComparison.OrdinalIgnoreCase) &&
                        !currentvariable.Equals("SystemRoot", StringComparison.OrdinalIgnoreCase) &&
                        !currentvariable.Equals("SystemDrive", StringComparison.OrdinalIgnoreCase) &&
                        !currentvariable.Equals("TEMP", StringComparison.OrdinalIgnoreCase))
                    {
                        Environment.SetEnvironmentVariable(de.Key.ToString(), null);
                    }
                }

                SetDllDirectory(string.Empty); // removes current working directory as dll search path, but requires kernel32.dll by itself to be looked up.
            }

#if DEBUG
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
#endif

            System.Windows.Forms.Application.ThreadException += new ThreadExceptionEventHandler(UnhanledThreadExceptionHandler);
            System.Windows.Forms.Application.SetUnhandledExceptionMode(System.Windows.Forms.UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(true);
            if (!xmlUtil.LoadSettings())
            {
                // settings.xml does not exist create default settings.xml file
                xmlUtil.WriteDefaultSettings();
                xmlUtil.LoadSettings();
            }

            Program.SetCulture(Settings.ProgramLanguage);
#if DEBUG
            stopwatch.Stop();
            Log.Write(LogType.info, "Settings load time: " + stopwatch.ElapsedMilliseconds + " ms");
#endif
            bool   visualstyle;
            bool   resetpositions;
            bool   newnote = false;
            string newnotetitle;
            string newnotecontent;
            ParserArguments(args, out visualstyle, out resetpositions, out newnote, out newnotetitle, out newnotecontent);
            if (Program.CurrentOS == OS.WINDOWS)
            {
                if (!Settings.ProgramSuspressWarnAdmin)
                {
                    // Security measure, show warning if runned with dangerous administrator rights.
                    System.Security.Principal.WindowsIdentity  identity  = System.Security.Principal.WindowsIdentity.GetCurrent();
                    System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
                    if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
                    {
                        string program_runasadministrator           = Strings.T("You are now running {0} as elevated Administrator.\nWhich is not recommended for security.\nPress OK if your understand the risks of running as administrator and want to hide this message in the future.", Program.AssemblyTitle);
                        string program_runasadministratortitle      = Strings.T("Elevated administrator");
                        System.Windows.Forms.DialogResult dlganswer = System.Windows.Forms.MessageBox.Show(program_runasadministrator, program_runasadministratortitle, System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Warning);
                        if (dlganswer == System.Windows.Forms.DialogResult.OK)
                        {
                            Settings.ProgramSuspressWarnAdmin = true;
                            if (!System.IO.Directory.Exists(Program.AppDataFolder))
                            {
                                Directory.CreateDirectory(Program.AppDataFolder);
                            }

                            xmlUtil.WriteSettings();
                        }
                    }
                }
            }

            if (visualstyle)
            {
                if (Program.CurrentOS == OS.WINDOWS)
                {
                    System.Windows.Forms.Application.EnableVisualStyles();
                }
            }

            bool pluginsupdated = false;
            if (Settings.ProgramPluginsAllEnabled)
            {
                pluginsupdated = PluginsManager.UpdatePluginReplaceFiles();
            }

            if (!pluginsupdated)
            {
                if (Program.CheckInstancesRunning() > 1)
                {
                    string program_alreadyrunning            = Strings.T("{0} is already running.\nLoad another instance? (not recommended)", Program.AssemblyTitle);
                    string program_alreadyrunningtitle       = Strings.T("already running");
                    System.Windows.Forms.DialogResult dlgres = System.Windows.Forms.MessageBox.Show(program_alreadyrunning, program_alreadyrunningtitle, System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation);
                    if (dlgres == System.Windows.Forms.DialogResult.No)
                    {
                        // shutdown by don't continue this Main method
                        return;
                    }
                }
            }

            SyntaxHighlight.InitHighlighter();
            Program.notes = new Notes(resetpositions);
            if (Settings.ProgramPluginsAllEnabled)
            {
                PluginsManager.LoadPlugins();
            }

            Program.notes.ShowNotesVisible();
            formmanager = new FormManager(notes);
            trayicon    = new TrayIcon(formmanager);

            if (!Settings.ProgramFirstrunned)
            {
                // disable the firstrun the next time.
                Settings.ProgramFirstrunned = true;
                Settings.UpdatecheckUseGPG  = false;
                GPGVerifyWrapper gpgverif = new GPGVerifyWrapper();
                if (!string.IsNullOrEmpty(gpgverif.GetGPGPath()) && gpgverif != null)
                {
                    Settings.UpdatecheckGPGPath = gpgverif.GetGPGPath();
                    Settings.UpdatecheckUseGPG  = true;
                }

                gpgverif = null;
                Log.Write(LogType.info, "firstrun occur");
                xmlUtil.WriteSettings();
            }

            if (!Settings.ProgramLastrunVersion.Equals(Program.AssemblyVersionAsString, StringComparison.Ordinal))
            {
                Settings.ProgramLastrunVersion = Program.AssemblyVersionAsString;
                xmlUtil.WriteSettings();
                Log.Write(LogType.info, "Updated ProgramLastrunVersion setting.");

                if (PluginsManager.EnabledPlugins != null)
                {
                    for (int p = 0; p < PluginsManager.EnabledPlugins.Count; p++)
                    {
                        PluginsManager.EnabledPlugins[p].ProgramUpgraded();
                    }
                }
            }

            if (Settings.UpdatecheckEverydays > 0)
            {
                DateTime lastupdate = DateTime.Parse(Settings.UpdatecheckLastDate);
                if (lastupdate.AddDays(Settings.UpdatecheckEverydays) <= DateTime.Now)
                {
                    Settings.UpdatecheckLastDate = UpdateGetLatestVersion();
                    xmlUtil.WriteSettings();
                }
            }

            if (newnote)
            {
                formmanager.OpenNewNote(newnotetitle, newnotecontent);
            }
            else
            {
                newnotetitle   = null;
                newnotecontent = null;
            }

            SyntaxHighlight.DeinitHighlighter();
            System.Windows.Forms.Application.Run();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Set some application wide note settings on this note (fonts, transparency, detect hyperlinks etc.) and
        /// do full syntax check on the note content again.
        /// </summary>
        /// <param name="contentset">Boolean if the note rtf content already set.</param>
        public void UpdateForm(bool contentset)
        {
            if (!contentset)
            {
                this.BackColor = this.notes.GetPrimaryClr(this.note.SkinNr);
                if (this.notes.GetPrimaryTexture(this.note.SkinNr) != null)
                {
                    this.BackgroundImageLayout = this.notes.GetPrimaryTextureLayout(this.note.SkinNr);
                    this.BackgroundImage       = this.notes.GetPrimaryTexture(this.note.SkinNr);
                }
                else
                {
                    this.BackgroundImage = null;
                }

                this.pnlHead.BackColor = Color.Transparent;
                if (!Settings.NotesTransparencyEnabled)
                {
                    this.Opacity = 1.0;
                }

                this.lblNoteTitle.ForeColor = this.notes.GetTextClr(this.note.SkinNr);
                if (Settings.FontTitleStylebold)
                {
                    this.lblNoteTitle.Font = new Font(Settings.FontTitleFamily, Settings.FontTitleSize, FontStyle.Bold);
                }
                else
                {
                    if (Settings.FontTitleSize < 6)
                    {
                        Settings.FontTitleSize = 6;
                    }

                    this.lblNoteTitle.Font = new Font(Settings.FontTitleFamily, Settings.FontTitleSize, FontStyle.Regular);
                }

                this.lblNoteTitle.RightToLeft = (RightToLeft)Settings.FontTextdirection;
                this.RightToLeft             = (RightToLeft)Settings.FontTextdirection;
                this.rtbNote.RightToLeft     = (RightToLeft)Settings.FontTextdirection;
                this.menuSendToEmail.Enabled = Settings.SharingEmailEnabled;
            }
            else
            {
                if (this.lblNoteTitle.Height + this.lblNoteTitle.Location.Y >= this.pnlHead.Height)
                {
                    if (this.lblNoteTitle.Height < Settings.NotesTitlepanelMaxHeight)
                    {
                        this.pnlHead.Height = this.lblNoteTitle.Height;
                    }
                    else
                    {
                        this.pnlHead.Height = Settings.NotesTitlepanelMaxHeight;
                    }
                }
                else
                {
                    this.pnlHead.Height = Settings.NotesTitlepanelMinHeight;
                }

                if (Program.CurrentOS == Program.OS.WINDOWS)
                {
                    this.pnlNote.Location = new Point(0, this.pnlHead.Height - 1);
                    this.pnlNote.Size     = new Size(this.Width, this.Height - this.pnlHead.Height + 1);
                }
                else if (Program.CurrentOS == Program.OS.LINUX)
                {
                    this.pnlNote.Location = new Point(0, this.pnlHead.Height - 1);
                    this.pnlNote.Size     = new Size(this.Width - 6, this.Height - this.pnlHead.Height - 5);
                }

                this.rtbNote.DetectUrls = Settings.HighlightHyperlinks;
                if (!SyntaxHighlight.KeywordsInitialized)
                {
                    SyntaxHighlight.InitHighlighter();
                }

                this.SetFormTooltips();
                this.CreateSkinsMenu(true);
                SyntaxHighlight.CheckSyntaxFull(this.rtbNote, this.note.SkinNr, this.notes);
            }
        }