예제 #1
0
        private void AddReferenceScript(object sender, EventArgs e)
        {
            Microsoft.Win32.OpenFileDialog openFileExplorer = new Microsoft.Win32.OpenFileDialog()
            {
                CheckFileExists  = true,
                CheckPathExists  = true,
                InitialDirectory = @"Documents",
                ShowReadOnly     = true,
                Filter           = "Lua Scripts (*.lua)|*.lua|All files (*.*)|*.*"
            };

            Nullable <bool> result = openFileExplorer.ShowDialog();

            if (result == true)
            {
                string newFilePath = openFileExplorer.FileName;
                int    newFileId   = FileManager.AddReference(newFilePath);

                //OLD	LuaFileView.Items.Add(LHregistry.getSimpleName(newFilePath));
                Label newLabelToAdd = new Label();
                newLabelToAdd.Content = LHregistry.getSimpleName(newFilePath);
                newLabelToAdd.Cursor  = Cursors.Hand;


                styleLabel(newLabelToAdd);
                LuaFileView.Items.Add(newLabelToAdd);
            }
        }
예제 #2
0
        public void Execute(object parameter)
        {
            //MessageBox.Show("HelloWorld");
            string writePath = LHregistry.GetFile(FileManager.currentFileId);

            AdvancedMode.inst.textEditor.Save(writePath);
            AdvancedMode.UnChangedFile(AdvancedMode.Listbox);
        }
예제 #3
0
 /// <summary>
 /// creates new file, returns -1 if failed
 /// </summary>
 /// <param name="filepath">full path of </param>
 /// <returns></returns>
 public static void LoadAllFiles()
 {
     string[] filenames = LHregistry.GetAllFilenames();
     int[]    fileids   = LHregistry.GetAllFileIds();
     for (int i = 0; i < fileids.Length; i++)
     {
         files[fileids[i]] = LHregistry.GetFile(fileids[i]);
     }
 }
예제 #4
0
        public AdvancedMode()
        {
            InitializeComponent();

            LuaFileView.SelectionChanged += LuaFileView_SelectionChanged;
            FileManager.LoadAllFiles();

            inst      = this;
            Focusable = true;

            StartupValues val = LHregistry.GetStartupValues();

            //SimpleMode.LastFileOpened = val.LastSimpleFileSelected;
            textEditor.FontSize = val.StartFontSize;
            textEditor.Text     = "function Start()\n	print(\"preview\")\nend\n\n\n\n\n\n\n\n";
            LoadFileFromId(val.StartupFileId);

            textEditor.InputBindings.Add(
                new InputBinding(new SaveCommand(),
                                 new KeyGesture(Key.S, ModifierKeys.Control)
                                 ));
            textEditor.InputBindings.Add(
                new InputBinding(new LineToggleCommand(),
                                 new KeyGesture(Key.L, ModifierKeys.Control)
                                 ));
            textEditor.ShowLineNumbers = Convert.ToBoolean(val.ShowLineNumbers);

            //set file view to the listbox
            Listbox = LuaFileView;
            StyleLuaListbox();

            //get all the filenames from registry
            int len = LHregistry.GetAllFilenames().Length;

            for (int i = 0; i < len; i++)
            {
                Label  txtbox    = new Label();
                string wholePath = LHregistry.GetAllFilenames()[i];
                txtbox.Content = LHregistry.getSimpleName(wholePath);

                styleLabel(txtbox);
                txtbox.Foreground = white;
                txtbox.Background = transparent;

                LuaFileView.Items.Add(txtbox);
            }

            BypassTextChangedEvent = true;

            //Alle icoontjes
            PlusIcon.Source   = ImageSourceFromBitmap(LeHandUI.Properties.Resources.PALE_GREEN_AddIcon64x64);
            DeleteIcon.Source = ImageSourceFromBitmap(LeHandUI.Properties.Resources.WASHED_OUT_RED_DeleteIcon64x64);
            //RefreshIcon.Source = ImageSourceFromBitmap(LeHandUI.Properties.Resources.AQUA_RefreshIcon64x64);
            //AddReferenceIcon.Source = ImageSourceFromBitmap(LeHandUI.Properties.Resources.AddReference16x16);
            SaveIcon.Source    = ImageSourceFromBitmap(LeHandUI.Properties.Resources.SaveScript64x64);
            RunPrgmIcon.Source = ImageSourceFromBitmap(LeHandUI.Properties.Resources.StartScript64x64);
        }
