Exemplo n.º 1
0
        private void resetColor(tabbutton newbutton)
        {
            int count = -1;

            // Reset Color of tab
            foreach (tabbutton item in WindowsFormsApp5.frame_home.buttonList)
            {
                count = count + 1;
                if (item.Name == newbutton.Name)
                {
                    newbutton.BackColor   = System.Drawing.Color.FromArgb(((int)(((byte)(173)))), ((int)(((byte)(216)))), ((int)(((byte)(107)))));;
                    newbutton.Normalcolor = System.Drawing.Color.FromArgb(((int)(((byte)(173)))), ((int)(((byte)(216)))), ((int)(((byte)(107)))));
                    frame_home.focusedtab = count;
                    continue;
                }
                item.BackColor   = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(44)))), ((int)(((byte)(52)))));;
                item.Normalcolor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(44)))), ((int)(((byte)(52)))));
            }
        }
Exemplo n.º 2
0
        private bool Save(tabbutton item, fctb_box fctb)
        {
            if (item.fileLocation == null)
            {
                sfdMain.FileName = item.Text;
                if (sfdMain.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return(false);
                }
                item.fileLocation = sfdMain.FileName;
                string filename = Path.GetFileName(item.fileLocation);
                if (filename.Length > 3 && filename.Substring(filename.Length - 3, 3) == ".py")
                {
                    filename = filename.Substring(0, filename.Length - 3);
                }
                item.Text = filename;
            }

            try
            {
                // Replace 4 spaces with Tab while saving file
                // File.WriteAllText(item.fileLocation as string, fctb.Text.Replace("    ","\t"));
                File.WriteAllText(item.fileLocation as string, fctb.Text);
                fctb.IsChanged = false;
                item.openedTab = true;
            }
            catch (Exception ex)
            {
                item.fileLocation = null;
                item.Text         = "Untitled";
                if (MessageBox.Show(ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    return(Save(item, fctb));
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        public void newTab(string filename, int tabIndex)
        {
            String button_text  = "untitled";
            String fileLocation = null;

            if (filename != null)
            {
                fileLocation = filename;
                filename     = Path.GetFileName(filename);
                if (filename.Length > 3 && filename.Substring(filename.Length - 3, 3) == ".py")
                {
                    filename = filename.Substring(0, filename.Length - 3);
                }
                button_text = filename;

                if (tabIndex != -1)
                {
                    tabbutton temp_button = buttonList[tabIndex];
                    temp_button.openedTab = true;
                    temp_button.Text      = button_text;
                    int ind = getFctbBox(temp_button.Target);
                    fctbList[ind].OpenFile(fileLocation);
                    fctbList[ind].BringToFront();
                    temp_button.fileLocation = fileLocation;
                    buttonList[tabIndex]     = temp_button;
                    resetColor(buttonList[tabIndex]);
                    return;
                }
            }
            incrementcount++;
            tabCount++;
            button_text = "untitled" + incrementcount;
            String button_name = "tab" + incrementcount;
            String fctb_name   = "fctb" + incrementcount;

            fctb_box  fctb_box = new fctb_box();
            tabbutton button   = new tabbutton();

            if (filename != null)
            {
                fctb_box.OpenFile(fileLocation);
                button_text      = filename;
                button.openedTab = true;
            }
            fctb_box.Name = fctb_name;
            fctbList.Add(fctb_box);
            panel_editor.Controls.Add(fctbList[fctbList.Count - 1]);
            fctbList[fctbList.Count - 1].BringToFront();
            if (!panel_editor.Controls.Contains(tabpanel))
            {
                panel_editor.Controls.Add(tabpanel);
            }


            button.Text         = button_text;
            button.Name         = button_name;
            button.Target       = fctb_name;
            button.fileLocation = fileLocation;


            button.Location = new Point((focusedtab + 1) * 320, 0);
            buttonList.Insert(focusedtab + 1, button);
            // update location
            int cnt = -1;

            foreach (tabbutton item in buttonList)
            {
                cnt++;
                if (cnt > focusedtab + 1)
                {
                    item.Location = new Point(item.Location.X + 320, 0);
                }
            }
            tabpanel.Controls.Add(buttonList[focusedtab + 1]);
            resetColor(buttonList[focusedtab + 1]);
            fctbList[focusedtab].Select();
        }
Exemplo n.º 4
0
        protected override void WndProc(ref Message m)
        {
            if (m_aeroEnabled)
            {
                var v = 2;
                DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                MARGINS margins = new MARGINS()
                {
                    bottomHeight = 1,
                    leftWidth    = 0,
                    rightWidth   = 0,
                    topHeight    = 0
                }; DwmExtendFrameIntoClientArea(this.Handle, ref margins);
            }

            if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT)
            {
                m.Result = (IntPtr)HTCAPTION;
            }



            ////////////////////////////////////////////////////////////////////////////////
            ///       IMPORTANT: THIS MESSAGE CODE IS FOR MUTEX USED IN PROGRAM.CS       ///
            ///           DELETING THIS WILL CHANGE HOW MULTIPROCESS IS HANDLED          ///
            ////////////////////////////////////////////////////////////////////////////////



            else if (m.Msg == NativeMethods.WM_COPYDATA)
            {   // Extract the file name
                NativeMethods.COPYDATASTRUCT copyData =
                    (NativeMethods.COPYDATASTRUCT)Marshal.PtrToStructure
                        (m.LParam, typeof(NativeMethods.COPYDATASTRUCT));
                int dataType = (int)copyData.dwData;
                if (dataType == 2)
                {
                    string fileName = Marshal.PtrToStringAnsi(copyData.lpData);
                    if (fileName != null)
                    {
                        open(fileName);
                    }
                    BringWindowToFront();
                }



                else if (dataType == 3)
                {
                    string tabdata = Marshal.PtrToStringAnsi(copyData.lpData);
                    if (tabdata != null)
                    {
                        String[] spearator = { "$" };
                        Int32    count     = 10;
                        String[] strlist   = tabdata.Split(spearator, count,
                                                           StringSplitOptions.RemoveEmptyEntries);

                        if (strlist[1] == Program.guid.ToString())
                        {
                            if (strlist[2] == NativeMethods.DRAG_RECEIVED)
                            {
                                // Write file
                                TabClosedStarted = true;
                                TabCloseTrigger  = true;
                                string tempPath = Path.GetTempPath();


                                tabbutton btn = frame_home.buttonList[int.Parse(strlist[3])];
                                int       ind = frame_home.access_home.getFctbBox(btn.Target);
                                tempPath = Path.Combine(tempPath, "Xpress_editorGarbage.txt");
                                File.WriteAllText(tempPath, frame_home.fctbList[ind].Text);
                                TabClosedStarted = false;

                                // Send data to open file to pid
                                string location = btn.fileLocation;
                                if (location == null)
                                {
                                    location = "null";
                                }
                                string com_data = Program.guid + "$" + strlist[0] + "$" + NativeMethods.DRAG_FINISH + "$" +
                                                  Path.Combine(Path.GetTempPath(), "Xpress_editorGarbage.txt") + "$" + btn.Text + "$" + location + "$" + Convert.ToInt32(fctbList[getFctbBox(btn.Target)].IsChanged);
                                Process[] processes = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
                                foreach (Process p in processes)
                                {
                                    if (p.Id.ToString() == strlist[0])
                                    {
                                        IntPtr windowHandle = p.MainWindowHandle;
                                        NativeMethods.communicate(com_data, windowHandle, NativeMethods.WM_COPYDATA);
                                    }
                                }
                            }
                            else if (strlist[2] == NativeMethods.DRAG_FINISH)
                            {
                                string guid      = strlist[0];
                                string grbg_path = strlist[3];
                                string name      = strlist[4];
                                string location  = strlist[5];
                                bool   ischanged = Convert.ToBoolean(Int32.Parse(strlist[6]));
                                if (location == "null")
                                {
                                    location = null;
                                }
                                int old = buttonList.Count;
                                new Thread(() => threadFun(name, location, ischanged)).Start();
                                Thread.Sleep(100);
                                newTab(grbg_path, -1);
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show(String.Format("Unrecognized data type = {0}.",
                                                  dataType), "SendMessageDemo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (m.Msg == Program.WM_ACTIVATEAPP)
            {
                // Maximizes and bring it to front.
                BringWindowToFront();
            }
            // END
            base.WndProc(ref m);
        }
Exemplo n.º 5
0
        private void test()
        {
            while (move)
            {
                this.Invoke((MethodInvoker) delegate
                {
                    int cnt = -1;
                    foreach (tabbutton item in frame_home.buttonList)
                    {
                        cnt++;

                        // best way to access non static method
                        // make a static variable of class1;
                        // in main class type  variable = this
                        // access the static variable from other class
                        Point pt = frame_home.access_home.PointToClient(Cursor.Position);
                        // Individual window work only for top and left
                        if (pt.X > 0 && pt.Y > 0 && pt.X < frame_home.access_home.getWindowSize().X&& pt.Y < frame_home.access_home.getWindowSize().Y)
                        {
                            if (Decimal.ToInt16((MousePosition.X - frame_home.access_home.getWindowLocation().X) / 320) == cnt)
                            {
                                movedtab = cnt;
                                if (initialtab != cnt)
                                {
                                    item.BackColor   = System.Drawing.Color.FromArgb(((int)(((byte)(216)))), ((int)(((byte)(173)))), ((int)(((byte)(107)))));;
                                    item.Normalcolor = System.Drawing.Color.FromArgb(((int)(((byte)(216)))), ((int)(((byte)(173)))), ((int)(((byte)(107)))));
                                }
                                continue;
                            }
                        }
                        else
                        {
                            movedtab = -1;
                        }
                        item.BackColor   = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(44)))), ((int)(((byte)(52)))));;
                        item.Normalcolor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(44)))), ((int)(((byte)(52)))));
                    }
                });

                Thread.Sleep(100);
            }

            // open cnt tab;

            if (movedtab == -1 && frame_home.buttonList.Count > 1)
            {
                string tempPath = Path.GetTempPath();
                int    ind      = frame_home.access_home.getFctbBox(frame_home.buttonList[initialtab].Target);
                tempPath = Path.Combine(tempPath, "Xpress_editorGarbage.txt");
                File.WriteAllText(tempPath, frame_home.fctbList[ind].Text);

                // If Within .2 sec no message comes Proceed to open it as new window.
                Thread.Sleep(200);
                if (frame_home.TabCloseTrigger == true)
                {
                    while (frame_home.TabClosedStarted)
                    {
                        Thread.Sleep(100);
                    }
                    // force close without saving
                    Invoke((MethodInvoker) delegate
                    {
                        frame_home.access_home.closeTab(true, initialtab);
                    });

                    frame_home.TabCloseTrigger = false;

                    return;
                }


                // Start tab as a new Window
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName = Path.Combine(System.Reflection.Assembly.GetEntryAssembly().Location);
                // Data Location, Name, saved location
                string location = frame_home.buttonList[initialtab].fileLocation;
                if (location == null)
                {
                    location = "null";
                }
                startInfo.Arguments = "\"" + tempPath + "\" \"" + frame_home.buttonList[initialtab].Text + "\" \"" + location + "\" \"" +
                                      Convert.ToInt32(frame_home.fctbList[frame_home.access_home.getFctbBox(frame_home.buttonList[initialtab].Target)].IsChanged) + "\"";
                Process.Start(startInfo);
                Invoke((MethodInvoker) delegate
                {
                    frame_home.access_home.closeTab(true, initialtab);
                });

                return;
            }
            if (movedtab == -1)
            {
                movedtab = initialtab;
            }

            // Adjust tab order
            frame_home.access_home.swapButtonLocation(initialtab, movedtab);
            // make a copy of initialtab at movedtab
            tabbutton tmp = frame_home.buttonList[initialtab];

            if (initialtab - movedtab < 0)
            {
                frame_home.buttonList.Insert(movedtab + 1, tmp);
            }

            else
            {
                frame_home.buttonList.Insert(movedtab, tmp);
            }

            // remove copied tab
            if (initialtab - movedtab < 0)
            {
                frame_home.buttonList.RemoveAt(initialtab);
            }

            else
            {
                frame_home.buttonList.RemoveAt(initialtab + 1);
            }


            // reset spaces
            frame_home.access_home.resetButtonLocation();
            int cnt1 = -1;

            // reset color
            foreach (tabbutton item in WindowsFormsApp5.frame_home.buttonList)
            {
                cnt1++;
                item.BackColor   = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(44)))), ((int)(((byte)(52)))));;
                item.Normalcolor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(44)))), ((int)(((byte)(52)))));
            }

            // highlight moved tab color
            frame_home.buttonList[movedtab].BackColor   = Color.FromArgb(((int)(((byte)(173)))), ((int)(((byte)(216)))), ((int)(((byte)(107)))));;
            frame_home.buttonList[movedtab].Normalcolor = Color.FromArgb(((int)(((byte)(173)))), ((int)(((byte)(216)))), ((int)(((byte)(107)))));
            Invoke((MethodInvoker) delegate
            {
                frame_home.fctbList[frame_home.access_home.getFctbBox(frame_home.buttonList[movedtab].Target)].BringToFront();
            });
        }