Author Topic: open file with edit in main mdi window from macro called in floating window  (Read 9092 times)

TKasparek

  • Senior Community Member
  • Posts: 246
  • Hero Points: 29
I'm writing a macro that parses a line for a file and attempts to open the file in the main mdi window (parsed file is in floating window so both are still in view.) I have everything I need to get the file name and verify it's correct but I'm not sure why forcing it to open in the main mdi is so difficult. Looking at examples in the slickedit macros I believe what I'm looking for is something like:
Code: [Select]
      // Make SE Main Form Window the focus program.
      mdisetfocus(_mdi);
      edit(file);

I've gone through countless trial and error stages at this point and just can't get this to work. (I'm on Linux). Everything I run from a floating window opens the file in the same floating window (unless it's already open in another window).

Slickedit Help files don't seem to be very helpful here, or I'm missing something so obvious that it doesn't need documentation. What am I doing wrong and where can I find info on how to do this? I want focus to stay on the file opened but it needs to be in the main window.

Graeme

  • Senior Community Member
  • Posts: 2812
  • Hero Points: 347
Have you had  a look at float_window_toggle.  After you call Edit you could call _MDIChildIsFloating to check if it's a floating window.

Code: [Select]
   if (_mdi.p_child._no_child_windows()==0) {
      _mdi.p_child._set_focus();
   }


Code: [Select]
_command void float_window_toggle() name_info(','VSARG2_ICON|VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_LINEHEX|VSARG2_REQUIRES_MINMAXRESTOREICONIZE_WINDOW|VSARG2_NOEXIT_SCROLL)
{
   if ( !(_default_option(VSOPTION_APIFLAGS) & VSAPIFLAG_MDI_TABGROUPS) ) {
      // tab groups not supported;
      return;
   }
   int wid=p_window_id;
   if (_MDIChildIsFloating(wid)) {
      _MDIChildFloatWindow(wid,false);
      wid._set_focus();
   } else {
      _MDIChildFloatWindow(wid,true);
   }
}

TKasparek

  • Senior Community Member
  • Posts: 246
  • Hero Points: 29
Getting closer. That does open the file in the main mdi window but it does so because it is forcing the floating window there before hand. To be more specific, from a macro I need to:
  • parse a file name and line number from current line in file open in a floating window (done)
  • open a file using edit in the main mdi window without changing any current window configuration
  • set focus to the file that was opened
  • goto line specified (done)
  • goto first non-blank character in line (done)

This is the full function:
Code: [Select]
/**
 *
 * navigate_to_project_file_and_line
 *
 */
void navigate_to_project_file_and_line(_str file_name='', _str line_number='') {

   _str file_found = '';
   _str message_string = '';

   // See if the file supplied is an absolute path.
   if (file_exists(file_name)) {

      file_found = file_name;
      message_string = "Absolute";
   }

   // See if the path/file supplied is relative to the project.
   if (file_found == '' _project_name != '') {

      // Try just opening the file from the projet working directory.

      project_folder := _ProjectGet_WorkingDir (_ProjectHandle (_project_name));
      if (project_folder != '') {

         project_folder = absolute (project_folder, strip_filename (_project_name,'N'));
      }

      project_file_name := project_folder :+ file_name;

      if (file_exists(project_file_name)) {

         file_found = project_file_name;
         message_string = "Relative";
      }
   }

   // See if the filename is in the current project by stripping the path.
   if (file_found == '' && project_file_match(strip_filename (file_name, 'PD'), true) != '') {

      // Qualify the file name by search for it in the current project.
      file_found = _projectFindFile(_workspace_filename, _project_name, file_name, 1);
      if (file_found == '') {

         // Look for any project file name without comparing path.

         file_found = _projectFindFile(_workspace_filename, _project_name, file_name, 0, 1);
         if (file_found != '') {

            // If there are duplicates, check for
            file_found = _prompt_for_duplicate_files(file_found);
         }
      }

      if (file_found != '') {

         message_string = "Project";
      }
   }

   if (file_found != '' && file_found != COMMAND_CANCELLED_RC) {

      // Open file in SE Main Form Window.

      // NEED HELP HERE!!

      /*
      int wid=p_window_id;
      if (_MDIChildIsFloating(wid)) {

         _MDIChildFloatWindow(wid,false);
         wid._set_focus();

      } else {

         _MDIChildFloatWindow(wid,true);
      }

      say("1 mdi:" :+ _mdi);
      say("1 wid:" :+ wid);
      say("1 p_window_id:" :+ p_window_id);
      say("1 _mdi._edit_window" :+ _mdi._edit_window());
      */

      mdisetfocus(_mdi);
       
      /*
      say("2 mdi:" :+ _mdi);
      say("2 p_window_id:" :+ p_window_id);
      say("2 _mdi._edit_window" :+ _mdi._edit_window());

      p_window_id=_mdi._edit_window(); //

      say("3 mdi:" :+ _mdi);
      say("3 p_window_id:" :+ p_window_id);
      say("3 _mdi._edit_window" :+ _mdi._edit_window());
      */
      edit(file_found); //, EDIT_RESTOREPOS);

      message_string :+= " navigation to: \"" :+ file_found :+ "\"";

      // Validate a line number if supplied.
      if ((line_number != '') && isinteger(line_number)) {

         goto_line(line_number);
         first_non_blank();
         message_string :+= ":" :+ line_number;
      }

      message(message_string);

   } else {

      message("\"" :+ file_name :+ "\" not found!");
   }
}

Graeme

  • Senior Community Member
  • Posts: 2812
  • Hero Points: 347
This works for me
Code: [Select]
   edit('C:\temp\junk.cpp');

   int wid=p_window_id;
   if (_MDIChildIsFloating(wid)) {
      _MDIChildFloatWindow(wid,false);
      wid._set_focus();
   }

TKasparek

  • Senior Community Member
  • Posts: 246
  • Hero Points: 29
Guess I was trying to get it to pop up in the correct spot to begin with. Moving it there afterward works good enough. Thanks for the help! ++hp