예제 #5
0
        public static void SaveAll()
        {
            for (int i = 0; i < FileManager.isFileNotSaved.Length; i++)
            {
                if (FileManager.isFileNotSaved[i])
                {
                    File.WriteAllText(LHregistry.GetFile(i), FileCache[i]);
                }
            }

            AdvancedMode.inst.SaveTextEditor();
        }
예제 #6
0
 public static int AddReference(string filepath)
 {
     for (int i = 0; i < 50; i++)
     {
         if (files[i] == null)
         {
             //open file
             files[i] = filepath;
             LHregistry.SetFile(filepath, i);
             return(i);
         }
     }
     return(-1);
 }
예제 #7
0
        private void SaveScript(object sender, EventArgs e)
        {
            string writePath = LHregistry.GetFile(FileManager.currentFileId);

            try
            {
                textEditor.Save(writePath);
            }
            catch (System.ArgumentException)
            { Debug.WriteLine("Caught Argument Exception error, propably that the file can't be empty string, so yeah..."); }

            UnChangedFile(Listbox);
            return;
        }
예제 #8
0
 public static string[] FileNames()
 {
     if (MainWindow.Directory == null || !Directory.Exists(MainWindow.Directory + "Files"))
     {
         System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory);
         Registry.CurrentUser.OpenSubKey("Software\\LeHand", true).SetValue("Dir", AppDomain.CurrentDomain.BaseDirectory);
         MainWindow.Directory = AppDomain.CurrentDomain.BaseDirectory;
     }
     string[] outstr = Directory.GetFiles(MainWindow.Directory + "\\Files");
     for (int i = 0; i < outstr.Length; i++)
     {
         outstr[i] = LHregistry.getSimpleName(outstr[i]);
         outstr[i] = outstr[i].Split('.')[0];
     }
     return(outstr);
 }
예제 #9
0
        private void RunLuaScript(object sender, EventArgs e)
        {
            if (FileManager.currentFileId < 0)
            {
                return;
            }
            //check if files are saved
            bool unsavedFiles = false;

            for (int i = 0; i < FileManager.isFileNotSaved.Length; i++)
            {
                if (FileManager.isFileNotSaved[i])
                {
                    unsavedFiles = true;
                    break;
                }
            }
            if (unsavedFiles)
            {
                MessageBoxResult res = CustomMessageBox.ShowYesNoCancel(
                    "There are unsaved files, do you want to save all files?",
                    "Unsaved Files",
                    "Yes", "No", "Cancel", MessageBoxImage.Exclamation
                    );
                if (res == MessageBoxResult.Yes)
                {
                    string writePath = LHregistry.GetFile(FileManager.currentFileId);
                    textEditor.Save(writePath);
                    UnChangedFile(Listbox);
                }
                if (res == MessageBoxResult.Cancel)
                {
                    return;
                }
            }
            //load and run lua script

            Communicator.load(FileManager.files[FileManager.currentFileId]);
            Communicator.start();
            //start monitoring
            Startwindow sw = new Startwindow();

            sw.Show();

            LuaFileView.Items.Refresh();
            return;
        }
예제 #10
0
        /*public static int Addfile(string filepath)
         * {
         *  for(int i = 0; i < 50; i++)
         *  {
         *      if (files[i] == null) {
         *          //open file
         *          //string[] pathparts = filepath.Split('\\');
         *          //string newFilePath = ".\\Resources\\LuaFiles\\" + pathparts[(pathparts.Length - 1)];
         *          //files[i] = File.Create(newFilePath);
         *          //LHregistry.SetFile(newFilePath, i);
         *          return i;
         *      }
         *  }
         *  return -1;
         * }*/

        public static string LoadFile(int id)
        {
            string fileContents = "";

            //check if file is cached
            if (!isFileNotSaved[id] && files[id] != null)
            {
                //load new file
                byte[] cont = new byte[files[id].Length];
                if (files[id] != null)
                {
                    if (File.Exists(LHregistry.GetFile(id)))
                    {
                        FileStream   stream = File.OpenRead(LHregistry.GetFile(id));
                        StreamReader reader = new StreamReader(stream);
                        fileContents = reader.ReadToEnd();
                        reader.Close();
                        stream.Close();


                        isFileNotSaved[id] = false;
                    }
                    else
                    {
                        var res = MessageBox.Show("The File in question was not found, delete reference?", "File Not Found", MessageBoxButton.YesNo, MessageBoxImage.Error);
                        if (res == MessageBoxResult.Yes)
                        {
                            //delete reference
                            Deletefile(id);
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                fileContents = FileCache[id];
            }
            currentFileId = id;
            return(fileContents);
        }
예제 #11
0
        private void Application_Exit(object sender, ExitEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("LeHand is exiting...");
            if (!LeHandExited)
            {
                Communicator.quit();
            }
            LeHandExited = true;

            StartupValues values = new StartupValues();

            values.StartFontSize   = Convert.ToInt32(AdvancedMode.inst.textEditor.FontSize);
            values.StartupFileId   = FileManager.currentFileId;
            values.ShowLineNumbers = Convert.ToInt32(AdvancedMode.inst.textEditor.ShowLineNumbers);

            LHregistry.SetStartupValues(values);

            System.Windows.Application.Current.Shutdown();
            Environment.Exit(0);
        }
예제 #12
0
        private void RemoveLuaScript(object sender, EventArgs e)
        {
            int idToBeRemoved = -1;             //some ridiculous number, i. e. -1 just isn't possible

            if (LuaFileView.SelectedIndex != -1)
            {
                //check if file is open
                idToBeRemoved = (LuaFileView.SelectedIndex);
                int[] allIds = LHregistry.GetAllFileIds();

                if (allIds.Length > idToBeRemoved && idToBeRemoved != -1)
                {
                    LHregistry.RemoveFile(allIds[idToBeRemoved]);
                    LuaFileView.Items.RemoveAt(idToBeRemoved);

                    LuaFileView.Items.Refresh();
                }

                RefreshLuaScript();
            }
        }
예제 #13
0
        private void RefreshLuaScript()
        {
            List <string> LuaNames = new List <string>(LHregistry.GetAllFilenames());

            int currOpenedFileId = FileManager.currentLoadedIndex;


            for (int i = 0; i < LuaNames.Count; i++)
            {
                Label currLuaFileViewLabel = (Label)(LuaFileView.Items[i]);

                if (LuaNames[i] == (string)currLuaFileViewLabel.Content)
                {
                    continue;
                }
                else
                {
                    Label label = new Label();
                    label.Name    = "TxtBox" + i.ToString();
                    label.Content = LHregistry.getSimpleName(LuaNames[i]);

                    if (FileManager.isFileNotSaved[i])
                    {
                        label.Content += "*";
                    }

                    if (currOpenedFileId == i)
                    {
                        styleOpenedFileLabel(label);
                    }
                    else
                    {
                        styleLabel(label);
                    }
                    LuaFileView.Items.RemoveAt(i);
                    LuaFileView.Items.Insert(i, label);
                }
            }
            LuaFileView.Items.Refresh();
        }
예제 #14
0
        private void LoadLuaFileFromSelectedObjectInList(object sender, EventArgs e)
        {
            ListBox lstbx = (ListBox)(sender);

            SelectedItemIndex = lstbx.SelectedIndex;
            if (SelectedItemIndex < 0)
            {
                return;
            }

            FileManager.currentLoadedIndex = SelectedItemIndex;


            int[] id           = LHregistry.GetAllFileIds();
            int   ActualFileId = id[SelectedItemIndex];

            LoadFileFromId(ActualFileId);
            LuaFileView.Items.Refresh();
            //ALWAYS REFRESH, saves some headaches, like trying to solve a nonexistent problem for two hours. Trust me, I know.

            RefreshLuaScript();
        }
예제 #15
0
 public static void Deletefile(int fileid)
 {
     LHregistry.RemoveFile(fileid);
 }
예제 #16
0
        public void SaveTextEditor()
        {
            string writePath = LHregistry.GetFile(FileManager.currentFileId);

            textEditor.Save(writePath);
        }